@principal-ai/agent-monitoring
v0.3.22
Published
Agent event monitoring and processing system
Maintainers
Readme
@principal-ai/agent-monitoring
Agent event monitoring and processing system for AI coding assistants.
Overview
This package provides a unified monitoring and event processing system for various AI coding assistants including Claude, Cline, and OpenCode. It offers:
- Normalized event types across different agents
- Path normalization and file operation detection
- Event processors for each supported agent
- Hook configuration utilities
- Type-safe event handling
Installation
bun install @principal-ai/agent-monitoringFeatures
Supported Agents
- Claude (Anthropic's CLI)
- Cline (VS Code extension)
- OpenCode (Open source CLI)
- Droid (Factory AI)
Event Processing
- Unified event normalization across agents
- Tool usage tracking
- File operation detection
- Path context analysis
Hook Configuration
- Agent-specific hook types
- Configurable matchers
- Event filtering
Usage
import {
SupportedAgent,
ClaudeEventProcessor,
AgentEventPipeline,
CLAUDE_HOOK_TYPES,
} from "@principal-ai/agent-monitoring";
// Process a raw Claude event
const processor = new ClaudeEventProcessor();
const universalEvent = processor.normalize(rawClaudeHookData);
// Or use the full pipeline with path normalization
const pipeline = new AgentEventPipeline(pathAdapter, {
metrics: {
onEventProcessed: (event, durationMs, agent) => {
console.log(`Processed ${agent} event in ${durationMs}ms`);
},
},
});
const normalizedEvent = await pipeline.processRawEvent(
SupportedAgent.CLAUDE,
rawClaudeHookData
);
// Access normalized data
console.log(normalizedEvent.repository?.branch);
console.log(normalizedEvent.files?.map(f => f.displayPath));API Reference
Types
SupportedAgent- Enum of supported AI agents (claude, cline, opencode, droid)UniversalAgentSessionEvent- Agent-normalized event format (intermediate)RepoNormalizedUniversalAgentSessionEvent- Final event format with repository contextNormalizedPathInfo- File path with repository metadata and contextPathContext- File classification enum (REPO_FILE, SYSTEM_FILE, USER_FILE, TEMP_FILE, CONFIG_FILE)FileOperation- Operation type enum (READ, WRITE, CREATE, DELETE, EDIT, SEARCH, LIST)
Event Processors
ClaudeEventProcessor- Normalize Claude hook eventsClineEventProcessor- Normalize Cline hook eventsOpenCodeEventProcessor- Normalize OpenCode hook eventsDroidEventProcessor- Normalize Droid hook events
Pipeline
AgentEventPipeline- Full processing pipeline with path normalizationPathNormalizationService- Service for enriching paths with repository context
Hook Types
CLAUDE_HOOK_TYPES- Available Claude hook event typesCLINE_HOOK_TYPES- Available Cline hook event typesOPENCODE_HOOK_TYPES- Available OpenCode hook event typesDROID_HOOK_TYPES- Available Droid hook event types
Utility Functions
getAvailableHookTypes(agent)- Get hook types for a specific agentgetHookTypeDisplayName(hookType)- Get human-readable hook type namegetHookTypeDescription(hookType)- Get hook type descriptionisToolEvent(event)- Check if event is a tool use eventisStopEvent(event)- Check if event is a stop eventgetEventFilePaths(event)- Extract file paths from an eventclassifyPath(path)- Classify a file path into a PathContext
License
MIT
