Documentation
¶
Overview ¶
Package ccsubagents is the ONE reading of a Claude Code session's subagents: which Agent calls a parent transcript made, what each subagent's own files say, the status rule that decides running / done / failed (State), and the work ledger that counts how many run now (Ledger).
🔴 ONE RULE, ONE PLACE, TWO READERS. muster-mirror reads it for a mirrored window (internal/mirrorhost: the rendered view's subagent cards and the card's live work chip) and ccd reads it inside a dispatched claude-code pod (cmd/ccd/work.go), so the two kinds of card cannot count subagents differently.
🔴 A LEAF: it imports the standard library, internal/cctranscript and internal/redact only. It is linked into the agent pod's ccd, so it must not bring the wire package (internal/mirror, which pulls a websocket client) or the host package (internal/mirrorhost, which pulls object-store and database clients) with it. The wire's subagent names and bounds live HERE, and internal/mirror re-exports them unchanged; internal/modulegate's TestTheSubagentLeafPullsNoNetworkOrStorageClient pins the dependency set.
Index ¶
- Constants
- func Dir(transcript string) string
- func IsSubagentTool(name string) bool
- func ReadTailRows(f *os.File, size int64) [][]byte
- func State(res *ParentResult, note *ParentNotice, f Facts, now time.Time) string
- func StepLine(s Step) string
- func ValidID(id string) bool
- type Facts
- type Ledger
- type Meta
- type ParentNotice
- type ParentResult
- type Step
- type Tracker
Constants ¶
const ( Running = "running" Done = "done" Failed = "failed" )
The values of a subagent's state (mirror.SubagentRunning and so on).
const BackfillWindow = 4 << 20
BackfillWindow is the tail of a transcript file a fresh reader starts from (mirror.BackfillWindow): the file is never read wholesale.
const MaxSubagents = 64
MaxSubagents bounds one view's summary list (internal/mirror re-exports it as mirror.MaxSubagents, a property of the wire).
const MaxTrackedCalls = 4 * MaxSubagents
MaxTrackedCalls bounds the Agent calls one tracker remembers.
const Quiet = 15 * time.Second
Quiet is how long a subagent whose last row is a final reply must go without a new row before it is called done with no word from the parent (rule 3 of State).
const TailRead = 256 << 10
TailRead bounds how much of the END of a subagent's transcript one summary or tail reads. A tool result can be a whole file, so a few rows can be this large; the newest step is what matters.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
Dir is the subagents directory of the session whose transcript is transcript: <dir>/<session-id>/subagents.
func IsSubagentTool ¶
IsSubagentTool reports whether a tool call of this name spawns a subagent (mirror.IsSubagentTool).
func ReadTailRows ¶
ReadTailRows is every WHOLE line in the last TailRead bytes of f (size bytes long): the first, partial line of the window and a torn last line (no newline yet) are left out.
func State ¶
func State(res *ParentResult, note *ParentNotice, f Facts, now time.Time) string
State is THE STATUS RULE, in this order:
- The parent's tool_result for the Agent call decides — failed when it is an error, else done — unless it is only a background agent's LAUNCH (async), which says nothing about the agent finishing.
- Else the parent's latest task notification for it decides — "completed" (or no status) is done, any other ("failed", "killed", "stopped") failed.
- Else the agent is done when its last row is a final reply (text, no tool call) and its transcript has had no new row for Quiet.
- Else it is running.
🔴 A PARENT SIGNAL OLDER THAN THE AGENT'S LAST ROW DECIDES NOTHING (1 and 2): a finished agent can be resumed (SendMessage), and its new rows then come after the notification that said it finished. Both times are the CLI's own timestamps; a signal or a row with none is taken as current.
Types ¶
type Facts ¶
type Facts struct {
Exists bool
Mtime time.Time
Started int64
Updated int64
// Final: its last message row is an assistant reply with text and no tool
// call — the agent stopped, unless more rows follow.
Final bool
Last string
}
Facts is what a subagent's own transcript says.
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
Ledger follows ONE parent transcript's Agent calls: the calls and the parent's signals (Tracker.Observe), when each call was made, and which were killed.
func (*Ledger) Read ¶
func (l *Ledger) Read()
Read takes every WHOLE line written since the last read. The first read — and any read that finds more than BackfillWindow new bytes — starts at most that far from the end, at a line boundary; a torn last line (the CLI mid-write) is left for the next read. A file that shrank is read again from its new end's window.
type Meta ¶
type Meta struct {
AgentType, Description, ToolUseID, Shape, Parent string
}
Meta is what a meta file says.
type ParentNotice ¶
ParentNotice is the parent's latest task notification for an Agent call.
type ParentResult ¶
ParentResult is the parent's tool_result for an Agent call.
type Step ¶
type Step struct {
// Tool is the tool a call step ran; "" for a text step.
Tool string `json:"tool,omitempty"`
// Text is the call's one-line target, or the text's first line. Redacted.
Text string `json:"text"`
At int64 `json:"at,omitempty"`
}
Step is one step of a subagent: a tool call or a reply's text (mirror.SubagentStep is this type).
type Tracker ¶
type Tracker struct {
Dir string
Calls []string // Agent tool_use ids, in transcript order
Results map[string]ParentResult
Notices map[string]ParentNotice
ByTool map[string]string // tool_use id → agent id, from results
Metas map[string]Meta
// contains filtered or unexported fields
}
Tracker is one parent transcript's subagents: the Agent calls and the parent's signals about them, as the reader observes its transcript (Observe), and what each agent's own files say (ReadMetas, FactsOf).
🔴 IN MEMORY, BOUNDED: it lives as long as its reader and is replaced when the reader's transcript is (a /clear, a restart).
func NewTracker ¶
NewTracker is a tracker for the session whose transcript is transcript.
func (*Tracker) Observe ¶
func (t *Tracker) Observe(events []cctranscript.Event)
Observe takes the parent's events, in transcript order.