M3: lens LSP diagnostics + lsp tool
ci / check (push) Canceled after 0s

- seq log: monotonic project/file seq with change source
- minimal LSP JSON-RPC client (no lsp-types): framing, requests with timeout, server->client requests,
  publishDiagnostics with versions, $/progress + rust-analyzer serverStatus busy tracking
- manager: built-in table (rust-analyzer, tsserver, pyright, gopls, clangd), outermost-root detection,
  lazy spawn, idle eviction, crash restart with 2-failure breaker, degradation notes, ContentModified retry,
  session-start warmup, config overrides/disable
- turn-end hook: diagnostics for files changed this turn, errors first, per-file cap, total cap,
  unchanged findings not repeated, one 'no problems' after a fix; agent_end/off modes
- lsp tool: diagnostics, definition, references, hover, symbols
- tests: real rust-analyzer + pyright (skipped if absent); tests/lens_e2e.sh proves an introduced type error
  is surfaced and fixed without prompting

Closes #21, closes #22, closes #23, closes #24, closes #25, closes #26
This commit is contained in:
hermes committed 2026-09-30 10:48:37 +00:00
1 parent 89c9833e43
commit 9b8cf48e21
13 files changed
+1522 -17

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
"""Lens e2e: fake model writes a Rust type error; hx must inject rust-analyzer diagnostics at turn end;
the fake model only fixes the file if it sees the error in the next request.
Usage: python3 tests/fake_lens.py PORT
"""
import http.server, json, sys
LOG = []
def sse(ev, d):
return f"event: {ev}\ndata: {json.dumps(d)}\n\n".encode()
def last_user_text(body):
m = body["messages"][-1]
return "\n".join(b.get("text", "") for b in m["content"] if b.get("type") == "text")
class H(http.server.BaseHTTPRequestHandler):
def log_message(self, *a):
pass
def do_POST(self):
body = json.loads(self.rfile.read(int(self.headers["content-length"])))
LOG.append(body)
n = len(LOG)
lens = last_user_text(body)
if n == 1:
turn = ("tool", "Write", {"path": "src/lib.rs", "content": "pub fn f() -> u32 {\n \"oops\"\n}\n"})
elif "[lens]" in lens and "error" in lens:
turn = ("tool", "Write", {"path": "src/lib.rs", "content": "pub fn f() -> u32 {\n 42\n}\n"})
else:
turn = ("text", "FINISHED lens=" + ("clean" if "no problems" in lens else "none"))
self.send_response(200)
self.send_header("content-type", "text/event-stream")
self.end_headers()
w = self.wfile.write
w(sse("message_start", {"message": {"usage": {"input_tokens": 1, "output_tokens": 1}}}))
if turn[0] == "text":
w(sse("content_block_start", {"index": 0, "content_block": {"type": "text", "text": ""}}))
w(sse("content_block_delta", {"index": 0, "delta": {"type": "text_delta", "text": turn[1]}}))
stop = "end_turn"
else:
w(sse("content_block_start", {"index": 0, "content_block": {"type": "tool_use", "id": f"t{n}", "name": turn[1], "input": {}}}))
w(sse("content_block_delta", {"index": 0, "delta": {"type": "input_json_delta", "partial_json": json.dumps(turn[2])}}))
stop = "tool_use"
w(sse("content_block_stop", {"index": 0}))
w(sse("message_delta", {"delta": {"stop_reason": stop}, "usage": {"output_tokens": 1}}))
w(sse("message_stop", {}))
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(json.dumps(LOG).encode())
http.server.ThreadingHTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
# Lens e2e: introduced type error is surfaced by rust-analyzer and fixed without prompting.
set -eu
command -v rust-analyzer >/dev/null || { echo "skip: rust-analyzer not installed"; exit 0; }
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
trap 'kill $srv 2>/dev/null; rm -rf "$tmp"' EXIT
port=$((20000 + $$ % 20000))
python3 "$root/tests/fake_lens.py" $port & srv=$!
mkdir -p "$tmp/home/.hx" "$tmp/repo/src"
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999}}' > "$tmp/home/.hx/auth.json"
printf '[package]\nname = "t"\nversion = "0.1.0"\nedition = "2021"\n' > "$tmp/repo/Cargo.toml"
sleep 0.5
export RUSTUP_HOME="${RUSTUP_HOME:-$HOME/.rustup}" CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}"
cd "$tmp/repo"
HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port" "$root/target/debug/hx" -p "add f" > "$tmp/out" 2> "$tmp/err" || { cat "$tmp/err"; exit 1; }
grep -q "FINISHED lens=clean" "$tmp/out" || { echo "--- out"; cat "$tmp/out"; echo "--- err"; cat "$tmp/err"; exit 1; }
grep -q "42" src/lib.rs
curl -s "http://127.0.0.1:$port/" | grep -q 'mismatched types'
echo "lens e2e ok"