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/README.md
CHANGED
|
@@ -53,18 +53,74 @@ codetrap list
|
|
|
53
53
|
codetrap show 1
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
+
## 5-Minute Agent Setup
|
|
57
|
+
|
|
58
|
+
For a first AI-agent user, the fastest path is CLI-first project guidance:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# npm/source installs require Bun because the package entrypoint uses /usr/bin/env bun
|
|
62
|
+
bun --version # If this fails, install Bun first or use the binary install in docs/installation.md
|
|
63
|
+
npm install -g codetrap
|
|
64
|
+
|
|
65
|
+
# Initialize pitfall memory in the target project
|
|
66
|
+
cd /path/to/project
|
|
67
|
+
codetrap init
|
|
68
|
+
codetrap doctor
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Add the packaged agent guidance to `AGENTS.md` for Codex, or to `CLAUDE.md` for Claude Code:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cat "$(npm root -g)/codetrap/plugins/codetrap-agent/templates/AGENTS.codetrap.md" >> AGENTS.md
|
|
75
|
+
# or:
|
|
76
|
+
cat "$(npm root -g)/codetrap/plugins/codetrap-agent/templates/AGENTS.codetrap.md" >> CLAUDE.md
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Then have the agent run this before non-trivial edits:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
codetrap search "<task keywords>" --mode hybrid --json
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
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.
|
|
86
|
+
|
|
87
|
+
After a user correction, repeated test failure, or review finding, have the agent draft a candidate instead of writing confirmed memory:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
91
|
+
Title: <durable pitfall>
|
|
92
|
+
Context: <when it triggers>
|
|
93
|
+
Mistake: <what the agent did wrong>
|
|
94
|
+
Fix: <what to do instead>
|
|
95
|
+
EOF
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Review pending candidates with `codetrap session status`, `codetrap session list`, `codetrap doctor`, or `codetrap web`; accepting a candidate remains an explicit human decision.
|
|
99
|
+
|
|
100
|
+
Use the returned `candidate_id` and `session_id` to inspect and resolve the candidate:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
codetrap session candidate <candidate-id> --session <session-id> --json
|
|
104
|
+
|
|
105
|
+
# Only after explicit human approval:
|
|
106
|
+
codetrap session accept <candidate-id> --session <session-id>
|
|
107
|
+
|
|
108
|
+
# Or reject instead:
|
|
109
|
+
codetrap session reject <candidate-id> --session <session-id> --reason "<reason>"
|
|
110
|
+
```
|
|
111
|
+
|
|
56
112
|
## Features
|
|
57
113
|
|
|
58
114
|
- **Structured trap recording** — title, category, context, mistake, fix, severity, tags, lifecycle, evidence, before/after code
|
|
59
115
|
- **Session mode capture** — record implementation notes, promote explicit structured trap notes into candidates, and save only user-accepted lessons
|
|
60
116
|
- **Dual scope** — project-scoped (`.codetrap/traps.db`) and global (`~/.codetrap/traps.db`)
|
|
61
117
|
- **CLI-first agent API** — `search/show/list/stats/doctor --json` and stdin query support for shell-friendly automation
|
|
62
|
-
- **Three search modes** — FTS (SQLite FTS5), semantic (Jina embeddings), hybrid (RRF fusion)
|
|
118
|
+
- **Three search modes** — FTS (SQLite FTS5), semantic (local Ollama or Jina embeddings), hybrid (RRF fusion)
|
|
63
119
|
- **Chinese + mixed-language search** — CJK bigram tokenizer, synonym map for Chinese-English terms
|
|
64
120
|
- **MCP server** — optional tools + resources for AI agent integration
|
|
65
|
-
- **Embedding cache** with freshness tracking —
|
|
121
|
+
- **Embedding cache** with multi-profile freshness tracking — Jina/Ollama vectors can coexist and stale ones auto-invalidate
|
|
66
122
|
- **Doctor diagnostics** — scope, database, and embedding health in text or JSON
|
|
67
|
-
- **Schema migrations** — in-code migration system from v0 through current
|
|
123
|
+
- **Schema migrations** — in-code migration system from v0 through current v6
|
|
68
124
|
- **Single-binary builds** — `bun build --compile` produces standalone binaries in `dist/`
|
|
69
125
|
|
|
70
126
|
## Directory Structure
|
|
@@ -74,7 +130,7 @@ codetrap/
|
|
|
74
130
|
├── src/
|
|
75
131
|
│ ├── index.ts CLI entry point
|
|
76
132
|
│ ├── mcp-server.ts MCP server entry point
|
|
77
|
-
│ ├── commands/router.ts
|
|
133
|
+
│ ├── commands/router.ts Optional thin CLI adapter + renderer
|
|
78
134
|
│ ├── commands/workflow.ts CLI command behavior
|
|
79
135
|
│ ├── commands/command-result.ts CLI command results + rendering
|
|
80
136
|
│ ├── mcp/
|
|
@@ -87,9 +143,12 @@ codetrap/
|
|
|
87
143
|
│ │ ├── store.ts Project/global scope orchestration
|
|
88
144
|
│ │ ├── trap-operations.ts Shared CLI/MCP operation semantics
|
|
89
145
|
│ │ ├── session-operations.ts Session command semantics + accept/reject flow
|
|
146
|
+
│ │ ├── session-review.ts Shared session review payloads + CLI conflict presenter
|
|
90
147
|
│ │ ├── session-store.ts Session files, active state, index, recaps
|
|
91
148
|
│ │ ├── session-codec.ts Session JSON/Markdown/candidate file conversion
|
|
92
|
-
│ │ ├── session-capture.ts Candidate
|
|
149
|
+
│ │ ├── session-capture.ts Candidate draft normalization, extraction, and merge policy
|
|
150
|
+
│ │ ├── session-candidate-document.ts Candidate document transition rules
|
|
151
|
+
│ │ ├── session-candidate-scope.ts Candidate accepted-scope fallback
|
|
93
152
|
│ │ ├── session-conflicts.ts Candidate vs active-trap conflict checks
|
|
94
153
|
│ │ ├── trap-quality.ts Deterministic candidate quality scoring
|
|
95
154
|
│ │ ├── command-requests.ts CLI/MCP request normalization helpers
|
|
@@ -97,7 +156,9 @@ codetrap/
|
|
|
97
156
|
│ │ ├── scope-context.ts cwd/project/global DB context + repo selection
|
|
98
157
|
│ │ ├── scope-migration.ts Safe project trap scope repair/migration
|
|
99
158
|
│ │ ├── doctor.ts Scope and embedding health diagnostics
|
|
159
|
+
│ │ ├── embedding-runtime.ts Embedding provider runtime/config/status
|
|
100
160
|
│ │ ├── embedding-health.ts Fresh/stale/missing embedding summaries
|
|
161
|
+
│ │ ├── embedding-management.ts Embedding profile command output
|
|
101
162
|
│ │ ├── search-service.ts FTS/semantic/hybrid candidate retrieval
|
|
102
163
|
│ │ ├── search-policy.ts Applicability filtering, rerank, fusion signals
|
|
103
164
|
│ │ ├── search-result-card.ts Compact agent-facing result cards
|
|
@@ -107,10 +168,13 @@ codetrap/
|
|
|
107
168
|
│ │ ├── trap-json-fields.ts Tags/path/evidence JSON array codec
|
|
108
169
|
│ │ ├── trap-codec.ts Storage/JSON/archive/import shape conversion
|
|
109
170
|
│ │ ├── trap-mutation-result.ts Mutation result + scope fallback semantics
|
|
171
|
+
│ │ ├── string-list.ts Shared string list de-duping
|
|
172
|
+
│ │ ├── text-lines.ts Shared line trimming helpers
|
|
173
|
+
│ │ ├── value-types.ts Shared runtime value guards
|
|
110
174
|
│ │ ├── trap-scope-match.ts Path/module/owner applicability matching
|
|
111
175
|
│ │ ├── trap-archive.ts Import/export compatibility
|
|
112
176
|
│ │ ├── trap-transfer.ts DB-to-DB transfer for scope migration
|
|
113
|
-
│ │ ├── embedder.ts Jina Embeddings
|
|
177
|
+
│ │ ├── embedder.ts Ollama and Jina Embeddings adapters
|
|
114
178
|
│ │ ├── embedding-job.ts Batch embedding generation
|
|
115
179
|
│ │ ├── format.ts CLI output formatting
|
|
116
180
|
│ │ ├── scope.ts Project root detection
|
|
@@ -121,6 +185,13 @@ codetrap/
|
|
|
121
185
|
│ │ ├── queries.ts CRUD, search, stats, import/export
|
|
122
186
|
│ │ ├── embedding-queries.ts Embedding storage SQL
|
|
123
187
|
│ │ └── repository.ts Single-DB facade
|
|
188
|
+
│ ├── web/
|
|
189
|
+
│ │ ├── server.ts Thin Web API adapter over shared operations
|
|
190
|
+
│ │ ├── static.ts HTML/CSS shell
|
|
191
|
+
│ │ ├── client-shell.ts Pane sizing/collapse behavior
|
|
192
|
+
│ │ ├── client-review.ts Review queue + candidate draft/request model
|
|
193
|
+
│ │ ├── client-script.ts DOM composition and event wiring
|
|
194
|
+
│ │ └── client-text.ts Localized UI strings
|
|
124
195
|
│ └── tests/
|
|
125
196
|
│ ├── search-*.test.ts
|
|
126
197
|
│ ├── trap-*.test.ts
|
|
@@ -130,8 +201,7 @@ codetrap/
|
|
|
130
201
|
│ ├── scope-migration-cli.test.ts
|
|
131
202
|
│ ├── import-export-cli.test.ts
|
|
132
203
|
│ └── fixtures/search-eval.json
|
|
133
|
-
├──
|
|
134
|
-
├── plugins/codetrap-agent/ Sample Codex plugin bundle
|
|
204
|
+
├── plugins/codetrap-agent/ Codex plugin bundle with skills, MCP config, hooks, and templates
|
|
135
205
|
├── scripts/ Release asset and preflight scripts
|
|
136
206
|
├── docs/ Architecture + reference docs
|
|
137
207
|
├── package.json
|
|
@@ -144,7 +214,7 @@ codetrap/
|
|
|
144
214
|
| Command | Description |
|
|
145
215
|
|---|---|
|
|
146
216
|
| `init` | Initialize `.codetrap/` in current project |
|
|
147
|
-
| `add` | Record a
|
|
217
|
+
| `add` | Record a confirmed trap (`--json` structured input; interactive mode is not implemented) |
|
|
148
218
|
| `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) |
|
|
149
219
|
| `list` | List traps (--category, --scope, --status, --path, --module, --owner, --limit, --json) |
|
|
150
220
|
| `show <id>` | Show full trap details (--json) |
|
|
@@ -159,8 +229,10 @@ codetrap/
|
|
|
159
229
|
| `doctor` | Diagnose cwd, scope, database paths, trap counts, and embedding health (--json) |
|
|
160
230
|
| `repair-scope` | Move legacy mis-scoped project traps into the current project (dry-run by default, `--apply` to mutate, `--json`) |
|
|
161
231
|
| `migrate-project` | Move project traps between initialized projects (`--from-project-path`, `--to-project-path`, dry-run by default, `--apply`, `--json`) |
|
|
162
|
-
| `embed` | Generate embeddings (requires
|
|
163
|
-
| `
|
|
232
|
+
| `embed` | Generate embeddings (requires configured Ollama or Jina provider) |
|
|
233
|
+
| `embeddings` | Manage embedding profiles (`status`, `list`, `use ollama|jina`, `reindex`) |
|
|
234
|
+
| `session` | Start a development session, append notes, capture post-flight candidates, promote explicit structured trap notes into candidates, accept/reject candidates, and clean up session files |
|
|
235
|
+
| `web` | Start the local review, trap library, insights, and Embeddings console |
|
|
164
236
|
| `serve` | Start MCP server |
|
|
165
237
|
|
|
166
238
|
### Session Mode
|
|
@@ -170,15 +242,36 @@ Session mode stores temporary working memory in `.codetrap/sessions/`. It does n
|
|
|
170
242
|
```bash
|
|
171
243
|
codetrap session start "implement agent harness" --spec docs/agent-harness-spec.md --module agent-runtime
|
|
172
244
|
codetrap session note --kind decision --text "Defaulted tool calls to 30s because the spec does not define timeout behavior."
|
|
173
|
-
|
|
245
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
246
|
+
Title: Do not parse nested tool calls with regex
|
|
247
|
+
Context: When implementing parser logic for nested tool-call arguments.
|
|
248
|
+
Mistake: Using regex to split nested calls corrupts arguments.
|
|
249
|
+
Fix: Use a tokenizer/parser and add regression tests for nested calls.
|
|
250
|
+
Tags: parser, tool-calls
|
|
251
|
+
Severity: error
|
|
252
|
+
EOF
|
|
174
253
|
codetrap session close --propose-traps
|
|
175
254
|
codetrap session candidates
|
|
176
255
|
codetrap session candidate cand-001
|
|
256
|
+
|
|
257
|
+
# Only after explicit human approval:
|
|
177
258
|
codetrap session accept cand-001
|
|
178
259
|
```
|
|
179
260
|
|
|
261
|
+
`session capture` is the low-friction post-flight path: an agent drafts a structured Markdown or JSON candidate, codetrap scores it and puts it in the session inbox, and nothing is written to `traps.db` until the candidate is accepted. If no session is active, capture creates a post-flight session, writes the candidate and recap, then closes it.
|
|
262
|
+
|
|
263
|
+
Pending candidates are surfaced through `codetrap session status`, `codetrap session list`, `codetrap doctor`, and the local `codetrap web` review console so candidate lessons do not disappear into session files.
|
|
264
|
+
|
|
180
265
|
`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
266
|
|
|
267
|
+
Session maintenance commands keep temporary files from becoming stale context:
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
codetrap session cleanup <session-id> --deleted-trap-candidates
|
|
271
|
+
codetrap session delete <session-id>
|
|
272
|
+
codetrap session prune --older-than 90d --apply
|
|
273
|
+
```
|
|
274
|
+
|
|
182
275
|
## Agent Integration
|
|
183
276
|
|
|
184
277
|
For AI coding agents, use the CLI as the default integration path:
|
|
@@ -225,13 +318,13 @@ Default to CLI JSON from the current project cwd:
|
|
|
225
318
|
codetrap search "<keywords>" --mode hybrid --json
|
|
226
319
|
```
|
|
227
320
|
|
|
228
|
-
Read the top 3 action cards before deciding no trap applies.
|
|
321
|
+
Read 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 cards, inspect before editing when the card is highly relevant or has `critical`/`error` severity:
|
|
229
322
|
|
|
230
323
|
```bash
|
|
231
324
|
codetrap show <id> --scope <project|global> --json
|
|
232
325
|
```
|
|
233
326
|
|
|
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.
|
|
327
|
+
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.
|
|
235
328
|
|
|
236
329
|
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
330
|
|
|
@@ -242,7 +335,12 @@ For longer implementation work, use session mode to keep temporary notes and exp
|
|
|
242
335
|
```bash
|
|
243
336
|
codetrap session start "<goal>"
|
|
244
337
|
codetrap session note --kind decision --text "<what changed and why>"
|
|
245
|
-
codetrap session
|
|
338
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
339
|
+
Title: <durable pitfall>
|
|
340
|
+
Context: <when it triggers>
|
|
341
|
+
Mistake: <what the agent did wrong>
|
|
342
|
+
Fix: <what to do instead>
|
|
343
|
+
EOF
|
|
246
344
|
codetrap session close --propose-traps
|
|
247
345
|
codetrap session candidates
|
|
248
346
|
```
|
|
@@ -262,26 +360,27 @@ Recommended behavior:
|
|
|
262
360
|
- Use `codetrap search --json` before risky edits in APIs, auth, database, security, migrations, or project conventions.
|
|
263
361
|
- Read the top 3 returned action cards, or all returned cards if fewer than 3, before deciding there is no relevant trap.
|
|
264
362
|
- Run the returned `next_action.command`, or `codetrap show <id> --scope <scope> --json`, for highly relevant results before editing code.
|
|
265
|
-
- Treat `critical` or `error` traps as worth drilling into when they are plausibly related, even if they are not ranked first.
|
|
266
|
-
- When editing a known area, pass applicability hints such as `--path
|
|
363
|
+
- Treat `critical` or `error` traps as worth drilling into only when they are plausibly related, even if they are not ranked first. 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. Severity alone is not enough to apply a trap.
|
|
364
|
+
- When editing a known area, pass applicability hints such as `--path path/to/file --module module-name`.
|
|
267
365
|
- 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.
|
|
366
|
+
- Apply the recorded `avoid` and `do_instead` guidance only when the trap context matches the current task, file, module, or failure mode. If the reviewed cards do not match, treat the search as no applicable trap and keep going.
|
|
269
367
|
- 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,
|
|
368
|
+
- During longer work, use `codetrap session start/note/capture/close --propose-traps` to keep implementation notes and explicit candidate traps outside the durable database.
|
|
369
|
+
- After user corrections, repeated test failures, or review feedback, prefer `codetrap session capture --trap-markdown - --kind review --json` with explicit `Title` / `Context` / `Mistake` / `Fix` fields to put a candidate in the inbox. `--trap-json` remains supported for structured callers. Ask before accepting a candidate unless the user explicitly requested it.
|
|
272
370
|
|
|
273
|
-
### Codex Skills
|
|
371
|
+
### Codex Plugin Skills
|
|
274
372
|
|
|
275
|
-
Codex
|
|
373
|
+
Codex skills are distributed through the bundled plugin at `plugins/codetrap-agent/skills/`:
|
|
276
374
|
|
|
277
375
|
- `codetrap-check` — pre-flight check before code changes.
|
|
278
376
|
- `codetrap-search` — search existing lessons.
|
|
279
|
-
- `codetrap-
|
|
377
|
+
- `codetrap-capture` — propose an agent-discovered post-flight lesson into the candidate inbox.
|
|
378
|
+
- `codetrap-add` — record a confirmed pitfall only after explicit user approval.
|
|
280
379
|
- `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.
|
|
281
380
|
|
|
282
|
-
|
|
381
|
+
The plugin skill directory is the single source of truth for Codex skill packaging. The repo does not keep a duplicate root `skills/` tree.
|
|
283
382
|
|
|
284
|
-
|
|
383
|
+
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.
|
|
285
384
|
|
|
286
385
|
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
386
|
|
|
@@ -329,7 +428,11 @@ codetrap://project/recent?cwd=%2Fpath%2Fto%2Fproject
|
|
|
329
428
|
|
|
330
429
|
| Env Variable | Required | Description |
|
|
331
430
|
|---|---|---|
|
|
332
|
-
| `
|
|
431
|
+
| `CODETRAP_EMBEDDING_PROVIDER` | No | Embedding provider for semantic/hybrid search: `ollama` or `jina`. Recommended local value: `ollama` |
|
|
432
|
+
| `CODETRAP_OLLAMA_MODEL` | No | Ollama embedding model. Recommended: `qwen3-embedding:0.6b` |
|
|
433
|
+
| `CODETRAP_OLLAMA_ENDPOINT` | No | Ollama endpoint. Default: `http://127.0.0.1:11434` |
|
|
434
|
+
| `CODETRAP_OLLAMA_DIMENSIONS` | No | Ollama embedding dimensions. Default: `1024` for `qwen3-embedding:0.6b` |
|
|
435
|
+
| `JINA_API_KEY` | No | Jina AI API key for optional cloud semantic/hybrid search. Get one at [jina.ai](https://jina.ai/api-dashboard/) |
|
|
333
436
|
| `CODETRAP_SEARCH_MODE` | No | Default search mode: `fts`, `semantic`, or `hybrid` |
|
|
334
437
|
| `CODETRAP_SEARCH_LIMIT` | No | Default search result limit |
|
|
335
438
|
| `CODETRAP_SEARCH_SCOPE` | No | Default search scope: `project` or `global` |
|
|
@@ -344,6 +447,12 @@ Behavior preferences can also live in `~/.codetrap/config.json`; CLI args overri
|
|
|
344
447
|
"limit": 20,
|
|
345
448
|
"scope": "project",
|
|
346
449
|
"rerank": true
|
|
450
|
+
},
|
|
451
|
+
"embeddings": {
|
|
452
|
+
"provider": "ollama",
|
|
453
|
+
"endpoint": "http://127.0.0.1:11434",
|
|
454
|
+
"model": "qwen3-embedding:0.6b",
|
|
455
|
+
"dimensions": 1024
|
|
347
456
|
}
|
|
348
457
|
}
|
|
349
458
|
```
|
|
@@ -364,61 +473,60 @@ Trap JSON supports optional applicability fields:
|
|
|
364
473
|
|
|
365
474
|
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.
|
|
366
475
|
|
|
367
|
-
###
|
|
476
|
+
### Local Ollama Embeddings Setup
|
|
368
477
|
|
|
369
|
-
codetrap works
|
|
478
|
+
codetrap works with no embedding provider. In that mode, search uses local SQLite FTS keyword matching, and hybrid search falls back to FTS.
|
|
370
479
|
|
|
371
|
-
|
|
480
|
+
Recommended local semantic search uses Ollama with `qwen3-embedding:0.6b`. This keeps trap passages and query text on your machine.
|
|
372
481
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
macOS or Linux with zsh:
|
|
482
|
+
1. Install Ollama, then pull the 0.6B embedding model:
|
|
376
483
|
|
|
377
484
|
```bash
|
|
378
|
-
|
|
379
|
-
source ~/.zshrc
|
|
485
|
+
ollama pull qwen3-embedding:0.6b
|
|
380
486
|
```
|
|
381
487
|
|
|
382
|
-
|
|
488
|
+
Do not omit `:0.6b`; `qwen3-embedding:latest` is much larger.
|
|
383
489
|
|
|
384
|
-
|
|
385
|
-
echo 'export JINA_API_KEY="your-jina-api-key"' >> ~/.bashrc
|
|
386
|
-
source ~/.bashrc
|
|
387
|
-
```
|
|
490
|
+
2. Configure codetrap to use Ollama:
|
|
388
491
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
setx JINA_API_KEY "your-jina-api-key"
|
|
492
|
+
```bash
|
|
493
|
+
codetrap embeddings use ollama
|
|
494
|
+
codetrap embeddings status
|
|
393
495
|
```
|
|
394
496
|
|
|
395
|
-
|
|
497
|
+
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.
|
|
396
498
|
|
|
397
|
-
3. Verify
|
|
499
|
+
3. Verify Ollama embedding generation:
|
|
398
500
|
|
|
399
501
|
```bash
|
|
400
|
-
|
|
502
|
+
curl http://127.0.0.1:11434/api/embed -d '{"model":"qwen3-embedding:0.6b","input":"HTTP request timeout"}'
|
|
401
503
|
```
|
|
402
504
|
|
|
403
505
|
4. Generate embeddings for the traps you want semantic search to use:
|
|
404
506
|
|
|
405
507
|
```bash
|
|
406
508
|
cd /path/to/your/project
|
|
407
|
-
codetrap
|
|
408
|
-
codetrap
|
|
509
|
+
codetrap embeddings reindex --scope project
|
|
510
|
+
codetrap embeddings reindex --scope global
|
|
409
511
|
```
|
|
410
512
|
|
|
513
|
+
`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.
|
|
514
|
+
|
|
515
|
+
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.
|
|
516
|
+
|
|
411
517
|
5. Search with hybrid mode:
|
|
412
518
|
|
|
413
519
|
```bash
|
|
414
520
|
codetrap search "HTTP request timeout" --mode hybrid
|
|
415
521
|
```
|
|
416
522
|
|
|
417
|
-
|
|
523
|
+
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.
|
|
524
|
+
|
|
525
|
+
If no embedding provider is configured:
|
|
418
526
|
|
|
419
527
|
- `codetrap search "<query>" --mode fts` works normally.
|
|
420
528
|
- `codetrap search "<query>" --mode hybrid` works, but falls back to FTS.
|
|
421
|
-
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require
|
|
529
|
+
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require an embedding provider.
|
|
422
530
|
|
|
423
531
|
## Build
|
|
424
532
|
|
|
@@ -445,7 +553,7 @@ bun run eval:dogfood -- report --live # Dogfood eval with configured embedding
|
|
|
445
553
|
|---|---|
|
|
446
554
|
| Runtime | Bun + TypeScript |
|
|
447
555
|
| Database | SQLite (bun:sqlite) + FTS5 |
|
|
448
|
-
| Embeddings | Jina AI (`jina-embeddings-v5-text-small`) |
|
|
556
|
+
| Embeddings | Local Ollama (`qwen3-embedding:0.6b`) or Jina AI (`jina-embeddings-v5-text-small`) |
|
|
449
557
|
| MCP | `@modelcontextprotocol/sdk` |
|
|
450
558
|
| Search | FTS5 + cosine similarity + RRF fusion + generic rerank |
|
|
451
559
|
|