Send mid-turn chat prompts to the harness and queue the rest durably on the server

Claude Code (stream-json stdin) and Codex (turn/steer pinned to the active
turn) receive a prompt sent while a turn runs immediately. Other harnesses
(OpenCode) get a durable chat_prompt_queue row owned by the session: it
survives the last client detaching and a server restart, is delivered in
order when the turn ends with or without a client, and is deduplicated by
operation id. chat_subscribe carries the queue, chat_queue frames report
delivered/removed/failed changes, and chat_unqueue removes a waiting prompt.
This commit is contained in:
2026-11-01 18:30:20 +00:00
parent d300fdc5a5
commit e42f9cc031
25 changed files with 1568 additions and 78 deletions
+23
View File
@@ -211,8 +211,31 @@ def handle(line):
if images and log_path:
with open(log_path + ".content", "a", encoding="utf-8") as log:
log.write(json.dumps(content) + "\n")
pending = state["pending"]
if pending and pending["kind"] == "long":
steer(pending, text)
return
user_message(text)
def steer(pending, text):
"""A message written while a turn runs is read at the turn's next step,
recorded as a queued_command attachment, and the same turn finishes."""
if log_path:
with open(log_path + ".steer", "a", encoding="utf-8") as log:
log.write(text + "\n")
state["pending"] = None
append({"type": "attachment", "uuid": "steer-%d" % state["turn"], "timestamp": stamp(),
"attachment": {"type": "queued_command", "commandMode": "prompt",
"prompt": [{"type": "text", "text": text}]}})
reply = "Noted: " + text
append({"type": "assistant", "uuid": "asst-steer-%d" % state["turn"], "timestamp": stamp(),
"message": {"id": pending["message"] + "_steer", "role": "assistant", "model": "claude-test",
"content": [{"type": "text", "text": reply}]}})
send({"type": "assistant", "message": {"id": pending["message"] + "_steer", "role": "assistant",
"model": "claude-test", "content": [{"type": "text", "text": reply}]}})
finish(pending["message"])
for line in sys.stdin:
handle(line.strip())