Documentation
¶
Overview ¶
Package transcriptindex reads what an agent's transcript gains once for everything that follows it. A transcript is one append-only file of JSON lines, and several parts of the runtime follow each: the conversation's feed, its background work, what the session says about itself. Each used to keep a cursor of its own, open the file and decode the same lines again. The index keeps one cursor per file: a look stats the file, reads the bytes it gained in bounded blocks, cuts them into whole lines, and hands each block to the file's subscribers while it is held. A line is decoded as JSON at most once, into the few fields the subscribers read (Fields), whoever asks first.
The index holds nothing of a transcript: no line outlives the look that read it. A file is known only while it has subscribers, so a conversation that let go of its transcript (parked, deleted) costs the index nothing, and its file is never opened. The index reads no history: a subscriber reads its own start (a tail, a page of the past) and seats itself where that read ended; from there on the lines come from the index. A subscriber the index cannot serve in order — it could not take a block (a full Queue), the file was replaced or cut, its place is not one the index reads from — is lost: it reads from its own place itself and seats again. A loss is counted and logged.
The index is driven by its subscribers' looks (Sync), not by a clock of its own: a look is a stat, and a look shortly after another subscriber's takes that one's word.
Index ¶
Constants ¶
const ( // DefaultFollowBytes is how much of a transcript a Follower holds for its reader. DefaultFollowBytes = 64 << 10 // DefaultFollowIdle is for how long a Follower holds lines for a reader that does not come for them. DefaultFollowIdle = 2 * time.Minute )
const ( // DefaultBlock is how many bytes of a transcript one read takes; a longer line is read whole. DefaultBlock = 1 << 20 // DefaultFresh is for how long a look that found a file as it was answers the other subscribers' looks at it. DefaultFresh = 500 * time.Millisecond )
const DefaultQueueBytes = 1 << 20
DefaultQueueBytes is how much of a transcript a Queue holds for its reader.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch struct {
Path string
// From is the start of the first line and To the end of the last, its newline included.
From, To int64
// contains filtered or unexported fields
}
Batch is the whole lines a transcript gained from a subscriber's place on. Valid only while the Sink is called.
type Counters ¶
type Counters struct {
Files int // transcripts with a subscriber
Subs int // subscriptions
// Looks counts the stats of transcripts, Opens the times a transcript was opened to read what it gained, Bytes
// what was read; all since the runtime started.
Looks, Opens, Bytes int64
// Overflows counts the subscribers lost because they could not take a batch; Gaps, those whose place the index
// could not read from; Resets, the files found replaced, cut or gone.
Overflows, Gaps, Resets int64
}
Counters are the index's own numbers.
type Fields ¶
type Fields struct {
Type string `json:"type"`
Subtype string `json:"subtype"`
Operation string `json:"operation"`
Timestamp any `json:"timestamp"`
IsSidechain any `json:"isSidechain"`
QuerySource string `json:"querySource"`
Cwd string `json:"cwd"`
Content any `json:"content"`
AITitle string `json:"aiTitle"`
CustomTitle string `json:"customTitle"`
Message struct {
Content any `json:"content"`
} `json:"message"`
Params struct {
OutputConfig struct {
Effort string `json:"effort"`
} `json:"output_config"`
} `json:"params"`
Attachment struct {
Type string `json:"type"`
Met bool `json:"met"`
Condition string `json:"condition"`
HookName string `json:"hookName"`
} `json:"attachment"`
}
Fields is what a transcript line says, as far as the index's subscribers read it: one decode serves them all.
type Follower ¶
type Follower struct {
// contains filtered or unexported fields
}
Follower serves a reader that reads transcripts when asked, not on a clock: a list of sessions, a count of messages, a page of costs. Such a reader keeps a cursor of its own in many files, most of them at rest. For the files the index follows anyway (a conversation is live on them) the Follower holds the lines the index reads, so the reader does not open those files again; it never makes the index follow a file, and ends with the file's last other subscriber. For every other file, and whenever Take says no, the reader reads the file itself as it always did and tells the Follower where it stands (Seat).
What a Follower holds is bounded twice: by bytes per file (lines that do not fit are not kept and the place is given up) and by time (a reader that has not come for DefaultFollowIdle holds nothing until it comes again). Giving a place up is the ordinary course for such a reader, not a loss: it is neither counted nor logged. A nil Follower serves nothing: every Take says no.
func (*Follower) Seat ¶
Seat says the reader has read the transcript up to offset, the start of a line, itself. A transcript the index does not follow is not followed for the reader's sake.
func (*Follower) Take ¶
Take gives the whole lines the transcript gained after offset, the reader's own place: data is the reader's to keep. partial says a line is still being written after them. ok is false when the Follower cannot say what the file gained after offset: the reader reads the file itself and seats again. With ok and no data and no partial the file is as the reader left it.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is the shared reader. Safe for concurrent use.
func (*Index) Follower ¶
Follower is a follower for the reader called name that holds max bytes per file (DefaultFollowBytes when 0). On a nil index it is nil.
type Line ¶
type Line struct {
// Offset is where the line starts in the file, End where the next one does.
Offset, End int64
Raw []byte
// contains filtered or unexported fields
}
Line is one line of a transcript, without its newline. Valid only while the Sink is called.
type Options ¶
type Options struct {
// Block is how many bytes one read takes (DefaultBlock).
Block int
// Fresh is for how long a look answers the other subscribers' unforced looks (DefaultFresh); negative: never.
Fresh time.Duration
// Warn logs a subscriber lost; nil logs nothing.
Warn func(msg string, kv ...any)
// Now is the clock; nil is time.Now.
Now func() time.Time
}
Options are the index's settings; the zero value is the defaults.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue is a subscriber that reads on its own goroutine, in its own time: the lines the transcript gained wait in it, as they are in the file, until it takes them. It holds max bytes at most: lines that do not fit are not kept, the queue is lost, and its reader reads the file from its own place.
func (*Queue) Close ¶
func (q *Queue) Close()
Close ends the queue's subscription and drops what it holds.
func (*Queue) Lines ¶
Lines keeps a copy of the batch for the reader, or nothing at all when it does not fit.
func (*Queue) Take ¶
Take looks at the file and gives the reader the whole lines it gained since the reader's place: data starts at byte from of the file and is the reader's to keep. partial says a line is still being written after them. Anything but Fresh gives no lines: the reader reads from its own place and seats again.
type Sink ¶
Sink takes the whole lines a transcript gained, in order, on the goroutine of whoever looked. The batch and everything reached through it are valid only during the call. It must be quick: the file's other subscribers wait for it. false says the batch could not be taken: the subscriber is lost from here on.
type Sub ¶
type Sub struct {
// contains filtered or unexported fields
}
Sub is one subscriber's place in one transcript.
func (*Sub) Close ¶
func (s *Sub) Close()
Close ends the subscription. A file without subscribers is forgotten whole.
func (*Sub) Closed ¶
Closed says the subscription has ended: by Close, or with the file's last subscriber that kept it.
func (*Sub) Seat ¶
Seat says the subscriber has read the file up to offset, the start of a line, itself: the lines from there on are the index's to hand over. ino is the inode of the file the subscriber read, 0 when it does not know.
func (*Sub) Sync ¶
Sync looks at the file for the subscriber: what it gained is read and handed to every subscriber in order. force makes the look a stat of its own; without it a look another subscriber made within Options.Fresh answers. partial says the file ends in a line still being written past the subscriber's place.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package indextest helps a reader's tests hold that it says the same of a transcript whether it reads the file itself or takes the lines from the shared read: two copies of one made-up transcript grow by the same writes, one of them followed by the index as a live conversation's transcript is.
|
Package indextest helps a reader's tests hold that it says the same of a transcript whether it reads the file itself or takes the lines from the shared read: two copies of one made-up transcript grow by the same writes, one of them followed by the index as a live conversation's transcript is. |
|
Package tally counts what reading transcripts costs the process: the files opened, the bytes read off them, the stats and the lines decoded as JSON.
|
Package tally counts what reading transcripts costs the process: the files opened, the bytes read off them, the stats and the lines decoded as JSON. |