Skip to content

"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/

Python

fix(renderdoc): address follow-up PR #133 review (Copilot round 2)

alvinshi90c730ddf434
diff --git a/renderdoc/agent-harness/HARNESS.md b/renderdoc/agent-harness/HARNESS.md
index 61f93a5dd..6d5759ae1 100644
--- a/renderdoc/agent-harness/HARNESS.md
+++ b/renderdoc/agent-harness/HARNESS.md
@@ -72,8 +72,9 @@ agent-harness/
No dependency on `renderdoc` module. Uses synthetic data.
- **E2E tests** (`test_full_e2e.py`): Require a real RenderDoc installation and
at least one `.rdc` capture file. Test full CLI invocation via subprocess.
-- **Subprocess tests**: Use `_resolve_cli("cli-anything-renderdoc")` to find the
- installed CLI binary.
+- **Subprocess tests**: Invoke the CLI with
+ `python -m cli_anything.renderdoc.renderdoc_cli` from `agent-harness/` (see
+ `test_core.py` / `test_full_e2e.py`).
## Dependencies
diff --git a/renderdoc/agent-harness/cli_anything/renderdoc/core/capture.py b/renderdoc/agent-harness/cli_anything/renderdoc/core/capture.py
index 4ef46c43b..6c0098a44 100644
--- a/renderdoc/agent-harness/cli_anything/renderdoc/core/capture.py
+++ b/renderdoc/agent-harness/cli_anything/renderdoc/core/capture.py
@@ -36,6 +36,22 @@ def _require_rd():
)
+def _api_properties_summary(props: Any) -> Dict[str, Any]:
+ """JSON-friendly subset of CaptureFile.APIProperties / GetAPIProperties."""
+ out: Dict[str, Any] = {"api": str(props.pipelineType)}
+ if hasattr(props, "degraded"):
+ out["degraded"] = bool(props.degraded)
+ driver = None
+ for attr in ("localRenderer", "vendor"):
+ if hasattr(props, attr):
+ val = getattr(props, attr)
+ if val is not None and str(val):
+ driver = str(val)
+ break
+ out["driver"] = driver if driver is not None else str(props.pipelineType)
+ return out
+
+
# ---------------------------------------------------------------------------
# Global RenderDoc replay API (InitialiseReplay / ShutdownReplay) — refcounted
# ---------------------------------------------------------------------------
@@ -108,14 +124,11 @@ class CaptureHandle:
result: Dict[str, Any] = {"path": self.path}
try:
props = self._cap.APIProperties()
- result["api"] = str(props.pipelineType)
- result["driver"] = str(getattr(props, "degraded", props.pipelineType))
+ result.update(_api_properties_summary(props))
except AttributeError:
- # Fallback: get API info from replay controller
self._ensure_replay()
api_props = self._controller.GetAPIProperties()
- result["api"] = str(api_props.pipelineType)
- result["driver"] = str(api_props.pipelineType)
+ result.update(_api_properties_summary(api_props))
try:
result["replay_supported"] = self._cap.LocalReplaySupport()
except AttributeError:
diff --git a/renderdoc/agent-harness/cli_anything/renderdoc/core/counters.py b/renderdoc/agent-harness/cli_anything/renderdoc/core/counters.py
index f9c1991c3..3f38b0601 100644
--- a/renderdoc/agent-harness/cli_anything/renderdoc/core/counters.py
+++ b/renderdoc/agent-harness/cli_anything/renderdoc/core/counters.py
@@ -53,8 +53,14 @@ def fetch_counters(
else:
return {"error": "No counters available"}
- # Convert int IDs to rd.GPUCounter
- rd_counters = [rd.GPUCounter(c) for c in counter_ids]
+ valid_ids = [int(c) for c in available]
+ try:
+ rd_counters = [rd.GPUCounter(c) for c in counter_ids]
+ except (ValueError, TypeError) as exc:
+ return {
+ "error": "Invalid counter id(s) %s: %s" % (counter_ids, exc),
+ "valid_counter_ids": valid_ids,
+ }
results = controller.FetchCounters(rd_counters)
diff --git a/renderdoc/agent-harness/cli_anything/renderdoc/core/mesh.py b/renderdoc/agent-harness/cli_anything/renderdoc/core/mesh.py
index 7e80c4e5f..8c5bc9c00 100644
--- a/renderdoc/agent-harness/cli_anything/renderdoc/core/mesh.py
+++ b/renderdoc/agent-harness/cli_anything/renderdoc/core/mesh.py
@@ -153,17 +153,21 @@ def _flatten(actions, out=None):
def _get_indices(controller, ib, action):
"""Decode index buffer."""
if action.flags & rd.ActionFlags.Indexed and ib.resourceId != rd.ResourceId.Null():
+ if action.numIndices <= 0:
+ return []
+
idx_fmt = "B"
if ib.byteStride == 2:
idx_fmt = "H"
elif ib.byteStride == 4:
idx_fmt = "I"
- ibdata = controller.GetBufferData(ib.resourceId, ib.byteOffset, 0)
- offset = action.indexOffset * ib.byteStride
+ start = ib.byteOffset + action.indexOffset * ib.byteStride
+ length = action.numIndices * ib.byteStride
+ ibdata = controller.GetBufferData(ib.resourceId, start, length)
fmt_str = str(action.numIndices) + idx_fmt
try:
- indices = _struct.unpack_from(fmt_str, bytes(ibdata), offset)
+ indices = _struct.unpack(fmt_str, bytes(ibdata))
return [i + action.baseVertex for i in indices]
except Exception as e:
click.echo(f"Warning: failed to unpack indices: {e}", err=True)
diff --git a/renderdoc/agent-harness/cli_anything/renderdoc/renderdoc_cli.py b/renderdoc/agent-harness/cli_anything/renderdoc/renderdoc_cli.py
index 685722476..1309ffaf6 100644
--- a/renderdoc/agent-harness/cli_anything/renderdoc/renderdoc_cli.py
+++ b/renderdoc/agent-harness/cli_anything/renderdoc/renderdoc_cli.py
@@ -125,7 +125,10 @@ def cli(ctx, capture, json_mode, debug):
Run without a subcommand to enter interactive REPL mode.
"""
ctx.ensure_object(dict)
- ctx.obj["capture_path"] = capture
+ # Preserve REPL session state: nested `cli.main(...)` omits global options, so
+ # only overwrite capture when the user passed `-c` on that invocation.
+ if capture is not None:
+ ctx.obj["capture_path"] = capture
ctx.obj["json_mode"] = json_mode
ctx.obj["debug"] = debug
@@ -876,7 +879,7 @@ def repl(ctx):
args = line.split()
try:
- cli.main(args, standalone_mode=False)
+ cli.main(args, standalone_mode=False, obj=ctx.obj)
except SystemExit:
pass
except click.exceptions.UsageError as e:
diff --git a/renderdoc/agent-harness/cli_anything/renderdoc/skills/SKILL.md b/renderdoc/agent-harness/cli_anything/renderdoc/skills/SKILL.md
index 8daae5250..3e6ded739 100644
--- a/renderdoc/agent-harness/cli_anything/renderdoc/skills/SKILL.md
+++ b/renderdoc/agent-harness/cli_anything/renderdoc/skills/SKILL.md
@@ -7,6 +7,7 @@ install: pip install cli-anything-renderdoc
requires:
- renderdoc (Python bindings from RenderDoc installation)
- click>=8.0
+ - prompt-toolkit>=3.0
categories:
- graphics
- debugging
diff --git a/renderdoc/agent-harness/setup.py b/renderdoc/agent-harness/setup.py
index 57d6e4222..9df3c4c00 100644
--- a/renderdoc/agent-harness/setup.py
+++ b/renderdoc/agent-harness/setup.py
@@ -31,6 +31,8 @@ setup(
package_data={
"cli_anything.renderdoc": ["skills/*.md", "README.md"],
},
+ include_package_data=True,
+ zip_safe=False,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",