codetrap 0.1.0 → 0.1.2

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 CHANGED
@@ -10,7 +10,7 @@ AI coding agents make the same mistakes repeatedly across sessions and projects.
10
10
 
11
11
  ## Quick Start
12
12
 
13
- For detailed setup options, see [Installation](docs/installation.md).
13
+ For detailed setup options, see [Installation](docs/installation.md). Maintainers can use the Chinese [Release Playbook](docs/release-playbook.zh-CN.md) when publishing updates.
14
14
 
15
15
  ```bash
16
16
  # Prerequisites: Bun >= 1.x (https://bun.sh)
@@ -48,13 +48,13 @@ codetrap show 1
48
48
 
49
49
  ## Features
50
50
 
51
- - **Structured trap recording** — title, category, context, mistake, fix, severity, tags, before/after code
51
+ - **Structured trap recording** — title, category, context, mistake, fix, severity, tags, lifecycle, evidence, before/after code
52
52
  - **Dual scope** — project-scoped (`.codetrap/traps.db`) and global (`~/.codetrap/traps.db`)
53
53
  - **Three search modes** — FTS (SQLite FTS5), semantic (Jina embeddings), hybrid (RRF fusion)
54
54
  - **Chinese + mixed-language search** — CJK bigram tokenizer, synonym map for Chinese-English terms
55
55
  - **MCP server** — 10 tools + 4 resources for AI agent integration
56
56
  - **Embedding cache** with freshness tracking — embeddings are rebuildable, stale ones auto-invalidated
57
- - **Schema migrations** — in-code migration system from v0 through current v3
57
+ - **Schema migrations** — in-code migration system from v0 through current v4
58
58
  - **Single-binary builds** — `bun build --compile` produces standalone binaries in `dist/`
59
59
 
60
60
  ## Directory Structure
@@ -67,19 +67,24 @@ codetrap/
67
67
  │ ├── commands/router.ts CLI command dispatch
68
68
  │ ├── mcp/
69
69
  │ │ ├── server.ts MCP stdio transport + handlers
70
- │ │ ├── tools.ts 7 MCP tool definitions
70
+ │ │ ├── tools.ts 10 MCP tool definitions
71
71
  │ │ └── resources.ts 4 MCP resource URIs
72
72
  │ ├── domain/trap.ts Trap types, builders, schemas
73
73
  │ ├── lib/
74
74
  │ │ ├── store.ts Project/global scope orchestration
75
+ │ │ ├── trap-operations.ts Shared CLI/MCP operation semantics
75
76
  │ │ ├── search-service.ts FTS/semantic/hybrid search, RRF fusion
77
+ │ │ ├── search-result-card.ts Compact agent-facing result cards
76
78
  │ │ ├── search-normalizer.ts CJK bigram, synonyms, search_text
77
79
  │ │ ├── fts-query.ts Safe FTS5 literal query compiler
80
+ │ │ ├── trap-search-document.ts Derived search text + embedding passage
81
+ │ │ ├── trap-json-fields.ts Tags/evidence JSON array codec
82
+ │ │ ├── trap-archive.ts Import/export compatibility
78
83
  │ │ ├── embedder.ts Jina Embeddings adapter
79
84
  │ │ ├── embedding-job.ts Batch embedding generation
80
85
  │ │ ├── format.ts CLI output formatting
81
86
  │ │ ├── scope.ts Project root detection
82
- │ │ └── constants.ts Categories, severities, defaults
87
+ │ │ └── constants.ts Categories, severities, statuses, defaults
83
88
  │ ├── db/
84
89
  │ │ ├── connection.ts SQLite connection + PRAGMAs
85
90
  │ │ ├── schema.ts Schema init + migrations
@@ -87,11 +92,11 @@ codetrap/
87
92
  │ │ ├── embedding-queries.ts Embedding storage SQL
88
93
  │ │ └── repository.ts Single-DB facade
89
94
  │ └── tests/
90
- │ ├── search-safety.test.ts
91
- │ ├── search-normalizer.test.ts
92
- │ ├── search-chinese.test.ts
93
- │ ├── search-semantic.test.ts
94
- │ ├── search-eval.test.ts
95
+ │ ├── search-*.test.ts
96
+ │ ├── trap-*.test.ts
97
+ │ ├── mcp-tools.test.ts
98
+ │ ├── scope.test.ts
99
+ │ ├── import-export-cli.test.ts
95
100
  │ └── fixtures/search-eval.json
96
101
  ├── skills/ Agent skill definitions
97
102
  ├── docs/ Architecture + reference docs
@@ -105,12 +110,15 @@ codetrap/
105
110
  | Command | Description |
106
111
  |---|---|
107
112
  | `init` | Initialize `.codetrap/` in current project |
108
- | `add` | Record a new trap (JSON or interactive) |
109
- | `search <query>` | Search traps (--mode fts\|semantic\|hybrid) |
110
- | `list` | List traps (--category, --severity, --scope, --limit) |
113
+ | `add` | Record a new trap (`--json` structured input; interactive mode is not implemented) |
114
+ | `search <query>` | Search traps (--mode fts\|semantic\|hybrid, --category, --scope, --status, --limit) |
115
+ | `list` | List traps (--category, --scope, --status, --limit) |
111
116
  | `show <id>` | Show full trap details |
112
117
  | `edit <id>` | Edit a trap |
113
118
  | `delete <id>` | Delete a trap |
119
+ | `add_trap_evidence <id>` | Attach source/evidence metadata |
120
+ | `archive_trap <id>` | Archive a trap so default search skips it |
121
+ | `supersede_trap <old_id> <new_id>` | Mark one trap as replaced by another |
114
122
  | `export` | Export traps to JSON |
115
123
  | `import` | Import traps from JSON |
116
124
  | `stats` | Show database statistics |
package/bin/codetrap ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bun
2
+
3
+ import "../src/index.ts";
4
+
@@ -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.0
76
- git push origin v0.1.0
75
+ git tag v0.1.1
76
+ git push origin v0.1.1
77
77
  ```
78
78
 
79
- The release tag must match `package.json` exactly. For example, package version `0.1.0` must use tag `v0.1.0`.
79
+ The release tag must match `package.json` exactly. For example, package version `0.1.1` must use tag `v0.1.1`.
80
80
 
81
81
  The workflow runs:
82
82
 
@@ -192,7 +192,7 @@ npm pack --dry-run
192
192
  npm publish --access public
193
193
  ```
194
194
 
195
- The package is source-based: the npm package installs the `codetrap` command from `src/index.ts`, so users still need Bun installed.
195
+ The package is source-based: the npm package installs the `codetrap` command from `bin/codetrap`, so users still need Bun installed.
196
196
 
197
197
  You can preview the npm package locally:
198
198
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codetrap",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Capture and retrieve coding pitfalls so AI doesn't repeat mistakes",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -24,6 +24,7 @@
24
24
  "bun": ">=1.0.0"
25
25
  },
26
26
  "files": [
27
+ "bin",
27
28
  "src/commands",
28
29
  "src/db",
29
30
  "src/domain",
@@ -39,11 +40,11 @@
39
40
  "LICENSE"
40
41
  ],
41
42
  "bin": {
42
- "codetrap": "./src/index.ts"
43
+ "codetrap": "bin/codetrap"
43
44
  },
44
45
  "scripts": {
45
46
  "dev": "bun run src/index.ts",
46
- "install:cli": "ln -sf \"$PWD/src/index.ts\" \"$(bun pm bin -g)/codetrap\"",
47
+ "install:cli": "ln -sf \"$PWD/bin/codetrap\" \"$(bun pm bin -g)/codetrap\"",
47
48
  "build:release": "bun run scripts/build-release.ts",
48
49
  "check:release-version": "bun run scripts/check-release-version.ts",
49
50
  "build": "bun build ./src/index.ts --compile --outfile dist/codetrap && bun build ./src/mcp-server.ts --compile --outfile dist/codetrap-serve",
package/src/index.ts CHANGED
File without changes
package/src/lib/scope.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { existsSync, mkdirSync } from "node:fs";
2
- import { join } from "node:path";
2
+ import { dirname, join, resolve } from "node:path";
3
3
  import { homedir } from "node:os";
4
4
  import { CODETRAP_DIR, TRAPS_DB_FILE } from "./constants";
5
5
 
@@ -13,11 +13,13 @@ export function getGlobalDB(): string {
13
13
  return join(getGlobalDir(), TRAPS_DB_FILE);
14
14
  }
15
15
 
16
- export function findProjectRoot(cwd: string): string | null {
17
- let dir = cwd;
16
+ export function findProjectRoot(cwd: string, homeDir = homedir()): string | null {
17
+ let dir = resolve(cwd);
18
+ const home = resolve(homeDir);
18
19
  while (true) {
20
+ if (dir === home) return null;
19
21
  if (existsSync(join(dir, CODETRAP_DIR))) return dir;
20
- const parent = join(dir, "..");
22
+ const parent = dirname(dir);
21
23
  if (parent === dir) return null;
22
24
  dir = parent;
23
25
  }