chore: delete code comments, add ratchet lint and ADRs

Classify every comment as tautology, stale, excuse or decision record.
Tautology/stale/excuse comments are deleted (excuses filed as issues
#196-#236), decisions moved to docs/adr/0001-0034.

- scripts/lint-comments.sh + .comment-baseline: per-file comment count
  may only go down; wired into tests/all.sh
- .claude/skills/delete-comment: repeatable audit workflow
- cargo fmt applied to touched crates

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-21 13:37:32 +01:00
1 parent 0545702fe0
commit a94632ea3d
131 files changed
+1051 -1746

No files matched your search

+2 -2
View File
@@ -8,7 +8,7 @@ Scenario (against tests/fake_anthropic.py with acp_turns.json):
import json, subprocess, sys, urllib.request
hx, repo, sid, port = sys.argv[1:5]
seen = [] # every notification and request from hx, in order
seen = []
class Hx:
@@ -30,7 +30,7 @@ class Hx:
m = json.loads(line)
if "method" in m:
seen.append(m)
if "id" in m: # permission request: allow once
if "id" in m:
assert m["method"] == "session/request_permission", m
self.send({"id": m["id"], "result": {"outcome": {"outcome": "selected", "optionId": "allow_once"}}})
elif m.get("id") == self.n:
-2
View File
@@ -1,6 +1,4 @@
#!/bin/sh
# ACP e2e: `hx serve --acp` driven by a fake orchestrator (tests/acp_client.py) against a fake Anthropic API:
# permission requests, hx/edit|usage|intent|decision|plan|step_result, limits, hx/message, session continuation.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
+1 -2
View File
@@ -1,12 +1,11 @@
#!/bin/sh
# Full local check: fmt, clippy, unit tests, all e2e scripts.
cd "$(dirname "$0")/.."
export PATH="$HOME/.local/bin:$PATH"
set -e
bash scripts/lint-comments.sh
cargo fmt --all --check
cargo clippy -q --workspace --all-targets -- -D warnings
log=$(mktemp)
# rust-analyzer test runs alone: under parallel cargo load its flycheck can publish stale results (see issue)
cargo test -q --workspace -- --skip rust_analyzer_turn_end >"$log" 2>&1 || { grep -E 'FAILED|panicked' -A4 "$log"; exit 1; }
cargo test -q -p hx-lens rust_analyzer_turn_end >>"$log" 2>&1 || { grep -E 'FAILED|panicked' -A4 "$log"; exit 1; }
grep -oE 'ok. [0-9]+ passed' "$log" | awk '{s+=$2} END {print s" unit tests ok"}'
-3
View File
@@ -1,5 +1,4 @@
#!/bin/sh
# (print mode has no prompt, so the permission bridge allows) claude_cli = [] routes Claude through the `claude` binary (fake here): streamed text arrives, argv is right.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
@@ -13,7 +12,6 @@ export HOME="$tmp/home" HX_CLAUDE_BIN="$root/tests/fake_claude.py" FAKE_CLAUDE_L
grep -q "claude Bash: echo hi-from-tool" "$tmp/out" && grep -q "approve: allow" "$tmp/out" || { echo "FAIL text"; cat "$tmp/out" "$tmp/err"; exit 1; }
grep -q '"--permission-prompt-tool"' "$tmp/argv" && grep -q '"--mcp-config"' "$tmp/argv" && grep -q '"stream-json"' "$tmp/argv" || { echo "FAIL argv"; cat "$tmp/argv"; exit 1; }
grep -q "cm-ok" "$tmp/out" || { echo "FAIL codemode"; cat "$tmp/out" "$tmp/err"; exit 1; }
# bridge goes through the bus: an extension blocks a secret Read and `curl`; tool events reach NDJSON
cd "$tmp/repo"
export FAKE_ASK=1
timeout 20 "$root/target/debug/hx" -p "go" --mode json -s "$tmp/s2.jsonl" > "$tmp/o2" 2> "$tmp/e2" || { echo "FAIL ask run"; cat "$tmp/e2"; exit 1; }
@@ -34,7 +32,6 @@ ev = [json.loads(l) for l in open(sys.argv[1]) if l.startswith("{")]
res = [e for e in ev if e["type"] == "tool_result"]
assert len(res) == 2 and all(r["is_error"] and "blocked: guard: " in r["content"] for r in res), res
PY
# a dead guard must not leave the run open under permissions = "extensions-only"
printf 'claude_cli = []\npermissions = "extensions-only"\n[lsp]\nmode = "off"\ntests = "off"\n' > "$tmp/home/.hx/config.toml"
timeout 20 "$root/target/debug/hx" -p "go" --mode json -s "$tmp/s4.jsonl" > "$tmp/o4" 2> "$tmp/e4" || { echo "FAIL deny run"; cat "$tmp/e4"; exit 1; }
grep -q 'extensions-only' "$tmp/o4" && ! grep -q '"content":"allow' "$tmp/o4" || { echo "FAIL extensions-only"; cat "$tmp/o4"; exit 1; }
+1 -4
View File
@@ -1,5 +1,4 @@
#!/bin/sh
# End-to-end: hx -p against a scripted fake Anthropic API. No network, no real credentials.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
@@ -16,9 +15,8 @@ grep -q "Done: file says hi from hx." "$tmp/out"
log=$(curl -s "http://127.0.0.1:$port/")
echo "$log" | grep -q '"auth": "Bearer fake-token"'
echo "$log" | grep -q 'oauth-2025-04-20'
echo "$log" | grep -q 'hi from hx' # bash tool result sent back to the model
echo "$log" | grep -q 'hi from hx'
ls "$tmp/home/.hx/sessions/"*/*.jsonl > /dev/null
# a GPT model goes to the Codex endpoint, not to the Claude API (both logged in)
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999},"codex":{"access":"cx-token","refresh":"r","expires":99999999999999,"account_id":"acc"}}' > "$tmp/home/.hx/auth.json"
HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port" "$root/target/debug/hx" -m gpt-5.6-terra -p "hi" > /dev/null 2> "$tmp/err" || true
curl -s "http://127.0.0.1:$port/" | python3 -c '
@@ -26,7 +24,6 @@ import json, sys
last = json.load(sys.stdin)[-1]
assert last["path"].endswith("/responses") and last["body"]["model"] == "gpt-5.6-terra" and last["auth"] == "Bearer cx-token", last
' || { echo "FAIL: gpt model not routed to codex"; cat "$tmp/err"; exit 1; }
# inside herdr: working, idle and release reach the herdr binary; resume command carries the session
printf '#!/bin/sh\necho "$@" >> "%s/herdr.log"\n' "$tmp" > "$tmp/herdr"; chmod +x "$tmp/herdr"
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999}}' > "$tmp/home/.hx/auth.json"
HERDR_ENV=1 HERDR_PANE_ID=p7 HERDR_BIN_PATH="$tmp/herdr" HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port" "$root/target/debug/hx" -p "make hello.txt" > /dev/null 2>&1
+1 -3
View File
@@ -10,7 +10,7 @@ TURNS = [
[("tool_use", {"id": "t2", "name": "Bash", "input": {"command": "sed -n p hello.txt"}})],
[("text", "Done: file says hi from hx.")],
]
if len(sys.argv) > 2: # optional scripted turns: JSON [[["tool_use", {...}] | ["text", "..."], ...], ...]
if len(sys.argv) > 2:
TURNS = [[tuple(b) for b in t] for t in json.load(open(sys.argv[2]))]
LOG = []
@@ -27,7 +27,6 @@ class H(http.server.BaseHTTPRequestHandler):
body = json.loads(self.rfile.read(int(self.headers["content-length"])))
LOG.append({"path": self.path, "auth": self.headers.get("authorization"), "beta": self.headers.get("anthropic-beta"), "body": body})
if self.path.endswith("/responses"):
# Codex route: only the request matters to the tests
self.send_response(400)
self.end_headers()
self.wfile.write(b'{"detail": "fake codex"}')
@@ -58,7 +57,6 @@ class H(http.server.BaseHTTPRequestHandler):
self.send_response(200)
self.end_headers()
if self.path.startswith("/v1/models"):
# live catalog: newest first, includes a model the static fallback doesn't know
self.wfile.write(json.dumps({"data": [
{"id": "claude-opus-5-5", "max_input_tokens": 1000000},
{"id": "claude-sonnet-5-5", "max_input_tokens": 1000000},
+3 -3
View File
@@ -6,7 +6,7 @@ if "--version" in sys.argv:
print("fake"); sys.exit(0)
def out(o): print(json.dumps(o), flush=True)
reply = "hello from claude"
if os.environ.get("FAKE_ASK"): # ask hx about a secret Read and `curl x` (ids t1/t2); report the answers
if os.environ.get("FAKE_ASK"):
import subprocess
cfg = json.loads(sys.argv[sys.argv.index("--mcp-config") + 1])["mcpServers"]["hx"]
p = subprocess.Popen([cfg["command"], *cfg["args"]], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
@@ -16,7 +16,7 @@ if os.environ.get("FAKE_ASK"): # ask hx about a secret Read and `curl x` (ids t
p.stdin.flush()
p.stdout.readline()
ans = []
for i, (tid, n, inp) in enumerate(asks): # one at a time: deterministic order
for i, (tid, n, inp) in enumerate(asks):
p.stdin.write(json.dumps({"jsonrpc": "2.0", "id": 10 + i, "method": "tools/call", "params": {"name": "approve",
"arguments": {"tool_name": n, "input": inp, "tool_use_id": tid}}}) + "\n")
p.stdin.flush()
@@ -29,7 +29,7 @@ if os.environ.get("FAKE_ASK"): # ask hx about a secret Read and `curl x` (ids t
"content": a["behavior"] + ": " + a.get("message", ""), "is_error": a["behavior"] == "deny"}]}})
out({"type": "result", "session_id": "S1", "is_error": False, "result": "done", "usage": {"input_tokens": 1, "output_tokens": 1}})
sys.exit(0)
if "--permission-prompt-tool" in sys.argv: # act like claude: ask hx whether `rm -rf x` may run
if "--permission-prompt-tool" in sys.argv:
import subprocess
cfg = json.loads(sys.argv[sys.argv.index("--mcp-config") + 1])["mcpServers"]["hx"]
p = subprocess.Popen([cfg["command"], *cfg["args"]], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
-2
View File
@@ -1,5 +1,4 @@
#!/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)
@@ -17,7 +16,6 @@ HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port" "$root/target/debug/hx" -p
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'
# same run in json mode: the lens report reaches UIs as an `injected` event
kill $srv; python3 "$root/tests/fake_lens.py" $port & srv=$!; sleep 0.5
git checkout -q -- . 2>/dev/null || rm -f src/lib.rs
HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port" "$root/target/debug/hx" -p "add f" --mode json > "$tmp/json" 2> "$tmp/err" || { cat "$tmp/err"; exit 1; }
-6
View File
@@ -1,6 +1,4 @@
#!/bin/sh
# M4 e2e: ruff lint findings reach the model, ruff-format runs without tripping the read-guard,
# diag_mark persists and hides the finding.
set -eu
command -v ruff >/dev/null || { echo "skip: ruff not installed"; exit 0; }
root=$(cd "$(dirname "$0")/.." && pwd)
@@ -10,7 +8,6 @@ port=$((20000 + $$ % 20000))
python3 "$root/tests/fake_m4.py" $port & srv=$!
mkdir -p "$tmp/home/.hx" "$tmp/repo"
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999}}' > "$tmp/home/.hx/auth.json"
# ruff.toml enables ruff-format (formatters only run when configured)
echo 'line-length = 100' > "$tmp/repo/ruff.toml"
printf '[lsp]\ndisable = ["pyright"]\n' > "$tmp/home/.hx/config.toml"
sleep 0.5
@@ -21,12 +18,9 @@ curl -s "http://127.0.0.1:$port/" > "$log"
fail() { echo "FAIL: $1"; echo "--- log"; python3 -m json.tool < "$log"; echo "--- err"; cat "$tmp/err"; exit 1; }
chk() { python3 -c "import json,sys; l=json.load(open(sys.argv[1])); $1" "$log"; }
grep -q FINISHED "$tmp/out" || fail "no finish"
# turn 2 request carries lens report with ruff F401
chk 'assert "[F401]" in l[1] and "(ruff)" in l[1], l[1]' || fail "no ruff finding"
# formatter applied, and the following edit was not blocked
grep -qx "x = 2" p.py && grep -qx "print(x)" p.py || fail "format/edit: $(cat p.py)"
chk 'assert l[2].startswith("OK:edited"), l[2]' || fail "edit blocked"
# diag_mark succeeded and persisted
chk 'assert "OK:marked FalsePositive" in l[3], l[3]' || fail "mark"
grep -q F401 "$tmp"/home/.hx/projects/*/triage.json || fail "triage not persisted"
[ -s "$tmp/home/.hx/latency.log" ] || fail "no latency log"
-1
View File
@@ -1,5 +1,4 @@
#!/bin/sh
# M5 e2e: failing affected test is surfaced at turn end and fixed without prompting; green reported.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
-4
View File
@@ -1,6 +1,4 @@
#!/bin/sh
# M6 e2e: model discovers an MCP tool via the lazy index, describes and calls it; `hx mcp` reports costs;
# `hx mcp-serve` answers another MCP client (hx itself, configured as a server) with lens tools.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
@@ -20,14 +18,12 @@ export HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port"
grep -q "FINISHED OK:42" "$tmp/out" || { echo "--- out"; cat "$tmp/out"; echo "--- log"; curl -s "http://127.0.0.1:$port/"; echo "--- err"; cat "$tmp/err"; exit 1; }
"$root/target/debug/hx" mcp > "$tmp/st"
grep -q "f: 5 tools.*lazy (index ~[0-9]* tok, eager schemas ~[0-9]* tok)" "$tmp/st" || { cat "$tmp/st"; exit 1; }
# mcp-serve: hx as MCP server, consumed by hx as MCP client
printf 'fn main() {}\n' > main.rs
cat > "$tmp/repo/.hx/mcp.json" <<EOF
{"mcpServers": {"hx": {"command": "$root/target/debug/hx", "args": ["mcp-serve"], "eager": false}}}
EOF
"$root/target/debug/hx" mcp > "$tmp/st2"
grep -q "hx.lsp: Language server queries" "$tmp/st2" || { cat "$tmp/st2"; exit 1; }
# a foreign client (python, raw JSON-RPC) gets pyright diagnostics through hx mcp-serve
if command -v pyright-langserver >/dev/null; then
printf 'x: int = "no"\n' > bad.py
python3 - "$root/target/debug/hx" > "$tmp/diag" <<'PY'
-6
View File
@@ -1,6 +1,4 @@
#!/bin/sh
# M7 e2e: --mode json emits NDJSON events; examples/rpc_client.py drives a session over --mode rpc;
# examples/ext_guard.py (extension) blocks a bash call and provides a tool.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
@@ -18,7 +16,6 @@ start() {
}
fail() { echo "FAIL: $1"; cat "$2"; exit 1; }
# 1) json mode: every line parses; tool_call, tool_result, text and done are present
start 1
"$root/target/debug/hx" -p "go" --mode json > "$tmp/json" 2> "$tmp/err" || fail "json run" "$tmp/err"
python3 - "$tmp/json" <<'PY' || fail "ndjson schema" "$tmp/json"
@@ -33,7 +30,6 @@ assert any(e["type"] == "tool_result" and "hi from hx" in e["content"] for e in
PY
kill $srv; rm -f hello.txt
# 2) rpc mode driven by the example client
start 2
python3 "$root/examples/rpc_client.py" "$root/target/debug/hx" "go" > "$tmp/rpc" 2> "$tmp/err" || fail "rpc" "$tmp/err"
grep -q "Done: file says hi from hx." "$tmp/rpc" || fail "rpc text" "$tmp/rpc"
@@ -43,14 +39,12 @@ grep -q "BUSY_CHECK claude-x" "$tmp/rpc" || fail "rpc set_model" "$tmp/rpc"
grep -q "COMPLETE 0 \['/model'\]" "$tmp/rpc" || fail "rpc complete" "$tmp/rpc"
grep -q "SESSIONS [0-9]* go 6" "$tmp/rpc" || fail "rpc sessions" "$tmp/rpc"
grep -q "RESUMED 6 go" "$tmp/rpc" || fail "rpc resume" "$tmp/rpc"
# hx -r <query> resumes the matching session (the rpc run above titled it "go")
"$root/target/debug/hx" -r go -p "again" > /dev/null 2> "$tmp/err" || true
grep -q "\[resuming: go\]" "$tmp/err" || fail "hx -r query" "$tmp/err"
"$root/target/debug/hx" -r nomatchzz -p x > /dev/null 2> "$tmp/err" && fail "hx -r no match should fail" "$tmp/err"
grep -q "matches \"nomatchzz\"" "$tmp/err" || fail "hx -r no match message" "$tmp/err"
kill $srv; rm -f hello.txt
# 3) extension blocks the bash call (cat) and registers its tool
start 3
printf '[[extensions]]\ncommand = ["python3", "%s/examples/ext_guard.py", "sed -n p hello"]\n' "$root" >> "$tmp/home/.hx/config.toml"
"$root/target/debug/hx" -p "go" --mode json > "$tmp/ext" 2> "$tmp/err" || fail "ext run" "$tmp/err"
-4
View File
@@ -1,6 +1,4 @@
#!/bin/sh
# M8 e2e: the parent calls `task`; the child (own session, cheap model) reads a file and answers;
# only the answer reaches the parent; child usage is logged under <session>.sub/.
set -eu
root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
@@ -34,10 +32,8 @@ assert "haiku" in child1["model"] and "sonnet" in parent["model"], (child1["mode
assert child1["messages"][0]["content"][0]["text"] == "what is in note.txt?"
assert {t["name"] for t in child1["tools"]} == {"Read", "Bash", "skill"}, [t["name"] for t in child1["tools"]]
assert "Task" in {t["name"] for t in parent["tools"]}
# children get the project context (AGENTS.md) in their system prompt, like the parent
for r in (parent, child1, child2):
assert "PROJECT-RULE-XYZ" in json.dumps(r["system"]), r["model"]
# parent got only the child's answer (+ stats line), not the Read result
res = json.dumps(parent2["messages"][-1])
assert "secret is 42" in res and "[task explore" in res
PY
-1
View File
@@ -1,5 +1,4 @@
#!/bin/sh
# Sandbox: no raw child spawns outside the chokepoint (real confinement is tested in hx-core sandbox::tests::confines).
cd "$(dirname "$0")/.."
bad=$(grep -rn "Command::new" crates/hx-lens/src crates/hx-tools/src --include=*.rs | grep -v "tests\?\.rs\|manager.rs\|cargo\|stty\|\"kill\"")
[ -z "$bad" ] || { echo "sandbox e2e FAIL: raw spawn: $bad"; exit 1; }
+1 -1
View File
@@ -61,7 +61,7 @@ check("installer shown", "Run `sh -c mkdir")
send(b"y", 3)
check("answer logged", " yes")
check("installed", "") if os.path.exists(binp) else (print("FAIL installer did not run"), globals().update(ok=False))
send(b"\x03", 1) # ctrl-c on empty -> quit
send(b"\x03", 1)
try:
_, st = os.waitpid(pid, 0)
print("exit status", st)
+6 -10
View File
@@ -4,7 +4,6 @@ import os, pty, sys, time, subprocess, select, re, json, tempfile, signal
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
port = 20000 + os.getpid() % 20000
srv = subprocess.Popen([sys.executable, f"{root}/tests/fake_anthropic.py", str(port)])
# resolved: hx sees the real cwd (macOS /var -> /private/var) and derives the session dir slug from it
tmp = os.path.realpath(tempfile.mkdtemp())
os.makedirs(f"{tmp}/home/.hx"); os.makedirs(f"{tmp}/repo")
open(f"{tmp}/home/.hx/auth.json", "w").write(json.dumps({"claude": {"access": "fake-token", "refresh": "r", "expires": 99999999999999}}))
@@ -26,7 +25,7 @@ if pid == 0:
import fcntl, termios, struct
fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 30, 100, 0, 0))
os.write(fd, b"\x1b[?62;c") # answer hx's keyboard-protocol probe like a terminal without kitty support
os.write(fd, b"\x1b[?62;c")
buf = b""
def pump(t):
global buf
@@ -55,15 +54,15 @@ def check(label, needle):
pump(1.5)
check("startup footer", "Claude")
check("latest default model", "claude-sonnet-5-5")
send(b"l1"); send(b"\x1b[13;2u"); send(b"l2") # shift-enter as CSI-u (kitty protocol)
send(b"l1"); send(b"\x1b[13;2u"); send(b"l2")
check("shift-enter is a newline, not a submit", "l1")
send(b"\x15\x7f\x15") # kill line 2, join, kill line 1
send(b"\x15\x7f\x15")
send(b"/skills\r")
check("skills from ~/.agents", "/deploy — ship it")
check("project .agents skills", "/lint — project lint")
send(b"@not"); send(b"\t")
check("tab completion", "es.md")
send(b"\x15") # ctrl-u
send(b"\x15")
send(b"make hello.txt"); send(b"\r", 2)
check("permission prompt", "permission")
check("allow all edits option", "allow all edits this session")
@@ -86,7 +85,6 @@ send(b"/model claude-sonnet-5-6-preview\r")
check("live catalog window", "2000k")
check("live catalog cached", "") if os.path.exists(f"{tmp}/home/.hx/models-claude.json") else (print("FAIL no model cache"), globals().update(ok=False))
buf = b""
# auto mode: per-prompt choice, one-turn @override, pinning turns it off
send(b"/model auto\r")
check("auto on", "model: auto")
send(b"fix the typo in notes.md\r", 3)
@@ -105,12 +103,10 @@ ok &= "codex" not in plain(); print("PASS no codex without login" if "codex" not
send(b"\x15")
send(b"/bogus\r")
check("unknown cmd", "unknown command /bogus")
send(b"\x10") # ctrl-p
send(b"\x10")
send(b"OLDPROMPT")
check("picker lists past session", "session just now")
send(b"\r", 1)
# screen text can be split by ratatui's cursor-move diffing; the OSC window title is written whole
# and only carries the old prompt once the session is resumed
check("picker resumes session", "hx · OLDPROMPT about parsers")
send(b"/new\r")
check("new session", "new session")
@@ -120,7 +116,7 @@ send(b"make", 0.8)
check("sessions filter", "make hello.txt")
send(b"\r", 1)
check("resume from /sessions", "resumed ")
send(b"\x03", 1) # ctrl-c on empty -> quit
send(b"\x03", 1)
try:
_, st = os.waitpid(pid, 0)
print("exit status", st)