HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
feat(media): naming a clip as the input carries on from the frame it ended on
richard-epsilla81e183f38b72
diff --git a/gateway/app.py b/gateway/app.pyindex ca5a00de..8f7a31a1 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -8977,11 +8977,15 @@ _MEDIA_MCP_TOOLS = ["description": ("REQUIRED. Every model bills by length and ""one of them defaults to 15 s.")},"from_image": {"type": "string",- "description": ("A media id (med_…) or job id (mjob_…) "- "from an earlier image. Animates that "- "image instead of generating from text. "- "Only some models can do this and the "- "tool says which one it used.")},+ "description": ("A media id (med_…) or job id (mjob_…) to "+ "start from, instead of generating from "+ "text alone. An IMAGE becomes this shot's "+ "first frame. A CLIP means 'carry on from "+ "where that one ended' — its last frame "+ "is used, which is how two shots join "+ "without a visible jump. Only some models "+ "can do this and the tool says which one "+ "it used.")},"aspect": {"enum": ["16:9", "9:16", "1:1"]},"allow_watermark": {"type": "boolean", "default": False},"shot": {"type": "string", "maxLength": 60,@@ -9260,6 +9264,25 @@ async def _media_resolve_input_image(sid: str, ref: str) -> tuple[str, str, str]if not job.get("media_id"):raise media_plane.MediaError(f"Job {ref} has produced nothing to work from yet.")med = str(job["media_id"])++ # NAMING A CLIP MEANS "CARRY ON FROM WHERE THAT ONE ENDED", and the frame it ended on is the+ # only thing that can express it: the still that seeded a shot is where the shot BEGAN, and+ # five seconds of movement later the world has moved on. Handing the mp4 over as though it+ # were an image is what happened before — a video sent to an image input, paid for, refused.+ meta = await _media_meta(sid, med) or {}+ if str(meta.get("mime") or "").startswith("video/") or str(meta.get("ext") or "") == "mp4":+ data = await _blob_get(_media_blob(sid, med, str(meta.get("ext") or "mp4")), kb=BLOB_KB)+ if not data:+ raise media_plane.MediaError(f"The clip behind {med} is no longer readable.")+ tmp = tempfile.mkdtemp(prefix="hr-frame-")+ try:+ path = os.path.join(tmp, f"clip.{meta.get('ext') or 'mp4'}")+ pathlib.Path(path).write_bytes(data)+ frame = await media_plane.to_thread(media_plane.grab_frame, path)+ finally:+ shutil.rmtree(tmp, ignore_errors=True)+ return med, base64.b64encode(frame).decode(), "image/jpeg"+b64, mime = await _media_read_image(sid, med)return med, b64, mimediff --git a/gateway/media_plane.py b/gateway/media_plane.pyindex 070c4ba5..a54a15ea 100644--- a/gateway/media_plane.py+++ b/gateway/media_plane.py@@ -1457,6 +1457,36 @@ def _run(cmd: list[str], timeout: float) -> subprocess.CompletedProcess:return subprocess.run(cmd, capture_output=True, timeout=timeout, check=False)+def grab_frame(path: str, seconds: float | None = None) -> bytes:+ """One frame of a clip, as jpeg bytes. `seconds` defaults to the LAST frame.++ This is how one shot continues into the next: the frame a clip ends on becomes the frame the+ next shot starts from, so the cut lands on the same picture instead of on a second guess at+ the same scene. Nothing else can produce that frame — the still that seeded a shot is where+ it BEGAN, and five seconds of movement later the world has moved on.+ """+ if not have_ffmpeg():+ raise ExportRefused("This deployment cannot read a frame out of a clip — ffmpeg is not "+ "installed.")+ dur = float(probe_file(path).get("seconds") or 0.0)+ if seconds is None:+ # Not the very last presentation timestamp: seeking exactly to the end lands past the+ # final frame on some files and decodes nothing at all.+ seconds = max(0.0, dur - 0.08) if dur else 0.0+ out = path + ".frame.jpg"+ p = _run(["ffmpeg", "-nostdin", "-y", "-ss", f"{max(0.0, seconds):.3f}", "-i", path,+ "-frames:v", "1", "-q:v", "2", out], timeout=120)+ if p.returncode != 0 or not os.path.exists(out) or not os.path.getsize(out):+ raise ExportRefused("That clip's frame could not be read.")+ try:+ return pathlib.Path(out).read_bytes()+ finally:+ try:+ os.unlink(out)+ except OSError:+ pass++def probe_file(path: str) -> dict:"""{seconds, width, height, has_audio} for a file on disk, or {} when it cannot be read."""if not have_ffmpeg():diff --git a/gateway/tests/test_media_mcp.py b/gateway/tests/test_media_mcp.pyindex d4d3318c..cd34ba35 100644--- a/gateway/tests/test_media_mcp.py+++ b/gateway/tests/test_media_mcp.py@@ -2114,6 +2114,37 @@ def test_a_layer_rides_over_the_cut_without_moving_it(client, harness, session,assert abs(rec["seconds"] - 2.0) < 0.5, rec+@needs_ffmpeg+def test_naming_a_clip_as_the_input_takes_the_frame_it_ENDED_on():+ """How one shot continues into the next.++ A still that seeded a shot is where the shot BEGAN; five seconds of movement later the world+ has moved on, so seeding the next shot from it produces a visible jump backwards. The frame+ to carry forward is the one the clip ended on. This clip goes green-to-red, and what comes+ back is red.+ """+ with tempfile.TemporaryDirectory() as d:+ clip = os.path.join(d, "c.mp4")+ subprocess.run(["ffmpeg", "-nostdin", "-y", "-f", "lavfi",+ "-i", "color=c=green:s=128x72:d=1", "-f", "lavfi",+ "-i", "color=c=red:s=128x72:d=1",+ "-filter_complex", "[0][1]concat=n=2:v=1[v]", "-map", "[v]",+ "-c:v", "libx264", "-pix_fmt", "yuv420p", clip],+ capture_output=True, check=True)+ last = media_plane.grab_frame(clip)+ first = media_plane.grab_frame(clip, 0.0)+ def middle(jpg: bytes) -> tuple[int, int, int]:+ f = os.path.join(d, "f.jpg")+ Path(f).write_bytes(jpg)+ raw = subprocess.run(["ffmpeg", "-nostdin", "-v", "error", "-i", f, "-vf",+ "crop=8:8:60:32", "-f", "rawvideo", "-pix_fmt", "rgb24", "-"],+ capture_output=True, check=True).stdout+ return tuple(raw[:3])+ ends, begins = middle(last), middle(first)+ assert ends[0] > ends[1], f"the closing frame was not the red one: {ends}"+ assert begins[1] > begins[0], f"the opening frame was not the green one: {begins}"++def test_a_sound_that_is_no_longer_on_the_canvas_stops_the_export(client, harness, session,provider):"""A film delivered without the music somebody asked for is not the film.