Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/tui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof setInterval> | undefined;
Expand All @@ -280,6 +292,7 @@ export default Plugin.define({
stopTicker();
stopOpen();
stopClose();
stopMarker();
if (autoplay) clearInterval(autoplay);
unregister();
};
Expand Down