createEventStore
SQLite persistence layer for tool usage events. Provides storage, querying, and analysis capabilities for pattern detection.Function Signature
src/core/event-store.ts:345
Parameters
Path to SQLite database file. Defaults to the Auto-Skill index database in the Claude config directory.
Return Value
Returns anEventStore instance with storage and query methods.
ToolEvent Type
Unique event identifier (ULID).
Session identifier grouping related events.
Absolute path to the project workspace.
Name of the tool invoked (e.g.
"Read", "Edit", "Bash").JSON object containing tool parameters (file paths, commands, search patterns, etc.).
Tool output, truncated to 1000 chars to save space.
null if no response.Whether the tool invocation succeeded.
ISO-8601 timestamp of the event.
Optional identifier for the coding agent (e.g.
"claude-code", "cursor").src/types/index.ts:14-24
Methods
recordEvent
Records a single tool usage event to the database.Session identifier for grouping related events.
Absolute path to the project workspace.
Name of the tool invoked.
Tool parameters as a JSON object.
Tool output (truncated to 1000 chars). Defaults to
null.Whether the tool invocation succeeded.
Optional agent identifier.
ToolEvent - The recorded event with generated ID and timestamp.
Source: src/core/event-store.ts:103
getSessionEvents
Retrieves all events for a specific session, ordered chronologically.Session identifier.
ToolEvent[] - Ordered list of events in the session.
Source: src/core/event-store.ts:151
getToolSequences
Extracts tool name sequences grouped by session for pattern detection.Filter to specific project.
undefined returns all projects.How many days of history to include.
Minimum number of tools in a sequence. Sessions with fewer tools are excluded.
string[][] - List of tool name sequences, one per session.
Example return:
src/core/event-store.ts:171
getEventsWithInputs
Retrieves full events (including tool inputs) grouped by session.Filter to specific project.
undefined returns all projects.How many days of history to include.
ToolEvent[][] - Array of session event arrays with complete metadata.
Useful for sophisticated pattern matching that considers tool parameters, not just tool names.
Source: src/core/event-store.ts:227
getStats
Calculates summary statistics about stored events. Returns:EventStoreStats object:
Total number of recorded events.
Count of distinct sessions.
Count of distinct project paths.
Top 10 most-used tools with usage counts.
src/core/event-store.ts:279
cleanupOldEvents
Deletes events older than the specified retention period.Number of days to keep. Events older than this are deleted.
number - Count of deleted events.
Source: src/core/event-store.ts:322
close
Closes the database connection. Source:src/core/event-store.ts:337
Database Schema
The event store uses a single SQLite table:idx_session_idonsession_ididx_project_pathonproject_pathidx_timestampontimestampidx_tool_nameontool_name
src/core/event-store.ts:70-95
Usage Example
Hybrid Storage Model
The event store uses a global database with project tagging:- Single database: All events stored in
~/.claude/auto-skill/index.db - Project filtering: Each event tagged with
project_path - Session grouping: Events grouped by
session_idfor pattern analysis
- Cross-project pattern detection (learning from all projects)
- Project-specific analysis (filter by
project_path) - Efficient storage (single database, indexed queries)
src/core/event-store.ts:1-13
Response Truncation
Tool responses are truncated to 1000 characters to save storage space:src/core/event-store.ts:20-32
See Also
- createPatternDetector - Detect patterns from stored events
- ToolEvent Type - Event schema reference