codetrap 0.1.2 → 0.1.3
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/.agents/plugins/marketplace.json +20 -0
- package/README.md +107 -32
- package/docs/installation.md +18 -10
- package/package.json +4 -1
- package/plugins/codetrap-agent/.codex-plugin/plugin.json +34 -0
- package/plugins/codetrap-agent/hooks/post-flight-capture.example.md +25 -0
- package/plugins/codetrap-agent/hooks/pre-edit.example.sh +10 -0
- package/plugins/codetrap-agent/hooks.json +11 -0
- package/plugins/codetrap-agent/skills/codetrap-capture/SKILL.md +19 -0
- package/plugins/codetrap-agent/skills/codetrap-check/SKILL.md +14 -0
- package/plugins/codetrap-agent/templates/AGENTS.codetrap.md +25 -0
- package/scripts/release-preflight.ts +55 -0
- package/skills/codetrap-add/SKILL.md +4 -1
- package/skills/codetrap-check/SKILL.md +24 -4
- package/skills/codetrap-search/SKILL.md +32 -12
- package/src/commands/command-result.ts +29 -0
- package/src/commands/router.ts +6 -400
- package/src/commands/workflow.ts +466 -0
- package/src/db/embedding-queries.ts +33 -0
- package/src/db/queries.ts +119 -20
- package/src/db/repository.ts +39 -2
- package/src/db/schema.ts +35 -0
- package/src/domain/trap.ts +31 -2
- package/src/index.ts +13 -1
- package/src/lib/config.ts +102 -0
- package/src/lib/constants.ts +1 -1
- package/src/lib/doctor.ts +76 -0
- package/src/lib/embedding-health.ts +49 -0
- package/src/lib/format.ts +5 -1
- package/src/lib/output-json.ts +116 -0
- package/src/lib/scope-context.ts +116 -0
- package/src/lib/scope-migration.ts +360 -0
- package/src/lib/search-normalizer.ts +6 -0
- package/src/lib/search-policy.ts +276 -0
- package/src/lib/search-result-card.ts +1 -0
- package/src/lib/search-service.ts +36 -98
- package/src/lib/store.ts +96 -107
- package/src/lib/trap-archive.ts +9 -42
- package/src/lib/trap-codec.ts +113 -0
- package/src/lib/trap-json-fields.ts +12 -0
- package/src/lib/trap-mutation-result.ts +36 -0
- package/src/lib/trap-operations.ts +27 -6
- package/src/lib/trap-scope-match.ts +112 -0
- package/src/lib/trap-search-document.ts +8 -1
- package/src/lib/trap-transfer.ts +88 -0
- package/src/mcp/server.ts +75 -57
- package/src/mcp/tools.ts +32 -5
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "codetrap-local",
|
|
3
|
+
"interface": {
|
|
4
|
+
"displayName": "codetrap Local"
|
|
5
|
+
},
|
|
6
|
+
"plugins": [
|
|
7
|
+
{
|
|
8
|
+
"name": "codetrap-agent",
|
|
9
|
+
"source": {
|
|
10
|
+
"source": "local",
|
|
11
|
+
"path": "./plugins/codetrap-agent"
|
|
12
|
+
},
|
|
13
|
+
"policy": {
|
|
14
|
+
"installation": "AVAILABLE",
|
|
15
|
+
"authentication": "ON_INSTALL"
|
|
16
|
+
},
|
|
17
|
+
"category": "Productivity"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> A local-first coding pitfall memory bank — record mistakes once, never repeat them twice.
|
|
4
4
|
|
|
5
|
-
**codetrap** records structured coding pitfalls ("traps") and provides search across them before you write code. It
|
|
5
|
+
**codetrap** records structured coding pitfalls ("traps") and provides search across them before you write code. It is CLI-first for humans and AI coding agents, with an optional MCP (Model Context Protocol) adapter for clients that prefer tool schemas.
|
|
6
6
|
|
|
7
7
|
## Why?
|
|
8
8
|
|
|
@@ -36,9 +36,12 @@ codetrap add --json '{
|
|
|
36
36
|
"tags": ["fetch", "timeout", "http"]
|
|
37
37
|
}'
|
|
38
38
|
|
|
39
|
-
# Search for relevant traps
|
|
39
|
+
# Search for relevant traps as a human
|
|
40
40
|
codetrap search "HTTP request timeout" --mode hybrid
|
|
41
41
|
|
|
42
|
+
# Search for relevant traps as an agent
|
|
43
|
+
codetrap search "HTTP request timeout" --mode hybrid --json
|
|
44
|
+
|
|
42
45
|
# List all traps
|
|
43
46
|
codetrap list
|
|
44
47
|
|
|
@@ -50,11 +53,13 @@ codetrap show 1
|
|
|
50
53
|
|
|
51
54
|
- **Structured trap recording** — title, category, context, mistake, fix, severity, tags, lifecycle, evidence, before/after code
|
|
52
55
|
- **Dual scope** — project-scoped (`.codetrap/traps.db`) and global (`~/.codetrap/traps.db`)
|
|
56
|
+
- **CLI-first agent API** — `search/show/list/stats/doctor --json` and stdin query support for shell-friendly automation
|
|
53
57
|
- **Three search modes** — FTS (SQLite FTS5), semantic (Jina embeddings), hybrid (RRF fusion)
|
|
54
58
|
- **Chinese + mixed-language search** — CJK bigram tokenizer, synonym map for Chinese-English terms
|
|
55
|
-
- **MCP server** —
|
|
59
|
+
- **MCP server** — optional tools + resources for AI agent integration
|
|
56
60
|
- **Embedding cache** with freshness tracking — embeddings are rebuildable, stale ones auto-invalidated
|
|
57
|
-
- **
|
|
61
|
+
- **Doctor diagnostics** — scope, database, and embedding health in text or JSON
|
|
62
|
+
- **Schema migrations** — in-code migration system from v0 through current v5
|
|
58
63
|
- **Single-binary builds** — `bun build --compile` produces standalone binaries in `dist/`
|
|
59
64
|
|
|
60
65
|
## Directory Structure
|
|
@@ -64,7 +69,9 @@ codetrap/
|
|
|
64
69
|
├── src/
|
|
65
70
|
│ ├── index.ts CLI entry point
|
|
66
71
|
│ ├── mcp-server.ts MCP server entry point
|
|
67
|
-
│ ├── commands/router.ts CLI
|
|
72
|
+
│ ├── commands/router.ts Thin CLI adapter + renderer
|
|
73
|
+
│ ├── commands/workflow.ts CLI command behavior
|
|
74
|
+
│ ├── commands/command-result.ts CLI command results + rendering
|
|
68
75
|
│ ├── mcp/
|
|
69
76
|
│ │ ├── server.ts MCP stdio transport + handlers
|
|
70
77
|
│ │ ├── tools.ts 10 MCP tool definitions
|
|
@@ -73,13 +80,23 @@ codetrap/
|
|
|
73
80
|
│ ├── lib/
|
|
74
81
|
│ │ ├── store.ts Project/global scope orchestration
|
|
75
82
|
│ │ ├── trap-operations.ts Shared CLI/MCP operation semantics
|
|
76
|
-
│ │ ├──
|
|
83
|
+
│ │ ├── output-json.ts Shared CLI/MCP JSON presenters
|
|
84
|
+
│ │ ├── scope-context.ts cwd/project/global DB context + repo selection
|
|
85
|
+
│ │ ├── scope-migration.ts Safe project trap scope repair/migration
|
|
86
|
+
│ │ ├── doctor.ts Scope and embedding health diagnostics
|
|
87
|
+
│ │ ├── embedding-health.ts Fresh/stale/missing embedding summaries
|
|
88
|
+
│ │ ├── search-service.ts FTS/semantic/hybrid candidate retrieval
|
|
89
|
+
│ │ ├── search-policy.ts Applicability filtering, rerank, fusion signals
|
|
77
90
|
│ │ ├── search-result-card.ts Compact agent-facing result cards
|
|
78
91
|
│ │ ├── search-normalizer.ts CJK bigram, synonyms, search_text
|
|
79
92
|
│ │ ├── fts-query.ts Safe FTS5 literal query compiler
|
|
80
93
|
│ │ ├── trap-search-document.ts Derived search text + embedding passage
|
|
81
|
-
│ │ ├── trap-json-fields.ts Tags/evidence JSON array codec
|
|
94
|
+
│ │ ├── trap-json-fields.ts Tags/path/evidence JSON array codec
|
|
95
|
+
│ │ ├── trap-codec.ts Storage/JSON/archive/import shape conversion
|
|
96
|
+
│ │ ├── trap-mutation-result.ts Mutation result + scope fallback semantics
|
|
97
|
+
│ │ ├── trap-scope-match.ts Path/module/owner applicability matching
|
|
82
98
|
│ │ ├── trap-archive.ts Import/export compatibility
|
|
99
|
+
│ │ ├── trap-transfer.ts DB-to-DB transfer for scope migration
|
|
83
100
|
│ │ ├── embedder.ts Jina Embeddings adapter
|
|
84
101
|
│ │ ├── embedding-job.ts Batch embedding generation
|
|
85
102
|
│ │ ├── format.ts CLI output formatting
|
|
@@ -96,9 +113,12 @@ codetrap/
|
|
|
96
113
|
│ ├── trap-*.test.ts
|
|
97
114
|
│ ├── mcp-tools.test.ts
|
|
98
115
|
│ ├── scope.test.ts
|
|
116
|
+
│ ├── scope-migration-cli.test.ts
|
|
99
117
|
│ ├── import-export-cli.test.ts
|
|
100
118
|
│ └── fixtures/search-eval.json
|
|
101
119
|
├── skills/ Agent skill definitions
|
|
120
|
+
├── plugins/codetrap-agent/ Sample Codex plugin bundle
|
|
121
|
+
├── scripts/ Release asset and preflight scripts
|
|
102
122
|
├── docs/ Architecture + reference docs
|
|
103
123
|
├── package.json
|
|
104
124
|
├── tsconfig.json
|
|
@@ -111,29 +131,32 @@ codetrap/
|
|
|
111
131
|
|---|---|
|
|
112
132
|
| `init` | Initialize `.codetrap/` in current project |
|
|
113
133
|
| `add` | Record a new trap (`--json` structured input; interactive mode is not implemented) |
|
|
114
|
-
| `search <query>` | Search traps (--mode fts\|semantic\|hybrid, --category, --scope, --status, --limit) |
|
|
115
|
-
| `list` | List traps (--category, --scope, --status, --limit) |
|
|
116
|
-
| `show <id>` | Show full trap details |
|
|
117
|
-
| `edit <id>` | Edit a trap |
|
|
118
|
-
| `delete <id>` | Delete a trap |
|
|
119
|
-
| `add_trap_evidence <id>` | Attach source/evidence metadata |
|
|
120
|
-
| `archive_trap <id>` | Archive a trap so default search skips it |
|
|
121
|
-
| `supersede_trap <old_id> <new_id>` | Mark one trap as replaced by another |
|
|
134
|
+
| `search <query>` | Search traps (--mode fts\|semantic\|hybrid, --category, --scope, --status, --limit, --path, --module, --owner, --no-rerank, --ranking-signals, --json; query can come from stdin) |
|
|
135
|
+
| `list` | List traps (--category, --scope, --status, --path, --module, --owner, --limit, --json) |
|
|
136
|
+
| `show <id>` | Show full trap details (--json) |
|
|
137
|
+
| `edit <id>` | Edit a trap (`--json` input, `--output-json` output) |
|
|
138
|
+
| `delete <id>` | Delete a trap (--json) |
|
|
139
|
+
| `add_trap_evidence <id>` | Attach source/evidence metadata (--output-json) |
|
|
140
|
+
| `archive_trap <id>` | Archive a trap so default search skips it (--json) |
|
|
141
|
+
| `supersede_trap <old_id> <new_id>` | Mark one trap as replaced by another (--json) |
|
|
122
142
|
| `export` | Export traps to JSON |
|
|
123
|
-
| `import` | Import traps from JSON |
|
|
124
|
-
| `stats` | Show database statistics |
|
|
143
|
+
| `import` | Import traps from JSON (--json) |
|
|
144
|
+
| `stats` | Show database statistics (--json includes embedding health) |
|
|
145
|
+
| `doctor` | Diagnose cwd, scope, database paths, trap counts, and embedding health (--json) |
|
|
146
|
+
| `repair-scope` | Move legacy mis-scoped project traps into the current project (dry-run by default, `--apply` to mutate, `--json`) |
|
|
147
|
+
| `migrate-project` | Move project traps between initialized projects (`--from-project-path`, `--to-project-path`, dry-run by default, `--apply`, `--json`) |
|
|
125
148
|
| `embed` | Generate embeddings (requires JINA_API_KEY) |
|
|
126
149
|
| `serve` | Start MCP server |
|
|
127
150
|
|
|
128
151
|
## Agent Integration
|
|
129
152
|
|
|
130
|
-
For AI coding agents, use
|
|
153
|
+
For AI coding agents, use the CLI as the default integration path:
|
|
131
154
|
|
|
132
|
-
- **
|
|
155
|
+
- **CLI JSON** is the primary agent API and works in any client that can run shell commands.
|
|
133
156
|
- **AGENTS.md / CLAUDE.md** tells the agent when to use codetrap.
|
|
134
|
-
- **
|
|
157
|
+
- **MCP** is an optional adapter for clients that prefer tool schemas.
|
|
135
158
|
|
|
136
|
-
|
|
159
|
+
CLI and project guidance are the main path. MCP should stay thin and share the same store/search behavior.
|
|
137
160
|
|
|
138
161
|
### MCP Setup
|
|
139
162
|
|
|
@@ -165,26 +188,37 @@ Add this to `AGENTS.md` for Codex, or to `CLAUDE.md` for Claude Code:
|
|
|
165
188
|
|
|
166
189
|
Before non-trivial code edits, check codetrap for relevant pitfalls.
|
|
167
190
|
|
|
168
|
-
|
|
169
|
-
- `search_traps`
|
|
170
|
-
- `get_trap`
|
|
171
|
-
- `add_trap`
|
|
191
|
+
Default to CLI JSON from the current project cwd:
|
|
172
192
|
|
|
173
|
-
|
|
193
|
+
```bash
|
|
194
|
+
codetrap search "<keywords>" --mode hybrid --json
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Read the top 3 action cards before deciding no trap applies. If a card is highly relevant, or has `critical`/`error` severity and is plausibly related, inspect it before editing:
|
|
174
198
|
|
|
175
199
|
```bash
|
|
176
|
-
codetrap
|
|
200
|
+
codetrap show <id> --scope <project|global> --json
|
|
177
201
|
```
|
|
178
202
|
|
|
203
|
+
When `.codetrap/` exists, prefer project scope for project conventions. Use global for cross-project rules.
|
|
204
|
+
|
|
205
|
+
MCP tools are optional:
|
|
206
|
+
- `search_traps`
|
|
207
|
+
- `get_trap`
|
|
208
|
+
- `add_trap`
|
|
209
|
+
|
|
179
210
|
When a new recurring mistake or project convention is discovered, ask whether to record it with codetrap.
|
|
180
211
|
````
|
|
181
212
|
|
|
182
213
|
Recommended behavior:
|
|
183
214
|
|
|
184
|
-
- Use `
|
|
185
|
-
-
|
|
215
|
+
- Use `codetrap search --json` before risky edits in APIs, auth, database, security, migrations, or project conventions.
|
|
216
|
+
- Read the top 3 returned action cards, or all returned cards if fewer than 3, before deciding there is no relevant trap.
|
|
217
|
+
- Run the returned `next_action.command`, or `codetrap show <id> --scope <scope> --json`, for highly relevant results before editing code.
|
|
218
|
+
- Treat `critical` or `error` traps as worth drilling into when they are plausibly related, even if they are not ranked first.
|
|
219
|
+
- When editing a known area, pass applicability hints such as `--path src/db/repository.ts --module db`.
|
|
186
220
|
- Apply the recorded `avoid` and `do_instead` guidance while making changes.
|
|
187
|
-
- Ask before recording a new trap unless the user explicitly requested it.
|
|
221
|
+
- After user corrections, repeated test failures, or review feedback, propose a post-flight trap capture. Ask before recording a new trap unless the user explicitly requested it.
|
|
188
222
|
|
|
189
223
|
### Codex Skills
|
|
190
224
|
|
|
@@ -196,6 +230,8 @@ Codex users can optionally install the bundled skills from `skills/`:
|
|
|
196
230
|
|
|
197
231
|
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.
|
|
198
232
|
|
|
233
|
+
The repo also includes a sample Codex plugin bundle at `plugins/codetrap-agent` with skills, optional MCP config, hook templates, and an `AGENTS.md` snippet.
|
|
234
|
+
|
|
199
235
|
### MCP Tools
|
|
200
236
|
|
|
201
237
|
| Tool | Description |
|
|
@@ -219,13 +255,50 @@ Skills are a convenience layer for Codex users. They do not replace MCP or `AGEN
|
|
|
219
255
|
- `codetrap://global/top` — Most-hit global traps
|
|
220
256
|
- `codetrap://{scope}/trap/{id}` — Individual trap by ID
|
|
221
257
|
|
|
258
|
+
Resources can accept an optional encoded `cwd` query parameter when the client knows the target workspace:
|
|
259
|
+
|
|
260
|
+
```text
|
|
261
|
+
codetrap://project/recent?cwd=%2Fpath%2Fto%2Fproject
|
|
262
|
+
```
|
|
263
|
+
|
|
222
264
|
## Configuration
|
|
223
265
|
|
|
224
266
|
| Env Variable | Required | Description |
|
|
225
267
|
|---|---|---|
|
|
226
268
|
| `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/) |
|
|
269
|
+
| `CODETRAP_SEARCH_MODE` | No | Default search mode: `fts`, `semantic`, or `hybrid` |
|
|
270
|
+
| `CODETRAP_SEARCH_LIMIT` | No | Default search result limit |
|
|
271
|
+
| `CODETRAP_SEARCH_SCOPE` | No | Default search scope: `project` or `global` |
|
|
272
|
+
| `CODETRAP_RERANK` | No | Enable query-aware reranking (`true`/`false`) |
|
|
273
|
+
|
|
274
|
+
Behavior preferences can also live in `~/.codetrap/config.json`; CLI args override config, config overrides env vars, and env vars override built-in defaults.
|
|
275
|
+
|
|
276
|
+
```json
|
|
277
|
+
{
|
|
278
|
+
"search": {
|
|
279
|
+
"mode": "hybrid",
|
|
280
|
+
"limit": 20,
|
|
281
|
+
"scope": "project",
|
|
282
|
+
"rerank": true
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
API keys still belong in environment variables, not config files.
|
|
288
|
+
|
|
289
|
+
### Scoped Traps
|
|
290
|
+
|
|
291
|
+
Trap JSON supports optional applicability fields:
|
|
292
|
+
|
|
293
|
+
```json
|
|
294
|
+
{
|
|
295
|
+
"path_globs": ["src/db/**"],
|
|
296
|
+
"module": "db",
|
|
297
|
+
"owner": "platform"
|
|
298
|
+
}
|
|
299
|
+
```
|
|
227
300
|
|
|
228
|
-
|
|
301
|
+
Empty applicability fields mean the trap applies everywhere. `search` and `list` can filter with `--path`, `--module`, and `--owner`; matching scoped traps receive a small rerank boost.
|
|
229
302
|
|
|
230
303
|
### Jina Embeddings Setup
|
|
231
304
|
|
|
@@ -289,6 +362,8 @@ If `JINA_API_KEY` is not set:
|
|
|
289
362
|
bun run build # Build CLI + MCP server binaries → dist/
|
|
290
363
|
bun run build:cli # dist/codetrap
|
|
291
364
|
bun run build:serve # dist/codetrap-serve
|
|
365
|
+
bunx tsc --noEmit # Type-check without emitting files
|
|
366
|
+
bun run release:preflight # tests, builds, release assets, smoke test, npm dry-runs
|
|
292
367
|
```
|
|
293
368
|
|
|
294
369
|
## Test
|
|
@@ -306,7 +381,7 @@ bun test src/tests/search-eval.test.ts # Recall@5 evaluation
|
|
|
306
381
|
| Database | SQLite (bun:sqlite) + FTS5 |
|
|
307
382
|
| Embeddings | Jina AI (`jina-embeddings-v5-text-small`) |
|
|
308
383
|
| MCP | `@modelcontextprotocol/sdk` |
|
|
309
|
-
| Search | FTS5 + cosine similarity + RRF fusion |
|
|
384
|
+
| Search | FTS5 + cosine similarity + RRF fusion + generic rerank |
|
|
310
385
|
|
|
311
386
|
## License
|
|
312
387
|
|
package/docs/installation.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Installation
|
|
2
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
|
|
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 for the published `codetrap` package.
|
|
4
4
|
|
|
5
5
|
## Method 1: Source Install
|
|
6
6
|
|
|
@@ -72,11 +72,11 @@ Release binaries are built by `.github/workflows/release.yml` when a version tag
|
|
|
72
72
|
3. Create and push a matching tag:
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
|
-
git tag v0.1.
|
|
76
|
-
git push origin v0.1.
|
|
75
|
+
git tag v0.1.2
|
|
76
|
+
git push origin v0.1.2
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
The release tag must match `package.json` exactly. For example, package version `0.1.
|
|
79
|
+
The release tag must match `package.json` exactly. For example, package version `0.1.2` must use tag `v0.1.2`.
|
|
80
80
|
|
|
81
81
|
The workflow runs:
|
|
82
82
|
|
|
@@ -158,7 +158,7 @@ Then add `%USERPROFILE%\bin` to your user `Path`.
|
|
|
158
158
|
|
|
159
159
|
## Method 3: Package-Manager Install
|
|
160
160
|
|
|
161
|
-
Best for long-term use
|
|
161
|
+
Best for long-term use with the published `codetrap` package.
|
|
162
162
|
|
|
163
163
|
### For maintainers
|
|
164
164
|
|
|
@@ -202,7 +202,7 @@ npm pack --dry-run
|
|
|
202
202
|
|
|
203
203
|
### For users
|
|
204
204
|
|
|
205
|
-
Bun users can install it globally
|
|
205
|
+
Bun users can install it globally:
|
|
206
206
|
|
|
207
207
|
```bash
|
|
208
208
|
bun add -g codetrap
|
|
@@ -216,7 +216,7 @@ npm install -g codetrap
|
|
|
216
216
|
codetrap --help
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
-
|
|
219
|
+
For local development or unpublished branch testing, use the source install method:
|
|
220
220
|
|
|
221
221
|
```bash
|
|
222
222
|
git clone <repo-url>
|
|
@@ -296,11 +296,19 @@ codex mcp add codetrap -- "$(bun pm bin -g)/codetrap" serve
|
|
|
296
296
|
Agents can also use the CLI directly from `AGENTS.md`:
|
|
297
297
|
|
|
298
298
|
```md
|
|
299
|
-
Before non-trivial code edits, check codetrap:
|
|
299
|
+
Before non-trivial code edits, check codetrap from the current project cwd:
|
|
300
300
|
|
|
301
|
-
codetrap search "<keywords>" --mode hybrid
|
|
301
|
+
codetrap search "<keywords>" --mode hybrid --json
|
|
302
|
+
|
|
303
|
+
Review the top 3 action cards before deciding no trap applies. If a critical/error result is plausibly related, inspect it before editing:
|
|
304
|
+
|
|
305
|
+
codetrap show <id> --scope <project|global> --json
|
|
306
|
+
|
|
307
|
+
When editing a known area, pass applicability hints:
|
|
308
|
+
|
|
309
|
+
codetrap search "<keywords>" --path src/db/repository.ts --module db --json
|
|
302
310
|
|
|
303
311
|
To add a lesson:
|
|
304
312
|
|
|
305
|
-
codetrap add --json '{...}'
|
|
313
|
+
codetrap add --json '{...}' --output-json
|
|
306
314
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codetrap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Capture and retrieve coding pitfalls so AI doesn't repeat mistakes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"src/index.ts",
|
|
34
34
|
"src/mcp-server.ts",
|
|
35
35
|
"skills",
|
|
36
|
+
"plugins",
|
|
37
|
+
".agents/plugins/marketplace.json",
|
|
36
38
|
"scripts",
|
|
37
39
|
"docs/installation.md",
|
|
38
40
|
".env.example",
|
|
@@ -46,6 +48,7 @@
|
|
|
46
48
|
"dev": "bun run src/index.ts",
|
|
47
49
|
"install:cli": "ln -sf \"$PWD/bin/codetrap\" \"$(bun pm bin -g)/codetrap\"",
|
|
48
50
|
"build:release": "bun run scripts/build-release.ts",
|
|
51
|
+
"release:preflight": "bun run scripts/release-preflight.ts",
|
|
49
52
|
"check:release-version": "bun run scripts/check-release-version.ts",
|
|
50
53
|
"build": "bun build ./src/index.ts --compile --outfile dist/codetrap && bun build ./src/mcp-server.ts --compile --outfile dist/codetrap-serve",
|
|
51
54
|
"build:cli": "bun build ./src/index.ts --compile --outfile dist/codetrap",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "codetrap-agent",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "CLI-first codetrap integration bundle for coding agents.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "codetrap maintainers",
|
|
7
|
+
"email": "maintainers@example.com",
|
|
8
|
+
"url": "https://github.com/woertedetiankong/codetrap"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/woertedetiankong/codetrap#readme",
|
|
11
|
+
"repository": "https://github.com/woertedetiankong/codetrap",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"keywords": ["agent", "memory", "cli", "mcp", "pitfalls"],
|
|
14
|
+
"skills": "./skills/",
|
|
15
|
+
"hooks": "./hooks.json",
|
|
16
|
+
"mcpServers": "./.mcp.json",
|
|
17
|
+
"interface": {
|
|
18
|
+
"displayName": "codetrap Agent",
|
|
19
|
+
"shortDescription": "Check local pitfall memory before code changes.",
|
|
20
|
+
"longDescription": "Installs CLI-first guidance, optional MCP config, and example hooks so coding agents can search codetrap before risky edits and propose new trap captures after failures.",
|
|
21
|
+
"developerName": "codetrap maintainers",
|
|
22
|
+
"category": "Productivity",
|
|
23
|
+
"capabilities": ["Tools", "Memory", "Code"],
|
|
24
|
+
"websiteURL": "https://github.com/woertedetiankong/codetrap",
|
|
25
|
+
"privacyPolicyURL": "https://github.com/woertedetiankong/codetrap#readme",
|
|
26
|
+
"termsOfServiceURL": "https://github.com/woertedetiankong/codetrap/blob/main/LICENSE",
|
|
27
|
+
"defaultPrompt": [
|
|
28
|
+
"Check codetrap before editing this code.",
|
|
29
|
+
"Search prior pitfalls for this task.",
|
|
30
|
+
"Propose a codetrap for this failure."
|
|
31
|
+
],
|
|
32
|
+
"brandColor": "#2563EB"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Post-flight Codetrap Capture
|
|
2
|
+
|
|
3
|
+
Use this template after a task reveals a reusable pitfall. Do not write the trap automatically; ask the user to confirm first.
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"title": "Short pitfall title",
|
|
8
|
+
"category": "bug",
|
|
9
|
+
"scope": "project",
|
|
10
|
+
"context": "When this situation appears...",
|
|
11
|
+
"mistake": "The agent tends to...",
|
|
12
|
+
"fix": "Do this instead...",
|
|
13
|
+
"tags": ["area", "tool"],
|
|
14
|
+
"severity": "warning",
|
|
15
|
+
"path_globs": ["src/example/**"],
|
|
16
|
+
"module": "example",
|
|
17
|
+
"owner": "platform"
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
After confirmation:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
codetrap add --json '<json above>' --output-json
|
|
25
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Example codetrap hook bundle. Treat these commands as templates for clients with hook support.",
|
|
3
|
+
"pre_edit": {
|
|
4
|
+
"description": "Before non-trivial edits, search local pitfalls from the target project cwd.",
|
|
5
|
+
"command": "codetrap search \"$CODETRAP_QUERY\" --mode hybrid --json"
|
|
6
|
+
},
|
|
7
|
+
"post_task": {
|
|
8
|
+
"description": "After repeated failures or user corrections, propose a structured trap; write only after user confirmation.",
|
|
9
|
+
"command": "codetrap add --json '{...}' --output-json"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codetrap-capture
|
|
3
|
+
description: Propose a new codetrap after repeated failures, user corrections, or review feedback.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Use this after a task exposes a recurring mistake pattern. Draft a candidate trap with:
|
|
7
|
+
|
|
8
|
+
- triggering context
|
|
9
|
+
- mistake to avoid
|
|
10
|
+
- fix to apply next time
|
|
11
|
+
- severity
|
|
12
|
+
- tags
|
|
13
|
+
- optional `path_globs`, `module`, and `owner`
|
|
14
|
+
|
|
15
|
+
Ask the user to confirm before writing. After confirmation, run:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
codetrap add --json '{...}' --output-json
|
|
19
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codetrap-check
|
|
3
|
+
description: Check codetrap from the current project cwd before non-trivial code edits.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Before risky code changes, run:
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
codetrap search "<task keywords>" --mode hybrid --json
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Review the top 3 action cards. If a card is highly relevant, or has `critical` or `error` severity and is plausibly related, run its `next_action.command` before editing.
|
|
13
|
+
|
|
14
|
+
Use MCP only as an optional adapter. When calling MCP tools, pass `cwd` when the client supports it.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## Codetrap
|
|
2
|
+
|
|
3
|
+
Before non-trivial code edits, check local pitfall memory from the current project cwd:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
codetrap search "<keywords>" --mode hybrid --json
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Review the top 3 action cards before deciding no trap applies. If a card is highly relevant, or has `critical` or `error` severity and is plausibly related, inspect it before editing:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
codetrap show <id> --scope <project|global> --json
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
When editing a specific area, pass applicability hints:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
codetrap search "<keywords>" --path src/db/repository.ts --module db --json
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
After user corrections, repeated test failures, or review feedback, propose a new trap. Only write it after user confirmation:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
codetrap add --json '{...}' --output-json
|
|
25
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
const tag = process.argv[2] ?? process.env.RELEASE_TAG;
|
|
4
|
+
const packageJson = await Bun.file("package.json").json() as { name?: string; version?: string };
|
|
5
|
+
const published = await packageVersionExists(packageJson.name, packageJson.version);
|
|
6
|
+
|
|
7
|
+
const commands: { name: string; cmd: string[]; optional?: boolean }[] = [
|
|
8
|
+
...(tag ? [{ name: "check release version", cmd: ["bun", "run", "check:release-version", tag] }] : []),
|
|
9
|
+
{ name: "test", cmd: ["bun", "test", "src/tests"] },
|
|
10
|
+
{ name: "build", cmd: ["bun", "run", "build"] },
|
|
11
|
+
{ name: "build release assets", cmd: ["bun", "run", "build:release"] },
|
|
12
|
+
{ name: "smoke test release binary", cmd: [hostBinaryPath(), "--help"] },
|
|
13
|
+
{ name: "npm pack dry-run", cmd: ["npm", "pack", "--dry-run"] },
|
|
14
|
+
...(!published ? [{ name: "npm publish dry-run", cmd: ["npm", "publish", "--dry-run", "--access", "public"] }] : []),
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
for (const step of commands) {
|
|
18
|
+
console.log(`\n==> ${step.name}`);
|
|
19
|
+
const proc = Bun.spawnSync({
|
|
20
|
+
cmd: step.cmd,
|
|
21
|
+
stdout: "inherit",
|
|
22
|
+
stderr: "inherit",
|
|
23
|
+
});
|
|
24
|
+
if (!proc.success) {
|
|
25
|
+
console.error(`Release preflight failed at: ${step.name}`);
|
|
26
|
+
process.exit(proc.exitCode ?? 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (published) {
|
|
31
|
+
console.log(`\nSkipped npm publish dry-run because ${packageJson.name}@${packageJson.version} is already published.`);
|
|
32
|
+
}
|
|
33
|
+
console.log("\nRelease preflight passed. No package was published and no GitHub release was created.");
|
|
34
|
+
|
|
35
|
+
function hostBinaryPath(): string {
|
|
36
|
+
const platform = process.platform;
|
|
37
|
+
const arch = process.arch;
|
|
38
|
+
if (platform === "darwin" && arch === "arm64") return "./dist/release/codetrap-darwin-arm64";
|
|
39
|
+
if (platform === "darwin" && arch === "x64") return "./dist/release/codetrap-darwin-x64";
|
|
40
|
+
if (platform === "linux" && arch === "arm64") return "./dist/release/codetrap-linux-arm64";
|
|
41
|
+
if (platform === "linux" && arch === "x64") return "./dist/release/codetrap-linux-x64";
|
|
42
|
+
if (platform === "win32" && arch === "x64") return "./dist/release/codetrap-windows-x64.exe";
|
|
43
|
+
throw new Error(`Unsupported release smoke-test platform: ${platform}/${arch}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function packageVersionExists(name?: string, version?: string): Promise<boolean> {
|
|
47
|
+
if (!name || !version) return false;
|
|
48
|
+
const proc = Bun.spawnSync({
|
|
49
|
+
cmd: ["npm", "view", `${name}@${version}`, "version", "--json"],
|
|
50
|
+
stdout: "pipe",
|
|
51
|
+
stderr: "pipe",
|
|
52
|
+
});
|
|
53
|
+
if (!proc.success) return false;
|
|
54
|
+
return new TextDecoder().decode(proc.stdout).trim().replace(/^"|"$/g, "") === version;
|
|
55
|
+
}
|
|
@@ -50,9 +50,12 @@ codetrap add --json '{
|
|
|
50
50
|
"fix": "<what should be done instead>",
|
|
51
51
|
"tags": ["<tag1>", "<tag2>"],
|
|
52
52
|
"severity": "<warning|error|critical>",
|
|
53
|
+
"path_globs": ["src/example/**"],
|
|
54
|
+
"module": "<optional subsystem>",
|
|
55
|
+
"owner": "<optional team>",
|
|
53
56
|
"before_code": "<wrong code snippet (optional)>",
|
|
54
57
|
"after_code": "<correct code snippet (optional)>"
|
|
55
|
-
}'
|
|
58
|
+
}' --output-json
|
|
56
59
|
```
|
|
57
60
|
|
|
58
61
|
If the CLI is not available, use the MCP tool `add_trap` instead.
|
|
@@ -23,13 +23,33 @@ From the user's request, extract search keywords. Focus on:
|
|
|
23
23
|
|
|
24
24
|
## Step 2: Search the database
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Default to the CLI from the current project cwd:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
codetrap search "<keywords>" --mode hybrid --json
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
When the task targets a known file or subsystem, include applicability hints:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
codetrap search "<keywords>" --path src/db/repository.ts --module db --json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
If the query comes from another tool, stdin is also supported:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
echo "<keywords>" | codetrap search --mode hybrid --json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
MCP `search_traps` is optional. Use it only when it is already available and project-scoped correctly; pass `cwd` when the client supports it.
|
|
45
|
+
|
|
46
|
+
Review the top 3 returned action cards before deciding that no trap applies. Do not stop after only the first result; relevant traps may rank second or third. If fewer than 3 cards are returned, review all returned cards.
|
|
27
47
|
|
|
28
48
|
## Step 3: Apply the lessons
|
|
29
49
|
|
|
30
|
-
For each relevant trap found:
|
|
50
|
+
For each relevant trap found in the reviewed top cards:
|
|
31
51
|
1. Read the action card's `avoid` and `do_instead`
|
|
32
|
-
2. If the card is highly relevant and you are about to edit code, call `get_trap` with `next_action.details_args.id` and `next_action.details_args.scope`
|
|
52
|
+
2. If the card is highly relevant, or has `critical`/`error` severity and is plausibly related, and you are about to edit code, run `next_action.command` from CLI JSON; with MCP, call `get_trap` with `next_action.details_args.id` and `next_action.details_args.scope`
|
|
33
53
|
3. Adjust your code generation to follow the correct approach
|
|
34
54
|
4. If a trap matches exactly what you were about to do, explicitly tell the user: "I was about to [avoid], but the codetrap database says [do_instead]. I'll do it the right way."
|
|
35
55
|
|
|
@@ -44,4 +64,4 @@ If no traps found, say nothing — don't waste tokens.
|
|
|
44
64
|
|
|
45
65
|
## Step 5: Record new pitfalls
|
|
46
66
|
|
|
47
|
-
If while writing code you discover a NEW pitfall that isn't in the database,
|
|
67
|
+
If while writing code you discover a NEW pitfall that isn't in the database, propose a post-flight trap candidate. Do not write it automatically; ask: "This seems like a recurring pitfall. Want me to record it with `/codetrap-add`?"
|