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
7 changes: 4 additions & 3 deletions lib/cantrip/acp/agent_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,10 @@ defmodule Cantrip.ACP.AgentHandler do
runtime = :ets.lookup_element(table, :runtime, 2)
bridge = lookup_bridge(table, session_id)

with {:ok, session} <- prepare_prompt(runtime, table, session_id, session) do
prompt_prepared_runtime(runtime, table, session_id, bridge, session, text)
else
case prepare_prompt(runtime, table, session_id, session) do
{:ok, session} ->
prompt_prepared_runtime(runtime, table, session_id, bridge, session, text)

{:error, reason, next_session} ->
:ets.insert(table, {{:session, session_id}, next_session})
{:error, %ACP.Error{code: -32_002, message: Cantrip.SafeFormat.inspect(reason)}}
Expand Down
10 changes: 8 additions & 2 deletions test/cli/renderer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ defmodule Cantrip.CLI.RendererTest do
state = Renderer.new()
event = {env(1), {:tool_call, %{gate: "read_file", tool_call_id: nil}}}
{output, _, _} = Renderer.render_event(state, event)
text = IO.iodata_to_binary(output)
text = plain_text(output)
# Depth 1 = 2 spaces prefix, then " ▸ read_file"
assert text =~ " ▸"
end
Expand All @@ -362,7 +362,7 @@ defmodule Cantrip.CLI.RendererTest do
state = Renderer.new()
event = {env(1), {:code, "done.(\"ok\")"}}
{output, _, _} = Renderer.render_event(state, event)
text = IO.iodata_to_binary(output)
text = plain_text(output)
assert text =~ " ╷"
assert text =~ " │"
end
Expand All @@ -374,4 +374,10 @@ defmodule Cantrip.CLI.RendererTest do
assert IO.iodata_to_binary(output) =~ "bash"
end
end

defp plain_text(output) do
output
|> IO.iodata_to_binary()
|> String.replace(~r/\e\[[0-?]*[ -\/]*[@-~]/, "")
end
end