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 ¶
- func Canonical(v any) ([]byte, error)
- func Chain(nodes []Node, parent NodeID)
- type Actor
- type Attachment
- type Cursor
- type Edit
- type Header
- type Item
- type Kind
- type MCP
- type Native
- type Node
- type NodeID
- type Origin
- type PlanEntry
- type Profile
- type Reasoning
- type Role
- type Search
- type Segment
- type Shell
- type Subagent
- type ToolCall
- type ToolKind
- type ToolPair
- type ToolResult
- type ToolStatus
- type Write
- type WriteMode
- type WriteRequest
- type WriteResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 ¶
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 ¶
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 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.
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 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 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 WriteMode ¶
type WriteMode string
WriteMode is whether a write creates a session or extends one.
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.