k0ntext 3.1.0 → 3.2.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/README.md +78 -2
- package/dist/cli/commands/batch-index.d.ts +16 -0
- package/dist/cli/commands/batch-index.d.ts.map +1 -0
- package/dist/cli/commands/batch-index.js +387 -0
- package/dist/cli/commands/batch-index.js.map +1 -0
- package/dist/cli/index.js +65 -0
- package/dist/cli/index.js.map +1 -1
- package/package.json +2 -2
- package/src/cli/commands/batch-index.ts +492 -0
- package/src/cli/index.ts +81 -3
- package/templates/base/CLI_COMMANDS.md +589 -0
- package/templates/base/agents/api-developer.md +37 -0
- package/templates/base/agents/context-engineer.md +41 -0
- package/templates/base/agents/core-architect.md +41 -0
- package/templates/base/agents/database-ops.md +38 -0
- package/templates/base/agents/deployment-ops.md +41 -0
- package/templates/base/agents/integration-hub.md +37 -0
- package/templates/base/commands/analytics.md +33 -0
- package/templates/base/commands/auto-sync.md +33 -0
- package/templates/base/commands/collab.md +37 -0
- package/templates/base/commands/context-optimize.md +36 -0
- package/templates/base/commands/help.md +55 -0
- package/templates/base/commands/rpi-implement.md +36 -0
- package/templates/base/commands/rpi-plan.md +32 -0
- package/templates/base/commands/rpi-research.md +34 -0
- package/templates/base/commands/session-resume.md +32 -0
- package/templates/base/commands/session-save.md +29 -0
- package/templates/base/commands/validate-all.md +36 -0
- package/templates/base/commands/verify-docs-current.md +33 -0
- package/templates/base/settings.json +10 -1
package/README.md
CHANGED
|
@@ -9,6 +9,38 @@
|
|
|
9
9
|
|
|
10
10
|
Universal AI context engineering for Claude, GitHub Copilot, Cline, Cursor, Windsurf, Aider, Continue, Antigravity, and Gemini with OpenRouter-powered intelligent analysis.
|
|
11
11
|
|
|
12
|
+
## Table of Contents
|
|
13
|
+
|
|
14
|
+
- [Quick Start](#-quick-start-30-seconds)
|
|
15
|
+
- [Zero-to-Hero Workflow](#-zero-to-hero-workflow)
|
|
16
|
+
- [Windows Support](#-windows-support)
|
|
17
|
+
- [Features Overview](#-features-overview)
|
|
18
|
+
- [Intelligent Analysis](#-intelligent-analysis)
|
|
19
|
+
- [Semantic Search](#-semantic-search)
|
|
20
|
+
- [Cross-Tool Sync](#-cross-tool-sync)
|
|
21
|
+
- [Git Hooks Automation](#-git-hooks-automation-v310)
|
|
22
|
+
- [Drift Detection](#-drift-detection-v310)
|
|
23
|
+
- [Fact-Checking](#-fact-checking-v310)
|
|
24
|
+
- [Map-Based Context](#-map-based-context-v310)
|
|
25
|
+
- [MCP Server](#-mcp-server)
|
|
26
|
+
- [Complete CLI](#-complete-cli-18-commands)
|
|
27
|
+
- [Smart Agents](#-smart-agents)
|
|
28
|
+
- [SQLite Storage](#-sqlite-storage)
|
|
29
|
+
- [Complete CLI Reference](#-complete-cli-reference)
|
|
30
|
+
- [Core Commands](#core-commands)
|
|
31
|
+
- [v3.1.0 New Commands](#v310-new-commands)
|
|
32
|
+
- [Git Hooks Workflow](#-git-hooks-workflow-v310)
|
|
33
|
+
- [MCP Server Usage](#-mcp-server-usage)
|
|
34
|
+
- [Supported AI Tools](#-supported-ai-tools)
|
|
35
|
+
- [Configuration](#-configuration)
|
|
36
|
+
- [Architecture](#-architecture)
|
|
37
|
+
- [Development](#-development)
|
|
38
|
+
- [Performance Monitoring](#-performance-monitoring)
|
|
39
|
+
- [Troubleshooting](#-troubleshooting)
|
|
40
|
+
- [Community](#-community)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
12
44
|
## 🚀 Quick Start (30 Seconds)
|
|
13
45
|
|
|
14
46
|
```bash
|
|
@@ -38,7 +70,7 @@ k0ntext index
|
|
|
38
70
|
# 3. Generate context files
|
|
39
71
|
k0ntext generate
|
|
40
72
|
|
|
41
|
-
# 4. Start MCP server
|
|
73
|
+
# 4. Start MCP server (auto-configured)
|
|
42
74
|
k0ntext mcp
|
|
43
75
|
```
|
|
44
76
|
|
|
@@ -111,12 +143,36 @@ K0ntext uses native SQLite extensions for high-performance vector search.
|
|
|
111
143
|
- Alternative to verbose documentation format
|
|
112
144
|
|
|
113
145
|
### 🤖 MCP Server
|
|
146
|
+
- **Auto-Configuration** (v3.1.1) - MCP server automatically configured in `.claude/settings.json` on init
|
|
147
|
+
- **10 Tools:** search_context, get_item, add_knowledge, analyze, get_tool_configs, query_graph, get_stats
|
|
148
|
+
- **6 Prompts:** context-engineer, core-architect, api-developer, database-ops, integration-hub, deployment-ops
|
|
149
|
+
- Real-time context access for AI assistants
|
|
150
|
+
- Knowledge graph traversal
|
|
114
151
|
- **10 Tools:** search_context, get_item, add_knowledge, analyze, get_tool_configs, query_graph, get_stats
|
|
115
152
|
- **6 Prompts:** context-engineer, core-architect, api-developer, database-ops, integration-hub, deployment-ops
|
|
116
153
|
- Real-time context access for AI assistants
|
|
117
154
|
- Knowledge graph traversal
|
|
118
155
|
|
|
119
156
|
### 🛠️ Complete CLI (18 Commands)
|
|
157
|
+
- `init` - Initialize with intelligent analysis **(auto-configures MCP in v3.1.1)**
|
|
158
|
+
- `generate` - Generate context files for all tools
|
|
159
|
+
- `mcp` - Start MCP server
|
|
160
|
+
- `sync` - Sync across AI tools
|
|
161
|
+
- `cleanup` - Clean up conflicting tool folders
|
|
162
|
+
- `validate` - Validate context files
|
|
163
|
+
- `export` - Export database
|
|
164
|
+
- `import` - Import from exports
|
|
165
|
+
- `performance` - Show performance metrics
|
|
166
|
+
- `watch` - Auto-index file changes
|
|
167
|
+
- `index` - Index codebase
|
|
168
|
+
- `search` - Search indexed content
|
|
169
|
+
- `stats` - View database statistics
|
|
170
|
+
- **`drift-detect`** - AI-powered documentation drift detection (v3.1.0)
|
|
171
|
+
- **`cross-sync`** - Intelligent sync across all AI tools (v3.1.0)
|
|
172
|
+
- **`hooks`** - Git hooks management (install/uninstall/status) (v3.1.0)
|
|
173
|
+
- **`fact-check`** - Validate documentation accuracy (v3.1.0)
|
|
174
|
+
- `generate --map` - Generate concise map-based context files (v3.1.0)
|
|
175
|
+
- **CLI documentation in all templates** (v3.1.1) - Agent and command templates now include k0ntext CLI usage guidance
|
|
120
176
|
- `init` - Initialize with intelligent analysis
|
|
121
177
|
- `generate` - Generate context files for all tools
|
|
122
178
|
- `mcp` - Start MCP server
|
|
@@ -519,9 +575,29 @@ git commit --no-verify -m "message"
|
|
|
519
575
|
|
|
520
576
|
## 🤖 MCP Server Usage
|
|
521
577
|
|
|
578
|
+
### Auto-Configuration (v3.1.1)
|
|
579
|
+
|
|
580
|
+
When you run `k0ntext init`, the MCP server is **automatically configured** in `.claude/settings.json`:
|
|
581
|
+
|
|
582
|
+
```json
|
|
583
|
+
{
|
|
584
|
+
"mcpServers": {
|
|
585
|
+
"k0ntext": {
|
|
586
|
+
"command": "npx",
|
|
587
|
+
"args": ["k0ntext", "mcp"],
|
|
588
|
+
"env": {
|
|
589
|
+
"K0NTEXT_PROJECT_ROOT": "${projectFolder}"
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
**Manual setup is no longer required!** The MCP server works immediately after initialization.
|
|
597
|
+
|
|
522
598
|
### Start the Server
|
|
523
599
|
```bash
|
|
524
|
-
# Start MCP server
|
|
600
|
+
# Start MCP server (auto-configured)
|
|
525
601
|
k0ntext mcp
|
|
526
602
|
```
|
|
527
603
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch Index Command
|
|
3
|
+
*
|
|
4
|
+
* Indexes large monorepos by processing modules in batches.
|
|
5
|
+
* Handles the 100-file limit by splitting content across multiple batches.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Batch index command
|
|
9
|
+
*/
|
|
10
|
+
export declare function batchIndexCommand(options: {
|
|
11
|
+
batchSize?: number;
|
|
12
|
+
'max-files'?: number;
|
|
13
|
+
'skip-embeddings'?: boolean;
|
|
14
|
+
verbose?: boolean;
|
|
15
|
+
}): Promise<void>;
|
|
16
|
+
//# sourceMappingURL=batch-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-index.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/batch-index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0OH;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAoPhB"}
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch Index Command
|
|
3
|
+
*
|
|
4
|
+
* Indexes large monorepos by processing modules in batches.
|
|
5
|
+
* Handles the 100-file limit by splitting content across multiple batches.
|
|
6
|
+
*/
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import ora from 'ora';
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import { createIntelligentAnalyzer } from '../../analyzer/intelligent-analyzer.js';
|
|
12
|
+
import { hasOpenRouterKey } from '../../embeddings/openrouter.js';
|
|
13
|
+
import { DatabaseClient } from '../../db/client.js';
|
|
14
|
+
/**
|
|
15
|
+
* Default monorepo module detection patterns
|
|
16
|
+
*/
|
|
17
|
+
const DEFAULT_MODULES = [
|
|
18
|
+
{ name: 'root', path: '.', priority: 1, description: 'Root configuration files' },
|
|
19
|
+
{ name: 'docs', path: 'docs', priority: 2, description: 'Documentation' },
|
|
20
|
+
{ name: 'backend', path: 'backend', priority: 3, description: 'Backend services' },
|
|
21
|
+
{ name: 'frontend', path: 'frontend', priority: 4, description: 'Frontend applications' },
|
|
22
|
+
{ name: 'core', path: 'core', priority: 5, description: 'Core libraries' },
|
|
23
|
+
{ name: 'shared', path: 'shared', priority: 6, description: 'Shared utilities' },
|
|
24
|
+
{ name: 'packages', path: 'packages', priority: 7, description: 'Packages (npm/yarn workspaces)' },
|
|
25
|
+
{ name: 'services', path: 'services', priority: 8, description: 'Microservices' },
|
|
26
|
+
{ name: 'apps', path: 'apps', priority: 9, description: 'Applications' },
|
|
27
|
+
{ name: 'devops', path: 'devops', priority: 10, description: 'DevOps/deployment configs' },
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Detect monorepo structure from current directory
|
|
31
|
+
*/
|
|
32
|
+
function detectMonorepoStructure(projectRoot) {
|
|
33
|
+
const detectedModules = [];
|
|
34
|
+
// Always include root
|
|
35
|
+
detectedModules.push({
|
|
36
|
+
name: 'root',
|
|
37
|
+
path: '.',
|
|
38
|
+
priority: 1,
|
|
39
|
+
description: 'Root configuration and documentation'
|
|
40
|
+
});
|
|
41
|
+
// Detect common monorepo directories
|
|
42
|
+
const commonDirs = ['backend', 'frontend', 'core', 'packages', 'services', 'apps', 'docs', 'devops', 'shared', 'lib'];
|
|
43
|
+
for (const dir of commonDirs) {
|
|
44
|
+
const fullPath = path.join(projectRoot, dir);
|
|
45
|
+
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
|
|
46
|
+
// Check if directory has actual code files (not empty)
|
|
47
|
+
const hasContent = fs.readdirSync(fullPath).some(item => !item.startsWith('.') && item !== 'node_modules');
|
|
48
|
+
if (hasContent) {
|
|
49
|
+
detectedModules.push({
|
|
50
|
+
name: dir,
|
|
51
|
+
path: dir,
|
|
52
|
+
priority: detectedModules.length + 1,
|
|
53
|
+
description: `${dir} module`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Detect subdirectories within main modules
|
|
59
|
+
for (const module of [...detectedModules]) {
|
|
60
|
+
if (module.path === '.' || module.path === 'root')
|
|
61
|
+
continue;
|
|
62
|
+
const modulePath = path.join(projectRoot, module.path);
|
|
63
|
+
if (!fs.existsSync(modulePath))
|
|
64
|
+
continue;
|
|
65
|
+
try {
|
|
66
|
+
const entries = fs.readdirSync(modulePath, { withFileTypes: true });
|
|
67
|
+
for (const entry of entries) {
|
|
68
|
+
if (entry.isDirectory() && !entry.name.startsWith('.') && entry.name !== 'node_modules') {
|
|
69
|
+
const subPath = path.join(module.path, entry.name);
|
|
70
|
+
// Check if this submodule has code files
|
|
71
|
+
const subModulePath = path.join(projectRoot, subPath);
|
|
72
|
+
const hasCode = fs.readdirSync(subModulePath).some(item => {
|
|
73
|
+
const ext = path.extname(item);
|
|
74
|
+
return ['.ts', '.tsx', '.js', '.jsx', '.py', '.go', '.rs', '.java'].includes(ext);
|
|
75
|
+
});
|
|
76
|
+
if (hasCode) {
|
|
77
|
+
detectedModules.push({
|
|
78
|
+
name: `${module.name}/${entry.name}`,
|
|
79
|
+
path: subPath,
|
|
80
|
+
priority: detectedModules.length + 1,
|
|
81
|
+
description: `${entry.name} submodule`
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Skip if we can't read directory
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return detectedModules.sort((a, b) => a.priority - b.priority);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Split files into batches
|
|
95
|
+
*/
|
|
96
|
+
function splitIntoBatches(items, batchSize) {
|
|
97
|
+
const batches = [];
|
|
98
|
+
for (let i = 0; i < items.length; i += batchSize) {
|
|
99
|
+
batches.push(items.slice(i, i + batchSize));
|
|
100
|
+
}
|
|
101
|
+
return batches;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Index a single batch of files
|
|
105
|
+
*/
|
|
106
|
+
async function indexBatch(db, files, itemType, projectRoot, spinner) {
|
|
107
|
+
let indexedCount = 0;
|
|
108
|
+
for (const file of files) {
|
|
109
|
+
try {
|
|
110
|
+
const content = fs.existsSync(file.path)
|
|
111
|
+
? fs.readFileSync(file.path, 'utf-8').slice(0, 20000)
|
|
112
|
+
: '';
|
|
113
|
+
if (!content)
|
|
114
|
+
continue;
|
|
115
|
+
db.upsertItem({
|
|
116
|
+
type: itemType,
|
|
117
|
+
name: path.basename(file.relativePath),
|
|
118
|
+
content,
|
|
119
|
+
filePath: file.relativePath,
|
|
120
|
+
metadata: {
|
|
121
|
+
size: file.size,
|
|
122
|
+
module: file.relativePath.split(path.sep)[0]
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
indexedCount++;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
// Skip files that can't be read
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return indexedCount;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Generate embeddings for indexed items
|
|
135
|
+
*/
|
|
136
|
+
async function generateEmbeddingsBatch(db, filePaths, analyzer, spinner) {
|
|
137
|
+
let embeddingsCount = 0;
|
|
138
|
+
try {
|
|
139
|
+
const embeddings = new Map();
|
|
140
|
+
spinner.text = `Generating embeddings for ${filePaths.length} files...`;
|
|
141
|
+
// Process in smaller chunks to avoid overwhelming the API
|
|
142
|
+
const embeddingBatchSize = 50;
|
|
143
|
+
const batches = splitIntoBatches(filePaths, embeddingBatchSize);
|
|
144
|
+
for (let i = 0; i < batches.length; i++) {
|
|
145
|
+
const batch = batches[i];
|
|
146
|
+
spinner.text = `Generating embeddings: batch ${i + 1}/${batches.length} (${batch.length} files)...`;
|
|
147
|
+
for (const filePath of batch) {
|
|
148
|
+
try {
|
|
149
|
+
const item = db.getAllItems().find((item) => item.filePath === filePath);
|
|
150
|
+
if (item && item.content) {
|
|
151
|
+
const embedding = await analyzer.embedText(item.content.slice(0, 2000));
|
|
152
|
+
embeddings.set(filePath, embedding);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Skip embedding failures
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (embeddings.size > 0) {
|
|
161
|
+
spinner.text = `Storing ${embeddings.size} embeddings...`;
|
|
162
|
+
for (const [filePath, embedding] of embeddings.entries()) {
|
|
163
|
+
try {
|
|
164
|
+
const item = db.getAllItems().find((item) => item.filePath === filePath);
|
|
165
|
+
if (item && item.id) {
|
|
166
|
+
db.storeEmbedding(item.id, embedding);
|
|
167
|
+
embeddingsCount++;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// Skip storage failures
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
spinner.warn(`Embeddings generation partially failed: ${error instanceof Error ? error.message : error}`);
|
|
178
|
+
}
|
|
179
|
+
return embeddingsCount;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Batch index command
|
|
183
|
+
*/
|
|
184
|
+
export async function batchIndexCommand(options) {
|
|
185
|
+
console.log(`
|
|
186
|
+
${chalk.cyan('╔═══════════════════════════════════════════════════════════════╗')}
|
|
187
|
+
${chalk.cyan('║')} ${chalk.bold.white('K0ntext')} ${chalk.gray('Batch Index')} ${chalk.cyan('║')}
|
|
188
|
+
${chalk.cyan('║')} ${chalk.gray('Monorepo-aware batch indexing for large codebases')} ${chalk.cyan('║')}
|
|
189
|
+
${chalk.cyan('╚═══════════════════════════════════════════════════════════════╝')}
|
|
190
|
+
`);
|
|
191
|
+
const projectRoot = process.cwd();
|
|
192
|
+
const batchSize = options.batchSize ? Number(options.batchSize) : 100;
|
|
193
|
+
const maxFilesPerModule = options['max-files'] ? Number(options['max-files']) : 500;
|
|
194
|
+
const skipEmbeddings = options['skip-embeddings'] || false;
|
|
195
|
+
const verbose = options.verbose || false;
|
|
196
|
+
const spinner = ora();
|
|
197
|
+
let db;
|
|
198
|
+
try {
|
|
199
|
+
spinner.start('Analyzing monorepo structure...');
|
|
200
|
+
// Detect monorepo modules
|
|
201
|
+
const modules = detectMonorepoStructure(projectRoot);
|
|
202
|
+
if (modules.length === 0) {
|
|
203
|
+
spinner.warn('No modules detected. Are you in a project directory?');
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
spinner.succeed(`Detected ${modules.length} modules`);
|
|
207
|
+
// Show detected modules
|
|
208
|
+
console.log(chalk.bold('\nDetected Modules:'));
|
|
209
|
+
for (const module of modules) {
|
|
210
|
+
const fullPath = path.join(projectRoot, module.path);
|
|
211
|
+
let fileCount = 0;
|
|
212
|
+
try {
|
|
213
|
+
const { glob } = await import('glob');
|
|
214
|
+
const files = await glob('**/*.{ts,tsx,js,jsx,py,go,rs,java,cs,rb,php,md}', {
|
|
215
|
+
cwd: fullPath,
|
|
216
|
+
ignore: ['**/node_modules/**', '**/dist/**', '**/build/**', '**/.git/**'],
|
|
217
|
+
nodir: true
|
|
218
|
+
});
|
|
219
|
+
fileCount = files.length;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// Ignore glob errors
|
|
223
|
+
}
|
|
224
|
+
console.log(` ${chalk.cyan('•')} ${chalk.bold(module.name.padEnd(25))} ${chalk.gray(`(${fileCount} files`)}${chalk.gray(`) - ${module.description}`)}`);
|
|
225
|
+
}
|
|
226
|
+
console.log();
|
|
227
|
+
// Initialize database
|
|
228
|
+
spinner.start('Initializing database...');
|
|
229
|
+
db = new DatabaseClient(projectRoot);
|
|
230
|
+
spinner.succeed('Database initialized');
|
|
231
|
+
// Initialize analyzer
|
|
232
|
+
const analyzer = createIntelligentAnalyzer(projectRoot);
|
|
233
|
+
const hasEmbeddings = hasOpenRouterKey() && !skipEmbeddings;
|
|
234
|
+
if (!hasEmbeddings) {
|
|
235
|
+
console.log(chalk.yellow('Note: OPENROUTER_API_KEY not set. Skipping semantic embeddings.'));
|
|
236
|
+
}
|
|
237
|
+
// Track overall progress
|
|
238
|
+
const totalStats = {
|
|
239
|
+
modulesProcessed: 0,
|
|
240
|
+
docsIndexed: 0,
|
|
241
|
+
codeIndexed: 0,
|
|
242
|
+
configsIndexed: 0,
|
|
243
|
+
embeddingsGenerated: 0,
|
|
244
|
+
filesSkipped: 0
|
|
245
|
+
};
|
|
246
|
+
// Process each module
|
|
247
|
+
for (const module of modules) {
|
|
248
|
+
const modulePath = path.join(projectRoot, module.path);
|
|
249
|
+
const moduleAnalyzer = createIntelligentAnalyzer(modulePath);
|
|
250
|
+
spinner.start(`Processing module: ${module.name}...`);
|
|
251
|
+
try {
|
|
252
|
+
// Discover content in this module
|
|
253
|
+
const [docs, code, tools] = await Promise.all([
|
|
254
|
+
moduleAnalyzer.discoverDocs(),
|
|
255
|
+
moduleAnalyzer.discoverCode(),
|
|
256
|
+
moduleAnalyzer.discoverToolConfigs()
|
|
257
|
+
]);
|
|
258
|
+
const totalFiles = docs.length + code.length + tools.length;
|
|
259
|
+
if (totalFiles === 0) {
|
|
260
|
+
spinner.info(`Skipping ${module.name} (no files found)`);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
spinner.text = `Processing ${module.name}: ${totalFiles} files found...`;
|
|
264
|
+
// Apply per-module file limit
|
|
265
|
+
const limitedCode = code.slice(0, maxFilesPerModule);
|
|
266
|
+
// Split code into batches
|
|
267
|
+
const codeBatches = splitIntoBatches(limitedCode, batchSize);
|
|
268
|
+
// Index docs (no batching needed for docs usually)
|
|
269
|
+
let moduleDocsIndexed = 0;
|
|
270
|
+
for (const doc of docs) {
|
|
271
|
+
const content = fs.existsSync(doc.path)
|
|
272
|
+
? fs.readFileSync(doc.path, 'utf-8').slice(0, 50000)
|
|
273
|
+
: '';
|
|
274
|
+
if (content) {
|
|
275
|
+
db.upsertItem({
|
|
276
|
+
type: 'doc',
|
|
277
|
+
name: path.basename(doc.relativePath),
|
|
278
|
+
content,
|
|
279
|
+
filePath: doc.relativePath,
|
|
280
|
+
metadata: {
|
|
281
|
+
size: doc.size,
|
|
282
|
+
module: module.name
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
moduleDocsIndexed++;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
// Index tool configs
|
|
289
|
+
let moduleConfigsIndexed = 0;
|
|
290
|
+
for (const config of tools) {
|
|
291
|
+
const content = fs.existsSync(config.path)
|
|
292
|
+
? fs.readFileSync(config.path, 'utf-8').slice(0, 50000)
|
|
293
|
+
: '';
|
|
294
|
+
if (content) {
|
|
295
|
+
db.upsertItem({
|
|
296
|
+
type: 'tool_config',
|
|
297
|
+
name: `${config.tool}:${path.basename(config.relativePath)}`,
|
|
298
|
+
content,
|
|
299
|
+
filePath: config.relativePath,
|
|
300
|
+
metadata: {
|
|
301
|
+
tool: config.tool,
|
|
302
|
+
size: config.size,
|
|
303
|
+
module: module.name
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
moduleConfigsIndexed++;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
// Index code in batches
|
|
310
|
+
let moduleCodeIndexed = 0;
|
|
311
|
+
const allIndexedCodePaths = [];
|
|
312
|
+
for (let i = 0; i < codeBatches.length; i++) {
|
|
313
|
+
const batch = codeBatches[i];
|
|
314
|
+
spinner.text = `Processing ${module.name}: code batch ${i + 1}/${codeBatches.length} (${batch.length} files)...`;
|
|
315
|
+
for (const codeFile of batch) {
|
|
316
|
+
const content = fs.existsSync(codeFile.path)
|
|
317
|
+
? fs.readFileSync(codeFile.path, 'utf-8').slice(0, 20000)
|
|
318
|
+
: '';
|
|
319
|
+
if (content) {
|
|
320
|
+
const item = db.upsertItem({
|
|
321
|
+
type: 'code',
|
|
322
|
+
name: path.basename(codeFile.relativePath),
|
|
323
|
+
content,
|
|
324
|
+
filePath: codeFile.relativePath,
|
|
325
|
+
metadata: {
|
|
326
|
+
size: codeFile.size,
|
|
327
|
+
module: module.name
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
moduleCodeIndexed++;
|
|
331
|
+
allIndexedCodePaths.push(codeFile.relativePath);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (verbose) {
|
|
335
|
+
console.log(chalk.gray(` Batch ${i + 1}/${codeBatches.length}: ${batch.length} files indexed`));
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
// Generate embeddings for this module
|
|
339
|
+
let moduleEmbeddings = 0;
|
|
340
|
+
if (hasEmbeddings && allIndexedCodePaths.length > 0) {
|
|
341
|
+
moduleEmbeddings = await generateEmbeddingsBatch(db, allIndexedCodePaths, analyzer, spinner);
|
|
342
|
+
}
|
|
343
|
+
// Update stats
|
|
344
|
+
totalStats.modulesProcessed++;
|
|
345
|
+
totalStats.docsIndexed += moduleDocsIndexed;
|
|
346
|
+
totalStats.codeIndexed += moduleCodeIndexed;
|
|
347
|
+
totalStats.configsIndexed += moduleConfigsIndexed;
|
|
348
|
+
totalStats.embeddingsGenerated += moduleEmbeddings;
|
|
349
|
+
if (code.length > maxFilesPerModule) {
|
|
350
|
+
totalStats.filesSkipped += code.length - maxFilesPerModule;
|
|
351
|
+
}
|
|
352
|
+
spinner.succeed(`${module.name}: ${moduleDocsIndexed} docs, ${moduleCodeIndexed} code, ${moduleConfigsIndexed} configs` +
|
|
353
|
+
(moduleEmbeddings > 0 ? `, ${moduleEmbeddings} embeddings` : ''));
|
|
354
|
+
}
|
|
355
|
+
catch (error) {
|
|
356
|
+
spinner.fail(`${module.name} failed: ${error instanceof Error ? error.message : error}`);
|
|
357
|
+
// Continue with next module
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// Final summary
|
|
361
|
+
console.log();
|
|
362
|
+
console.log(chalk.bold('Batch Index Summary:'));
|
|
363
|
+
console.log(` ${chalk.cyan('•')} Modules Processed: ${totalStats.modulesProcessed}`);
|
|
364
|
+
console.log(` ${chalk.cyan('•')} Documentation Files: ${totalStats.docsIndexed}`);
|
|
365
|
+
console.log(` ${chalk.cyan('•')} Code Files: ${totalStats.codeIndexed}`);
|
|
366
|
+
console.log(` ${chalk.cyan('•')} Config Files: ${totalStats.configsIndexed}`);
|
|
367
|
+
console.log(` ${chalk.cyan('•')} Embeddings: ${totalStats.embeddingsGenerated}`);
|
|
368
|
+
if (totalStats.filesSkipped > 0) {
|
|
369
|
+
console.log(` ${chalk.yellow('•')} Files Skipped: ${totalStats.filesSkipped} (hit max-files limit)`);
|
|
370
|
+
console.log(chalk.gray(`\n Tip: Use --max-files <n> to increase the limit per module`));
|
|
371
|
+
}
|
|
372
|
+
const totalIndexed = totalStats.docsIndexed + totalStats.codeIndexed + totalStats.configsIndexed;
|
|
373
|
+
console.log(` ${chalk.bold.green('✓')} Total Indexed: ${totalIndexed} files`);
|
|
374
|
+
db.close();
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
if (spinner.isSpinning) {
|
|
378
|
+
spinner.fail('Batch indexing failed');
|
|
379
|
+
}
|
|
380
|
+
console.error(chalk.red(`\nError: ${error instanceof Error ? error.message : error}`));
|
|
381
|
+
if (db) {
|
|
382
|
+
db.close();
|
|
383
|
+
}
|
|
384
|
+
process.exit(1);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
//# sourceMappingURL=batch-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch-index.js","sourceRoot":"","sources":["../../../src/cli/commands/batch-index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAY,MAAM,KAAK,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,yBAAyB,EAAuB,MAAM,wCAAwC,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAuBpD;;GAEG;AACH,MAAM,eAAe,GAAqB;IACxC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,WAAW,EAAE,0BAA0B,EAAE;IACjF,EAAE,IAAI,EAAE,MAAM,EAA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wB,UAAU,CAAC,YAAY,wBAAwB,CAAC,CAAC;YAC3G,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,+DAA+D,CAAC,CAAC,CAAC;QAC3F,CAAC;QAED,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,GAAG,UAAU,CAAC,cAAc,CAAC;QACjG,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,YAAY,QAAQ,CAAC,CAAC;QAEpF,EAAE,CAAC,KAAK,EAAE,CAAC;IAEb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACvF,IAAI,EAAE,EAAE,CAAC;YACP,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC"}
|
package/dist/cli/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import { driftDetectCommand } from './commands/drift-detect.js';
|
|
|
25
25
|
import { crossSyncCommand } from './commands/cross-sync.js';
|
|
26
26
|
import { hooksCommand } from './commands/hooks.js';
|
|
27
27
|
import { factCheckCommand } from './commands/fact-check.js';
|
|
28
|
+
import { batchIndexCommand } from './commands/batch-index.js';
|
|
28
29
|
const __filename = fileURLToPath(import.meta.url);
|
|
29
30
|
const __dirname = path.dirname(__filename);
|
|
30
31
|
// Read package.json for version
|
|
@@ -57,6 +58,55 @@ function _parseAiTools(toolsString) {
|
|
|
57
58
|
const allTools = AI_TOOLS.filter(t => t !== 'all');
|
|
58
59
|
return tools.includes('all') ? allTools : tools;
|
|
59
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Configure MCP server for AI tools that support it
|
|
63
|
+
*
|
|
64
|
+
* Tools with native MCP support:
|
|
65
|
+
* - Claude Code (.claude/settings.json)
|
|
66
|
+
* - Cursor (.cursor/mcp.json or settings)
|
|
67
|
+
* - Continue (.continue/config.json)
|
|
68
|
+
*/
|
|
69
|
+
async function configureMcpServer(projectRoot) {
|
|
70
|
+
const fsPromises = fs.promises;
|
|
71
|
+
// Configure Claude Code MCP server
|
|
72
|
+
const claudeSettingsPath = path.join(projectRoot, '.claude', 'settings.json');
|
|
73
|
+
try {
|
|
74
|
+
let settings = {};
|
|
75
|
+
// Read existing settings if they exist
|
|
76
|
+
if (fs.existsSync(claudeSettingsPath)) {
|
|
77
|
+
const content = fs.readFileSync(claudeSettingsPath, 'utf-8');
|
|
78
|
+
try {
|
|
79
|
+
settings = JSON.parse(content);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// File exists but is invalid JSON, start fresh
|
|
83
|
+
settings = {};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Ensure mcpServers object exists
|
|
87
|
+
if (!settings.mcpServers) {
|
|
88
|
+
settings.mcpServers = {};
|
|
89
|
+
}
|
|
90
|
+
// Add k0ntext MCP server configuration
|
|
91
|
+
if (!settings.mcpServers.k0ntext) {
|
|
92
|
+
settings.mcpServers.k0ntext = {
|
|
93
|
+
command: 'npx',
|
|
94
|
+
args: ['k0ntext', 'mcp'],
|
|
95
|
+
env: {
|
|
96
|
+
K0NTEXT_PROJECT_ROOT: projectRoot
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// Ensure directory exists
|
|
101
|
+
await fsPromises.mkdir(path.dirname(claudeSettingsPath), { recursive: true });
|
|
102
|
+
// Write settings with proper formatting
|
|
103
|
+
await fsPromises.writeFile(claudeSettingsPath, JSON.stringify(settings, null, 2), 'utf-8');
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
// Log warning but don't fail the entire init process
|
|
107
|
+
console.warn(chalk.yellow(`\nWarning: Could not configure MCP server: ${error instanceof Error ? error.message : error}`));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
60
110
|
/**
|
|
61
111
|
* Create the CLI program
|
|
62
112
|
*/
|
|
@@ -116,6 +166,10 @@ function createProgram() {
|
|
|
116
166
|
}
|
|
117
167
|
}
|
|
118
168
|
console.log(`\n${chalk.green('✓')} AI Context initialized successfully!`);
|
|
169
|
+
// Configure MCP server for Claude Code and other tools
|
|
170
|
+
spinner.start('Configuring MCP server...');
|
|
171
|
+
await configureMcpServer(targetDir);
|
|
172
|
+
spinner.succeed('MCP server configured');
|
|
119
173
|
console.log(`\n${chalk.bold('Next Steps:')}`);
|
|
120
174
|
console.log(` ${chalk.cyan('1.')} Run ${chalk.white('k0ntext stats')} to view database statistics`);
|
|
121
175
|
console.log(` ${chalk.cyan('2.')} Run ${chalk.white('k0ntext mcp')} to start the MCP server`);
|
|
@@ -465,6 +519,17 @@ function createProgram() {
|
|
|
465
519
|
process.exit(1);
|
|
466
520
|
}
|
|
467
521
|
});
|
|
522
|
+
// ==================== Batch Index Command ====================
|
|
523
|
+
program
|
|
524
|
+
.command('index:batch')
|
|
525
|
+
.description('Index large monorepos by processing modules in batches')
|
|
526
|
+
.option('-b, --batch-size <n>', 'Files per batch', '100')
|
|
527
|
+
.option('-m, --max-files <n>', 'Maximum files per module', '500')
|
|
528
|
+
.option('--skip-embeddings', 'Skip generating embeddings')
|
|
529
|
+
.option('-v, --verbose', 'Show detailed output')
|
|
530
|
+
.action(async (options) => {
|
|
531
|
+
await batchIndexCommand(options);
|
|
532
|
+
});
|
|
468
533
|
return program;
|
|
469
534
|
}
|
|
470
535
|
// Main entry point
|