codetrap 0.1.6 → 0.1.8
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/README.md +159 -51
- package/docs/installation.md +113 -29
- package/package.json +4 -3
- package/plugins/codetrap-agent/.codex-plugin/plugin.json +1 -2
- package/plugins/codetrap-agent/hooks/post-flight-capture.example.md +19 -17
- package/plugins/codetrap-agent/hooks.json +2 -2
- package/{skills → plugins/codetrap-agent/skills}/codetrap-add/SKILL.md +10 -4
- package/plugins/codetrap-agent/skills/codetrap-capture/SKILL.md +14 -3
- package/plugins/codetrap-agent/skills/codetrap-capture-external/SKILL.md +52 -9
- package/plugins/codetrap-agent/skills/codetrap-check/SKILL.md +74 -6
- package/{skills → plugins/codetrap-agent/skills}/codetrap-search/SKILL.md +6 -5
- package/plugins/codetrap-agent/templates/AGENTS.codetrap.md +31 -5
- package/scripts/search-policy-sweep.ts +131 -0
- package/src/commands/workflow.ts +186 -68
- package/src/db/connection.ts +6 -6
- package/src/db/embedding-queries.ts +230 -48
- package/src/db/queries.ts +0 -25
- package/src/db/repository.ts +32 -21
- package/src/db/schema.ts +80 -0
- package/src/index.ts +32 -7
- package/src/lib/command-requests.ts +134 -1
- package/src/lib/config.ts +57 -7
- package/src/lib/constants.ts +1 -1
- package/src/lib/doctor.ts +96 -6
- package/src/lib/embed-output.ts +26 -0
- package/src/lib/embedder.ts +118 -3
- package/src/lib/embedding-health.ts +3 -1
- package/src/lib/embedding-job.ts +3 -0
- package/src/lib/embedding-management.ts +65 -0
- package/src/lib/embedding-runtime.ts +177 -0
- package/src/lib/output-json.ts +0 -2
- package/src/lib/scope-context.ts +17 -11
- package/src/lib/scope-migration.ts +2 -1
- package/src/lib/scope.ts +4 -6
- package/src/lib/search-eval.ts +136 -23
- package/src/lib/search-policy-sweep.ts +563 -0
- package/src/lib/search-policy.ts +0 -4
- package/src/lib/search-service.ts +14 -15
- package/src/lib/session-candidate-document.ts +175 -0
- package/src/lib/session-candidate-scope.ts +6 -0
- package/src/lib/session-capture.ts +298 -32
- package/src/lib/session-codec.ts +1 -8
- package/src/lib/session-operations.ts +111 -51
- package/src/lib/session-review.ts +327 -0
- package/src/lib/session-store.ts +177 -55
- package/src/lib/store.ts +79 -11
- package/src/lib/string-list.ts +3 -0
- package/src/lib/text-lines.ts +7 -0
- package/src/lib/trap-search-document.ts +2 -1
- package/src/lib/value-types.ts +3 -0
- package/src/web/client-review.ts +171 -0
- package/src/web/client-script.ts +1543 -0
- package/src/web/client-shell.ts +414 -0
- package/src/web/client-text.ts +447 -0
- package/src/web/project-registry.ts +3 -5
- package/src/web/server.ts +184 -111
- package/src/web/static.ts +581 -484
- package/skills/codetrap-capture-external/SKILL.md +0 -62
- package/skills/codetrap-check/SKILL.md +0 -69
- package/src/lib/embedding-index.ts +0 -53
package/docs/installation.md
CHANGED
|
@@ -63,6 +63,8 @@ This method does not require Bun at runtime once release binaries are published.
|
|
|
63
63
|
|
|
64
64
|
### For maintainers
|
|
65
65
|
|
|
66
|
+
Maintainer-only: agents must not create tags, push, publish packages, or create releases unless the user explicitly requests a release operation.
|
|
67
|
+
|
|
66
68
|
Release binaries are built by `.github/workflows/release.yml` when a version tag is pushed.
|
|
67
69
|
|
|
68
70
|
1. Make sure `package.json` has the version you want to release.
|
|
@@ -72,11 +74,12 @@ Release binaries are built by `.github/workflows/release.yml` when a version tag
|
|
|
72
74
|
3. Create and push a matching tag:
|
|
73
75
|
|
|
74
76
|
```bash
|
|
75
|
-
|
|
76
|
-
git
|
|
77
|
+
# Maintainer-only: do not run unless explicitly releasing.
|
|
78
|
+
git tag v<version>
|
|
79
|
+
git push origin v<version>
|
|
77
80
|
```
|
|
78
81
|
|
|
79
|
-
The release tag must match `package.json` exactly. For example, package version
|
|
82
|
+
The release tag must match `package.json` exactly. For example, package version `<version>` must use tag `v<version>`.
|
|
80
83
|
|
|
81
84
|
The workflow runs:
|
|
82
85
|
|
|
@@ -162,6 +165,8 @@ Best for long-term use with the published `codetrap` package.
|
|
|
162
165
|
|
|
163
166
|
### For maintainers
|
|
164
167
|
|
|
168
|
+
Maintainer-only: agents must not create tags, push, publish packages, or create releases unless the user explicitly requests a release operation.
|
|
169
|
+
|
|
165
170
|
Package publishing is handled by `.github/workflows/npm-publish.yml` when a GitHub Release is published.
|
|
166
171
|
|
|
167
172
|
Before automated publishing, configure npm trusted publishing:
|
|
@@ -179,6 +184,7 @@ If npm does not let you configure trusted publishing before the first version ex
|
|
|
179
184
|
|
|
180
185
|
```bash
|
|
181
186
|
npm pack --dry-run
|
|
187
|
+
# Maintainer-only: do not run unless explicitly publishing.
|
|
182
188
|
npm publish --access public
|
|
183
189
|
```
|
|
184
190
|
|
|
@@ -189,6 +195,7 @@ The workflow runs:
|
|
|
189
195
|
```bash
|
|
190
196
|
bun test src/tests
|
|
191
197
|
npm pack --dry-run
|
|
198
|
+
# Maintainer-only: this is run by the release workflow after explicit release approval.
|
|
192
199
|
npm publish --access public
|
|
193
200
|
```
|
|
194
201
|
|
|
@@ -225,59 +232,113 @@ bun install
|
|
|
225
232
|
bun run install:cli
|
|
226
233
|
```
|
|
227
234
|
|
|
228
|
-
##
|
|
235
|
+
## 5-Minute Agent Setup
|
|
229
236
|
|
|
230
|
-
|
|
237
|
+
Use this path when the first user is a coding agent such as Codex or Claude Code.
|
|
231
238
|
|
|
232
|
-
|
|
239
|
+
```bash
|
|
240
|
+
bun --version # If this fails, install Bun first or use Method 2 binary install
|
|
241
|
+
npm install -g codetrap
|
|
242
|
+
cd /path/to/project
|
|
243
|
+
codetrap init
|
|
244
|
+
codetrap doctor
|
|
245
|
+
```
|
|
233
246
|
|
|
234
|
-
|
|
247
|
+
Add the packaged agent guidance to `AGENTS.md` or `CLAUDE.md`:
|
|
235
248
|
|
|
236
249
|
```bash
|
|
237
|
-
|
|
238
|
-
|
|
250
|
+
cat "$(npm root -g)/codetrap/plugins/codetrap-agent/templates/AGENTS.codetrap.md" >> AGENTS.md
|
|
251
|
+
# or:
|
|
252
|
+
cat "$(npm root -g)/codetrap/plugins/codetrap-agent/templates/AGENTS.codetrap.md" >> CLAUDE.md
|
|
239
253
|
```
|
|
240
254
|
|
|
241
|
-
|
|
255
|
+
Then have the agent run a pre-edit check from the project cwd:
|
|
242
256
|
|
|
243
257
|
```bash
|
|
244
|
-
|
|
245
|
-
source ~/.bashrc
|
|
258
|
+
codetrap search "<task keywords>" --mode hybrid --json
|
|
246
259
|
```
|
|
247
260
|
|
|
248
|
-
|
|
261
|
+
Review the top 3 returned action cards, or all returned cards if fewer than 3, before deciding whether any trap applies. Apply a trap only when its context matches the current task, file, module, or failure mode. Severity alone is not enough to apply a trap. Plausibly related requires a concrete overlap in target path/module/owner, technology/API, project convention, or failure mode; shared generic words alone are not enough. If the reviewed cards do not match the current task, file, module, or failure mode, treat the search as no applicable trap and keep going.
|
|
249
262
|
|
|
250
|
-
|
|
251
|
-
|
|
263
|
+
After user corrections, repeated test failures, or review feedback, have the agent write a candidate into the review inbox:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
267
|
+
Title: <durable pitfall>
|
|
268
|
+
Context: <when it triggers>
|
|
269
|
+
Mistake: <what the agent did wrong>
|
|
270
|
+
Fix: <what to do instead>
|
|
271
|
+
EOF
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Use `codetrap session status`, `codetrap session list`, `codetrap doctor`, or `codetrap web` to review pending candidates. Do not accept candidates automatically.
|
|
275
|
+
|
|
276
|
+
Use the returned `candidate_id` and `session_id` to inspect and resolve the candidate:
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
codetrap session candidate <candidate-id> --session <session-id> --json
|
|
280
|
+
|
|
281
|
+
# Only after explicit human approval:
|
|
282
|
+
codetrap session accept <candidate-id> --session <session-id>
|
|
283
|
+
|
|
284
|
+
# Or reject instead:
|
|
285
|
+
codetrap session reject <candidate-id> --session <session-id> --reason "<reason>"
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Optional: Local Ollama Embeddings
|
|
289
|
+
|
|
290
|
+
codetrap works with no embedding provider. In that mode, search uses SQLite FTS keyword matching, and hybrid search falls back to FTS.
|
|
291
|
+
|
|
292
|
+
Recommended local semantic search uses Ollama with `qwen3-embedding:0.6b`. This keeps trap passages and query text on your machine.
|
|
293
|
+
|
|
294
|
+
Install Ollama, then pull the 0.6B embedding model:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
ollama pull qwen3-embedding:0.6b
|
|
252
298
|
```
|
|
253
299
|
|
|
254
|
-
|
|
300
|
+
Do not omit `:0.6b`; `qwen3-embedding:latest` is much larger.
|
|
255
301
|
|
|
256
|
-
|
|
302
|
+
Configure codetrap to use Ollama:
|
|
257
303
|
|
|
258
304
|
```bash
|
|
259
|
-
|
|
305
|
+
codetrap embeddings use ollama
|
|
306
|
+
codetrap embeddings status
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
This writes `~/.codetrap/config.json`. Environment variables such as `CODETRAP_EMBEDDING_PROVIDER` and `CODETRAP_OLLAMA_MODEL` are still supported for temporary shell or CI overrides.
|
|
310
|
+
|
|
311
|
+
Verify Ollama embedding generation:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
curl http://127.0.0.1:11434/api/embed -d '{"model":"qwen3-embedding:0.6b","input":"HTTP request timeout"}'
|
|
260
315
|
```
|
|
261
316
|
|
|
262
317
|
Generate embeddings for the traps you want semantic search to use:
|
|
263
318
|
|
|
264
319
|
```bash
|
|
265
320
|
cd /path/to/your/project
|
|
266
|
-
codetrap
|
|
267
|
-
codetrap
|
|
321
|
+
codetrap embeddings reindex --scope project
|
|
322
|
+
codetrap embeddings reindex --scope global
|
|
268
323
|
```
|
|
269
324
|
|
|
325
|
+
`codetrap embed` remains as a short alias for reindexing. codetrap stores embeddings by profile, so switching between Jina and Ollama does not overwrite existing vectors; it creates or refreshes the selected profile.
|
|
326
|
+
|
|
327
|
+
You can also run `codetrap web` and open the `Embeddings` view to inspect the active provider/profile, see project and global fresh/stale/missing counts, switch between Ollama and Jina, and reindex project or global embeddings from the web console. The web console does not save Jina API keys; Jina still reads `JINA_API_KEY` from the environment.
|
|
328
|
+
|
|
270
329
|
Then search:
|
|
271
330
|
|
|
272
331
|
```bash
|
|
273
332
|
codetrap search "HTTP request timeout" --mode hybrid
|
|
274
333
|
```
|
|
275
334
|
|
|
276
|
-
|
|
335
|
+
Optional cloud provider: run `codetrap embeddings use jina` and set `JINA_API_KEY` to use Jina instead of Ollama. Privacy note: codetrap does not collect telemetry. FTS and Ollama search are local-only. When Jina is configured, reindexing sends trap passages to Jina, and semantic or hybrid search may send query text to Jina to compute embeddings.
|
|
336
|
+
|
|
337
|
+
If no embedding provider is configured:
|
|
277
338
|
|
|
278
339
|
- `codetrap search "<query>" --mode fts` works normally.
|
|
279
340
|
- `codetrap search "<query>" --mode hybrid` works, but falls back to FTS.
|
|
280
|
-
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require
|
|
341
|
+
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require an embedding provider.
|
|
281
342
|
|
|
282
343
|
## Optional: Codex MCP
|
|
283
344
|
|
|
@@ -295,36 +356,59 @@ codex mcp add codetrap -- "$(bun pm bin -g)/codetrap" serve
|
|
|
295
356
|
|
|
296
357
|
Agents can also use the CLI directly from `AGENTS.md`:
|
|
297
358
|
|
|
298
|
-
|
|
359
|
+
````md
|
|
299
360
|
Before non-trivial code edits, check codetrap from the current project cwd:
|
|
300
361
|
|
|
301
362
|
codetrap search "<keywords>" --mode hybrid --json
|
|
302
363
|
|
|
303
|
-
Review the top 3 action cards before deciding no trap applies.
|
|
364
|
+
Review the top 3 action cards, or all returned cards if fewer than 3, before deciding no trap applies. Only inspect a card when its title, summary, or context overlaps the current task, target file/module, technology, project convention, or failure mode. For matching critical/error results, inspect before editing:
|
|
304
365
|
|
|
305
366
|
codetrap show <id> --scope <project|global> --json
|
|
306
367
|
|
|
368
|
+
Apply a trap only when its context matches the current task, file, module, or failure mode. Severity alone is not enough to apply a trap. Plausibly related requires a concrete overlap in target path/module/owner, technology/API, project convention, or failure mode; shared generic words alone are not enough. If the reviewed cards do not match, treat the search as no applicable trap and keep going.
|
|
369
|
+
|
|
307
370
|
When editing a known area, pass applicability hints:
|
|
308
371
|
|
|
309
|
-
codetrap search "<keywords>" --path
|
|
372
|
+
codetrap search "<keywords>" --path path/to/file --module module-name --json
|
|
373
|
+
|
|
374
|
+
To capture a post-flight lesson from agent work:
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
378
|
+
Title: <durable pitfall>
|
|
379
|
+
Context: <when it triggers>
|
|
380
|
+
Mistake: <what the agent did wrong>
|
|
381
|
+
Fix: <what to do instead>
|
|
382
|
+
EOF
|
|
383
|
+
```
|
|
310
384
|
|
|
311
|
-
|
|
385
|
+
`--trap-json` remains available for callers that already have a structured object:
|
|
312
386
|
|
|
313
|
-
|
|
387
|
+
```bash
|
|
388
|
+
codetrap session capture --trap-json '{...}' --kind review --json
|
|
389
|
+
```
|
|
314
390
|
|
|
315
391
|
For longer implementation work, keep temporary notes and explicit candidate traps in session files first:
|
|
316
392
|
|
|
317
393
|
```bash
|
|
318
394
|
codetrap session start "<goal>"
|
|
319
395
|
codetrap session note --kind decision --text "<what changed and why>"
|
|
320
|
-
codetrap session
|
|
396
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
397
|
+
Title: <durable pitfall>
|
|
398
|
+
Context: <when it triggers>
|
|
399
|
+
Mistake: <what the agent did wrong>
|
|
400
|
+
Fix: <what to do instead>
|
|
401
|
+
EOF
|
|
321
402
|
codetrap session close --propose-traps
|
|
322
403
|
codetrap session candidates
|
|
323
404
|
```
|
|
324
405
|
|
|
406
|
+
Pending candidates are visible from `codetrap session status`, `codetrap session list`, `codetrap doctor`, and `codetrap web`.
|
|
407
|
+
|
|
325
408
|
Only accepted candidates are written to `traps.db`:
|
|
326
409
|
|
|
327
410
|
```bash
|
|
411
|
+
# Only after explicit human approval:
|
|
328
412
|
codetrap session accept <candidate-id>
|
|
329
413
|
```
|
|
330
414
|
|
|
@@ -333,4 +417,4 @@ codetrap session accept <candidate-id>
|
|
|
333
417
|
To save a lesson from an external article or reference, let the agent read the source and attach the URL as evidence after the user confirms the trap:
|
|
334
418
|
|
|
335
419
|
codetrap add_trap_evidence <id> --scope global --source_type article --source_ref "https://example.com/post" --output-json
|
|
336
|
-
|
|
420
|
+
````
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codetrap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Capture and retrieve coding pitfalls so AI doesn't repeat mistakes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"src/web",
|
|
34
34
|
"src/index.ts",
|
|
35
35
|
"src/mcp-server.ts",
|
|
36
|
-
"skills",
|
|
37
36
|
"plugins",
|
|
38
37
|
".agents/plugins/marketplace.json",
|
|
39
38
|
"scripts",
|
|
@@ -52,6 +51,7 @@
|
|
|
52
51
|
"release:preflight": "bun run scripts/release-preflight.ts",
|
|
53
52
|
"check:release-version": "bun run scripts/check-release-version.ts",
|
|
54
53
|
"eval:dogfood": "bun run scripts/dogfood-eval.ts",
|
|
54
|
+
"eval:search-policy": "bun run scripts/search-policy-sweep.ts",
|
|
55
55
|
"build": "bun build ./src/index.ts --compile --outfile dist/codetrap && bun build ./src/mcp-server.ts --compile --outfile dist/codetrap-serve",
|
|
56
56
|
"build:cli": "bun build ./src/index.ts --compile --outfile dist/codetrap",
|
|
57
57
|
"build:serve": "bun build ./src/mcp-server.ts --compile --outfile dist/codetrap-serve"
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@types/bun": "latest"
|
|
66
|
+
"@types/bun": "latest",
|
|
67
|
+
"playwright-core": "^1.56.1"
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -12,12 +12,11 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"keywords": ["agent", "memory", "cli", "mcp", "pitfalls"],
|
|
14
14
|
"skills": "./skills/",
|
|
15
|
-
"hooks": "./hooks.json",
|
|
16
15
|
"mcpServers": "./.mcp.json",
|
|
17
16
|
"interface": {
|
|
18
17
|
"displayName": "codetrap Agent",
|
|
19
18
|
"shortDescription": "Check local pitfall memory before code changes.",
|
|
20
|
-
"longDescription": "Installs CLI-first guidance
|
|
19
|
+
"longDescription": "Installs CLI-first guidance and optional MCP config so coding agents can search codetrap before risky edits, propose new trap captures after failures, and save useful lessons from external references. Hook files are packaged as examples, not auto-installed.",
|
|
21
20
|
"developerName": "codetrap maintainers",
|
|
22
21
|
"category": "Productivity",
|
|
23
22
|
"capabilities": ["Tools", "Memory", "Code"],
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
# Post-flight Codetrap Capture
|
|
2
2
|
|
|
3
|
-
Use this template after a task reveals a reusable pitfall. Do not write the trap automatically;
|
|
3
|
+
Use this template after a task reveals a reusable pitfall. Do not write the trap automatically; put it in the session candidate inbox first.
|
|
4
4
|
|
|
5
|
-
```
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"owner": "platform"
|
|
18
|
-
}
|
|
5
|
+
```markdown
|
|
6
|
+
Title: Short pitfall title
|
|
7
|
+
Category: bug
|
|
8
|
+
Scope: project
|
|
9
|
+
Context: When this situation appears...
|
|
10
|
+
Mistake: The agent tends to...
|
|
11
|
+
Fix: Do this instead...
|
|
12
|
+
Tags: area, tool
|
|
13
|
+
Severity: warning
|
|
14
|
+
Path globs: src/example/**
|
|
15
|
+
Module: example
|
|
16
|
+
Owner: platform
|
|
19
17
|
```
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
Capture the candidate:
|
|
22
20
|
|
|
23
21
|
```bash
|
|
24
|
-
codetrap
|
|
22
|
+
codetrap session capture --trap-markdown-file candidate.md --kind review --json
|
|
25
23
|
```
|
|
24
|
+
|
|
25
|
+
Hook-based clients can set `CODETRAP_CANDIDATE_FILE` to a Markdown file with the same fields and run the packaged `post_task` command. The hook must still leave the candidate in the inbox; it must not accept or write a confirmed trap automatically.
|
|
26
|
+
|
|
27
|
+
Then review it with `codetrap session candidate <candidate-id> --session <session-id> --json` and accept, edit, reject, or supersede it explicitly.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"command": "codetrap search \"$CODETRAP_QUERY\" --mode hybrid --json"
|
|
6
6
|
},
|
|
7
7
|
"post_task": {
|
|
8
|
-
"description": "After repeated failures or user corrections,
|
|
9
|
-
"command": "codetrap
|
|
8
|
+
"description": "After repeated failures or user corrections, capture a structured trap draft in the session candidate inbox; do not write a confirmed trap automatically.",
|
|
9
|
+
"command": "codetrap session capture --trap-markdown-file \"$CODETRAP_CANDIDATE_FILE\" --kind review --json"
|
|
10
10
|
}
|
|
11
11
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: codetrap-add
|
|
3
|
-
description: Record a coding pitfall as a structured codetrap entry
|
|
3
|
+
description: Record a confirmed coding pitfall as a structured codetrap entry after explicit user approval. For agent-discovered post-flight lessons, prefer codetrap-capture and the session candidate inbox.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
You are helping the user record a "coding pitfall" (a mistake pattern that AI coding assistants tend to make, and the correct approach). These pitfalls are stored in a local database and will be used to warn AI in future sessions.
|
|
7
7
|
|
|
8
|
+
This skill writes confirmed memory. Do not use it for autonomous post-flight agent discoveries, repeated failures, or review feedback unless the user explicitly asks to save the trap as confirmed memory. For agent-drafted lessons, prefer:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
codetrap session capture --trap-markdown - --kind review --json
|
|
12
|
+
```
|
|
13
|
+
|
|
8
14
|
## Step 1: Gather information
|
|
9
15
|
|
|
10
16
|
Ask the user to describe what went wrong. Guide them to provide:
|
|
@@ -40,9 +46,9 @@ Pick the best-fitting category:
|
|
|
40
46
|
- `bug` — Common logic errors, edge cases
|
|
41
47
|
- `other` — Everything else
|
|
42
48
|
|
|
43
|
-
## Step 4: Structure and
|
|
49
|
+
## Step 4: Structure and confirm
|
|
44
50
|
|
|
45
|
-
Convert the user's description into this JSON structure
|
|
51
|
+
Convert the user's description into this JSON structure, show the draft to the user, and ask for explicit confirmation before writing it as confirmed memory:
|
|
46
52
|
|
|
47
53
|
```bash
|
|
48
54
|
codetrap add --json '{
|
|
@@ -62,7 +68,7 @@ codetrap add --json '{
|
|
|
62
68
|
}' --output-json
|
|
63
69
|
```
|
|
64
70
|
|
|
65
|
-
If the CLI is not available, use the MCP tool `add_trap` instead.
|
|
71
|
+
Only after the user confirms the draft should you call the CLI. If the CLI is not available and the user explicitly confirmed the save, use the MCP tool `add_trap` instead.
|
|
66
72
|
|
|
67
73
|
## Step 5: Confirm
|
|
68
74
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: codetrap-capture
|
|
3
|
-
description: Propose a new codetrap after repeated failures, user corrections, or review feedback.
|
|
3
|
+
description: Propose a new codetrap candidate after repeated failures, user corrections, or review feedback without writing confirmed memory automatically.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
Use this after a task exposes a recurring mistake pattern. Draft a candidate trap with:
|
|
@@ -12,8 +12,19 @@ Use this after a task exposes a recurring mistake pattern. Draft a candidate tra
|
|
|
12
12
|
- tags
|
|
13
13
|
- optional `path_globs`, `module`, and `owner`
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Do not write the confirmed trap directly. Put the draft into the session candidate inbox:
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
codetrap
|
|
18
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
19
|
+
Title: <durable pitfall>
|
|
20
|
+
Context: <when it triggers>
|
|
21
|
+
Mistake: <what the agent did wrong>
|
|
22
|
+
Fix: <what to do instead>
|
|
23
|
+
Severity: warning
|
|
24
|
+
Tags: <area>,<tool>
|
|
25
|
+
EOF
|
|
19
26
|
```
|
|
27
|
+
|
|
28
|
+
Use `--trap-json` only when you already have a structured object. Prefer Markdown for agent-drafted lessons because it avoids shell-escaping long text.
|
|
29
|
+
|
|
30
|
+
If no session is active, `session capture` creates and closes a post-flight session automatically. Tell the user the returned candidate id and session id, then ask whether they want to accept, edit, reject, or supersede the candidate. Pending candidates are also visible through `codetrap session status`, `codetrap session list`, `codetrap doctor`, and `codetrap web`.
|
|
@@ -5,15 +5,58 @@ description: Extract durable coding pitfalls from an external article, blog post
|
|
|
5
5
|
|
|
6
6
|
Use this when the user shares an external source and wants to save useful lessons for future AI coding work.
|
|
7
7
|
|
|
8
|
-
The
|
|
8
|
+
The external source is read by the agent. Do not ask codetrap CLI to fetch URLs or crawl the web. codetrap stays a local memory store.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
## Step 1: Read The Source
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
2. Extract every candidate trap that has a clear trigger, mistake, and fix. Do not force a fixed count.
|
|
14
|
-
3. Filter out broad summaries, one-off facts, vague advice, and source details that will not change future coding behavior.
|
|
15
|
-
4. Rank the recommended candidates and ask the user which ones to save.
|
|
16
|
-
5. After confirmation, run `codetrap add --json '<trap-json>' --output-json`.
|
|
17
|
-
6. Attach the source with `codetrap add_trap_evidence <id> --scope <project|global> --source_type article --source_ref "<url-or-source-id>" --note "External lesson captured from <short source title>." --output-json`.
|
|
12
|
+
Open or read the provided URL, article text, issue, paper, or reference. Identify lessons that could change future implementation behavior.
|
|
18
13
|
|
|
19
|
-
|
|
14
|
+
Do not summarize the whole source into codetrap. Extract only durable pitfalls with a clear trigger, mistake, and fix.
|
|
15
|
+
|
|
16
|
+
## Step 2: Extract Candidate Traps
|
|
17
|
+
|
|
18
|
+
Create as many candidate traps as pass the quality bar. Do not force a fixed count.
|
|
19
|
+
|
|
20
|
+
Each candidate must include:
|
|
21
|
+
|
|
22
|
+
- `context`: when this lesson applies
|
|
23
|
+
- `mistake`: what an AI coding agent might do wrong
|
|
24
|
+
- `fix`: what it should do instead
|
|
25
|
+
- `severity`: `warning`, `error`, or `critical`
|
|
26
|
+
- `tags`: useful retrieval terms
|
|
27
|
+
- optional `path_globs`, `module`, and `owner` when the lesson is project-specific
|
|
28
|
+
|
|
29
|
+
Reject or omit candidates that are broad summaries, one-off facts, vague advice, marketing claims, or source details that would not change future coding behavior.
|
|
30
|
+
|
|
31
|
+
## Step 3: Rank And Ask
|
|
32
|
+
|
|
33
|
+
Present the recommended candidates in priority order. Include a short reason for each recommendation.
|
|
34
|
+
|
|
35
|
+
Ask the user which candidates to save. Do not write any trap until the user confirms.
|
|
36
|
+
|
|
37
|
+
If a candidate is useful but needs a narrower scope, ask for or propose edits before saving.
|
|
38
|
+
|
|
39
|
+
## Step 4: Save Confirmed Lessons
|
|
40
|
+
|
|
41
|
+
For each confirmed candidate, call:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
codetrap add --json '<trap-json>' --output-json
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then attach the external source as evidence:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
codetrap add_trap_evidence <id> \
|
|
51
|
+
--scope <project|global> \
|
|
52
|
+
--source_type article \
|
|
53
|
+
--source_ref "<url-or-source-id>" \
|
|
54
|
+
--note "External lesson captured from <short source title>." \
|
|
55
|
+
--output-json
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Use `global` for generally reusable lessons across projects. Use `project` only when the lesson is specific to the current repository or technology stack.
|
|
59
|
+
|
|
60
|
+
## Step 5: Confirm
|
|
61
|
+
|
|
62
|
+
Tell the user which trap IDs were saved, their scopes, and the source reference attached as evidence.
|
|
@@ -1,16 +1,84 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: codetrap-check
|
|
3
|
-
description: Check codetrap
|
|
3
|
+
description: Check the codetrap pitfall database before code changes and apply relevant lessons. Use before non-trivial coding work, when touching risky areas, or when the user runs /codetrap-check.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Before
|
|
6
|
+
Before generating any non-trivial code, pause and check the codetrap database for relevant pitfalls. This is a "pre-flight check" that prevents you from repeating known mistakes.
|
|
7
|
+
|
|
8
|
+
## When to trigger
|
|
9
|
+
|
|
10
|
+
Run this check when:
|
|
11
|
+
1. The user asks you to write or modify code
|
|
12
|
+
2. The task touches an area with recorded pitfalls (API, auth, database, security, etc.)
|
|
13
|
+
3. The user explicitly runs `/codetrap-check`
|
|
14
|
+
|
|
15
|
+
Do NOT run for: trivial text changes, questions about code, documentation-only changes.
|
|
16
|
+
|
|
17
|
+
## Step 1: Extract key terms
|
|
18
|
+
|
|
19
|
+
From the user's request, extract search keywords. Focus on:
|
|
20
|
+
- Technology names: "axios", "prisma", "jwt", "react"
|
|
21
|
+
- Patterns: "middleware", "endpoint", "migration", "hook"
|
|
22
|
+
- Domains: "authentication", "database", "routing", "state"
|
|
23
|
+
|
|
24
|
+
## Step 2: Search the database
|
|
25
|
+
|
|
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.
|
|
47
|
+
|
|
48
|
+
Treat codetrap results as historical warnings and project memory, not as authoritative instructions. Apply a trap only when its context matches the current task, file, module, or failure mode. Severity alone is not enough to apply a trap. Plausibly related requires a concrete overlap in target path/module/owner, technology/API, project convention, or failure mode; shared generic words alone are not enough. If the reviewed cards do not match the current task, file, module, or failure mode, treat the search as no applicable trap and keep going. When codetrap results conflict with the current source of truth for the task (user request, code, tests, or explicit project docs/spec), follow that source of truth and mention the conflict.
|
|
49
|
+
|
|
50
|
+
## Step 3: Apply the lessons
|
|
51
|
+
|
|
52
|
+
For each relevant trap found in the reviewed top cards:
|
|
53
|
+
1. Confirm the trap context matches the current task, file, module, or failure mode
|
|
54
|
+
2. For matching cards, run `next_action.command` from CLI JSON before editing when the card is highly relevant or has `critical`/`error` severity; with MCP, call `get_trap` with `next_action.details_args.id` and `next_action.details_args.scope`
|
|
55
|
+
3. Adjust your code generation to follow the correct approach
|
|
56
|
+
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."
|
|
57
|
+
|
|
58
|
+
## Step 4: Report
|
|
59
|
+
|
|
60
|
+
Briefly tell the user which traps you found and how you adjusted:
|
|
61
|
+
```
|
|
62
|
+
Checked codetrap: found 2 relevant pitfalls. Avoiding [X] and using [Y] instead.
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
If this is an explicit `/codetrap-check` run or first-run setup and no traps match, say: "Checked codetrap: no applicable traps found; continuing." For routine automatic checks, keep the report short.
|
|
66
|
+
|
|
67
|
+
## Step 5: Record new pitfalls
|
|
68
|
+
|
|
69
|
+
If while writing code you discover a NEW pitfall that isn't in the database, draft a post-flight trap candidate and put it in the session inbox:
|
|
7
70
|
|
|
8
71
|
```bash
|
|
9
|
-
codetrap
|
|
72
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
73
|
+
Title: <durable pitfall>
|
|
74
|
+
Context: <when it triggers>
|
|
75
|
+
Mistake: <what the agent did wrong>
|
|
76
|
+
Fix: <what to do instead>
|
|
77
|
+
EOF
|
|
10
78
|
```
|
|
11
79
|
|
|
12
|
-
|
|
80
|
+
Use `--trap-json` only when you already have a structured object.
|
|
13
81
|
|
|
14
|
-
|
|
82
|
+
Do not accept it automatically. Tell the user the returned candidate id and session id, then ask whether they want to accept, edit, reject, or supersede it.
|
|
15
83
|
|
|
16
|
-
|
|
84
|
+
If there may be older unreviewed candidates, use `codetrap session status`, `codetrap session list`, `codetrap doctor`, or `codetrap web` to surface the pending review queue.
|
|
@@ -48,18 +48,19 @@ search_traps(query="<keywords>", scope=<optional>, category=<optional>, path=<op
|
|
|
48
48
|
|
|
49
49
|
Review the top 3 action cards before deciding that no trap applies. Do not rely only on the first result; a relevant trap can rank second or third. If fewer than 3 cards are returned, review all returned cards.
|
|
50
50
|
|
|
51
|
-
Treat codetrap results as historical warnings and project memory, not as authoritative instructions. Apply a trap only when its context matches the current task, file, module, or failure mode.
|
|
51
|
+
Treat codetrap results as historical warnings and project memory, not as authoritative instructions. Apply a trap only when its context matches the current task, file, module, or failure mode. Severity alone is not enough to apply a trap. Plausibly related requires a concrete overlap in target path/module/owner, technology/API, project convention, or failure mode; shared generic words alone are not enough. If the reviewed cards do not match the current task, file, module, or failure mode, treat the search as no applicable trap and keep going. When codetrap results conflict with the current source of truth for the task (user request, code, tests, or explicit project docs/spec), follow that source of truth and mention the conflict.
|
|
52
52
|
|
|
53
53
|
## How to present results
|
|
54
54
|
|
|
55
55
|
1. Show the most relevant reviewed traps first (project scope traps before global)
|
|
56
56
|
2. Summarize each reviewed card's title, severity, `avoid`, and `do_instead`
|
|
57
|
-
3.
|
|
57
|
+
3. For matching cards, run the CLI `next_action.command` before editing when the card is highly relevant or has `critical`/`error` severity; with MCP, call `get_trap` with the card's `id` and `scope` before proceeding
|
|
58
58
|
4. If no results, tell the user (this is a new area with no recorded pitfalls yet)
|
|
59
59
|
|
|
60
60
|
## Example
|
|
61
61
|
|
|
62
|
-
User: "I need to add a new API endpoint"
|
|
63
|
-
→ Search: `codetrap search "API endpoint" --mode hybrid --json`
|
|
62
|
+
User: "I need to add a new API endpoint that calls an external service"
|
|
63
|
+
→ Search: `codetrap search "API endpoint external service" --mode hybrid --json`
|
|
64
64
|
→ Results show: "Don't use axios, use fetchWrapper" (project, error)
|
|
65
|
-
→
|
|
65
|
+
→ Because the task includes outbound HTTP, tell user: "I see a matching project convention: always use fetchWrapper instead of axios. I'll follow that."
|
|
66
|
+
→ If the endpoint does not make outbound HTTP calls, ignore this card even if severity is error.
|