feat(annotate): token-cheap annotation with record output and a runner

The LLM now only labels speech emotions, music changes and sprite exits; speaker,
kind, location, time of day and positions are derived deterministically. Adds
`annotate run` (claude CLI by default, any stdin/stdout command), a hash-keyed
text cache and a usage log; removes the per-line JSON format and its schema.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-10-19 04:41:59 +02:00
1 parent f3017295d8
commit 3d2a91af49
6 files changed
+1098 -761

No files matched your search

+22 -66
View File
@@ -3,7 +3,7 @@ import json
import pytest
from vnpipe import SCHEMA_DIR
from vnpipe import SCHEMA_DIR, annotate
from vnpipe.schema import SchemaError, validate
SHA = "a" * 64
@@ -24,69 +24,10 @@ def _ann(**over):
return ann
def _cache(**over):
doc = {"chunk_id": "s_c01", "input_sha256": SHA, "annotations": [_ann()]}
doc.update(over)
return doc
def _load(name):
return json.loads((SCHEMA_DIR / f"{name}.schema.json").read_text(encoding="utf-8"))
def test_valid_annotation_cache():
validate(_cache(), "annotation")
def test_music_is_optional():
ann = _ann()
del ann["music"]
validate(_cache(annotations=[ann]), "annotation")
@pytest.mark.parametrize("key", ["chunk_id", "input_sha256", "annotations"])
def test_cache_required_fields(key):
doc = _cache()
del doc[key]
with pytest.raises(SchemaError):
validate(doc, "annotation")
@pytest.mark.parametrize(
"key", ["id", "speaker", "kind", "emotion", "location", "time_of_day", "on_stage"]
)
def test_annotation_required_fields(key):
ann = _ann()
del ann[key]
with pytest.raises(SchemaError):
validate(_cache(annotations=[ann]), "annotation")
@pytest.mark.parametrize(
"over",
[
{"emotion": "happy"},
{"kind": "verse"},
{"time_of_day": "noon"},
{"music": "loud"},
{"extra": 1},
{"on_stage": [{"character": "faust", "position": "top"}]},
{"on_stage": [{"character": "faust"}]},
{"on_stage": [{"character": "faust", "position": "left", "scale": 2}]},
],
)
def test_annotation_bad_values(over):
with pytest.raises(SchemaError):
validate(_cache(annotations=[_ann(**over)]), "annotation")
def test_cache_rejects_extra_field_and_bad_hash():
with pytest.raises(SchemaError):
validate(_cache(extra=1), "annotation")
with pytest.raises(SchemaError):
validate(_cache(input_sha256="xyz"), "annotation")
def _annotated():
ann = _ann()
del ann["id"]
@@ -136,15 +77,30 @@ def test_annotated_rejects_problems():
def test_annotated_definitions_match_source_schemas():
"""annotated.schema.json duplicates definitions from the other schemas; keep them in sync."""
annotated = _load("annotated")["$defs"]
source = _load("annotation")["$defs"]
expected = copy.deepcopy(source["annotation"])
expected["required"].remove("id")
del expected["properties"]["id"]
assert annotated["ann"] == expected
assert annotated["position"] == source["position"]
assert annotated["ann"]["properties"]["emotion"]["enum"] == list(annotate.EMOTIONS)
assert annotated["ann"]["properties"]["music"]["enum"] == [*annotate.MUSIC, None]
assert annotated["position"]["enum"] == list(annotate.POSITIONS)
parsed_line = _load("parsed")["properties"]["scenes"]["items"]["properties"]["lines"]["items"]
line = copy.deepcopy(annotated["line"])
assert line["required"] == [*parsed_line["required"], "ann"]
del line["properties"]["ann"]
assert line["properties"] == parsed_line["properties"]
@pytest.mark.parametrize(
"over",
[
{"kind": "verse"},
{"time_of_day": "noon"},
{"music": "loud"},
{"extra": 1},
{"on_stage": [{"character": "faust", "position": "top"}]},
{"on_stage": [{"character": "faust"}]},
],
)
def test_annotated_bad_ann_values(over):
doc = _annotated()
doc["scenes"][0]["lines"][0]["ann"].update(over)
with pytest.raises(SchemaError):
validate(doc, "annotated")