Module: Kward::SessionTreeToolDisplay

Defined in:
lib/kward/session_tree_tool_display.rb

Overview

Formats persisted tool calls for compact session tree rows.

Both the terminal session tree and the RPC session tree need the same short labels for tool result nodes. Keeping that display rule here prevents the two frontends from drifting while leaving each frontend free to render its own tree prefixes and wire payloads.

Class Method Summary collapse

Class Method Details

.label(tool_call) ⇒ String

Returns a concise bracketed label for a tool call.

Parameters:

  • tool_call (Hash)

    OpenAI/Codex-style tool call hash

Returns:

  • (String)

    label such as [read: README.md:2-4]



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kward/session_tree_tool_display.rb', line 19

def label(tool_call)
  name = ToolCall.display_name(tool_call)
  args = ToolCall.arguments(tool_call)
  case name
  when "read"
    read_label(args)
  when "write", "edit"
    path = args["path"] || args[:path] || args["file_path"] || args[:file_path]
    "[#{name}: #{path}]"
  when "bash"
    command = (args["command"] || args[:command]).to_s.gsub(/[\n\t]/, " ").strip
    "[bash: #{truncate(command, 50)}]"
  else
    serialized = JSON.dump(args)
    "[#{name}: #{truncate(serialized, 40)}]"
  end
end