|
| 1 | +# @vibe-x/agentlens-cli |
| 2 | + |
| 3 | +> Command-line interface for Agent Lens - Track and identify AI agent contributions in code |
| 4 | +
|
| 5 | + |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +Agent Lens CLI is a command-line tool that helps you track which code in your repository was written by AI agents (like Cursor, Claude Code) versus humans. It integrates with AI coding assistants via hooks to capture code changes in real-time. |
| 10 | + |
| 11 | +**For a visual experience**, we recommend using the CLI together with the [Agent Lens VS Code Extension](https://marketplace.visualstudio.com/items?itemName=vibe-x-ai.agentlens), which provides GitLens-style inline blame annotations and a sidebar for browsing AI activity. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +# Install globally via npm |
| 17 | +npm install -g @vibe-x/agentlens-cli |
| 18 | + |
| 19 | +# Or use npx |
| 20 | +npx @vibe-x/agentlens-cli --help |
| 21 | +``` |
| 22 | + |
| 23 | +## Quick Start |
| 24 | + |
| 25 | +```bash |
| 26 | +# 1. Initialize Agent Lens in your project |
| 27 | +cd your-project |
| 28 | +agentlens config --init |
| 29 | + |
| 30 | +# 2. Connect to an AI Agent |
| 31 | +agentlens hook connect cursor # For Cursor |
| 32 | +agentlens hook connect claude-code # For Claude Code |
| 33 | + |
| 34 | +# 3. Use your AI Agent normally - changes are tracked automatically |
| 35 | + |
| 36 | +# 4. View annotated diff with contributor information |
| 37 | +agentlens diff --annotated |
| 38 | +``` |
| 39 | + |
| 40 | +## Commands |
| 41 | + |
| 42 | +### `agentlens config` |
| 43 | + |
| 44 | +Configure Agent Lens settings in your project. |
| 45 | + |
| 46 | +```bash |
| 47 | +# Initialize Agent Lens in the current project |
| 48 | +agentlens config --init |
| 49 | + |
| 50 | +# Show current configuration |
| 51 | +agentlens config --show |
| 52 | + |
| 53 | +# Set a configuration value |
| 54 | +agentlens config --set key=value |
| 55 | + |
| 56 | +# Reset configuration to defaults |
| 57 | +agentlens config --reset |
| 58 | +``` |
| 59 | + |
| 60 | +**After initialization**, a `.agentlens/` directory is created with: |
| 61 | +- `data/sessions/` - Session data from AI agents |
| 62 | +- `data/hooks/` - Hook captured code changes (sharded by date) |
| 63 | +- `data/todos.json` - TODO items from agent sessions |
| 64 | +- `config/` - Configuration files |
| 65 | + |
| 66 | +### `agentlens hook` |
| 67 | + |
| 68 | +Manage AI Agent hooks for data collection. |
| 69 | + |
| 70 | +```bash |
| 71 | +# Connect to an AI Agent |
| 72 | +agentlens hook connect <agent> # cursor, claude-code |
| 73 | + |
| 74 | +# Disconnect from an AI Agent |
| 75 | +agentlens hook disconnect <agent> |
| 76 | + |
| 77 | +# Show connection status for all agents |
| 78 | +agentlens hook status |
| 79 | + |
| 80 | +# List supported AI Agents |
| 81 | +agentlens hook list |
| 82 | +``` |
| 83 | + |
| 84 | +**Supported Agents:** |
| 85 | +| Agent | ID | Config Location | |
| 86 | +|-------|------|----------------| |
| 87 | +| Cursor | `cursor` | `~/.cursor/hooks.json` | |
| 88 | +| Claude Code | `claude-code` | `~/.claude/settings.json` | |
| 89 | + |
| 90 | +**Note for Cursor users:** You need to enable "Third-party skills" in Cursor Settings for hooks to work. |
| 91 | + |
| 92 | +### `agentlens diff` |
| 93 | + |
| 94 | +Show annotated diff with AI/human contributor information. |
| 95 | + |
| 96 | +```bash |
| 97 | +# Show working tree changes with contributor info (default) |
| 98 | +agentlens diff --annotated |
| 99 | + |
| 100 | +# Show staged changes only |
| 101 | +agentlens diff --staged |
| 102 | + |
| 103 | +# Diff against a specific git reference |
| 104 | +agentlens diff --ref HEAD~3 |
| 105 | + |
| 106 | +# Output formats |
| 107 | +agentlens diff --format terminal # Default, colored terminal output |
| 108 | +agentlens diff --format markdown # Markdown format |
| 109 | +agentlens diff --format json # JSON format |
| 110 | + |
| 111 | +# Write output to file |
| 112 | +agentlens diff --format markdown -o report.md |
| 113 | + |
| 114 | +# Disable colored output |
| 115 | +agentlens diff --no-color |
| 116 | +``` |
| 117 | + |
| 118 | +**Options:** |
| 119 | +| Option | Description | |
| 120 | +|--------|-------------| |
| 121 | +| `-a, --annotated` | Show annotated diff with contributor info (default: true) | |
| 122 | +| `-f, --format <format>` | Output format: terminal, markdown, json | |
| 123 | +| `-r, --ref <ref>` | Git reference to diff against | |
| 124 | +| `--staged` | Show staged changes only | |
| 125 | +| `-o, --output <file>` | Write output to file | |
| 126 | +| `--no-color` | Disable colored output | |
| 127 | + |
| 128 | +### `agentlens review` |
| 129 | + |
| 130 | +Start an interactive code review session. |
| 131 | + |
| 132 | +```bash |
| 133 | +# Start review session |
| 134 | +agentlens review |
| 135 | + |
| 136 | +# Filter by session ID |
| 137 | +agentlens review --session abc123 |
| 138 | + |
| 139 | +# Show changes since a specific date |
| 140 | +agentlens review --since "2024-01-01" |
| 141 | + |
| 142 | +# Export to markdown |
| 143 | +agentlens review --format markdown -o review-report.md |
| 144 | +``` |
| 145 | + |
| 146 | +**Options:** |
| 147 | +| Option | Description | |
| 148 | +|--------|-------------| |
| 149 | +| `-f, --format <format>` | Output format: terminal, markdown | |
| 150 | +| `--session <id>` | Filter by session ID | |
| 151 | +| `--since <date>` | Show changes since date | |
| 152 | +| `-o, --output <file>` | Write report to file | |
| 153 | + |
| 154 | +### `agentlens todos` |
| 155 | + |
| 156 | +Manage TODO items from Agent sessions. |
| 157 | + |
| 158 | +```bash |
| 159 | +# List all TODOs |
| 160 | +agentlens todos |
| 161 | + |
| 162 | +# Filter by status |
| 163 | +agentlens todos --status pending |
| 164 | +agentlens todos --status in_progress |
| 165 | +agentlens todos --status completed |
| 166 | + |
| 167 | +# Filter by session |
| 168 | +agentlens todos --session abc123 |
| 169 | + |
| 170 | +# Output as JSON |
| 171 | +agentlens todos --format json |
| 172 | +``` |
| 173 | + |
| 174 | +**Options:** |
| 175 | +| Option | Description | |
| 176 | +|--------|-------------| |
| 177 | +| `-l, --list` | List all TODOs (default) | |
| 178 | +| `-s, --status <status>` | Filter by status: pending, in_progress, completed | |
| 179 | +| `--session <id>` | Filter by session ID | |
| 180 | +| `-f, --format <format>` | Output format: terminal, json | |
| 181 | + |
| 182 | +## How It Works |
| 183 | + |
| 184 | +### Hook System |
| 185 | + |
| 186 | +Agent Lens uses a hook system to capture code changes from AI agents: |
| 187 | + |
| 188 | +1. **For Cursor**: Uses the [Third-party Hooks](https://cursor.com/cn/docs/agent/hooks) feature |
| 189 | +2. **For Claude Code**: Uses the [Hooks](https://docs.anthropic.com/en/docs/claude-code/hooks) feature |
| 190 | + |
| 191 | +When you run `agentlens hook connect <agent>`, the CLI: |
| 192 | +1. Detects if the agent is installed on your system |
| 193 | +2. Creates/updates the agent's hook configuration file |
| 194 | +3. Points the hooks to the `agentlens` CLI commands |
| 195 | + |
| 196 | +### Data Storage |
| 197 | + |
| 198 | +All captured data is stored in `.agentlens/data/hooks/`: |
| 199 | + |
| 200 | +``` |
| 201 | +.agentlens/data/hooks/ |
| 202 | +├── changes/ # Code change records (sharded by date) |
| 203 | +│ ├── 2024-01-10.jsonl |
| 204 | +│ ├── 2024-01-11.jsonl |
| 205 | +│ └── ... |
| 206 | +├── prompts/ # User prompts (sharded by date) |
| 207 | +│ └── 2024-01-10.jsonl |
| 208 | +└── sessions.json # Session metadata |
| 209 | +``` |
| 210 | + |
| 211 | +### Contributor Detection |
| 212 | + |
| 213 | +Agent Lens uses **4-level filtering with Levenshtein similarity matching** to determine code authorship: |
| 214 | + |
| 215 | +``` |
| 216 | +Level 1: File Path Filter (100 records → 30 records) |
| 217 | + ↓ |
| 218 | +Level 2: Time Window Filter (30 records → 15 records) |
| 219 | + ↓ |
| 220 | +Level 3: Content Length Filter (15 records → 5 records) |
| 221 | + ↓ |
| 222 | +Level 4: Levenshtein Matching (5 candidates → best match) |
| 223 | +``` |
| 224 | + |
| 225 | +**Classification Thresholds:** |
| 226 | +- ≥ 90% similarity → **AI Generated** |
| 227 | +- 70-90% similarity → **AI Generated (Human Modified)** |
| 228 | +- < 70% similarity → **Human Contribution** |
| 229 | + |
| 230 | +## VS Code Extension |
| 231 | + |
| 232 | +For the best experience, use the CLI together with the [Agent Lens VS Code Extension](https://marketplace.visualstudio.com/items?itemName=vibe-x-ai.agentlens). |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | +The extension provides: |
| 237 | + |
| 238 | +- **GitLens-style inline blame** - Hover over any line to see if it was written by AI or human |
| 239 | +- **Sidebar views** - Browse connected agents and recent AI-generated code changes |
| 240 | +- **One-click issue reporting** - Report matching problems directly from VS Code |
| 241 | +- **Auto cleanup** - Automatic cleanup of old data files |
| 242 | + |
| 243 | +### Installation |
| 244 | + |
| 245 | +```bash |
| 246 | +# Install from VS Code Marketplace |
| 247 | +code --install-extension vibe-x-ai.agentlens |
| 248 | +``` |
| 249 | + |
| 250 | +Or search for "Agent Lens" in VS Code Extensions (`Cmd+Shift+X` / `Ctrl+Shift+X`). |
| 251 | + |
| 252 | +**Note:** The VS Code extension works independently and does not require the CLI to be installed. Both tools can connect to AI agents directly. |
| 253 | + |
| 254 | +## Requirements |
| 255 | + |
| 256 | +- Node.js >= 22.15.1 |
| 257 | +- Git repository |
| 258 | +- Supported AI Agent (Cursor or Claude Code) |
| 259 | + |
| 260 | +## Related |
| 261 | + |
| 262 | +- [Agent Lens](https://github.com/vibe-x-ai/agent-blame) - Main repository |
| 263 | +- [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=vibe-x-ai.agentlens) |
| 264 | + |
| 265 | +## License |
| 266 | + |
| 267 | +MIT |
0 commit comments