Skip to content

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

Python

fix: address second round of PR review feedback

Vicky Tamb1f9a3c6ba0f
diff --git a/musescore/agent-harness/cli_anything/musescore/core/instruments.py b/musescore/agent-harness/cli_anything/musescore/core/instruments.py
index 89e6c4d6e..be8eed0f3 100644
--- a/musescore/agent-harness/cli_anything/musescore/core/instruments.py
+++ b/musescore/agent-harness/cli_anything/musescore/core/instruments.py
@@ -4,10 +4,13 @@ For listing, uses mscore --score-meta. For add/remove/reorder,
manipulates the MSCX XML directly.
"""
+import logging
import os
from pathlib import Path
from cli_anything.musescore.utils import musescore_backend as backend
+
+logger = logging.getLogger(__name__)
from cli_anything.musescore.utils import mscx_xml as xml_utils
@@ -32,8 +35,8 @@ def list_instruments(path: str) -> list[dict]:
}
for i, p in enumerate(parts)
]
- except Exception:
- pass
+ except Exception as e:
+ logger.debug("mscore metadata failed for instruments, falling back to XML: %s", e)
# Fallback: XML parsing
try:
@@ -76,11 +79,12 @@ def add_instrument(path: str, output_path: str, instrument_id: str,
if score is None:
raise RuntimeError("No <Score> element found in MSCX")
- # Create a new Part element
+ # Count existing parts BEFORE adding the new one
import xml.etree.ElementTree as ET
+ staff_id = str(len(score.findall("Part")) + 1)
+
part = ET.SubElement(score, "Part")
staff = ET.SubElement(part, "Staff")
- staff_id = str(len(root.findall(".//Part")) + 1)
staff.set("id", staff_id)
instrument = ET.SubElement(part, "Instrument")
diff --git a/musescore/agent-harness/cli_anything/musescore/core/media.py b/musescore/agent-harness/cli_anything/musescore/core/media.py
index 8b6639e9b..625301285 100644
--- a/musescore/agent-harness/cli_anything/musescore/core/media.py
+++ b/musescore/agent-harness/cli_anything/musescore/core/media.py
@@ -1,11 +1,14 @@
"""Media operations — probe, diff, stats."""
+import logging
import os
from pathlib import Path
from cli_anything.musescore.utils import musescore_backend as backend
from cli_anything.musescore.utils import mscx_xml as xml_utils
+logger = logging.getLogger(__name__)
+
def probe_score(path: str) -> dict:
"""Get comprehensive metadata about a score.
@@ -25,7 +28,8 @@ def probe_score(path: str) -> dict:
try:
meta = backend.get_score_meta(path)
result["metadata"] = meta
- except Exception:
+ except Exception as e:
+ logger.debug("mscore metadata failed for probe, falling back to XML: %s", e)
# XML fallback
try:
tree = xml_utils.read_score_tree(path)
diff --git a/musescore/agent-harness/cli_anything/musescore/core/parts.py b/musescore/agent-harness/cli_anything/musescore/core/parts.py
index 25b248578..798918638 100644
--- a/musescore/agent-harness/cli_anything/musescore/core/parts.py
+++ b/musescore/agent-harness/cli_anything/musescore/core/parts.py
@@ -1,11 +1,14 @@
"""Part extraction and management."""
import base64
+import logging
import os
from pathlib import Path
from cli_anything.musescore.utils import musescore_backend as backend
+logger = logging.getLogger(__name__)
+
def list_parts(path: str) -> list[dict]:
"""List all parts in a score.
@@ -31,8 +34,8 @@ def list_parts(path: str) -> list[dict]:
}
for i, p in enumerate(parts)
]
- except Exception:
- pass
+ except Exception as e:
+ logger.debug("mscore metadata failed for parts, falling back to score-parts: %s", e)
# Fallback: score-parts (parts = list of names, partsMeta = list of dicts)
try:
diff --git a/musescore/agent-harness/cli_anything/musescore/core/project.py b/musescore/agent-harness/cli_anything/musescore/core/project.py
index f56b17b54..bef5d4efa 100644
--- a/musescore/agent-harness/cli_anything/musescore/core/project.py
+++ b/musescore/agent-harness/cli_anything/musescore/core/project.py
@@ -1,8 +1,11 @@
"""Project management — create, open, save, info."""
+import logging
import os
from pathlib import Path
+logger = logging.getLogger(__name__)
+
from cli_anything.musescore.utils import musescore_backend as backend
from cli_anything.musescore.utils import mscx_xml as xml_utils
@@ -28,7 +31,8 @@ def open_project(path: str) -> dict:
project["metadata"] = meta
if meta.get("title"):
project["name"] = meta["title"]
- except Exception:
+ except Exception as e:
+ logger.debug("mscore metadata failed, falling back to XML: %s", e)
# Fall back to XML parsing for metadata
try:
tree = xml_utils.read_score_tree(path)
@@ -42,19 +46,19 @@ def open_project(path: str) -> dict:
"measures": xml_utils.count_measures(tree),
"notes": xml_utils.count_notes(tree),
}
- except Exception:
- pass
+ except Exception as e:
+ logger.debug("XML parsing also failed: %s", e)
return project
-def save_project(project: dict, path: str | None = None) -> str:
- """Save a project. Currently just returns the path (scores are
- saved via mscore export, not by rewriting the file directly)."""
- save_path = path or project.get("path")
- if not save_path:
- raise RuntimeError("No save path specified.")
- return str(save_path)
+def save_project(input_path: str, output_path: str) -> dict:
+ """Save/convert a score to .mscz format via mscore export.
+
+ This delegates to mscore -o which handles all format conversion.
+ """
+ from cli_anything.musescore.core import export
+ return export.export_score(input_path, output_path, fmt="mscz")
def project_info(path: str) -> dict:
@@ -73,8 +77,8 @@ def project_info(path: str) -> dict:
meta = backend.get_score_meta(path)
info["metadata"] = meta
return info
- except Exception:
- pass
+ except Exception as e:
+ logger.debug("mscore metadata failed for info, falling back to XML: %s", e)
# Fall back to XML parsing
try:
diff --git a/musescore/agent-harness/cli_anything/musescore/musescore_cli.py b/musescore/agent-harness/cli_anything/musescore/musescore_cli.py
index 27489dbfc..2b5033ae6 100644
--- a/musescore/agent-harness/cli_anything/musescore/musescore_cli.py
+++ b/musescore/agent-harness/cli_anything/musescore/musescore_cli.py
@@ -146,13 +146,14 @@ def project_info(path):
@project.command("save")
[email protected]("-o", "--output", "path", default=None, help="Save path")
[email protected]("-i", "--input", "input_path", required=True, help="Input score file")
[email protected]("-o", "--output", "output_path", required=True, help="Output score file")
@handle_error
-def project_save(path):
- """Save the current project."""
- sess = get_session()
- saved = proj_mod.save_project(sess.get_project(), path)
- output({"saved": saved}, f"Saved to: {saved}")
+def project_save(input_path, output_path):
+ """Save/convert a score to .mscz format via mscore export."""
+ from cli_anything.musescore.core import export as export_mod_local
+ result = export_mod_local.export_score(input_path, output_path, fmt="mscz")
+ output(result, f"Saved to: {output_path}")
# ── Transpose Commands ────────────────────────────────────────────────
@@ -292,7 +293,7 @@ def export_group():
def _make_export_cmd(fmt_name, description):
"""Factory for format-specific export commands."""
- @export_group.command(fmt_name)
+ @export_group.command(fmt_name, help=description)
@click.option("-i", "--input", "input_path", required=True, help="Input score")
@click.option("-o", "--output", "output_path", required=True, help="Output file")
@click.option("--dpi", type=int, default=None, help="DPI for PNG export")
@@ -310,7 +311,6 @@ def _make_export_cmd(fmt_name, description):
)
output(result, f"Exported {fmt_name}: {output_path}")
- export_cmd.__doc__ = description
return export_cmd
@@ -526,6 +526,9 @@ def repl():
import shlex
args = shlex.split(line)
+ # Preserve --json flag across REPL commands
+ if _json_output and "--json" not in args:
+ args = ["--json"] + args
try:
cli.main(args, standalone_mode=False)
except SystemExit: