Replace dasher-pack with unified animation-pack using original Blender bone names
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
@tool
|
||||
extends Logger
|
||||
|
||||
## Editor-process Logger subclass.
|
||||
##
|
||||
## NOTE: deliberately no `class_name` — `extends Logger` requires the Logger
|
||||
## class which Godot only exposes from 4.5+. This file lives in the
|
||||
## `.gdignore`'d `runtime/loggers/` folder so Godot's editor filesystem scan
|
||||
## skips it entirely — on Godot < 4.5 it is never parsed, so it emits no
|
||||
## "Could not find base class Logger" error (it used to, before #475's
|
||||
## follow-up). plugin.gd builds it from source at runtime via
|
||||
## `logger_loader.gd` and only calls OS.add_logger() after gating on
|
||||
## ClassDB.class_exists("Logger"), so the `extends Logger` parse only ever
|
||||
## happens on 4.5+ where it resolves. Registered from plugin.gd::_enter_tree
|
||||
## so we can intercept editor-process script errors — parse errors, @tool
|
||||
## runtime errors, EditorPlugin errors, push_error/push_warning — and
|
||||
## surface them via `logs_read(source="editor")`. Without this, the LLM
|
||||
## sees nothing in `logs_read` while the same errors show in red lines in
|
||||
## Godot's Output panel.
|
||||
##
|
||||
## Why only `_log_error` and not `_log_message`:
|
||||
## `_log_message(msg, error)` covers print() and printerr(), which is the
|
||||
## firehose path — running editors print thousands of internal info lines
|
||||
## a session. The issue (#231) explicitly asks to filter so the buffer
|
||||
## isn't drowned. Errors and warnings flow through `_log_error` (parse
|
||||
## errors, push_error/push_warning, runtime errors), which is what
|
||||
## debugging callers actually need. If we discover @tool printerr() is a
|
||||
## valuable source later, _log_message can be added behind the same filter.
|
||||
##
|
||||
## Logger virtuals can be called from any thread (e.g. async script
|
||||
## loaders push parse errors off the main thread). McpEditorLogBuffer is
|
||||
## mutex-protected so we can append directly without an intermediate queue.
|
||||
|
||||
const ADDON_PATH_MARKER := "/addons/godot_ai/"
|
||||
|
||||
## Resolve McpLogBacktrace by path, not by the `McpLogBacktrace` class_name.
|
||||
## This script is compiled from source at runtime by logger_loader.gd; a bare
|
||||
## class_name reference depends on the global class-name table being populated
|
||||
## at compile time, which isn't guaranteed on a cold editor enable mid-scan.
|
||||
## `const preload` resolves at compile time independent of the registry —
|
||||
## matches game_logger.gd's deliberate choice for the same reason.
|
||||
const _LogBacktrace := preload("res://addons/godot_ai/utils/log_backtrace.gd")
|
||||
|
||||
## McpEditorLogBuffer — untyped because this script is loaded dynamically and
|
||||
## McpEditorLogBuffer's class_name isn't yet registered on the parser at the
|
||||
## time `extends Logger` resolves. Constructor-injected so the hot path
|
||||
## doesn't need a per-call null check.
|
||||
var _buffer
|
||||
|
||||
|
||||
func _init(buffer = null) -> void:
|
||||
_buffer = buffer
|
||||
|
||||
|
||||
func _log_error(
|
||||
function: String,
|
||||
file: String,
|
||||
line: int,
|
||||
code: String,
|
||||
rationale: String,
|
||||
_editor_notify: bool,
|
||||
error_type: int,
|
||||
script_backtraces: Array,
|
||||
) -> void:
|
||||
if _buffer == null:
|
||||
return
|
||||
## Cheap reject for the firehose: when `file` is already non-user (the
|
||||
## bulk of editor-internal C++ chatter), there's no backtrace to remap
|
||||
## from, and the message doesn't name a project resource, the resolved
|
||||
## path can only stay non-user — drop without paying for resolve_error's
|
||||
## call frame + dict allocation.
|
||||
var message := rationale if not rationale.is_empty() else code
|
||||
var message_res_path := _extract_user_res_path(message)
|
||||
if not _is_user_script(file) and script_backtraces.is_empty() and message_res_path.is_empty():
|
||||
return
|
||||
var resolved := _LogBacktrace.resolve_error(
|
||||
function, file, line, code, rationale, error_type, script_backtraces,
|
||||
)
|
||||
if not _is_user_script(resolved.path):
|
||||
if message_res_path.is_empty():
|
||||
return
|
||||
resolved.path = message_res_path
|
||||
resolved.line = 0
|
||||
resolved.function = function
|
||||
_update_resolved_details(resolved)
|
||||
if _is_in_godot_ai_addon(resolved.path):
|
||||
return
|
||||
if not message_res_path.is_empty() and _is_in_godot_ai_addon(message_res_path):
|
||||
return
|
||||
var details: Dictionary = resolved.get("details", {})
|
||||
_buffer.append(resolved.level, resolved.message, resolved.path, resolved.line, resolved.function, details)
|
||||
|
||||
|
||||
static func _update_resolved_details(resolved: Dictionary) -> void:
|
||||
var details: Dictionary = resolved.get("details", {})
|
||||
if details.is_empty():
|
||||
return
|
||||
details["resolved"] = {
|
||||
"path": resolved.get("path", ""),
|
||||
"line": resolved.get("line", 0),
|
||||
"function": resolved.get("function", ""),
|
||||
}
|
||||
resolved["details"] = details
|
||||
|
||||
|
||||
## Predicate broken out so tests can drive the path-filter logic without
|
||||
## constructing real Logger calls.
|
||||
static func _is_user_script(path: String) -> bool:
|
||||
if path.is_empty():
|
||||
return false
|
||||
## Match .gd / .cs (case-insensitively to handle .GD on case-insensitive
|
||||
## filesystems). C# scripts compile elsewhere but the parser path can
|
||||
## still surface .cs files for assembly load failures.
|
||||
var lower := path.to_lower()
|
||||
return lower.ends_with(".gd") or lower.ends_with(".cs")
|
||||
|
||||
|
||||
## Path-substring check works for both `res://addons/godot_ai/foo.gd` and
|
||||
## globalized absolute paths (`/Users/.../addons/godot_ai/foo.gd`) that
|
||||
## Godot can also report depending on where the error originated.
|
||||
static func _is_in_godot_ai_addon(path: String) -> bool:
|
||||
if path.begins_with("res://addons/godot_ai/"):
|
||||
return true
|
||||
return path.find(ADDON_PATH_MARKER) >= 0
|
||||
|
||||
|
||||
## Some engine-origin errors have no ScriptBacktrace even though they are
|
||||
## project-relevant, notably ResourceLoader failures:
|
||||
## `Failed loading resource: res://does/not/exist.tres.`. Capture these by
|
||||
## extracting a named `res://` path from the message while keeping editor
|
||||
## internals and this addon's own resources filtered.
|
||||
static func _extract_user_res_path(message: String) -> String:
|
||||
var start := message.find("res://")
|
||||
if start < 0:
|
||||
return ""
|
||||
var end := message.length()
|
||||
var quote_end := message.find("'", start)
|
||||
if quote_end >= 0:
|
||||
end = mini(end, quote_end)
|
||||
quote_end = message.find("\"", start)
|
||||
if quote_end >= 0:
|
||||
end = mini(end, quote_end)
|
||||
quote_end = message.find("`", start)
|
||||
if quote_end >= 0:
|
||||
end = mini(end, quote_end)
|
||||
var path := message.substr(start, end - start).strip_edges()
|
||||
while not path.is_empty() and path.substr(path.length() - 1, 1) in [".", ",", ";", ":", ")"]:
|
||||
path = path.substr(0, path.length() - 1)
|
||||
if path.is_empty() or _is_in_godot_ai_addon(path):
|
||||
return ""
|
||||
return path
|
||||
@@ -0,0 +1,158 @@
|
||||
@tool
|
||||
extends Logger
|
||||
|
||||
## Game-process Logger subclass.
|
||||
##
|
||||
## NOTE: deliberately no `class_name` — `extends Logger` requires the Logger
|
||||
## class which Godot only exposes from 4.5+. This file lives in the
|
||||
## `.gdignore`'d `runtime/loggers/` folder so Godot's editor filesystem scan
|
||||
## skips it entirely — on Godot < 4.5 it is never parsed, so it emits no
|
||||
## "Could not find base class Logger" error (it used to, before #475's
|
||||
## follow-up). game_helper.gd builds it from source at runtime via
|
||||
## `logger_loader.gd` and only calls OS.add_logger() after gating on
|
||||
## ClassDB.class_exists("Logger"). Registered from inside the running game
|
||||
## so we can intercept print(), printerr(), push_error(), and
|
||||
## push_warning() and ferry them back to the editor over the
|
||||
## EngineDebugger channel — the same bridge PR #76 uses for screenshots.
|
||||
##
|
||||
## Logger virtuals can be called from any thread (e.g. async loaders push
|
||||
## errors off the main thread). We accumulate into _pending under a Mutex
|
||||
## and the host (game_helper.gd) flushes once per frame from the main
|
||||
## thread, where EngineDebugger.send_message is safe to call.
|
||||
|
||||
## `McpLogBacktrace` is published as a `class_name` on log_backtrace.gd, but a
|
||||
## freshly-launched game subprocess (no prior editor scan; e.g. CI launching
|
||||
## `--headless --path`) hits this autoload before the global class_name table
|
||||
## is populated, and parsing this script fails with
|
||||
## "Identifier 'McpLogBacktrace' not declared in the current scope". Using
|
||||
## `const preload` resolves the path at parse time and is independent of the
|
||||
## class_name registry — matches the project convention in CLAUDE.md
|
||||
## ("Internals … skip class_name entirely and load via const preload").
|
||||
const _LogBacktrace := preload("res://addons/godot_ai/utils/log_backtrace.gd")
|
||||
|
||||
var _pending: Array = []
|
||||
var _mutex := Mutex.new()
|
||||
## #490: a monotonic sequence + a small ring of recent GDScript runtime
|
||||
## (script-type) errors, each with its text AND the function names in its
|
||||
## backtrace. game_helper uses this to attribute a runtime error to the
|
||||
## *specific* eval that raised it: each eval's wrapper has a uniquely named
|
||||
## inner function, and game_helper asks find_script_error_since() whether any
|
||||
## error past its pre-eval baseline carries that function in its stack. This
|
||||
## avoids failing an eval on an unrelated background game error that merely
|
||||
## advanced a global counter, and keeps overlapping evals from cross-
|
||||
## attributing. Gated on ERROR_TYPE_SCRIPT (2) so push_error()/push_warning()
|
||||
## (types 0/1) never count. Mutex-guarded: _log_error can fire from any thread.
|
||||
const _ERROR_TYPE_SCRIPT := 2
|
||||
const _MAX_RECENT_SCRIPT_ERRORS := 64
|
||||
var _script_error_seq: int = 0
|
||||
var _recent_script_errors: Array = []
|
||||
|
||||
|
||||
func _log_message(message: String, error: bool) -> void:
|
||||
## `error` is true for printerr(), false for print().
|
||||
var level := "error" if error else "info"
|
||||
_append(level, message)
|
||||
|
||||
|
||||
func _log_error(
|
||||
function: String,
|
||||
file: String,
|
||||
line: int,
|
||||
code: String,
|
||||
rationale: String,
|
||||
_editor_notify: bool,
|
||||
error_type: int,
|
||||
script_backtraces: Array,
|
||||
) -> void:
|
||||
## EngineDebugger's payload shape is `[level, text]` — the source
|
||||
## location has nowhere structured to land for the game side, so we
|
||||
## inline it into `text`. editor_logger keeps the resolved fields
|
||||
## as structured columns instead.
|
||||
var resolved := _LogBacktrace.resolve_error(
|
||||
function, file, line, code, rationale, error_type, script_backtraces,
|
||||
)
|
||||
var loc := ""
|
||||
if not resolved.path.is_empty():
|
||||
loc = "%s:%d @ %s" % [resolved.path, resolved.line, resolved.function] if not resolved.function.is_empty() else "%s:%d" % [resolved.path, resolved.line]
|
||||
var text: String = "%s (%s)" % [resolved.message, loc] if not loc.is_empty() else resolved.message
|
||||
var details: Dictionary = resolved.get("details", {})
|
||||
_append(resolved.level, text, details)
|
||||
if error_type == _ERROR_TYPE_SCRIPT:
|
||||
## Collect every function name in the first non-empty backtrace so
|
||||
## game_helper can match its eval's uniquely named wrapper function.
|
||||
var funcs := PackedStringArray()
|
||||
for bt in script_backtraces:
|
||||
if bt != null and bt.get_frame_count() > 0:
|
||||
for i in bt.get_frame_count():
|
||||
funcs.append(bt.get_frame_function(i))
|
||||
break
|
||||
_mutex.lock()
|
||||
_script_error_seq += 1
|
||||
_recent_script_errors.append({"seq": _script_error_seq, "text": text, "funcs": funcs})
|
||||
if _recent_script_errors.size() > _MAX_RECENT_SCRIPT_ERRORS:
|
||||
_recent_script_errors.remove_at(0)
|
||||
_mutex.unlock()
|
||||
|
||||
|
||||
func _append(level: String, text: String, details: Dictionary = {}) -> void:
|
||||
_mutex.lock()
|
||||
if details.is_empty():
|
||||
_pending.append([level, text])
|
||||
else:
|
||||
_pending.append([level, text, details.duplicate(true)])
|
||||
_mutex.unlock()
|
||||
|
||||
|
||||
## Drain the pending queue and return entries as [[level, text], ...].
|
||||
## Called from the main thread by game_helper each frame.
|
||||
func drain() -> Array:
|
||||
_mutex.lock()
|
||||
var out := _pending
|
||||
_pending = []
|
||||
_mutex.unlock()
|
||||
return out
|
||||
|
||||
|
||||
func has_pending() -> bool:
|
||||
_mutex.lock()
|
||||
var any := not _pending.is_empty()
|
||||
_mutex.unlock()
|
||||
return any
|
||||
|
||||
|
||||
## #490: monotonic count of script-type runtime errors seen this run.
|
||||
## game_helper snapshots this before an eval to use as the `since_seq`
|
||||
## baseline for find_script_error_since(). Mutex-guarded.
|
||||
func script_error_seq() -> int:
|
||||
_mutex.lock()
|
||||
var v := _script_error_seq
|
||||
_mutex.unlock()
|
||||
return v
|
||||
|
||||
|
||||
## #490: text (with inlined path:line @ function) of the most recent
|
||||
## script-type runtime error, or "" if none seen this run.
|
||||
func last_script_error_text() -> String:
|
||||
_mutex.lock()
|
||||
var v: String = _recent_script_errors[-1]["text"] if not _recent_script_errors.is_empty() else ""
|
||||
_mutex.unlock()
|
||||
return v
|
||||
|
||||
|
||||
## #490: text of the most recent script error with seq > since_seq whose
|
||||
## backtrace includes `function_name`, or "" if none. Lets game_helper
|
||||
## attribute a runtime error to the exact eval whose uniquely named wrapper
|
||||
## function appears in the stack — ignoring unrelated game errors and errors
|
||||
## from before the eval started. Mutex-guarded.
|
||||
func find_script_error_since(since_seq: int, function_name: String) -> String:
|
||||
_mutex.lock()
|
||||
var found := ""
|
||||
for i in range(_recent_script_errors.size() - 1, -1, -1):
|
||||
var rec: Dictionary = _recent_script_errors[i]
|
||||
if int(rec["seq"]) <= since_seq:
|
||||
break
|
||||
if (rec["funcs"] as PackedStringArray).has(function_name):
|
||||
found = rec["text"]
|
||||
break
|
||||
_mutex.unlock()
|
||||
return found
|
||||
Reference in New Issue
Block a user