Repository navigation
feat: add usage statistics tracking - #2568
Conversation
|
Thank you! This is great! My personal preference is to put this off by default, as I believe is some kind of tracking. |
agreed, makes sense |
Adds .direnv directory to gitignore as it's generated by direnv and should not be tracked in version control.
There was a problem hiding this comment.
Pull Request Overview
This PR adds usage statistics tracking functionality to espanso, allowing users to view and manage statistics about their text expansion usage. The feature is opt-in (disabled by default) and stores expansion data in a local SQLite database.
Key Changes:
- Adds a new
espanso statsCLI command with subcommands for viewing, clearing, and pruning statistics - Implements a background thread-based statistics recorder using SQLite for persistence
- Integrates stats recording into the engine's event processing pipeline via middleware
Reviewed Changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
espanso/src/cli/stats.rs |
New CLI module implementing stats viewing, database management, and background recording thread |
espanso/src/cli/worker/stats_recorder.rs |
Adapter implementing the StatsRecorder trait for the worker process |
espanso/src/cli/worker/mod.rs |
Initializes stats database and recorder when stats are enabled |
espanso-engine/src/process/middleware/stats.rs |
New middleware tracking match expansions and recording statistics |
espanso-engine/src/process/default.rs |
Adds stats middleware to the processing pipeline |
espanso-engine/src/event/internal.rs |
Adds trigger field to ImageRequestedEvent for stats tracking |
espanso/src/cli/worker/engine/process/middleware/multiplex.rs |
Populates trigger field when creating ImageRequestedEvent |
espanso-config/src/config/mod.rs |
Adds stats_enabled() method to Config trait |
espanso-config/src/config/resolve.rs |
Implements stats configuration resolution with default=false |
espanso-config/src/config/parse/yaml.rs |
Adds YAML parsing support for stats configuration |
espanso/src/main.rs |
Adds stats subcommand with argument definitions |
espanso/Cargo.toml |
Adds rusqlite dependency |
Cargo.lock |
Updates lock file with rusqlite and transitive dependencies |
.gitignore |
Adds .direnv/ to ignored paths |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let display_trigger: String = trigger.chars().take(19).collect(); | ||
| println!("│ {:<19} │ {:>5} │", display_trigger, cnt); |
There was a problem hiding this comment.
Using chars().take(19) to truncate triggers can produce incorrect display widths for characters that occupy more than one terminal column (e.g., emojis, CJK characters). This will cause table misalignment. Consider using a crate like unicode-width to properly calculate display width, or use graphemes for proper character boundary handling.
There was a problem hiding this comment.
It's a nice comment, but nah, not worth to add a crate (even if it's already used multiple times in Cargo lock). It would be rare that a trigger use an emoji.
Non ascii characters may be a problem in the future, once #2123 is solved. Even then 19 chars is more than enough to recognize a trigger
| let icon_paths = | ||
| crate::icon::load_icon_paths(&paths.runtime).expect("unable to initialize icons"); | ||
|
|
||
| // Initialize stats database and set recorder (configurable, default ON) |
There was a problem hiding this comment.
The comment states "default ON" but the code in espanso-config/src/config/resolve.rs line 309 shows self.parsed.stats_enabled.unwrap_or(false), meaning stats are disabled by default. The comment should say "default OFF" to match the actual default behavior.
| // Initialize stats database and set recorder (configurable, default ON) | |
| // Initialize stats database and set recorder (configurable, default OFF) |
| let display_trigger: String = trigger.chars().take(19).collect(); | ||
| println!("│ {:<19} │ {:>5} │", display_trigger, cnt); |
There was a problem hiding this comment.
It's a nice comment, but nah, not worth to add a crate (even if it's already used multiple times in Cargo lock). It would be rare that a trigger use an emoji.
Non ascii characters may be a problem in the future, once #2123 is solved. Even then 19 chars is more than enough to recognize a trigger
|
Reviewing the pr:
Some comments, that don't stop this PR from merging:
Copilot did some nice suggestions, some of them aren't useful, but some do! Do this changes and I think we are good to go, but in general it's a very nice implementation. Thank you very much for the submission! |
|
All suggestions addressed.
Should the documentation be added to https://github.com/espanso/website? |
|
Yes! I meant that documentation, not to document here 😅 |
* chore: add .direnv to .gitignore Adds .direnv directory to gitignore as it's generated by direnv and should not be tracked in version control. * feat: add usage statistics tracking
Adds usage statistics tracking for match expansions.
Usage:
Configuration:
I'm using this locally. If you're interested, feel free to test it. Will convert to a regular PR in one week.
Closes #2563