Project Structure
ContextWeaver source code lives in src/, and tests live in tests/.
src/
├── index.ts
├── config.ts
├── defaultEnv.ts
├── api/
├── chunking/
├── cli/
├── db/
├── indexer/
├── mcp/
├── scanner/
├── search/
├── stats/
├── utils/
└── vectorStore/Top-level entrypoints
| File | Description |
|---|---|
src/index.ts | CLI entrypoint and command registration |
src/config.ts | Environment variables, API config, ignore rules |
src/defaultEnv.ts | Default .env template generated by contextweaver init |
api
src/api/
├── embedding.ts
└── reranker.tsWraps external model APIs. This layer handles request shape, error responses, retries, and compatibility with different provider response formats.
scanner
src/scanner/
├── crawler.ts
├── filter.ts
├── hash.ts
├── index.ts
├── language.ts
├── processor.ts
└── watcher.tsFinds files, filters them, reads content, detects language, computes hashes, and coordinates watch-mode incremental scans.
chunking
src/chunking/
├── LanguageSpec.ts
├── ParserPool.ts
├── SemanticSplitter.ts
├── SourceAdapter.ts
└── types.tsHandles Tree-sitter AST chunking, language specifications, parser reuse, and offset normalization.
indexer / db / vectorStore
src/indexer/index.ts
src/db/index.ts
src/db/bootstrap.ts
src/vectorStore/index.tsThis is the indexing write core:
indexerorchestrates embeddings and cross-store writesdbmanages SQLite schema, FTS, metadata, stats, and pending marksbootstraphandles migrations and pending mark replayvectorStorewraps pure LanceDB vector operations
search
src/search/
├── SearchService.ts
├── GraphExpander.ts
├── ContextPacker.ts
├── ChunkContentLoader.ts
├── QueryCache.ts
├── fts.ts
├── config.ts
├── loadConfig.ts
├── resolvers/
└── types.tsThe search layer includes hybrid recall, RRF, rerank, Smart TopK, context expansion, and token-aware packing.
mcp
src/mcp/
├── server.ts
├── main.ts
└── tools/MCP tools are implemented in src/mcp/tools/. Each tool usually has an independent handler so CLI mirrors can reuse the same logic.
tests
tests/
├── chunking/
├── cli/
├── db/
├── indexer/
├── integration/
├── mcp/
├── scanner/
├── search/
├── stats/
└── vectorStore/The test tree mirrors the source modules. Add new tests under the module-specific directory whenever possible.