Skip to content

Commit 3242cf6

Browse files
CSCSoftwareclaude
andcommitted
feat: Auto-setup on install, comprehensive AI instructions, code refactoring (v1.12.0)
- postinstall now auto-runs aidex setup (opt-out: AIDEX_NO_SETUP=1 or CI) - CLAUDE.md/GEMINI.md block expanded: decision tree, search modes, all 27 tools - Duplicate detection: skips if manual AiDex instructions already exist - Shared utilities extracted (shared.ts, global-shared.ts) — ~200 lines eliminated - DB fixes: transactions, N+1 batch query, stats 7→1 query, SQL injection fix Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 281452f commit 3242cf6

24 files changed

Lines changed: 1881 additions & 1717 deletions

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

33
All notable changes to AiDex will be documented in this file.
44

5+
## [1.12.0] - 2026-03-07
6+
7+
### Added
8+
- **Auto-setup on install**: `npm install -g aidex-mcp` now automatically registers AiDex with all detected AI clients and installs AI instructions (`CLAUDE.md`, `GEMINI.md`)
9+
- Opt-out via `AIDEX_NO_SETUP=1` or `CI` environment variable
10+
- Graceful fallback: shows manual hint if auto-setup fails
11+
- **Comprehensive AI instructions**: The CLAUDE.md block installed by `aidex setup` now covers all 27 tools
12+
- Decision tree: "Do I want to search code? → .aidex/ exists? → STOP, use AiDex"
13+
- Explicit ❌/✅ examples (never Grep when .aidex exists)
14+
- Search modes explained (exact/contains/starts_with)
15+
- Session notes, task backlog, global search, screenshots — all with examples
16+
- **Duplicate detection**: `aidex setup` skips CLAUDE.md/GEMINI.md if manual AiDex instructions already exist (avoids double entries)
17+
18+
### Changed
19+
- **Refactored commands**: Extracted shared utilities into `shared.ts` and `global-shared.ts`
20+
- `validateIndex()`, `noIndexError()`, `withDatabase()`, `withProjectDb()`~200 lines of boilerplate eliminated across 10 command files
21+
- `withGlobalDb()`, `EMPTY_TOTALS` — 4 global commands refactored
22+
- **README**: Expanded "Make your AI use it" section with full best-practice instruction block
23+
24+
### Fixed
25+
- **DB transactions**: `clearFileData()` and `bulkInsert*()` now wrapped in transactions
26+
- **N+1 query**: Batch `getOccurrencesByItems()` replaces per-item queries
27+
- **Stats query**: `getStats()` reduced from 7 queries to 1
28+
- **SQL injection**: `global-signatures.ts``t.kind = '${kind}'` → parameterized query
29+
- **Session**: Eliminated duplicate `getMetadata` calls
30+
- **Tasks**: Added null-check for `tableInfo` result
31+
532
## [1.11.0] - 2026-03-07
633

734
### Added

README.md

Lines changed: 183 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,74 @@ AiDex is an MCP server that gives AI coding assistants instant access to your en
1818

1919
</details>
2020

21+
### What's Inside — 27 Tools in One Server
22+
23+
| Category | Tools | What it does |
24+
|----------|-------|--------------|
25+
| **Search & Index** | `init`, `query`, `update`, `remove`, `status` | Index your project, search identifiers by name (exact/contains/starts_with), time-based filtering |
26+
| **Signatures** | `signature`, `signatures` | Get classes + methods of any file without reading it — single file or glob pattern |
27+
| **Project Overview** | `summary`, `tree`, `describe`, `files` | Entry points, language breakdown, file tree with stats, file listing by type |
28+
| **Cross-Project** | `link`, `unlink`, `links`, `scan` | Link dependencies, discover indexed projects |
29+
| **Global Search** | `global_init`, `global_query`, `global_signatures`, `global_status`, `global_refresh` | Search across ALL your projects at once — "Have I ever written X?" |
30+
| **Sessions** | `session`, `note` | Track sessions, detect external changes, leave notes for next session (with searchable history) |
31+
| **Task Backlog** | `task`, `tasks` | Built-in task management with priorities, tags, and auto-logged history |
32+
| **Screenshots** | `screenshot`, `windows` | Cross-platform screen capture (fullscreen, window, region) — no index needed |
33+
| **Viewer** | `viewer` | Interactive browser UI with file tree, signatures, tasks, and live reload |
34+
35+
**11 languages** — C#, TypeScript, JavaScript, Rust, Python, C, C++, Java, Go, PHP, Ruby
36+
37+
<details>
38+
<summary><strong>Quick Examples</strong> — see it in action</summary>
39+
40+
```
41+
# Find where "PlayerHealth" is defined — 1 call, ~50 tokens
42+
aidex_query({ term: "PlayerHealth" })
43+
→ Engine.cs:45, Player.cs:23, UI.cs:156
44+
45+
# All methods in a file — without reading the whole file
46+
aidex_signature({ file: "src/Engine.cs" })
47+
→ class GameEngine { Update(), Render(), LoadScene(), ... }
48+
49+
# What changed in the last 2 hours?
50+
aidex_query({ term: "render", modified_since: "2h" })
51+
52+
# Search across ALL your projects at once
53+
aidex_global_query({ term: "TransparentWindow", mode: "contains" })
54+
→ Found in: LibWebAppGpu (3 hits), DebugViewer (1 hit)
55+
56+
# Leave a note for your next session
57+
aidex_note({ path: ".", note: "Test the parser fix after restart" })
58+
59+
# Create a task while working
60+
aidex_task({ path: ".", action: "create", title: "Fix edge case in parser", priority: 1, tags: "bug" })
61+
```
62+
63+
</details>
64+
65+
## Table of Contents
66+
67+
- [What's Inside](#whats-inside--27-tools-in-one-server)
68+
- [The Problem](#the-problem)
69+
- [The Solution](#the-solution)
70+
- [Why Not Just Grep?](#why-not-just-grep)
71+
- [How It Works](#how-it-works)
72+
- [Features](#features)
73+
- [Supported Languages](#supported-languages)
74+
- [Quick Start](#quick-start)
75+
- [Available Tools](#available-tools)
76+
- [Time-based Filtering](#time-based-filtering)
77+
- [Project Structure](#project-structure)
78+
- [Session Notes](#session-notes)
79+
- [Task Backlog](#task-backlog)
80+
- [Global Search](#global-search)
81+
- [Screenshots](#screenshots)
82+
- [Interactive Viewer](#interactive-viewer)
83+
- [CLI Usage](#cli-usage)
84+
- [Performance](#performance)
85+
- [Technology](#technology)
86+
- [Contributing](#contributing)
87+
- [License](#license)
88+
2189
## The Problem
2290

2391
Every time your AI assistant searches for code, it:
@@ -85,18 +153,13 @@ The index lives in `.aidex/index.db` (SQLite) - fast, portable, no external depe
85153

86154
## Features
87155

88-
- **Screenshots**: Cross-platform screenshot capture (fullscreen, window, region) with auto-path for instant AI viewing
89-
- **Smart Extraction**: Uses Tree-sitter to parse code properly - indexes identifiers, not keywords
90-
- **Method Signatures**: Get function prototypes without reading implementations
91-
- **Project Summary**: Auto-detected entry points, main classes, language breakdown
92-
- **Incremental Updates**: Re-index single files after changes
93-
- **Cross-Project Links**: Query across multiple related projects
94-
- **Global Search**: Search across ALL indexed projects at once - "Have I ever written X?"
156+
- **Tree-sitter Parsing**: Real code parsing, not regex — indexes identifiers, ignores keywords and noise
157+
- **~50 Tokens per Search**: vs 2000+ with grep — your AI keeps its context for actual work
158+
- **Persistent Index**: Survives between sessions — no re-scanning, no re-reading
159+
- **Incremental Updates**: Re-index single files after changes, not the whole project
95160
- **Time-based Filtering**: Find what changed in the last hour, day, or week
96-
- **Project Structure**: Query all files (code, config, docs, assets) without filesystem access
97-
- **Session Notes**: Leave reminders for the next session - persists in the database, with searchable history
98-
- **Task Backlog**: Built-in task management that lives with your code index - no external tools needed
99161
- **Auto-Cleanup**: Excluded files (e.g., build outputs) are automatically removed from index
162+
- **Zero Dependencies**: SQLite with WAL mode — single file, fast, portable
100163

101164
## Supported Languages
102165

@@ -116,14 +179,15 @@ The index lives in `.aidex/index.db` (SQLite) - fast, portable, no external depe
116179

117180
## Quick Start
118181

119-
### 1. Install & Register
182+
### 1. Install
120183

121184
```bash
122185
npm install -g aidex-mcp
123-
aidex setup
124186
```
125187

126-
`aidex setup` automatically detects and registers AiDex with your installed AI clients (Claude Code, Claude Desktop, Cursor, Windsurf, Gemini CLI, VS Code Copilot). To unregister: `aidex unsetup`.
188+
**That's it.** Setup runs automatically after install — it detects your installed AI clients (Claude Code, Claude Desktop, Cursor, Windsurf, Gemini CLI, VS Code Copilot) and registers AiDex as an MCP server. It also adds usage instructions to your AI's config (`~/.claude/CLAUDE.md`, `~/.gemini/GEMINI.md`).
189+
190+
To re-run setup manually: `aidex setup` | To unregister: `aidex unsetup` | To skip auto-setup: `AIDEX_NO_SETUP=1 npm install -g aidex-mcp`
127191

128192
### 2. Or register manually with your AI assistant
129193

@@ -182,20 +246,117 @@ aidex setup
182246

183247
### 3. Make your AI actually use it
184248

185-
Add to your AI's instructions (e.g., `~/.claude/CLAUDE.md` for Claude Code):
249+
Add to your AI's instructions (e.g., `~/.claude/CLAUDE.md` for Claude Code, or the equivalent for your AI client). This tells the AI **when and how** to use AiDex instead of grepping:
186250

187251
```markdown
188-
## AiDex - Use for ALL code searches!
252+
## AiDex - Persistent Code Index (MCP Server)
253+
254+
AiDex provides fast, precise code search through a pre-built index.
255+
**Always prefer AiDex over Grep/Glob for code searches.**
256+
257+
### REQUIRED: Before using Grep/Glob/Read for code searches
258+
259+
```
260+
Do I want to search code?
261+
├── .aidex/ exists → STOP! Use AiDex instead
262+
├── .aidex/ missing → run aidex_init (don't ask), THEN use AiDex
263+
└── Config/Logs/Text → Grep/Read is fine
264+
```
265+
266+
**NEVER do this when .aidex/ exists:**
267+
- ❌ `Grep pattern="functionName"` → ✅ `aidex_query term="functionName"`
268+
- ❌ `Grep pattern="class.*Name"` → ✅ `aidex_query term="Name" mode="contains"`
269+
- ❌ `Read file.cs` to see methods → ✅ `aidex_signature file="file.cs"`
270+
- ❌ `Glob pattern="**/*.cs"` + Read → ✅ `aidex_signatures pattern="**/*.cs"`
271+
272+
### Session-Start Rule (REQUIRED — every session, no exceptions)
273+
274+
1. Call `aidex_session({ path: "<project>" })` — detects external changes, auto-reindexes
275+
2. If `.aidex/` does NOT exist → run `aidex_init` automatically (don't ask)
276+
3. If a session note exists → **show it to the user** before continuing
277+
4. **Before ending a session:** always leave a note about what to do next
278+
279+
### Question → Right Tool
189280
190-
**Before using Grep/Glob, check if `.aidex/` exists in the project.**
281+
| Question | Tool |
282+
|----------|------|
283+
| "Where is X defined?" | `aidex_query term="X"` |
284+
| "Find anything containing X" | `aidex_query term="X" mode="contains"` |
285+
| "All functions starting with X" | `aidex_query term="X" mode="starts_with"` |
286+
| "What methods does file Y have?" | `aidex_signature file="Y"` |
287+
| "Explore all files in src/" | `aidex_signatures pattern="src/**"` |
288+
| "Project overview" | `aidex_summary` + `aidex_tree` |
289+
| "What changed recently?" | `aidex_query term="X" modified_since="2h"` |
290+
| "What files changed today?" | `aidex_files path="." modified_since="8h"` |
291+
| "Have I ever written X?" | `aidex_global_query term="X" mode="contains"` |
292+
| "Which project has class Y?" | `aidex_global_signatures term="Y" kind="class"` |
293+
| "All indexed projects?" | `aidex_global_status` |
191294
192-
If yes, use AiDex instead:
193-
- `aidex_query` - Find functions, classes, variables by name
194-
- `aidex_signature` - Get all methods in a file with line numbers
195-
- `aidex_signatures` - Get methods from multiple files (glob pattern)
196-
- `aidex_summary` - Project overview with entry points
295+
### Search Modes
197296
198-
If no `.aidex/` exists, offer to run `aidex_init` first.
297+
- **`exact`** (default): Finds only the exact identifier — `log` won't match `catalog`
298+
- **`contains`**: Finds identifiers containing the term — `render` matches `preRenderSetup`
299+
- **`starts_with`**: Finds identifiers starting with the term — `Update` matches `UpdatePlayer`, `UpdateUI`
300+
301+
### All Tools (27)
302+
303+
| Category | Tools | Purpose |
304+
|----------|-------|---------|
305+
| Search & Index | `aidex_init`, `aidex_query`, `aidex_update`, `aidex_remove`, `aidex_status` | Index project, search identifiers (exact/contains/starts_with), time filter |
306+
| Signatures | `aidex_signature`, `aidex_signatures` | Get classes + methods without reading files |
307+
| Overview | `aidex_summary`, `aidex_tree`, `aidex_describe`, `aidex_files` | Entry points, file tree, file listing by type |
308+
| Cross-Project | `aidex_link`, `aidex_unlink`, `aidex_links`, `aidex_scan` | Link dependencies, discover projects |
309+
| Global Search | `aidex_global_init`, `aidex_global_query`, `aidex_global_signatures`, `aidex_global_status`, `aidex_global_refresh` | Search across ALL projects |
310+
| Sessions | `aidex_session`, `aidex_note` | Track sessions, leave notes (with searchable history) |
311+
| Tasks | `aidex_task`, `aidex_tasks` | Built-in backlog with priorities, tags, auto-logged history |
312+
| Screenshots | `aidex_screenshot`, `aidex_windows` | Cross-platform screen capture (no index needed) |
313+
| Viewer | `aidex_viewer` | Interactive browser UI with file tree, signatures, tasks |
314+
315+
**11 languages:** C#, TypeScript, JavaScript, Rust, Python, C, C++, Java, Go, PHP, Ruby
316+
317+
### Session Notes
318+
319+
Leave notes for the next session — they persist in the database:
320+
```
321+
aidex_note({ path: ".", note: "Test the fix after restart" }) # Write
322+
aidex_note({ path: ".", note: "Also check edge cases", append: true }) # Append
323+
aidex_note({ path: "." }) # Read
324+
aidex_note({ path: ".", search: "parser" }) # Search history
325+
aidex_note({ path: ".", clear: true }) # Clear
326+
```
327+
- **Before ending a session:** automatically leave a note about next steps
328+
- **User says "remember for next session: ..."** → write it immediately
329+
330+
### Task Backlog
331+
332+
Track TODOs, bugs, and features right next to your code index:
333+
```
334+
aidex_task({ path: ".", action: "create", title: "Fix bug", priority: 1, tags: "bug" })
335+
aidex_task({ path: ".", action: "update", id: 1, status: "done" })
336+
aidex_task({ path: ".", action: "log", id: 1, note: "Root cause found" })
337+
aidex_tasks({ path: ".", status: "active" })
338+
```
339+
Priority: 1=high, 2=medium, 3=low | Status: `backlog → active → done | cancelled`
340+
341+
### Global Search (across all projects)
342+
343+
```
344+
aidex_global_init({ path: "/path/to/all/repos" }) # Scan & register
345+
aidex_global_init({ path: "...", index_unindexed: true }) # + auto-index small projects
346+
aidex_global_query({ term: "TransparentWindow", mode: "contains" }) # Search everywhere
347+
aidex_global_signatures({ term: "Render", kind: "method" }) # Find methods everywhere
348+
aidex_global_status({ sort: "recent" }) # List all projects
349+
```
350+
351+
### Screenshots
352+
353+
```
354+
aidex_screenshot() # Full screen
355+
aidex_screenshot({ mode: "active_window" }) # Active window
356+
aidex_screenshot({ mode: "window", window_title: "VS Code" }) # Specific window
357+
aidex_windows({ filter: "chrome" }) # Find window titles
358+
```
359+
No index needed. Returns file path → use `Read` to view immediately.
199360
```
200361

201362
### 4. Index your project

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aidex-mcp",
3-
"version": "1.11.0",
3+
"version": "1.12.0",
44
"mcpName": "io.github.CSCSoftware/aidex",
55
"description": "MCP Server for persistent code indexing. Gives AI assistants (Claude, Gemini, Copilot, Cursor) instant access to your codebase. 50x less context than grep.",
66
"main": "build/index.js",

scripts/postinstall.mjs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
// Postinstall hint - shown after npm install -g aidex-mcp
2-
console.log('\n AiDex installed! Run "aidex setup" to register with your AI clients.\n');
1+
// Postinstall - auto-register AiDex with AI clients
2+
// Skip with: AIDEX_NO_SETUP=1 npm install -g aidex-mcp
3+
4+
import { execSync } from 'child_process';
5+
import { existsSync } from 'fs';
6+
import { resolve, dirname } from 'path';
7+
import { fileURLToPath } from 'url';
8+
9+
if (process.env.AIDEX_NO_SETUP === '1' || process.env.CI) {
10+
console.log('\n AiDex installed. Setup skipped (AIDEX_NO_SETUP=1 or CI detected).\n');
11+
process.exit(0);
12+
}
13+
14+
// Find the built index.js relative to this script
15+
const thisDir = dirname(fileURLToPath(import.meta.url));
16+
const indexJs = resolve(thisDir, '..', 'build', 'index.js');
17+
18+
if (!existsSync(indexJs)) {
19+
// Build not available yet (e.g. development install) - show hint
20+
console.log('\n AiDex installed! Run "aidex setup" to register with your AI clients.\n');
21+
process.exit(0);
22+
}
23+
24+
try {
25+
execSync(`"${process.execPath}" "${indexJs}" setup`, { stdio: 'inherit', timeout: 15000 });
26+
} catch {
27+
// Setup failed - not critical, show manual hint
28+
console.log('\n Auto-setup failed. Run "aidex setup" manually to register with your AI clients.\n');
29+
}

0 commit comments

Comments
 (0)