codetrap 0.1.7 → 0.1.9
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 +132 -98
- package/docs/installation.md +61 -63
- package/package.json +4 -3
- package/plugins/codetrap-agent/.codex-plugin/plugin.json +2 -3
- 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-maintainer.md +15 -0
- package/plugins/codetrap-agent/templates/AGENTS.codetrap.md +16 -5
- package/scripts/release-preflight.ts +15 -0
- package/scripts/search-policy-sweep.ts +131 -0
- package/src/commands/workflow.ts +172 -68
- 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 +34 -4
- package/src/lib/codex-setup.ts +247 -0
- package/src/lib/command-requests.ts +112 -1
- package/src/lib/config.ts +57 -7
- package/src/lib/constants.ts +1 -1
- package/src/lib/doctor.ts +42 -12
- 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 +12 -6
- package/src/lib/scope-migration.ts +2 -1
- package/src/lib/scope.ts +0 -2
- package/src/lib/search-eval.ts +38 -18
- 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 +83 -60
- package/src/lib/session-review.ts +327 -0
- package/src/lib/session-store.ts +87 -73
- package/src/lib/store.ts +74 -10
- 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 +426 -51
- package/src/web/client-shell.ts +414 -0
- package/src/web/client-text.ts +112 -0
- package/src/web/project-registry.ts +3 -5
- package/src/web/server.ts +117 -103
- package/src/web/static.ts +364 -19
- 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,45 @@ 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 setup codex
|
|
68
|
+
codetrap doctor
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`codetrap setup codex` installs the bundled Codex skills into `~/.codex/skills`, initializes `.codetrap/` when needed, and writes `AGENTS.md`. It does not configure MCP by default.
|
|
72
|
+
|
|
73
|
+
To also configure Codex MCP, opt in explicitly:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
codetrap setup codex --mcp
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The packaged template is the source of truth for exact agent behavior. It tells agents to run CLI JSON checks before non-trivial edits, inspect only relevant action cards, keep post-flight lessons in the session candidate inbox, and require explicit human approval before accepting a candidate into `traps.db`.
|
|
80
|
+
|
|
81
|
+
For a quick manual check, agents can run `codetrap search "<task keywords>" --mode hybrid --json` from the project cwd.
|
|
82
|
+
|
|
56
83
|
## Features
|
|
57
84
|
|
|
58
85
|
- **Structured trap recording** — title, category, context, mistake, fix, severity, tags, lifecycle, evidence, before/after code
|
|
59
86
|
- **Session mode capture** — record implementation notes, promote explicit structured trap notes into candidates, and save only user-accepted lessons
|
|
60
87
|
- **Dual scope** — project-scoped (`.codetrap/traps.db`) and global (`~/.codetrap/traps.db`)
|
|
61
88
|
- **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)
|
|
89
|
+
- **Three search modes** — FTS (SQLite FTS5), semantic (local Ollama or Jina embeddings), hybrid (RRF fusion)
|
|
63
90
|
- **Chinese + mixed-language search** — CJK bigram tokenizer, synonym map for Chinese-English terms
|
|
64
91
|
- **MCP server** — optional tools + resources for AI agent integration
|
|
65
|
-
- **Embedding cache** with freshness tracking —
|
|
92
|
+
- **Embedding cache** with multi-profile freshness tracking — Jina/Ollama vectors can coexist and stale ones auto-invalidate
|
|
66
93
|
- **Doctor diagnostics** — scope, database, and embedding health in text or JSON
|
|
67
|
-
- **Schema migrations** — in-code migration system from v0 through current
|
|
94
|
+
- **Schema migrations** — in-code migration system from v0 through current v6
|
|
68
95
|
- **Single-binary builds** — `bun build --compile` produces standalone binaries in `dist/`
|
|
69
96
|
|
|
70
97
|
## Directory Structure
|
|
@@ -74,7 +101,7 @@ codetrap/
|
|
|
74
101
|
├── src/
|
|
75
102
|
│ ├── index.ts CLI entry point
|
|
76
103
|
│ ├── mcp-server.ts MCP server entry point
|
|
77
|
-
│ ├── commands/router.ts
|
|
104
|
+
│ ├── commands/router.ts Optional thin CLI adapter + renderer
|
|
78
105
|
│ ├── commands/workflow.ts CLI command behavior
|
|
79
106
|
│ ├── commands/command-result.ts CLI command results + rendering
|
|
80
107
|
│ ├── mcp/
|
|
@@ -87,9 +114,12 @@ codetrap/
|
|
|
87
114
|
│ │ ├── store.ts Project/global scope orchestration
|
|
88
115
|
│ │ ├── trap-operations.ts Shared CLI/MCP operation semantics
|
|
89
116
|
│ │ ├── session-operations.ts Session command semantics + accept/reject flow
|
|
117
|
+
│ │ ├── session-review.ts Shared session review payloads + CLI conflict presenter
|
|
90
118
|
│ │ ├── session-store.ts Session files, active state, index, recaps
|
|
91
119
|
│ │ ├── session-codec.ts Session JSON/Markdown/candidate file conversion
|
|
92
|
-
│ │ ├── session-capture.ts Candidate
|
|
120
|
+
│ │ ├── session-capture.ts Candidate draft normalization, extraction, and merge policy
|
|
121
|
+
│ │ ├── session-candidate-document.ts Candidate document transition rules
|
|
122
|
+
│ │ ├── session-candidate-scope.ts Candidate accepted-scope fallback
|
|
93
123
|
│ │ ├── session-conflicts.ts Candidate vs active-trap conflict checks
|
|
94
124
|
│ │ ├── trap-quality.ts Deterministic candidate quality scoring
|
|
95
125
|
│ │ ├── command-requests.ts CLI/MCP request normalization helpers
|
|
@@ -97,7 +127,9 @@ codetrap/
|
|
|
97
127
|
│ │ ├── scope-context.ts cwd/project/global DB context + repo selection
|
|
98
128
|
│ │ ├── scope-migration.ts Safe project trap scope repair/migration
|
|
99
129
|
│ │ ├── doctor.ts Scope and embedding health diagnostics
|
|
130
|
+
│ │ ├── embedding-runtime.ts Embedding provider runtime/config/status
|
|
100
131
|
│ │ ├── embedding-health.ts Fresh/stale/missing embedding summaries
|
|
132
|
+
│ │ ├── embedding-management.ts Embedding profile command output
|
|
101
133
|
│ │ ├── search-service.ts FTS/semantic/hybrid candidate retrieval
|
|
102
134
|
│ │ ├── search-policy.ts Applicability filtering, rerank, fusion signals
|
|
103
135
|
│ │ ├── search-result-card.ts Compact agent-facing result cards
|
|
@@ -107,10 +139,13 @@ codetrap/
|
|
|
107
139
|
│ │ ├── trap-json-fields.ts Tags/path/evidence JSON array codec
|
|
108
140
|
│ │ ├── trap-codec.ts Storage/JSON/archive/import shape conversion
|
|
109
141
|
│ │ ├── trap-mutation-result.ts Mutation result + scope fallback semantics
|
|
142
|
+
│ │ ├── string-list.ts Shared string list de-duping
|
|
143
|
+
│ │ ├── text-lines.ts Shared line trimming helpers
|
|
144
|
+
│ │ ├── value-types.ts Shared runtime value guards
|
|
110
145
|
│ │ ├── trap-scope-match.ts Path/module/owner applicability matching
|
|
111
146
|
│ │ ├── trap-archive.ts Import/export compatibility
|
|
112
147
|
│ │ ├── trap-transfer.ts DB-to-DB transfer for scope migration
|
|
113
|
-
│ │ ├── embedder.ts Jina Embeddings
|
|
148
|
+
│ │ ├── embedder.ts Ollama and Jina Embeddings adapters
|
|
114
149
|
│ │ ├── embedding-job.ts Batch embedding generation
|
|
115
150
|
│ │ ├── format.ts CLI output formatting
|
|
116
151
|
│ │ ├── scope.ts Project root detection
|
|
@@ -121,6 +156,13 @@ codetrap/
|
|
|
121
156
|
│ │ ├── queries.ts CRUD, search, stats, import/export
|
|
122
157
|
│ │ ├── embedding-queries.ts Embedding storage SQL
|
|
123
158
|
│ │ └── repository.ts Single-DB facade
|
|
159
|
+
│ ├── web/
|
|
160
|
+
│ │ ├── server.ts Thin Web API adapter over shared operations
|
|
161
|
+
│ │ ├── static.ts HTML/CSS shell
|
|
162
|
+
│ │ ├── client-shell.ts Pane sizing/collapse behavior
|
|
163
|
+
│ │ ├── client-review.ts Review queue + candidate draft/request model
|
|
164
|
+
│ │ ├── client-script.ts DOM composition and event wiring
|
|
165
|
+
│ │ └── client-text.ts Localized UI strings
|
|
124
166
|
│ └── tests/
|
|
125
167
|
│ ├── search-*.test.ts
|
|
126
168
|
│ ├── trap-*.test.ts
|
|
@@ -130,8 +172,7 @@ codetrap/
|
|
|
130
172
|
│ ├── scope-migration-cli.test.ts
|
|
131
173
|
│ ├── import-export-cli.test.ts
|
|
132
174
|
│ └── fixtures/search-eval.json
|
|
133
|
-
├──
|
|
134
|
-
├── plugins/codetrap-agent/ Sample Codex plugin bundle
|
|
175
|
+
├── plugins/codetrap-agent/ Codex plugin bundle with skills, MCP config, hooks, and templates
|
|
135
176
|
├── scripts/ Release asset and preflight scripts
|
|
136
177
|
├── docs/ Architecture + reference docs
|
|
137
178
|
├── package.json
|
|
@@ -144,7 +185,7 @@ codetrap/
|
|
|
144
185
|
| Command | Description |
|
|
145
186
|
|---|---|
|
|
146
187
|
| `init` | Initialize `.codetrap/` in current project |
|
|
147
|
-
| `add` | Record a
|
|
188
|
+
| `add` | Record a confirmed trap (`--json` structured input; interactive mode is not implemented) |
|
|
148
189
|
| `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
190
|
| `list` | List traps (--category, --scope, --status, --path, --module, --owner, --limit, --json) |
|
|
150
191
|
| `show <id>` | Show full trap details (--json) |
|
|
@@ -157,11 +198,13 @@ codetrap/
|
|
|
157
198
|
| `import` | Import traps from JSON (--json) |
|
|
158
199
|
| `stats` | Show database statistics (--json includes embedding health) |
|
|
159
200
|
| `doctor` | Diagnose cwd, scope, database paths, trap counts, and embedding health (--json) |
|
|
201
|
+
| `setup codex` | Install Codex skills and project guidance; MCP is opt-in with `--mcp` |
|
|
160
202
|
| `repair-scope` | Move legacy mis-scoped project traps into the current project (dry-run by default, `--apply` to mutate, `--json`) |
|
|
161
203
|
| `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
|
-
| `
|
|
164
|
-
| `
|
|
204
|
+
| `embed` | Generate embeddings (requires configured Ollama or Jina provider) |
|
|
205
|
+
| `embeddings` | Manage embedding profiles (`status`, `list`, `use ollama|jina`, `reindex`) |
|
|
206
|
+
| `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 |
|
|
207
|
+
| `web` | Start the local review, trap library, insights, and Embeddings console |
|
|
165
208
|
| `serve` | Start MCP server |
|
|
166
209
|
|
|
167
210
|
### Session Mode
|
|
@@ -171,13 +214,26 @@ Session mode stores temporary working memory in `.codetrap/sessions/`. It does n
|
|
|
171
214
|
```bash
|
|
172
215
|
codetrap session start "implement agent harness" --spec docs/agent-harness-spec.md --module agent-runtime
|
|
173
216
|
codetrap session note --kind decision --text "Defaulted tool calls to 30s because the spec does not define timeout behavior."
|
|
174
|
-
|
|
217
|
+
cat <<'EOF' | codetrap session capture --trap-markdown - --kind review --json
|
|
218
|
+
Title: Do not parse nested tool calls with regex
|
|
219
|
+
Context: When implementing parser logic for nested tool-call arguments.
|
|
220
|
+
Mistake: Using regex to split nested calls corrupts arguments.
|
|
221
|
+
Fix: Use a tokenizer/parser and add regression tests for nested calls.
|
|
222
|
+
Tags: parser, tool-calls
|
|
223
|
+
Severity: error
|
|
224
|
+
EOF
|
|
175
225
|
codetrap session close --propose-traps
|
|
176
226
|
codetrap session candidates
|
|
177
227
|
codetrap session candidate cand-001
|
|
228
|
+
|
|
229
|
+
# Only after explicit human approval:
|
|
178
230
|
codetrap session accept cand-001
|
|
179
231
|
```
|
|
180
232
|
|
|
233
|
+
`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.
|
|
234
|
+
|
|
235
|
+
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.
|
|
236
|
+
|
|
181
237
|
`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.
|
|
182
238
|
|
|
183
239
|
Session maintenance commands keep temporary files from becoming stale context:
|
|
@@ -198,14 +254,28 @@ For AI coding agents, use the CLI as the default integration path:
|
|
|
198
254
|
|
|
199
255
|
CLI and project guidance are the main path. MCP should stay thin and share the same store/search behavior.
|
|
200
256
|
|
|
201
|
-
###
|
|
257
|
+
### Codex Setup
|
|
258
|
+
|
|
259
|
+
Default setup installs skills and project guidance without MCP:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
codetrap setup codex
|
|
263
|
+
```
|
|
202
264
|
|
|
203
|
-
|
|
265
|
+
MCP is optional. To configure it too, opt in explicitly:
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
codetrap setup codex --mcp
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
You can also add MCP manually:
|
|
204
272
|
|
|
205
273
|
```bash
|
|
206
274
|
codex mcp add codetrap -- codetrap serve
|
|
207
275
|
```
|
|
208
276
|
|
|
277
|
+
### MCP Setup
|
|
278
|
+
|
|
209
279
|
Generic MCP client config:
|
|
210
280
|
|
|
211
281
|
```json
|
|
@@ -221,76 +291,31 @@ Generic MCP client config:
|
|
|
221
291
|
|
|
222
292
|
### Project Guidance
|
|
223
293
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
````md
|
|
227
|
-
## Codetrap
|
|
228
|
-
|
|
229
|
-
Before non-trivial code edits, check codetrap for relevant pitfalls.
|
|
230
|
-
|
|
231
|
-
Default to CLI JSON from the current project cwd:
|
|
232
|
-
|
|
233
|
-
```bash
|
|
234
|
-
codetrap search "<keywords>" --mode hybrid --json
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
Read the top 3 action cards before deciding no trap applies. If a card is highly relevant, or has `critical`/`error` severity and is plausibly related, inspect it before editing:
|
|
238
|
-
|
|
239
|
-
```bash
|
|
240
|
-
codetrap show <id> --scope <project|global> --json
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
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.
|
|
244
|
-
|
|
245
|
-
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.
|
|
246
|
-
|
|
247
|
-
When `.codetrap/` exists, prefer project scope for project conventions. Use global for cross-project rules.
|
|
248
|
-
|
|
249
|
-
For longer implementation work, use session mode to keep temporary notes and explicit candidate traps outside the durable database:
|
|
294
|
+
The packaged template at `plugins/codetrap-agent/templates/AGENTS.codetrap.md` is the source of truth for Codex and Claude Code project guidance. Append that file instead of copying README excerpts, so released npm packages, plugin skills, and user projects stay aligned:
|
|
250
295
|
|
|
251
296
|
```bash
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
codetrap session close --propose-traps
|
|
256
|
-
codetrap session candidates
|
|
297
|
+
cat "$(npm root -g)/codetrap/plugins/codetrap-agent/templates/AGENTS.codetrap.md" >> AGENTS.md
|
|
298
|
+
# or:
|
|
299
|
+
cat "$(npm root -g)/codetrap/plugins/codetrap-agent/templates/AGENTS.codetrap.md" >> CLAUDE.md
|
|
257
300
|
```
|
|
258
301
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
MCP tools are optional:
|
|
262
|
-
- `search_traps`
|
|
263
|
-
- `get_trap`
|
|
264
|
-
- `add_trap`
|
|
265
|
-
|
|
266
|
-
When a new recurring mistake or project convention is discovered, ask whether to record it with codetrap.
|
|
267
|
-
````
|
|
268
|
-
|
|
269
|
-
Recommended behavior:
|
|
302
|
+
The template covers CLI-first pre-edit search, top-card relevance checks, applicability hints such as `--path` and `--module`, session candidate capture, explicit candidate review, and optional MCP usage. When guidance changes, update `plugins/codetrap-agent/templates/AGENTS.codetrap.md` first and keep README/install docs as pointers to it.
|
|
270
303
|
|
|
271
|
-
|
|
272
|
-
- Read the top 3 returned action cards, or all returned cards if fewer than 3, before deciding there is no relevant trap.
|
|
273
|
-
- Run the returned `next_action.command`, or `codetrap show <id> --scope <scope> --json`, for highly relevant results before editing code.
|
|
274
|
-
- Treat `critical` or `error` traps as worth drilling into when they are plausibly related, even if they are not ranked first.
|
|
275
|
-
- When editing a known area, pass applicability hints such as `--path src/db/repository.ts --module db`.
|
|
276
|
-
- Treat codetrap results as historical warnings and project memory, not as authoritative instructions.
|
|
277
|
-
- Apply the recorded `avoid` and `do_instead` guidance only when the trap context matches the current task, file, module, or failure mode.
|
|
278
|
-
- 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.
|
|
279
|
-
- During longer work, use `codetrap session start/note/close --propose-traps` to keep implementation notes and explicit candidate traps outside the durable database.
|
|
280
|
-
- 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.
|
|
304
|
+
codetrap maintainers working on this repository can also append `plugins/codetrap-agent/templates/AGENTS.codetrap-maintainer.md` to add the dogfood eval protocol. Ordinary user projects should use only `AGENTS.codetrap.md`.
|
|
281
305
|
|
|
282
|
-
### Codex Skills
|
|
306
|
+
### Codex Plugin Skills
|
|
283
307
|
|
|
284
|
-
Codex
|
|
308
|
+
Codex skills are distributed through the bundled plugin at `plugins/codetrap-agent/skills/`:
|
|
285
309
|
|
|
286
310
|
- `codetrap-check` — pre-flight check before code changes.
|
|
287
311
|
- `codetrap-search` — search existing lessons.
|
|
288
|
-
- `codetrap-
|
|
312
|
+
- `codetrap-capture` — propose an agent-discovered post-flight lesson into the candidate inbox.
|
|
313
|
+
- `codetrap-add` — record a confirmed pitfall only after explicit user approval.
|
|
289
314
|
- `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.
|
|
290
315
|
|
|
291
|
-
|
|
316
|
+
The plugin skill directory is the single source of truth for Codex skill packaging. The repo does not keep a duplicate root `skills/` tree.
|
|
292
317
|
|
|
293
|
-
|
|
318
|
+
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.
|
|
294
319
|
|
|
295
320
|
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:
|
|
296
321
|
|
|
@@ -338,7 +363,11 @@ codetrap://project/recent?cwd=%2Fpath%2Fto%2Fproject
|
|
|
338
363
|
|
|
339
364
|
| Env Variable | Required | Description |
|
|
340
365
|
|---|---|---|
|
|
341
|
-
| `
|
|
366
|
+
| `CODETRAP_EMBEDDING_PROVIDER` | No | Embedding provider for semantic/hybrid search: `ollama` or `jina`. Recommended local value: `ollama` |
|
|
367
|
+
| `CODETRAP_OLLAMA_MODEL` | No | Ollama embedding model. Recommended: `qwen3-embedding:0.6b` |
|
|
368
|
+
| `CODETRAP_OLLAMA_ENDPOINT` | No | Ollama endpoint. Default: `http://127.0.0.1:11434` |
|
|
369
|
+
| `CODETRAP_OLLAMA_DIMENSIONS` | No | Ollama embedding dimensions. Default: `1024` for `qwen3-embedding:0.6b` |
|
|
370
|
+
| `JINA_API_KEY` | No | Jina AI API key for optional cloud semantic/hybrid search. Get one at [jina.ai](https://jina.ai/api-dashboard/) |
|
|
342
371
|
| `CODETRAP_SEARCH_MODE` | No | Default search mode: `fts`, `semantic`, or `hybrid` |
|
|
343
372
|
| `CODETRAP_SEARCH_LIMIT` | No | Default search result limit |
|
|
344
373
|
| `CODETRAP_SEARCH_SCOPE` | No | Default search scope: `project` or `global` |
|
|
@@ -353,6 +382,12 @@ Behavior preferences can also live in `~/.codetrap/config.json`; CLI args overri
|
|
|
353
382
|
"limit": 20,
|
|
354
383
|
"scope": "project",
|
|
355
384
|
"rerank": true
|
|
385
|
+
},
|
|
386
|
+
"embeddings": {
|
|
387
|
+
"provider": "ollama",
|
|
388
|
+
"endpoint": "http://127.0.0.1:11434",
|
|
389
|
+
"model": "qwen3-embedding:0.6b",
|
|
390
|
+
"dimensions": 1024
|
|
356
391
|
}
|
|
357
392
|
}
|
|
358
393
|
```
|
|
@@ -373,61 +408,60 @@ Trap JSON supports optional applicability fields:
|
|
|
373
408
|
|
|
374
409
|
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.
|
|
375
410
|
|
|
376
|
-
###
|
|
377
|
-
|
|
378
|
-
codetrap works without a Jina API key. In that mode, search uses SQLite FTS keyword matching. If you want semantic search or stronger hybrid search, configure `JINA_API_KEY`.
|
|
411
|
+
### Local Ollama Embeddings Setup
|
|
379
412
|
|
|
380
|
-
|
|
413
|
+
codetrap works with no embedding provider. In that mode, search uses local SQLite FTS keyword matching, and hybrid search falls back to FTS.
|
|
381
414
|
|
|
382
|
-
|
|
415
|
+
Recommended local semantic search uses Ollama with `qwen3-embedding:0.6b`. This keeps trap passages and query text on your machine.
|
|
383
416
|
|
|
384
|
-
|
|
417
|
+
1. Install Ollama, then pull the 0.6B embedding model:
|
|
385
418
|
|
|
386
419
|
```bash
|
|
387
|
-
|
|
388
|
-
source ~/.zshrc
|
|
420
|
+
ollama pull qwen3-embedding:0.6b
|
|
389
421
|
```
|
|
390
422
|
|
|
391
|
-
|
|
423
|
+
Do not omit `:0.6b`; `qwen3-embedding:latest` is much larger.
|
|
392
424
|
|
|
393
|
-
|
|
394
|
-
echo 'export JINA_API_KEY="your-jina-api-key"' >> ~/.bashrc
|
|
395
|
-
source ~/.bashrc
|
|
396
|
-
```
|
|
425
|
+
2. Configure codetrap to use Ollama:
|
|
397
426
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
setx JINA_API_KEY "your-jina-api-key"
|
|
427
|
+
```bash
|
|
428
|
+
codetrap embeddings use ollama
|
|
429
|
+
codetrap embeddings status
|
|
402
430
|
```
|
|
403
431
|
|
|
404
|
-
|
|
432
|
+
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.
|
|
405
433
|
|
|
406
|
-
3. Verify
|
|
434
|
+
3. Verify Ollama embedding generation:
|
|
407
435
|
|
|
408
436
|
```bash
|
|
409
|
-
|
|
437
|
+
curl http://127.0.0.1:11434/api/embed -d '{"model":"qwen3-embedding:0.6b","input":"HTTP request timeout"}'
|
|
410
438
|
```
|
|
411
439
|
|
|
412
440
|
4. Generate embeddings for the traps you want semantic search to use:
|
|
413
441
|
|
|
414
442
|
```bash
|
|
415
443
|
cd /path/to/your/project
|
|
416
|
-
codetrap
|
|
417
|
-
codetrap
|
|
444
|
+
codetrap embeddings reindex --scope project
|
|
445
|
+
codetrap embeddings reindex --scope global
|
|
418
446
|
```
|
|
419
447
|
|
|
448
|
+
`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.
|
|
449
|
+
|
|
450
|
+
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.
|
|
451
|
+
|
|
420
452
|
5. Search with hybrid mode:
|
|
421
453
|
|
|
422
454
|
```bash
|
|
423
455
|
codetrap search "HTTP request timeout" --mode hybrid
|
|
424
456
|
```
|
|
425
457
|
|
|
426
|
-
|
|
458
|
+
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.
|
|
459
|
+
|
|
460
|
+
If no embedding provider is configured:
|
|
427
461
|
|
|
428
462
|
- `codetrap search "<query>" --mode fts` works normally.
|
|
429
463
|
- `codetrap search "<query>" --mode hybrid` works, but falls back to FTS.
|
|
430
|
-
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require
|
|
464
|
+
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require an embedding provider.
|
|
431
465
|
|
|
432
466
|
## Build
|
|
433
467
|
|
|
@@ -454,7 +488,7 @@ bun run eval:dogfood -- report --live # Dogfood eval with configured embedding
|
|
|
454
488
|
|---|---|
|
|
455
489
|
| Runtime | Bun + TypeScript |
|
|
456
490
|
| Database | SQLite (bun:sqlite) + FTS5 |
|
|
457
|
-
| Embeddings | Jina AI (`jina-embeddings-v5-text-small`) |
|
|
491
|
+
| Embeddings | Local Ollama (`qwen3-embedding:0.6b`) or Jina AI (`jina-embeddings-v5-text-small`) |
|
|
458
492
|
| MCP | `@modelcontextprotocol/sdk` |
|
|
459
493
|
| Search | FTS5 + cosine similarity + RRF fusion + generic rerank |
|
|
460
494
|
|
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,112 +232,103 @@ bun install
|
|
|
225
232
|
bun run install:cli
|
|
226
233
|
```
|
|
227
234
|
|
|
228
|
-
##
|
|
229
|
-
|
|
230
|
-
`JINA_API_KEY` is optional. Without it, codetrap still works with SQLite FTS keyword search, and hybrid search falls back to FTS.
|
|
235
|
+
## 5-Minute Agent Setup
|
|
231
236
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
macOS or Linux with zsh:
|
|
237
|
+
Use this path when the first user is a coding agent such as Codex or Claude Code.
|
|
235
238
|
|
|
236
239
|
```bash
|
|
237
|
-
|
|
238
|
-
|
|
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 setup codex
|
|
244
|
+
codetrap doctor
|
|
239
245
|
```
|
|
240
246
|
|
|
241
|
-
|
|
247
|
+
`codetrap setup codex` installs the bundled Codex skills into `~/.codex/skills`, initializes `.codetrap/` when needed, and writes `AGENTS.md`. It appends the packaged source-of-truth template at `plugins/codetrap-agent/templates/AGENTS.codetrap.md`. It does not configure MCP by default.
|
|
248
|
+
|
|
249
|
+
To also configure Codex MCP, opt in explicitly:
|
|
242
250
|
|
|
243
251
|
```bash
|
|
244
|
-
|
|
245
|
-
source ~/.bashrc
|
|
252
|
+
codetrap setup codex --mcp
|
|
246
253
|
```
|
|
247
254
|
|
|
248
|
-
|
|
255
|
+
The packaged template is the source of truth for exact agent behavior. It tells agents to run CLI JSON checks before non-trivial edits, inspect only relevant action cards, keep post-flight lessons in the session candidate inbox, and require explicit human approval before accepting a candidate into `traps.db`.
|
|
249
256
|
|
|
250
|
-
|
|
251
|
-
setx JINA_API_KEY "your-jina-api-key"
|
|
252
|
-
```
|
|
257
|
+
For a quick manual check, agents can run `codetrap search "<task keywords>" --mode hybrid --json` from the project cwd.
|
|
253
258
|
|
|
254
|
-
|
|
259
|
+
## Optional: Local Ollama Embeddings
|
|
255
260
|
|
|
256
|
-
|
|
261
|
+
codetrap works with no embedding provider. In that mode, search uses SQLite FTS keyword matching, and hybrid search falls back to FTS.
|
|
257
262
|
|
|
258
|
-
|
|
259
|
-
bun -e 'console.log(process.env.JINA_API_KEY ? "has-key" : "no-key")'
|
|
260
|
-
```
|
|
263
|
+
Recommended local semantic search uses Ollama with `qwen3-embedding:0.6b`. This keeps trap passages and query text on your machine.
|
|
261
264
|
|
|
262
|
-
|
|
265
|
+
Install Ollama, then pull the 0.6B embedding model:
|
|
263
266
|
|
|
264
267
|
```bash
|
|
265
|
-
|
|
266
|
-
codetrap embed --scope project
|
|
267
|
-
codetrap embed --scope global
|
|
268
|
+
ollama pull qwen3-embedding:0.6b
|
|
268
269
|
```
|
|
269
270
|
|
|
270
|
-
|
|
271
|
+
Do not omit `:0.6b`; `qwen3-embedding:latest` is much larger.
|
|
272
|
+
|
|
273
|
+
Configure codetrap to use Ollama:
|
|
271
274
|
|
|
272
275
|
```bash
|
|
273
|
-
codetrap
|
|
276
|
+
codetrap embeddings use ollama
|
|
277
|
+
codetrap embeddings status
|
|
274
278
|
```
|
|
275
279
|
|
|
276
|
-
|
|
280
|
+
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.
|
|
277
281
|
|
|
278
|
-
|
|
279
|
-
- `codetrap search "<query>" --mode hybrid` works, but falls back to FTS.
|
|
280
|
-
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require `JINA_API_KEY`.
|
|
281
|
-
|
|
282
|
-
## Optional: Codex MCP
|
|
283
|
-
|
|
284
|
-
If the `codetrap` command is on your `PATH`, add it to Codex as an MCP server:
|
|
282
|
+
Verify Ollama embedding generation:
|
|
285
283
|
|
|
286
284
|
```bash
|
|
287
|
-
|
|
285
|
+
curl http://127.0.0.1:11434/api/embed -d '{"model":"qwen3-embedding:0.6b","input":"HTTP request timeout"}'
|
|
288
286
|
```
|
|
289
287
|
|
|
290
|
-
|
|
288
|
+
Generate embeddings for the traps you want semantic search to use:
|
|
291
289
|
|
|
292
290
|
```bash
|
|
293
|
-
|
|
291
|
+
cd /path/to/your/project
|
|
292
|
+
codetrap embeddings reindex --scope project
|
|
293
|
+
codetrap embeddings reindex --scope global
|
|
294
294
|
```
|
|
295
295
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
```md
|
|
299
|
-
Before non-trivial code edits, check codetrap from the current project cwd:
|
|
296
|
+
`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.
|
|
300
297
|
|
|
301
|
-
codetrap
|
|
298
|
+
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.
|
|
302
299
|
|
|
303
|
-
|
|
300
|
+
Then search:
|
|
304
301
|
|
|
305
|
-
|
|
302
|
+
```bash
|
|
303
|
+
codetrap search "HTTP request timeout" --mode hybrid
|
|
304
|
+
```
|
|
306
305
|
|
|
307
|
-
When
|
|
306
|
+
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.
|
|
308
307
|
|
|
309
|
-
|
|
308
|
+
If no embedding provider is configured:
|
|
310
309
|
|
|
311
|
-
|
|
310
|
+
- `codetrap search "<query>" --mode fts` works normally.
|
|
311
|
+
- `codetrap search "<query>" --mode hybrid` works, but falls back to FTS.
|
|
312
|
+
- `codetrap search "<query>" --mode semantic` and `codetrap embed` require an embedding provider.
|
|
312
313
|
|
|
313
|
-
|
|
314
|
+
## Optional: Codex MCP
|
|
314
315
|
|
|
315
|
-
|
|
316
|
+
MCP is optional. `codetrap setup codex` does not configure MCP unless you pass `--mcp`:
|
|
316
317
|
|
|
317
318
|
```bash
|
|
318
|
-
codetrap
|
|
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
|
|
319
|
+
codetrap setup codex --mcp
|
|
323
320
|
```
|
|
324
321
|
|
|
325
|
-
|
|
322
|
+
You can also add MCP manually if the `codetrap` command is on your `PATH`:
|
|
326
323
|
|
|
327
324
|
```bash
|
|
328
|
-
codetrap
|
|
325
|
+
codex mcp add codetrap -- codetrap serve
|
|
329
326
|
```
|
|
330
327
|
|
|
331
|
-
|
|
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:
|
|
328
|
+
If your MCP client does not inherit your shell `PATH`, use the absolute path:
|
|
334
329
|
|
|
335
|
-
|
|
330
|
+
```bash
|
|
331
|
+
codex mcp add codetrap -- "$(bun pm bin -g)/codetrap" serve
|
|
336
332
|
```
|
|
333
|
+
|
|
334
|
+
Agents can also use the CLI directly when the project guidance tells them when to call it. `codetrap setup codex` installs that guidance in `AGENTS.md`.
|