From bc53f3320f586edb564b6aa58259fab9c56e4b08 Mon Sep 17 00:00:00 2001 From: Nabheet Sandhu Date: Fri, 20 Nov 2026 17:16:56 -0700 Subject: [PATCH] feat: open a clip from a message marker A finished message containing `media-panel: /path` now opens that clip. The plugin subscribes to session.text.ended through the client it already holds, so the request originates inside the TUI process and takes the same RPC path as /media: client call, server event, local render. No shell, no CLI. Fixes the documented payload shape (events carry `data`) and records both paths in the README. --- CHANGELOG.md | 10 ++++++++++ README.md | 12 ++++++++++++ src/tui.tsx | 13 +++++++++++++ 3 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b3c09..d985e2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 0.1.12 + +- Add: a message marker. A finished message containing a line + `media-panel: /path/to/clip.mp4` opens that clip. The plugin subscribes to + `session.text.ended` through the client it already has, so the request is + raised inside the TUI process and travels the same RPC path as `/media`; no + shell, no CLI, no second process. +- Fix: session events carry their payload under `data`; the marker reader reads + `event.data.text`. + ## 0.1.11 - Change: every open now travels through the plugin's own server RPC. `/media` diff --git a/README.md b/README.md index 1af1f4d..2ce6b0e 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,18 @@ The panel belongs to a session, so opening a file from the home screen reports Paths with spaces are fine: the whole argument is the path. Remote URLs work too, as long as ffmpeg can read the protocol. +### Opening it from a message + +A finished message containing this line opens the clip: + +```text +media-panel: /home/user/clips/demo.mp4 +``` + +That is useful for an agent: it writes the marker in its reply, the plugin reads +the session text event it already receives, and the panel opens through the same +RPC path `/media` uses. Nothing runs a command. + ### Opening it from outside the TUI A script, an agent, or another plugin can open the panel without typing. The diff --git a/src/tui.tsx b/src/tui.tsx index 9a09d0a..d1f40e8 100644 --- a/src/tui.tsx +++ b/src/tui.tsx @@ -254,6 +254,18 @@ export default Plugin.define({ context.ui.panel.close(); }); + // A marker in a finished message opens a clip without any shell command: + // the client already receives session text, so the plugin is the one that + // raises the request. `media-panel: /path/to/clip.mp4` on its own line. + const marker = /(?:^|\n)[ \t]*media-panel:[ \t]*(\S+)[ \t]*(?=\n|$)/; + const stopMarker = context.data.on("session.text.ended", (event) => { + // The event carries its payload under `data`. + const text = (event as { data?: { text?: unknown } }).data?.text; + if (typeof text !== "string") return; + const match = marker.exec(text); + if (match?.[1]) open(match[1]); + }); + const remembered = options.remember ? saved.source.trim() : ""; const initial = options.source ?? (remembered === "" ? undefined : remembered); let autoplay: ReturnType | undefined; @@ -280,6 +292,7 @@ export default Plugin.define({ stopTicker(); stopOpen(); stopClose(); + stopMarker(); if (autoplay) clearInterval(autoplay); unregister(); };