cc-dejavu 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +264 -0
  3. package/dist/index.js +3051 -0
  4. package/package.json +41 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Michael
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,264 @@
1
+ # deja
2
+
3
+ [![CI](https://github.com/Michaelliv/cc-dejavu/actions/workflows/ci.yml/badge.svg)](https://github.com/Michaelliv/cc-dejavu/actions/workflows/ci.yml)
4
+ [![codecov](https://codecov.io/gh/Michaelliv/cc-dejavu/graph/badge.svg)](https://codecov.io/gh/Michaelliv/cc-dejavu)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Bun](https://img.shields.io/badge/Bun-%23000000.svg?logo=bun&logoColor=white)](https://bun.sh)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
8
+
9
+ Search and browse your Claude Code bash command history.
10
+
11
+ ```
12
+ "What was that docker command I ran yesterday?"
13
+ ```
14
+
15
+ ```bash
16
+ $ deja search docker --limit 4
17
+
18
+ [ok] docker build --no-cache --platform linux/amd64 -t ghcr.io/user/api-service:latest .
19
+ Rebuild without cache for production
20
+ 12/30/2025, 12:46 AM | ~/projects/api-service
21
+
22
+ [ok] docker build -t api-service:test .
23
+ Build test image
24
+ 12/30/2025, 12:45 AM | ~/projects/api-service
25
+
26
+ [ok] docker run --rm api-service:test npm test
27
+ Run tests in container
28
+ 12/30/2025, 12:46 AM | ~/projects/api-service
29
+
30
+ [ok] docker push ghcr.io/user/api-service:latest
31
+ Push to registry
32
+ 12/30/2025, 12:48 AM | ~/projects/api-service
33
+ ```
34
+
35
+ Every bash command Claude Code runs is logged in session files. `deja` indexes them into a searchable database so you can find that command you ran last week, see what worked, and avoid repeating mistakes.
36
+
37
+ ## Features
38
+
39
+ - **Frecency-based sorting** - Commands are ranked by a combination of frequency and recency, so your most useful commands appear first
40
+ - **Match highlighting** - Search patterns are highlighted in yellow in the output
41
+ - **Automatic sync** - History is automatically synced before each search
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ # With Bun (recommended)
47
+ bun add -g cc-dejavu
48
+
49
+ # With npm
50
+ npm install -g cc-dejavu
51
+
52
+ # Or build from source
53
+ git clone https://github.com/Michaelliv/cc-dejavu
54
+ cd cc-dejavu
55
+ bun install
56
+ bun run build # Creates ./deja binary
57
+ ```
58
+
59
+ ## Usage
60
+
61
+ ```bash
62
+ # Search for commands containing "docker"
63
+ deja search docker
64
+
65
+ # Use regex patterns
66
+ deja search "git commit.*fix" --regex
67
+
68
+ # Filter by project directory
69
+ deja search npm --cwd /projects/myapp
70
+
71
+ # Filter by current directory
72
+ deja search npm --here
73
+
74
+ # Sort by time instead of frecency
75
+ deja search npm --sort time
76
+
77
+ # List recent commands
78
+ deja list
79
+ deja list --limit 50
80
+
81
+ # List commands from current project only
82
+ deja list --here
83
+
84
+ # Manually sync (usually automatic)
85
+ deja sync
86
+ deja sync --force # Re-index everything
87
+ ```
88
+
89
+ ## Examples
90
+
91
+ **Find a failing build command:**
92
+ ```bash
93
+ $ deja search "npm run build" --limit 5
94
+ # Look for [error] entries to see what failed
95
+ ```
96
+
97
+ **What commands did I run in this project?**
98
+ ```bash
99
+ $ deja list --here --limit 20
100
+ # Shows only commands from current directory
101
+ ```
102
+
103
+ **What commands did I run in a specific project?**
104
+ ```bash
105
+ $ deja search "" --cwd /projects/api --limit 20
106
+ # Empty pattern matches everything, filtered by directory
107
+ ```
108
+
109
+ **Re-run something from last week:**
110
+ ```bash
111
+ $ deja list --limit 100
112
+ # Scroll through recent history, copy what you need
113
+ ```
114
+
115
+ ## Commands
116
+
117
+ ### `deja search <pattern>`
118
+
119
+ Search command history by substring or regex.
120
+
121
+ | Flag | Description |
122
+ |------|-------------|
123
+ | `--regex`, `-r` | Treat pattern as regular expression |
124
+ | `--cwd <path>` | Filter by working directory |
125
+ | `--here`, `-H` | Filter by current directory |
126
+ | `--limit`, `-n <N>` | Limit number of results |
127
+ | `--sort <mode>` | Sort by: `frecency` (default), `time` |
128
+ | `--no-sync` | Skip auto-sync before searching |
129
+
130
+ ### `deja list`
131
+
132
+ Show recent commands, sorted by frecency by default.
133
+
134
+ | Flag | Description |
135
+ |------|-------------|
136
+ | `--limit`, `-n <N>` | Number of commands (default: 20) |
137
+ | `--here`, `-H` | Filter by current directory |
138
+ | `--sort <mode>` | Sort by: `frecency` (default), `time` |
139
+ | `--no-sync` | Skip auto-sync before listing |
140
+
141
+ ### `deja sync`
142
+
143
+ Index new commands from Claude Code sessions.
144
+
145
+ | Flag | Description |
146
+ |------|-------------|
147
+ | `--force`, `-f` | Re-index all sessions from scratch |
148
+
149
+ ## Frecency Algorithm
150
+
151
+ Results are sorted by "frecency" - a combination of frequency and recency:
152
+
153
+ - **Recency weights**: Commands run in the last 4 hours score highest, with decreasing weights for last day, week, month, and older
154
+ - **Frequency**: Uses logarithmic scaling to prevent very frequent commands from dominating
155
+
156
+ This means recently-used commands you run often appear at the top, while one-off commands from months ago sink to the bottom.
157
+
158
+ Use `--sort time` to revert to simple timestamp ordering.
159
+
160
+ ## How It Works
161
+
162
+ Claude Code stores conversation data in `~/.claude/projects/`. Each session is a JSONL file containing messages, tool calls, and results.
163
+
164
+ `deja` scans these files, extracts Bash tool invocations, and indexes them into a local SQLite database at `~/.cc-dejavu/history.db`. It tracks file positions so subsequent syncs only process new content.
165
+
166
+ **Auto-sync**: By default, `search` and `list` automatically sync before returning results. Use `--no-sync` to skip this if you want faster queries.
167
+
168
+ **Privacy**: `deja` is read-only and local-only. It reads Claude's session files but never modifies them. No data is sent anywhere.
169
+
170
+ ## Data Model
171
+
172
+ Each indexed command includes:
173
+
174
+ | Field | Description |
175
+ |-------|-------------|
176
+ | `command` | The bash command that was executed |
177
+ | `description` | What Claude said it does (e.g., "Build the project") |
178
+ | `cwd` | Working directory when command ran |
179
+ | `timestamp` | When the command was executed |
180
+ | `is_error` | Whether the command failed |
181
+ | `stdout` | Command output (stored, not displayed by default) |
182
+ | `stderr` | Error output (stored, not displayed by default) |
183
+ | `session_id` | Which Claude session ran this command |
184
+
185
+ ## For AI Agents
186
+
187
+ Run `deja onboard` to add a section to `~/.claude/CLAUDE.md` so Claude knows how to search its own history:
188
+
189
+ ```bash
190
+ deja onboard
191
+ ```
192
+
193
+ This adds:
194
+
195
+ ```xml
196
+ <deja>
197
+ Use `deja` to search bash commands from previous Claude Code sessions.
198
+
199
+ <commands>
200
+ - `deja search <pattern>` - Search by substring (or `--regex`)
201
+ - `deja list` - Recent commands
202
+ - `deja list --here` - Recent commands in current project
203
+ - `deja search <pattern> --here` - Search in current project
204
+ </commands>
205
+
206
+ <when-to-use>
207
+ - "Deploy like we did last time"
208
+ - "Run the same build command"
209
+ - "What was that curl/docker/git command?"
210
+ - "Set it up like we did on the other project"
211
+ - "Show me the failed builds"
212
+ - Looking up commands from previous sessions
213
+ </when-to-use>
214
+
215
+ <when-not-to-use>
216
+ - Finding files -> use Glob
217
+ - Searching file contents -> use Grep
218
+ - Commands from current session -> already in context
219
+ </when-not-to-use>
220
+ </deja>
221
+ ```
222
+
223
+ Now Claude knows how to search its own history.
224
+
225
+ ### When to use `deja`
226
+
227
+ - User asks "what was that command I/you ran?"
228
+ - User wants to find a command from a previous session
229
+ - User needs to recall commands from a specific project
230
+ - User wants to see commands that failed
231
+
232
+ ### When NOT to use `deja`
233
+
234
+ - Finding files by name -> use `Glob`
235
+ - Searching file contents -> use `Grep`
236
+ - Checking recent conversation context -> already in your context
237
+ - User's personal shell history -> not indexed, only Claude's commands
238
+
239
+ ## Development
240
+
241
+ ```bash
242
+ # Install dependencies
243
+ bun install
244
+
245
+ # Run directly
246
+ bun run src/index.ts search docker
247
+
248
+ # Run tests
249
+ bun test
250
+
251
+ # Run tests with coverage
252
+ bun test --coverage
253
+
254
+ # Build binary
255
+ bun run build
256
+ ```
257
+
258
+ ## About the name
259
+
260
+ `deja` - short for deja vu, "already seen." It shows you commands you've already run.
261
+
262
+ ---
263
+
264
+ MIT License