feat: add automated tool-usage collection via Yarn plugin and agent hooks (Phase 2)#28815
Conversation
This commit introduces a new SQLite database setup for tracking tool usage events. It includes the following changes: - Added `db.ts` for database initialization and schema creation. - Implemented `trackEvent` function in `events.ts` to log events with relevant metadata. - Created test files for both database operations and event tracking to ensure functionality and reliability. - Added a CLI script (`tool-usage-collection.ts`) for collecting tool usage data via command-line arguments. Additionally, updated `package.json` and `yarn.lock` to include necessary dependencies for SQLite and TypeScript support. CHANGELOG entry: Added SQLite database handling for tool usage tracking.
…rgument parsing in tool-usage-collection.ts to enforce value requirements for flags.
- Introduced a new skill for creating and removing git worktrees, including detailed usage instructions. - Added a plugin for tracking script execution in Yarn, logging events to a local SQLite database. - Updated package.json to include the new @modelcontextprotocol/sdk dependency. - Enhanced event tracking functionality in the tooling scripts, ensuring accurate logging of tool usage events. - Created configuration files for the new skill and tracking server, improving project tooling capabilities.
…CWP-513-po-c-phase-2-automated-collection
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
This comment was marked as outdated.
This comment was marked as outdated.
…lag values and improve process.exit handling. Added tests for --help and missing flag values.
This comment was marked as outdated.
This comment was marked as outdated.
…CWP-513-po-c-phase-2-automated-collection
…CWP-513-po-c-phase-2-automated-collection # Conflicts: # scripts/tooling/events.ts
- Added a system to automatically record usage of Yarn scripts, Claude Code skills, and Cursor skills to a local SQLite database. - Introduced new hooks in Yarn and Claude Code for tracking events, including a `beforeReadFile` hook in Cursor. - Updated the database schema to include an 'interrupted' event type for better tracking of script execution. - Created a new README for tooling usage collection, detailing the architecture and usage instructions. - Enhanced tests to validate the new event type and ensure proper functionality of the tracking system.
# Conflicts: # scripts/tooling/db.test.ts # scripts/tooling/db.ts # scripts/tooling/events.test.ts # scripts/tooling/events.ts # scripts/tooling/tool-usage-collection.test.ts # scripts/tooling/tool-usage-collection.ts # yarn.lock
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #28815 +/- ##
==========================================
- Coverage 82.20% 82.20% -0.01%
==========================================
Files 5017 5023 +6
Lines 131659 131903 +244
Branches 29381 29445 +64
==========================================
+ Hits 108228 108428 +200
- Misses 16083 16110 +27
- Partials 7348 7365 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…tests This update simplifies the cursor hook logic by removing the `mustSkip` function, which was previously used to determine if tracking should be skipped based on environment variables. The handling of CI and opt-out conditions is now managed directly in the shell command within `.cursor/hooks.json`. Additionally, tests related to these conditions have been removed to reflect the updated logic, ensuring a cleaner and more efficient implementation.
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: NicolasMassart <4677568+NicolasMassart@users.noreply.github.com>
Head branch was pushed to by a user without write access
Resolved by merging |
Remove yarn command from event inspection instructions.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
None of these files touch app source code, E2E test infrastructure, CI/CD workflows, controllers, Engine, navigation, UI components, or any wallet functionality. No E2E tests are needed. Performance Test Selection: |
|



Description
Phase 2 of the automated tool-usage collection infrastructure (MCWP-513), building on the core DB write infrastructure from Phase 1.
What changed:
plugin-usage-tracking.cjs): automatically recordsstart/end/interruptedevents for everyyarn <script>execution via thewrapScriptExecutionhook — no changes topackage.jsonscript entries required. Fires-and-forgets via a detachedtsxsubprocess so it never blocks the terminal. Exit code 129 (SIGHUP/Ctrl+C) is recorded asinterruptedwithsuccess=NULLto distinguish abandoned sessions from genuine failures.PreToolUsehook (.claude/skills/pr-changelog/SKILL.md): frontmatter hook fires automatically on the first tool call after the skill loads — zero tokens, agent-invisible.beforeReadFilehook (.cursor/hooks.json+cursor-hook-skill-tracking.ts): fires automatically when Cursor reads any.agents/skills/*/SKILL.md— zero tokens, agent-invisible. UsesexecFileSyncwith an explicit argument array to avoid shell injection. Guardsfile_pathtype before extracting the skill name.TOOL_USAGE_COLLECTION_OPT_IN=false): all three collection paths (Yarn plugin, Claude hook, Cursor hook) skip silently whenCIis set or whenTOOL_USAGE_COLLECTION_OPT_IN=falseis exported in the developer's shell profile. The Yarn plugin returns an empty factory; the shell commands use[ -z "$CI" ] && [ "$TOOL_USAGE_COLLECTION_OPT_IN" != "false" ] &&guards. The Cursor hook uses|| echo '{"permission":"allow"}'as a fallback so Cursor always receives an explicit JSON permission response, even when the guards short-circuit.scripts/tooling/README.md,AGENTS.md,docs/readme/development-process.md): documents all three collection paths, skip conditions, and the architecture with a Mermaid diagram; clarifies that data is recorded locally only, never sent outside.Changelog
CHANGELOG entry: null
Related issues
Fixes MCWP-513
Manual testing steps
Screenshots/Recordings
Before
N/A
After
N/A
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches developer build tooling by hooking into every
yarnscript execution and spawning detached subprocesses; while guarded for CI/opt-out, misconfigurations could impact local dev workflows.Overview
Adds automated local developer tool-usage collection across Yarn scripts and AI agent skills, writing
start/end/interruptedevents to~/.tool-usage-collection/events.dbwith opt-out viaTOOL_USAGE_COLLECTION_OPT_IN=falseand automatic CI disable.Introduces a Yarn Berry plugin that wraps
yarn <script>runs and fire-and-forgets a detachedtsxsubprocess for tracking, plus new Cursor and Claude hooks to record skill usage; updates the SQLite schema/CLI/tests to support the newinterruptedevent type and expands documentation for setup/inspection.Reviewed by Cursor Bugbot for commit 0877b05. Bugbot is set up for automated code reviews on this repo. Configure here.