@nithin554/code-crawler 0.0.0 → 0.1.2

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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +221 -45
  3. package/dist/config.d.ts +13 -0
  4. package/dist/config.js +32 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/crawler.d.ts +46 -0
  7. package/dist/crawler.js +303 -0
  8. package/dist/crawler.js.map +1 -0
  9. package/dist/graph/queries.d.ts +111 -0
  10. package/dist/graph/queries.js +265 -0
  11. package/dist/graph/queries.js.map +1 -0
  12. package/dist/graph/schema.d.ts +63 -0
  13. package/dist/graph/schema.js +54 -0
  14. package/dist/graph/schema.js.map +1 -0
  15. package/dist/graph/store.d.ts +66 -0
  16. package/dist/graph/store.js +251 -0
  17. package/dist/graph/store.js.map +1 -0
  18. package/dist/index.d.ts +2 -0
  19. package/dist/index.js +133 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/parser/language.d.ts +111 -0
  22. package/dist/parser/language.js +13 -0
  23. package/dist/parser/language.js.map +1 -0
  24. package/dist/parser/languages/index.d.ts +5 -0
  25. package/dist/parser/languages/index.js +31 -0
  26. package/dist/parser/languages/index.js.map +1 -0
  27. package/dist/parser/languages/java.d.ts +10 -0
  28. package/dist/parser/languages/java.js +334 -0
  29. package/dist/parser/languages/java.js.map +1 -0
  30. package/dist/parser/treeSitter.d.ts +28 -0
  31. package/dist/parser/treeSitter.js +114 -0
  32. package/dist/parser/treeSitter.js.map +1 -0
  33. package/dist/resolver/javaResolver.d.ts +20 -0
  34. package/dist/resolver/javaResolver.js +253 -0
  35. package/dist/resolver/javaResolver.js.map +1 -0
  36. package/dist/resolver/types.d.ts +45 -0
  37. package/dist/resolver/types.js +80 -0
  38. package/dist/resolver/types.js.map +1 -0
  39. package/dist/server.d.ts +15 -0
  40. package/dist/server.js +282 -0
  41. package/dist/server.js.map +1 -0
  42. package/package.json +44 -7
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nithin
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 CHANGED
@@ -1,45 +1,221 @@
1
- # @nithin554/code-crawler
2
-
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@nithin554/code-crawler`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
1
+ # Code-Crawler
2
+
3
+ **Static call tracing MCP server backed by a persistent property graph of your codebase.**
4
+
5
+ Code-Crawler indexes a project into a SQLite-backed property graph — files, packages,
6
+ classes, methods, fields, imports, and **call edges** — then exposes that graph to LLM
7
+ clients as MCP tools: find callers, trace call paths, explore neighborhoods, and search
8
+ symbols across the whole codebase.
9
+
10
+ ```
11
+ ┌─────────────────────── MCP (stdio) ───────────────────────┐
12
+ │ crawl_project search_symbols get_callers get_callees │
13
+ │ trace_path get_subgraph get_node get_schema ... │
14
+ └───────────────┬──────────────────────────────┬───────────────┘
15
+ │ │
16
+ ┌──────▼───────┐ ┌────────▼────────┐
17
+ │ crawler │ │ graph queries │
18
+ │ parse+resolve│ │ recursive CTEs │
19
+ └──────┬───────┘ └────────┬────────┘
20
+ │ │
21
+ ┌──────▼──────────────────────────────▼──────┐
22
+ │ SQLite property graph (WAL) │
23
+ │ nodes (kind, fqn, props) + edges (kind) │
24
+ └─────────────────────────────────────────────┘
25
+ ```
26
+
27
+ ## Why a graph?
28
+
29
+ Plain-text grep can't answer questions like:
30
+
31
+ - *"Who transitively calls `OrderRepository#create`?"*
32
+ - *"Is there a static path from `Main#main` to `Tracking#dispatch`?"*
33
+ - *"What is the impact radius of changing `OrderService#place`?"*
34
+
35
+ These need graph traversal. Code-Crawler builds the graph once (idempotently, file-by-file)
36
+ and answers them instantly with bounded recursive SQL queries.
37
+
38
+ ## Features
39
+
40
+ - **Java-first** via the `tree-sitter-java` grammar (WASM — no native build step).
41
+ The parser/resolver layer is designed so more languages plug in per-language config modules.
42
+ - **Call resolution heuristics** that go beyond naive string matching:
43
+ receiver types inferred from locals, parameters, fields, `new T()` expressions,
44
+ bare/`this`/`super` calls, static/qualified calls, and superclass chains.
45
+ Unresolvable calls become `unknown_symbol` phantom nodes with `resolved:false` edges,
46
+ so the graph stays traversable.
47
+ - **Idempotent, file-scoped indexing** — re-crawling refreshes changed files and removes
48
+ stale ones without duplicating the graph.
49
+ - **Self-contained**: single SQLite file, no external services.
50
+ - **LLM-friendly**: every tool returns structured JSON, unknown symbols come back with
51
+ fuzzy search suggestions.
52
+
53
+ ## Install & build
54
+
55
+ Requires Node.js ≥ 20.
56
+
57
+ ```bash
58
+ npm install
59
+ npm run build # tsc → dist/
60
+ npm test # vitest (53 tests)
61
+ ```
62
+
63
+ ## CLI
64
+
65
+ ```bash
66
+ codecrawler crawl <path> # index a project
67
+ codecrawler status # index summary
68
+ codecrawler query <symbol> # fuzzy-lookup a symbol
69
+ codecrawler serve # start the MCP server over stdio (default)
70
+ ```
71
+
72
+ Environment variables:
73
+
74
+ | Variable | Default | Purpose |
75
+ | --- | --- | --- |
76
+ | `CODECRAWLER_DB` | `~/.code-crawler/index.db` | Database path |
77
+ | `CODECRAWLER_EXCLUDE_DIRS` | `.git,node_modules,dist,build,target,...` | Dirs skipped during crawl |
78
+ | `CODECRAWLER_DEFAULT_LIMIT` | `50` | Default result cap |
79
+ | `CODECRAWLER_MAX_DEPTH` | `10` | Traversal depth cap |
80
+
81
+ ## CI & publishing
82
+
83
+ GitHub Actions runs on every pull request (`pull-request.yml`): `npm ci` →
84
+ typecheck → tests → build → smoke-test of the built CLI.
85
+
86
+ Merges to `main` trigger `publish.yml`, which re-runs the same checks and then,
87
+ if green, **auto-releases**:
88
+
89
+ 1. Reads the most recent `v*` tag (or `package.json` version on the first run),
90
+ computes the next patch version, and pushes a `vX.Y.Z` tag.
91
+ 2. Creates a matching GitHub release.
92
+ 3. Publishes the package to the npm registry with **provenance** (OIDC
93
+ trusted publishing) — no token or repository secret is needed.
94
+
95
+ ## Using as an MCP server
96
+
97
+ ### Claude Desktop
98
+
99
+ `claude_desktop_config.json`:
100
+
101
+ ```json
102
+ {
103
+ "mcpServers": {
104
+ "code-crawler": {
105
+ "command": "node",
106
+ "args": ["/absolute/path/to/code-crawler/dist/index.js", "serve"],
107
+ "env": { "CODECRAWLER_DB": "/absolute/path/to/your/index.db" }
108
+ }
109
+ }
110
+ }
111
+ ```
112
+
113
+ ### Cursor / other stdio MCP clients
114
+
115
+ Point the client at the same command. The typical flow for an LLM agent:
116
+
117
+ 1. `crawl_project` the repo once.
118
+ 2. `search_symbols` to locate the symbol of interest.
119
+ 3. `get_callers` / `get_callees` / `trace_path` to reason about the call graph.
120
+
121
+ ## MCP surface
122
+
123
+ **Tools**
124
+
125
+ | Tool | Purpose |
126
+ | --- | --- |
127
+ | `crawl_project` | Index a directory (idempotent) |
128
+ | `index_status` | Node/edge/file counts + last crawl |
129
+ | `search_symbols` | Fuzzy lookup by name or FQN, optional kind filter |
130
+ | `get_node` | Metadata + source location for one symbol |
131
+ | `get_callers` | Direct or transitive callers (depth-bounded) |
132
+ | `get_callees` | Direct or transitive callees (depth-bounded) |
133
+ | `trace_path` | Static call paths between two symbols (BFS, shortest first) |
134
+ | `get_subgraph` | Neighborhood extraction for visualization |
135
+ | `get_schema` | Describe the graph model |
136
+ | `clear_index` | Reset the database |
137
+
138
+ **Resources**: `codecrawler://schema`, `codecrawler://status`
139
+ **Prompt**: `trace-call-path(from, to)`
140
+
141
+ ## Graph model
142
+
143
+ **Nodes** — `kind` is one of `file | package | class | interface | enum | method |
144
+ constructor | field | import | unknown_symbol`. Every node has a globally unique
145
+ `qualifiedName` and a JSON `properties` blob (signature, modifiers, lines, ...).
146
+
147
+ **Edges** — `kind` is one of `CALLS | DECLARED_IN | CONTAINS | IMPLEMENTS | EXTENDS |
148
+ IMPORTS | REFERENCES`. `CALLS` edges carry `line`, `resolved`, and `confidence`.
149
+
150
+ Id scheme:
151
+
152
+ | Symbol | Example |
153
+ | --- | --- |
154
+ | type | `com.acme.OrderService` |
155
+ | method | `com.acme.OrderService#place` |
156
+ | constructor | `com.acme.OrderService#<init>` |
157
+ | field | `com.acme.OrderService$repo` |
158
+ | import | `__import__:java.util.List` |
159
+ | unresolved call | `__unknown__:System.out.println` |
160
+
161
+ ## Java resolution heuristics
162
+
163
+ 1. **Constructor calls** (`new Foo(...)`) → resolve `Foo` → `#<init>` (default ctor if implicit).
164
+ 2. **Bare / `this.` / `super.` calls** → enclosing type + superclass chain.
165
+ 3. **Type-qualified calls** (`com.acme.Foo.bar`) → resolve the type directly.
166
+ 4. **Instance calls** (`x.method()`) → infer receiver type from locals → params → fields,
167
+ then search that type and its ancestors.
168
+ 5. **Otherwise** → phantom `unknown_symbol` node, `resolved:false`, with the inference
169
+ failure reason attached to the edge.
170
+
171
+ Each resolved edge carries a `confidence` score and a human-readable `reason` trace
172
+ (e.g. `via local orders: OrderService`), so LLM clients can weigh how much to trust it.
173
+
174
+ ## Roadmap: multi-language
175
+
176
+ The parsing layer is language-agnostic. Adding a language requires:
177
+
178
+ 1. `src/parser/languages/<lang>.ts` — a `LanguageConfig` implementing `parseFile`
179
+ (package/module extraction, type/member extraction, raw call sites, local type tables).
180
+ 2. Register it in `src/parser/languages/index.ts`.
181
+ 3. `src/resolver/<lang>Resolver.ts` — translate raw call sites into resolved targets
182
+ using the shared `TypeIndex`.
183
+
184
+ Natural next targets: **Python** (native AST or tree-sitter-python), **TypeScript/JavaScript**
185
+ (tree-sitter-typescript), and **Go** (tree-sitter-go). The graph schema, store, traversal
186
+ queries, and MCP surface all stay the same.
187
+
188
+ Planned enhancements:
189
+
190
+ - Package-level dependency graphs (module boundaries, cycle detection).
191
+ - Global call-graph analytics: hotspots (most-called methods), dead-code candidates
192
+ (methods with no incoming CALLS edges), fan-in/fan-out metrics.
193
+ - Test coverage mapping (which tests exercise a given symbol).
194
+ - Incremental crawling (watch mode) and git-blame aware invalidation.
195
+
196
+ ## Architecture
197
+
198
+ ```
199
+ src/
200
+ ├── index.ts CLI (crawl | status | query | serve)
201
+ ├── server.ts MCP server: tools, resources, prompt (thin handlers)
202
+ ├── crawler.ts file discovery → parse → index → resolve → persist
203
+ ├── config.ts env-overridable configuration
204
+ ├── graph/
205
+ │ ├── schema.ts node/edge kinds, id scheme, property shapes
206
+ │ ├── store.ts better-sqlite3 schema + idempotent file-scoped upserts
207
+ │ └── queries.ts recursive-CTE traversal (callers/callees/path/subgraph)
208
+ ├── parser/
209
+ │ ├── language.ts LanguageConfig contract
210
+ │ ├── treeSitter.ts WASM runtime + grammar loading + CST walk helpers
211
+ │ └── languages/
212
+ │ ├── index.ts language registry
213
+ │ └── java.ts Java structural extraction
214
+ └── resolver/
215
+ ├── types.ts TypeIndex (global name/method index) + ResolvedCall
216
+ └── javaResolver.ts Java call-target resolution heuristics
217
+ ```
218
+
219
+ ## License
220
+
221
+ MIT
@@ -0,0 +1,13 @@
1
+ export interface Config {
2
+ /** Path to the SQLite property-graph database. */
3
+ dbPath: string;
4
+ /** Directory names excluded during crawling. */
5
+ excludeDirs: string[];
6
+ /** Default number of results for list-returning tools. */
7
+ defaultLimit: number;
8
+ /** Cap on transitive traversal depth to keep queries bounded. */
9
+ maxDepth: number;
10
+ /** When true, errors include symbol-search suggestions. */
11
+ helpfulErrors: boolean;
12
+ }
13
+ export declare function loadConfig(): Config;
package/dist/config.js ADDED
@@ -0,0 +1,32 @@
1
+ import path from "node:path";
2
+ import os from "node:os";
3
+ /**
4
+ * Global configuration for code-crawler.
5
+ *
6
+ * All values can be overridden via environment variables so MCP clients can
7
+ * point the server at different databases without code changes.
8
+ */
9
+ const DEFAULT_DB_PATH = path.join(os.homedir(), ".code-crawler", "index.db");
10
+ function envStr(name, fallback) {
11
+ const v = process.env[name];
12
+ return v && v.length > 0 ? v : fallback;
13
+ }
14
+ function envBool(name, fallback) {
15
+ const v = process.env[name];
16
+ if (v === undefined)
17
+ return fallback;
18
+ return v === "1" || v.toLowerCase() === "true";
19
+ }
20
+ export function loadConfig() {
21
+ return {
22
+ dbPath: envStr("CODECRAWLER_DB", DEFAULT_DB_PATH),
23
+ excludeDirs: envStr("CODECRAWLER_EXCLUDE_DIRS", ".git,node_modules,dist,build,target,.idea,.venv,.gradle,out,.next,coverage")
24
+ .split(",")
25
+ .map((s) => s.trim())
26
+ .filter((s) => s.length > 0),
27
+ defaultLimit: Number(envStr("CODECRAWLER_DEFAULT_LIMIT", "50")),
28
+ maxDepth: Number(envStr("CODECRAWLER_MAX_DEPTH", "10")),
29
+ helpfulErrors: envBool("CODECRAWLER_HELPFUL_ERRORS", true),
30
+ };
31
+ }
32
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB;;;;;GAKG;AAEH,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC;AAE7E,SAAS,MAAM,CAAC,IAAY,EAAE,QAAgB;IAC5C,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC1C,CAAC;AAED,SAAS,OAAO,CAAC,IAAY,EAAE,QAAiB;IAC9C,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACrC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;AACjD,CAAC;AAeD,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,gBAAgB,EAAE,eAAe,CAAC;QACjD,WAAW,EAAE,MAAM,CACjB,0BAA0B,EAC1B,4EAA4E,CAC7E;aACE,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,2BAA2B,EAAE,IAAI,CAAC,CAAC;QAC/D,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC;QACvD,aAAa,EAAE,OAAO,CAAC,4BAA4B,EAAE,IAAI,CAAC;KAC3D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,46 @@
1
+ import type { GraphStore } from "./graph/store.js";
2
+ import type { GraphEdge, GraphNode } from "./graph/schema.js";
3
+ import type { ParsedFile } from "./parser/language.js";
4
+ import { buildTypeIndex } from "./resolver/types.js";
5
+ /**
6
+ * Project crawler: discover source files, parse them, build a global type
7
+ * index, resolve call targets, and persist an idempotent file-scoped graph.
8
+ */
9
+ export interface CrawlOptions {
10
+ /** Force a specific language regardless of extension. */
11
+ language?: string;
12
+ /** Optional include filter: path must contain this substring. */
13
+ fileFilter?: string;
14
+ }
15
+ export interface CrawlResult {
16
+ projectPath: string;
17
+ filesScanned: number;
18
+ filesParsed: number;
19
+ filesRemoved: number;
20
+ nodes: number;
21
+ edges: number;
22
+ resolvedCalls: number;
23
+ unresolvedCalls: number;
24
+ languages: string[];
25
+ durationMs: number;
26
+ }
27
+ /** Discover source files under a project, respecting exclusion dirs. */
28
+ export declare function discoverSourceFiles(projectPath: string, excludeDirs: string[], language?: string): string[];
29
+ /** Convert a ParsedFile into graph nodes + edges (declarations only). */
30
+ export declare function buildDeclarationGraph(parsed: ParsedFile): {
31
+ nodes: GraphNode[];
32
+ edges: GraphEdge[];
33
+ };
34
+ /** Resolve call sites for a parsed file into CALLS edges + phantom nodes. */
35
+ export declare function buildCallEdges(parsed: ParsedFile, index: ReturnType<typeof buildTypeIndex>, knownNodeIds: Set<string>): {
36
+ edges: GraphEdge[];
37
+ phantomNodes: GraphNode[];
38
+ resolved: number;
39
+ unresolved: number;
40
+ };
41
+ /**
42
+ * Crawl a project directory and index it into the store.
43
+ * Idempotent: re-crawling refreshes the graph; files that disappeared are
44
+ * removed from the index.
45
+ */
46
+ export declare function crawlProject(store: GraphStore, projectPath: string, excludeDirs: string[], options?: CrawlOptions): Promise<CrawlResult>;