Documentation
¶
Overview ¶
Package handoff carries a conversation's context to another one: a fork's own copy of a Claude session cut after a turn, an excerpt of a transcript within a budget, the note an agent writes for the next one, and the blocks these go in as a first message (a handoff) or as a message back into the conversation a fork came from (a merge).
Index ¶
- Constants
- Variables
- func Agent(p wire.Provider) string
- func Bootstrap(_ From, mode wire.HandoffMode, fork bool, path string) string
- func Budget(provider wire.Provider, model string) int
- func BudgetIn(window int) int
- func CodexNoteArgs(session, model, out string) []string
- func Cut(turns []wire.Turn, at string, working bool) (keep wire.Turn, next string, ok bool)
- func Excerpt(turns []feed.WholeTurn, agent wire.Provider, budget int) (text string, kept int)
- func ForkClaude(src, oldID, newID, cutBefore string) (string, error)
- func Handoff(from From, mode wire.HandoffMode, fork bool, text string) string
- func PromptOf(mode wire.DraftMode) string
- func Result(fork From, text string) string
- func Tokens(s string) int
- func UUIDOfTurn(turnID string) string
- func Window(provider wire.Provider, model string) int
- func WriteNote(ctx context.Context, run NoteRun) (string, error)
- type ArtifactStore
- func (s *ArtifactStore) Claim(sourceID, artifactID, targetID string) (string, int64, error)
- func (s *ArtifactStore) PutText(targetID, text string) (string, int64, error)
- func (s *ArtifactStore) Release(targetID, path string) error
- func (s *ArtifactStore) Snapshot(sourceID, transcriptPath, targetID string) (wire.HandoffArtifact, error)
- func (s *ArtifactStore) Take(sourceID, artifactID, targetID string, max int64) ([]byte, error)
- func (s *ArtifactStore) Target(sourceID, artifactID string) (string, error)
- type From
- type NoteRun
Constants ¶
const DefaultBudget = 16_000
DefaultBudget is how many tokens an excerpt takes at most unless the target's window is smaller.
const NotePrompt = "Write a handoff note for another agent that will continue this work in a new conversation. " +
"It has no access to this conversation: only to the same folder. Use exactly these Markdown sections: " +
"## Goal, ## Decisions, ## Current state, ## Next steps, ## Files, ## Verify, ## Gotchas. " +
"Be concrete: paths, commands, ids, what passed and what failed. Leave out what does not matter for the next steps. " +
"No preamble and no closing words. Write in the language the person writes in."
NotePrompt is what the source agent is asked to write the handoff note with.
const NoteTimeout = 180 * time.Second
NoteTimeout is how long an agent has to write a note.
const ResultPrompt = "This chat is a branch of another conversation. Write a short result note for that conversation: " +
"what was done here, the files touched, the decisions made and what is left. Markdown, at most about 25 lines. " +
"No preamble and no closing words. Write in the language the person writes in."
ResultPrompt is what a fork's agent is asked to write the note it sends back with.
Variables ¶
var ( ErrNoCompleteHistory = errors.New("handoff: transcript has no complete record") ErrArtifactNotFound = errors.New("handoff: artifact not found") )
var ErrArtifactTooBig = errors.New("handoff: artifact is too big")
ErrArtifactTooBig: the material is larger than the caller allows.
var ErrNoCut = errors.New("the transcript has no such turn")
ErrNoCut: the transcript has no line of the turn a fork is to be cut before.
var ErrNoNote = errors.New("the agent wrote no note")
ErrNoNote: the agent wrote nothing; the error's text says why when the CLI did.
Functions ¶
func Bootstrap ¶ added in v0.16.5
Bootstrap is a short first prompt whose approved context is in a private runtime-owned file. The CLI receives the path as prompt text, never as an argv substitution; the agent reads large files in bounded pieces.
func Budget ¶
Budget is the tokens an excerpt for the model may take: DefaultBudget, and never more than a quarter of its window.
func BudgetIn ¶ added in v0.15.46
BudgetIn is Budget for a model whose window is known: the vendors' models on a backend profile have their own.
func CodexNoteArgs ¶
CodexNoteArgs are the arguments of `codex` that write a note from a fork of session: never saved, read-only, no approvals and no hooks (the fork is no conversation of the runtime's), the last message into out, the prompt on stdin.
func Cut ¶
Cut is where a fork of turns cuts: after the turn at, or after the last finished one when at is "". next is the turn that opens right after the cut ("" when the cut is the transcript's end); ok is false when at is not a finished turn of them. working says the last turn still runs.
func Excerpt ¶
Excerpt is the context of a conversation within budget tokens: the person's first request and as many of the latest turns as fit, oldest first, with the roles kept and the texts whole — the person's messages, the agent's replies, and the key commands of a turn with the end of their output. A turn that does not fit with its commands goes without them; one that does not fit at all ends the excerpt there. Reasoning, tool state and attachments stay out. kept is how many turns it holds, the first one included.
func ForkClaude ¶
ForkClaude writes a Claude session of its own for a fork: the lines of the transcript at src before the line whose uuid is cutBefore (the whole transcript when it is ""), each with its session id made newID, into a file newID.jsonl beside it, whose path it returns. The queue's own lines that stand right before the cut belong to the turn cut off and stay out of the copy. Claude resumes the copy as it resumes any session it kept: the fork starts with the history up to the cut, and the conversation it came from is not touched.
func Handoff ¶
Handoff is the first message of a conversation that takes over another one's context: the text (an excerpt or a note) in a block that says where it comes from and what the agent is to do with it. fork marks the excerpt a fork starts with where the agent could not fork its session.
func PromptOf ¶
PromptOf is the prompt that writes the draft of a mode that needs the agent; "" for an excerpt.
func Result ¶
Result is the message a fork sends back into the conversation it came from: the result note in a block that says which branch it is.
func Tokens ¶
Tokens is the size of a text as the runtime estimates it: about four characters a token.
func UUIDOfTurn ¶
UUIDOfTurn is the transcript line a Claude turn id names ("c:<uuid>#<k>"); "" for another id.
Types ¶
type ArtifactStore ¶ added in v0.16.5
type ArtifactStore struct {
// Written is told when material was written (a draft, a claim, approved text): under a hub the runtime moves it
// into the store's `handoff` collection at once (internal/datamove). It must not block.
Written func()
// contains filtered or unexported fields
}
ArtifactStore keeps handoff material in private server-owned paths. Draft history is bound to both conversations; claimed material is bound to the conversation whose CLI may read it.
func NewArtifactStore ¶ added in v0.16.5
func NewArtifactStore(dataDir string) (*ArtifactStore, error)
NewArtifactStore opens the private handoff store below dataDir and removes expired material left by a previous runtime. Claimed material is normally released when its first turn ends; its TTL bounds crash leftovers.
func (*ArtifactStore) Claim ¶ added in v0.16.5
func (s *ArtifactStore) Claim(sourceID, artifactID, targetID string) (string, int64, error)
Claim atomically moves a draft to the target conversation. A draft can be claimed only once and only by the source and target pair it was created for.
func (*ArtifactStore) PutText ¶ added in v0.16.5
func (s *ArtifactStore) PutText(targetID, text string) (string, int64, error)
PutText stores approved editable handoff text directly for a target conversation and returns its private path.
func (*ArtifactStore) Release ¶ added in v0.16.5
func (s *ArtifactStore) Release(targetID, path string) error
Release removes claimed material after its target conversation no longer needs it. Both the target id and the exact server-owned path must match, so persisted state cannot make the runtime remove an arbitrary file. It is idempotent.
func (*ArtifactStore) Snapshot ¶ added in v0.16.5
func (s *ArtifactStore) Snapshot(sourceID, transcriptPath, targetID string) (wire.HandoffArtifact, error)
Snapshot reads the transcript size observed at open time, converts every complete record to provider-neutral semantic JSONL, and discards only an actively-written trailing record. It never loads the transcript as a whole.
func (*ArtifactStore) Take ¶ added in v0.16.5
func (s *ArtifactStore) Take(sourceID, artifactID, targetID string, max int64) ([]byte, error)
Take reads a draft in full and removes it, for material that leaves the machine (a move to another one): it exists on disk for as long as it takes to read it. A draft larger than max bytes is removed unread.
type NoteRun ¶
type NoteRun struct {
Provider wire.Provider
SessionID, Cwd string
Model, Prompt string
BaseEnv []string
Timeout time.Duration
Claude sidechat.Runtime
ClaudeProjectDir string
CodexBinary string
Log func(level, msg string, kv ...any)
// contains filtered or unexported fields
}
NoteRun is one note to write: the agent of Provider asked Prompt on a throwaway fork of its session SessionID, in Cwd, with no tools that change anything. Nothing of it is added to the session.