## A collapsed panel for the model's pre-action commentary. ## ## Reasoning is worth showing — it explains the tool call that follows — but ## rendered inline it buries the conversation, since a model thinking through ## a task will produce far more of it than of answer. So it collapses to one ## line and opens on click, the same shape the tool cards use. @tool class_name ClaudeGodotReasoningCard extends VBoxContainer const COLOR_DIM := "#8a8a8a" const MAX_BODY_LINES := 200 var _text := "" var _expanded := false var _header: Button var _header_label: RichTextLabel var _body: VBoxContainer func setup(text: String) -> void: _text = text _header = Button.new() _header.flat = true _header.custom_minimum_size = Vector2(0, 22) _header.pressed.connect(_toggle) add_child(_header) _header_label = RichTextLabel.new() _header_label.bbcode_enabled = true _header_label.scroll_active = false _header_label.mouse_filter = Control.MOUSE_FILTER_IGNORE _header_label.set_anchors_preset(Control.PRESET_FULL_RECT) _header.add_child(_header_label) _body = VBoxContainer.new() _body.visible = false add_child(_body) _refresh_header() func to_plain_text() -> String: return _text func _toggle() -> void: _expanded = not _expanded _body.visible = _expanded if _expanded and _body.get_child_count() == 0: var rtl := RichTextLabel.new() rtl.bbcode_enabled = true rtl.fit_content = true rtl.scroll_active = false rtl.size_flags_horizontal = Control.SIZE_EXPAND_FILL rtl.append_text("[i][color=%s]%s[/color][/i]" % [COLOR_DIM, _capped(_text)]) _body.add_child(rtl) _refresh_header() func _refresh_header() -> void: _header_label.clear() _header_label.append_text("[color=%s]%s thought · %d words[/color]" % [ COLOR_DIM, "▾" if _expanded else "▸", _word_count(), ]) func _word_count() -> int: var n := 0 for word in _text.split(" ", false): if word.strip_edges() != "": n += 1 return n func _capped(text: String) -> String: var escaped := text.replace("[", "[lb]") var lines := escaped.split("\n") if lines.size() <= MAX_BODY_LINES: return escaped return "\n".join(lines.slice(0, MAX_BODY_LINES)) + "\n… %d more lines" % (lines.size() - MAX_BODY_LINES)