tscodesearch / vscode-codesearch
AGENTS.md5 starsChanged 7 months agoMITView on GitHub
VS Code extension that provides a real-time search panel backed by the local Tantivy index managed by the codesearch/ daemon. As the user types, it issues queries against the daemon's HTTP API and renders results with file metadata, highlights, and one-click file opening. The split between client.ts and extension.ts is intentional: client.ts imports nothing from vscode, so it can be unit-tested with plain Node.js. Defined in client.ts MODES array. Each entry has key, label, queryBy, weights, desc, and optionally astMode/uses_kind.…
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository2 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 95
All error notifications include an Open Settings button.
- Very specific: line 124
After install, reload the VS Code window.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
vscode-codesearch -- developer notes
VS Code extension that provides a real-time search panel backed by the local
Tantivy index managed by the codesearch/ daemon. As the user types, it
issues queries against the daemon's HTTP API and renders results with file
metadata, highlights, and one-click file opening.
Architecture
----------------------------------------------------------
WEBVIEW (HTML + inline JS, runs in isolated iframe)
search input | mode selector | filters | results list
communicates via postMessage
----------------------------------------------------------
| vscode.postMessage / onDidReceiveMessage
----------------------------------------------------------
EXTENSION HOST (Node.js, src/extension.ts)
command registration | panel lifecycle
config discovery | message routing
| imports
src/client.ts (pure logic, no vscode dependency)
----------------------------------------------------------
| HTTP localhost:{port}
codesearch daemon (indexserver/daemon.py)
(in-process Tantivy backend per root)The split between client.ts and extension.ts is intentional: client.ts
imports nothing from vscode, so it can be unit-tested with plain Node.js.
Module map
| File | Responsibility |
src/client.ts | All VS Code-free logic. MODES constant, CodesearchConfig type, loadConfig, getRoots, sanitizeName, collectionForRoot, doQueryCodebase, doQuerySingleFile, runSearchPipeline, renderTextTree, resolveFilePath. Exported for tests. |
src/server.ts | ServerManager -- daemon lifecycle wrapper. Spawns node ts.mjs for start/stop/restart, manages roots in config.json. |
src/extension.ts | VS Code wiring only. Config discovery, view and command registration, and activate / deactivate. |
src/status.ts | Status bar item. Polls the daemon's /status and /verify/status every 5 s and renders state. |
src/treeview.ts | "Roots" tree view in the activity bar. |
src/watcher.ts | Thin HTTP helper used by the status bar. |
src/test/client.test.ts | ~65 unit tests. No daemon required. Covers config parsing, root/collection resolution, every search mode, path resolution, HTTP behaviour against a mock server. |
src/test/pipeline.test.ts | Pipeline integration tests. Skip when daemon is not running. |
src/test/status.test.ts | Status-bar formatting tests. |
package.json | Extension manifest. Registers codesearch.openPanel (Ctrl+Shift+F1), settings, build/test scripts. |
tsconfig.json | CommonJS target, esModuleInterop: true, strict. Output to out/. |
.vscodeignore | Excludes src/, node_modules/, maps from the packaged VSIX. |
.vscode/launch.json | F5 launches the Extension Development Host with this folder loaded. |
.vscode/tasks.json | Default build task runs npm run compile; background task runs npm run watch. |
Search modes
Defined in client.ts MODES array. Each entry has key, label, queryBy, weights, desc, and optionally astMode/uses_kind. The daemon's /query-codebase does an index pre-filter (Tantivy) followed by tree-sitter AST post-processing for line-level matches.
The queryBy/weights fields on MODES are not sent to the daemon -- /query-codebase resolves them server-side from astMode + uses_kind (see _resolve_query_params in indexserver/daemon.py). They survive on the client only as labels for the panel UI and may go away in a future cleanup. The intent column below describes what the user sees; the actual field set queried is determined by the server.
Mode names are canonical and match the MCP query_codebase modes. The
text entry (which used to send the unrecognized mode text to the daemon
and silently fail) has been removed; use all_refs for broad identifier
search.
| Key | astMode sent to daemon | uses_kind | Intent |
declarations | declarations | -- | Method/type signature search [T1] |
implements | implements | -- | Interface implementors [T1] |
calls | calls | -- | Call sites of a method [T1] |
uses | uses | -- | Type reference search (default type_refs,cast_types) [T2] |
casts | casts | -- | Explicit (T)expr / as T cast sites [T1] |
attrs | attrs | -- | [Attribute] / @decorator / #[attribute] [T1] |
all_refs | all_refs | -- | All identifier occurrences -- broadest |
accesses_on | accesses_on | -- | .Member accesses on instances of a type |
uses_field | uses | field | Fields/properties declared as a given type |
uses_param | uses | param | Method/ctor parameters typed as a given type |
The server-side field-set mapping (one source of truth) lives in indexserver.daemon._resolve_query_params; see ../AGENTS.md for the full mode -> query-by table.
Config
The extension reads tscodesearch/config.json -- the same file used by the daemon.
{
"api_key": "codesearch-local",
"port": 8108,
"roots": { "default": { "path": "C:/myproject/src" } }
}Discovery order:
- VS Code setting
tscodesearch.repoPath(must point to the tscodesearch repository root) - Auto-detect: looks for
config.jsonin each workspace folder and validates that it containsapi_key
findConfigPath() in extension.ts resolves config.json beneath the discovered repository root and validates its JSON.
All error notifications include an Open Settings button.
Build
cd vscode-codesearch
npm install # first time only
npm run compile # one-shot build -> out/
npm run watch # incremental rebuild on save
npm test # all tests (skip pipeline if daemon not up)The out/ directory must exist before VS Code loads the extension. If you see "command 'codesearch.openPanel' not found", run npm run compile and reload the window.
Install / run
Development (F5):
Open vscode-codesearch/ as a VS Code workspace, press F5. A new Extension Development Host opens with the extension loaded.
Install from folder (no packaging):
F1 -> Developer: Install Extension from Location... -> select vscode-codesearch/.
Package and install:
npm install -g @vscode/vsce
npm run package -- -o codesearch.vsix
code --install-extension codesearch.vsixAfter install, reload the VS Code window. The panel opens with Ctrl+Shift+F1 or F1 -> TsCodeSearch: Open Panel.
Testing
npm test # all tests
node --require tsx/cjs --test src/test/client.test.ts # unit tests onlyPipeline tests need the daemon running (ts start); they skip with a clear message otherwise.
Webview message protocol
| Direction | Message | Fields |
| Webview -> Host | search | query, mode, ext, sub, root, limit |
| Webview -> Host | openFile | relativePath, root |
| Host -> Webview | results | hits, found, elapsed, query, mode |
| Host -> Webview | error | message |
| Host -> Webview | configError | message |
Key gotchas
Must compile before loading. VS Code loads out/extension.js. If out/ is missing, the command is registered but activation fails silently -> "command not found". Always run npm run compile (or use npm run watch during development).
Schema is fixed at index creation time. Indexed fields are populated by the AST extractors, which pre-split compound forms into individual identifiers (e.g. Task<Widget> -> Task, Widget). After any schema change, ts recreate is the way to rebuild.
repoPath must point to the repository root. The extension resolves config.json, ts.mjs, and the local daemon from that directory.
Webview HTML is a TypeScript template literal. The entire HTML including inline JS is built as a backtick string in buildWebviewHtml(). The inline JS must use regular quote strings ('...', "..."), not template literals, to avoid ambiguity with TypeScript's own ${} interpolation. The nonce and initial data (MODES, ROOTS, DEFAULT_ROOT) are the only TypeScript interpolations.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

