feed

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 23 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 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

View Source
const NowEvery = 500 * time.Millisecond

NowEvery is how often "now" may go to a conversation's subscribers: at most twice a second.

View Source
const ShellCommand = "!"

ShellCommand is the name the transcript gives a bash-mode line («! cmd»).

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

View Source
const TailEntries = 2000

TailEntries is how many timeline entries the first read takes from the end at most; older ones come page by page.

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

func CommandLine(name, args string) string

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 (*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

func Everything(conv string, provider wire.Provider, src Source, size int64) *Feed

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 New

func New(conv string, provider wire.Provider, src Source) *Feed

New is the feed of a conversation over its transcript source.

func (*Feed) After

func (f *Feed) After(entryID string) (ts []wire.Turn, es []wire.Entry, ok bool)

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

func (f *Feed) Context() int64

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

func (f *Feed) Delivered(p string) (string, bool)

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) Entry

func (f *Feed) Entry(id string) (wire.Entry, bool)

Entry is one entry by its id.

func (*Feed) ErrorEnd

func (f *Feed) ErrorEnd(id string) (string, bool)

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

func (f *Feed) FindUser(offset int64, at wire.Ms) (string, bool)

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

func (f *Feed) FindUserText(offset int64, at wire.Ms, text string) (string, bool)

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

func (f *Feed) From(turnID string, limit int) (wire.TurnsPage, bool)

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

func (f *Feed) Held(fn func(wire.Entry)) bool

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) LastTurn

func (f *Feed) LastTurn() *wire.Turn

LastTurn is the newest turn's record, nil before any.

func (*Feed) Late

func (f *Feed) Late() bool

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

func (f *Feed) LimitEnd(id string) (Limit, string, bool)

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

func (f *Feed) Load() Update

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

func (f *Feed) Messages(fn func(wire.Entry))

Messages calls fn with each of the person's messages and the agent's answers (user and say entries), oldest first.

func (*Feed) Model

func (f *Feed) Model() string

Model is the model the agent last answered with, "" when its transcript does not say.

func (*Feed) Now

func (f *Feed) Now(word string, at wire.Ms) *wire.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) OpenTurn

func (f *Feed) OpenTurn() string

OpenTurn is the turn still running in the transcript, "" none.

func (*Feed) Output

func (f *Feed) Output(entryID string) (wire.OutputPage, bool)

Output is the whole output of a tool entry.

func (*Feed) PendingTool

func (f *Feed) PendingTool() (wire.Entry, bool)

PendingTool is the open turn's latest tool call still without its result: the call a permission prompt is about.

func (*Feed) Poll

func (f *Feed) Poll() Update

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) Records

func (f *Feed) Records() []wire.Turn

Records are the records of the turns the feed holds, oldest first.

func (*Feed) Refail

func (f *Feed) Refail(id string, failure *wire.TurnFailure) (wire.Turn, bool)

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

func (f *Feed) Release() bool

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) Released

func (f *Feed) Released() bool

Released says whether the feed holds nothing read now.

func (*Feed) Restore

func (f *Feed) Restore(s Saved) bool

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

func (f *Feed) Resume(id string) (wire.Turn, bool)

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

func (f *Feed) RewindPoint(turnID string) (Point, bool)

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

func (f *Feed) Save() (Saved, bool)

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

func (f *Feed) SetClientID(entryID, clientID string) (wire.Entry, bool)

SetClientID marks a user entry as the page's message.

func (*Feed) Size

func (f *Feed) Size() int64

Size is how far the transcript is read: an entry written after it is newer than anything the feed has.

func (*Feed) Snapshot

func (f *Feed) Snapshot(turns int) (ts []wire.Turn, es []wire.Entry, before *string)

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) Snippet

func (f *Feed) Snippet(t wire.Turn) string

Snippet is the first SnippetMax characters of a turn's answer.

func (*Feed) Sources

func (f *Feed) Sources() []*jsvalue.Object

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

func (f *Feed) Tasks() []wire.Task

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

func (f *Feed) Touched(p string) bool

Touched is whether a turn of the feed wrote, edited or read the file at this path, as the transcript names it.

func (*Feed) Turn

func (f *Feed) Turn(id string) (wire.Turn, bool)

Turn is a turn's record by its id.

func (*Feed) TurnEntries

func (f *Feed) TurnEntries(turnID string) (wire.EntriesPage, bool)

TurnEntries is every entry of one turn.

func (*Feed) Turns

func (f *Feed) Turns(before string, limit int) (wire.TurnsPage, bool)

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

func (f *Feed) TurnsWithSteps(before string, limit int) (wire.TurnsPage, bool)

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.

func (*Feed) Uses

func (f *Feed) Uses() int

Uses counts the reads of the feed beyond the summary a look asks for: a caller that sees it unchanged for a while knows nobody reads the feed.

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

func ClaudeLimitText(message string, when time.Time) (Limit, bool)

ClaudeLimitText reads Claude Code's words of a usage limit hit at when: which window, and the reset it names.

func CodexLimitText

func CodexLimitText(message string, when time.Time) Limit

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

func VendorLimitText(message string, _ time.Time) (Limit, bool)

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

func (t *NowThrottle) Offer(n *wire.Now, now time.Time) *wire.NowEv

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.

type WholeTurn

type WholeTurn struct {
	Turn    wire.Turn
	Entries []wire.Entry
}

WholeTurn is one turn of a whole transcript with every entry it holds, in order: what opened it first.

func Whole

func Whole(conv string, provider wire.Provider, src Source) []WholeTurn

Whole is every turn of a transcript, oldest first, read from its start: what a handoff takes its excerpt from and what a fork finds its cut in. The live feed of the conversation is not touched.

Jump to

Keyboard shortcuts

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