@maxgfr/codeindex 2.15.0 → 2.17.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 +52 -4
- package/package.json +2 -2
- package/scripts/engine.d.mts +38 -3
- package/scripts/engine.mjs +332 -105
- package/src/ast/grammars-pull.ts +95 -1
- package/src/ast/warm.ts +74 -0
- package/src/engine-cli.ts +83 -85
- package/src/engine.ts +14 -1
- package/src/mcp.ts +34 -4
- package/src/rewrite.ts +169 -0
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ engine as a single file instead of taking an npm dependency.
|
|
|
17
17
|
and count caps (`capped` flag, never silent truncation), symlink-cycle guard.
|
|
18
18
|
- **Scan** every file into a `FileRecord`: classification, language, symbols,
|
|
19
19
|
imports, headings, hashes — with an incremental cache fastpath.
|
|
20
|
-
- **Extract symbols** via tree-sitter (
|
|
20
|
+
- **Extract symbols** via tree-sitter (13 languages, when the wasm sidecar is
|
|
21
21
|
present) or per-language regex rules (15 languages, always available).
|
|
22
22
|
- **Resolve imports** across languages: tsconfig paths, package `exports`,
|
|
23
23
|
go.mod, Cargo, Java packages, PSR-4, C# namespaces.
|
|
@@ -192,17 +192,65 @@ Full details incl. the HTTP protocol (build your own server):
|
|
|
192
192
|
|
|
193
193
|
## Use as an MCP server
|
|
194
194
|
|
|
195
|
-
`codeindex mcp` (or `node scripts/cli.mjs mcp`) serves the engine over stdio
|
|
196
|
-
|
|
197
|
-
`grep`. Register it in Claude Code with:
|
|
195
|
+
`codeindex mcp` (or `node scripts/cli.mjs mcp`) serves the engine over stdio.
|
|
196
|
+
Register it in Claude Code with:
|
|
198
197
|
|
|
199
198
|
```sh
|
|
200
199
|
claude mcp add codeindex -- codeindex mcp
|
|
201
200
|
```
|
|
202
201
|
|
|
202
|
+
**26 tools**, grouped by what they answer:
|
|
203
|
+
|
|
204
|
+
| group | tools |
|
|
205
|
+
|---|---|
|
|
206
|
+
| orient | `scan_summary`, `repo_map`, `graph`, `mermaid`, `workspaces` |
|
|
207
|
+
| find | `search`, `grep`, `find_symbol`, `symbols`, `symbols_overview` |
|
|
208
|
+
| impact | `find_references`, `callers`, `dead_code` |
|
|
209
|
+
| risk | `hotspots`, `churn`, `coupling`, `complexity`, `check_rules` |
|
|
210
|
+
| edit *(write)* | `replace_symbol_body`, `insert_after_symbol`, `insert_before_symbol` |
|
|
211
|
+
| memory | `write_memory`, `read_memory`, `list_memories`, `delete_memory` *(write except reads)* |
|
|
212
|
+
| embeddings | `embed_status` |
|
|
213
|
+
|
|
214
|
+
### Pinning the server to one repository
|
|
215
|
+
|
|
216
|
+
Every tool takes a `repo` argument. A host that runs one server per workspace
|
|
217
|
+
can pin it instead, so `repo` becomes optional on every tool — the pin is
|
|
218
|
+
reflected in the advertised schema, not merely tolerated at call time:
|
|
219
|
+
|
|
220
|
+
```sh
|
|
221
|
+
codeindex mcp --repo /path/to/workspace
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
An explicit per-call `repo` still wins, so a pinned server can still answer
|
|
225
|
+
about another checkout. `--server-name <name>` overrides the announced
|
|
226
|
+
`serverInfo.name` for hosts that embed the server under their own identity.
|
|
227
|
+
|
|
228
|
+
**Prime the index first** and activation becomes a load, not a rebuild:
|
|
229
|
+
`codeindex index --repo <dir> --out <dir>/.codeindex`. The first tool call
|
|
230
|
+
deserializes those artifacts when the engine version, commit and artifact
|
|
231
|
+
hashes all match.
|
|
232
|
+
|
|
203
233
|
`engine.mjs` is a pure side-effect-free library (safe for consumers to inline
|
|
204
234
|
into their own CLIs); `cli.mjs` is the thin standalone CLI/MCP wrapper.
|
|
205
235
|
|
|
236
|
+
## Command rewriting
|
|
237
|
+
|
|
238
|
+
`codeindex rewrite '<command line>'` maps an expensive tree-wide search onto
|
|
239
|
+
its indexed equivalent, for agent harnesses that intercept shell commands
|
|
240
|
+
(iterion's `rewriters` plugin kind, generalizing rtk):
|
|
241
|
+
|
|
242
|
+
```sh
|
|
243
|
+
$ codeindex rewrite 'grep -rn TODO src'
|
|
244
|
+
codeindex grep TODO --scope src
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
It prints the replacement and exits `0`, or exits `1` with empty stdout when it
|
|
248
|
+
has no opinion — run the original. The parser is deliberately conservative: any
|
|
249
|
+
shell metacharacter (pipe, redirect, substitution, chaining), any unrecognized
|
|
250
|
+
flag, a non-recursive `grep`, or more than one search path all refuse the
|
|
251
|
+
rewrite. A refusal costs nothing; a wrong rewrite silently changes what the
|
|
252
|
+
agent asked for.
|
|
253
|
+
|
|
206
254
|
## Versioning
|
|
207
255
|
|
|
208
256
|
- `ENGINE_VERSION` — the release tag, embedded greppably in the bundle.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maxgfr/codeindex",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "Self-contained, deterministic repo-indexing engine: walk + language detection + symbol/import extraction (tree-sitter AST with regex fallback) + import resolution + typed cross-file link-graph + analytics. Ships as a single zero-dependency engine.mjs that consumer tools vendor.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@10.33.0",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"tsup": "^8.3.0",
|
|
78
78
|
"typescript": "^5.5.0",
|
|
79
79
|
"vitest": "^4.1.0",
|
|
80
|
-
"web-tree-sitter": "^0.26.
|
|
80
|
+
"web-tree-sitter": "^0.26.11"
|
|
81
81
|
},
|
|
82
82
|
"pnpm": {
|
|
83
83
|
"onlyBuiltDependencies": [
|
package/scripts/engine.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const ENGINE_VERSION = "2.
|
|
1
|
+
declare const ENGINE_VERSION = "2.17.0";
|
|
2
2
|
declare const SCHEMA_VERSION = 4;
|
|
3
3
|
declare const EXTRACTOR_VERSION = 10;
|
|
4
4
|
type FileKind = "code" | "doc" | "config" | "asset" | "other";
|
|
@@ -255,7 +255,7 @@ declare function extractAst(rel: string, ext: string, content: string, opts?: {
|
|
|
255
255
|
maxCalls?: number;
|
|
256
256
|
}): AstResult | undefined;
|
|
257
257
|
|
|
258
|
-
declare const DEFAULT_GRAMMARS_URL = "https://github.com/maxgfr/codeindex/releases/download/v2.
|
|
258
|
+
declare const DEFAULT_GRAMMARS_URL = "https://github.com/maxgfr/codeindex/releases/download/v2.17.0/grammars-2.17.0.tar.gz";
|
|
259
259
|
interface GrammarsPullTarget {
|
|
260
260
|
url: string;
|
|
261
261
|
sha256Url?: string;
|
|
@@ -265,6 +265,38 @@ declare function fetchGrammarsTarball(url: string, expectedSha256?: string): Pro
|
|
|
265
265
|
declare function fetchExpectedSha256(url: string): Promise<string>;
|
|
266
266
|
declare function extractTarInto(rawTar: Uint8Array, destDir: string): string[];
|
|
267
267
|
declare function extractGrammarsTarball(bytes: Uint8Array, destDir: string): string[];
|
|
268
|
+
interface GrammarsPullResult {
|
|
269
|
+
ok: boolean;
|
|
270
|
+
status: "up-to-date" | "pulled" | "failed";
|
|
271
|
+
cacheDir: string;
|
|
272
|
+
/** One human-readable line; the CLI writes it to stderr, a library caller may log or drop it. */
|
|
273
|
+
message: string;
|
|
274
|
+
}
|
|
275
|
+
declare function pullGrammars(cacheDir: string, opts?: {
|
|
276
|
+
onNote?: (msg: string) => void;
|
|
277
|
+
}): Promise<GrammarsPullResult>;
|
|
278
|
+
|
|
279
|
+
interface WarmGrammarsResult {
|
|
280
|
+
/** Tier AFTER the warm-up (a successful pull moves "none" → "cache"). */
|
|
281
|
+
tier: GrammarsTierName;
|
|
282
|
+
/** True when at least one requested grammar is loaded ⇒ the AST tier is live. */
|
|
283
|
+
ready: boolean;
|
|
284
|
+
/** True when this call populated the shared cache over the network. */
|
|
285
|
+
pulled: boolean;
|
|
286
|
+
/** Everything written to `onNote`, in order — so a caller can persist the trail in its run artifacts. */
|
|
287
|
+
notes: string[];
|
|
288
|
+
}
|
|
289
|
+
interface WarmGrammarsOptions {
|
|
290
|
+
/** Grammars to load. Default: every shipped grammar. Narrow it with `grammarKeysForExts` when the repo's languages are known. */
|
|
291
|
+
keys?: Iterable<string>;
|
|
292
|
+
/** Fetch the wasms into the shared cache when nothing is resolvable. Default true; `CODEINDEX_NO_GRAMMARS_PULL=1` forces false. */
|
|
293
|
+
pull?: boolean;
|
|
294
|
+
/** Prefix for the diagnostics ("ultrasec: …"). Default "codeindex". */
|
|
295
|
+
label?: string;
|
|
296
|
+
/** Where diagnostics go. Default: process.stderr. Pass a sink to keep stdout/stderr clean. */
|
|
297
|
+
onNote?: (msg: string) => void;
|
|
298
|
+
}
|
|
299
|
+
declare function warmGrammars(opts?: WarmGrammarsOptions): Promise<WarmGrammarsResult>;
|
|
268
300
|
|
|
269
301
|
type Resolution = {
|
|
270
302
|
kind: "resolved";
|
|
@@ -713,9 +745,12 @@ interface McpServerOptions {
|
|
|
713
745
|
name?: string;
|
|
714
746
|
version?: string;
|
|
715
747
|
};
|
|
748
|
+
defaultRepo?: string;
|
|
716
749
|
}
|
|
717
750
|
declare function runMcpServer(opts?: McpServerOptions): Promise<void>;
|
|
718
751
|
|
|
752
|
+
declare function rewriteCommand(cmd: string, bin?: string): string | undefined;
|
|
753
|
+
|
|
719
754
|
declare function sha1(s: string | Uint8Array): string;
|
|
720
755
|
declare function shortHash(s: string, n?: number): string;
|
|
721
756
|
|
|
@@ -747,4 +782,4 @@ declare function rrf<T>(lists: T[][], keyOf: (item: T) => string, k?: number): M
|
|
|
747
782
|
|
|
748
783
|
declare function runCli(argv: string[]): Promise<void>;
|
|
749
784
|
|
|
750
|
-
export { type ArchRule, type BuildIndexOptions, type BuiltinRule, type CallerEntry, type CallerIndex, type CallerIndexOptions, type CallerSite, type ChangeCoupling, type CodeInfo, type CodeSymbol, type CouplingOptions, DEFAULT_GRAMMARS_URL, DEFAULT_MAX_FILES, type DeadSymbol, type DiffFile, type DiffSpec, EMBED_VERSION, ENGINE_VERSION, EXTRACTOR_VERSION, type Edge, type EdgeKind, type EditResult, type EmbedEndpointOptions, type EmbedPullTarget, type EmbeddingIndex, type EmbeddingRecord, type EmbeddingUnit, type FileCategory, type FileKind, type FileNode, type FileRecord, type FindSymbolOptions, type ForbiddenEdgeRule, type GrammarsPullTarget, type GrammarsTier, type GrammarsTierName, type Graph, type GrepOptions, type Hotspot, type Hunk, type IgnoreRule, type IndexArtifacts, MARKDOWN_EXT, type MarkdownInfo, type McpServerOptions, type MermaidOptions, type ModuleInfo, type ModuleNode, type RawCallerIndex, type RawCallerSite, type RawRef, type RenderScipOptions, type RepoMapOptions, type RepoScan, type Resolution, type ResolveContext, type RiskHotspot, type RuleSeverity, type RuleViolation, SCHEMA_VERSION, type ScanOptions, type SearchHit, type SearchOptions, type SearchResult, type SemanticSearchOptions, type SemanticSearchResult, type ShResult, type StaticEmbedModel, type SurpriseEdge, type SymbolComplexity, type SymbolIndex, type SymbolMatch, type SymbolReferences, type TestMap, type Tier, type WalkOptions, type WalkResult, type WalkedFile, type WorkspaceInfo, type WorkspaceKind, type WorkspacePackage, allGrammarKeys, applyCentrality, basicTokenize, betweennessOf, buildArtifactsFromScan, buildCallerIndex, buildEmbeddingIndex, buildEndpointIndex, buildGraph, buildIndexArtifacts, buildModules, buildRawCallerIndex, buildResolveContext, buildSymbolIndex, byKey, byStr, categorize, changeCoupling, changedSince, checkRules, classify, clip, clipInline, communityOf, compileGlobs, complexityOfSource, computeImportPairs, computeSurprises, computeSymbolRefs, computeTestMap, deleteMemory, deserializeEmbeddings, detectCommunities, detectWorkspaces, diffFiles, diffHunks, embedEndpointUrl, embedViaEndpoint, embeddingUnits, enclosingSymbol, encode, encodeQueryViaEndpoint, ensureGrammars, escapeRegExp, extToLang, extractAst, extractCode, extractGrammarsTarball, extractMarkdown, extractSymbols, extractTarInto, fetchExpectedSha256, fetchGrammarsTarball, findDeadCode, findReferences, findSymbol, foldText, gitChurn, grammarKeyForExt, grammarKeysForExts, grammarReady, grepRepo, hasEmbedModel, have, headCommit, healthzUrl, insertAfterSymbol, insertBeforeSymbol, intDot, isCode, isDoc, isGitWorktree, isIgnored, isSurprising, isTestFile, isTestPath, keywords, languageOf, listMemories, loadEmbedModel, pagerankOf, parseGitignore, parseRules, probeEndpoint, quantize, rankHotspots, rankedKeywords, readMemory, readText, renderGraphJson, renderMermaid, renderRepoMap, renderScip, renderSymbolsJson, replaceSymbolBody, resolveBaseRef, resolveCallEdges, resolveDocLink, resolveEmbedEndpoint, resolveEmbedModelDir, resolveEmbedPullUrl, resolveGrammarsDir, resolveGrammarsPullTarget, resolveGrammarsTier, resolveImport, resolveUniqueSymbol, riskHotspots, roundHalfToEven, rrf, runCli, runMcpServer, scanRepo, searchIndex, searchSemantic, serializeEmbeddings, sh, sha1, sharedGrammarsCacheDir, shortHash, slugify, subtokens, symbolComplexity, symbolsOverview, testsForModule, tierForPath, tokenize, uniqueSymbolDefs, untestedModules, untrackedFiles, walk, wordpiece, writeMemory };
|
|
785
|
+
export { type ArchRule, type BuildIndexOptions, type BuiltinRule, type CallerEntry, type CallerIndex, type CallerIndexOptions, type CallerSite, type ChangeCoupling, type CodeInfo, type CodeSymbol, type CouplingOptions, DEFAULT_GRAMMARS_URL, DEFAULT_MAX_FILES, type DeadSymbol, type DiffFile, type DiffSpec, EMBED_VERSION, ENGINE_VERSION, EXTRACTOR_VERSION, type Edge, type EdgeKind, type EditResult, type EmbedEndpointOptions, type EmbedPullTarget, type EmbeddingIndex, type EmbeddingRecord, type EmbeddingUnit, type FileCategory, type FileKind, type FileNode, type FileRecord, type FindSymbolOptions, type ForbiddenEdgeRule, type GrammarsPullResult, type GrammarsPullTarget, type GrammarsTier, type GrammarsTierName, type Graph, type GrepOptions, type Hotspot, type Hunk, type IgnoreRule, type IndexArtifacts, MARKDOWN_EXT, type MarkdownInfo, type McpServerOptions, type MermaidOptions, type ModuleInfo, type ModuleNode, type RawCallerIndex, type RawCallerSite, type RawRef, type RenderScipOptions, type RepoMapOptions, type RepoScan, type Resolution, type ResolveContext, type RiskHotspot, type RuleSeverity, type RuleViolation, SCHEMA_VERSION, type ScanOptions, type SearchHit, type SearchOptions, type SearchResult, type SemanticSearchOptions, type SemanticSearchResult, type ShResult, type StaticEmbedModel, type SurpriseEdge, type SymbolComplexity, type SymbolIndex, type SymbolMatch, type SymbolReferences, type TestMap, type Tier, type WalkOptions, type WalkResult, type WalkedFile, type WarmGrammarsOptions, type WarmGrammarsResult, type WorkspaceInfo, type WorkspaceKind, type WorkspacePackage, allGrammarKeys, applyCentrality, basicTokenize, betweennessOf, buildArtifactsFromScan, buildCallerIndex, buildEmbeddingIndex, buildEndpointIndex, buildGraph, buildIndexArtifacts, buildModules, buildRawCallerIndex, buildResolveContext, buildSymbolIndex, byKey, byStr, categorize, changeCoupling, changedSince, checkRules, classify, clip, clipInline, communityOf, compileGlobs, complexityOfSource, computeImportPairs, computeSurprises, computeSymbolRefs, computeTestMap, deleteMemory, deserializeEmbeddings, detectCommunities, detectWorkspaces, diffFiles, diffHunks, embedEndpointUrl, embedViaEndpoint, embeddingUnits, enclosingSymbol, encode, encodeQueryViaEndpoint, ensureGrammars, escapeRegExp, extToLang, extractAst, extractCode, extractGrammarsTarball, extractMarkdown, extractSymbols, extractTarInto, fetchExpectedSha256, fetchGrammarsTarball, findDeadCode, findReferences, findSymbol, foldText, gitChurn, grammarKeyForExt, grammarKeysForExts, grammarReady, grepRepo, hasEmbedModel, have, headCommit, healthzUrl, insertAfterSymbol, insertBeforeSymbol, intDot, isCode, isDoc, isGitWorktree, isIgnored, isSurprising, isTestFile, isTestPath, keywords, languageOf, listMemories, loadEmbedModel, pagerankOf, parseGitignore, parseRules, probeEndpoint, pullGrammars, quantize, rankHotspots, rankedKeywords, readMemory, readText, renderGraphJson, renderMermaid, renderRepoMap, renderScip, renderSymbolsJson, replaceSymbolBody, resolveBaseRef, resolveCallEdges, resolveDocLink, resolveEmbedEndpoint, resolveEmbedModelDir, resolveEmbedPullUrl, resolveGrammarsDir, resolveGrammarsPullTarget, resolveGrammarsTier, resolveImport, resolveUniqueSymbol, rewriteCommand, riskHotspots, roundHalfToEven, rrf, runCli, runMcpServer, scanRepo, searchIndex, searchSemantic, serializeEmbeddings, sh, sha1, sharedGrammarsCacheDir, shortHash, slugify, subtokens, symbolComplexity, symbolsOverview, testsForModule, tierForPath, tokenize, uniqueSymbolDefs, untestedModules, untrackedFiles, walk, warmGrammars, wordpiece, writeMemory };
|