transcript

package
v0.261.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 15 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 transcript forwards an officer instance's LIVE session transcript to HQ while the instance holds a claimed item (docs/officers.md, "Transcript to HQ"), so HQ's officer pages can show what the officer is doing.

THE SOURCE is the instance's own Claude Code transcript — the structured JSONL the CLI writes, decoded by internal/cctranscript exactly as every other reader of a session decodes it — served incrementally by the instance pod's ccd on GET /v1/transcript (cmd/ccd/transcript_route.go). Never the screen.

THE SINK is HQ's POST /officers/{id}/items/{item}/transcript, sent with the officer's own token by officers.Client (the token never leaves it).

🔴 EVERY TEXT IS REDACTED BEFORE IT LEAVES: the officer's own token is replaced (officers.Client.Scrub — a shape filter cannot know an opaque token), then the CI-log secret filter (officership.RedactText, the same RedactLines officer_ci_logs uses) withholds every line that looks like it carries a credential, then the text is cut to the contract's 8 KiB with a marker. Transcript text is never logged.

🔴 THE SEQ IS A FUNCTION OF THE TRANSCRIPT POSITION, NOT OF MEMORY (Seq): the end offset of the event's line in the transcript file times 32768, plus the event's index within that line. It strictly increases along the file, so a restarted muster derives the SAME seq for the same event, and HQ's idempotency rule (a seq at or below its highest stored is skipped) turns a resume's re-read into no duplicates. A resume re-reads a backfill window (Config.Backfill) of the transcript, so events written while muster was down are sent too, as long as they fit in it. It stays below 2^53 for any file under 256 GiB, so it survives a JSON reader that parses numbers as doubles.

The one case the file position cannot order is a NEW CONVERSATION mid-item (a new transcript file, offsets from zero — ccd resumes the primary's own conversation by id, so this is an operator's /clear, not a restart). A forwarder that sees it shifts every later seq above the highest it had (worker.shift). A forwarder that restarted INTO such a file has lost the shift; HQ then answers stored 0 with a last_seq above a batch read LIVE (past the resume's re-read, so it cannot be a duplicate), and the forwarder re-sequences that batch and every later one above it (heal). What that case can lose is the part of the resume's re-read HQ skipped as old.

🔴 IT NEVER BLOCKS THE OFFICER. Claimed, Ended and Sync — called from the officer tools and the wake loop — only record state under a mutex; every read and post runs on the forwarder's own loop (Run → Tick). An instance's buffer is capped (Config.MaxBuffer): past it the OLDEST events are dropped and counted (muster_officer_transcript_events_total{result="dropped_buffer"}), never held without bound.

Index

Constants

View Source
const (
	DefaultInterval        = 2 * time.Second
	DefaultMaxBuffer       = 1000
	DefaultMaxRetries      = 5
	DefaultMaxBackoff      = time.Minute
	DefaultBackfill        = 256 << 10
	DefaultMaxPostsPerTick = 10
	DefaultRequestTimeout  = 15 * time.Second
)

Defaults.

View Source
const ClaimSlack = 5 * time.Second

ClaimSlack is how far before a claim's own time its first read reaches: the pod's clock and muster's can differ, and the officer_claim call itself (the tool_use, written just before the claim) belongs to the item.

Variables

This section is empty.

Functions

func Seq

func Seq(end int64, idx int) (int64, bool)

Seq is the seq of the idx'th event of the line ending at end, or false when none exists (an index past 32767, an offset past 256 GiB).

func Truncate

func Truncate(s string, n int) string

Truncate cuts s to at most n bytes on a character boundary, ending it with "… [truncated N bytes]" (N the bytes removed) when it cuts.

Types

type Config

type Config struct {
	Source Source
	Poster Poster
	Logger *log.Logger
	Now    func() time.Time
	// Interval is the cadence: how often each instance's transcript is read
	// and its new events posted.
	Interval time.Duration
	// MaxBuffer caps one instance's events read but not yet accepted by HQ.
	MaxBuffer int
	// MaxRetries is how many times one batch is re-sent after an HQ outage
	// (5xx, 429, no answer) before it is dropped (counted).
	MaxRetries int
	// MaxBackoff caps the wait between re-sends (Interval doubled per failure).
	MaxBackoff time.Duration
	// Backfill is the window, in bytes, a RESUME (a held item muster was not
	// forwarding — after a restart) re-reads from the end of the transcript.
	Backfill int
	// MaxPostsPerTick bounds one instance's posts per tick.
	MaxPostsPerTick int
	// RequestTimeout bounds one read or post.
	RequestTimeout time.Duration
}

Config is New's input. Zero values take the defaults.

type Forwarder

type Forwarder struct {
	// contains filtered or unexported fields
}

Forwarder is the transcript forwarder: one worker per officer instance that holds a claimed item of a transcript-enabled officer.

func New

func New(cfg Config) (*Forwarder, error)

New builds a forwarder.

func (*Forwarder) Active

func (f *Forwarder) Active() map[string]officers.ItemID

Active is each forwarding instance's item.

func (*Forwarder) Claimed

func (f *Forwarder) Claimed(o officers.Officer, instance string, item officers.ItemID)

Claimed is officer_claim succeeding: instance now holds item. Forwarding starts AT THE CLAIM: the first read takes the transcript's backfill window and keeps only the lines written since the claim (less ClaimSlack) — what the instance does from the claim on is the item's, and nothing written between the claim and the forwarder's next tick is lost. An instance already forwarding another item switches to this one, keeping its place in the transcript.

An untimed line in that first read cannot be shown to follow the claim and is not sent.

func (*Forwarder) Ended

func (f *Forwarder) Ended(o officers.Officer, instance string, item officers.ItemID)

Ended is officer_complete or officer_release succeeding: the item is no longer the instance's, and forwarding for it stops.

func (*Forwarder) Run

func (f *Forwarder) Run(ctx context.Context)

Run ticks every Interval until ctx ends.

func (*Forwarder) Sync

func (f *Forwarder) Sync(o officers.Officer, claimed []officers.Item, at time.Time)

Sync is one wake-loop pass's view of o's claimed items, read at at: every item one of o's instances holds under a live lease is forwarded (a RESUME, from the backfill window, when muster was not forwarding it — after a restart), and forwarding stops for an item no instance of o holds any more. A claim made after at (Claimed) is not undone by this pass.

func (*Forwarder) Tick

func (f *Forwarder) Tick(ctx context.Context)

Tick runs one step for every worker: read its transcript's new lines, then post what is buffered (unless it is backing off).

type Poster

type Poster interface {
	Post(ctx context.Context, o officers.Officer, item officers.ItemID, instance string, events []officers.TranscriptEvent) (officers.TranscriptAck, error)
	Scrub(o officers.Officer, s string) string
}

Poster is the HQ side: the transcript route, and the officer-token scrub.

func NewBackendPoster added in v0.209.0

func NewBackendPoster(b *officers.Backends) Poster

NewBackendPoster is a Poster over each officer's own backend. A backend that does not serve transcripts answers officers.ErrNotServed.

type Query

type Query struct {
	// Session is the session the reader's offset belongs to ("" for none yet).
	Session string
	// After is the offset to read from; -1 is the tail (the last Backfill
	// bytes; Backfill 0 starts live, at the end).
	After    int64
	Backfill int
}

Query is one read of an instance's transcript.

type Source

type Source interface {
	Read(ctx context.Context, o officers.Officer, instance string, q Query) (cctranscript.Page, error)
}

Source reads an officer instance's transcript (production: the instance pod's ccd, GET /v1/transcript).

Jump to

Keyboard shortcuts

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