Documentation
¶
Overview ¶
Package ingest discovers Claude Code transcript files (~/.claude/projects/**), tails them, and turns their JSONL lines into normalized events. The transcript format is not a public contract: the parser is schema-versioned, tolerates unknown fields and line types, and skips malformed lines instead of failing. See .ai/03-contracts.md § Transcript JSONL (observed shape).
Index ¶
Constants ¶
const SchemaVersion = 1
SchemaVersion is bumped whenever the parser's expectations of the transcript shape change. Stored with the daemon's meta so a future migration can decide whether historical events need re-derivation.
Variables ¶
var ErrMalformed = errors.New("malformed line")
ErrMalformed marks lines that are not valid JSON objects.
var ErrSkip = errors.New("skip line")
ErrSkip marks lines that carry nothing we consume (meta lines, blank lines).
Functions ¶
Types ¶
type Line ¶
type Line struct {
Type string `json:"type"`
UUID string `json:"uuid"`
ParentUUID string `json:"parentUuid"`
SessionID string `json:"sessionId"`
PromptID string `json:"promptId"`
Cwd string `json:"cwd"`
Timestamp string `json:"timestamp"`
Version string `json:"version"`
GitBranch string `json:"gitBranch"`
IsSidechain bool `json:"isSidechain"`
AgentID string `json:"agentId"`
Subtype string `json:"subtype"`
DurationMs int64 `json:"durationMs"`
Message *struct {
Role string `json:"role"`
Model string `json:"model"`
ID string `json:"id"`
Content json.RawMessage `json:"content"`
Usage *struct {
InputTokens int64 `json:"input_tokens"`
OutputTokens int64 `json:"output_tokens"`
CacheReadInputTokens int64 `json:"cache_read_input_tokens"`
CacheCreationInputTokens int64 `json:"cache_creation_input_tokens"`
CacheCreation *struct {
Ephemeral5m int64 `json:"ephemeral_5m_input_tokens"`
Ephemeral1h int64 `json:"ephemeral_1h_input_tokens"`
} `json:"cache_creation"`
} `json:"usage"`
} `json:"message"`
}
Line is the subset of a transcript line the parser understands.
func (*Line) Events ¶
Events converts a parsed line into zero or more normalized events. Keys are chosen to collide with the hook shim's keys for the same logical event ("pre:<tool_use_id>", "post:<tool_use_id>", "prompt:<prompt_id>"), so whichever plane arrives first wins and the other dedupes in the store.
type Stats ¶
type Stats struct {
FilesKnown int `json:"files_known"`
LinesParsed int64 `json:"lines_parsed"`
LinesMalformed int64 `json:"lines_malformed"`
LinesSkipped int64 `json:"lines_skipped"`
EventsStored int64 `json:"events_stored"`
EventsDeduped int64 `json:"events_deduped"`
BackfillDone bool `json:"backfill_done"`
}
Stats counts what the tailer has done (exposed on /v1/status).
type Tailer ¶
type Tailer struct {
Root string
Recorder *rollup.Recorder
Store *store.Store
Log *slog.Logger
// PollInterval is the fallback rescan cadence (fsnotify is best-effort and not
// recursive; new project directories and network filesystems need the poll).
PollInterval time.Duration
// BackfillWindow: files last modified longer ago than this are backfilled in
// the background after live files; zero means everything is treated as live.
BackfillWindow time.Duration
// MaxLine bounds one JSONL line (a tool_result can embed a whole file).
MaxLine int
// contains filtered or unexported fields
}
Tailer follows every *.jsonl under Root and records normalized events.