codetrap 0.1.4 → 0.1.6
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 +64 -2
- package/docs/installation.md +25 -3
- package/package.json +3 -1
- package/plugins/codetrap-agent/.codex-plugin/plugin.json +3 -2
- package/plugins/codetrap-agent/skills/codetrap-capture-external/SKILL.md +19 -0
- package/plugins/codetrap-agent/skills/codetrap-check/SKILL.md +2 -0
- package/plugins/codetrap-agent/templates/AGENTS.codetrap.md +4 -0
- package/scripts/dogfood-eval.ts +53 -0
- package/skills/codetrap-add/SKILL.md +4 -0
- package/skills/codetrap-capture-external/SKILL.md +62 -0
- package/skills/codetrap-check/SKILL.md +3 -1
- package/skills/codetrap-search/SKILL.md +3 -1
- package/src/commands/workflow.ts +261 -2
- package/src/db/connection.ts +1 -1
- package/src/domain/session.ts +119 -0
- package/src/domain/trap.ts +1 -1
- package/src/index.ts +9 -0
- package/src/lib/command-requests.ts +156 -0
- package/src/lib/constants.ts +1 -1
- package/src/lib/search-eval.ts +412 -0
- package/src/lib/session-capture.ts +96 -0
- package/src/lib/session-codec.ts +261 -0
- package/src/lib/session-conflicts.ts +104 -0
- package/src/lib/session-operations.ts +214 -0
- package/src/lib/session-store.ts +503 -0
- package/src/lib/trap-quality.ts +111 -0
- package/src/lib/trap-scope-match.ts +1 -1
- package/src/web/project-registry.ts +106 -0
- package/src/web/server.ts +441 -0
- package/src/web/static.ts +776 -0
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ codetrap show 1
|
|
|
56
56
|
## Features
|
|
57
57
|
|
|
58
58
|
- **Structured trap recording** — title, category, context, mistake, fix, severity, tags, lifecycle, evidence, before/after code
|
|
59
|
+
- **Session mode capture** — record implementation notes, promote explicit structured trap notes into candidates, and save only user-accepted lessons
|
|
59
60
|
- **Dual scope** — project-scoped (`.codetrap/traps.db`) and global (`~/.codetrap/traps.db`)
|
|
60
61
|
- **CLI-first agent API** — `search/show/list/stats/doctor --json` and stdin query support for shell-friendly automation
|
|
61
62
|
- **Three search modes** — FTS (SQLite FTS5), semantic (Jina embeddings), hybrid (RRF fusion)
|
|
@@ -81,9 +82,17 @@ codetrap/
|
|
|
81
82
|
│ │ ├── tools.ts 10 MCP tool definitions
|
|
82
83
|
│ │ └── resources.ts 4 MCP resource URIs
|
|
83
84
|
│ ├── domain/trap.ts Trap types, builders, schemas
|
|
85
|
+
│ ├── domain/session.ts Session, note, and candidate trap types
|
|
84
86
|
│ ├── lib/
|
|
85
87
|
│ │ ├── store.ts Project/global scope orchestration
|
|
86
88
|
│ │ ├── trap-operations.ts Shared CLI/MCP operation semantics
|
|
89
|
+
│ │ ├── session-operations.ts Session command semantics + accept/reject flow
|
|
90
|
+
│ │ ├── session-store.ts Session files, active state, index, recaps
|
|
91
|
+
│ │ ├── session-codec.ts Session JSON/Markdown/candidate file conversion
|
|
92
|
+
│ │ ├── session-capture.ts Candidate trap extraction from explicit structured notes
|
|
93
|
+
│ │ ├── session-conflicts.ts Candidate vs active-trap conflict checks
|
|
94
|
+
│ │ ├── trap-quality.ts Deterministic candidate quality scoring
|
|
95
|
+
│ │ ├── command-requests.ts CLI/MCP request normalization helpers
|
|
87
96
|
│ │ ├── output-json.ts Shared CLI/MCP JSON presenters
|
|
88
97
|
│ │ ├── scope-context.ts cwd/project/global DB context + repo selection
|
|
89
98
|
│ │ ├── scope-migration.ts Safe project trap scope repair/migration
|
|
@@ -115,6 +124,7 @@ codetrap/
|
|
|
115
124
|
│ └── tests/
|
|
116
125
|
│ ├── search-*.test.ts
|
|
117
126
|
│ ├── trap-*.test.ts
|
|
127
|
+
│ ├── session-cli.test.ts
|
|
118
128
|
│ ├── mcp-tools.test.ts
|
|
119
129
|
│ ├── scope.test.ts
|
|
120
130
|
│ ├── scope-migration-cli.test.ts
|
|
@@ -150,8 +160,25 @@ codetrap/
|
|
|
150
160
|
| `repair-scope` | Move legacy mis-scoped project traps into the current project (dry-run by default, `--apply` to mutate, `--json`) |
|
|
151
161
|
| `migrate-project` | Move project traps between initialized projects (`--from-project-path`, `--to-project-path`, dry-run by default, `--apply`, `--json`) |
|
|
152
162
|
| `embed` | Generate embeddings (requires JINA_API_KEY) |
|
|
163
|
+
| `session` | Start a development session, append notes, promote explicit structured trap notes into candidates, and accept/reject candidates |
|
|
153
164
|
| `serve` | Start MCP server |
|
|
154
165
|
|
|
166
|
+
### Session Mode
|
|
167
|
+
|
|
168
|
+
Session mode stores temporary working memory in `.codetrap/sessions/`. It does not add anything to `traps.db` until a candidate is explicitly accepted.
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
codetrap session start "implement agent harness" --spec docs/agent-harness-spec.md --module agent-runtime
|
|
172
|
+
codetrap session note --kind decision --text "Defaulted tool calls to 30s because the spec does not define timeout behavior."
|
|
173
|
+
codetrap session note --kind review --text $'Title: Do not parse nested tool calls with regex\nContext: When implementing parser logic for nested tool-call arguments.\nMistake: Using regex to split nested calls corrupts arguments.\nFix: Use a tokenizer/parser and add regression tests for nested calls.'
|
|
174
|
+
codetrap session close --propose-traps
|
|
175
|
+
codetrap session candidates
|
|
176
|
+
codetrap session candidate cand-001
|
|
177
|
+
codetrap session accept cand-001
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
`session accept` writes the confirmed lesson through `TrapOperations`, attaches session evidence, and checks similar active traps before saving. `--edit-json` is applied before the conflict check, so edits to scope/module/title/tags/path globs affect both the saved trap and conflict detection. If a possible conflict is found, the candidate keeps its edited trap shape and conflict diagnostics; use `--accept-anyway` to keep both traps or `--supersedes <trap-id>` to preserve lifecycle history.
|
|
181
|
+
|
|
155
182
|
## Agent Integration
|
|
156
183
|
|
|
157
184
|
For AI coding agents, use the CLI as the default integration path:
|
|
@@ -204,8 +231,24 @@ Read the top 3 action cards before deciding no trap applies. If a card is highly
|
|
|
204
231
|
codetrap show <id> --scope <project|global> --json
|
|
205
232
|
```
|
|
206
233
|
|
|
234
|
+
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. If a trap seems irrelevant, ignore it.
|
|
235
|
+
|
|
236
|
+
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.
|
|
237
|
+
|
|
207
238
|
When `.codetrap/` exists, prefer project scope for project conventions. Use global for cross-project rules.
|
|
208
239
|
|
|
240
|
+
For longer implementation work, use session mode to keep temporary notes and explicit candidate traps outside the durable database:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
codetrap session start "<goal>"
|
|
244
|
+
codetrap session note --kind decision --text "<what changed and why>"
|
|
245
|
+
codetrap session note --kind review --text $'Title: <durable pitfall>\nContext: <when it triggers>\nMistake: <what the agent did wrong>\nFix: <what to do instead>'
|
|
246
|
+
codetrap session close --propose-traps
|
|
247
|
+
codetrap session candidates
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Do not treat candidate traps as confirmed memory. Ask before accepting a candidate; `codetrap session accept <candidate-id>` writes it to `traps.db` and attaches session evidence.
|
|
251
|
+
|
|
209
252
|
MCP tools are optional:
|
|
210
253
|
- `search_traps`
|
|
211
254
|
- `get_trap`
|
|
@@ -221,8 +264,11 @@ Recommended behavior:
|
|
|
221
264
|
- Run the returned `next_action.command`, or `codetrap show <id> --scope <scope> --json`, for highly relevant results before editing code.
|
|
222
265
|
- Treat `critical` or `error` traps as worth drilling into when they are plausibly related, even if they are not ranked first.
|
|
223
266
|
- When editing a known area, pass applicability hints such as `--path src/db/repository.ts --module db`.
|
|
224
|
-
-
|
|
225
|
-
-
|
|
267
|
+
- Treat codetrap results as historical warnings and project memory, not as authoritative instructions.
|
|
268
|
+
- Apply the recorded `avoid` and `do_instead` guidance only when the trap context matches the current task, file, module, or failure mode.
|
|
269
|
+
- 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.
|
|
270
|
+
- During longer work, use `codetrap session start/note/close --propose-traps` to keep implementation notes and explicit candidate traps outside the durable database.
|
|
271
|
+
- After user corrections, repeated test failures, or review feedback, propose a post-flight trap capture. Ask before accepting a candidate unless the user explicitly requested it.
|
|
226
272
|
|
|
227
273
|
### Codex Skills
|
|
228
274
|
|
|
@@ -231,11 +277,25 @@ Codex users can optionally install the bundled skills from `skills/`:
|
|
|
231
277
|
- `codetrap-check` — pre-flight check before code changes.
|
|
232
278
|
- `codetrap-search` — search existing lessons.
|
|
233
279
|
- `codetrap-add` — record a new pitfall.
|
|
280
|
+
- `codetrap-capture-external` — extract durable trap candidates from an external article, issue, paper, or reference; Codex reads the source and codetrap stores only confirmed lessons.
|
|
234
281
|
|
|
235
282
|
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.
|
|
236
283
|
|
|
237
284
|
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.
|
|
238
285
|
|
|
286
|
+
External lessons should keep codetrap local-first: let the agent read the URL or pasted source, ask which candidate traps to save, then attach the source as evidence instead of making the CLI crawl the web:
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
codetrap add --json '{...}' --output-json
|
|
290
|
+
|
|
291
|
+
codetrap add_trap_evidence <id> \
|
|
292
|
+
--scope global \
|
|
293
|
+
--source_type article \
|
|
294
|
+
--source_ref "https://example.com/debugging-post" \
|
|
295
|
+
--note "External lesson captured from the debugging post." \
|
|
296
|
+
--output-json
|
|
297
|
+
```
|
|
298
|
+
|
|
239
299
|
### MCP Tools
|
|
240
300
|
|
|
241
301
|
| Tool | Description |
|
|
@@ -375,6 +435,8 @@ bun run release:preflight # tests, builds, release assets, smoke test, npm dry-
|
|
|
375
435
|
```bash
|
|
376
436
|
bun test src/tests/ # All tests
|
|
377
437
|
bun test src/tests/search-eval.test.ts # Recall@5 evaluation
|
|
438
|
+
bun run eval:dogfood -- report # Maintainer dogfood eval report
|
|
439
|
+
bun run eval:dogfood -- report --live # Dogfood eval with configured embedding provider
|
|
378
440
|
```
|
|
379
441
|
|
|
380
442
|
## Tech Stack
|
package/docs/installation.md
CHANGED
|
@@ -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.6
|
|
76
|
+
git push origin v0.1.6
|
|
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.6` must use tag `v0.1.6`.
|
|
80
80
|
|
|
81
81
|
The workflow runs:
|
|
82
82
|
|
|
@@ -311,4 +311,26 @@ codetrap search "<keywords>" --path src/db/repository.ts --module db --json
|
|
|
311
311
|
To add a lesson:
|
|
312
312
|
|
|
313
313
|
codetrap add --json '{...}' --output-json
|
|
314
|
+
|
|
315
|
+
For longer implementation work, keep temporary notes and explicit candidate traps in session files first:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
codetrap session start "<goal>"
|
|
319
|
+
codetrap session note --kind decision --text "<what changed and why>"
|
|
320
|
+
codetrap session note --kind review --text $'Title: <durable pitfall>\nContext: <when it triggers>\nMistake: <what the agent did wrong>\nFix: <what to do instead>'
|
|
321
|
+
codetrap session close --propose-traps
|
|
322
|
+
codetrap session candidates
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Only accepted candidates are written to `traps.db`:
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
codetrap session accept <candidate-id>
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
`codetrap session accept --edit-json ...` applies the edit before conflict detection. If a possible active-trap conflict is found, the candidate remains proposed and records conflict diagnostics until you choose `--accept-anyway`, `--supersedes <trap-id>`, or reject it.
|
|
332
|
+
|
|
333
|
+
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
|
+
|
|
335
|
+
codetrap add_trap_evidence <id> --scope global --source_type article --source_ref "https://example.com/post" --output-json
|
|
314
336
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codetrap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Capture and retrieve coding pitfalls so AI doesn't repeat mistakes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"src/domain",
|
|
31
31
|
"src/lib",
|
|
32
32
|
"src/mcp",
|
|
33
|
+
"src/web",
|
|
33
34
|
"src/index.ts",
|
|
34
35
|
"src/mcp-server.ts",
|
|
35
36
|
"skills",
|
|
@@ -50,6 +51,7 @@
|
|
|
50
51
|
"build:release": "bun run scripts/build-release.ts",
|
|
51
52
|
"release:preflight": "bun run scripts/release-preflight.ts",
|
|
52
53
|
"check:release-version": "bun run scripts/check-release-version.ts",
|
|
54
|
+
"eval:dogfood": "bun run scripts/dogfood-eval.ts",
|
|
53
55
|
"build": "bun build ./src/index.ts --compile --outfile dist/codetrap && bun build ./src/mcp-server.ts --compile --outfile dist/codetrap-serve",
|
|
54
56
|
"build:cli": "bun build ./src/index.ts --compile --outfile dist/codetrap",
|
|
55
57
|
"build:serve": "bun build ./src/mcp-server.ts --compile --outfile dist/codetrap-serve"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"interface": {
|
|
18
18
|
"displayName": "codetrap Agent",
|
|
19
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
|
|
20
|
+
"longDescription": "Installs CLI-first guidance, optional MCP config, and example hooks so coding agents can search codetrap before risky edits, propose new trap captures after failures, and save useful lessons from external references.",
|
|
21
21
|
"developerName": "codetrap maintainers",
|
|
22
22
|
"category": "Productivity",
|
|
23
23
|
"capabilities": ["Tools", "Memory", "Code"],
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"defaultPrompt": [
|
|
28
28
|
"Check codetrap before editing this code.",
|
|
29
29
|
"Search prior pitfalls for this task.",
|
|
30
|
-
"Propose a codetrap for this failure."
|
|
30
|
+
"Propose a codetrap for this failure.",
|
|
31
|
+
"Capture useful lessons from this article."
|
|
31
32
|
],
|
|
32
33
|
"brandColor": "#2563EB"
|
|
33
34
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codetrap-capture-external
|
|
3
|
+
description: Extract durable coding pitfalls from an external article, blog post, issue, paper, or reference, then save selected lessons to codetrap with source evidence after user confirmation.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Use this when the user shares an external source and wants to save useful lessons for future AI coding work.
|
|
7
|
+
|
|
8
|
+
The agent should read the source. The codetrap CLI should not fetch URLs or crawl the web; it only stores confirmed lessons and evidence.
|
|
9
|
+
|
|
10
|
+
Workflow:
|
|
11
|
+
|
|
12
|
+
1. Read the URL, article text, issue, paper, or reference.
|
|
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`.
|
|
18
|
+
|
|
19
|
+
Default to `global` for generally reusable engineering lessons. Use `project` only when the source lesson is specific to the current repository or stack.
|
|
@@ -11,4 +11,6 @@ codetrap search "<task keywords>" --mode hybrid --json
|
|
|
11
11
|
|
|
12
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
13
|
|
|
14
|
+
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. If a trap seems irrelevant, ignore it. 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.
|
|
15
|
+
|
|
14
16
|
Use MCP only as an optional adapter. When calling MCP tools, pass `cwd` when the client supports it.
|
|
@@ -12,6 +12,10 @@ Review the top 3 action cards before deciding no trap applies. If a card is high
|
|
|
12
12
|
codetrap show <id> --scope <project|global> --json
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
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. If a trap seems irrelevant, ignore it.
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
15
19
|
When editing a specific area, pass applicability hints:
|
|
16
20
|
|
|
17
21
|
```bash
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_SEARCH_EVAL_FIXTURE,
|
|
5
|
+
formatSearchEvalReport,
|
|
6
|
+
recordDogfoodCase,
|
|
7
|
+
reportDogfood,
|
|
8
|
+
} from "../src/lib/search-eval";
|
|
9
|
+
|
|
10
|
+
async function main(): Promise<void> {
|
|
11
|
+
const args = parseArgs(process.argv.slice(2));
|
|
12
|
+
const command = args.positionals[0];
|
|
13
|
+
const fixturePath = args.opts.fixture ?? DEFAULT_SEARCH_EVAL_FIXTURE;
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
if (command === "record") {
|
|
17
|
+
console.log(JSON.stringify(recordDogfoodCase(fixturePath, args.opts.json), null, 2));
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (command === "report") {
|
|
22
|
+
const result = await reportDogfood(fixturePath, args.opts.live === "true");
|
|
23
|
+
console.log(args.opts.json === "true" ? JSON.stringify(result, null, 2) : formatSearchEvalReport(result));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
throw new Error([
|
|
28
|
+
"Usage:",
|
|
29
|
+
" bun run eval:dogfood -- report [--live] [--json] [--fixture path]",
|
|
30
|
+
" bun run eval:dogfood -- record --json '<record>' [--fixture path]",
|
|
31
|
+
].join("\n"));
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseArgs(args: string[]): { opts: Record<string, string>; positionals: string[] } {
|
|
39
|
+
const opts: Record<string, string> = {};
|
|
40
|
+
const positionals: string[] = [];
|
|
41
|
+
for (let i = 0; i < args.length; i++) {
|
|
42
|
+
const arg = args[i];
|
|
43
|
+
if (arg.startsWith("--")) {
|
|
44
|
+
const key = arg.slice(2);
|
|
45
|
+
opts[key] = args[i + 1] && !args[i + 1].startsWith("--") ? args[++i] : "true";
|
|
46
|
+
} else {
|
|
47
|
+
positionals.push(arg);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { opts, positionals };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
await main();
|
|
@@ -16,6 +16,10 @@ Ask the user to describe what went wrong. Guide them to provide:
|
|
|
16
16
|
|
|
17
17
|
If the user already provided enough detail, don't re-ask — just proceed to structuring.
|
|
18
18
|
|
|
19
|
+
## Quality gate
|
|
20
|
+
|
|
21
|
+
Only record stable lessons that are likely to change future AI behavior. Do not save unverified guesses, one-off logs, overly broad advice, or traps without a clear trigger and actionable fix. If the candidate is too vague, ask the user to clarify or suggest keeping it as a note instead of writing it to codetrap.
|
|
22
|
+
|
|
19
23
|
## Step 2: Determine scope
|
|
20
24
|
|
|
21
25
|
Ask the user (or infer from context):
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: codetrap-capture-external
|
|
3
|
+
description: Extract durable coding pitfalls from an external article, blog post, issue, paper, or reference, then save selected lessons to codetrap with source evidence after user confirmation.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Use this when the user shares an external source and wants to save useful lessons for future AI coding work.
|
|
7
|
+
|
|
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
|
+
|
|
10
|
+
## Step 1: Read The Source
|
|
11
|
+
|
|
12
|
+
Open or read the provided URL, article text, issue, paper, or reference. Identify lessons that could change future implementation behavior.
|
|
13
|
+
|
|
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.
|
|
@@ -45,10 +45,12 @@ MCP `search_traps` is optional. Use it only when it is already available and pro
|
|
|
45
45
|
|
|
46
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
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. If a trap seems irrelevant, ignore it. 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
|
+
|
|
48
50
|
## Step 3: Apply the lessons
|
|
49
51
|
|
|
50
52
|
For each relevant trap found in the reviewed top cards:
|
|
51
|
-
1.
|
|
53
|
+
1. Confirm the trap context matches the current task, file, module, or failure mode
|
|
52
54
|
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`
|
|
53
55
|
3. Adjust your code generation to follow the correct approach
|
|
54
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."
|
|
@@ -48,11 +48,13 @@ 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. If a trap seems irrelevant, ignore it. 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
|
+
|
|
51
53
|
## How to present results
|
|
52
54
|
|
|
53
55
|
1. Show the most relevant reviewed traps first (project scope traps before global)
|
|
54
56
|
2. Summarize each reviewed card's title, severity, `avoid`, and `do_instead`
|
|
55
|
-
3. If any reviewed card is highly relevant, or has `critical`/`error` severity and is plausibly related, and you are about to edit code, run the CLI `next_action.command`; with MCP, call `get_trap` with the card's `id` and `scope` before proceeding
|
|
57
|
+
3. If any reviewed card is highly relevant, has matching context, or has `critical`/`error` severity and is plausibly related, and you are about to edit code, run the CLI `next_action.command`; with MCP, call `get_trap` with the card's `id` and `scope` before proceeding
|
|
56
58
|
4. If no results, tell the user (this is a new area with no recorded pitfalls yet)
|
|
57
59
|
|
|
58
60
|
## Example
|