Documentation
¶
Overview ¶
Package feed is a conversation's feed on top of the agent's transcript: entries with ids that come from the transcript itself (a re-read and an incremental read agree), cut into turns by the runtime, read in pages by turn, and the signals in it that move the agent's state (a question asked, a gate resolved, a turn ended).
The transcript is read by internal/transcript (Claude and Codex); the feed only reads its timeline entries, through Source, so a test gives it files from testdata.
Index ¶
- Constants
- func CommandLine(name, args string) string
- type AntigravitySource
- func (s *AntigravitySource) AtRest() bool
- func (s *AntigravitySource) Before(before int64, max int) transcript.Chunk
- func (s *AntigravitySource) Close()
- func (s *AntigravitySource) Seat(offset int64)
- func (s *AntigravitySource) Since() transcript.Incremental
- func (s *AntigravitySource) Tail(max int) transcript.Chunk
- type ClaudeSource
- func (s *ClaudeSource) AtRest() bool
- func (s *ClaudeSource) Before(beforeByte int64, max int) transcript.Chunk
- func (s *ClaudeSource) BeforeWindow(beforeByte, window int64, max int) transcript.Chunk
- func (s *ClaudeSource) Close()
- func (s *ClaudeSource) Seat(offset int64)
- func (s *ClaudeSource) Since() transcript.Incremental
- func (s *ClaudeSource) Tail(max int) transcript.Chunk
- func (s *ClaudeSource) TailWindow(window int64, max int) transcript.Chunk
- type CodexSource
- type Feed
- func (f *Feed) After(entryID string) (ts []wire.Turn, es []wire.Entry, ok bool)
- func (f *Feed) Close()
- func (f *Feed) Context() int64
- func (f *Feed) Delivered(p string) (string, bool)
- func (f *Feed) EndTurn(id string, st wire.TurnStatus, failure *wire.TurnFailure, at wire.Ms) (wire.Turn, bool)
- func (f *Feed) Entry(id string) (wire.Entry, bool)
- func (f *Feed) ErrorEnd(id string) (string, bool)
- func (f *Feed) FindUser(offset int64, at wire.Ms) (string, bool)
- func (f *Feed) FindUserText(offset int64, at wire.Ms, text string) (string, bool)
- func (f *Feed) From(turnID string, limit int) (wire.TurnsPage, bool)
- func (f *Feed) Held(fn func(wire.Entry)) bool
- func (f *Feed) LastTurn() *wire.Turn
- func (f *Feed) Late() bool
- func (f *Feed) LimitEnd(id string) (Limit, string, bool)
- func (f *Feed) Load() Update
- func (f *Feed) Messages(fn func(wire.Entry))
- func (f *Feed) Model() string
- func (f *Feed) Now(word string, at wire.Ms) *wire.Now
- func (f *Feed) OnVendor()
- func (f *Feed) OpenTurn() string
- func (f *Feed) Output(entryID string) (wire.OutputPage, bool)
- func (f *Feed) PendingTool() (wire.Entry, bool)
- func (f *Feed) Poll() Update
- func (f *Feed) Records() []wire.Turn
- func (f *Feed) Refail(id string, failure *wire.TurnFailure) (wire.Turn, bool)
- func (f *Feed) Release() bool
- func (f *Feed) Released() bool
- func (f *Feed) Restore(s Saved) bool
- func (f *Feed) Resume(id string) (wire.Turn, bool)
- func (f *Feed) RewindPoint(turnID string) (Point, bool)
- func (f *Feed) Save() (Saved, bool)
- func (f *Feed) SetClientID(entryID, clientID string) (wire.Entry, bool)
- func (f *Feed) Size() int64
- func (f *Feed) Snapshot(turns int) (ts []wire.Turn, es []wire.Entry, before *string)
- func (f *Feed) Snippet(t wire.Turn) string
- func (f *Feed) Sources() []*jsvalue.Object
- func (f *Feed) Tasks() []wire.Task
- func (f *Feed) Touched(p string) bool
- func (f *Feed) Turn(id string) (wire.Turn, bool)
- func (f *Feed) TurnEntries(turnID string) (wire.EntriesPage, bool)
- func (f *Feed) Turns(before string, limit int) (wire.TurnsPage, bool)
- func (f *Feed) TurnsWithSteps(before string, limit int) (wire.TurnsPage, bool)
- func (f *Feed) Uses() int
- type Limit
- type NowThrottle
- type Point
- type Saved
- type SavedEnd
- type Signal
- type SignalKind
- type Source
- type Update
- type WholeTurn
Constants ¶
const NowEvery = 500 * time.Millisecond
NowEvery is how often "now" may go to a conversation's subscribers: at most twice a second.
const ShellCommand = "!"
ShellCommand is the name the transcript gives a bash-mode line («! cmd»).
const TailBytes = 4 << 20
TailBytes is how much of a transcript read by bytes the first read takes from its end, and each read of older bytes before what the feed holds; a window that holds fewer than TailTurns turns is doubled until it does.
const TailEntries = 2000
TailEntries is how many timeline entries the first read takes from the end at most; older ones come page by page.
const TailTurns = 4
TailTurns is how many turns the first read wants whole: the last three a snapshot holds with their steps, and one more, so the newest turns are never cut at their start.
Variables ¶
This section is empty.
Functions ¶
func CommandLine ¶ added in v0.16.15
CommandLine is a command as the person types it: «/name args», or «! args» for a bash-mode line.
Types ¶
type AntigravitySource ¶
type AntigravitySource struct {
Root string
Path string
Index *transcriptindex.Index
// contains filtered or unexported fields
}
AntigravitySource reads the native brain/<uuid>/.system_generated/logs/transcript.jsonl. DONE belongs to one native step, never to the conversation's turn.
func (*AntigravitySource) AtRest ¶
func (s *AntigravitySource) AtRest() bool
func (*AntigravitySource) Before ¶
func (s *AntigravitySource) Before(before int64, max int) transcript.Chunk
func (*AntigravitySource) Close ¶
func (s *AntigravitySource) Close()
func (*AntigravitySource) Seat ¶
func (s *AntigravitySource) Seat(offset int64)
func (*AntigravitySource) Since ¶
func (s *AntigravitySource) Since() transcript.Incremental
func (*AntigravitySource) Tail ¶
func (s *AntigravitySource) Tail(max int) transcript.Chunk
type ClaudeSource ¶
type ClaudeSource struct {
Path string
// Index, when set, reads what the transcript gains for the source and for the transcript's other readers at once;
// nil has the source read the file itself.
Index *transcriptindex.Index
// contains filtered or unexported fields
}
ClaudeSource reads a Claude Code transcript.
func (*ClaudeSource) AtRest ¶
func (s *ClaudeSource) AtRest() bool
AtRest says a read that starts at the source's place with nothing held reads what this one would.
func (*ClaudeSource) Before ¶
func (s *ClaudeSource) Before(beforeByte int64, max int) transcript.Chunk
func (*ClaudeSource) BeforeWindow ¶
func (s *ClaudeSource) BeforeWindow(beforeByte, window int64, max int) transcript.Chunk
func (*ClaudeSource) Close ¶
func (s *ClaudeSource) Close()
Close lets go of the source's place in the index: the transcript is not read for it any more. A later read of the source takes a place again.
func (*ClaudeSource) Seat ¶
func (s *ClaudeSource) Seat(offset int64)
Seat makes Since go on from offset with nothing held.
func (*ClaudeSource) Since ¶
func (s *ClaudeSource) Since() transcript.Incremental
func (*ClaudeSource) Tail ¶
func (s *ClaudeSource) Tail(max int) transcript.Chunk
func (*ClaudeSource) TailWindow ¶
func (s *ClaudeSource) TailWindow(window int64, max int) transcript.Chunk
type CodexSource ¶
type CodexSource struct {
Path string
// Index, when set, reads what the transcript gains for the source and for the transcript's other readers at once;
// nil has the source read the file itself.
Index *transcriptindex.Index
// contains filtered or unexported fields
}
CodexSource reads a Codex transcript.
func (*CodexSource) AtRest ¶
func (s *CodexSource) AtRest() bool
func (*CodexSource) Before ¶
func (s *CodexSource) Before(beforeByte int64, max int) transcript.Chunk
func (*CodexSource) Close ¶
func (s *CodexSource) Close()
Close lets go of the source's place in the index.
func (*CodexSource) Seat ¶
func (s *CodexSource) Seat(offset int64)
func (*CodexSource) Since ¶
func (s *CodexSource) Since() transcript.Incremental
func (*CodexSource) Tail ¶
func (s *CodexSource) Tail(max int) transcript.Chunk
type Feed ¶
type Feed struct {
// contains filtered or unexported fields
}
Feed is one conversation's feed. Not safe for concurrent use: the conversation's actor owns it.
func Everything ¶ added in v0.15.46
Everything is a feed that reads a transcript of size bytes whole, in one read: for what wants all the messages of a conversation (the search index), not for a page of turns.
func (*Feed) After ¶
After is what follows an entry: the entries after it, and every turn from the entry's own on, as they are now. The turns go along whether or not an entry after the cursor touches them: a page that had the chat from elsewhere (the cluster's copy) saw the entry's turn running, and has to learn that it ended, or that a new turn began with nothing in it yet. ok is false when the feed does not have the entry.
func (*Feed) Close ¶
func (f *Feed) Close()
Close lets go of what the feed's source holds outside the feed (its place in the transcript index). The feed stays usable: its next read takes a place again.
func (*Feed) Context ¶
Context is the tokens the agent's last answer was asked with, 0 when its transcript does not say.
func (*Feed) Delivered ¶ added in v0.16.86
Delivered is the sha256 the agent's latest hand-over of the file at this path vouched for (deliver_file's card).
func (*Feed) EndTurn ¶
func (f *Feed) EndTurn(id string, st wire.TurnStatus, failure *wire.TurnFailure, at wire.Ms) (wire.Turn, bool)
EndTurn ends a turn the transcript left open (a stop hook ahead of its line, a failure, an interrupt): the record as it is now. Ending one already ended changes nothing, but a failure the transcript ended as done.
func (*Feed) ErrorEnd ¶
ErrorEnd is the error a turn ends on ("" the open one): its last line is the agent's own error notice (a call to its model refused: the login expired, the service failed). A turn that stops on it answered nothing, it failed.
func (*Feed) FindUser ¶
FindUser is the first user entry whose line is at or after offset, or (an entry read before its offset was known) written at or after at: the message typed then.
func (*Feed) FindUserText ¶
FindUserText is FindUser for one message: the first user entry at or after offset (or written at or after at) that carries its text, or its start when Claude cut the paste short, or holds it among the messages Claude read at once. An entry of someone else — the person typing into the terminal, another tool — is never taken for it.
func (*Feed) From ¶
From is the turns from turnID to the end, by their faces (the message that opened each and its answer), at most limit of the newest; ok false when the transcript has no such turn.
func (*Feed) Held ¶
Held is Messages over what the feed holds now, without reading a released feed again or counting a use: a look the actor makes by itself on the clock must not keep an idle chat's transcript in memory. False when released.
func (*Feed) Late ¶
Late: the runtime ended a turn ahead of its transcript (the stop hook came before the agent's last lines, its answer among them), and the transcript has not ended it yet.
func (*Feed) LimitEnd ¶
LimitEnd is the usage limit a turn ends on ("" the open one): its last entry is the agent's notice of the limit. The notice's words come with it.
func (*Feed) Load ¶
Load reads the transcript's tail. Its signals are the state of the transcript as it is now (an open question, an open turn): the caller weighs them as a look at the past, not as news.
A windowed source is read from its end by bytes: the window doubles until it holds TailTurns turns, TailEntries entries or the whole file, so the newest turns are there at once however large the transcript is.
func (*Feed) Messages ¶
Messages calls fn with each of the person's messages and the agent's answers (user and say entries), oldest first.
func (*Feed) Model ¶
Model is the model the agent last answered with, "" when its transcript does not say.
func (*Feed) Now ¶
Now is what the agent does in the open turn this moment: its latest thought, the tool call still running, the live reply off the screen (word, "" none). Nil outside a turn.
func (*Feed) OnVendor ¶ added in v0.15.46
func (f *Feed) OnVendor()
OnVendor says the chat runs on a backend profile: a usage limit is read off the vendor's words only.
func (*Feed) Output ¶
func (f *Feed) Output(entryID string) (wire.OutputPage, bool)
Output is the whole output of a tool entry.
func (*Feed) PendingTool ¶
PendingTool is the open turn's latest tool call still without its result: the call a permission prompt is about.
func (*Feed) Poll ¶
Poll reads what the transcript gained since the last read. The entries' offset is where the read began: their lines start there or later.
func (*Feed) Refail ¶
Refail names again why a failed turn failed: its last lines came after it ended (Claude fires StopFailure before its refusal is on the transcript). The record as it is now; false when the turn did not fail.
func (*Feed) Release ¶
Release lets go of the entries read, keeping where the read stood; false while a turn is open (the actor reads the open turn on every look), before the first read, or when already released.
func (*Feed) Restore ¶
Restore makes a feed that read nothing yet stand where the saved one stood, released; false when its source cannot go on from a place written down. The caller knows the transcript is the one the feed was saved over, unchanged.
func (*Feed) Resume ¶
Resume opens again a turn the runtime ended on silence that the transcript has not ended: the agent was working all along (its spinner off the screen) and writes on. The record as it is now; false when it is not that turn.
func (*Feed) RewindPoint ¶
RewindPoint is the turn turnID as a rewind's point; ok false when the transcript has no such turn or a person's message did not open it. Older turns than the feed holds are read until it is found.
func (*Feed) Save ¶
Save is the feed as Restore takes it; false when the feed is not at rest: nothing read yet, a turn open, a source that cannot go on from a place written down, or one holding a line half read.
func (*Feed) SetClientID ¶
SetClientID marks a user entry as the page's message.
func (*Feed) Size ¶
Size is how far the transcript is read: an entry written after it is newer than anything the feed has.
func (*Feed) Snapshot ¶
Snapshot is the last turns as a conv snapshot holds them: up to turns full records, oldest first, the steps of the last three and the answer entry of each older one; before is the cursor for older turns.
func (*Feed) Sources ¶
Sources are the source entries the feed holds, oldest first: what its reads took, for what starts to be gathered beside the feed after them. Nothing is read from the transcript beyond what a released feed takes back.
func (*Feed) Tasks ¶
Tasks is the agent's task list as the entries read so far make it, in the order the tasks were made.
func (*Feed) Touched ¶
Touched is whether a turn of the feed wrote, edited or read the file at this path, as the transcript names it.
func (*Feed) TurnEntries ¶
func (f *Feed) TurnEntries(turnID string) (wire.EntriesPage, bool)
TurnEntries is every entry of one turn.
func (*Feed) Turns ¶
Turns is the page of turns before a turn ("" from the end), at most limit, oldest first, with their answer entries. Older turns than the feed holds are read from the transcript first: a turn named that the feed does not hold now (a cursor kept from before the runtime restarted, older than the tail it read) is looked for there too, so a walk through the chat goes on from where it stopped.
func (*Feed) TurnsWithSteps ¶
TurnsWithSteps is the page Turns gives with the steps of every turn in it, not only of the newest: what the cluster's copy is backfilled from, so a folded turn opens from the copy too.
type Limit ¶
type Limit struct {
Window wire.LimitWindow
ResetsAt wire.Ms
}
Limit is a usage limit of the agent's plan that a notice of its transcript says it hit: which window and when it resets (0 when the notice names no time).
func ClaudeLimitText ¶
ClaudeLimitText reads Claude Code's words of a usage limit hit at when: which window, and the reset it names.
func CodexLimitText ¶
CodexLimitText is the limit Codex's words of it name, seen at when (Codex prints the machine's time).
func VendorLimitText ¶ added in v0.15.46
VendorLimitText reads the usage limit a backend profile's vendor names (GLM, Kimi): which window and the reset, when it names one. Claude's words are not read here: a vendor's text never counts as a limit of the Anthropic plan.
type NowThrottle ¶
type NowThrottle struct {
// contains filtered or unexported fields
}
NowThrottle lets "now" out at most once per NowEvery: a change inside the window waits for its end, and only the latest one goes; the same "now" again goes nowhere.
func (*NowThrottle) Due ¶
func (t *NowThrottle) Due(now time.Time) *wire.NowEv
Due is the "now" kept back, when its window has passed.
func (*NowThrottle) Offer ¶
Offer is a fresh "now": the event to publish at once, or nil when it waits for Wake.
func (*NowThrottle) Reset ¶
func (t *NowThrottle) Reset()
Reset forgets what went: the next "now" goes at once (a turn ended, a new one starts).
func (*NowThrottle) Wake ¶
func (t *NowThrottle) Wake() time.Time
Wake is when Due has something to let out, zero when nothing waits.
type Point ¶
type Point struct {
// Turns is how many turns the rewind leaves behind: this one and every one after it.
Turns int
// After is the last turn kept (nil: none the feed read), and its end (nil: it has not ended).
After *string
AfterEnd *wire.Ms
// At is when the message was written.
At wire.Ms
}
Point is a turn a rewind goes back to: the turn the person's message opened, and what the rewind leaves behind.
type Saved ¶
type Saved struct {
Start int64 `json:"start"`
Size int64 `json:"size"`
More bool `json:"more,omitempty"`
LastTurn *wire.Turn `json:"lastTurn,omitempty"`
Snippet string `json:"snippet,omitempty"`
Context int64 `json:"context,omitempty"`
Model string `json:"model,omitempty"`
Tasks []wire.Task `json:"tasks,omitempty"`
Revs map[string]int64 `json:"revs,omitempty"`
Clients map[string]string `json:"clients,omitempty"`
Ends map[string]SavedEnd `json:"ends,omitempty"`
}
Saved is a feed at rest written down: what a released feed keeps, and what the runtime set on the feed beyond the transcript. A feed made again over the same transcript takes it (Restore) and stands where the saved one stood without reading a byte; the first read of its entries reads the same bytes of the transcript the saved one held.
type SavedEnd ¶
type SavedEnd struct {
Status wire.TurnStatus `json:"status"`
Failure *wire.TurnFailure `json:"failure,omitempty"`
At wire.Ms `json:"at"`
}
SavedEnd is the end the runtime gave a turn the transcript left open.
type Signal ¶
type Signal struct {
K SignalKind
EntryID string
TurnID string
GateID string
Offset int64
At wire.Ms
Question *wire.Question
Permission *wire.Permission
Failure string
Detail string
// Text is the line a user signal stands for when its entry is not a user message (a command: «/compact», «! ls»).
Text string
}
Signal is one such thing; Offset is a lower bound of where its line starts (-1 unknown).
type SignalKind ¶
type SignalKind string
SignalKind is what an entry tells the conversation's actor beyond the feed: the agent asks, a gate resolved, a user entry the outbox may own.
const ( SignalUser SignalKind = "user" // a user entry: maybe the message on its way SignalTurnOpened SignalKind = "turn-opened" // a user entry (or a task's notification between turns) opened a turn SignalTurnEnded SignalKind = "turn-ended" // the transcript's end of a turn SignalQuestion SignalKind = "question" // an AskUserQuestion without its answer SignalPlan SignalKind = "plan" // ExitPlanMode waiting for approval SignalPermission SignalKind = "permission" // Codex asks to approve a command or a patch SignalGateResolved SignalKind = "gate-resolved" // the tool result of a question, a plan or an approval SignalInterrupt SignalKind = "interrupt" // the transcript shows the turn interrupted SignalFailure SignalKind = "terminal-failure" // a non-retryable provider failure: the current turn must stop )
type Source ¶
type Source interface {
// Tail is the last max entries; it sets where Since goes on from.
Tail(max int) transcript.Chunk
// Before is up to max entries that end before the byte.
Before(beforeByte int64, max int) transcript.Chunk
// Since is what the transcript gained after the last read.
Since() transcript.Incremental
}
Source reads one transcript.
type Update ¶
type Update struct {
// Steps are the new entries in order, each with its turn's counters after it.
Steps []wire.StepEv
// Updated are entries changed in place (rev+1).
Updated []wire.Entry
// Started and Ended are the turns that opened and ended, as their records are now.
Started []wire.Turn
Ended []wire.Turn
Signals []Signal
// Events are all of the above as the conversation's channel takes them, in the transcript's order: turn_started,
// step, entry_update, and turn_finished of a turn the transcript ended.
Events []wire.Event
// Read are the source entries the read took, in the transcript's order, for what is gathered from the same read
// beside the feed. Whole says they are all the feed holds now (a first read, a transcript read anew), not what
// it gained.
Read []*jsvalue.Object
Whole bool
}
Update is what a read added to the feed.