diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index fea49ec..691760e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -1,7 +1,7 @@ # CI: the three checks CLAUDE.md requires before any work is finished, -# plus the corpus gate, enforced on every push. Runs on the self-hosted -# mac-arm64 runner in host mode (no containers), so the toolchain is the -# same one releases are built with. +# plus the extension's JavaScript tests and the corpus gate, enforced on +# every push. Runs on the self-hosted mac-arm64 runner in host mode (no +# containers), so the toolchain is the same one releases are built with. name: ci on: push: @@ -19,6 +19,10 @@ jobs: run: cargo clippy --all-targets -- -D warnings - name: cargo test run: cargo test --workspace + # The VS Code extension's headless checks (a stubbed `vscode`, no npm + # dependencies): node >= 18 for `--test`; the runner has node 22. + - name: extension tests + run: node --test editors/vscode/*_test.js # The 99.1% headline, enforced: score the 820-file corpus and fail on any # regression below scripts/corpus-baseline (verification errors and diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index cefa1b4..159d598 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -2,8 +2,8 @@ # publishes a Gitea release with the CHANGELOG section for that version as # its notes. What the release page carries is the seven .vsix packages — # the universal one, the five (darwin-arm64/darwin-x64/linux-x64/ -# linux-arm64/win32-x64) with the lucisv + lucisv-server binaries embedded, -# and the all-platforms one carrying every pair at once — plus SHA256SUMS. +# linux-arm64/win32-x64) with the lucisv + lucisv-server + lucisv-mcp binaries embedded, +# and the all-platforms one carrying every platform's three binaries at once — plus SHA256SUMS. # Every package is a must: a missing one fails the release, by name # (tools/prune_release_assets.sh). The loose binaries are still built for # every target diff --git a/README.md b/README.md index 875f483..dee3907 100644 --- a/README.md +++ b/README.md @@ -929,7 +929,7 @@ parents into sections alongside Other Modules. Stars persist per workspace; **VS Code needs no separate binary**: every release on the [releases page](https://git.luci.ooo/lucio/lucisv/releases) carries a -platform-specific `.vsix` with both binaries inside it — pick yours +platform-specific `.vsix` with the binaries inside it — pick yours (`darwin-arm64`, `darwin-x64`, `linux-x64`, `linux-arm64`, `win32-x64`) and sideload it: @@ -983,6 +983,20 @@ vim.lsp.enable('lucisv') `nvim-lspconfig`, Vim 9 (`vim-lsp`) and coc.nvim equivalents: `editors/nvim/README.md`. +**Agents (MCP).** `lucisv-mcp` is lucisv as a Model Context Protocol server +for coding agents: project overview, unit interfaces, outlines, one item's +source, definition/references/hierarchy, diagnostics, and verified edits +(format, lint fixes, rename, the port refactorings, single-item +replace/insert/delete), each with `dry_run`. The platform `.vsix` packages +carry it as a third binary and, on VS Code 1.101+, register it with agent +mode — one server per workspace folder, under **MCP: List Servers** +(`lucisv.mcp.enabled`, `lucisv.mcp.path`). For Claude Code or Cursor, run +**lucisv: Copy MCP server config** in VS Code, or by hand: +`cargo build --release -p lucisv_mcp`, then +`claude mcp add lucisv -- lucisv-mcp --root .`. The tool list, the config +snippets and the safety rules are in the +[Agents (MCP) guide](docs/site/src/content/docs/guides/agents.md). + **Which files the server indexes.** A filelist if the project has one — the `filelist` key of its `lucisv.toml`, or the editor setting `lucisv.filelist` (a path, absolute or relative to the workspace folder) — and then exactly the diff --git a/TODO-MCP.md b/TODO-MCP.md index c5f1954..baf77ad 100644 --- a/TODO-MCP.md +++ b/TODO-MCP.md @@ -224,13 +224,13 @@ mcp_test.js,mcp_smoke.js,.vscodeignore,README.md,CHANGELOG.md}`, trunk; touches no Rust. `extension.js` changes are limited to requiring `mcp.js` and calling its `activate(context)`. -- [ ] `release.sh`: stage `lucisv-mcp[.exe]` into `bin/` (platform) and +- [x] `release.sh`: stage `lucisv-mcp[.exe]` into `bin/` (platform) and `bin//` (all); `expect_vsix_bins` lists grow to three; `mcp_smoke.js` run against the host binary and against the one unzipped from the host vsix and the all-platforms vsix (mirror `smoke_embedded_server`); `audit_artifacts.sh` accepts the third name; the universal vsix still asserts no `extension/bin/*` -- [ ] `mcp.js`: the three-rung binary ladder reusing `bundledBinary`; +- [x] `mcp.js`: the three-rung binary ladder reusing `bundledBinary`; the guarded `registerMcpServerDefinitionProvider("lucisv.mcp", …)` with one `McpStdioServerDefinition` per workspace folder (`--root`, `--index-cache `, `cwd`, `version` from `package.json`), @@ -241,20 +241,20 @@ trunk; touches no Rust. `extension.js` changes are limited to requiring binary; `mcp_test.js` with a stubbed `vscode` (the `hierarchyView_test` pattern) covering the ladder, the guard on an old VS Code (no `lm`), and the three snippets -- [ ] `package.json`: `contributes.mcpServerDefinitionProviders`, the two +- [x] `package.json`: `contributes.mcpServerDefinitionProviders`, the two settings, the command + palette entry; engine stays `^1.82.0` unless `vsce package` refuses — then bump to `^1.101.0` and record why in the README and CHANGELOG -- [ ] docs: the site guide page (install via vsix → nothing to do; Claude +- [x] docs: the site guide page (install via vsix → nothing to do; Claude Code / Cursor snippets; the standalone `cargo build` line; the tool list generated from `tools/list` output, checked in); `README.md` paragraph; `tools/RELEASING.md` (three binaries; the smoke); the extension README and CHANGELOG -- [ ] CI: `node --test editors/vscode/*_test.js` in `ci.yml` -- [ ] README `mcp-packaging`; work log; `node --test` green; a local +- [x] CI: `node --test editors/vscode/*_test.js` in `ci.yml` +- [x] README `mcp-packaging`; work log; `node --test` green; a local `tools/release.sh` (host only) producing a darwin-arm64 vsix with the three binaries, unzipped and checked -- [ ] QA: install the vsix into a clean VS Code profile: the server listed +- [x] QA: install the vsix into a clean VS Code profile: the server listed under **MCP: List Servers**, trusted, `project_overview` answered in agent mode; `lucisv.mcp.enabled: false` removes it; a multi-root workspace registers one server per folder; the universal vsix on a diff --git a/docs/features/mcp-packaging/README.md b/docs/features/mcp-packaging/README.md new file mode 100644 index 0000000..761274c --- /dev/null +++ b/docs/features/mcp-packaging/README.md @@ -0,0 +1,339 @@ +# mcp-packaging + +## Goal + +Ship `lucisv-mcp` (the Model Context Protocol server of `docs/mcp/PLAN.md`) +the way `lucisv-server` ships: as a third binary in every platform `.vsix` and +in the all-platforms one, smoke-tested out of the package by +`tools/release.sh`; registered by the VS Code extension with agent mode (one +stdio server per workspace folder) on a VS Code that has the MCP API; and +reachable from hosts that do not read VS Code's registry (Claude Code, Cursor) +through a copy-config command and a docs page. TODO-MCP **M5**, PLAN §5. + +## Assumptions + +- **Engine stays `^1.82.0`.** `npx @vscode/vsce package` (vsce 4.0.0, + 2026-09-23) packages `contributes.mcpServerDefinitionProviders` under + `^1.82.0` with no warning beyond the pre-existing "bundle your extension" + one, so no bump. The registration is guarded at runtime: `vscode.lm`, + `vscode.lm.registerMcpServerDefinitionProvider` and + `vscode.McpStdioServerDefinition` must all exist (VS Code 1.101+); on an + older VS Code nothing is registered, one line goes to the lucisv output + channel, and the rest of the extension is unaffected. +- **`McpStdioServerDefinition`'s constructor is positional**, not an object: + `(label, command, args?, env?, version?)`, with `cwd` a plain property. + Verified against the installed VS Code 1.138's `vscode.d.ts` and its + extension-host implementation (`constructor(t,e,n,o={},i,s){this.label=t; + this.command=e;this.args=n;this.env=o;this.version=i;…}`). PLAN §2.3 and the + VS Code extension guide's sample show an object argument — that would make + the object the label and leave `command` undefined. `mcp.js` uses the + positional form and assigns `cwd` afterwards. +- **Activation.** `activationEvents` is unchanged: VS Code derives + `onMcpCollection:lucisv.mcp` from the contribution point itself (seen in the + 1.138 workbench: `activationEventsGenerator` yields it for every provider + id), so agent mode can activate the extension without a Verilog file open. + Activation starts the language server too — `mcp.activate` is called at the + end of `extension.js`'s `activate`, after the server start. +- **Where the binary is found** — the server's three-rung ladder: an explicit + `lucisv.mcp.path` (read with `inspect()`; blank and the manifest default + count as unset — the `userServerPath` rule), else `bin/lucisv-mcp` or + `bin/-/lucisv-mcp` in the package (`extension.js`'s own + `bundledBinary`, handed to `mcp.activate` — so there is one implementation + of the two layouts and the chmod), else `lucisv-mcp` on `PATH`. +- **What the extension passes**: `--root ` and, when VS Code + gives one, `--index-cache ` — the + same directory the language server receives as `storagePath`. `cwd` is the + folder's URI, `env` is `{}`, `version` is `package.json`'s. Not passed: + `lucisv.index.cachePath` (the LSP's override of that directory) and + `lucisv.filelist` (MCP reads the project's `lucisv.toml` `filelist` itself). + M6, which reads the store, may want the former. +- **What VS Code shows**: one `lucisv ()` server per workspace + folder under **MCP: List Servers**; trust is VS Code's own per-server + prompt. A folder added/removed or any `lucisv.mcp.*` change fires + `onDidChangeMcpServerDefinitions`, so the list follows without a reload. +- **`lucisv.mcp.enabled: false` is live.** The provider stays registered and + returns no definitions while the setting is off (one output-channel line at + activation says so); turning it back on needs no reload. The brief said + "register nothing" — returning nothing has the same visible effect and + avoids the reload. +- **A missing binary is not started.** `resolveMcpServerDefinition` checks the + command exists (as given when it has a directory part, else on `PATH`); + when not, it logs one line to the lucisv output channel and returns + `undefined`, which the API defines as "do not start". This is the universal + package on a machine without `lucisv-mcp`. +- **Hosts that need the copied config**: Claude Code (`.mcp.json`, + `mcpServers`), Cursor (`.cursor/mcp.json`, `mcpServers`) — neither reads VS + Code's provider registry — and VS Code itself when configured by hand + (`.vscode/mcp.json`, `servers` with `type: "stdio"`). The snippet names the + resolved binary and one `--root` per workspace folder; when that binary is + the bundled one, the message warns that its path changes on update. +- **The loose binaries stay unpublished**, as for the other two + (`tools/prune_release_assets.sh`, unchanged: it keys on the seven `.vsix` + names). +- **CI runs the extension's JavaScript tests** with `node --test + editors/vscode/*_test.js`. The runner is this Mac in host mode, node 22 + (`--test` needs ≥ 18). The tests stub `vscode` and need no `npm ci`. + +## Handshakes + +- **`editors/vscode ─▶ lucisv_mcp` (spawn contract).** Binary name + `lucisv-mcp` (`lucisv-mcp.exe` on Windows); arguments `--root DIR` and + optionally `--index-cache DIR`, nothing else; stdio newline-delimited + JSON-RPC; cwd the folder. Pinned by `mcp_test.js` (exact args) and + `mcp_smoke.js` (spawns the real binary with the same shape). A rename of + either flag in `crates/lucisv_mcp/src/main.rs` breaks both. +- **`tools/ ─▶ lucisv_mcp` (packaging).** `release.sh` builds `-p + lucisv_mcp` for the host and every cross triple and expects + `target/[/]release/lucisv-mcp[.exe]`; `mcp_smoke.js` expects + `serverInfo.name == "lucisv-mcp"`, ≥ 26 tools and a non-error + `project_overview` whose text names the top module. Lowering the tool count + means lowering `MIN_TOOLS` in `mcp_smoke.js`. +- **Promised to users**: the settings `lucisv.mcp.enabled` / `lucisv.mcp.path`, + the command `lucisv.mcp.copyConfig`, the provider id `lucisv.mcp`. +- **Request to the lead (outside this lane's files)**: + `.gitea/workflows/release.yml`'s header comment still says the platform + packages embed "the lucisv + lucisv-server binaries"; it wants "lucisv, + lucisv-server and lucisv-mcp". `docs/mcp/PLAN.md` §2.3/§5.2 show the object + form of the `McpStdioServerDefinition` constructor, which is wrong (see + Assumptions). `docs/topo.md` edges are M6's. + +## Status / TODO + +- [x] `release.sh`: `-p lucisv_mcp` in the host and cross builds; loose + `dist/lucisv-mcp--[.exe]`; staged as `bin/lucisv-mcp` + and `bin//lucisv-mcp`; `expect_vsix_bins` three per platform, + fifteen for `all`; universal still asserts no `bin/`; + `smoke_embedded_mcp` for the host platform package and (with `--cross`) + the `all` package; host `mcp_smoke.js` run; checksummed +- [x] `audit_artifacts.sh`: every binary must be one of the three names; the + same per-triple audits apply to `lucisv-mcp` +- [x] `prune_release_assets.sh`: read, unchanged +- [x] `mcp.js`, `mcp_test.js`, `mcp_smoke.js`; `extension.js` +2 lines +- [x] `package.json`: provider, two settings, command + palette; engine kept +- [x] `.vscodeignore`: `mcp_test.js`, `mcp_smoke.js` excluded +- [x] CI step `node --test editors/vscode/*_test.js` +- [x] docs: site guide `guides/agents.md` + sidebar, `README.md` paragraph, + `tools/RELEASING.md`, extension README + CHANGELOG (Unreleased) +- [x] local `tools/release.sh` (host) green; darwin-arm64 vsix unzipped +- [ ] QA (TODO-MCP M5 last box) + +## Work log + +### 2026-09-23 (dev) + +- **VS Code API check.** Read the installed VS Code 1.138's `vscode.d.ts` and + minified extension host: the stdio definition's constructor is positional; + the plan's object form would have produced a server with an object label + and no command. The contribution point generates `onMcpCollection:` + activation implicitly. +- **`mcp.js`** (≈ 180 lines with comments): ladder, provider with + `provideMcpServerDefinitions` / `resolveMcpServerDefinition` / + `onDidChangeMcpServerDefinitions`, copy-config command (registered on every + VS Code, including those without the MCP API). `bundledBinary` and the + output channel are passed in from `extension.js`, whose change is two lines + (the `require`, and the call after `restarter.start()`). +- **`mcp_test.js`**: 7 groups — the ladder (explicit / blank / bundled / + PATH), one definition per folder with exact args/cwd/version and both + storage fallbacks, change events (folders, `lucisv.mcp`, not others), + `enabled: false` (no definitions, one log line, re-enabled live), the old + VS Code guard in three forms (no `lm`, `lm` without the function, no + definition class; no throw with no channel), missing-binary refusal, and + the three snippets' exact JSON plus the dismissed pick. +- **`mcp_smoke.js`**: temp project of two files, the extension's spawn shape, + all four messages written then stdin closed; checks serverInfo, tool count, + overview text, stdout purity and exit status 0. Fails cleanly (exit 1) on + a missing binary and on the wrong binary (`lucisv-server` refuses + `--root`). `--tool-table` prints the Markdown table checked into the guide. +- **`release.sh`** host run under `tools/guard.sh -t 1800`: exit 0; both + smokes passed on the loose binaries and on the ones unzipped from + `lucisv-0.56.0-darwin-arm64.vsix`; `shasum -c` OK for all five artifacts. + `unzip -Z1 … 'extension/bin/*'` → `lucisv`, `lucisv-mcp`, `lucisv-server`; + `extension/mcp.js` present; no `mcp_test.js` / `mcp_smoke.js`. The universal + vsix has `extension/mcp.js` and no `bin/`. +- **Size**: `lucisv-0.56.0-darwin-arm64.vsix` = 6 784 784 bytes; the + `lucisv-mcp` entry is 4 532 816 bytes, 1 922 890 deflated, `mcp.js` 2 686 + deflated — **+1.93 MB** per platform package (≈ +9.6 MB for `all`, by the + same ratio across five targets; not measured, needs `--cross`). +- **Cross check** (not in the brief, cheap insurance): built `-p lucisv_mcp` + for `x86_64-unknown-linux-gnu`, `x86_64-pc-windows-gnu` and + `x86_64-unknown-linux-musl` with the script's recipes; `audit_artifacts.sh` + passed all three (glibc ceiling `GLIBC_2.28`); a stray name + (`lucisv-lsp-…`) is rejected. +- **vsce**: engine `^1.82.0` accepted (see Assumptions); no bump. +- `node --test editors/vscode/*_test.js`: 6 files, all pass. The docs site + builds (`astro build` to a scratch dir) with the new page. +- No Rust touched. + +## QA log + +### 2026-09-23 (QA) — verdict: **pass** (headless); live-VS Code steps filed as manual-acceptance rows 18–25 + +Everything below ran on master 23ec444 + the lane's uncommitted tree; scratch +work under the session scratchpad, nothing committed, no Rust touched. + +1. **API claim — confirmed.** VS Code **1.138.0** (`code --version`; + `/Applications/Visual Studio Code.app/Contents/Resources/app/out/vscode-dts/vscode.d.ts`): + `vscode.d.ts:20467` `constructor(label: string, command: string, args?: string[], env?: Record, version?: string);` + and `vscode.d.ts:20434` `cwd?: Uri;` (a plain, non-readonly property; + `label` is the only readonly one). The extension host + (`out/vs/workbench/api/node/extensionHostProcess.js`) implements it as + `constructor(t,e,n,o={},i,s){this.label=t;this.command=e;this.args=n;this.env=o;this.version=i;this.metadata=s}`. + `resolveMcpServerDefinition` may return `undefined` = "do not start" + (`vscode.d.ts:20538`). Contribution point schema in + `workbench.desktop.main.js`: `extensionPoint:"mcpServerDefinitionProviders"`, + items `{id, label, when}` (`additionalProperties:false`), and + `activationEventsGenerator` yields `onMcpCollection:` — the + Assumptions' implicit-activation claim holds. `package.json` uses exactly + `id`/`label`; `PROVIDER_ID` in `mcp.js` equals it. +2. **`mcp.js`** — read line by line; `node --test editors/vscode/*_test.js`: + 6 files, 6 pass, 0 fail (node v22.13.1). Ladder order, blank = unset, + one definition per folder with args exactly `--root + --index-cache `, change events, `enabled:false`, the three + old-VS Code shapes, the snippets — all asserted. **Mutation check** (8 + mutants of a scratch `mcp.js`: bundled-before-explicit, untrimmed blank, + `--index-cache` renamed, `cwd` dropped, fire on every config change, + `type:"stdio"` dropped, `enabled` ignored, `lm` guard dropped): all 8 + killed by `mcp_test.js` under `node --test`. **Own scratch checks** + (`qa_mcp_test.js`, not checked in), all pass, with + `unhandledRejection`/`uncaughtException` hooks asserting nothing escaped: + zero folders (`workspaceFolders` both `undefined` and `[]`): no + definitions, no log line, each snippet `JSON.parse`s with `args: []`; + folder `/work/my proj` and bundled path `/ext dir/bin/lucisv-mcp`: label + `lucisv (my proj)`, args keep the space inside one element, `cwd.fsPath` + right, all three snippets `JSON.parse` and round-trip the path, only the + VS Code one has `"type":"stdio"`, and a real existing binary under a + directory with a space resolves; `lucisv.mcp.path` → + `/definitely/not/here/lucisv-mcp`: the setting wins over bundled, resolve + returns `undefined` without throwing, one output-channel line (and no + throw with no channel at all); no `vscode.lm`: copy-config still yields + valid VS Code JSON naming bare `lucisv-mcp`. +3. **`extension.js`**: `git diff` is exactly +2 lines (the `require` and + `mcp.activate(context, { bundledBinary, outputChannel: client.outputChannel })` + after `restarter.start()`; no early return in `activate` before it). + `restart_test.js` passes (44 checks); `tools/guard.sh -- cargo build + --release -p lucisv_server -p lucisv_mcp` then `node + editors/vscode/smoke.js target/release/lucisv-server`: OK (55 messages). +4. **Packaging**: `tools/guard.sh -t 1800 -- tools/release.sh` → exit 0 + (both smokes on the loose binaries and on the ones unzipped from the + darwin-arm64 vsix; `bin/ contents ok` for both packages; vsce 4.0.0 + printed only the pre-existing "bundle your extension" warning — engine + `^1.82.0` accepted). `shasum -a 256 -c SHA256SUMS`: 5 × OK. + `unzip -Z1 dist/lucisv-0.56.0-darwin-arm64.vsix | sort` minus 315 + `extension/node_modules/` entries: `[Content_Types].xml`, + `extension.vsixmanifest`, `extension/LICENSE.txt`, + `extension/bin/lucisv`, `extension/bin/lucisv-mcp`, + `extension/bin/lucisv-server`, `extension/changelog.md`, + `extension/extension.js`, `extension/extract.js`, + `extension/hierarchyModel.js`, `extension/hierarchySections.js`, + `extension/hierarchyView.js`, `extension/images/{architecture.png,feature-map.png,hierarchy.svg,icon.png}`, + `extension/mcp.js`, `extension/media/{hierarchy.css,hierarchy.js}`, + `extension/package.json`, `extension/readme.md`, `extension/restart.js`, + `extension/snippets/{systemverilog,verilog}.json`, + `extension/syntaxes/systemverilog.tmLanguage.json` — no `*_test.js`, no + `smoke.js`/`mcp_smoke.js`. Universal `lucisv-0.56.0.vsix`: 0 + `extension/bin/` entries, `extension/mcp.js` present. Unzipped by hand + to scratch: `mcp_smoke.js` against the embedded `lucisv-mcp` → OK + (0.56.0, 26 tools); it is byte-identical (`cmp`) to the loose binary. + Negative smokes exit 1: missing path (ENOENT), `lucisv-server` and + `lucisv` (both refuse `--root`). **Clean-profile install**: `code + --user-data-dir --extensions-dir --install-extension + dist/lucisv-0.56.0-darwin-arm64.vsix` → installed, + `guoliangchen.lucisv@0.56.0`, `bin/` holds the three executables (755). + `tools/prune_release_assets.sh`: not in `git diff`/`git status`; its + seven suffixes (`""`, darwin-arm64, darwin-x64, linux-x64, linux-arm64, + win32-x64, all) match `vsce_target_for` + the universal + `-all` in + `release.sh` (read, cross not run). `--cross` artifact arithmetic in + `RELEASING.md` (6 triples × 3 = eighteen loose binaries, fifteen `bin/` + entries in `all`) matches the script. `audit_artifacts.sh` on a scratch + copy of dist: clean → exit 0 (3 audited, incl. `lucisv-mcp-…`); a stray + `lucisv-foo-0.56.0-aarch64-apple-darwin` → `FAIL: … not lucisv, + lucisv-server or lucisv-mcp`, exit 1; a Mach-O renamed + `lucisv-mcp-0.56.0-x86_64-unknown-linux-musl` → `not an x86-64 ELF`, + exit 1 (the per-triple audit really applies to the third name). +5. **CI**: `yaml.safe_load` parses `ci.yml`; job `checks` steps in order + `cargo fmt`, `cargo clippy`, `cargo test`, `extension tests` (after the + cargo steps). Local node v22.13.1 (≥ 18); the runner's node version is + the dev's statement, not checked from here. +6. **Docs**: `node editors/vscode/mcp_smoke.js --tool-table + target/release/lucisv-mcp` regenerated; `diff` against the guide's table + → identical (26 rows). Every one of the 14 write tools has `dry_run` in + its input schema (the guide's "on any edit tool" holds); `lucisv-mcp + --bogus` → usage line, exit 2; default root `.` (`canonical_roots`) — the + Standalone paragraph is accurate. Links: the guide has one, absolute; the + extension README's only non-`https://` links are in-page anchors + (`#agents-mcp`, new; `#large-workspaces`, pre-existing), which vsce + accepts (it packaged). Site: `tools/guard.sh -t 600 -- npx astro build + --outDir ` → 14 pages, `guides/agents/` built, sidebar entry on + every page, the `` `define `` row renders as text, `\a@b@1` intact. (Built + to scratch because `docs/site/dist/` is **tracked** — see lead items.) + `README.md` paragraph and `RELEASING.md` agree with `release.sh` + (three binaries, both smokes, host + `all` re-smoke, the artifact + table, "nine crates" = 9 `version.workspace` crates). +7. **PLAN §2.3/§5.2**: found already corrected in the working tree (not + this lane's edit) to the positional form with `cwd` set afterwards; + `release.yml`'s header now names `lucisv-mcp`. + +Extra, headless proxies for the QA checklist's live-VS Code clauses: the +Claude Code snippet built by `configSnippet` with the *installed* extension's +`bin/lucisv-mcp` and a root containing a space, spawned exactly as +`command`/`args` from an unrelated cwd (`os.tmpdir()`): status 0, +`serverInfo.name` `lucisv-mcp`, `project_overview` non-error with the right +root. `lucisv-mcp --index-cache /nonexistent/dir/x` starts and answers +(exit 0) — VS Code creates `storageUri` lazily, so the directory the +extension passes may not exist yet. + +**Findings** (none blocking; no fix made): + +- F1 (docs, minor) `tools/RELEASING.md:240` — "~13 MB rather than ~3 MB (both + before `lucisv-mcp` joined them; the darwin-arm64 package measured 6.8 MB + with it, +1.9 MB)": 3 + 1.9 ≠ 6.8. The pre-MCP darwin-arm64 package was + already ≈ 4.9 MB (6 785 772 − 1 922 890 deflated), so "~3 MB" was stale + before this lane; the new parenthesis makes the inconsistency visible. + Same stale "about 13 MB against 3 MB" at `editors/vscode/README.md:55` + (pre-existing, untouched by the lane). +- F2 (docs, drift risk) `editors/vscode/README.md:196` hard-codes "its 26 + tools"; `MIN_TOOLS` in `mcp_smoke.js` only guards the floor, so a 27th + tool leaves this stale silently. Suggest "its tools" or regenerate with the + guide's table. +- F3 (hardening, optional) `mcp.js:157` — `registerMcpServerDefinitionProvider` + is not wrapped: if it ever throws (e.g. a future VS Code rejecting the + provider), `activate` in `extension.js:293` throws *after* the language + server has started, and VS Code reports the whole extension's activation + as failed. A try/catch logging one line would keep the MCP part + strictly additive. Not reproducible today (the id is declared). +- F4 (for M6) the `--index-cache` directory may not exist when VS Code spawns + the server (see above); the M6 reader must treat a missing directory as + "cold start", not an error. + +**Lead items (outside this lane's files):** `docs/site/dist/` is tracked +and was not rebuilt, so the committed site build lacks `guides/agents/` until +someone regenerates it; `.gitea/workflows/release.yml:6` still says "every +pair at once" one line below the corrected binary list; PLAN §5.2 now shows +`undefined` for `env` where `mcp.js` passes `{}` (equivalent — the host +defaults `env` to `{}` — noted only so the two read alike). + +**Not done here (owner, live VS Code):** MCP: List Servers, trust, an agent-mode +`project_overview`, `enabled:false` live, multi-root, universal-without-PATH +degradation as VS Code shows it, the copied snippet in a real Claude Code +session — `docs/manual-acceptance.md` rows 18–25. The stubbed unit tests and +the headless proxies above cover the logic behind each; only VS Code's own UI +reaction (e.g. whether it adds a toast when `resolve` returns `undefined`) is +unverified. + +## Review + +**Lead, 2026-09-23 (M5).** The lane is scripts, JavaScript and docs, and it +did the one thing the plan got wrong right: VS Code's +`McpStdioServerDefinition` is a positional constructor (confirmed by the dev +and by QA against 1.138's `vscode.d.ts`), so the plan's object form is +corrected in `docs/mcp/PLAN.md` §2.3/§5.2. Rulings kept from the dev's +deviations: `lucisv.mcp.enabled: false` leaves the provider registered and +returning no servers (no reload to turn it back on); a missing binary is +refused at `resolveMcpServerDefinition` with one output-channel line, which +is what the universal package needs. Engine stays `^1.82.0` — vsce 4 accepts +the contribution point and the registration is guarded at runtime. QA's F1/F2 +(stale size and tool-count prose) fixed by the lead; F3 (a try/catch around +the registration) and F4 (`--index-cache` may not exist yet — M6's reader +must tolerate it) noted for M6. The tracked docs site rebuilt so the Agents +page ships. Rows 18–25 of `docs/manual-acceptance.md` are the owner's in a +live VS Code. Committed as M5. diff --git a/docs/manual-acceptance.md b/docs/manual-acceptance.md index 816a542..7df5e75 100644 --- a/docs/manual-acceptance.md +++ b/docs/manual-acceptance.md @@ -24,6 +24,14 @@ hour. Record the release, the date and any failure in the table at the end. | 15 | Hierarchy pane: right-click `aes` → "Star as DUT". | Three sections: "DUT: aes" (open, `aes` and its five children), "Parents of aes" (open, `aes` above `aes_tb`, `aes_wrap`, `tb`), "Other modules" (closed, 297 roots — the 292 plain ones plus the five `aes_tb` held beside `aes`, re-rooted). Right-click `aes` again → "Unstar DUT" puts the plain tree back exactly as it was. | | 16 | Star `aes`, then `hmac`. | Five sections in that order; "Other modules" has 297 roots; each section opens and closes on its own; a module under both keeps its own open state in each. Title bar "Clear DUTs" removes both. | | 17 | Add `"lucisv.hierarchy.duts": ["aes"]` to the workspace `.vscode/settings.json`. | The section appears without starring; right-clicking `aes` offers only a greyed "DUT from settings" whose tooltip names the setting; "Clear DUTs" leaves it. Remove the setting again. | +| 18 | MCP (VS Code 1.101+, platform `.vsix` in a clean profile: `code --profile lucisv-mcp-qa --install-extension lucisv--darwin-arm64.vsix`, opentitan open). Command palette → **MCP: List Servers**. | `lucisv (opentitan)` listed under the `lucisv` provider without opening a Verilog file first (the contribution point activates the extension); no error toast. | +| 19 | Start it from that list; accept VS Code's trust prompt. In Chat (agent mode) ask: "call lucisv's project_overview". | One trust prompt; the tool call answers with `roots: …/opentitan`, the file and unit counts; the server's MCP output log shows `lucisv-mcp: indexed N files` and no error. | +| 20 | Settings → `lucisv.mcp.enabled` off, then on again (no reload). | The server leaves **MCP: List Servers** when off and returns when on; Output → lucisv logged nothing new except, on the next activation with it off, one "lucisv.mcp.enabled is false" line. | +| 21 | File → Add Folder to Workspace… (a second folder); then remove it. | Two servers, `lucisv (opentitan)` and `lucisv ()`, appear without a reload; removing the folder leaves one. | +| 22 | `lucisv.mcp.path` set to `/nowhere/lucisv-mcp`; start the server from the list. Reset the setting. | Not started; Output → lucisv: `cannot start the MCP server: "/nowhere/lucisv-mcp" not found …`; record whether VS Code itself adds a toast (acceptable if it is only VS Code's own "did not start" notice, not an extension error dialog). | +| 23 | Universal `lucisv-.vsix` with no `lucisv-mcp` on PATH; start the server. | Same as 22 with `"lucisv-mcp" not found`; the language server (steps 1–5) unaffected. | +| 24 | **lucisv: Copy MCP server config** → Claude Code; paste into `.mcp.json` of a scratch copy of a project; in a terminal there run `claude`, `/mcp`. Repeat for VS Code → `.vscode/mcp.json` in another window. | The info message names `.mcp.json` and warns the bundled path moves on update; Claude Code lists `lucisv` connected and answers `project_overview`; the `.vscode/mcp.json` server (`"type": "stdio"`) starts too. | +| 25 | Optional, if a VS Code older than 1.101 is at hand: install the platform `.vsix` there. | Extension activates normally; Output → lucisv has one "no MCP server API (needs 1.101+)" line; the copy-config command still works. | ## Runs diff --git a/docs/mcp/PLAN.md b/docs/mcp/PLAN.md index 257c62d..18f2190 100644 --- a/docs/mcp/PLAN.md +++ b/docs/mcp/PLAN.md @@ -122,7 +122,10 @@ Confirmed against the VS Code extension guide (2026-09-23): where the provider has `provideMcpServerDefinitions()` returning `vscode.McpServerDefinition[]`, optional `resolveMcpServerDefinition()` (called at server start) and `onDidChangeMcpServerDefinitions`. -- `new vscode.McpStdioServerDefinition({ label, command, args, cwd, env, version })`. +- `new vscode.McpStdioServerDefinition(label, command, args?, env?, version?)` — + **positional**, with `cwd` set as a property afterwards (corrected 2026-09-23 + by the M5 dev against VS Code 1.138's `vscode.d.ts`; the VS Code guide's + object form is not what the extension host accepts). - Users see the server under **MCP: List Servers** and the Extensions view; trust is per server via the Accounts menu. Extension-provided servers are usable by VS Code's agent mode (Copilot). @@ -375,9 +378,9 @@ still carries no binaries and looks `lucisv-mcp` up on `PATH`. - if `vscode.lm.registerMcpServerDefinitionProvider` exists and `lucisv.mcp.enabled` (default `true`), registers provider `lucisv.mcp` returning one `McpStdioServerDefinition` per workspace folder: - `{ label: "lucisv ()", command, args: ["--root", folder, - "--index-cache", storagePath], cwd: folder, version }`, re-fired on - workspace-folder changes; + `new McpStdioServerDefinition("lucisv ()", command, ["--root", folder, + "--index-cache", storagePath], undefined, version)` with `cwd = folder` set + afterwards, re-fired on workspace-folder changes; - contributes the command **lucisv: Copy MCP server config** that puts a JSON snippet on the clipboard in the host's dialect (Claude Code `.mcp.json` → `mcpServers`; Cursor `.cursor/mcp.json`; VS Code diff --git a/docs/site/astro.config.mjs b/docs/site/astro.config.mjs index 3a05e1f..69c24d5 100644 --- a/docs/site/astro.config.mjs +++ b/docs/site/astro.config.mjs @@ -43,6 +43,7 @@ export default defineConfig({ { label: 'Formatter', slug: 'guides/formatter' }, { label: 'Linter', slug: 'guides/linter' }, { label: 'Editors & LSP', slug: 'guides/editors' }, + { label: 'Agents (MCP)', slug: 'guides/agents' }, { label: 'Supported syntax', slug: 'guides/syntax' } ] }, { label: 'Reference', items: [ diff --git a/docs/site/dist/guides/agents/index.html b/docs/site/dist/guides/agents/index.html new file mode 100644 index 0000000..fbc8265 --- /dev/null +++ b/docs/site/dist/guides/agents/index.html @@ -0,0 +1,300 @@ +Agents (MCP) | lucisvSkip to content

Agents (MCP)

lucisv-mcp is lucisv as a Model Context Protocol +server. A coding agent spawns it over stdio and asks it about the +Verilog/SystemVerilog tree instead of reading whole files: a module’s ports, +a file’s outline, one always block, who instantiates what, every reference +to a signal. It can also make the edits lucisv already knows how to make +safely — format, lint fixes, rename, the port refactorings and single-item +replacements — each one verified before anything is written.

+

It is the same engine as the CLI and the language server (parser, index, +formatter, linter, refactorings), in a third binary that shares no state with +either.

+ + +

The platform .vsix packages (darwin-arm64, darwin-x64, linux-x64, +linux-arm64, win32-x64, and all) carry lucisv-mcp next to lucisv +and lucisv-server. On VS Code 1.101 or later the extension registers it +with agent mode, one server per workspace folder, named +lucisv (<folder>): open MCP: List Servers to see it, trust it once, and +agent mode can call its tools. The extension starts it as

+
Terminal window
lucisv-mcp --root <folder> --index-cache <the extension's workspace storage>
+

Two settings govern it:

+ + + + + + + + + + + + + + + + + + + + +
settingdefaultwhat it does
lucisv.mcp.enabledtruefalse withdraws the server from agent mode (takes effect without a reload)
lucisv.mcp.path""a lucisv-mcp to use instead of the bundled one; empty means the bundled one, else lucisv-mcp on PATH
+

The universal .vsix carries no binaries: it looks lucisv-mcp up on +PATH, and when there is none it says so in the lucisv output channel +instead of starting anything. VS Code older than 1.101 has no MCP API; the +extension then registers nothing and everything else works as before.

+ +

These read their own config file, not VS Code’s. In VS Code, run +lucisv: Copy MCP server config, pick the host, and paste the snippet into +the file the message names. It points at the binary the extension would run +(the bundled one’s path changes when the extension updates — copy it again +then, or point at a lucisv-mcp on PATH).

+

By hand, with lucisv-mcp on PATH:

+
Terminal window
# Claude Code, from the project directory
claude mcp add lucisv -- lucisv-mcp --root .
+

.mcp.json (Claude Code, at the project root) or .cursor/mcp.json (Cursor):

+
{
"mcpServers": {
"lucisv": { "command": "lucisv-mcp", "args": ["--root", "/path/to/project"] }
}
}
+

.vscode/mcp.json (VS Code, when configured by hand instead of through the +extension):

+
{
"servers": {
"lucisv": { "type": "stdio", "command": "lucisv-mcp", "args": ["--root", "/path/to/project"] }
}
}
+ +
Terminal window
cargo build --release -p lucisv_mcp # target/release/lucisv-mcp
+

Arguments: --root DIR (repeatable; default the current directory), +--filelist FILE (index exactly the files an EDA filelist names), +--index-cache DIR, --verbose (per-call timing on stderr). Anything else is +refused with a usage line and exit status 2.

+ +

Generated from the binary’s own tools/list (node editors/vscode/mcp_smoke.js target/release/lucisv-mcp --tool-table); the first sentence of each +description. The agent sees the full description and input schema.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
toolwriteswhat it answers
project_overviewSummarise the Verilog/SystemVerilog project under the roots: file count, units by kind, top-level modules (nothing instantiates them) and the largest files.
list_unitsList the modules, interfaces, packages, classes and programs declared in the project with their file:line, optionally filtered by kind and a name glob (*, ?).
unit_interfaceThe interface of one unit by name: a module’s or interface’s parameters with defaults, ports in declaration order (direction, type, range) and a ready-to-paste instantiation; an interface’s modports; a package’s or class’s members.
outlineThe declarations in one file as a tree with 1-based line ranges (units, ports, parameters, signals, functions, instances, blocks), plus its parse errors.
read_itemThe exact source text and 1-based line range of one item in a file: name, kind:name (e.g. function:crc), name@LINE when a name is declared twice, or always@LINE / initial@LINE / final@LINE / assign@LINE for the unlabelled block or assignment covering that line (@LINE is the last @ followed only by digits, so \a@b@1 is \a@b on line 1).
search_symbolsFind declarations whose name contains query (case-insensitive) across the project: units, and the ports, parameters and package/class members other files can name.
definesThe `define table: name, parameters, body (on one line) and file:line — of one file, of one macro name across the project (every definition; which one a use sees depends on include order, so none is picked), or of the whole project.
definitionWhere a name is declared: every declaration site as file:line:col, its kind and the declaration’s own source line (a name declared in several places lists them all, never a guess).
referencesEvery use of one declaration across the project, grouped by file as line:col and the line’s text — the same occurrences a rename would edit.
hierarchyThe instance tree as indented instance : module #(overrides) lines, down from root (default: every top-level module), or with direction: up every parent.instance that instantiates root, with file:line.
diagnosticsParse errors and lint findings for one file, or for every indexed file, grouped by file as line:col severity message [rule] — what lucisv check over the whole tree reports (cross-file rules on), under the project’s lucisv.toml [lint] settings and waivers.
formatyesFormat file (or the comma-separated files) as lucisv format does, under each file’s lucisv.toml; lines (12-40,55, one file only) formats just the constructs meeting those lines.
fix_lintyesApply the safe automatic fixes of the lint findings in file (or the comma-separated files), as lucisv check --fix does: the project’s [lint] config and waivers, never inside a // lucisv: off fence, never an unsafe fix.
renameyesRename one declaration and every reference to it across the project, verified before anything is written.
expand_wildcardyesReplace one instantiation’s .* with the named connections it binds, verified before anything is written.
convert_portsyesRewrite a module’s non-ANSI header (module m(a, b); input a; …) as an ANSI port list, verified before anything is written.
organize_importsyesRemove the unused import items of the scope at a position and sort the rest, verified before anything is written.
inline_moduleyesReplace one instantiation with the body of the module it instantiates, its connections substituted, verified before anything is written.
propagate_portsyesAdd a named connection for every port one instantiation leaves unconnected, verified before anything is written.
remove_portyesDelete one module port and its connection from every instantiation in the project, verified before anything is written.
add_portyesAdd one ANSI port to a module and a connection for it to every instantiation in the project, verified before anything is written.
extract_moduleyesMove the whole items on lines start_line..end_line of a module into a new module new_name, whose ports come from the dataflow across the selection, and instantiate it in their place; verified before anything is written.
replace_itemyesReplace one item (read_item’s selector) with text, verified before anything is written: the file must still parse; text must be ONE item of the same kind (a module stays a module) declaring the same names unless rename: true (references are then NOT updated; rename does that).
insert_itemyesInsert text (one item or more) before or after the item anchor names (read_item’s selector), or with anchor: "end" as the last items of the file’s last module, package or class (end@NAME for that unit), verified before anything is written: the file must still parse and text must be complete items the scope may hold.
delete_itemyesDelete one item (read_item’s selector) and its own leading comments (up to a blank line), verified before anything is written.
instantiateThe text of an instantiation of module name for the agent to place — parameters with their defaults, the instance name, and each port connected to a same-named signal (named) or as .* (wildcard).
+ +
    +
  • Answers come from the disk. Every call first re-checks the files it +indexes, so no answer is older than the disk at the moment the call +arrived. Unsaved editor buffers are invisible to it — save before asking.
  • +
  • Edits are verified, then written whole. Every edit tool computes and +verifies every file’s new text before the first write; a refusal names the +reason and touches nothing. The formatter’s own safety net applies to +format; replace_item, insert_item and delete_item require the file to +still parse and change no byte outside the item.
  • +
  • dry_run: true on any edit tool returns the unified diff instead of +writing.
  • +
  • Nothing outside the roots. Every path a tool takes must resolve inside a +--root; anything else is refused.
  • +
  • The language server’s cache is never written. --index-cache names +the directory the extension gives lucisv-server; lucisv-mcp accepts it +today and will read that store (read-only) for a warm start in a later +release — never write it, so there are never two writers.
  • +
+
\ No newline at end of file diff --git a/docs/site/dist/guides/editors/index.html b/docs/site/dist/guides/editors/index.html index 68a7903..6e593bf 100644 --- a/docs/site/dist/guides/editors/index.html +++ b/docs/site/dist/guides/editors/index.html @@ -38,7 +38,7 @@ })();