Files
RoboMovel/simulacao/robo-movel-godot/addons/claude_godot/agent/tools/tool_base.gd
T
mguinhosandClaude Opus 5.5 393019705c 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/

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 23:38:16 -03:00

83 lines
3.3 KiB
GDScript

## Base for every tool: one tool per file, each exposing the schema the model
## sees and the code that runs it. The registry in tools.gd instantiates each
## one — instance methods rather than statics, since calling a static through
## a script variable is not dependable across Godot versions.
class_name ClaudeGodotTool
extends RefCounted
## JSON schema the provider is given: {"name", "description", "input_schema"}.
func definition() -> Dictionary:
return {}
## Returns {"content": String} plus optional "is_error": bool, and any extra
## keys the dock wants (write_file and edit_file add "diff_ops").
func execute(_input: Dictionary) -> Dictionary:
return {"is_error": true, "content": "Tool not implemented."}
## Resolves a tool path. Everything is project-relative (res://) except the
## addon's own corner of user://, which holds memory and sessions — those are
## deliberately outside the project so they aren't committed with the game.
## No other part of user:// is reachable, and .. can't climb out of either.
static func resolve_path(path: String) -> String:
if path.begins_with(ClaudeGodotMemory.ROOT):
return path.simplify_path()
if not path.begins_with("res://"):
path = "res://" + path.trim_prefix("/")
return path.simplify_path()
## Shared by the settings-listing tools. `source` is the ProjectSettings
## singleton or an EditorSettings instance; both expose get_property_list().
static func list_settings(source, filter: String) -> Dictionary:
var needle := filter.to_lower()
var names: Array = []
for prop in source.get_property_list():
var n: String = prop.get("name", "")
if n == "":
continue
if needle == "" or n.to_lower().find(needle) != -1:
names.append(n)
names.sort()
var truncated := names.size() > 200
if truncated:
names = names.slice(0, 200)
var out := "\n".join(names) if names.size() > 0 else "(no matches)"
if truncated:
out += "\n… (truncated, use a more specific filter)"
return {"content": out}
## Identifies a file by its leading bytes rather than its extension — a
## screenshot saved as .dat is still a PNG, and a .png that is really text
## should not be announced as an image. Returns {"mime", "label"} for the
## formats the vision APIs accept, or {} for anything else.
static func sniff_image(bytes: PackedByteArray) -> Dictionary:
if bytes.size() < 12:
return {}
if _starts_with(bytes, [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]):
return {"mime": "image/png", "label": "PNG"}
if _starts_with(bytes, [0xFF, 0xD8, 0xFF]):
return {"mime": "image/jpeg", "label": "JPEG"}
if _starts_with(bytes, [0x47, 0x49, 0x46, 0x38]):
return {"mime": "image/gif", "label": "GIF"}
# WebP is a RIFF container: "RIFF" .... "WEBP".
if _starts_with(bytes, [0x52, 0x49, 0x46, 0x46]) and bytes.slice(8, 12).get_string_from_ascii() == "WEBP":
return {"mime": "image/webp", "label": "WebP"}
return {}
## Non-image binary: a NUL byte anywhere early is the classic tell, and no
## text file this tool should return will contain one.
static func looks_binary(bytes: PackedByteArray) -> bool:
var limit: int = mini(bytes.size(), 8192)
for i in range(limit):
if bytes[i] == 0:
return true
return false
static func _starts_with(bytes: PackedByteArray, prefix: Array) -> bool:
if bytes.size() < prefix.size():
return false
for i in range(prefix.size()):
if bytes[i] != prefix[i]:
return false
return true