Documentation
¶
Overview ¶
Package watcher tails Claude Code JSONL session files and forwards agent output to Telegram.
It uses fsnotify to watch the ~/.claude/projects/ directories for registered agents, reads new bytes from tracked file offsets, and parses complete JSONL lines to extract assistant text blocks, tool invocations, and AskUserQuestion events. Detected events are dispatched via caller-provided callbacks to the daemon for Telegram delivery.
Plane: manager
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodePath ¶
EncodePath converts an absolute path to CC's encoded project directory name. CC replaces / and . with - (e.g. /Users/neil/clawd -> -Users-neil-clawd).
Types ¶
type AgentWatcher ¶
type AgentWatcher struct {
// contains filtered or unexported fields
}
AgentWatcher watches a single agent's CC project directory for JSONL output.
func NewAgentWatcher ¶
func NewAgentWatcher(agentName, workDir string, send SendTextFunc) *AgentWatcher
NewAgentWatcher creates a watcher for a single CC agent's JSONL output.
func (*AgentWatcher) Run ¶
func (w *AgentWatcher) Run(done <-chan struct{})
Run starts watching the agent's project dir for JSONL writes. Blocks until done is closed.
type FileWatcher ¶ added in v1.8.0
type FileWatcher struct {
// contains filtered or unexported fields
}
FileWatcher watches a single JSONL file and sends assistant text to a callback. Unlike AgentWatcher (which watches an entire project dir), FileWatcher targets a specific session file so only one agent's output is captured.
func NewFileWatcher ¶ added in v1.8.0
func NewFileWatcher(agentName, filePath string, send SendTextFunc) *FileWatcher
NewFileWatcher creates a watcher for a specific JSONL file.
func (*FileWatcher) Run ¶ added in v1.8.0
func (w *FileWatcher) Run(done <-chan struct{})
Run watches the file's parent directory via fsnotify and filters for writes to the specific file. Blocks until done is closed. Must NOT acquire external mutexes — callers may close done while holding locks.
type SendFunc ¶
type SendFunc func(teamName, agentName, text string)
SendFunc is the callback for sending a message to Telegram. teamName and agentName identify the agent, text is the assistant text block.
type SendTextFunc ¶
type SendTextFunc func(text string)
SendTextFunc is called when new assistant text is detected.
type ToolFunc ¶ added in v1.0.0
type ToolFunc func(teamName, agentName, toolName string)
ToolFunc is called when a tool invocation is detected in CC JSONL.
type WatchedAgent ¶ added in v1.0.0
type WatchedAgent struct {
AgentInfo
ProjectsDir string // which projects/ dir this agent's JSONL lives in
EncodedDir string // the CC-encoded dir name (e.g. "-workspace-manager")
}
WatchedAgent pairs agent info with the projects dir and encoded dir name for its JSONL. Exported because daemon.go constructs the map.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher tails active CC JSONL files and sends assistant text to Telegram.