{"_id":"@aiderdesk/tree-sitter-utils","name":"@aiderdesk/tree-sitter-utils","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@aiderdesk/tree-sitter-utils","version":"0.1.0","description":"Tree-sitter utilities for code analysis, symbol extraction, and repository mapping","author":{"name":"Hotovo"},"homepage":"https://aiderdesk.hotovo.com","repository":{"type":"git","url":"git+https://github.com/hotovo/aider-desk.git","directory":"packages/tree-sitter-utils"},"bugs":{"url":"https://github.com/hotovo/aider-desk/issues"},"license":"MIT","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"scripts":{"build":"tsc --emitDeclarationOnly --declaration && esbuild src/index.ts --bundle --platform=node --packages=external --format=cjs --outfile=dist/index.js --sourcemap","build:check":"tsc --noEmit","typecheck":"tsc --noEmit","prepublishOnly":"npm run build"},"keywords":["tree-sitter","code-analysis","symbol-extraction","repository-map","pagerank","ast","parsing"],"dependencies":{"glob":"^13.0.6","graphology":"^0.26.0","graphology-metrics":"^2.4.0","simple-git":"^3.32.3","web-tree-sitter":"^0.26.6"},"devDependencies":{"@types/node":"^22.13.4","esbuild":"^0.25.0","typescript":"^5.5.4"},"engines":{"node":">=18.0.0"},"publishConfig":{"access":"public"},"_id":"@aiderdesk/tree-sitter-utils@0.1.0","gitHead":"884fe00931e57b88cacd4a5b0e9eab6536412bf2","_nodeVersion":"22.17.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-Vr44kjBiWT+UoWmmwkMlXjcFKrUouOk/HuI4X2hwaZpsYVhOO426aRG2nLby0xFMedCZk4nev1A8zHCkJX4l+A==","shasum":"8a4b6de31cd9a36ac493917d31e54b2b1b0df59c","tarball":"https://registry.npmjs.org/@aiderdesk/tree-sitter-utils/-/tree-sitter-utils-0.1.0.tgz","fileCount":59,"unpackedSize":150579,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIB83ySxAPM0/S3okJ4jBsduCxUDY1RDAgkTLUKKpJFAgAiB7Mn/mgUpOZdXU4+1QQV2S2lRC5CTylu3jgs7OGYS58w=="}]},"_npmUser":{"name":"wladimiiir","email":"wladimiiir@gmail.com"},"directories":{},"maintainers":[{"name":"wladimiiir","email":"wladimiiir@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/tree-sitter-utils_0.1.0_1772648591358_0.8080406449955211"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-04T18:23:11.253Z","0.1.0":"2026-03-04T18:23:11.545Z","modified":"2026-03-04T18:23:12.033Z"},"maintainers":[{"name":"wladimiiir","email":"wladimiiir@gmail.com"}],"description":"Tree-sitter utilities for code analysis, symbol extraction, and repository mapping","homepage":"https://aiderdesk.hotovo.com","keywords":["tree-sitter","code-analysis","symbol-extraction","repository-map","pagerank","ast","parsing"],"repository":{"type":"git","url":"git+https://github.com/hotovo/aider-desk.git","directory":"packages/tree-sitter-utils"},"author":{"name":"Hotovo"},"bugs":{"url":"https://github.com/hotovo/aider-desk/issues"},"license":"MIT","readme":"# @aiderdesk/tree-sitter-utils\n\nA comprehensive tree-sitter library for code analysis, symbol extraction, and repository mapping.\n\n## Features\n\n- 🌳 **Tree-Sitter Based**: Uses tree-sitter for accurate AST parsing\n- 📦 **On-Demand WASM Loading**: Automatically downloads language WASM files when needed\n- 🔍 **Symbol Extraction**: Extract functions, classes, variables, and other symbols from code\n- 🗺️ **Repository Mapping**: Generate comprehensive repository maps with PageRank-based symbol ranking\n- 💾 **Smart Caching**: SQLite-based caching for fast repeated analysis\n- 🌐 **Multi-Language Support**: Supports 18+ programming languages out of the box\n\n## Installation\n\n```bash\nnpm install @aiderdesk/tree-sitter-utils\n```\n\n## Quick Start\n\n### Extract Symbols from Files\n\n```typescript\nimport { extractSymbols } from '@aiderdesk/tree-sitter-utils';\n\nconst symbols = await extractSymbols([\n  '/path/to/file.ts',\n  '/path/to/another-file.py'\n]);\n\nconsole.log(symbols);\n// [\n//   { name: 'MyClass', kind: 'def', line: 10, rel_fname: 'file.ts', ... },\n//   { name: 'myFunction', kind: 'def', line: 25, rel_fname: 'file.ts', ... }\n// ]\n```\n\n### Generate Repository Map\n\n```typescript\nimport { getRepoMap } from '@aiderdesk/tree-sitter-utils';\n\nconst map = await getRepoMap('/path/to/project', {\n  maxLines: 1000,\n  excludePatterns: ['node_modules/**', 'dist/**']\n});\n\nconsole.log(map);\n// src/index.ts:\n// ├── class MyClass\n// ├── function myFunction\n// ...\n```\n\n### Advanced Usage with TreeSitterAnalyzer\n\n```typescript\nimport { TreeSitterAnalyzer } from '@aiderdesk/tree-sitter-utils';\n\nconst analyzer = new TreeSitterAnalyzer();\n\n// Initialize (optional - lazy initialization supported)\nawait analyzer.initialize();\n\n// Get repository map\nconst repoMap = await analyzer.getRepoMap('/path/to/project', {\n  maxLines: 500,\n  mentionedFiles: new Set(['src/important.ts']),\n  mentionedIdents: new Set(['ImportantClass'])\n});\n\n// Extract symbols\nconst symbols = await analyzer.extractSymbols(['/path/to/file.ts'], {\n  useCache: true\n});\n\n// Parse single file\nconst parseResult = await analyzer.parseFile('/path/to/file.ts');\n```\n\n## Supported Languages\n\n- Python\n- JavaScript / JSX\n- TypeScript / TSX\n- Java\n- Go\n- Rust\n- C / C++\n- C#\n- Ruby\n- PHP\n- Scala\n- Dart\n- OCaml / OCaml Interface\n- Haskell\n- Julia\n\n## Configuration Options\n\n### RepoMapOptions\n\n```typescript\ninterface RepoMapOptions {\n  root: string;                    // Root directory of the project\n  files?: string[];                // Specific files to analyze (optional)\n  excludePatterns?: string[];      // Glob patterns to exclude\n  mentionedFiles?: Set<string>;    // Files to prioritize in ranking\n  mentionedIdents?: Set<string>;   // Identifiers to prioritize\n  chatFiles?: Set<string>;         // Files to exclude from output\n  maxLines?: number;               // Maximum lines in output\n}\n```\n\n### SymbolOptions\n\n```typescript\ninterface SymbolOptions {\n  useCache?: boolean;              // Use SQLite cache (default: true)\n  rootDir?: string;                // Root directory for relative paths\n}\n```\n\n## How It Works\n\n1. **On-Demand WASM Loading**: When a language is first encountered, the library automatically downloads its WASM file from unpkg and caches it in `~/.cache/aiderdesk/tree-sitter/wasm/`\n\n2. **Tree-Sitter Parsing**: Uses tree-sitter queries (`.scm` files) to extract definitions and references from source code\n\n3. **PageRank Algorithm**: Builds a dependency graph and applies PageRank to rank symbols by importance\n\n4. **Smart Caching**: SQLite-based caching tracks file modification times to avoid re-parsing unchanged files\n\n## API Reference\n\n### Convenience Functions\n\n- `extractSymbols(filePaths: string[], options?: SymbolOptions): Promise<Symbol[]>`\n- `getRepoMap(root: string, options?: RepoMapOptions): Promise<string>`\n\n### TreeSitterAnalyzer Class\n\n- `initialize(): Promise<void>` - Initialize the analyzer\n- `getRepoMap(options: RepoMapOptions): Promise<string>` - Generate repository map\n- `extractSymbols(filePaths: string[], options?: SymbolOptions): Promise<Symbol[]>` - Extract symbols\n- `parseFile(filePath: string): Promise<ParseResult>` - Parse single file\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-476a89fbb90e2399a0e703c1ece79814"}