convert

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 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 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

View Source
const BudgetShare = 0.30

BudgetShare is the share of the target's context the converted history may use.

View Source
const CloudBudget = 2000

CloudBudget is a cloud briefing's size, in tokens: about what a sub-agent hands back as a distilled summary.

View Source
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

This section is empty.

Functions

func Archive added in v0.4.0

func Archive(nodes []ir.Node, r Request) ([]byte, error)

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

func BoundText(s string, limit int) string

BoundText includes its marker in the byte limit and never splits a UTF-8 sequence.

func HistoryFile added in v0.4.0

func HistoryFile(nodes []ir.Node, from, title string) (string, int)

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.

func MergeArchives added in v0.4.0

func MergeArchives(limit int64, parts ...[]byte) ([]byte, error)

MergeArchives deduplicates immutable portable records by their encoded content. It preserves differing renderings rather than silently dropping fork evidence.

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 Fidelity

type Fidelity string

Fidelity is how much of the source the target gets.

const (
	// History: the whole conversation, tool activity as text (oldest steps summarised
	// when over budget).
	History Fidelity = "history"
	// Note: only the briefing, in a new session.
	Note Fidelity = "note"
)

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

func (r Report) ContextSummary() string

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.

type Result

type Result struct {
	Items  []ir.Item `json:"-"`
	Report Report    `json:"report"`
}

Result is a rendering.

func Render

func Render(r Request) Result

Render turns nodes into items for the target writer.

type Rules

type Rules struct {
	File string
	Text string
}

Rules are the text of one selected instruction file, quoted in the briefing.

type Tally added in v0.4.0

type Tally struct {
	Messages  int `json:"messages"`
	ToolCalls int `json:"toolCalls"`
	Reasoning int `json:"reasoning"`
}

Tally counts what a conversation holds, for the loss report of a hand-off.

func Count added in v0.4.0

func Count(nodes []ir.Node) Tally

Count tallies nodes (hopsesh's own notes left out).

Jump to

Keyboard shortcuts

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