Add loop detector, budgets, and live session control

Milestone 8: the loop detector alerts when test failures repeat, budget
caps limit context/cost/wall-time per session with compaction support,
and live control lets you interrupt, message, or kill a running session
from the TUI. Decisions can now be vetoed, which sends hx/message and
rewinds the session to code. All 82 tests pass.

- src/budget.rs: pure functions for active time, budgets and loop detect
- src/runner.rs: Ctl control object polls for commands ~100ms, handles
  interrupt/message/abort/stop at every blocking point, re-runs on
  hints, and compacts when context is high
- src/db.rs: commands table for TUI→runner control
- src/detail.rs, src/goal.rs, src/tui/: loop detector box, budget caps,
  session keys (i/m/s/k/r), goal keys (v for veto), state forcing
- tests/fake_acp_hx.py: slow mode and hx/message, hx/compact log
- examples/machines/task.toml: [budget] with wall_secs, cost, compact_at

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
johannesandClaude Haiku 4.5 committed 2026-11-14 12:55:44 +01:00
1 parent 7bf0986640
commit bf609c2e0e
16 files changed
+1694 -55

No files matched your search

+22
View File
@@ -6,7 +6,10 @@ Behaviour per `hx/step`, chosen with FAKE_MODE (orch passes FAKE_* through the p
block_once blocked the first time (marker file .fake_blocked in cwd), done afterwards
needs_input step_result needs_input with a question; finishes when the retried step has a context.hint
permission asks session/request_permission first and records the answer in permission.txt
slow works until hx/interrupt (records hx/message and hx/compact in messages.txt / compact.txt), then
answers done; a retried step with context.hint finishes at once
crash exits without a step_result
FAKE_USAGE="ctx_used,ctx_limit,cost" makes every step report that usage first.
Every received message is appended to FAKE_LOG when set. Each step also appends its prompt kind to steps.txt.
"""
import json
@@ -47,6 +50,10 @@ def step(params):
if mode == "crash":
sys.exit(3)
note("hx/intent", {"text": f"working on {kind}"})
usage = os.environ.get("FAKE_USAGE") # "ctx_used,ctx_limit,cost"
if usage:
used, limit, cost = usage.split(",")
note("hx/usage", {"ctx_used": int(used), "ctx_limit": int(limit), "cost": float(cost)})
note("session/update", {"sessionId": session, "update": {"sessionUpdate": "tool_call", "toolCallId": "t1", "title": "edit src/lib.rs", "kind": "edit", "status": "in_progress"}})
if mode == "permission":
send({"id": 900, "method": "session/request_permission", "params": {
@@ -59,6 +66,21 @@ def step(params):
with open(os.path.join(cwd, "permission.txt"), "w") as f:
f.write(json.dumps(m["result"]))
break
# slow keeps working until the orchestrator interrupts it; it records what it is told meanwhile.
# A retried step (context.hint set, e.g. the user's reply after an interrupt) finishes at once.
if mode == "slow" and not params.get("context", {}).get("hint"):
while True:
m = recv()
md = m.get("method")
if md == "hx/message":
with open(os.path.join(cwd, "messages.txt"), "a") as f:
f.write(m["params"]["text"] + "\n")
elif md == "hx/compact":
with open(os.path.join(cwd, "compact.txt"), "a") as f:
f.write("compact\n")
elif md == "hx/interrupt":
note("hx/step_result", {"status": "done", "summary": "interrupted"})
return
# needs_input asks once; with the user's answer in context.hint the same step finishes
if mode == "needs_input" and not params.get("context", {}).get("hint"):
note("hx/step_result", {"status": "needs_input", "question": "Which provider?"})