Documentation
¶
Overview ¶
Package convert renders a conversation read from one agent for another agent's writer: what the receiving agent should see (its own words and the user's as messages, the other agent's tool activity as clearly labelled text), within a budget, with a report of everything left out and a briefing at the end. Brief renders a briefing alone, for a target hopsesh cannot write to (a cloud session's first prompt). It never calls a model.
Index ¶
- Constants
- Variables
- func Archive(nodes []ir.Node, r Request) ([]byte, error)
- func BoundText(s string, limit int) string
- func HistoryFile(nodes []ir.Node, from, title string) (string, int)
- func MergeArchives(limit int64, parts ...[]byte) ([]byte, error)
- type ArchiveWriter
- type BriefProfile
- type BriefRequest
- type BriefResult
- type Briefing
- type Fidelity
- type Report
- type Request
- type Result
- type Rules
- type Tally
Constants ¶
BudgetShare is the share of the target's context the converted history may use.
const CloudBudget = 2000
CloudBudget is a cloud briefing's size, in tokens: about what a sub-agent hands back as a distilled summary.
const HistoryBudget = 240 << 10
HistoryBudget is the most a committed history file holds, in bytes: about 30% of a 200,000-token window. The newest part is kept.
Variables ¶
var Program func() string
Program names hopsesh for the receiving agent's shell (the briefing's archive commands): "hopsesh" when the user's shell finds it, its full path otherwise. nil: "hopsesh".
Functions ¶
func Archive ¶ added in v0.4.0
Archive retains portable history independently of working-context limits. Vendor private state, signed reasoning and attachment bytes never cross this boundary.
func BoundText ¶ added in v0.4.0
BoundText includes its marker in the byte limit and never splits a UTF-8 sequence.
func HistoryFile ¶ added in v0.4.0
HistoryFile renders a conversation as the Markdown file a hand-off can commit (.hopsesh/handoff.md): the user's and the agent's messages, each tool call as one line (never its output), in a frame that says it is quoted history, not instructions, cut to HistoryBudget from the oldest end, with secrets masked. It returns the text and how many secrets were masked.
Types ¶
type ArchiveWriter ¶ added in v0.4.2
type ArchiveWriter struct {
// contains filtered or unexported fields
}
ArchiveWriter builds one portable archive incrementally: earlier archives are re-read record by record under the current redaction/mapping policy and merged with new history without holding several copies. Identical encoded records are kept once, differing renderings are all kept (fork evidence). Crossing the archive size limit is a LimitError; the archive is never truncated.
func NewArchiveWriter ¶ added in v0.4.2
func NewArchiveWriter(r Request) *ArchiveWriter
NewArchiveWriter starts an archive under r's mapping, redaction and limits.
func (*ArchiveWriter) AddArchive ¶ added in v0.4.2
func (w *ArchiveWriter) AddArchive(r io.Reader) error
AddArchive re-reads an earlier portable archive record by record through AddNode.
func (*ArchiveWriter) AddBriefing ¶ added in v0.4.2
func (w *ArchiveWriter) AddBriefing() error
AddBriefing keeps optional briefing data even when the working copy must shorten it.
func (*ArchiveWriter) AddNode ¶ added in v0.4.2
func (w *ArchiveWriter) AddNode(n ir.Node) error
AddNode strips private state, maps every portable textual field (including tool arguments and fragments) and appends the record unless it is already present.
func (*ArchiveWriter) AddNodes ¶ added in v0.4.2
func (w *ArchiveWriter) AddNodes(nodes []ir.Node) error
AddNodes adds nodes in order.
func (*ArchiveWriter) Bytes ¶ added in v0.4.2
func (w *ArchiveWriter) Bytes() []byte
Bytes is the archive so far.
func (*ArchiveWriter) Records ¶ added in v0.4.2
func (w *ArchiveWriter) Records() int
Records is the number of records in the archive so far.
type BriefProfile ¶ added in v0.4.0
type BriefProfile string
BriefProfile is what a briefing is for.
const ( // BriefContinue is the briefing a continuation in another agent ends with: what // Render writes with Fidelity Note. BriefContinue BriefProfile = "continue" // BriefCloud is the first prompt of a cloud session, all the cloud agent learns of the // conversation: within CloudBudget tokens, its quoted history framed as data, what // stayed on the machine, and secrets masked. BriefCloud BriefProfile = "cloud" )
type BriefRequest ¶ added in v0.4.0
type BriefRequest struct {
Profile BriefProfile
From string // the source agent's name ("Claude Code")
To string // the target agent's name ("Codex")
Briefing Briefing
}
BriefRequest is a briefing for a target hopsesh cannot write a session for.
type BriefResult ¶ added in v0.4.0
type BriefResult struct {
Text string `json:"text"`
Tokens int `json:"tokens"`
// Masked is how many secrets the scanner masked (cloud briefings).
Masked int `json:"masked,omitempty"`
// Shortened: parts were cut to fit the budget (cloud briefings).
Shortened bool `json:"shortened,omitempty"`
}
BriefResult is a rendered briefing.
func Brief ¶ added in v0.4.0
func Brief(nodes []ir.Node, r BriefRequest) BriefResult
Brief renders the briefing for nodes without a target writer. With BriefContinue it is the text Render puts in a continuation with Fidelity Note.
type Briefing ¶
type Briefing struct {
FromVersion string
SourceID string
SourceLoc string
TargetLoc string
TargetOS string
When time.Time
Branch string
Head string // the commit at transfer time
Dirty int
Plan []ir.PlanEntry
Missing []string // differences in instructions, skills, MCP servers
ToolNames string // the target's own tool names, to use instead of the history's
Note string // a handoff note the source agent wrote, if any
Rules []Rules // selected source instruction text, carried when asked
// For a cloud briefing (Brief with BriefCloud):
Title string // the session's title
Unpushed int // commits the cloud gets that were not on the remote
Withheld []string // files that stay on the machine (credential-like, or not chosen)
NotCarried []string // anything else the cloud does not get ("the user's personal CLAUDE.md")
HistoryFile string // the conversation committed on the branch (".hopsesh/handoff.md"), if it is
HistoryRecords int // records in the preserved portable archive, including earlier transfers
// Checkout: the cloud may start on another branch (its driver cannot choose one), so the
// briefing asks it to check out Branch of Repo (host/owner/repo) first.
Checkout bool
Repo string
}
Briefing is what the receiving agent is told at the end of the history.
type Report ¶
type Report struct {
Fidelity Fidelity `json:"fidelity"`
Method string `json:"method,omitempty"`
Capacity ir.Capacity `json:"capacity"`
Archive string `json:"archive,omitempty"`
BriefShortened bool `json:"briefShortened,omitempty"`
Blocked string `json:"blocked,omitempty"`
Budget int `json:"budgetTokens"`
Used int `json:"usedTokens"`
Messages int `json:"messages"`
ToolCalls int `json:"toolCalls"`
NativeCalls int `json:"nativeCalls,omitempty"`
Reasoning int `json:"reasoningDropped"`
Attachments int `json:"attachmentsAsPlaceholders,omitempty"`
Truncated int `json:"outputsShortened"`
Summarised int `json:"stepsSummarised"`
// Omitted entries are left out of the working context entirely (recent-turns mode);
// they stay in the portable archive and are never counted as covered.
Omitted int `json:"entriesOmitted,omitempty"`
// Older is how older history was carried (ir.OlderExtract or ir.OlderRecent).
Older string `json:"older,omitempty"`
// UserBudget is the user's context budget when it lowered the model's allowance.
UserBudget int `json:"userBudget,omitempty"`
// ArchiveRecords counts records preserved in the portable archive, including earlier
// transfers. Included context and archive preservation are reported separately.
ArchiveRecords int `json:"archiveRecords,omitempty"`
// OldestIncluded excerpts the oldest conversation entry carried verbatim (after any
// extract), so a review can see where the working context starts.
OldestIncluded string `json:"oldestIncluded,omitempty"`
Redactions int `json:"redactions,omitempty"`
PathsMapped int `json:"pathsMapped"`
Summary string `json:"summary"`
}
Report is what a conversion keeps and leaves out.
func (Report) ContextSummary ¶ added in v0.4.0
ContextSummary exposes the same capacity evidence to text front ends, including vendor import plans whose conversion summary describes a different operation.
type Request ¶
type Request struct {
// IncludeGenerated carries a known cloud handoff briefing as context in a new session.
IncludeGenerated bool
Nodes []ir.Node
From string // the source agent's name ("Claude Code")
To string // the target agent's name ("Codex")
Fidelity Fidelity
Native bool // render exact tool calls natively (the target writer supports it)
Limit *int // optional remaining incoming allowance
Window int // the target's context, in tokens
Mappings []agent.Mapping // source paths → target paths
Briefing Briefing
Redact func([]byte) ([]byte, int)
// Limits is the operation's history policy: the user's optional context budget, how
// older history is carried, and the portable archive's size limit.
Limits ir.Limits
}
Request is one rendering.