watcher

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 9 Imported by: 0

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

func EncodePath(path string) string

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 AgentInfo

type AgentInfo struct {
	TeamName  string
	AgentName string
}

AgentInfo pairs an agent with its team context.

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.

func New

func New(agents map[string]WatchedAgent, send SendFunc, onTool ToolFunc) (*Watcher, error)

New creates a Watcher from a pre-built agent map. Key is composite "teamName/encodedDir" to avoid collisions across teams. Config-driven: no DB or config.Load() required.

func (*Watcher) Run

func (w *Watcher) Run(done <-chan struct{}) error

Run starts watching. Blocks until done is closed.

Jump to

Keyboard shortcuts

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