Files
RoboMovel/simulacao/robo-movel-godot/addons/claude_godot/ui/task_strip.gd
T
mguinhos d17575771b Projeto: app demo, servidor/firmware em software/, simulacao Godot, planta do bloco D, chapas MDF da base, renders e slides
- app/: app demo (Kivy/buildozer) da API do robo
- software/: servidor RoboMovel (SLAM, profundidade, navegacao) e firmware da base movel (movido de firmware/)
- simulacao/: projeto Godot do robo e script de lancamento servidor + simulacao
- modelos/: planta do 5o andar do bloco D, cena Blender do corredor e modelo real do robo
- partes/mdf/: chapas identificadas e nesting da base do robo (DXF/SVG/FCStd)
- projeto/render, relatorio/imagens, slides: renders finais e apresentacoes de progresso
- ferramentas/scripts: encaixe de chapas, planta do bloco D e render do corredor no Blender
- .gitignore: ignora backups do Blender/FreeCAD e .godot/
2026-10-25 23:38:16 -03:00

167 lines
5.3 KiB
GDScript

## The background tasks, above the input box: one line each, expandable.
##
## A background run has no transcript in the dock — its conversation is its
## own — so this strip is the only place the user sees that something is
## happening on their project without them. That makes visibility the point:
## it hides itself when there is nothing running, and refuses to hide a
## failure.
@tool
class_name ClaudeGodotTaskStrip
extends VBoxContainer
const COLOR_RUNNING := "#e8a33d"
const COLOR_OK := "#4caf50"
const COLOR_FAIL := "#f44336"
const COLOR_DIM := "#8a8a8a"
## The trail can run to eighty entries; the strip shows the tail of it. The
## whole thing is still in the task tool for the agent.
const VISIBLE_ENTRIES := 8
## Task id -> whether the user opened that row. Kept here rather than on the
## run so a rebuild doesn't collapse everything the user had open.
var _expanded: Dictionary = {}
## Task id -> the header label, so the once-a-second clock tick can rewrite a
## line of text instead of rebuilding every row.
var _headers: Dictionary = {}
var _clock: Timer
func _ready() -> void:
_clock = Timer.new()
_clock.wait_time = 1.0
_clock.timeout.connect(_tick)
add_child(_clock)
func refresh() -> void:
var runs: Array = ClaudeGodotBackgroundTasks.all()
visible = not runs.is_empty()
_headers.clear()
for child in get_children():
if child != _clock:
child.queue_free()
if runs.is_empty():
if _clock:
_clock.stop()
return
# Newest first: a task just started is the one being watched.
runs.reverse()
for run in runs:
add_child(_build_row(run))
if _clock:
if ClaudeGodotBackgroundTasks.running().is_empty():
_clock.stop()
elif _clock.is_stopped():
_clock.start()
## Only the headers, and only their text: a full rebuild once a second would
## fight the user for the scroll position and the expand toggles.
func _tick() -> void:
var still_running := false
for id in _headers:
var run := ClaudeGodotBackgroundTasks.find(id)
var label: RichTextLabel = _headers[id]
if run == null or not is_instance_valid(label):
continue
label.text = _header_text(run)
still_running = still_running or run.is_running()
if not still_running:
_clock.stop()
func _build_row(run: ClaudeGodotTaskRun) -> Control:
var box := VBoxContainer.new()
var header := HBoxContainer.new()
box.add_child(header)
var toggle := Button.new()
toggle.flat = true
toggle.size_flags_horizontal = Control.SIZE_EXPAND_FILL
toggle.custom_minimum_size = Vector2(0, 22)
toggle.pressed.connect(func(): _toggle(run.id))
header.add_child(toggle)
# Same trick as the tool cards: a Button can't render BBCode, so a
# click-through label is drawn over it to carry the colour.
var label := RichTextLabel.new()
label.bbcode_enabled = true
label.scroll_active = false
label.fit_content = true
label.mouse_filter = Control.MOUSE_FILTER_IGNORE
label.set_anchors_preset(Control.PRESET_FULL_RECT)
label.text = _header_text(run)
toggle.add_child(label)
_headers[run.id] = label
if run.is_running():
var stop := Button.new()
stop.text = "✕"
stop.flat = true
stop.tooltip_text = "Stop this background task. It stops after the model call it is in the middle of; anything it already wrote stays written."
stop.pressed.connect(func(): run.stop())
header.add_child(stop)
if _expanded.get(run.id, false):
box.add_child(_build_detail(run))
return box
func _build_detail(run: ClaudeGodotTaskRun) -> Control:
var detail := RichTextLabel.new()
detail.bbcode_enabled = true
detail.fit_content = true
detail.selection_enabled = true
detail.add_theme_font_size_override("normal_font_size", 10)
var lines: Array = ["[color=%s]%s[/color]" % [COLOR_DIM, _escape(run.brief)]]
var tail: Array = run.entries.slice(maxi(run.entries.size() - VISIBLE_ENTRIES, 0))
for entry in tail:
var color := COLOR_DIM
var glyph := "·"
match entry["kind"]:
"tool":
glyph = "⚙"
"error":
glyph = "✗"
color = COLOR_FAIL
lines.append("[color=%s]%s %s[/color]" % [color, glyph, _escape(_one_line(entry["text"]))])
if not run.is_running() and run.summary != "":
lines.append("")
lines.append(_escape(run.summary))
detail.text = "\n".join(lines)
return detail
func _header_text(run: ClaudeGodotTaskRun) -> String:
var glyph := "[color=%s]●[/color]" % COLOR_RUNNING
var status := "[color=%s]%d step%s · %ds[/color]" % [
COLOR_DIM, run.steps, "" if run.steps == 1 else "s", run.elapsed_seconds(),
]
match run.state:
ClaudeGodotTaskRun.State.DONE:
glyph = "[color=%s]✓[/color]" % COLOR_OK
ClaudeGodotTaskRun.State.FAILED:
glyph = "[color=%s]✗[/color]" % COLOR_FAIL
status = "[color=%s]failed after %d steps[/color]" % [COLOR_FAIL, run.steps]
ClaudeGodotTaskRun.State.STOPPED:
glyph = "[color=%s]■[/color]" % COLOR_DIM
status = "[color=%s]stopped[/color]" % COLOR_DIM
return "%s %s %s" % [glyph, _escape(run.label), status]
func _toggle(id: String) -> void:
_expanded[id] = not _expanded.get(id, false)
refresh()
## Trail entries are whole tool outputs; a row wants one line of them.
static func _one_line(text: String) -> String:
var flat := text.strip_edges().replace("\n", " ⏎ ")
return flat if flat.length() <= 120 else flat.substr(0, 120) + "…"
## A file path with a [ in it would otherwise open a BBCode tag.
static func _escape(text: String) -> String:
return text.replace("[", "[lb]")