From 951a4ea065226cadb44bf2df1a0672ed12d2f4dc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 24 Jan 2026 03:46:07 +0000 Subject: [PATCH] fix: anchor MEDIA tag parsing --- CHANGELOG.md | 1 + src/media/parse.test.ts | 13 +++++++++++++ src/media/parse.ts | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 804ec6e78..7b3f4d913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/media/parse.test.ts b/src/media/parse.test.ts index 74c1eb52d..de60ca357 100644 --- a/src/media/parse.test.ts +++ b/src/media/parse.test.ts @@ -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(""); + }); }); diff --git a/src/media/parse.ts b/src/media/parse.ts index 4e35d6775..de0c6a5bc 100644 --- a/src/media/parse.ts +++ b/src/media/parse.ts @@ -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);