codebase-wiki 0.1.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 (41) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE +17 -0
  3. package/README.md +130 -0
  4. package/dist/CHANGELOG.md +34 -0
  5. package/dist/LICENSE +17 -0
  6. package/dist/README.md +130 -0
  7. package/dist/chunks/build.mjs +1976 -0
  8. package/dist/chunks/config.mjs +174 -0
  9. package/dist/chunks/llm.mjs +214 -0
  10. package/dist/code-wiki-mcp.mjs +367 -0
  11. package/dist/code-wiki.mjs +11 -0
  12. package/dist/codewiki.mjs +2002 -0
  13. package/dist/grammars/c.wasm +0 -0
  14. package/dist/grammars/cpp.wasm +0 -0
  15. package/dist/grammars/go.wasm +0 -0
  16. package/dist/grammars/java.wasm +0 -0
  17. package/dist/grammars/javascript.wasm +0 -0
  18. package/dist/grammars/python.wasm +0 -0
  19. package/dist/grammars/ruby.wasm +0 -0
  20. package/dist/grammars/rust.wasm +0 -0
  21. package/dist/grammars/tsx.wasm +0 -0
  22. package/dist/grammars/typescript.wasm +0 -0
  23. package/dist/plugin/.mcp.json +11 -0
  24. package/dist/plugin/CLAUDE.md +28 -0
  25. package/dist/plugin/commands/wiki-architecture.md +10 -0
  26. package/dist/plugin/commands/wiki-build.md +23 -0
  27. package/dist/plugin/commands/wiki-enrich.md +22 -0
  28. package/dist/plugin/commands/wiki-graph.md +16 -0
  29. package/dist/plugin/commands/wiki-help.md +49 -0
  30. package/dist/plugin/commands/wiki-refresh.md +13 -0
  31. package/dist/plugin/commands/wiki-search.md +18 -0
  32. package/dist/plugin/commands/wiki-symbol.md +21 -0
  33. package/dist/plugin/hooks/hooks.json +74 -0
  34. package/dist/plugin/hooks/nudge.mjs +197 -0
  35. package/dist/plugin/hooks/post-read-reminder.mjs +56 -0
  36. package/dist/plugin/hooks/post-tool-use.mjs +60 -0
  37. package/dist/plugin/hooks/pre-compact.mjs +25 -0
  38. package/dist/plugin/hooks/session-start.mjs +38 -0
  39. package/dist/plugin/hooks/user-prompt-submit.mjs +28 -0
  40. package/dist/plugin/manifest.json +54 -0
  41. package/package.json +100 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Fixed
6
+ - Slash commands now invoke `${CLAUDE_PLUGIN_ROOT}/dist/codewiki.mjs` directly
7
+ instead of relying on a globally-installed `codewiki` binary. Plugin is fully
8
+ self-contained.
9
+ - `install-plugin.sh` ships the full dist tree (CLI + MCP server + `chunks/` +
10
+ WASM grammars) **and** creates a Windows junction (or POSIX symlink) so the
11
+ bundled modules can resolve `node_modules` at runtime.
12
+ - `loader.ts` adds a 3rd-resolution candidate that uses `import.meta.dirname`
13
+ to find WASM grammars relative to the bundled chunk file. Fixes the
14
+ `tree-sitter grammar wasm not found` warning when running from a project's
15
+ working directory instead of the plugin's location.
16
+ - `build.config.ts` switches to `inlineDependencies: true` so the bundled
17
+ output only depends on what's imported from the plugin's own tree (pino and
18
+ similar packages had escaped inlining under the old config).
19
+
20
+ ### Pending
21
+ - v0.1.0 tag — all 9 milestones + install fix ready.
22
+
23
+ ## v0.1.0 (in progress, target tag)
24
+
25
+ ### Added
26
+ - M1: scaffolding, walker, minimal render, hooks, MCP server stub.
27
+ - M2: tree-sitter extraction (TS / JS / TSX / JSX).
28
+ - M3: 7 more language extractors (Python / Go / Rust / Java / C / C++ / Ruby).
29
+ - M4: graph extraction — imports + dependents; `wiki_callers` / `wiki_callees`.
30
+ - M5: MCP resource pagination, smarter auto-nudge (config-driven, freshness-aware).
31
+ - M6: incremental refresh — `codewiki refresh` (git diff) + `codewiki watch` (chokidar).
32
+ - M7: optional LLM enrichment (Haiku + Sonnet, content-hash cached).
33
+ - M8: Mermaid diagrams in architecture + module pages.
34
+ - M9: docs site, GitHub Actions CI, changesets, issue templates.
package/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2026 code-wiki contributors
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # code-wiki
2
+
3
+ > A Claude Code plugin that turns your repo into a browsable, **token-efficient** code wiki. Models read summaries on-demand instead of grepping source.
4
+
5
+ [![GitHub](https://img.shields.io/badge/GitHub-harrycjs%2Fcode--wiki-blue)](https://github.com/harrycjs/code-wiki)
6
+ [![npm](https://img.shields.io/npm/v/codebase-wiki)](https://www.npmjs.com/package/codebase-wiki)
7
+
8
+ Claude reads a 600-token wiki page instead of a 6000-token source file. Models get summaries on-demand, then drill in only when they need the real source.
9
+
10
+ ## Why
11
+
12
+ Working with a large repo in Claude Code eats tokens. Every `Read` ships the whole file. Every `Grep` ships a slice. With `code-wiki`:
13
+
14
+ - `/wiki-build` indexes your repo into a `.codewiki/` directory of small markdown files (one per file / function / class / module) plus a JSON sidecar.
15
+ - Hooks **automatically nudge** the model toward the wiki when it tries to `Read` source or `Grep` — without ever blocking it.
16
+ - The model reads a 600-token wiki page first, then drills into the 5-line function it actually needs.
17
+
18
+ Typical savings: **60–90%** of "source-read" tokens on a medium codebase.
19
+
20
+ ## Two install paths
21
+
22
+ Pick one.
23
+
24
+ ### Path A — Local marketplace (no publish required, fastest)
25
+
26
+ You point Claude Code at a directory on your machine that contains a `marketplace.json` describing the plugin. After `npm run build`, the install script stages everything.
27
+
28
+ ```bash
29
+ git clone https://github.com/harrycjs/code-wiki
30
+ cd code-wiki
31
+
32
+ npm install
33
+ npm run build
34
+
35
+ # Stage plugin into your local Claude Code marketplaces dir + link it
36
+ # so the bundled CLI/MCP can resolve its node_modules.
37
+ bash scripts/install-plugin.sh user
38
+
39
+ claude plugin marketplace update codebase-wiki-local
40
+ claude plugin install codebase-wiki@codebase-wiki-local
41
+ ```
42
+
43
+ Restart Claude Code (plugin registration happens at session start).
44
+
45
+ ### Path B — npm (you ship to friends / your team's machines)
46
+
47
+ ```bash
48
+ # In the code-wiki repo, with NPM_TOKEN in env:
49
+ npm run release # changeset version + npm publish
50
+ ```
51
+
52
+ Then in any target project:
53
+
54
+ ```bash
55
+ npm install -g codebase-wiki # puts `codewiki` on PATH
56
+ claude plugin marketplace add <your-github-username>/code-wiki
57
+ claude plugin install codebase-wiki@code-wiki
58
+ ```
59
+
60
+ The plugin is then resolvable by the bundled CLI path inside the plugin
61
+ **and** via the global `codewiki` binary if you prefer using that.
62
+
63
+ ## Usage
64
+
65
+ ```text
66
+ /wiki-build # build the wiki
67
+ /wiki-architecture # system overview
68
+ /wiki-search login # find symbols/files/modules
69
+ /wiki-symbol src/auth/login.ts:function.loginUser
70
+ /wiki-graph loginUser # callers / callees
71
+ /wiki-refresh # after edits
72
+ /wiki-help # one-screen summary
73
+ ```
74
+
75
+ MCP tools (auto-discovered by Claude Code):
76
+
77
+ - `wiki_search`, `wiki_drill`, `wiki_callers`, `wiki_callees`, `wiki_changed_since`
78
+ - Resources: `wiki://tree`, `wiki://architecture`, `wiki://module/...`, `wiki://file/...`, `wiki://symbol/...`
79
+
80
+ ## How the auto-nudge works
81
+
82
+ After `/wiki-build`, four layers of hooks nudge the model toward `.codewiki/`:
83
+
84
+ 1. **Session banner** at session start tells the model the wiki exists.
85
+ 2. **Per-prompt reminder** ("prefer wiki over source").
86
+ 3. **Pre-tool nudge** on `Read | Grep | Glob | Bash cat/head/tail` injects a `permissionDecisionReason` pointing at the matching wiki page, with a `use_mcp_tool('code-wiki', 'wiki_search', { query: "..." })` example for Grep.
87
+ 4. **Post-read note** after any source `Read` so the model has the wiki path next time.
88
+
89
+ Each nudge carries the file's freshness state: if the source is newer than the wiki, the model is told to run `/wiki-refresh` first.
90
+
91
+ No nudges block — they're suggestions, not gates.
92
+
93
+ Disable via `.codewikirc.json`:
94
+
95
+ ```json
96
+ { "nudge": { "enabled": false, "minFileLines": 50 } }
97
+ ```
98
+
99
+ ## Optional: LLM enrichment
100
+
101
+ If `ANTHROPIC_API_KEY` is set, `/wiki-enrich` deepens summaries using:
102
+
103
+ - **Haiku** for files with cyclomatic complexity > 15 OR no docstring OR > 800 tokens source.
104
+ - **Sonnet** for modules whose files changed.
105
+
106
+ Cost per build: **$0.001 / complex file + $0.005 / module**. Results are cached by content hash; re-runs without source edits are free.
107
+
108
+ Without an API key: zero cost, zero network, full coverage.
109
+
110
+ ## Project layout
111
+
112
+ - `src/cli/` — the `codewiki` binary (build/refresh/watch/search/show/enrich/invalidate/validate/clean).
113
+ - `src/core/` — pure indexing logic, no Claude/MCP coupling.
114
+ - `src/core/extract/` — tree-sitter symbol extraction across 10 languages.
115
+ - `src/core/graph/` — import edge extraction.
116
+ - `src/core/incremental.ts` — git diff + chokidar watcher + state.json.
117
+ - `src/core/render/` — markdown templates for all 5 page kinds.
118
+ - `src/core/summary/llm.ts` — optional Haiku/Sonnet enrichment.
119
+ - `src/mcp/` — the MCP server Claude Code talks to.
120
+ - `src/plugin/` — the Claude Code plugin surface (manifest, commands, hooks, CLAUDE.md).
121
+ - `examples/fixture-ts` — small TS lib used for integration tests.
122
+ - `scripts/install-plugin.sh` — local-dev install helper (Path A above).
123
+
124
+ ## Status
125
+
126
+ All 9 milestones shipped in v0.1.0. See [CHANGELOG.md](./CHANGELOG.md).
127
+
128
+ ## License
129
+
130
+ Apache-2.0. See [LICENSE](./LICENSE).
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ### Fixed
6
+ - Slash commands now invoke `${CLAUDE_PLUGIN_ROOT}/dist/codewiki.mjs` directly
7
+ instead of relying on a globally-installed `codewiki` binary. Plugin is fully
8
+ self-contained.
9
+ - `install-plugin.sh` ships the full dist tree (CLI + MCP server + `chunks/` +
10
+ WASM grammars) **and** creates a Windows junction (or POSIX symlink) so the
11
+ bundled modules can resolve `node_modules` at runtime.
12
+ - `loader.ts` adds a 3rd-resolution candidate that uses `import.meta.dirname`
13
+ to find WASM grammars relative to the bundled chunk file. Fixes the
14
+ `tree-sitter grammar wasm not found` warning when running from a project's
15
+ working directory instead of the plugin's location.
16
+ - `build.config.ts` switches to `inlineDependencies: true` so the bundled
17
+ output only depends on what's imported from the plugin's own tree (pino and
18
+ similar packages had escaped inlining under the old config).
19
+
20
+ ### Pending
21
+ - v0.1.0 tag — all 9 milestones + install fix ready.
22
+
23
+ ## v0.1.0 (in progress, target tag)
24
+
25
+ ### Added
26
+ - M1: scaffolding, walker, minimal render, hooks, MCP server stub.
27
+ - M2: tree-sitter extraction (TS / JS / TSX / JSX).
28
+ - M3: 7 more language extractors (Python / Go / Rust / Java / C / C++ / Ruby).
29
+ - M4: graph extraction — imports + dependents; `wiki_callers` / `wiki_callees`.
30
+ - M5: MCP resource pagination, smarter auto-nudge (config-driven, freshness-aware).
31
+ - M6: incremental refresh — `codewiki refresh` (git diff) + `codewiki watch` (chokidar).
32
+ - M7: optional LLM enrichment (Haiku + Sonnet, content-hash cached).
33
+ - M8: Mermaid diagrams in architecture + module pages.
34
+ - M9: docs site, GitHub Actions CI, changesets, issue templates.
package/dist/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2026 code-wiki contributors
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
package/dist/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # code-wiki
2
+
3
+ > A Claude Code plugin that turns your repo into a browsable, **token-efficient** code wiki. Models read summaries on-demand instead of grepping source.
4
+
5
+ [![GitHub](https://img.shields.io/badge/GitHub-harrycjs%2Fcode--wiki-blue)](https://github.com/harrycjs/code-wiki)
6
+ [![npm](https://img.shields.io/npm/v/codebase-wiki)](https://www.npmjs.com/package/codebase-wiki)
7
+
8
+ Claude reads a 600-token wiki page instead of a 6000-token source file. Models get summaries on-demand, then drill in only when they need the real source.
9
+
10
+ ## Why
11
+
12
+ Working with a large repo in Claude Code eats tokens. Every `Read` ships the whole file. Every `Grep` ships a slice. With `code-wiki`:
13
+
14
+ - `/wiki-build` indexes your repo into a `.codewiki/` directory of small markdown files (one per file / function / class / module) plus a JSON sidecar.
15
+ - Hooks **automatically nudge** the model toward the wiki when it tries to `Read` source or `Grep` — without ever blocking it.
16
+ - The model reads a 600-token wiki page first, then drills into the 5-line function it actually needs.
17
+
18
+ Typical savings: **60–90%** of "source-read" tokens on a medium codebase.
19
+
20
+ ## Two install paths
21
+
22
+ Pick one.
23
+
24
+ ### Path A — Local marketplace (no publish required, fastest)
25
+
26
+ You point Claude Code at a directory on your machine that contains a `marketplace.json` describing the plugin. After `npm run build`, the install script stages everything.
27
+
28
+ ```bash
29
+ git clone https://github.com/harrycjs/code-wiki
30
+ cd code-wiki
31
+
32
+ npm install
33
+ npm run build
34
+
35
+ # Stage plugin into your local Claude Code marketplaces dir + link it
36
+ # so the bundled CLI/MCP can resolve its node_modules.
37
+ bash scripts/install-plugin.sh user
38
+
39
+ claude plugin marketplace update codebase-wiki-local
40
+ claude plugin install codebase-wiki@codebase-wiki-local
41
+ ```
42
+
43
+ Restart Claude Code (plugin registration happens at session start).
44
+
45
+ ### Path B — npm (you ship to friends / your team's machines)
46
+
47
+ ```bash
48
+ # In the code-wiki repo, with NPM_TOKEN in env:
49
+ npm run release # changeset version + npm publish
50
+ ```
51
+
52
+ Then in any target project:
53
+
54
+ ```bash
55
+ npm install -g codebase-wiki # puts `codewiki` on PATH
56
+ claude plugin marketplace add <your-github-username>/code-wiki
57
+ claude plugin install codebase-wiki@code-wiki
58
+ ```
59
+
60
+ The plugin is then resolvable by the bundled CLI path inside the plugin
61
+ **and** via the global `codewiki` binary if you prefer using that.
62
+
63
+ ## Usage
64
+
65
+ ```text
66
+ /wiki-build # build the wiki
67
+ /wiki-architecture # system overview
68
+ /wiki-search login # find symbols/files/modules
69
+ /wiki-symbol src/auth/login.ts:function.loginUser
70
+ /wiki-graph loginUser # callers / callees
71
+ /wiki-refresh # after edits
72
+ /wiki-help # one-screen summary
73
+ ```
74
+
75
+ MCP tools (auto-discovered by Claude Code):
76
+
77
+ - `wiki_search`, `wiki_drill`, `wiki_callers`, `wiki_callees`, `wiki_changed_since`
78
+ - Resources: `wiki://tree`, `wiki://architecture`, `wiki://module/...`, `wiki://file/...`, `wiki://symbol/...`
79
+
80
+ ## How the auto-nudge works
81
+
82
+ After `/wiki-build`, four layers of hooks nudge the model toward `.codewiki/`:
83
+
84
+ 1. **Session banner** at session start tells the model the wiki exists.
85
+ 2. **Per-prompt reminder** ("prefer wiki over source").
86
+ 3. **Pre-tool nudge** on `Read | Grep | Glob | Bash cat/head/tail` injects a `permissionDecisionReason` pointing at the matching wiki page, with a `use_mcp_tool('code-wiki', 'wiki_search', { query: "..." })` example for Grep.
87
+ 4. **Post-read note** after any source `Read` so the model has the wiki path next time.
88
+
89
+ Each nudge carries the file's freshness state: if the source is newer than the wiki, the model is told to run `/wiki-refresh` first.
90
+
91
+ No nudges block — they're suggestions, not gates.
92
+
93
+ Disable via `.codewikirc.json`:
94
+
95
+ ```json
96
+ { "nudge": { "enabled": false, "minFileLines": 50 } }
97
+ ```
98
+
99
+ ## Optional: LLM enrichment
100
+
101
+ If `ANTHROPIC_API_KEY` is set, `/wiki-enrich` deepens summaries using:
102
+
103
+ - **Haiku** for files with cyclomatic complexity > 15 OR no docstring OR > 800 tokens source.
104
+ - **Sonnet** for modules whose files changed.
105
+
106
+ Cost per build: **$0.001 / complex file + $0.005 / module**. Results are cached by content hash; re-runs without source edits are free.
107
+
108
+ Without an API key: zero cost, zero network, full coverage.
109
+
110
+ ## Project layout
111
+
112
+ - `src/cli/` — the `codewiki` binary (build/refresh/watch/search/show/enrich/invalidate/validate/clean).
113
+ - `src/core/` — pure indexing logic, no Claude/MCP coupling.
114
+ - `src/core/extract/` — tree-sitter symbol extraction across 10 languages.
115
+ - `src/core/graph/` — import edge extraction.
116
+ - `src/core/incremental.ts` — git diff + chokidar watcher + state.json.
117
+ - `src/core/render/` — markdown templates for all 5 page kinds.
118
+ - `src/core/summary/llm.ts` — optional Haiku/Sonnet enrichment.
119
+ - `src/mcp/` — the MCP server Claude Code talks to.
120
+ - `src/plugin/` — the Claude Code plugin surface (manifest, commands, hooks, CLAUDE.md).
121
+ - `examples/fixture-ts` — small TS lib used for integration tests.
122
+ - `scripts/install-plugin.sh` — local-dev install helper (Path A above).
123
+
124
+ ## Status
125
+
126
+ All 9 milestones shipped in v0.1.0. See [CHANGELOG.md](./CHANGELOG.md).
127
+
128
+ ## License
129
+
130
+ Apache-2.0. See [LICENSE](./LICENSE).