Skip to content

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

Python

fix: harden WaveTone JSON validation

Shuhan Zhang94d2550b42f1
diff --git a/README.md b/README.md
index 58d99f1db..add5f7286 100644
--- a/README.md
+++ b/README.md
@@ -1228,7 +1228,7 @@ gimp 107 passed ✅ (64 unit + 43 e2e)
blender 208 passed ✅ (150 unit + 58 e2e)
inkscape 202 passed ✅ (148 unit + 54 e2e)
audacity 161 passed ✅ (107 unit + 54 e2e)
-wavetone 22 passed ✅ (17 unit + 5 e2e)
+wavetone 23 passed ✅ (18 unit + 5 e2e)
libreoffice 158 passed ✅ (89 unit + 69 e2e)
mubu 96 passed ✅ (85 unit + 11 e2e)
obs-studio 153 passed ✅ (116 unit + 37 e2e)
@@ -1308,7 +1308,7 @@ cli-anything/
├── 🧊 blender/agent-harness/ # Blender CLI (208 tests)
├── ✏️ inkscape/agent-harness/ # Inkscape CLI (202 tests)
├── 🎵 audacity/agent-harness/ # Audacity CLI (161 tests)
-├── wavetone/agent-harness/ # WaveTone CLI (22 tests: 17 unit + 5 e2e)
+├── wavetone/agent-harness/ # WaveTone CLI (23 tests: 18 unit + 5 e2e)
├── 🌐 browser/agent-harness/ # Browser CLI (DOMShell MCP, new)
├── 📄 libreoffice/agent-harness/ # LibreOffice CLI (158 tests)
├── 📧 mailchimp/agent-harness/ # Mailchimp Marketing API CLI (303 commands, 36 unit tests)
diff --git a/README_CN.md b/README_CN.md
index 941ae4b29..8169ed039 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -679,7 +679,7 @@ gimp 107 passed ✅ (64 unit + 43 e2e)
blender 208 passed ✅ (150 unit + 58 e2e)
inkscape 202 passed ✅ (148 unit + 54 e2e)
audacity 161 passed ✅ (107 unit + 54 e2e)
-wavetone 22 passed ✅ (17 unit + 5 e2e)
+wavetone 23 passed ✅ (18 unit + 5 e2e)
libreoffice 158 passed ✅ (89 unit + 69 e2e)
obs-studio 153 passed ✅ (116 unit + 37 e2e)
kdenlive 155 passed ✅ (111 unit + 44 e2e)
@@ -753,7 +753,7 @@ cli-anything/
├── 🧊 blender/agent-harness/ # Blender CLI(208 项测试)
├── ✏️ inkscape/agent-harness/ # Inkscape CLI(202 项测试)
├── 🎵 audacity/agent-harness/ # Audacity CLI(161 项测试)
-├── wavetone/agent-harness/ # WaveTone CLI(22 项测试:17 unit + 5 e2e)
+├── wavetone/agent-harness/ # WaveTone CLI(23 项测试:18 unit + 5 e2e)
├── 📄 libreoffice/agent-harness/ # LibreOffice CLI(158 项测试)
├── 📚 zotero/agent-harness/ # Zotero CLI(新增,支持文献导入)
├── 📓 joplin/agent-harness/ # Joplin CLI(134 测试:107 单元 + 27 e2e)
diff --git a/registry.json b/registry.json
index 77041f8b8..3509e3012 100644
--- a/registry.json
+++ b/registry.json
@@ -110,7 +110,7 @@
"source_url": null,
"install_cmd": "pip install git+https://github.com/HKUDS/CLI-Anything.git#subdirectory=wavetone/agent-harness",
"entry_point": "cli-anything-wavetone",
- "skill_md": "skills/cli-anything-wavetone/SKILL.md",
+ "skill_md": "wavetone/agent-harness/cli_anything/wavetone/skills/SKILL.md",
"category": "audio",
"contributors": [
{
diff --git a/skills/cli-anything-wavetone/SKILL.md b/skills/cli-anything-wavetone/SKILL.md
deleted file mode 100644
index a565109ed..000000000
--- a/skills/cli-anything-wavetone/SKILL.md
+++ /dev/null
@@ -1,53 +0,0 @@
----
-name: "cli-anything-wavetone"
-description: "Control WaveTone 2.61 workflows through a JSON manifest and launch the real Windows WaveTone executable."
----
-
-# cli-anything-wavetone
-
-Use this skill when an agent needs to prepare, inspect, and launch WaveTone 2.61
-audio transcription workflows.
-
-## Requirements
-
-- Windows host.
-- WaveTone 2.61 extracted locally.
-- Set `WAVETONE_EXE` to `wavetone.exe` or `WAVETONE_HOME` to the extracted
- WaveTone directory when the default portable path is not used.
-
-## Core Commands
-
-All commands support the top-level `--json` flag.
-
-```bash
-cli-anything-wavetone --json wavetone doctor
-cli-anything-wavetone --json project new input.wav -o project.wt.json
-cli-anything-wavetone --project project.wt.json --json audio probe
-cli-anything-wavetone --project project.wt.json --json project set-tempo --bpm 120 --meter 4/4
-cli-anything-wavetone --project project.wt.json --json project add-label chorus --time 64.0
-cli-anything-wavetone --project project.wt.json --json wavetone launch
-```
-
-## Command Groups
-
-- `project`: create manifests, set tempo, add labels, update intended analysis
- settings, and attach a WFD saved from WaveTone.
-- `audio`: probe audio metadata before opening it in WaveTone.
-- `wavetone`: run `doctor`, list supported formats, or launch the real GUI.
-- `session`: record lightweight event logs for multi-step agent workflows.
-- `defaults`: show default analysis settings.
-
-## Agent Guidance
-
-The JSON project manifest is not a WaveTone WFD file. It is an agent-facing plan
-for the source audio, intended analysis settings, labels, and tempo metadata.
-Use WaveTone itself to perform analysis and save WFD/MIDI/text/WAVE outputs.
-
-When running in automated checks, use:
-
-```bash
-cli-anything-wavetone --json wavetone launch input.wav --wait 1 --terminate
-```
-
-This confirms that the real backend can be started without leaving a persistent
-GUI process behind.
diff --git a/wavetone/agent-harness/cli_anything/wavetone/core/audio.py b/wavetone/agent-harness/cli_anything/wavetone/core/audio.py
index 4f419f0e9..f35f343f5 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/core/audio.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/core/audio.py
@@ -82,7 +82,7 @@ def _probe_ffprobe(path: Path) -> dict[str, Any]:
"codec": audio_stream.get("codec_name"),
"duration_seconds": round(duration, 6) if duration is not None else None,
"sample_rate": _safe_int(audio_stream.get("sample_rate")),
- "channels": audio_stream.get("channels"),
+ "channels": _safe_int(audio_stream.get("channels")),
"bit_rate": _safe_int(fmt.get("bit_rate")),
"size_bytes": _safe_int(fmt.get("size")) or path.stat().st_size,
"probe_method": "ffprobe",
diff --git a/wavetone/agent-harness/cli_anything/wavetone/core/project.py b/wavetone/agent-harness/cli_anything/wavetone/core/project.py
index 88bfa8391..7e06d8e07 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/core/project.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/core/project.py
@@ -114,6 +114,8 @@ def load_project(project_path: str | Path) -> dict[str, Any]:
if not path.exists():
raise FileNotFoundError(f"Project file not found: {path}")
data = json.loads(path.read_text(encoding="utf-8"))
+ if not isinstance(data, dict):
+ raise ValueError("Project file must be a JSON object")
if data.get("schema_version") != SCHEMA_VERSION:
raise ValueError(f"Unsupported WaveTone project schema: {data.get('schema_version')!r}")
return data
@@ -126,7 +128,7 @@ def add_label(
note: str | None = None,
) -> dict[str, Any]:
time_value = _finite_float(time_seconds, "Label time")
- if time_seconds < 0:
+ if time_value < 0:
raise ValueError("Label time must be >= 0")
label: dict[str, Any] = {"name": name, "time_seconds": round(time_value, 6)}
if note:
diff --git a/wavetone/agent-harness/cli_anything/wavetone/core/session.py b/wavetone/agent-harness/cli_anything/wavetone/core/session.py
index e939e9925..d9f2c7f26 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/core/session.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/core/session.py
@@ -3,6 +3,7 @@
from __future__ import annotations
import json
+import math
from pathlib import Path
from typing import Any
@@ -13,6 +14,17 @@ def _new_session() -> dict[str, Any]:
return {"schema_version": "wavetone-session/v1", "events": []}
+def _assert_json_safe(value: Any, path: str = "payload") -> None:
+ if isinstance(value, float) and not math.isfinite(value):
+ raise ValueError(f"{path} must contain only finite numbers")
+ if isinstance(value, dict):
+ for key, item in value.items():
+ _assert_json_safe(item, f"{path}.{key}")
+ elif isinstance(value, list):
+ for idx, item in enumerate(value):
+ _assert_json_safe(item, f"{path}[{idx}]")
+
+
def _load_session_data(path: Path) -> dict[str, Any]:
if not path.exists():
return _new_session()
@@ -33,10 +45,11 @@ def _load_session_data(path: Path) -> dict[str, Any]:
def append_event(session_path: str | Path, event: str, payload: dict[str, Any]) -> dict[str, Any]:
path = Path(session_path).expanduser().resolve()
data = _load_session_data(path)
+ _assert_json_safe(payload)
record = {"time": now_iso(), "event": event, "payload": payload}
data["events"].append(record)
path.parent.mkdir(parents=True, exist_ok=True)
- path.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
+ path.write_text(json.dumps(data, indent=2, sort_keys=True, allow_nan=False) + "\n", encoding="utf-8")
return record
diff --git a/wavetone/agent-harness/cli_anything/wavetone/tests/TEST.md b/wavetone/agent-harness/cli_anything/wavetone/tests/TEST.md
index 73ed7f5dd..3c0c3f8d9 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/tests/TEST.md
+++ b/wavetone/agent-harness/cli_anything/wavetone/tests/TEST.md
@@ -2,7 +2,7 @@
## Test Inventory Plan
-- `test_core.py`: 17 unit tests for project manifests, audio probing, session logs,
+- `test_core.py`: 18 unit tests for project manifests, audio probing, session logs,
and backend discovery.
- `test_full_e2e.py`: 5 E2E tests covering CLI subprocess workflows and real
WaveTone launch smoke coverage.
@@ -12,6 +12,7 @@
- Create a manifest from a supported WAV file.
- Reject missing files and unsupported extensions.
- Save and load schema-compatible JSON.
+- Reject non-object project JSON.
- Add labels in sorted time order.
- Set tempo and analysis options.
- Reject non-finite numeric project values before JSON serialization.
@@ -21,6 +22,7 @@
- Safely parse non-numeric ffprobe metadata.
- Append and reload session events.
- Reject invalid session JSON schemas with clear `ValueError`s.
+- Reject non-finite session payload values before writing JSON.
- Resolve `WAVETONE_EXE` from the environment.
- Preserve inherited project and JSON context for REPL-style nested CLI
invocations.
@@ -79,7 +81,7 @@ python -m pytest cli_anything\wavetone\tests\ -v -s
Result:
```text
-collected 22 items
+collected 23 items
cli_anything/wavetone/tests/test_core.py::test_create_project_manifest PASSED
cli_anything/wavetone/tests/test_core.py::test_rejects_unsupported_audio PASSED
@@ -87,6 +89,7 @@ cli_anything/wavetone/tests/test_core.py::test_save_load_project_roundtrip PASSE
cli_anything/wavetone/tests/test_core.py::test_labels_are_sorted PASSED
cli_anything/wavetone/tests/test_core.py::test_update_analysis_settings PASSED
cli_anything/wavetone/tests/test_core.py::test_rejects_non_finite_project_numbers PASSED
+cli_anything/wavetone/tests/test_core.py::test_load_project_rejects_non_object_json PASSED
cli_anything/wavetone/tests/test_core.py::test_probe_wav_metadata PASSED
cli_anything/wavetone/tests/test_core.py::test_probe_malformed_wav_falls_back_to_stat PASSED
cli_anything/wavetone/tests/test_core.py::test_ffprobe_uses_single_show_entries_argument PASSED
@@ -104,17 +107,18 @@ cli_anything/wavetone/tests/test_full_e2e.py::TestCLISubprocess::test_formats_js
cli_anything/wavetone/tests/test_full_e2e.py::TestRealWaveToneBackend::test_doctor_real_backend PASSED
cli_anything/wavetone/tests/test_full_e2e.py::TestRealWaveToneBackend::test_launch_real_backend_with_wav PASSED
-22 passed in 4.23s
+23 passed in 3.22s
```
## Coverage Notes
- Unit tests cover manifest creation, validation, persistence, labels, tempo,
- analysis settings, finite numeric validation, audio probing, malformed WAV
- fallback, session logs, session schema validation, backend discovery,
- ffprobe argument construction, ffprobe metadata parsing, inherited CLI
- project and JSON context, failed launch smoke reporting, Windows launch
- gating, and REPL Windows path splitting.
+ analysis settings, finite numeric validation, project JSON schema validation,
+ audio probing, malformed WAV fallback, session logs, session schema and
+ payload validation, backend discovery, ffprobe argument construction,
+ ffprobe metadata parsing, inherited CLI project and JSON context, failed
+ launch smoke reporting, Windows launch gating, and REPL Windows path
+ splitting.
- CLI subprocess tests resolve and use the installed `cli-anything-wavetone`
entry point.
- Real backend coverage launches `C:\Users\Hp\Desktop\wavetone2.6.1\wavetone.exe`
diff --git a/wavetone/agent-harness/cli_anything/wavetone/tests/test_core.py b/wavetone/agent-harness/cli_anything/wavetone/tests/test_core.py
index b4518cd0d..dff95e010 100644
--- a/wavetone/agent-harness/cli_anything/wavetone/tests/test_core.py
+++ b/wavetone/agent-harness/cli_anything/wavetone/tests/test_core.py
@@ -60,8 +60,9 @@ def test_labels_are_sorted(tmp_path: Path) -> None:
project = create_project(wav)
add_label(project, "late", 4.0)
add_label(project, "early", 1.0)
+ add_label(project, "middle", "2.5")
- assert [label["name"] for label in project["labels"]] == ["early", "late"]
+ assert [label["name"] for label in project["labels"]] == ["early", "middle", "late"]
def test_update_analysis_settings(tmp_path: Path) -> None:
@@ -85,6 +86,14 @@ def test_rejects_non_finite_project_numbers(tmp_path: Path) -> None:
update_analysis(project, reference_frequency_hz=float("inf"))
+def test_load_project_rejects_non_object_json(tmp_path: Path) -> None:
+ project_path = tmp_path / "broken.wt.json"
+ project_path.write_text("[]", encoding="utf-8")
+
+ with pytest.raises(ValueError, match="JSON object"):
+ load_project(project_path)
+
+
def test_probe_wav_metadata(tmp_path: Path) -> None:
wav = make_wav(tmp_path / "tone.wav", duration=0.5, sample_rate=16000)
info = probe_audio(wav)
@@ -124,7 +133,7 @@ def test_ffprobe_uses_single_show_entries_argument(tmp_path: Path, monkeypatch:
"codec_type": "audio",
"codec_name": "mp3",
"sample_rate": "44100",
- "channels": 2,
+ "channels": "2",
}
],
"format": {
@@ -147,6 +156,7 @@ def test_ffprobe_uses_single_show_entries_argument(tmp_path: Path, monkeypatch:
assert ":format=duration,format_name,bit_rate,size" in entries
assert info["probe_method"] == "ffprobe"
assert info["sample_rate"] == 44100
+ assert info["channels"] == 2
def test_ffprobe_handles_non_numeric_metadata(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -200,6 +210,13 @@ def test_session_rejects_invalid_schema(tmp_path: Path) -> None:
with pytest.raises(ValueError, match="events.*list"):
load_events(session_path)
+ session_path.unlink()
+
+ with pytest.raises(ValueError, match="finite"):
+ append_event(session_path, "bad", {"value": float("nan")})
+
+ assert not session_path.exists()
+
def test_find_wavetone_from_env(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
fake = tmp_path / "wavetone.exe"
diff --git a/wavetone/agent-harness/setup.py b/wavetone/agent-harness/setup.py
index 82c9ecd60..4821f34d0 100644
--- a/wavetone/agent-harness/setup.py
+++ b/wavetone/agent-harness/setup.py
@@ -43,7 +43,7 @@ setup(
"cli-anything-wavetone=cli_anything.wavetone.wavetone_cli:main",
],
},
- package_data={"cli_anything.wavetone": ["skills/SKILL.md", "skills/*.md"]},
+ package_data={"cli_anything.wavetone": ["README.md", "skills/SKILL.md", "skills/*.md"]},
include_package_data=True,
zip_safe=False,
)