dsh-codebase-chat 0.16.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 shinzarou-eng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,249 @@
1
+ # dsh-codebase-chat
2
+
3
+ [![Release](https://img.shields.io/github/v/release/shinzarou-eng/dsh-codebase-chat?logo=github)](https://github.com/shinzarou-eng/dsh-codebase-chat/releases)
4
+ [![License](https://img.shields.io/github/license/shinzarou-eng/dsh-codebase-chat?color=blue)](./LICENSE)
5
+ [![Node](https://img.shields.io/badge/node-%3E%3D20-brightgreen?logo=nodedotjs)](https://nodejs.org)
6
+ [![MCP](https://img.shields.io/badge/MCP-Compatible-purple)](https://modelcontextprotocol.io)
7
+
8
+ > A powerful, multi-language codebase intelligence engine for **DeepSeek Harness** and any **MCP-compatible** IDE (Windsurf, Cursor, Claude, etc.).
9
+ > Chat, search, explain, refactor, audit, and generate board-ready reports from a local codebase — without leaking data to third-party services.
10
+
11
+ <p align="center">
12
+ <a href="https://github.com/shinzarou-eng/dsh-codebase-chat/releases">Releases</a> ·
13
+ <a href="#install">Install</a> ·
14
+ <a href="#mcp-server">MCP</a> ·
15
+ <a href="#commands">Commands</a> ·
16
+ <a href="#github-pages-docs">Docs</a>
17
+ </p>
18
+
19
+ ---
20
+
21
+ ## Why dsh-codebase-chat?
22
+
23
+ Most codebase assistants are slow, paywalled, or force you to upload source code to the cloud. **dsh-codebase-chat** runs locally, reads only the files you point at, and turns raw code into structured intelligence:
24
+
25
+ | Capability | What it gives you |
26
+ | --- | --- |
27
+ | **Chat** | Ask anything about the project in plain language. |
28
+ | **Search** | Find symbols, terms, and usages with line references. |
29
+ | **Explain** | Understand a file or function with real code excerpts. |
30
+ | **Refactor** | Get production-ready code changes with diff rationale. |
31
+ | **Intelligence Pro** | CTO-level audit: architecture, tech radar, debt, security, competitors, roadmap. |
32
+ | **Audit** | Dedicated non-conformity and tech-debt scan with fixes. |
33
+ | **Strategic Report** | Board-ready SWOT, score cards, 90-day roadmap, marketing angle. |
34
+ | **Tasks** | Auto-generate `TASKS.md` with sprints, Before/After blocks, and patch application. |
35
+ | **Player Brief** | UX / playthrough analysis from a real user perspective. |
36
+ | **Crea** | Slogans, taglines, and feature ideas inspired by the code. |
37
+
38
+ Every output is **grounded in real source files** with file and line citations. No guesswork, no cloud, no data leakage.
39
+
40
+ ---
41
+
42
+ ## Quick start
43
+
44
+ ### 1. DeepSeek Harness plugin
45
+
46
+ ```powershell
47
+ # Install in any profile
48
+ pnpm add "file:C:/path/to/dsh-codebase-chat"
49
+ # or
50
+ npm install "file:C:/path/to/dsh-codebase-chat"
51
+ ```
52
+
53
+ Then open `http://127.0.0.1:3080` and click the **Codebase Pro** button in the sidebar.
54
+
55
+ ### 2. Standalone MCP server
56
+
57
+ ```bash
58
+ # Install globally
59
+ npm install -g dsh-codebase-chat-mcp
60
+
61
+ # Or run without installing
62
+ npx dsh-codebase-chat-mcp
63
+ ```
64
+
65
+ Configure Windsurf / Cursor / Claude:
66
+
67
+ ```json
68
+ {
69
+ "mcpServers": {
70
+ "dsh-codebase-chat": {
71
+ "command": "npx",
72
+ "args": ["dsh-codebase-chat-mcp"],
73
+ "env": {
74
+ "DEEPSEEK_API_KEY": "sk-...",
75
+ "CODEBASE_MODEL": "deepseek-chat"
76
+ }
77
+ }
78
+ }
79
+ }
80
+ ```
81
+
82
+ See [`mcp/README.md`](mcp/README.md) for the full config.
83
+
84
+ ### 3. From source
85
+
86
+ ```bash
87
+ git clone https://github.com/shinzarou-eng/dsh-codebase-chat.git
88
+ cd dsh-codebase-chat
89
+ pnpm install
90
+ ```
91
+
92
+ ---
93
+
94
+ ## Commands
95
+
96
+ ```powershell
97
+ # Ask a question (auto-detect project from current directory)
98
+ dsh --profile headless '/codebase "how is auth handled?"'
99
+
100
+ # Ask with explicit project
101
+ dsh --profile headless '/codebase "how is auth handled?" --project C:\my-app'
102
+
103
+ # Append a creative idea at the end
104
+ dsh --profile headless '/codebase "how does storage work?" --project C:\my-app --crea --crea-theme "slogan"'
105
+
106
+ # Search, explain, refactor
107
+ dsh --profile headless '/codebase-search "usePetStore" --project C:\my-app'
108
+ dsh --profile headless '/codebase-explain "storage.ts" --project C:\my-app'
109
+ dsh --profile headless '/codebase-refactor "split this hook" --file storage.ts --project C:\my-app'
110
+
111
+ # Professional briefs
112
+ dsh --profile headless '/codebase-intel --project C:\my-app'
113
+ dsh --profile headless '/codebase-audit --project C:\my-app'
114
+ dsh --profile headless '/codebase-report --project C:\my-app'
115
+ dsh --profile headless '/codebase-ceo --project C:\my-app'
116
+ dsh --profile headless '/codebase-player --project C:\my-app'
117
+
118
+ # Tasks & apply
119
+ dsh --profile headless '/codebase-tasks --project C:\my-app'
120
+ dsh --profile headless '/codebase-tasks-raw --project C:\my-app'
121
+ dsh --profile headless '/codebase-apply-tasks --project C:\my-app'
122
+
123
+ # Build & git
124
+ dsh --profile headless '/codebase-build --project C:\my-app'
125
+ dsh --profile headless '/codebase-git --project C:\my-app'
126
+ ```
127
+
128
+ ---
129
+
130
+ ## Architecture
131
+
132
+ ```mermaid
133
+ graph LR
134
+ A[User query] --> B[Codebase Pro UI / MCP / CLI]
135
+ B --> C[Context collector]
136
+ C --> D[Project files]
137
+ C --> E[Module graph / debt / tests]
138
+ C --> F[Prompt builder]
139
+ F --> G[LLM]
140
+ G --> H[Structured response with citations]
141
+ ```
142
+
143
+ 1. **Context collector** reads package.json, source files, tests, config, git, build output.
144
+ 2. **Module graph** maps who calls who.
145
+ 3. **Debt scanner** flags TODO/FIXME/HACK/console.log/any/etc.
146
+ 4. **Prompt builder** assembles a language-aware, evidence-based prompt.
147
+ 5. **LLM** returns a response that includes source citations, confidence scores, and severity badges.
148
+
149
+ ---
150
+
151
+ ## Web UI
152
+
153
+ When installed in the **web** profile, the plugin adds a **Codebase Pro** button in the sidebar footer:
154
+
155
+ <p align="center">
156
+ <img src="https://raw.githubusercontent.com/shinzarou-eng/dsh-codebase-chat/main/docs/assets/codebase-pro-button.svg" alt="Codebase Pro button" width="240">
157
+ </p>
158
+
159
+ One click opens the brief selector and launches the chosen mode in the user's language.
160
+
161
+ ---
162
+
163
+ ## Tools exposed
164
+
165
+ - `codebase_chat`
166
+ - `codebase_search`
167
+ - `codebase_explain`
168
+ - `codebase_refactor`
169
+ - `codebase_crea`
170
+ - `codebase_intelligence`
171
+ - `codebase_audit`
172
+ - `codebase_report`
173
+ - `codebase_tasks`
174
+ - `codebase_apply_tasks`
175
+ - `codebase_ceo`
176
+ - `codebase_build`
177
+ - `codebase_git`
178
+ - `codebase_apply`
179
+ - `codebase_player`
180
+
181
+ ---
182
+
183
+ ## Evidence & scoring
184
+
185
+ Every professional brief now requires the model to:
186
+
187
+ - Cite sources as `[source: relative/path/file.ts:line]`
188
+ - Mark recommendations with `[Confidence: X%]`
189
+ - Mark risks and issues with `[Severity: Critical/High/Medium/Low]`
190
+
191
+ No fabricated citations, no hand-waving.
192
+
193
+ ---
194
+
195
+ ## Multi-language
196
+
197
+ The plugin detects the user's language and generates the entire prompt in that language. Supported locales:
198
+
199
+ - `fr` — French
200
+ - `en` — English
201
+
202
+ More languages can be added by extending the `build*Prompt` functions.
203
+
204
+ ---
205
+
206
+ ## Install as a DSH plugin
207
+
208
+ ```powershell
209
+ dsh plugin --profile headless add "file:C:/Users/YOU/dsh-codebase-chat"
210
+ dsh plugin --profile web add "file:C:/Users/YOU/dsh-codebase-chat"
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Troubleshooting
216
+
217
+ ### `EADDRINUSE` — port 3080 already in use
218
+
219
+ ```powershell
220
+ Get-NetTCPConnection -LocalPort 3080 | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }
221
+ ```
222
+
223
+ Then restart `dsh --profile web`.
224
+
225
+ ---
226
+
227
+ ## Roadmap
228
+
229
+ - [ ] More language packs
230
+ - [ ] VS Code extension
231
+ - [ ] Indexed project cache for huge repos
232
+ - [ ] Interactive diff viewer in DSH UI
233
+
234
+ ---
235
+
236
+ ## Contributing
237
+
238
+ 1. Fork the repository
239
+ 2. Create a feature branch
240
+ 3. Run `node --check lib/index.js` before committing
241
+ 4. Open a PR against `main`
242
+
243
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for details.
244
+
245
+ ---
246
+
247
+ ## License
248
+
249
+ [MIT](./LICENSE) — Built and maintained by [shinzarou-eng](https://github.com/shinzarou-eng).
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: codebase-chat
3
+ name: dsh-codebase-chat
package/lib/cache.js ADDED
@@ -0,0 +1,84 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile, writeFile, mkdir, stat } from "node:fs/promises";
3
+ import { existsSync } from "node:fs";
4
+ import { dirname, join } from "node:path";
5
+ import { homedir } from "node:os";
6
+
7
+ const CACHE_VERSION = 1;
8
+
9
+ function getCacheDir() {
10
+ const base = process.env.CODEBASE_CACHE_DIR
11
+ || process.env.LOCALAPPDATA
12
+ || process.env.APPDATA
13
+ || join(homedir(), ".cache");
14
+ return join(base, "dsh-codebase-chat-cache");
15
+ }
16
+
17
+ function projectHash(absProject) {
18
+ return createHash("sha256").update(absProject.toLowerCase()).digest("hex").slice(0, 16);
19
+ }
20
+
21
+ export function cachePath(absProject) {
22
+ return join(getCacheDir(), `${projectHash(absProject)}.json`);
23
+ }
24
+
25
+ export async function loadCache(absProject) {
26
+ const p = cachePath(absProject);
27
+ if (!existsSync(p)) return null;
28
+ try {
29
+ const raw = await readFile(p, "utf8");
30
+ const data = JSON.parse(raw);
31
+ if (data?.version !== CACHE_VERSION) return null;
32
+ return data;
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
37
+
38
+ export async function saveCache(absProject, data) {
39
+ const p = cachePath(absProject);
40
+ await mkdir(dirname(p), { recursive: true });
41
+ const payload = {
42
+ version: CACHE_VERSION,
43
+ projectPath: absProject,
44
+ updatedAt: Date.now(),
45
+ ...data
46
+ };
47
+ await writeFile(p, JSON.stringify(payload), "utf8");
48
+ }
49
+
50
+ export function hashFile(stats, firstBytes = "") {
51
+ return createHash("sha256")
52
+ .update(`${stats.mtimeMs}:${stats.size}:${firstBytes.slice(0, 512)}`)
53
+ .digest("hex")
54
+ .slice(0, 24);
55
+ }
56
+
57
+ export async function fileStats(filePath) {
58
+ try {
59
+ return await stat(filePath);
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+
65
+ export function estimateTokens(text) {
66
+ return Math.ceil(text.length / 3.5);
67
+ }
68
+
69
+ export function truncateByTokens(text, maxTokens) {
70
+ if (estimateTokens(text) <= maxTokens) return text;
71
+ const targetChars = Math.floor(maxTokens * 3.5);
72
+ const lines = text.split("\n");
73
+ let acc = [];
74
+ let chars = 0;
75
+ for (const line of lines) {
76
+ if (chars + line.length + 1 > targetChars) {
77
+ acc.push("[... tronque pour respecter le budget de tokens ...]");
78
+ break;
79
+ }
80
+ acc.push(line);
81
+ chars += line.length + 1;
82
+ }
83
+ return acc.join("\n");
84
+ }