aidex-mcp 1.5.2 → 1.6.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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  All notable changes to AiDex will be documented in this file.
4
4
 
5
+ ## [1.6.0] - 2026-02-01
6
+
7
+ ### Added
8
+ - **Auto CLAUDE.md instructions**: `aidex setup` now installs AI instructions in `~/.claude/CLAUDE.md`
9
+ - Tells Claude to auto-run `aidex_init` when no `.aidex/` exists
10
+ - Provides tool usage guide (prefer AiDex over Grep/Glob)
11
+ - `aidex unsetup` cleanly removes the instructions block
12
+ - **Idempotent setup**: Re-running `aidex setup` updates existing config without errors
13
+
5
14
  ## [1.5.2] - 2026-02-01
6
15
 
7
16
  ### Fixed
@@ -2,6 +2,7 @@
2
2
  * AiDex Setup - Auto-register as MCP server in AI clients
3
3
  *
4
4
  * Supports: Claude Code (via CLI), Claude Desktop, Cursor, Windsurf
5
+ * Also installs CLAUDE.md instructions for Claude Code/Desktop.
5
6
  */
6
7
  export declare function setupMcpClients(): void;
7
8
  export declare function unsetupMcpClients(): void;
@@ -2,9 +2,10 @@
2
2
  * AiDex Setup - Auto-register as MCP server in AI clients
3
3
  *
4
4
  * Supports: Claude Code (via CLI), Claude Desktop, Cursor, Windsurf
5
+ * Also installs CLAUDE.md instructions for Claude Code/Desktop.
5
6
  */
6
- import { existsSync, readFileSync, writeFileSync } from 'fs';
7
- import { join } from 'path';
7
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
8
+ import { join, dirname } from 'path';
8
9
  import { homedir, platform } from 'os';
9
10
  import { execSync } from 'child_process';
10
11
  // ============================================================
@@ -15,6 +16,55 @@ const AIDEX_MCP_ENTRY = {
15
16
  args: []
16
17
  };
17
18
  // ============================================================
19
+ // CLAUDE.md Instructions Block
20
+ // ============================================================
21
+ const CLAUDE_MD_START = '<!-- AIDEX-START -->';
22
+ const CLAUDE_MD_END = '<!-- AIDEX-END -->';
23
+ const CLAUDE_MD_BLOCK = `${CLAUDE_MD_START}
24
+ ## AiDex - Persistent Code Index (MCP Server)
25
+
26
+ AiDex provides fast, precise code search through a pre-built index. **Always prefer AiDex over Grep/Glob for code searches.**
27
+
28
+ ### Auto-Init Rule
29
+
30
+ **At the start of every session, check if \`.aidex/\` exists in the project directory.**
31
+ - If \`.aidex/\` does NOT exist → **automatically run \`aidex_init\`** to create the index. Do not ask, just do it.
32
+ - If \`.aidex/\` exists → use AiDex tools for all code searches.
33
+
34
+ ### When to Use AiDex (instead of Grep/Glob)
35
+
36
+ | Task | Do NOT use | Use instead |
37
+ |------|-----------|-------------|
38
+ | Find a function/class/variable | \`Grep pattern="name"\` | \`aidex_query term="name"\` |
39
+ | See all methods in a file | \`Read entire_file.cs\` | \`aidex_signature file="..."\` |
40
+ | Explore multiple files | Multiple Read calls | \`aidex_signatures pattern="src/**"\` |
41
+ | Project overview | Many Glob/Read calls | \`aidex_summary\` + \`aidex_tree\` |
42
+ | What changed recently? | \`git log\` + Read | \`aidex_query term="X" modified_since="2h"\` |
43
+
44
+ ### Available Tools
45
+
46
+ | Tool | Purpose |
47
+ |------|---------|
48
+ | \`aidex_init\` | Index a project (creates \`.aidex/\`) |
49
+ | \`aidex_query\` | Search by term (exact/contains/starts_with) |
50
+ | \`aidex_signature\` | Get one file's classes + methods |
51
+ | \`aidex_signatures\` | Get signatures for multiple files (glob) |
52
+ | \`aidex_update\` | Re-index a single changed file |
53
+ | \`aidex_summary\` | Project overview with entry points |
54
+ | \`aidex_tree\` | File tree with statistics |
55
+ | \`aidex_files\` | List project files by type |
56
+ | \`aidex_session\` | Start session, detect external changes |
57
+ | \`aidex_note\` | Read/write session notes |
58
+ | \`aidex_viewer\` | Open interactive project tree in browser |
59
+
60
+ ### Why AiDex over Grep?
61
+
62
+ - **~50 tokens** per search vs 2000+ with Grep
63
+ - **Identifiers only** - no noise from comments/strings
64
+ - **Persistent** - index survives between sessions
65
+ - **Structure-aware** - knows methods, classes, types
66
+ ${CLAUDE_MD_END}`;
67
+ // ============================================================
18
68
  // Client Detection
19
69
  // ============================================================
20
70
  function getClients() {
@@ -122,6 +172,58 @@ function writeJsonConfig(filePath, data) {
122
172
  }
123
173
  }
124
174
  // ============================================================
175
+ // CLAUDE.md Management
176
+ // ============================================================
177
+ function getClaudeMdPath() {
178
+ return join(homedir(), '.claude', 'CLAUDE.md');
179
+ }
180
+ function installClaudeMd() {
181
+ const mdPath = getClaudeMdPath();
182
+ const dir = dirname(mdPath);
183
+ // Ensure directory exists
184
+ if (!existsSync(dir)) {
185
+ mkdirSync(dir, { recursive: true });
186
+ }
187
+ let content = '';
188
+ if (existsSync(mdPath)) {
189
+ content = readFileSync(mdPath, 'utf8');
190
+ // Already has AiDex block? Replace it
191
+ if (content.includes(CLAUDE_MD_START)) {
192
+ const regex = new RegExp(`${CLAUDE_MD_START}[\\s\\S]*?${CLAUDE_MD_END}`, 'g');
193
+ content = content.replace(regex, CLAUDE_MD_BLOCK);
194
+ writeFileSync(mdPath, content, 'utf8');
195
+ return { success: true, action: 'updated' };
196
+ }
197
+ // Append to existing file
198
+ content = content.trimEnd() + '\n\n' + CLAUDE_MD_BLOCK + '\n';
199
+ writeFileSync(mdPath, content, 'utf8');
200
+ return { success: true, action: 'appended' };
201
+ }
202
+ // Create new file
203
+ writeFileSync(mdPath, CLAUDE_MD_BLOCK + '\n', 'utf8');
204
+ return { success: true, action: 'created' };
205
+ }
206
+ function uninstallClaudeMd() {
207
+ const mdPath = getClaudeMdPath();
208
+ if (!existsSync(mdPath)) {
209
+ return { success: true, removed: false };
210
+ }
211
+ let content = readFileSync(mdPath, 'utf8');
212
+ if (!content.includes(CLAUDE_MD_START)) {
213
+ return { success: true, removed: false };
214
+ }
215
+ const regex = new RegExp(`\\n?\\n?${CLAUDE_MD_START}[\\s\\S]*?${CLAUDE_MD_END}\\n?`, 'g');
216
+ content = content.replace(regex, '').trim();
217
+ if (content.length === 0) {
218
+ // File would be empty, but don't delete it - might have been user-created
219
+ writeFileSync(mdPath, '', 'utf8');
220
+ }
221
+ else {
222
+ writeFileSync(mdPath, content + '\n', 'utf8');
223
+ }
224
+ return { success: true, removed: true };
225
+ }
226
+ // ============================================================
125
227
  // Setup
126
228
  // ============================================================
127
229
  function setupCliClient(client) {
@@ -132,9 +234,11 @@ function setupCliClient(client) {
132
234
  if (result.success) {
133
235
  return { status: ` ✓ ${client.name}`, registered: true };
134
236
  }
135
- else {
136
- return { status: ` ✗ ${client.name} (${result.error})`, registered: false };
237
+ // "already exists" is not an error
238
+ if (result.error && result.error.includes('already exists')) {
239
+ return { status: ` ✓ ${client.name} (already registered)`, registered: true };
137
240
  }
241
+ return { status: ` ✗ ${client.name} (${result.error})`, registered: false };
138
242
  }
139
243
  function setupJsonClient(client) {
140
244
  if (!existsSync(client.detectDir)) {
@@ -166,6 +270,8 @@ export function setupMcpClients() {
166
270
  let registered = 0;
167
271
  console.log('\nAiDex MCP Server Registration');
168
272
  console.log('==============================\n');
273
+ // Register with AI clients
274
+ console.log(' MCP Servers:');
169
275
  for (const client of clients) {
170
276
  const result = client.type === 'cli'
171
277
  ? setupCliClient(client)
@@ -174,6 +280,13 @@ export function setupMcpClients() {
174
280
  if (result.registered)
175
281
  registered++;
176
282
  }
283
+ // Install CLAUDE.md instructions
284
+ console.log('\n AI Instructions:');
285
+ const mdResult = installClaudeMd();
286
+ const mdPath = getClaudeMdPath();
287
+ if (mdResult.success) {
288
+ console.log(` ✓ CLAUDE.md (${mdResult.action}: ${mdPath})`);
289
+ }
177
290
  console.log(`\nRegistered AiDex with ${registered} client(s).\n`);
178
291
  if (registered > 0) {
179
292
  console.log('Restart your AI client(s) to activate AiDex.\n');
@@ -222,6 +335,8 @@ export function unsetupMcpClients() {
222
335
  let removed = 0;
223
336
  console.log('\nAiDex MCP Server Unregistration');
224
337
  console.log('================================\n');
338
+ // Unregister from AI clients
339
+ console.log(' MCP Servers:');
225
340
  for (const client of clients) {
226
341
  const result = client.type === 'cli'
227
342
  ? unsetupCliClient(client)
@@ -230,6 +345,15 @@ export function unsetupMcpClients() {
230
345
  if (result.removed)
231
346
  removed++;
232
347
  }
348
+ // Remove CLAUDE.md instructions
349
+ console.log('\n AI Instructions:');
350
+ const mdResult = uninstallClaudeMd();
351
+ if (mdResult.removed) {
352
+ console.log(` ✓ Removed AiDex block from CLAUDE.md`);
353
+ }
354
+ else {
355
+ console.log(` - CLAUDE.md (no AiDex block found)`);
356
+ }
233
357
  console.log(`\nUnregistered AiDex from ${removed} client(s).\n`);
234
358
  }
235
359
  //# sourceMappingURL=setup.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aidex-mcp",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "MCP Server providing persistent code indexing for Claude Code",
5
5
  "main": "build/index.js",
6
6
  "bin": {