Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client/cli/rag_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
from cli.startup_banner import (
_corpus_summary, backend_label, banner, banner_art, print_help,
)
from cli import terminal_ui
from cli.terminal_ui import (
C_BOLD, C_DIM, C_ERR, C_OK, C_RST, C_WARN, CliRuntimeObserver, STATUS,
Spinner, SpinnerProgress, interruptible, print_assistant,
Expand Down Expand Up @@ -1547,6 +1548,8 @@ def benchmark_toggle(name, default=True):
elif not transcript:
print_assistant("")

terminal_ui.close_tool_block()

# History keeps follow-up context ("ok redo it", "what next?") but
# tool transcripts go on the USER side — the same place they appear
# during live execution — so the model never sees itself "writing"
Expand Down
32 changes: 32 additions & 0 deletions client/cli/terminal_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ def runtime_tool_log(task_result):
def print_assistant(text):
"""Assistant response: ⏺ bullet on the first line, indented continuation."""
text = render_md(text.strip())
close_tool_block()

if not text:
print(f"{C_DIM}⏺ (no response){C_RST}")
Expand All @@ -515,6 +516,37 @@ def print_assistant(text):
print(f" {l}")


# A run of tool calls reads as one block: a line per call, nothing between
# them, and a result only when it is not the expected one. The block is closed
# by a blank line before whatever is printed next.

_TOOL_BLOCK = {"open": False}


def tool_step(name, arg, color=C_OK):
"""One call of a run: its header, set against the previous one."""

if not _TOOL_BLOCK["open"]:
print()

_TOOL_BLOCK["open"] = True
tool_use(name, arg, color=color)


def tool_step_result(text):
"""What a call of a run came to, when that is worth a line: a success is
not, the next header says it."""

if text:
tool_result(text)


def close_tool_block():
if _TOOL_BLOCK["open"]:
_TOOL_BLOCK["open"] = False
print()


def tool_use(name, arg, color=C_OK):
"""Tool-use header: ⏺ Bash(command)"""
arg = arg if vlen(arg) <= 90 else arg[:87] + "…"
Expand Down
20 changes: 12 additions & 8 deletions client/cli/tool_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
authorize_mutation, resolve_path, run_cmd_result, safe_mode_refusal,
)
from cli.terminal_ui import (
C_ACCENT, C_BOLD, C_RST, C_TOOL, tool_result, tool_use,
C_ACCENT, C_BOLD, C_RST, C_TOOL, tool_result, tool_step, tool_step_result, tool_use,
)
from cli.tool_handlers import (
NETWORK_ENABLED, SANDBOX_DOWN, WORK_PHASE, _classified_handler_result,
Expand Down Expand Up @@ -66,9 +66,8 @@ def context():
phase_ledger=getattr(agent_context, "work_phase", None))

def authorize(name, arguments, cwd=None):
print()
tool_use(_CORE_LABELS.get(name, name), _core_summary(name, arguments),
color=C_ACCENT if name in ("patch", "write_file", "delete_file") else C_TOOL)
tool_step(_CORE_LABELS.get(name, name), _core_summary(name, arguments),
color=C_ACCENT if name in ("patch", "write_file", "delete_file") else C_TOOL)
ctx = context()

if cwd:
Expand Down Expand Up @@ -153,10 +152,15 @@ def run(command, script, timeout, output_chars):
result.exit_code, result.summary or "")

def recorded(item):
tool_result(("refused" if item.refused else
"ok" if item.ok else "failed") + (
f" (exit {item.exit_code})" if item.exit_code not in (None, 0) else ""))
print()
code = f" (exit {item.exit_code})" if item.exit_code not in (None, 0) else ""

if item.refused:
tool_step_result("refused" + code)
elif not item.ok:
tool_step_result("failed" + code)
elif code:
tool_step_result("ok" + code)

record(item)

from harness.workspace import SandboxSpec
Expand Down
38 changes: 38 additions & 0 deletions client/tests/test_spinner_residue.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,43 @@ def test_the_tool_line_carries_no_leftover_token_count(self):
self.assertNotIn("tokens", tool)



class AToolRunIsOneBlock(unittest.TestCase):
def output(self, steps):
import contextlib
import io

from cli import terminal_ui

terminal_ui._TOOL_BLOCK["open"] = False
out = io.StringIO()

with contextlib.redirect_stdout(out):
for name, result in steps:
terminal_ui.tool_step(name, "x")
terminal_ui.tool_step_result(result)

terminal_ui.print_assistant("done")

return out.getvalue().split("\n")

def test_successes_follow_one_another_and_the_answer_is_set_apart(self):
import re

lines = [re.sub(r"\x1b\[[0-9;]*m", "", line)
for line in self.output([("Search", ""), ("Terminal", ""), ("Read", "")])]

self.assertEqual(lines, ["", "⏺ Search(x)", "⏺ Terminal(x)", "⏺ Read(x)",
"", "⏺ done", ""])

def test_a_failure_keeps_its_line(self):
import re

lines = [re.sub(r"\x1b\[[0-9;]*m", "", line)
for line in self.output([("Terminal", "failed (exit 2)"), ("Read", "")])]

self.assertEqual(lines[1:4], ["⏺ Terminal(x)", " ⎿ failed (exit 2)", "⏺ Read(x)"])


if __name__ == "__main__":
unittest.main()
Loading