open-codebase-index 0.21.0-bootstrap.0

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.
Files changed (39) hide show
  1. package/.claude-plugin/marketplace.json +16 -0
  2. package/.claude-plugin/plugin.json +35 -0
  3. package/.codex-plugin/plugin.json +43 -0
  4. package/.mcp.json +15 -0
  5. package/LICENSE +21 -0
  6. package/README.md +235 -0
  7. package/THIRD_PARTY_LICENSES.md +92 -0
  8. package/commands/call-graph.md +29 -0
  9. package/commands/definition.md +24 -0
  10. package/commands/find.md +25 -0
  11. package/commands/index.md +27 -0
  12. package/commands/peek.md +28 -0
  13. package/commands/pr-impact.md +23 -0
  14. package/commands/reindex.md +25 -0
  15. package/commands/search.md +28 -0
  16. package/commands/status.md +19 -0
  17. package/commands/visualize.md +30 -0
  18. package/dist/cli.cjs +19978 -0
  19. package/dist/cli.cjs.map +1 -0
  20. package/dist/cli.js +19970 -0
  21. package/dist/cli.js.map +1 -0
  22. package/dist/index.cjs +18530 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.js +18529 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/pi-extension.cjs +15070 -0
  27. package/dist/pi-extension.cjs.map +1 -0
  28. package/dist/pi-extension.js +15070 -0
  29. package/dist/pi-extension.js.map +1 -0
  30. package/hooks/hooks.json +17 -0
  31. package/native/codebase-index-native.darwin-arm64.node +0 -0
  32. package/native/codebase-index-native.darwin-x64.node +0 -0
  33. package/native/codebase-index-native.linux-arm64-gnu.node +0 -0
  34. package/native/codebase-index-native.linux-x64-gnu.node +0 -0
  35. package/native/codebase-index-native.win32-x64-msvc.node +0 -0
  36. package/package.json +147 -0
  37. package/scripts/link-local-mcp-bin.mjs +25 -0
  38. package/skill/SKILL.md +139 -0
  39. package/skills/codebase-search/SKILL.md +43 -0
@@ -0,0 +1,17 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "matcher": "startup|resume|clear|compact",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "printf '\nFor repository questions, use index_status when readiness is unknown, then call codebase_context before shell search, grep, or broad file reads. Pass symbol for definitions or from+to for dependency paths; use specialized lookup and graph tools afterward.\\n'",
10
+ "commandWindows": "Write-Output 'For repository questions, use index_status when readiness is unknown, then call codebase_context before shell search, grep, or broad file reads. Pass symbol for definitions or from+to for dependency paths; use specialized lookup and graph tools afterward.'",
11
+ "statusMessage": "Codebase Index ready"
12
+ }
13
+ ]
14
+ }
15
+ ]
16
+ }
17
+ }
package/package.json ADDED
@@ -0,0 +1,147 @@
1
+ {
2
+ "name": "open-codebase-index",
3
+ "version": "0.21.0-bootstrap.0",
4
+ "description": "Host-neutral semantic codebase search with embeddings, symbol discovery, and call-graph tooling",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "bin": {
16
+ "open-codebase-index-mcp": "dist/cli.js",
17
+ "opencode-codebase-index-mcp": "dist/cli.js"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Kenneth",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "https://github.com/Helweg/opencode-codebase-index"
24
+ },
25
+ "keywords": [
26
+ "semantic-search",
27
+ "codebase-indexing",
28
+ "vector-search",
29
+ "embeddings",
30
+ "tree-sitter",
31
+ "ai-coding",
32
+ "agent-extensions",
33
+ "pi-package",
34
+ "pi"
35
+ ],
36
+ "engines": {
37
+ "node": ">=20.0.0"
38
+ },
39
+ "scripts": {
40
+ "build": "npm run build:ts && npm run build:native",
41
+ "build:ts": "tsup && node scripts/smoke-test-built-cli.mjs",
42
+ "build:native": "cd native && cargo build --release && napi build --release --platform",
43
+ "build:native:all": "cd native && napi build --release --platform --target x86_64-apple-darwin --target aarch64-apple-darwin --target x86_64-unknown-linux-gnu --target aarch64-unknown-linux-gnu --target x86_64-pc-windows-msvc",
44
+ "visualize": "node dist/cli.js visualize",
45
+ "dev": "tsup --watch",
46
+ "eval": "npx tsx src/cli.ts eval run",
47
+ "eval:agent": "npx tsx src/cli.ts eval run --dataset benchmarks/golden/agent-context.json",
48
+ "eval:representative": "npx tsx src/cli.ts eval run --dataset benchmarks/golden/representative.json",
49
+ "eval:agent:ci": "npx tsx src/cli.ts eval run --dataset benchmarks/golden/agent-context.json --reindex --ci --budget benchmarks/budgets/agent-context.json",
50
+ "eval:smoke": "npx tsx src/cli.ts eval run --config .github/eval-config.json --reindex --dataset benchmarks/golden/small.json",
51
+ "eval:ci": "npx tsx src/cli.ts eval run --reindex --ci --budget benchmarks/budgets/default.json --against benchmarks/baselines/eval-baseline-summary.json",
52
+ "eval:ci:ollama": "npx tsx src/cli.ts eval run --config .github/eval-ollama-config.json --reindex --ci --budget benchmarks/budgets/default.json --against benchmarks/baselines/eval-baseline-summary.json",
53
+ "eval:compare": "npx tsx src/cli.ts eval compare",
54
+ "eval:effectiveness": "npx tsx scripts/effectiveness-report.ts",
55
+ "dev:link-mcp": "node scripts/link-local-mcp-bin.mjs",
56
+ "test": "vitest",
57
+ "pretest:run": "node scripts/run-build-native-with-rustflags.mjs",
58
+ "test:run": "vitest run",
59
+ "pretest:coverage": "node scripts/run-build-native-with-rustflags.mjs",
60
+ "test:coverage": "vitest run --coverage",
61
+ "lint": "eslint src/",
62
+ "typecheck": "tsc --noEmit",
63
+ "prepublishOnly": "npm run build"
64
+ },
65
+ "files": [
66
+ "dist",
67
+ "THIRD_PARTY_LICENSES.md",
68
+ "native/*.node",
69
+ "skill",
70
+ "commands",
71
+ "scripts/link-local-mcp-bin.mjs",
72
+ ".codex-plugin",
73
+ ".claude-plugin",
74
+ ".mcp.json",
75
+ "skills",
76
+ "hooks"
77
+ ],
78
+ "napi": {
79
+ "binaryName": "codebase-index-native",
80
+ "targets": [
81
+ "x86_64-apple-darwin",
82
+ "aarch64-apple-darwin",
83
+ "x86_64-unknown-linux-gnu",
84
+ "aarch64-unknown-linux-gnu",
85
+ "x86_64-pc-windows-msvc"
86
+ ]
87
+ },
88
+ "dependencies": {
89
+ "@modelcontextprotocol/sdk": "^1.29.0",
90
+ "@opencode-ai/plugin": "~1.3.13",
91
+ "chokidar": "^5.0.0",
92
+ "ignore": "^7.0.5",
93
+ "p-queue": "^9.1.1",
94
+ "p-retry": "^7.1.1",
95
+ "tiktoken": "^1.0.15",
96
+ "typebox": "^1.3.2",
97
+ "unicode-case-folding": "1.1.1",
98
+ "zod": "^4.4.3"
99
+ },
100
+ "devDependencies": {
101
+ "@earendil-works/pi-coding-agent": "^0.82.0",
102
+ "@eslint/js": "^9.39.4",
103
+ "@napi-rs/cli": "^3.6.0",
104
+ "@types/node": "^25.5.2",
105
+ "@vitest/coverage-v8": "^4.1.2",
106
+ "eslint": "^9.39.4",
107
+ "tsup": "^8.1.0",
108
+ "tsx": "^4.23.1",
109
+ "typescript": "^5.9.3",
110
+ "typescript-eslint": "^8.58.0",
111
+ "vitest": "^4.1.2"
112
+ },
113
+ "overrides": {
114
+ "@hono/node-server": "2.0.10",
115
+ "brace-expansion": "5.0.8",
116
+ "express-rate-limit": "8.5.2",
117
+ "fast-uri": "3.1.4",
118
+ "hono": "4.12.27",
119
+ "ip-address": "10.2.0",
120
+ "postcss": "8.5.18",
121
+ "qs": "6.15.2",
122
+ "vite": "8.0.16",
123
+ "esbuild": "0.28.1",
124
+ "body-parser": "2.3.0",
125
+ "js-yaml": "4.3.0"
126
+ },
127
+ "peerDependencies": {
128
+ "@earendil-works/pi-coding-agent": "*",
129
+ "@opencode-ai/plugin": "^1.0.0"
130
+ },
131
+ "peerDependenciesMeta": {
132
+ "@opencode-ai/plugin": {
133
+ "optional": true
134
+ },
135
+ "@earendil-works/pi-coding-agent": {
136
+ "optional": true
137
+ }
138
+ },
139
+ "pi": {
140
+ "extensions": [
141
+ "./dist/pi-extension.js"
142
+ ],
143
+ "skills": [
144
+ "./skills"
145
+ ]
146
+ }
147
+ }
@@ -0,0 +1,25 @@
1
+ import { existsSync, mkdirSync, rmSync, symlinkSync, writeFileSync } from "fs";
2
+ import { dirname, relative, resolve } from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
6
+ const cliPath = resolve(root, "dist/cli.js");
7
+ const binDir = resolve(root, "node_modules/.bin");
8
+ const binPath = resolve(binDir, "opencode-codebase-index-mcp");
9
+
10
+ if (!existsSync(cliPath)) {
11
+ console.error("dist/cli.js is missing. Run `npm run build:ts` first.");
12
+ process.exit(1);
13
+ }
14
+
15
+ mkdirSync(binDir, { recursive: true });
16
+ rmSync(binPath, { force: true });
17
+ rmSync(`${binPath}.cmd`, { force: true });
18
+
19
+ if (process.platform === "win32") {
20
+ writeFileSync(`${binPath}.cmd`, `@echo off\r\nnode "%~dp0\\..\\..\\dist\\cli.js" %*\r\n`, "utf-8");
21
+ } else {
22
+ symlinkSync(relative(dirname(binPath), cliPath), binPath);
23
+ }
24
+
25
+ console.log(`Linked ${binPath} -> ${cliPath}`);
package/skill/SKILL.md ADDED
@@ -0,0 +1,139 @@
1
+ ---
2
+ name: codebase-search
3
+ description: Semantic code and documentation search by meaning. Use codebase_peek to find WHERE code is (saves tokens), codebase_search to see actual code. For exact identifiers, use grep instead. Search local codebase before using websearch for code/library/API/example questions.
4
+ ---
5
+
6
+ # Codebase Search Skill
7
+
8
+ ## Important: Indexed Content
9
+
10
+ The indexed codebase contains **two types of content**:
11
+
12
+ 1. **Project Source Code** — all code files in the current workspace
13
+ 2. **Knowledge Base Documentation** — external documentation, usage guides, API references, and example programs added via `add_knowledge_base`
14
+
15
+ ## When to Use What
16
+
17
+ | Scenario | Tool | Why |
18
+ |----------|------|-----|
19
+ | Code/library/API question | `codebase_search` | Search local knowledge first |
20
+ | Just need file locations | `codebase_peek` | Metadata only, saves ~90% tokens |
21
+ | Need to see actual code | `codebase_search` | Returns full code content |
22
+ | Find duplicates/patterns | `find_similar` | Given code snippet → similar code |
23
+ | Understand code flow | `call_graph` | Find callers/callees of any function |
24
+ | Trace dependency paths | `call_graph_path` | Find a shortest known path between two symbols |
25
+ | Analyze PR blast radius | `pr_impact` | Find affected symbols, communities, hub nodes, and risk |
26
+ | Don't know function/class names | `codebase_peek` or `codebase_search` | Natural language → code |
27
+ | Know exact identifier names | `grep` | Faster, more precise |
28
+ | Need ALL occurrences | `grep` | Semantic returns top N only |
29
+ | Access specific URL | `webfetch` | Direct URL access, no codebase search needed |
30
+ | Local search fails | `websearch` | Fallback when codebase has no results |
31
+ | Local and web search fails | suggest adding knowledge base | Notify user to add related folder |
32
+
33
+ ## Search Rule
34
+
35
+ **Search local codebase first, then web search if needed.**
36
+
37
+ ```
38
+ Question received
39
+
40
+ Is this about code/library/API/framework?
41
+ ↓ YES
42
+ codebase_search(query)
43
+
44
+ Found relevant results? → YES → Return answer
45
+ ↓ NO
46
+ websearch(query)
47
+
48
+ Found relevant results? → YES → Return answer
49
+ ↓ NO
50
+ Suggest: "知识库中未找到相关信息,是否添加相关文档文件夹?"
51
+ ```
52
+
53
+ 1. Use `codebase_search` for code/library/API questions
54
+ 2. If no relevant results → use `websearch`
55
+ 3. If web search also fails → suggest adding a knowledge base folder
56
+
57
+ ## Recommended Workflow
58
+
59
+ 1. **Locate by meaning first**: `codebase_peek("authentication flow")` → get likely locations before grep or graph tools
60
+ 2. **Search with content**: `codebase_search("ADC channels ESP32")` → inspect implementation or knowledge-base matches
61
+ 3. **Read what matters**: `Read` the specific files you need
62
+ 4. **Trace structure after discovery**: `call_graph`, `call_graph_path`, `pr_impact`, or OMO CodeGraph once you know the relevant symbol
63
+ 5. **Drill down with grep**: `grep "validateToken"` for exact matches
64
+
65
+ ## Tools
66
+
67
+ ### `codebase_peek`
68
+ Find WHERE code is. Returns metadata only (file, line, name, type).
69
+
70
+ ```
71
+ codebase_peek(query="validation logic", chunkType="function", directory="src/utils")
72
+ codebase_peek(query="authentication flow", blameAuthor="jane@example.com")
73
+ ```
74
+
75
+ ### `codebase_search`
76
+ Find code with full content. Use when you need to see implementation.
77
+
78
+ ```
79
+ codebase_search(query="error handling middleware", fileType="ts", contextLines=2)
80
+ codebase_search(query="rate limiter", blameSince="2025-01-01")
81
+ ```
82
+
83
+ ### `find_similar`
84
+ Find code similar to a given snippet. Use for duplicate detection, pattern discovery, refactoring.
85
+
86
+ ```
87
+ find_similar(code="function validate(input) { return input.length > 0; }", excludeFile="src/current.ts")
88
+ ```
89
+
90
+ ### `call_graph`
91
+ Query callers or callees of a function/method.
92
+
93
+ ```
94
+ call_graph(name="validateToken", direction="callers")
95
+ ```
96
+
97
+ ### `index_codebase`
98
+ Manually trigger indexing. Required before first search.
99
+
100
+ ### `index_status`
101
+ Check if indexed and ready.
102
+
103
+ ### `add_knowledge_base`
104
+ Add a folder as a knowledge base. The folder will be indexed alongside project code.
105
+
106
+ ```
107
+ add_knowledge_base(path="/path/to/docs")
108
+ ```
109
+
110
+ ### `list_knowledge_bases`
111
+ List all configured knowledge base folders.
112
+
113
+ ### `remove_knowledge_base`
114
+ Remove a knowledge base folder from the index.
115
+
116
+ ```
117
+ remove_knowledge_base(path="/path/to/docs")
118
+ ```
119
+
120
+ ## Query Tips
121
+
122
+ **Describe behavior, not syntax:**
123
+ - Good: `"function that hashes passwords securely"`
124
+ - Bad: `"hashPassword"` (use grep for exact names)
125
+
126
+ **Search across documentation:**
127
+ - Good: `"how to configure WiFi in ESP-IDF"`
128
+ - Good: `"GPIO initialization example"`
129
+
130
+ ## Filters
131
+
132
+ | Filter | Example |
133
+ |--------|---------|
134
+ | `chunkType` | `function`, `class`, `interface`, `type`, `method` |
135
+ | `directory` | `"src/api"`, `"tests"` |
136
+ | `fileType` | `"ts"`, `"py"`, `"rs"` |
137
+ | `blameAuthor` | `"jane@example.com"` or `"Jane Doe"` |
138
+ | `blameSha` | `"abc1234"` |
139
+ | `blameSince` | `"2025-01-01"` |
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: codebase-search
3
+ description: Preferred local codebase-understanding workflow for Pi and Codex. Start with codebase_context before shell search or broad reads, then use specialized semantic and graph tools.
4
+ ---
5
+
6
+ # Codebase Search Skill
7
+
8
+ Use this skill when you need local repository knowledge before web lookup.
9
+
10
+ ## Core workflow
11
+
12
+ 1. Run `index_status` when index readiness or freshness is unknown.
13
+ 2. Use `codebase_context(query, ...)` before shell search, grep, or broad file reads. Pass `symbol` for an authoritative definition or `from` + `to` for a dependency path.
14
+ 3. Use `codebase_peek(query, ...)` for specialized metadata-only conceptual lookup.
15
+ 4. Use `codebase_search(query, ...)` when you need full code context.
16
+ 5. Use `implementation_lookup(query)` for known-symbol definitions and `call_graph` / `call_graph_path` for execution flow.
17
+ 6. Use `find_similar(code)` for duplicate patterns and refactor planning.
18
+
19
+ If results are weak, run `index_status` (check readiness) and `index_codebase`.
20
+
21
+ ## Tool Priority
22
+
23
+ - `codebase_context` as the preferred first repository tool and unified router.
24
+ - `codebase_peek` for specialized discovery (fastest, cheap tokens).
25
+ - `codebase_search` for exact implementation review.
26
+ - `find_similar` for pattern matching and duplication.
27
+ - `call_graph` and `call_graph_path` for execution flow.
28
+ - `index_codebase` (force/estimate/verbose) for first-time or stale indexes.
29
+ - `index_status`, `index_health_check`, `index_metrics`, `index_logs` for operational checks.
30
+
31
+ ## Suggested Commands
32
+
33
+ 1. `codebase_peek("payment processing flow")`
34
+ 2. `codebase_search("payment processing flow")`
35
+ 3. `call_graph("chargeCard", "callees")`
36
+ 4. `find_similar("function validate(data)")`
37
+ 5. `implementation_lookup("validate")`
38
+
39
+ ## Additional Notes
40
+
41
+ - Use `grep` for exact identifiers and tiny, deterministic lookups.
42
+ - Use `websearch` only when local tools return no results and docs are likely missing.
43
+ - Prefer `codebase_peek` before `codebase_search` to avoid high token usage.