ir

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ir is the conversation representation every agent module reads into and writes from, so a session can continue in another agent: N readers and N writers instead of a converter for every pair. It keeps what a coding conversation means (messages, tool calls with their intent, results, plans) and, beside it, each record's native form so a writer for the same agent can emit it unchanged.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canonical

func Canonical(v any) ([]byte, error)

Canonical encodes v as RFC 8785 (JSON Canonicalization Scheme) JSON: object keys sorted by UTF-16 code units, no insignificant whitespace, minimal string escaping. Numbers must be integers (hopsesh hashes no floats).

func Chain

func Chain(nodes []Node, parent NodeID)

Chain sets Parent and ID on nodes in order, starting after parent.

Types

type Actor

type Actor string

Actor is who produced a node.

const (
	User  Actor = "user"
	Agent Actor = "agent"
)

type Attachment

type Attachment struct {
	MIME string `json:"mime"`
	Data []byte `json:"data,omitempty"`
	Name string `json:"name,omitempty"`
}

Attachment is an image or file the user attached.

type Cursor

type Cursor struct {
	Offset int64  `json:"offset"`
	Head   NodeID `json:"head,omitempty"`
}

Cursor is where a read stopped: the byte offset after the last complete record of the session's main file, and the last node read.

type Edit

type Edit struct {
	Path string `json:"path"`
	Old  string `json:"old,omitempty"`
	New  string `json:"new,omitempty"`
	Diff string `json:"diff,omitempty"`
}

Edit changes part of a file: either Old/New text, or a unified diff.

type Header struct {
	Agent     string    `json:"agent"`
	Version   string    `json:"version,omitempty"`
	SessionID string    `json:"sessionId"`
	CWD       string    `json:"cwd"`
	Title     string    `json:"title,omitempty"`
	GitBranch string    `json:"gitBranch,omitempty"`
	Model     string    `json:"model,omitempty"`
	Created   time.Time `json:"created"`
}

Header describes a session as a whole.

type Item

type Item struct {
	Node   NodeID    `json:"node"`
	Role   Role      `json:"role"`
	Time   time.Time `json:"time"`
	Text   string    `json:"text,omitempty"`
	Tool   *ToolPair `json:"tool,omitempty"`   // native replay only
	Native *Native   `json:"native,omitempty"` // same-agent passthrough
}

Item is one rendered unit for a writer.

type Kind

type Kind string

Kind is what a node is.

const (
	KindMessage    Kind = "message"
	KindReasoning  Kind = "reasoning"
	KindToolCall   Kind = "tool_call"
	KindToolResult Kind = "tool_result"
	KindPlan       Kind = "plan"
	KindCompaction Kind = "compaction"
	KindAttachment Kind = "attachment"
)

type MCP

type MCP struct {
	Server string `json:"server"`
	Tool   string `json:"tool"`
}

MCP is a call to a tool of an MCP server.

type Native

type Native struct {
	Format  string          `json:"format"` // "claude.jsonl", "codex.rollout"
	Payload json.RawMessage `json:"payload"`
}

Native is a node's record as its agent wrote it.

type Node

type Node struct {
	ID     NodeID    `json:"id"`
	Parent NodeID    `json:"parent,omitempty"`
	Kind   Kind      `json:"kind"`
	Actor  Actor     `json:"actor"`
	Time   time.Time `json:"time"`
	// Text is the message, the reasoning summary or the compaction summary.
	Text       string      `json:"text,omitempty"`
	Tool       *ToolCall   `json:"tool,omitempty"`
	Result     *ToolResult `json:"result,omitempty"`
	Plan       []PlanEntry `json:"plan,omitempty"`
	Attachment *Attachment `json:"attachment,omitempty"`
	Reasoning  *Reasoning  `json:"reasoning,omitempty"`
	Native     *Native     `json:"native,omitempty"`
	Generated  bool        `json:"generated,omitempty"` // written by hopsesh (briefing, acknowledgement)
	Origin     *Origin     `json:"origin,omitempty"`    // set on nodes hopsesh converted from another agent
}

Node is one step of a conversation.

type NodeID

type NodeID string

NodeID is a content address: SHA-256 (hex) of the canonical form of a node's model-visible content and its parent's id. The same conversation read twice, or from a copy with other timestamps and native ids, gets the same ids.

func ComputeID

func ComputeID(n Node, parent NodeID) NodeID

ComputeID returns a node's content address given its parent.

type Origin

type Origin struct {
	Agent string `json:"agent"`
	Node  NodeID `json:"node"`
}

Origin says where a converted node came from.

type PlanEntry

type PlanEntry struct {
	Content string `json:"content"`
	Status  string `json:"status"` // pending | in_progress | completed
}

PlanEntry is one item of the agent's plan or to-do list.

type Profile

type Profile struct {
	Window       int  `json:"window"`       // the target model's usable context, in tokens
	NativeReplay bool `json:"nativeReplay"` // can render tool calls as its own tool pairs
}

Profile is what a writer can take.

type Reasoning

type Reasoning struct {
	Opaque bool `json:"opaque"` // signed or encrypted content (in Native)
}

Reasoning is the agent's thinking. It never crosses vendors: Opaque content is bound to the model, account or conversation prefix that produced it.

type Role

type Role string

Role is who a rendered item speaks as.

const (
	RoleUser  Role = "user"
	RoleAgent Role = "agent"
)
type Search struct {
	Pattern string `json:"pattern"`
	Path    string `json:"path,omitempty"`
}

Search looks for files or text.

type Segment

type Segment struct {
	Header Header `json:"header"`
	Nodes  []Node `json:"nodes"`
	Cursor Cursor `json:"cursor"`
}

Segment is what a Reader returns: the session's active branch from a cursor on.

type Shell

type Shell struct {
	Command string `json:"command"`
	Dir     string `json:"dir,omitempty"`
}

Shell is a command run in a shell.

type Subagent

type Subagent struct {
	Description string `json:"description,omitempty"`
	Prompt      string `json:"prompt,omitempty"`
}

Subagent hands a task to a sub-agent.

type ToolCall

type ToolCall struct {
	CallID string          `json:"callId"`
	Name   string          `json:"name"`  // the agent's tool name: "Bash", "exec_command", "mcp__github__x"
	Input  json.RawMessage `json:"input"` // exact input
	Kind   ToolKind        `json:"kind"`

	Shell    *Shell    `json:"shell,omitempty"`
	Edit     *Edit     `json:"edit,omitempty"`
	Write    *Write    `json:"write,omitempty"`
	Path     string    `json:"path,omitempty"` // read, delete
	Search   *Search   `json:"search,omitempty"`
	URL      string    `json:"url,omitempty"` // fetch
	Subagent *Subagent `json:"subagent,omitempty"`
	MCP      *MCP      `json:"mcp,omitempty"`
}

ToolCall is a tool the agent called. Exactly one of the intent fields is set when the reader understood the call; Name and Input always keep the original.

type ToolKind

type ToolKind string

ToolKind is the intent of a tool call (the Agent Client Protocol's kinds).

const (
	ToolRead     ToolKind = "read"
	ToolEdit     ToolKind = "edit"
	ToolDelete   ToolKind = "delete"
	ToolMove     ToolKind = "move"
	ToolSearch   ToolKind = "search"
	ToolExecute  ToolKind = "execute"
	ToolThink    ToolKind = "think"
	ToolFetch    ToolKind = "fetch"
	ToolPlan     ToolKind = "plan"
	ToolSubagent ToolKind = "subagent"
	ToolOther    ToolKind = "other"
)

type ToolPair

type ToolPair struct {
	Call   ToolCall   `json:"call"`
	Result ToolResult `json:"result"`
}

ToolPair is a tool call and its result, for native replay.

type ToolResult

type ToolResult struct {
	CallID   string     `json:"callId"`
	Status   ToolStatus `json:"status"`
	ExitCode *int       `json:"exitCode,omitempty"`
	Output   string     `json:"output"`
	// OutputBytes is the size of the full output when Output was shortened by the reader.
	OutputBytes int64 `json:"outputBytes,omitempty"`
}

ToolResult is what a tool call returned.

type ToolStatus

type ToolStatus string

ToolStatus is how a tool call ended.

const (
	StatusCompleted ToolStatus = "completed"
	StatusFailed    ToolStatus = "failed"
)

type Write

type Write struct {
	Path    string `json:"path"`
	Content string `json:"content"`
}

Write creates or replaces a whole file.

type WriteMode

type WriteMode string

WriteMode is whether a write creates a session or extends one.

const (
	WriteNew    WriteMode = "new"
	WriteAppend WriteMode = "append"
)

type WriteRequest

type WriteRequest struct {
	Mode WriteMode `json:"mode"`
	// SessionID is the session to append to (WriteAppend), or the id to use for a new one
	// ("" lets the writer choose).
	SessionID string `json:"sessionId,omitempty"`
	// Expect is where the session's main file must still end for an append (it was read up
	// to there); anything else is ErrDiverged.
	Expect Cursor `json:"expect"`
	Header Header `json:"header"`
	Items  []Item `json:"items"`
}

WriteRequest asks a writer for native records.

type WriteResult

type WriteResult struct {
	SessionID string `json:"sessionId"`
	Path      string `json:"path"`
	From      int64  `json:"from"` // byte range written into Path
	To        int64  `json:"to"`
	Cursor    Cursor `json:"cursor"` // the session's new end
}

WriteResult is what a writer wrote.

Jump to

Keyboard shortcuts

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