Co-do can build an opt-in, on-device search index of the folder you have opened, so both you (Ctrl/⌘+K) and the agent (search_folder_semantic) can find code and documents by meaning and keywords.
- Off by default. Nothing is indexed until you press Ctrl/⌘+K → Enable local index.
- Never uploaded. Chunking, embedding and querying all happen in the page. The index lives in IndexedDB (
co-do-db→folder-indexstore) on this device, scoped per workspace. - No model download. The default embedding is a deterministic hashed TF + character-trigram vector (512 dims), so it works offline straight away.
- Permission-gated for the agent.
search_folder_semanticgoes through the normal tool permission system (default Ask Each Time, under Tool Permissions → Local Search). Only the returned snippets (paths, line ranges and up to ~300 characters per hit) are shared with your AI provider, the same asgreporcatoutput. - Deletable. Delete index & disable removes every stored chunk for the current folder and switches the feature off.
flowchart LR
Files["Opened folder<br/>(File System Access)"] --> Filter["Filter<br/>skip node_modules, .git, dist,<br/>binaries, lockfiles, >256 KB"]
Filter --> Chunk["40-line chunks<br/>10-line overlap"]
Chunk --> Embed["EmbeddingProvider<br/>(local TF + trigram)"]
Embed --> Store[("VectorDB<br/>IndexedDB folder-index")]
Query["Query"] --> QEmbed["Embed query"] --> Store
Store --> Rerank["Hybrid rerank<br/>0.65 cosine + 0.35 keyword<br/>max 2 hits per file"]
Rerank --> Hits["path · lines · snippet · score"]
- Incremental refresh. Each chunk records its file's
size:lastModifiedsignature and the embedding provider id. Rebuilds only re-read changed files, drop deleted ones, and re-embed everything if the provider changes. The agent tool refreshes the index automatically at most every 30 s. - Tokenisation splits on punctuation and camelCase/PascalCase boundaries, so
saveApiKeymatches "api key". - Ranking combines cosine similarity (which captures sub-word overlap through trigrams) with the fraction of query terms found in the chunk or its path.
| Module | Purpose |
|---|---|
src/folder-search/embedding.ts |
EmbeddingProvider interface, tokenizer, LocalHashedEmbeddingProvider, cosine helpers |
src/folder-search/vector-store.ts |
VectorDB with an idb-vector-style contract (insert / update / delete / query(vector, { limit }) → { object, key, similarity }) and pluggable backends |
src/folder-search/folder-index.ts |
Chunking, filtering, incremental build(), hybrid search() (environment-agnostic, unit-tested) |
src/folder-search/service.ts |
Browser glue: File System Access source, IndexedDB backend, opt-in flag, workspace scoping |
src/folder-search-ui.ts |
Ctrl/⌘+K panel (combobox + listbox, arrow-key navigation, DOM/textContent rendering) |
src/tools.ts → search_folder_semantic |
Agent tool |
folderSearchService.setEmbeddingProvider(provider) accepts anything implementing:
interface EmbeddingProvider {
readonly id: string; // persisted; changing it triggers a re-embed
readonly dimensions: number;
embed(texts: string[]): Promise<Float32Array[]>;
}For example a WebGPU/WASM sentence-transformer or a browser built-in AI embedding API. The index, ranking, storage and tool stay unchanged.
Co-do ships a small (~150-line) store that matches the
idb-vectorcontract instead of adding a dependency. Swapping in the package later only means implementingVectorBackendon top of it.