fix: anchor MEDIA tag parsing

This commit is contained in:
Peter Steinberger
2026-01-24 03:46:07 +00:00
parent 4fa1517e6d
commit 951a4ea065
3 changed files with 21 additions and 0 deletions

View File

@@ -40,6 +40,7 @@ Docs: https://docs.clawd.bot
- Tests: skip embedded runner ordering assertion on Windows to avoid CI timeouts.
- Linux: include env-configured user bin roots in systemd PATH and align PATH audits. (#1512) Thanks @robbyczgw-cla.
- TUI: render Gateway slash-command replies as system output (for example, `/context`).
- Media: only parse `MEDIA:` tags when they start the line to avoid stripping prose mentions. (#1206)
- Media: preserve PNG alpha when possible; fall back to JPEG when still over size cap. (#1491) Thanks @robbyczgw-cla.
- Agents: treat plugin-only tool allowlists as opt-ins; keep core tools enabled. (#1467)
- Exec approvals: persist allowlist entry ids to keep macOS allowlist rows stable. (#1521) Thanks @ngutman.

View File

@@ -34,4 +34,17 @@ describe("splitMediaFromOutput", () => {
expect(first.audioAsVoice).toBe(true);
expect(second.audioAsVoice).toBe(true);
});
it("keeps MEDIA mentions in prose", () => {
const input = "The MEDIA: tag fails to deliver";
const result = splitMediaFromOutput(input);
expect(result.mediaUrls).toBeUndefined();
expect(result.text).toBe(input);
});
it("parses MEDIA tags with leading whitespace", () => {
const result = splitMediaFromOutput(" MEDIA:/tmp/screenshot.png");
expect(result.mediaUrls).toEqual(["/tmp/screenshot.png"]);
expect(result.text).toBe("");
});
});

View File

@@ -71,6 +71,13 @@ export function splitMediaFromOutput(raw: string): {
continue;
}
const trimmedStart = line.trimStart();
if (!trimmedStart.startsWith("MEDIA:")) {
keptLines.push(line);
lineOffset += line.length + 1; // +1 for newline
continue;
}
const matches = Array.from(line.matchAll(MEDIA_TOKEN_RE));
if (matches.length === 0) {
keptLines.push(line);