M2: interactive TUI, config, model switching, compaction
ci / check (push) Canceled after 0s

- hx-tui: ratatui app with streaming transcript, markdown-ish rendering, tool call status,
  colored edit diffs, collapsible bash/read output (ctrl-o), scrollback, spinner + footer (provider, model, ctx, tokens)
- editor: multi-line, history, word/line kill, bracketed paste, @file fuzzy tab completion; mentioned files attached
- message queue while agent runs; esc/ctrl-c abort; /model /provider /compact /clear /help /quit; resumed history shown
- hx-core: compaction (summarize older prompts, keep recent verbatim, session rebase keeps full file history),
  auto-compact at threshold; abort only ends current run
- config: ~/.hx/config.toml + project .hx/config.toml (provider, per-provider models, compact_at, max_tokens, system_prompt)
- API-equivalent cost estimate in exit summary
- tests/tui_smoke.py drives the real TUI in a pty against the fake API

Closes #15, closes #16, closes #17, closes #18, closes #19
This commit is contained in:
hermes committed 2026-09-30 10:37:56 +00:00
1 parent 21d4d2bb3d
commit 89c9833e43
13 files changed
+2875 -48

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
"""Drive the interactive TUI in a pty against the fake API. Prints screen text at checkpoints."""
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)])
tmp = 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}}))
open(f"{tmp}/repo/notes.md", "w").write("NOTES\n")
time.sleep(0.5)
pid, fd = pty.fork()
if pid == 0:
os.chdir(f"{tmp}/repo")
os.environ.update(HOME=f"{tmp}/home", HX_BASE_URL=f"http://127.0.0.1:{port}", TERM="xterm-256color", COLUMNS="100", LINES="30")
os.execv(f"{root}/target/debug/hx", ["hx"])
import fcntl, termios, struct
fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 30, 100, 0, 0))
buf = b""
def pump(t):
global buf
end = time.time() + t
while time.time() < end:
r, _, _ = select.select([fd], [], [], 0.05)
if r:
try:
buf += os.read(fd, 65536)
except OSError:
return
def plain():
s = buf.decode(errors="replace")
s = re.sub(r"\x1b\[[0-9;?]*[A-Za-z]", " ", s)
return re.sub(r"\x1b[()][A-Z0-9]|\x1b[=>]", "", s)
def send(b, t=0.6):
os.write(fd, b); pump(t)
ok = True
def check(label, needle):
global ok
hit = needle in plain()
ok &= hit
print(f"{'PASS' if hit else 'FAIL'} {label}: {needle!r}")
pump(1.5)
check("startup footer", "Claude")
send(b"@not"); send(b"\t")
check("tab completion", "es.md")
send(b"\x15") # ctrl-u
send(b"make hello.txt"); send(b"\r", 3)
check("tool call shown", "write hello.txt")
check("final answer", "Done: file says hi from hx.")
check("file written", "") if os.path.exists(f"{tmp}/repo/hello.txt") else (print("FAIL file"), None)
send(b"/model claude-opus-4-1\r")
check("model switch", "model → claude-opus-4-1")
send(b"/bogus\r")
check("unknown cmd", "unknown command /bogus")
send(b"\x03", 1) # ctrl-c on empty -> quit
try:
_, st = os.waitpid(pid, 0)
print("exit status", st)
except ChildProcessError:
pass
check("exit summary", "session")
srv.kill()
sys.exit(0 if ok else 1)