codemode-lsp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +130 -0
- package/dist/index.js +46550 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sai Ashirwad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# codemode-lsp
|
|
2
|
+
|
|
3
|
+
An MCP server exposing a **single `execute` tool** backed by LSP. The LLM
|
|
4
|
+
writes JavaScript that chains semantic code operations (`lsp.*`), executed in a
|
|
5
|
+
sandbox with transactional write semantics.
|
|
6
|
+
|
|
7
|
+
LLMs are better at writing code than orchestrating tool calls. Instead of
|
|
8
|
+
filtering, looping, and branching in natural language across many round-trips,
|
|
9
|
+
the model writes one script:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
const refs = await lsp.findReferences("src/api.ts", "handleRequest");
|
|
13
|
+
const relevant = refs.filter((r) => r.context.includes("deprecated"));
|
|
14
|
+
for (const ref of relevant) {
|
|
15
|
+
await lsp.replaceSymbolBody(ref.file, ref.symbolPath, newImpl);
|
|
16
|
+
}
|
|
17
|
+
({ modified: relevant.length });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
One round-trip. Nothing hits disk unless the whole script succeeds; if it
|
|
21
|
+
throws, every buffered write rolls back and the tool returns an operation trace
|
|
22
|
+
showing exactly where the script died. Successful writes come back as
|
|
23
|
+
reviewable unified diffs.
|
|
24
|
+
|
|
25
|
+
v1 targets TypeScript projects via `typescript-language-server`.
|
|
26
|
+
|
|
27
|
+
## Setup
|
|
28
|
+
|
|
29
|
+
Add the server to your MCP client — no install step needed. The package bundles
|
|
30
|
+
its own `typescript-language-server`, so `npx`/`bunx` is all it takes. The
|
|
31
|
+
workspace root is the directory the server is spawned from, so for a
|
|
32
|
+
project-level `.mcp.json` (Claude Code spawns servers from the project
|
|
33
|
+
directory):
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"mcpServers": {
|
|
38
|
+
"codemode-lsp": {
|
|
39
|
+
"command": "npx",
|
|
40
|
+
"args": ["-y", "codemode-lsp"]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
(`"command": "bunx"` with `"args": ["codemode-lsp"]` works too.)
|
|
47
|
+
|
|
48
|
+
To try it on a repo it physically cannot write to, add:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
"env": { "CODEMODE_READONLY": "1" }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Running from a clone instead: requires [Bun](https://bun.sh) — `bun install`,
|
|
55
|
+
then use `"command": "bun"`, `"args": ["run", "/absolute/path/to/codemode-lsp/src/index.ts"]`.
|
|
56
|
+
|
|
57
|
+
## The `execute` tool
|
|
58
|
+
|
|
59
|
+
Accepts JavaScript, runs it in a `vm` sandbox where `lsp.*` is available, and
|
|
60
|
+
returns `{ result, logs, changes }`:
|
|
61
|
+
|
|
62
|
+
- **result** — what the script's last expression evaluates to (JSON-serialized,
|
|
63
|
+
capped at 50k chars).
|
|
64
|
+
- **logs** — captured `console.log/warn/error` output.
|
|
65
|
+
- **changes** — every file that hit disk, as `{ file, kind, diff }` with a
|
|
66
|
+
unified diff against the pre-script content. Empty for read-only scripts.
|
|
67
|
+
|
|
68
|
+
The API surface is 16 functions plus `getDiagnostics`: 8 read ops (`readFile`,
|
|
69
|
+
`getSymbolBody`, `getSymbols`, `findSymbol`, `findReferences`,
|
|
70
|
+
`goToDefinition`, `searchText`, `listFiles`) and 7 write ops (`renameSymbol`,
|
|
71
|
+
`replaceSymbolBody`, `insertBeforeSymbol`, `insertAfterSymbol`,
|
|
72
|
+
`deleteSymbol`, `writeFile`, `deleteFile`). Symbols are addressed by
|
|
73
|
+
slash-separated paths (`MyClass/myMethod`) discovered via `getSymbols`. The
|
|
74
|
+
full type definitions are embedded in the tool description, generated straight
|
|
75
|
+
from the source (`bun run generate:types`).
|
|
76
|
+
|
|
77
|
+
See `PRD.md` for the complete spec.
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
No config file. Three environment variables:
|
|
82
|
+
|
|
83
|
+
| Variable | Default | Effect |
|
|
84
|
+
| --- | --- | --- |
|
|
85
|
+
| `CODEMODE_TIMEOUT_MS` | `30000` | Script timeout |
|
|
86
|
+
| `CODEMODE_LSP_BIN` | `typescript-language-server` | Language server command |
|
|
87
|
+
| `CODEMODE_READONLY` | unset | `1`/`true` removes the 7 write ops from the sandbox, the type defs, and the tool description |
|
|
88
|
+
|
|
89
|
+
Workspace root = the server's cwd. Paths resolving outside it are rejected,
|
|
90
|
+
reads and writes alike.
|
|
91
|
+
|
|
92
|
+
## Limitations (v1)
|
|
93
|
+
|
|
94
|
+
- TypeScript only (the architecture is language-agnostic; more servers later).
|
|
95
|
+
- Diagnostics cover files touched in the session, not the whole project —
|
|
96
|
+
`tsserver` only publishes for opened files.
|
|
97
|
+
- A synchronous infinite loop (`while (true) {}`) is not interrupted by the
|
|
98
|
+
script timeout; async work is.
|
|
99
|
+
- `Reference.isWriteAccess` is always `false` (not exposed over standard LSP).
|
|
100
|
+
|
|
101
|
+
## Eval
|
|
102
|
+
|
|
103
|
+
`bun run eval` measures the project's core success criterion: can an LLM, given
|
|
104
|
+
only the tool description, write correct scripts? It runs 15 benchmark tasks
|
|
105
|
+
(exploration, reference-finding, diagnostics, renames, multi-file refactors)
|
|
106
|
+
against a throwaway copy of the fixture project. The agent is headless Claude
|
|
107
|
+
Code (`claude -p`, billed to your Claude subscription — no API key) with every
|
|
108
|
+
built-in tool disabled, so the only way to solve a task is the `execute` tool.
|
|
109
|
+
It runs on Sonnet by default (pinned so pass rates are comparable);
|
|
110
|
+
`--model opus` etc. overrides.
|
|
111
|
+
Grading is deterministic: read tasks are scored on the final answer, write
|
|
112
|
+
tasks on the resulting disk state.
|
|
113
|
+
|
|
114
|
+
Each task ships with a reference solution that runs against the real server as
|
|
115
|
+
part of `bun test`, so the benchmark itself can never rot. The eval is run on
|
|
116
|
+
demand, never in CI.
|
|
117
|
+
|
|
118
|
+
Current pass rate: **15/15 (100%)** — headless Claude Code (Fable 5), 2026-06-10.
|
|
119
|
+
|
|
120
|
+
## Development
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
bun run check # typecheck + lint + all tests — run before declaring done
|
|
124
|
+
bun test # all tests (integration tests run the real language server)
|
|
125
|
+
bun run generate:types # regenerate src/lsp-types.generated.ts after API changes
|
|
126
|
+
bun run eval # LLM benchmark (on demand; needs the claude CLI)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The worked examples in the tool description run verbatim as golden tests
|
|
130
|
+
(`test/integration/golden-scripts.test.ts`), so the documentation cannot rot.
|