codetrap 0.1.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.
- package/.env.example +3 -0
- package/LICENSE +22 -0
- package/README.md +305 -0
- package/docs/installation.md +306 -0
- package/package.json +62 -0
- package/scripts/build-release.ts +64 -0
- package/scripts/check-release-version.ts +19 -0
- package/skills/codetrap-add/SKILL.md +65 -0
- package/skills/codetrap-check/SKILL.md +47 -0
- package/skills/codetrap-search/SKILL.md +43 -0
- package/src/commands/router.ts +407 -0
- package/src/db/connection.ts +36 -0
- package/src/db/embedding-queries.ts +154 -0
- package/src/db/queries.ts +296 -0
- package/src/db/repository.ts +141 -0
- package/src/db/schema.ts +205 -0
- package/src/domain/trap.ts +304 -0
- package/src/index.ts +58 -0
- package/src/lib/constants.ts +56 -0
- package/src/lib/embedder.ts +133 -0
- package/src/lib/embedding-job.ts +68 -0
- package/src/lib/format.ts +97 -0
- package/src/lib/fts-query.ts +17 -0
- package/src/lib/scope.ts +30 -0
- package/src/lib/search-normalizer.ts +92 -0
- package/src/lib/search-result-card.ts +38 -0
- package/src/lib/search-service.ts +189 -0
- package/src/lib/store.ts +272 -0
- package/src/lib/trap-archive.ts +91 -0
- package/src/lib/trap-json-fields.ts +42 -0
- package/src/lib/trap-operations.ts +127 -0
- package/src/lib/trap-search-document.ts +73 -0
- package/src/mcp/resources.ts +26 -0
- package/src/mcp/server.ts +167 -0
- package/src/mcp/tools.ts +106 -0
- package/src/mcp-server.ts +6 -0
package/.env.example
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 codetrap contributors
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# codetrap
|
|
2
|
+
|
|
3
|
+
> A local-first coding pitfall memory bank — record mistakes once, never repeat them twice.
|
|
4
|
+
|
|
5
|
+
**codetrap** records structured coding pitfalls ("traps") and provides search across them before you write code. It serves both human developers via CLI and AI coding agents via MCP (Model Context Protocol).
|
|
6
|
+
|
|
7
|
+
## Why?
|
|
8
|
+
|
|
9
|
+
AI coding agents make the same mistakes repeatedly across sessions and projects. codetrap gives them a shared memory of "what not to do" — so when an agent is about to write code, it can check the trap database first and avoid known pitfalls.
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
For detailed setup options, see [Installation](docs/installation.md).
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# Prerequisites: Bun >= 1.x (https://bun.sh)
|
|
17
|
+
|
|
18
|
+
# Source install
|
|
19
|
+
git clone <repo-url> && cd codetrap
|
|
20
|
+
bun install
|
|
21
|
+
bun run install:cli
|
|
22
|
+
codetrap --help
|
|
23
|
+
|
|
24
|
+
# Initialize codetrap data in a project
|
|
25
|
+
codetrap init
|
|
26
|
+
|
|
27
|
+
# Record your first trap
|
|
28
|
+
codetrap add --json '{
|
|
29
|
+
"title": "Dont use fetch() without timeout",
|
|
30
|
+
"category": "api",
|
|
31
|
+
"scope": "global",
|
|
32
|
+
"context": "Any external HTTP call in Node/Bun",
|
|
33
|
+
"mistake": "Using bare fetch() which has no default timeout",
|
|
34
|
+
"fix": "Always wrap fetch with AbortSignal.timeout(n)",
|
|
35
|
+
"severity": "critical",
|
|
36
|
+
"tags": ["fetch", "timeout", "http"]
|
|
37
|
+
}'
|
|
38
|
+
|
|
39
|
+
# Search for relevant traps
|
|
40
|
+
codetrap search "HTTP request timeout" --mode hybrid
|
|
41
|
+
|
|
42
|
+
# List all traps
|
|
43
|
+
codetrap list
|
|
44
|
+
|
|
45
|
+
# Show trap details
|
|
46
|
+
codetrap show 1
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Structured trap recording** — title, category, context, mistake, fix, severity, tags, before/after code
|
|
52
|
+
- **Dual scope** — project-scoped (`.codetrap/traps.db`) and global (`~/.codetrap/traps.db`)
|
|
53
|
+
- **Three search modes** — FTS (SQLite FTS5), semantic (Jina embeddings), hybrid (RRF fusion)
|
|
54
|
+
- **Chinese + mixed-language search** — CJK bigram tokenizer, synonym map for Chinese-English terms
|
|
55
|
+
- **MCP server** — 10 tools + 4 resources for AI agent integration
|
|
56
|
+
- **Embedding cache** with freshness tracking — embeddings are rebuildable, stale ones auto-invalidated
|
|
57
|
+
- **Schema migrations** — in-code migration system from v0 through current v3
|
|
58
|
+
- **Single-binary builds** — `bun build --compile` produces standalone binaries in `dist/`
|
|
59
|
+
|
|
60
|
+
## Directory Structure
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
codetrap/
|
|
64
|
+
├── src/
|
|
65
|
+
│ ├── index.ts CLI entry point
|
|
66
|
+
│ ├── mcp-server.ts MCP server entry point
|
|
67
|
+
│ ├── commands/router.ts CLI command dispatch
|
|
68
|
+
│ ├── mcp/
|
|
69
|
+
│ │ ├── server.ts MCP stdio transport + handlers
|
|
70
|
+
│ │ ├── tools.ts 7 MCP tool definitions
|
|
71
|
+
│ │ └── resources.ts 4 MCP resource URIs
|
|
72
|
+
│ ├── domain/trap.ts Trap types, builders, schemas
|
|
73
|
+
│ ├── lib/
|
|
74
|
+
│ │ ├── store.ts Project/global scope orchestration
|
|
75
|
+
│ │ ├── search-service.ts FTS/semantic/hybrid search, RRF fusion
|
|
76
|
+
│ │ ├── search-normalizer.ts CJK bigram, synonyms, search_text
|
|
77
|
+
│ │ ├── fts-query.ts Safe FTS5 literal query compiler
|
|
78
|
+
│ │ ├── embedder.ts Jina Embeddings adapter
|
|
79
|
+
│ │ ├── embedding-job.ts Batch embedding generation
|
|
80
|
+
│ │ ├── format.ts CLI output formatting
|
|
81
|
+
│ │ ├── scope.ts Project root detection
|
|
82
|
+
│ │ └── constants.ts Categories, severities, defaults
|
|
83
|
+
│ ├── db/
|
|
84
|
+
│ │ ├── connection.ts SQLite connection + PRAGMAs
|
|
85
|
+
│ │ ├── schema.ts Schema init + migrations
|
|
86
|
+
│ │ ├── queries.ts CRUD, search, stats, import/export
|
|
87
|
+
│ │ ├── embedding-queries.ts Embedding storage SQL
|
|
88
|
+
│ │ └── repository.ts Single-DB facade
|
|
89
|
+
│ └── tests/
|
|
90
|
+
│ ├── search-safety.test.ts
|
|
91
|
+
│ ├── search-normalizer.test.ts
|
|
92
|
+
│ ├── search-chinese.test.ts
|
|
93
|
+
│ ├── search-semantic.test.ts
|
|
94
|
+
│ ├── search-eval.test.ts
|
|
95
|
+
│ └── fixtures/search-eval.json
|
|
96
|
+
├── skills/ Agent skill definitions
|
|
97
|
+
├── docs/ Architecture + reference docs
|
|
98
|
+
├── package.json
|
|
99
|
+
├── tsconfig.json
|
|
100
|
+
└── CONTEXT.md Full project context for AI agents
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## CLI Commands
|
|
104
|
+
|
|
105
|
+
| Command | Description |
|
|
106
|
+
|---|---|
|
|
107
|
+
| `init` | Initialize `.codetrap/` in current project |
|
|
108
|
+
| `add` | Record a new trap (JSON or interactive) |
|
|
109
|
+
| `search <query>` | Search traps (--mode fts\|semantic\|hybrid) |
|
|
110
|
+
| `list` | List traps (--category, --severity, --scope, --limit) |
|
|
111
|
+
| `show <id>` | Show full trap details |
|
|
112
|
+
| `edit <id>` | Edit a trap |
|
|
113
|
+
| `delete <id>` | Delete a trap |
|
|
114
|
+
| `export` | Export traps to JSON |
|
|
115
|
+
| `import` | Import traps from JSON |
|
|
116
|
+
| `stats` | Show database statistics |
|
|
117
|
+
| `embed` | Generate embeddings (requires JINA_API_KEY) |
|
|
118
|
+
| `serve` | Start MCP server |
|
|
119
|
+
|
|
120
|
+
## Agent Integration
|
|
121
|
+
|
|
122
|
+
For AI coding agents, use three layers:
|
|
123
|
+
|
|
124
|
+
- **MCP** gives the agent structured tools like `search_traps` and `add_trap`.
|
|
125
|
+
- **AGENTS.md / CLAUDE.md** tells the agent when to use codetrap.
|
|
126
|
+
- **CLI** is the fallback that works even when MCP is unavailable.
|
|
127
|
+
|
|
128
|
+
MCP and project guidance are complementary. MCP tells the agent what it can call; `AGENTS.md` or `CLAUDE.md` tells it when to call it.
|
|
129
|
+
|
|
130
|
+
### MCP Setup
|
|
131
|
+
|
|
132
|
+
Codex:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
codex mcp add codetrap -- codetrap serve
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Generic MCP client config:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"mcpServers": {
|
|
143
|
+
"codetrap": {
|
|
144
|
+
"command": "codetrap",
|
|
145
|
+
"args": ["serve"]
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Project Guidance
|
|
152
|
+
|
|
153
|
+
Add this to `AGENTS.md` for Codex, or to `CLAUDE.md` for Claude Code:
|
|
154
|
+
|
|
155
|
+
````md
|
|
156
|
+
## Codetrap
|
|
157
|
+
|
|
158
|
+
Before non-trivial code edits, check codetrap for relevant pitfalls.
|
|
159
|
+
|
|
160
|
+
Prefer MCP tools when available:
|
|
161
|
+
- `search_traps`
|
|
162
|
+
- `get_trap`
|
|
163
|
+
- `add_trap`
|
|
164
|
+
|
|
165
|
+
Fallback to CLI:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
codetrap search "<keywords>" --mode hybrid
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
When a new recurring mistake or project convention is discovered, ask whether to record it with codetrap.
|
|
172
|
+
````
|
|
173
|
+
|
|
174
|
+
Recommended behavior:
|
|
175
|
+
|
|
176
|
+
- Use `search_traps` or `codetrap search` before risky edits in APIs, auth, database, security, migrations, or project conventions.
|
|
177
|
+
- Call `get_trap` for highly relevant results before editing code.
|
|
178
|
+
- Apply the recorded `avoid` and `do_instead` guidance while making changes.
|
|
179
|
+
- Ask before recording a new trap unless the user explicitly requested it.
|
|
180
|
+
|
|
181
|
+
### Codex Skills
|
|
182
|
+
|
|
183
|
+
Codex users can optionally install the bundled skills from `skills/`:
|
|
184
|
+
|
|
185
|
+
- `codetrap-check` — pre-flight check before code changes.
|
|
186
|
+
- `codetrap-search` — search existing lessons.
|
|
187
|
+
- `codetrap-add` — record a new pitfall.
|
|
188
|
+
|
|
189
|
+
Skills are a convenience layer for Codex users. They do not replace MCP or `AGENTS.md`; they make manual triggers like "run codetrap-check" easier.
|
|
190
|
+
|
|
191
|
+
### MCP Tools
|
|
192
|
+
|
|
193
|
+
| Tool | Description |
|
|
194
|
+
|---|---|
|
|
195
|
+
| `search_traps` | Compact action-card search across active traps |
|
|
196
|
+
| `add_trap` | Record a new trap |
|
|
197
|
+
| `get_trap` | Drill down into full trap details and evidence |
|
|
198
|
+
| `list_traps` | List traps with filters |
|
|
199
|
+
| `update_trap` | Edit an existing trap |
|
|
200
|
+
| `delete_trap` | Delete a trap |
|
|
201
|
+
| `add_trap_evidence` | Attach source/evidence metadata |
|
|
202
|
+
| `archive_trap` | Archive a trap so default search skips it |
|
|
203
|
+
| `supersede_trap` | Mark a trap as replaced by another |
|
|
204
|
+
| `get_stats` | Database statistics |
|
|
205
|
+
|
|
206
|
+
### Resources
|
|
207
|
+
|
|
208
|
+
- `codetrap://project/recent` — Recently added project traps
|
|
209
|
+
- `codetrap://global/recent` — Recently added global traps
|
|
210
|
+
- `codetrap://project/top` — Most-hit project traps
|
|
211
|
+
- `codetrap://global/top` — Most-hit global traps
|
|
212
|
+
- `codetrap://{scope}/trap/{id}` — Individual trap by ID
|
|
213
|
+
|
|
214
|
+
## Configuration
|
|
215
|
+
|
|
216
|
+
| Env Variable | Required | Description |
|
|
217
|
+
|---|---|---|
|
|
218
|
+
| `JINA_API_KEY` | No | Jina AI API key for semantic/hybrid search. Without it, hybrid falls back to FTS. Get one at [jina.ai](https://jina.ai/api-dashboard/) |
|
|
219
|
+
|
|
220
|
+
All other behavior is configured via sensible defaults — see `src/lib/constants.ts`.
|
|
221
|
+
|
|
222
|
+
### Jina Embeddings Setup
|
|
223
|
+
|
|
224
|
+
codetrap works without a Jina API key. In that mode, search uses SQLite FTS keyword matching. If you want semantic search or stronger hybrid search, configure `JINA_API_KEY`.
|
|
225
|
+
|
|
226
|
+
1. Create a Jina API key from the [Jina AI dashboard](https://jina.ai/api-dashboard/).
|
|
227
|
+
|
|
228
|
+
2. Add it to your shell environment.
|
|
229
|
+
|
|
230
|
+
macOS or Linux with zsh:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
echo 'export JINA_API_KEY="your-jina-api-key"' >> ~/.zshrc
|
|
234
|
+
source ~/.zshrc
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
macOS or Linux with bash:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
echo 'export JINA_API_KEY="your-jina-api-key"' >> ~/.bashrc
|
|
241
|
+
source ~/.bashrc
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Windows PowerShell:
|
|
245
|
+
|
|
246
|
+
```powershell
|
|
247
|
+
setx JINA_API_KEY "your-jina-api-key"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
After `setx`, open a new PowerShell window.
|
|
251
|
+
|
|
252
|
+
3. Verify that the key is visible without printing the secret:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
bun -e 'console.log(process.env.JINA_API_KEY ? "has-key" : "no-key")'
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
4. Generate embeddings for the traps you want semantic search to use:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
cd /path/to/your/project
|
|
262
|
+
codetrap embed --scope project
|
|
263
|
+
codetrap embed --scope global
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
5. Search with hybrid mode:
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
codetrap search "HTTP request timeout" --mode hybrid
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
If `JINA_API_KEY` is not set:
|
|
273
|
+
|
|
274
|
+
- `codetrap search "<query>" --mode fts` works normally.
|
|
275
|
+
- `codetrap search "<query>" --mode hybrid` works, but falls back to FTS.
|
|
276
|
+
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require `JINA_API_KEY`.
|
|
277
|
+
|
|
278
|
+
## Build
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
bun run build # Build CLI + MCP server binaries → dist/
|
|
282
|
+
bun run build:cli # dist/codetrap
|
|
283
|
+
bun run build:serve # dist/codetrap-serve
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Test
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
bun test src/tests/ # All tests
|
|
290
|
+
bun test src/tests/search-eval.test.ts # Recall@5 evaluation
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## Tech Stack
|
|
294
|
+
|
|
295
|
+
| Layer | Technology |
|
|
296
|
+
|---|---|
|
|
297
|
+
| Runtime | Bun + TypeScript |
|
|
298
|
+
| Database | SQLite (bun:sqlite) + FTS5 |
|
|
299
|
+
| Embeddings | Jina AI (`jina-embeddings-v5-text-small`) |
|
|
300
|
+
| MCP | `@modelcontextprotocol/sdk` |
|
|
301
|
+
| Search | FTS5 + cosine similarity + RRF fusion |
|
|
302
|
+
|
|
303
|
+
## License
|
|
304
|
+
|
|
305
|
+
MIT
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
codetrap supports three installation paths. Use source installation while developing the tool, binary installation for users who do not want a Bun toolchain, and package-manager installation after publishing the package.
|
|
4
|
+
|
|
5
|
+
## Method 1: Source Install
|
|
6
|
+
|
|
7
|
+
Best for developers who want to inspect or modify codetrap.
|
|
8
|
+
|
|
9
|
+
Requirements:
|
|
10
|
+
|
|
11
|
+
- Bun 1.x or newer
|
|
12
|
+
- Git
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone <repo-url>
|
|
16
|
+
cd codetrap
|
|
17
|
+
bun install
|
|
18
|
+
bun run install:cli
|
|
19
|
+
codetrap --help
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`bun run install:cli` creates a `codetrap` symlink in Bun's global bin directory. On macOS and Linux this is usually:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
$(bun pm bin -g)/codetrap
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
After installation, initialize codetrap inside any project:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
cd /path/to/your/project
|
|
32
|
+
codetrap init
|
|
33
|
+
codetrap stats
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use the CLI from any directory:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
codetrap search "HTTP request timeout" --mode hybrid
|
|
40
|
+
codetrap add --json '{
|
|
41
|
+
"title": "Dont use fetch() without timeout",
|
|
42
|
+
"category": "api",
|
|
43
|
+
"scope": "project",
|
|
44
|
+
"context": "Any external HTTP call in Node/Bun",
|
|
45
|
+
"mistake": "Using bare fetch() which has no default timeout",
|
|
46
|
+
"fix": "Always wrap fetch with AbortSignal.timeout(n)",
|
|
47
|
+
"severity": "critical",
|
|
48
|
+
"tags": ["fetch", "timeout", "http"]
|
|
49
|
+
}'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
If you move the codetrap repository after source installation, run this again from the new path:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
bun run install:cli
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Method 2: Binary Install
|
|
59
|
+
|
|
60
|
+
Best for ordinary users who only want the `codetrap` command.
|
|
61
|
+
|
|
62
|
+
This method does not require Bun at runtime once release binaries are published.
|
|
63
|
+
|
|
64
|
+
### For maintainers
|
|
65
|
+
|
|
66
|
+
Release binaries are built by `.github/workflows/release.yml` when a version tag is pushed.
|
|
67
|
+
|
|
68
|
+
1. Make sure `package.json` has the version you want to release.
|
|
69
|
+
|
|
70
|
+
2. Commit all release changes.
|
|
71
|
+
|
|
72
|
+
3. Create and push a matching tag:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
git tag v0.1.0
|
|
76
|
+
git push origin v0.1.0
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The release tag must match `package.json` exactly. For example, package version `0.1.0` must use tag `v0.1.0`.
|
|
80
|
+
|
|
81
|
+
The workflow runs:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
bun test src/tests
|
|
85
|
+
bun run build:release
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
It uploads these release assets:
|
|
89
|
+
|
|
90
|
+
```text
|
|
91
|
+
codetrap-darwin-arm64
|
|
92
|
+
codetrap-darwin-x64
|
|
93
|
+
codetrap-linux-x64
|
|
94
|
+
codetrap-linux-arm64
|
|
95
|
+
codetrap-windows-x64.exe
|
|
96
|
+
sha256sums.txt
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
You can build the same files locally:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
bun run build:release
|
|
103
|
+
ls dist/release
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### For users
|
|
107
|
+
|
|
108
|
+
Download the binary for your platform from GitHub Releases, then install it into a directory on your `PATH`.
|
|
109
|
+
|
|
110
|
+
macOS Apple Silicon:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
curl -L https://github.com/woertedetiankong/codetrap/releases/latest/download/codetrap-darwin-arm64 -o codetrap
|
|
114
|
+
mkdir -p ~/.local/bin
|
|
115
|
+
mv codetrap ~/.local/bin/codetrap
|
|
116
|
+
chmod +x ~/.local/bin/codetrap
|
|
117
|
+
codetrap --help
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
macOS Intel:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
curl -L https://github.com/woertedetiankong/codetrap/releases/latest/download/codetrap-darwin-x64 -o codetrap
|
|
124
|
+
mkdir -p ~/.local/bin
|
|
125
|
+
mv codetrap ~/.local/bin/codetrap
|
|
126
|
+
chmod +x ~/.local/bin/codetrap
|
|
127
|
+
codetrap --help
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Linux x64:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
curl -L https://github.com/woertedetiankong/codetrap/releases/latest/download/codetrap-linux-x64 -o codetrap
|
|
134
|
+
mkdir -p ~/.local/bin
|
|
135
|
+
mv codetrap ~/.local/bin/codetrap
|
|
136
|
+
chmod +x ~/.local/bin/codetrap
|
|
137
|
+
codetrap --help
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Make sure `~/.local/bin` is on your `PATH`. For zsh:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
|
|
144
|
+
source ~/.zshrc
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Windows PowerShell:
|
|
148
|
+
|
|
149
|
+
```powershell
|
|
150
|
+
New-Item -ItemType Directory -Force "$HOME\bin"
|
|
151
|
+
Invoke-WebRequest `
|
|
152
|
+
-Uri "https://github.com/woertedetiankong/codetrap/releases/latest/download/codetrap-windows-x64.exe" `
|
|
153
|
+
-OutFile "$HOME\bin\codetrap.exe"
|
|
154
|
+
codetrap --help
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Then add `%USERPROFILE%\bin` to your user `Path`.
|
|
158
|
+
|
|
159
|
+
## Method 3: Package-Manager Install
|
|
160
|
+
|
|
161
|
+
Best for long-term use after codetrap is published as a package.
|
|
162
|
+
|
|
163
|
+
### For maintainers
|
|
164
|
+
|
|
165
|
+
Package publishing is handled by `.github/workflows/npm-publish.yml` when a GitHub Release is published.
|
|
166
|
+
|
|
167
|
+
Before automated publishing, configure npm trusted publishing:
|
|
168
|
+
|
|
169
|
+
1. Create or log into your npm account.
|
|
170
|
+
2. Make sure the package name `codetrap` is available, or rename the package in `package.json`.
|
|
171
|
+
3. On npmjs.com, open the package settings and add a trusted publisher:
|
|
172
|
+
- Publisher: GitHub Actions
|
|
173
|
+
- Organization/user: `woertedetiankong`
|
|
174
|
+
- Repository: `codetrap`
|
|
175
|
+
- Workflow filename: `npm-publish.yml`
|
|
176
|
+
4. Publish a GitHub Release from the matching version tag.
|
|
177
|
+
|
|
178
|
+
If npm does not let you configure trusted publishing before the first version exists, do the first publish manually after checking the package contents:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
npm pack --dry-run
|
|
182
|
+
npm publish --access public
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Then configure trusted publishing for future releases.
|
|
186
|
+
|
|
187
|
+
The workflow runs:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
bun test src/tests
|
|
191
|
+
npm pack --dry-run
|
|
192
|
+
npm publish --access public
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
The package is source-based: the npm package installs the `codetrap` command from `src/index.ts`, so users still need Bun installed.
|
|
196
|
+
|
|
197
|
+
You can preview the npm package locally:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
npm pack --dry-run
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### For users
|
|
204
|
+
|
|
205
|
+
Bun users can install it globally after publishing:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
bun add -g codetrap
|
|
209
|
+
codetrap --help
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
npm users can install it globally if Bun is also installed, because the CLI entrypoint runs with Bun:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
npm install -g codetrap
|
|
216
|
+
codetrap --help
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Until the package is published, use the source install method:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
git clone <repo-url>
|
|
223
|
+
cd codetrap
|
|
224
|
+
bun install
|
|
225
|
+
bun run install:cli
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Optional: Jina Embeddings
|
|
229
|
+
|
|
230
|
+
`JINA_API_KEY` is optional. Without it, codetrap still works with SQLite FTS keyword search, and hybrid search falls back to FTS.
|
|
231
|
+
|
|
232
|
+
Create a key from the [Jina AI dashboard](https://jina.ai/api-dashboard/), then set it globally if you want semantic or hybrid search to work from every directory.
|
|
233
|
+
|
|
234
|
+
macOS or Linux with zsh:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
echo 'export JINA_API_KEY="your-jina-api-key"' >> ~/.zshrc
|
|
238
|
+
source ~/.zshrc
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
macOS or Linux with bash:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
echo 'export JINA_API_KEY="your-jina-api-key"' >> ~/.bashrc
|
|
245
|
+
source ~/.bashrc
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Windows PowerShell:
|
|
249
|
+
|
|
250
|
+
```powershell
|
|
251
|
+
setx JINA_API_KEY "your-jina-api-key"
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
After `setx`, open a new PowerShell window.
|
|
255
|
+
|
|
256
|
+
Verify that the key is visible without printing the secret:
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
bun -e 'console.log(process.env.JINA_API_KEY ? "has-key" : "no-key")'
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Generate embeddings for the traps you want semantic search to use:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
cd /path/to/your/project
|
|
266
|
+
codetrap embed --scope project
|
|
267
|
+
codetrap embed --scope global
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Then search:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
codetrap search "HTTP request timeout" --mode hybrid
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
If `JINA_API_KEY` is not set:
|
|
277
|
+
|
|
278
|
+
- `codetrap search "<query>" --mode fts` works normally.
|
|
279
|
+
- `codetrap search "<query>" --mode hybrid` works, but falls back to FTS.
|
|
280
|
+
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require `JINA_API_KEY`.
|
|
281
|
+
|
|
282
|
+
## Optional: Codex MCP
|
|
283
|
+
|
|
284
|
+
If the `codetrap` command is on your `PATH`, add it to Codex as an MCP server:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
codex mcp add codetrap -- codetrap serve
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
If your MCP client does not inherit your shell `PATH`, use the absolute path:
|
|
291
|
+
|
|
292
|
+
```bash
|
|
293
|
+
codex mcp add codetrap -- "$(bun pm bin -g)/codetrap" serve
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Agents can also use the CLI directly from `AGENTS.md`:
|
|
297
|
+
|
|
298
|
+
```md
|
|
299
|
+
Before non-trivial code edits, check codetrap:
|
|
300
|
+
|
|
301
|
+
codetrap search "<keywords>" --mode hybrid
|
|
302
|
+
|
|
303
|
+
To add a lesson:
|
|
304
|
+
|
|
305
|
+
codetrap add --json '{...}'
|
|
306
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "codetrap",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Capture and retrieve coding pitfalls so AI doesn't repeat mistakes",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/woertedetiankong/codetrap.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/woertedetiankong/codetrap/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/woertedetiankong/codetrap#readme",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ai",
|
|
17
|
+
"agent",
|
|
18
|
+
"cli",
|
|
19
|
+
"mcp",
|
|
20
|
+
"memory",
|
|
21
|
+
"sqlite"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"bun": ">=1.0.0"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src/commands",
|
|
28
|
+
"src/db",
|
|
29
|
+
"src/domain",
|
|
30
|
+
"src/lib",
|
|
31
|
+
"src/mcp",
|
|
32
|
+
"src/index.ts",
|
|
33
|
+
"src/mcp-server.ts",
|
|
34
|
+
"skills",
|
|
35
|
+
"scripts",
|
|
36
|
+
"docs/installation.md",
|
|
37
|
+
".env.example",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"bin": {
|
|
42
|
+
"codetrap": "./src/index.ts"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dev": "bun run src/index.ts",
|
|
46
|
+
"install:cli": "ln -sf \"$PWD/src/index.ts\" \"$(bun pm bin -g)/codetrap\"",
|
|
47
|
+
"build:release": "bun run scripts/build-release.ts",
|
|
48
|
+
"check:release-version": "bun run scripts/check-release-version.ts",
|
|
49
|
+
"build": "bun build ./src/index.ts --compile --outfile dist/codetrap && bun build ./src/mcp-server.ts --compile --outfile dist/codetrap-serve",
|
|
50
|
+
"build:cli": "bun build ./src/index.ts --compile --outfile dist/codetrap",
|
|
51
|
+
"build:serve": "bun build ./src/mcp-server.ts --compile --outfile dist/codetrap-serve"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/bun": "latest"
|
|
61
|
+
}
|
|
62
|
+
}
|