Documentation
¶
Overview ¶
Package wire implements the GCF (Graph Compact Format) encoder and decoder.
GCF is a compact, text-only, graph-native wire format designed for MCP tool responses. It exploits referential identity (local IDs), graph topology (edges as references), and hierarchical grouping (distance-based sections) to achieve 35-50% token savings over JSON while remaining human-readable.
TOON (Token-Oriented Object Notation) encoder for knowing context output. Uses the official toon-format/toon-go library for spec-conformant encoding.
TOON is a compact, human-readable format designed for LLM contexts. It uses tabular arrays (header + rows) for uniform object collections, which is ideal for symbol lists where every entry has the same fields.
Spec: https://github.com/toon-format/spec Library: https://github.com/toon-format/toon-go
Index ¶
- func Encode(p *Payload) string
- func EncodeTOON(p *Payload) (string, error)
- func EncodeWith(name string, p *Payload) (string, error)
- func EncodeWithSession(p *Payload, sess *Session) string
- func ListNames() string
- func Register(c *Codec)
- type Codec
- type Components
- type Decoder
- type Edge
- type Encoder
- type Payload
- type Session
- type Symbol
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeTOON ¶ added in v0.2.0
EncodeTOON encodes a Payload into TOON format using the official library.
func EncodeWith ¶
EncodeWith encodes a payload using the named codec.
func EncodeWithSession ¶
EncodeWithSession encodes a payload using GCF with session deduplication. Symbols that were already transmitted in prior responses are emitted as bare references (`@N # previously transmitted`) instead of full declarations. After encoding, newly-sent symbols are recorded in the session.
Types ¶
type Codec ¶
Codec is a registered encoding scheme with encode/decode functions and metadata.
type Components ¶
Components holds the score breakdown for a symbol.
type Edge ¶
type Edge struct {
Source string // qualified name of source symbol
Target string // qualified name of target symbol
EdgeType string
Status string // optional: "added", "removed", "unchanged" (for diff responses)
}
Edge represents a directed relationship in a GCF payload.
type Payload ¶
Payload is the input/output structure for GCF encoding/decoding.
func DecodeWith ¶
DecodeWith decodes input using the named codec.
func FromContextBlock ¶
func FromContextBlock(ctx stdctx.Context, block *knowingctx.ContextBlock, tool string, store types.GraphStore) (*Payload, error)
FromContextBlock converts a ContextBlock into a wire.Payload, optionally querying the store for edges between the included symbols.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session tracks symbols that have been transmitted to a client, enabling subsequent responses to reference them by ID without full retransmission. This makes multi-call workflows progressively cheaper.
Thread-safe: multiple tool handlers may encode concurrently within a session.
func (*Session) GetID ¶
GetID returns the session-global ID for a previously transmitted symbol. Returns -1 if not found.
func (*Session) Record ¶
Record marks symbols as transmitted and assigns session-global IDs. Call this after a successful encode to register newly-sent symbols.
func (*Session) Transmitted ¶
Transmitted returns true if the symbol has been sent in a previous response.