"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/
Python
fix: address review feedback on Godot CLI harness
Ömer8047ff9b86df
diff --git a/godot/agent-harness/GODOT.md b/godot/agent-harness/GODOT.mdindex f42749670..b2c8d4bc8 100644--- a/godot/agent-harness/GODOT.md+++ b/godot/agent-harness/GODOT.md@@ -34,3 +34,13 @@ Godot Engine is a feature-rich open-source game engine with strong CLI support v2. **Scene file I/O** — `.tscn` is a human-readable text format. We parse and generate it directly for scene operations instead of requiring Godot to be running.3. **Project file parsing** — `project.godot` is INI-like. We read it with string parsing rather than requiring the engine.4. **Temp scripts** — `script inline` writes a temporary `.gd` file inside the project (required for `res://` resolution), runs it, then cleans up.++## Security++- **`script inline`**: The provided GDScript code is written to a temporary file inside the project directory and executed via `godot --headless --script`. The temp file is deleted after execution. This command executes arbitrary code on the host machine — only use with trusted input. In an agent context, the agent is responsible for ensuring the code it generates is safe.++## Version Compatibility++- **`--export-all`** is available in Godot **4.3+**. Earlier 4.x versions require exporting each preset individually with `--export-release <preset>`.+- **`--check-only`** for script validation may not be available in all Godot 4.x versions.+- Binary discovery searches for `godot`, `godot4`, and common versioned binary names. Set `GODOT_BIN` for non-standard installations.diff --git a/godot/agent-harness/cli_anything/godot/README.md b/godot/agent-harness/cli_anything/godot/README.mdindex d08fd4d3f..791038e8f 100644--- a/godot/agent-harness/cli_anything/godot/README.md+++ b/godot/agent-harness/cli_anything/godot/README.md@@ -57,3 +57,12 @@ cli-anything-godot -p ./my-game session| `script` | run, inline, validate | GDScript execution || `engine` | version, status | Engine info || `session` | (REPL) | Interactive mode |++## Security Note++The `script inline` command writes user-provided GDScript to a temp file and executes it via Godot subprocess. This runs arbitrary code on the host — only use with trusted input.++## Version Compatibility++- `export build` without `--preset` uses `--export-all` (Godot 4.3+). For older 4.x, specify `--preset` explicitly.+- Set `GODOT_BIN` environment variable if your Godot binary has a non-standard name.diff --git a/godot/agent-harness/cli_anything/godot/core/export.py b/godot/agent-harness/cli_anything/godot/core/export.pyindex 06c7fe096..8baf4a3a5 100644--- a/godot/agent-harness/cli_anything/godot/core/export.py+++ b/godot/agent-harness/cli_anything/godot/core/export.py@@ -1,4 +1,9 @@-"""Godot project export — build game binaries for target platforms."""+"""Godot project export — build game binaries for target platforms.++Note: --export-all is available in Godot 4.3+. Earlier 4.x versions+use --export-release/--export-debug per preset. If export-all fails,+fall back to exporting each preset individually.+"""from pathlib import Pathdiff --git a/godot/agent-harness/cli_anything/godot/core/scene.py b/godot/agent-harness/cli_anything/godot/core/scene.pyindex 873c0d51e..e8c6529d3 100644--- a/godot/agent-harness/cli_anything/godot/core/scene.py+++ b/godot/agent-harness/cli_anything/godot/core/scene.py@@ -147,10 +147,9 @@ def add_node(# ---------- internal helpers ----------def _generate_uid() -> str:- """Generate a simple pseudo-UID for scene files."""- import random- chars = "abcdefghijklmnopqrstuvwxyz0123456789"- return "".join(random.choices(chars, k=12))+ """Generate a UID for scene files using uuid4 for uniqueness."""+ import uuid+ return uuid.uuid4().hex[:12]def _parse_tag_attrs(attr_string: str) -> dict:diff --git a/godot/agent-harness/cli_anything/godot/godot_cli.py b/godot/agent-harness/cli_anything/godot/godot_cli.pyindex 7f9a3c0f8..88cb60786 100644--- a/godot/agent-harness/cli_anything/godot/godot_cli.py+++ b/godot/agent-harness/cli_anything/godot/godot_cli.py@@ -22,17 +22,12 @@ from cli_anything.godot.utils.godot_backend import (find_godot_binary,)-# ── Global state ───────────────────────────────────────────────────────-_json_output = False-_repl_mode = False-_project_path: str | None = None-# ── Output helpers ─────────────────────────────────────────────────────-def _out(data: dict) -> None:- """Print result as JSON or human-readable."""- if _json_output:+def _out(ctx, data: dict) -> None:+ """Print result as JSON or human-readable based on context."""+ if ctx.obj.get("json"):click.echo(json_mod.dumps(data, indent=2, ensure_ascii=False))else:status = data.get("status", "")@@ -67,8 +62,9 @@ def _handle_error(func):try:return func(*args, **kwargs)except RuntimeError as e:- _out({"status": "error", "message": str(e)})- if not _repl_mode:+ ctx = click.get_current_context()+ _out(ctx, {"status": "error", "message": str(e)})+ if not ctx.obj.get("repl"):sys.exit(1)return wrapper@@ -81,19 +77,17 @@ def _handle_error(func):@click.pass_contextdef cli(ctx, use_json, project):"""cli-anything-godot — Agent-native CLI for the Godot game engine."""- global _json_output, _project_path- _json_output = use_json- if project:- _project_path = os.path.abspath(project)ctx.ensure_object(dict)- ctx.obj["project"] = _project_path+ ctx.obj["json"] = use_json+ ctx.obj["project"] = os.path.abspath(project) if project else None+ ctx.obj["repl"] = ctx.obj.get("repl", False)if ctx.invoked_subcommand is None:click.echo(ctx.get_help())def _get_project(ctx) -> str:- """Resolve project path from context, global, or cwd."""- p = ctx.obj.get("project") or _project_path or os.getcwd()+ """Resolve project path from context or cwd."""+ p = ctx.obj.get("project") or os.getcwd()return os.path.abspath(p)@@ -114,7 +108,7 @@ def project(ctx):def project_create(ctx, path, name):"""Create a new Godot project at PATH."""from cli_anything.godot.core.project import create_project- _out(create_project(os.path.abspath(path), name))+ _out(ctx, create_project(os.path.abspath(path), name))@project.command("info")@@ -123,7 +117,7 @@ def project_create(ctx, path, name):def project_info(ctx):"""Show project metadata from project.godot."""from cli_anything.godot.core.project import get_project_info- _out(get_project_info(_get_project(ctx)))+ _out(ctx, get_project_info(_get_project(ctx)))@project.command("scenes")@@ -132,7 +126,7 @@ def project_info(ctx):def project_scenes(ctx):"""List all scene files (.tscn, .scn) in the project."""from cli_anything.godot.core.project import list_scenes- _out(list_scenes(_get_project(ctx)))+ _out(ctx, list_scenes(_get_project(ctx)))@project.command("scripts")@@ -141,7 +135,7 @@ def project_scenes(ctx):def project_scripts(ctx):"""List all GDScript files (.gd) in the project."""from cli_anything.godot.core.project import list_scripts- _out(list_scripts(_get_project(ctx)))+ _out(ctx, list_scripts(_get_project(ctx)))@project.command("resources")@@ -150,7 +144,7 @@ def project_scripts(ctx):def project_resources(ctx):"""List all resource files (.tres, .res) in the project."""from cli_anything.godot.core.project import list_resources- _out(list_resources(_get_project(ctx)))+ _out(ctx, list_resources(_get_project(ctx)))@project.command("reimport")@@ -159,7 +153,7 @@ def project_resources(ctx):def project_reimport(ctx):"""Force re-import of all project resources via Godot."""from cli_anything.godot.core.project import reimport_project- _out(reimport_project(_get_project(ctx)))+ _out(ctx, reimport_project(_get_project(ctx)))# ── Scene commands ─────────────────────────────────────────────────────@@ -180,7 +174,7 @@ def scene(ctx):def scene_create(ctx, scene_path, root_type, root_name):"""Create a new .tscn scene file at SCENE_PATH (relative to project)."""from cli_anything.godot.core.scene import create_scene- _out(create_scene(_get_project(ctx), scene_path, root_type, root_name))+ _out(ctx, create_scene(_get_project(ctx), scene_path, root_type, root_name))@scene.command("read")@@ -190,7 +184,7 @@ def scene_create(ctx, scene_path, root_type, root_name):def scene_read(ctx, scene_path):"""Parse and display the node tree of a .tscn scene."""from cli_anything.godot.core.scene import read_scene- _out(read_scene(_get_project(ctx), scene_path))+ _out(ctx, read_scene(_get_project(ctx), scene_path))@scene.command("add-node")@@ -203,7 +197,7 @@ def scene_read(ctx, scene_path):def scene_add_node(ctx, scene_path, node_name, node_type, parent):"""Add a child node to an existing scene."""from cli_anything.godot.core.scene import add_node- _out(add_node(_get_project(ctx), scene_path, node_name, node_type, parent))+ _out(ctx, add_node(_get_project(ctx), scene_path, node_name, node_type, parent))# ── Export commands ────────────────────────────────────────────────────@@ -216,7 +210,7 @@ def export_group(ctx):@export_group.command("build")[email protected]("--preset", default=None, help="Export preset name. Omit to export all.")[email protected]("--preset", default=None, help="Export preset name. Omit to export all (Godot 4.3+).")@click.option("--output", default=None, help="Output file path.")@click.option("--debug", is_flag=True, help="Use debug export instead of release.")@click.pass_context@@ -224,7 +218,7 @@ def export_group(ctx):def export_build(ctx, preset, output, debug):"""Build/export the project using configured presets."""from cli_anything.godot.core.export import export_project- _out(export_project(_get_project(ctx), preset, output, debug))+ _out(ctx, export_project(_get_project(ctx), preset, output, debug))@export_group.command("presets")@@ -233,7 +227,7 @@ def export_build(ctx, preset, output, debug):def export_presets(ctx):"""List configured export presets."""from cli_anything.godot.core.export import list_export_presets- _out(list_export_presets(_get_project(ctx)))+ _out(ctx, list_export_presets(_get_project(ctx)))# ── Script commands ────────────────────────────────────────────────────@@ -253,7 +247,7 @@ def script(ctx):def script_run(ctx, script_path, timeout):"""Execute a GDScript file in headless mode. Must extend SceneTree."""from cli_anything.godot.core.script import run_script- _out(run_script(_get_project(ctx), script_path, timeout))+ _out(ctx, run_script(_get_project(ctx), script_path, timeout))@script.command("inline")@@ -262,9 +256,13 @@ def script_run(ctx, script_path, timeout):@click.pass_context@_handle_errordef script_inline(ctx, code, timeout):- """Run inline GDScript code (wrapped in SceneTree._init)."""+ """Run inline GDScript code (wrapped in SceneTree._init).++ Security: The provided code is written to a temp file and executed via+ Godot subprocess. Only use with trusted input.+ """from cli_anything.godot.core.script import run_inline- _out(run_inline(_get_project(ctx), code, timeout))+ _out(ctx, run_inline(_get_project(ctx), code, timeout))@script.command("validate")@@ -274,7 +272,7 @@ def script_inline(ctx, code, timeout):def script_validate(ctx, script_path):"""Validate GDScript syntax without executing."""from cli_anything.godot.core.script import validate_script- _out(validate_script(_get_project(ctx), script_path))+ _out(ctx, validate_script(_get_project(ctx), script_path))# ── Engine commands ────────────────────────────────────────────────────@@ -287,19 +285,21 @@ def engine(ctx):@engine.command("version")[email protected]_context@_handle_error-def engine_version():+def engine_version(ctx):"""Show Godot engine version."""- _out(get_version())+ _out(ctx, get_version())@engine.command("status")[email protected]_context@_handle_error-def engine_status():+def engine_status(ctx):"""Check if Godot binary is available."""available = is_available()binary = find_godot_binary()- _out({+ _out(ctx, {"status": "ok","available": available,"binary": binary or "not found",@@ -312,8 +312,7 @@ def engine_status():@click.pass_contextdef session(ctx):"""Start an interactive REPL session."""- global _repl_mode- _repl_mode = True+ ctx.obj["repl"] = Truetry:from cli_anything.godot.utils.repl_skin import ReplSkin@@ -328,7 +327,8 @@ def session(ctx):from prompt_toolkit.history import InMemoryHistoryprompt_session = PromptSession(history=InMemoryHistory())- project_name = os.path.basename(_project_path) if _project_path else "no-project"+ project_path = ctx.obj.get("project")+ project_name = os.path.basename(project_path) if project_path else "no-project"while True:try:@@ -354,7 +354,7 @@ def session(ctx):continuetry:- cli.main(args=args, standalone_mode=False)+ cli.main(args=args, standalone_mode=False, obj=ctx.obj)except SystemExit:passexcept click.exceptions.UsageError as e:@@ -370,8 +370,6 @@ def session(ctx):else:click.echo("Goodbye.")- _repl_mode = False-# ── Entry point ────────────────────────────────────────────────────────diff --git a/godot/agent-harness/cli_anything/godot/tests/test_full_e2e.py b/godot/agent-harness/cli_anything/godot/tests/test_full_e2e.pynew file mode 100644index 000000000..8935faded--- /dev/null+++ b/godot/agent-harness/cli_anything/godot/tests/test_full_e2e.py@@ -0,0 +1,137 @@+"""End-to-end tests for cli-anything-godot.++These tests require Godot 4.x to be installed and on PATH.+They are automatically skipped when the binary is not available.+Run explicitly with: pytest -m e2e+"""++import json++import pytest+from click.testing import CliRunner++from cli_anything.godot.godot_cli import cli+from cli_anything.godot.utils.godot_backend import is_available+++_godot_missing = not is_available()+skip_no_godot = pytest.mark.skipif(+ _godot_missing, reason="Godot binary not found on PATH"+)+++def runner():+ return CliRunner()+++def e2e_project(tmp_path):+ """Create a real Godot project for E2E tests."""+ runner = CliRunner()+ runner.invoke(cli, ["project", "create", str(tmp_path / "e2e_game"), "--name", "E2E Game"])+ return tmp_path / "e2e_game"+++@skip_no_godot+class TestE2EEngineVersion:+ def test_version(self, runner):+ result = runner.invoke(cli, ["--json", "engine", "version"])+ assert result.exit_code == 0+ data = json.loads(result.output)+ assert "version" in data++ def test_status(self, runner):+ result = runner.invoke(cli, ["--json", "engine", "status"])+ data = json.loads(result.output)+ assert data["available"] is True+++@skip_no_godot+class TestE2EProject:+ def test_create_and_info(self, runner, tmp_path):+ project_dir = tmp_path / "test_game"+ result = runner.invoke(cli, [+ "--json", "project", "create", str(project_dir), "--name", "Test Game"+ ])+ data = json.loads(result.output)+ assert data["status"] == "ok"++ result = runner.invoke(cli, ["--json", "-p", str(project_dir), "project", "info"])+ data = json.loads(result.output)+ assert data["name"] == "Test Game"++ def test_reimport(self, runner, e2e_project):+ result = runner.invoke(cli, ["--json", "-p", str(e2e_project), "project", "reimport"])+ data = json.loads(result.output)+ assert "status" in data+++@skip_no_godot+class TestE2EScene:+ def test_create_and_read(self, runner, e2e_project):+ result = runner.invoke(cli, [+ "--json", "-p", str(e2e_project),+ "scene", "create", "scenes/TestScene.tscn",+ "--root-type", "Node2D",+ ])+ data = json.loads(result.output)+ assert data["status"] == "ok"++ result = runner.invoke(cli, [+ "--json", "-p", str(e2e_project),+ "scene", "read", "scenes/TestScene.tscn",+ ])+ data = json.loads(result.output)+ assert data["status"] == "ok"+ assert len(data["nodes"]) >= 1++ def test_add_node_and_verify(self, runner, e2e_project):+ runner.invoke(cli, [+ "-p", str(e2e_project),+ "scene", "create", "scenes/NodeTest.tscn",+ ])+ result = runner.invoke(cli, [+ "--json", "-p", str(e2e_project),+ "scene", "add-node", "scenes/NodeTest.tscn",+ "--name", "Sprite", "--type", "Sprite2D",+ ])+ data = json.loads(result.output)+ assert data["status"] == "ok"++ result = runner.invoke(cli, [+ "--json", "-p", str(e2e_project),+ "scene", "read", "scenes/NodeTest.tscn",+ ])+ data = json.loads(result.output)+ node_names = [n.get("name") for n in data["nodes"]]+ assert "Sprite" in node_names+++@skip_no_godot+class TestE2EScript:+ def test_run_script(self, runner, e2e_project):+ script_path = e2e_project / "tool_test.gd"+ script_path.write_text(+ 'extends SceneTree\n\n'+ 'func _init():\n'+ '\tprint("Hello from CLI-Anything!")\n'+ '\tquit()\n',+ encoding="utf-8",+ )+ result = runner.invoke(cli, [+ "--json", "-p", str(e2e_project),+ "script", "run", "tool_test.gd",+ ])+ data = json.loads(result.output)+ assert "status" in data+ if data["status"] == "ok":+ assert "Hello from CLI-Anything!" in data.get("stdout", "")++ def test_inline_script(self, runner, e2e_project):+ result = runner.invoke(cli, [+ "--json", "-p", str(e2e_project),+ "script", "inline", 'print("inline test")',+ ])+ data = json.loads(result.output)+ assert "status" in datadiff --git a/godot/agent-harness/cli_anything/godot/utils/repl_skin.py b/godot/agent-harness/cli_anything/godot/utils/repl_skin.pyindex b356cb835..de9884a0f 100644--- a/godot/agent-harness/cli_anything/godot/utils/repl_skin.py+++ b/godot/agent-harness/cli_anything/godot/utils/repl_skin.py@@ -48,6 +48,7 @@ _ACCENT_COLORS = {"kdenlive": "\033[38;5;69m", # slate blue"shotcut": "\033[38;5;35m", # teal green"ollama": "\033[38;5;255m", # white (Ollama branding)+ "godot": "\033[38;5;74m", # Godot blue (#478cbf)}_DEFAULT_ACCENT = "\033[38;5;75m" # default sky blue