ccsubagents

package
v0.220.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 12 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 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 window's live work count) and ccd reads it inside a dispatched claude-code pod (cmd/ccd/work.go), so the two kinds of entry 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

View Source
const (
	Running = "running"
	Done    = "done"
	Failed  = "failed"
)

The values of a subagent's state (mirror.SubagentRunning and so on).

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

View Source
const MaxSubagents = 64

MaxSubagents bounds one view's summary list (internal/mirror re-exports it as mirror.MaxSubagents, a property of the wire).

View Source
const MaxTrackedCalls = 4 * MaxSubagents

MaxTrackedCalls bounds the Agent calls one tracker remembers.

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

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

func Dir(transcript string) string

Dir is the subagents directory of the session whose transcript is transcript: <dir>/<session-id>/subagents.

func IsSubagentTool

func IsSubagentTool(name string) bool

IsSubagentTool reports whether a tool call of this name spawns a subagent (mirror.IsSubagentTool).

func ReadTailRows

func ReadTailRows(f *os.File, size int64) [][]byte

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:

  1. 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.
  2. Else the parent's latest task notification for it decides — "completed" (or no status) is done, any other ("failed", "killed", "stopped") failed.
  3. 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.
  4. 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.

func StepLine

func StepLine(s Step) string

StepLine is a step on one line: "Bash: go test" or the text.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a subagent (or tool_use) id the wire carries (mirror.ValidSubagentID).

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.

func ReadFacts

func ReadFacts(path string) Facts

ReadFacts reads what path says about its agent (zero facts when it does not exist yet).

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 NewLedger

func NewLedger(path string, started int64) *Ledger

func (*Ledger) Path

func (l *Ledger) Path() string

Path is the transcript the ledger follows.

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.

func (*Ledger) Running

func (l *Ledger) Running(now time.Time) int

Running is how many of the ledger's calls are running now: not killed, not older than the CLI, and running by the subagent cards' state rule. A call whose agent is not known yet (no meta, no result) is running — the rule's own verdict for no signal and no file.

func (*Ledger) Started

func (l *Ledger) Started() int64

Started is the CLI start time (Unix ms) the ledger was made for.

type Meta

type Meta struct {
	AgentType, Description, ToolUseID, Shape, Parent string
}

Meta is what a meta file says.

func ReadMeta

func ReadMeta(path string) (Meta, bool)

ReadMeta reads one meta file; ok is false when it cannot be read or names no toolUseId. Each field is read by name and only when it is a string.

type ParentNotice

type ParentNotice struct {
	At     int64
	Status string
}

ParentNotice is the parent's latest task notification for an Agent call.

type ParentResult

type ParentResult struct {
	At    int64
	OK    bool
	Async bool
}

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

func Steps

func Steps(rows [][]byte) []Step

Steps is what rows contribute as steps, oldest first: each tool call (its tool and one-line target) and each reply text (its first line), with what looks like a secret redacted. A subagent's prompt, its tool results and its thinking are not steps.

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

func NewTracker(transcript string) *Tracker

NewTracker is a tracker for the session whose transcript is transcript.

func (*Tracker) FactsOf

func (t *Tracker) FactsOf(agent string) Facts

FactsOf is agent's facts, re-read only when its file changed.

func (*Tracker) Observe

func (t *Tracker) Observe(events []cctranscript.Event)

Observe takes the parent's events, in transcript order.

func (*Tracker) ReadMetas

func (t *Tracker) ReadMetas()

ReadMetas reads every meta file in the directory not read yet. A meta, once written, does not change.

Jump to

Keyboard shortcuts

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