wire

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package wire is the message line format, on disk and on the network.

A message is exactly one line:

<seq> <UTC ts> <from>> <one line of text>

Plain text on purpose: the readers are LLMs, so it stays token-lean and greppable. Ordering, cursors, and resume use seq only. The timestamp is there to be read; nothing is ever gated on it.

Index

Constants

View Source
const MaxBody = 512

MaxBody caps a message body so that one append is one write, and so a reader never sees half a message except at the tail of a file.

View Source
const MaxName = 64

MaxName caps a node or topic name.

Variables

View Source
var ErrMalformed = errors.New("malformed line")

ErrMalformed marks a line that is not a message: garbage, or the torn tail of a file that was being appended to as we read it.

Functions

func CheckBody

func CheckBody(s string) error

CheckBody validates a message body: one line, bounded, printable, UTF-8. Rejecting control characters is what keeps one message equal to one line.

func CheckName

func CheckName(s string) error

CheckName validates a node or topic name. Names become filenames, so the charset is deliberately narrow: no dot, no slash, no separator of any kind, which makes traversal out of the workspace unrepresentable rather than merely checked for. A leading '#' marks a topic.

func Display added in v0.7.0

func Display(m Msg, style string) string

Display renders a message for a reader, which is not the same job as Format.

What is stored never changes: a full UTC stamp, greppable by date, so an inbox is its own archive. What a reader sees is a preference -- the timestamp is the widest field on the line and the least load bearing, since order and resume come from seq and nothing is ever gated on time. "hm" keeps the part people actually read; "none" admits that in a live conversation the arrival time is now.

func Escape

func Escape(s string) string

Escape folds a multi-line text into the one-line body the wire requires: backslash to `\\`, newline to `\n`, tab to `\t`, nothing else. One message is one line on disk and on the wire -- the newline is the frame, and that is not negotiable -- so multi-line content travels folded, and readers that care unfold it. Like the thread grammar, the escape set is pinned to exactly these three so historical mail never grows dialects.

func Format

func Format(m Msg) string

Format renders a message as its line. The line has no trailing newline.

func ReplyTo

func ReplyTo(body string) (uint64, bool)

ReplyTo reports the message a body replies to, under the one thread grammar: "re:<seq>" at the very start of the body, one target, followed by a space and the text. Nothing else counts -- not "re: 42", not "Re:42", not a reference mid-body -- because a convention loose enough to have variants makes historical mail unparseable the day someone builds a thread view. The relay never calls this; threads are a client concern, and this function is the grammar's single definition.

func Unescape

func Unescape(s string) string

Unescape is Escape's inverse. Unknown escapes pass through untouched rather than erroring: a lone backslash in old mail is text, not a frame.

Types

type Msg

type Msg struct {
	Seq  uint64
	TS   time.Time
	From string
	Body string
}

Msg is one line of a log.

func Parse

func Parse(line string) (Msg, error)

Parse reads a line back. Names contain neither a space nor a '>', so the field boundaries are unambiguous and a body may contain anything else.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL