Skip to content

feat(tui): inline image rendering via MEDIA: protocol - #36740

Closed
ademczuk wants to merge 15 commits into
openclaw:mainfrom
ademczuk:feat/tui-inline-image-rendering
Closed

ademczuk wants to merge 15 commits into
openclaw:mainfrom
ademczuk:feat/tui-inline-image-rendering

Conversation

@ademczuk

@ademczuk ademczuk commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: When agents use image-viewing tools (e.g., view-image, imgcat), the resulting images are invisible — TUI shows only text output, WebUI shows nothing.
  • Why it matters: Image-generating workflows (screenshots, diagrams, AI-generated art) produce files the user cannot see without leaving the terminal.
  • What changed: End-to-end inline image rendering pipeline: image tool emits MEDIA:<path> text blocks + {type:"image"} base64 blocks → gateway detects markers and injects images into chat.history responses → TUI renders via iTerm2 graphics protocol → WebUI renders inline after history reload.
  • What did NOT change (scope boundary): Audio/video MEDIA: handling, existing text-based tool output rendering, chat message format, WebSocket protocol, agent execution flow.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • TUI: Images from agent tool calls render inline in iTerm2/WezTerm terminals (Kitty graphics protocol).
  • WebUI: Images appear inline in the chat after the agent tool completes (requires page to declare caps: ["tool-events"]).
  • No change for terminals without image protocol support — they see text output as before.

Screenshots

TUI (Docker terminal) + WebUI (OpenClaw Control) — inline image rendering

TUI and WebUI inline image rendering

Agent executes sh /app/view-image.sh /home/node/.openclaw/workspace/cute-cat.jpg. Left: TUI renders the image inline via iTerm2 graphics protocol. Right: WebUI renders the same image inline after the gateway injection pipeline.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? Yes — image tool now emits additional content blocks (MEDIA: text + base64 image data).
  • Data access scope changed? Yes — gateway reads image files from the container filesystem to inject base64 into chat history responses.
  • Risk + mitigation: The gateway's readImageAsBase64 function has multiple guards: (1) path traversal check on raw input BEFORE path.normalize(), (2) null byte rejection, (3) absolute-path-only requirement, (4) extension allowlist (png/jpg/jpeg/gif/webp), (5) 10MB file size cap, (6) lstat rejects symlinks. Images are read from within the container's filesystem only — not from the host.

Repro + Verification

Environment

  • OS: Any (developed on Windows, Docker container runs Linux)
  • Runtime/container: Docker with openclaw-secure image, iTerm2-compatible terminal (WezTerm)
  • Model/provider: Any model that uses image-viewing tools
  • Integration/channel: TUI (terminal) + WebUI (browser)
  • Relevant config: ITERM_SESSION_ID=wezterm-iterm2 in container env

Steps

  1. Start openclaw gateway in Docker with iTerm2 protocol enabled
  2. Ask agent to generate or view an image (e.g., "take a screenshot" or "show me cute-cat.jpg")
  3. Agent runs view-image tool → image appears inline in TUI
  4. Open WebUI → same image appears inline in chat history

Expected

Images render inline in both TUI and WebUI without leaving the terminal or manually opening files.

Actual

Before: TUI shows text-only tool output; WebUI shows nothing for image results.
After: TUI renders images via iTerm2 graphics protocol; WebUI renders images inline after gateway injects base64 into chat history.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

118 tests across 6 test files:

  • image-tool.test.ts (27) — MEDIA emission, base64 bypass
  • chat.media-injection.test.ts (26) — gateway image extraction/injection
  • tui-event-handlers.test.ts (15) — verbose bypass for MEDIA results
  • tui-formatters.test.ts (35) — resultHasMedia detection
  • app-tool-stream.node.test.ts (8) — WebUI tool stream image detection
  • chat-event-reload.test.ts (7) — WebUI history reload on image detection

Human Verification (required)

  • Verified scenarios: Docker + WezTerm TUI rendering, WebUI rendering after tool completion, multiple images in single conversation, verbose=off mode (images still render).
  • Edge cases checked: Path traversal rejected (../etc/shadow.png), null bytes rejected, symlinks rejected, non-image extensions rejected, files >10MB rejected, MEDIA: tokens inside fenced code blocks not extracted.
  • What I did NOT verify: Behavior with very large numbers of images in a single conversation (potential memory pressure from base64 accumulation). WebUI rendering in non-Chromium browsers.

Changed Files

Area Files What
Agent tools image-tool.ts, pi-embedded-subscribe.tools.ts Emit MEDIA + image blocks, bypass base64 stripping
Gateway server-chat.ts, chat.ts MEDIA bypass filter, image extraction/injection pipeline
TUI tool-execution.ts, tui-formatters.ts, tui-event-handlers.ts, tui-session-actions.ts Two-stage image render (file + base64 fallback)
WebUI app-tool-stream.ts, chat-event-reload.ts, app-gateway.ts, grouped-render.ts, tool-cards.ts Detect images in tool stream, reload history
Shared src/media/parse.ts MEDIA_IMAGE_LINE_RE regex constant
Tests 6 test files 118 tests covering all pipelines

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No — iTerm2 protocol support uses existing ITERM_SESSION_ID env var.
  • Migration needed? No — WebUI clients that don't declare caps: ["tool-events"] simply don't receive tool stream events (server-side capability gating, graceful degradation).

Failure Recovery (if this breaks)

  • How to revert: git revert on the merge commit, or restore these key files:
    • src/agents/tools/image-tool.ts — remove MEDIA/image block emission
    • src/gateway/server-methods/chat.ts — remove image injection pipeline
    • src/tui/tool-execution.ts — remove inline image rendering
    • ui/src/ui/app-tool-stream.ts — remove IMAGE_VIEWER_RE detection
  • Known bad symptoms: If the injection pipeline breaks: images not appearing in WebUI (fallback: text output still shows). If the security guards break: watch for gateway reading unexpected files (check readImageAsBase64 error logs). If tool stream detection breaks: WebUI may reload history unnecessarily (performance impact, not data loss).

Risks and Mitigations

  • Risk: Gateway memory spike when processing many large images (base64 encoding ~33% overhead).

    • Mitigation: 10MB per-file size cap. Images are read on-demand during chat.history calls, not cached. Base64 data flows through existing WebSocket frame limits.
  • Risk: MEDIA_IMAGE_LINE_RE regex drift between shared constant and inline usage.

    • Mitigation: Single source of truth in src/media/parse.ts, imported by all consumers. No inline regex duplicates.
  • Risk: TOCTOU between lstat (symlink check) and readFile in readImageAsBase64.

    • Mitigation: Damage bounded by 10MB size cap + extension allowlist + absolute-path-only guard. Atomic open+fstat would eliminate the window entirely but requires native bindings — tracked as future hardening.

Test Plan

pnpm vitest run src/agents/tools/image-tool.test.ts                    # 27 tests
pnpm vitest run src/gateway/server-methods/chat.media-injection.test.ts # 26 tests
pnpm vitest run src/tui/tui-event-handlers.test.ts                     # 15 tests
pnpm vitest run src/tui/tui-formatters.test.ts                         # 35 tests
cd ui && pnpm vitest run --config vitest.node.config.ts src/ui/app-tool-stream.node.test.ts  # 8 tests
cd ui && pnpm vitest run src/ui/chat-event-reload.test.ts              # 7 tests
pnpm tsgo   # type-check clean
pnpm check  # lint clean

Supersedes #36641 (closed for clean commit history and fresh bot review).

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: XL labels Mar 5, 2026
@ademczuk
ademczuk force-pushed the feat/tui-inline-image-rendering branch 2 times, most recently from 7d053d4 to 61d26d2 Compare March 5, 2026 21:36
@greptile-apps

greptile-apps Bot commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR implements an end-to-end inline image rendering pipeline: the image tool emits MEDIA:<path> text blocks alongside base64 image blocks; the gateway reads those paths and injects base64 into chat history responses; the TUI renders via iTerm2 graphics protocol with a two-stage file-read/base64 fallback; and the WebUI reloads history after image-producing tool runs to display the injected content.

The implementation is thorough and carefully engineered, with comprehensive security guards (.. rejection pre-normalization, null byte check, absolute-path-only requirement, extension allowlist, 10 MB size cap, lstat symlink rejection, post-read size re-check). All issues flagged in prior review rounds have been resolved (flush-path dedup, conditional MEDIA filter, TOCTOU post-read guard, hoisted regex, DRY import, case-insensitive matching).

One remaining inconsistency to address:

  • resultHasMedia in src/tui/tui-formatters.ts (line 415), the display filter in extractText in src/tui/components/tool-execution.ts (line 154), and the verbose-bypass hasMedia check in src/gateway/server-chat.ts all call MEDIA_IMAGE_LINE_RE.test(text) on potentially multi-line content without first excluding code-fence spans. The authoritative extractMediaImagePaths in src/gateway/server-methods/chat.ts correctly uses parseFenceSpans + offset tracking. A tool result whose text block contains a MEDIA:image.png example inside a fenced code block would trigger the verbose bypass and suppress display of that line unexpectedly. This is an edge case but is an inconsistency with the stated design principle ("MEDIA: tokens inside fenced code blocks not extracted").

Confidence Score: 4/5

  • Safe to merge; one edge-case inconsistency with fence exclusion is the only remaining issue.
  • All security guards are robust and consistent, all prior review findings are resolved, the budget/dedup logic is correct, and the overall pipeline is well-tested (118 tests). Score is 4 rather than 5 because resultHasMedia, extractText, and the verbose bypass in server-chat.ts apply MEDIA_IMAGE_LINE_RE to multi-line text without fence exclusion — inconsistent with extractMediaImagePaths and the stated design invariant.
  • src/tui/tui-formatters.ts (resultHasMedia fence exclusion), src/tui/components/tool-execution.ts (extractText filter fence exclusion), src/gateway/server-chat.ts (hasMedia verbose-bypass fence exclusion)

Last reviewed commit: 3cc443e

Comment thread src/gateway/server-methods/chat.ts Resolved
Comment thread ui/src/ui/chat/tool-cards.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3324207a74

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Resolved
Comment thread src/tui/components/tool-execution.ts Resolved
@ademczuk

ademczuk commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@ademczuk

ademczuk commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

@Takhoffman — this touches TUI (tool-execution, formatters, event-handlers), gateway (server-chat, chat.ts injection pipeline), and WebUI (tool-cards, grouped-render, chat-event-reload). You're the closest domain match for TUI+gateway. Would appreciate your review when you have a moment.

Bot review findings addressed:

  • ✅ greptile: duplicate regex → now imports shared MEDIA_IMAGE_LINE_RE from src/media/parse.ts (11cb6923d7)
  • ✅ greptile: case-sensitive startsWith → updated to case-insensitive regex (11cb6923d7)
  • ✅ codex P1: sanitize-before-inject ordering → by design (sanitize strips stale binary, inject re-reads from paths)
  • ✅ codex P2: MEDIA lines stripped on non-image terminals → acknowledged, tracked as hardening enhancement

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11cb6923d7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Resolved
Comment thread src/gateway/server-methods/chat.ts Resolved
@ademczuk

ademczuk commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

@joshavant Would you be open to reviewing this PR? It spans gateway (chat.ts injection pipeline), media (parse.ts shared regex), TUI (tool-execution.ts two-stage render), and WebUI (app-tool-stream.ts + chat-event-reload.ts) — areas you've recently worked in (#35094). All 6 bot comments are addressed, CI is green (22/22), and 118 scoped tests pass. Happy to clarify any part of the pipeline.

@ademczuk
ademczuk force-pushed the feat/tui-inline-image-rendering branch from 3985d81 to a2f9397 Compare March 6, 2026 00:28
@ademczuk ademczuk closed this Mar 6, 2026
@ademczuk ademczuk reopened this Mar 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2f9397886

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Resolved
Comment thread ui/src/ui/app-tool-stream.ts Resolved
@ademczuk
ademczuk force-pushed the feat/tui-inline-image-rendering branch from 131392a to 6e270f8 Compare March 6, 2026 06:25
@ademczuk ademczuk closed this Mar 6, 2026
@ademczuk ademczuk reopened this Mar 6, 2026
Comment thread src/gateway/server-methods/chat.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e270f861a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Resolved
Comment thread src/gateway/server-methods/chat.ts Resolved
@ademczuk ademczuk closed this Mar 6, 2026
@ademczuk ademczuk reopened this Mar 6, 2026
Comment thread src/tui/components/tool-execution.ts Resolved
Comment thread src/tui/components/tool-execution.ts Resolved
@ademczuk

ademczuk commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

All bot review findings from the latest round (commits 6e270f86 and 2ce0cae9) are now addressed:

Fixed in 695b7f648d:

  • ✅ greptile: flush path missing base64 dedup — added seen64 Set filter mirroring main injection path
  • ✅ greptile: MEDIA lines filtered unconditionally on non-image terminals — gated filter on willRenderImages
  • ✅ greptile: TOCTOU lstat/readFile asymmetry — added post-read size guard matching server-side pattern

Replied (no code change needed):

  • ✅ codex P2: regex word boundary — false positive (greedy quantifier already prevents mid-filename match)
  • ✅ codex P1: bare image blocks lost — repeat of earlier finding, acknowledged limitation for URL-sourced images (out of scope)

Bot comment tally: 18 root comments, 18 answered (0 unanswered).
CI: All green on prior run; new run triggered by this push.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 695b7f648d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Resolved
@ademczuk
ademczuk force-pushed the feat/tui-inline-image-rendering branch from cbb033c to 670c132 Compare March 6, 2026 07:53
Comment thread src/tui/tui-formatters.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cc443e062

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/gateway/server-methods/chat.ts Resolved
@ademczuk
ademczuk force-pushed the feat/tui-inline-image-rendering branch from 3cc443e to ecfceb5 Compare March 7, 2026 08:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ecfceb531e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

for (const entry of this.result?.content ?? []) {
if (entry.type === "text" && typeof entry.text === "string") {
lastMediaRenderedFromFile = false;
for (const match of entry.text.matchAll(MEDIA_TOKEN_RE)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip fenced MEDIA tokens before reading local image files

The inline-render path scans entry.text with MEDIA_TOKEN_RE directly, so a literal MEDIA:/...png inside fenced code (or other non-artifact text) is treated as a real file reference. On image-capable terminals this can trigger unintended local file reads/renders, while the gateway-side extractor intentionally skips fenced spans. Reusing the same fence-aware extraction logic here (instead of raw matchAll) avoids rendering artifacts from documentation/examples.

Useful? React with 👍 / 👎.

@ademczuk

ademczuk commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor Author

The secrets CI check failure is expected — fork PRs cannot access repo secrets. All other checks should pass normally.

Rebase cleanup (latest):

  • Rebased onto latest main (includes Android package rename commits)
  • Dropped unrelated openai-http.ts source.data guard commit — not part of inline image rendering
  • Removed meta rebase-proof screenshot (process noise, not a feature asset)
  • PR now contains 26 files, all directly related to the inline image rendering pipeline (TUI, gateway, WebUI, shared media, tests, docs screenshots)

ademczuk and others added 15 commits March 7, 2026 10:48
Add end-to-end inline image rendering for TUI and WebUI when agents use
image-viewing tools. The image tool now emits MEDIA:<path> text blocks
alongside base64 image content blocks. The gateway's chat.history endpoint
detects these markers, reads the images from disk, and injects base64 data
into the response so both the TUI and WebUI can render images inline.

Key changes:
- image-tool.ts: emit MEDIA:<container-path> + {type:"image"} blocks
- pi-embedded-subscribe.tools.ts: bypass base64 stripping when MEDIA present
- server-chat.ts: MEDIA bypass preserves tool results with image data
- chat.ts: extractMediaImagePaths + injectMediaImagesIntoHistory pipeline
- chat.ts: path traversal check BEFORE normalize (security hardening)
- chat.ts: collect regex matches synchronously before async I/O (concurrency fix)
- tool-execution.ts: two-stage render (file-based + base64 fallback)
- tui-formatters.ts: resultHasMedia() for MEDIA + image block detection
- app-tool-stream.ts: detect MEDIA image paths in WebUI tool stream
- chat-event-reload.ts: reload chat history when images detected
- Shared MEDIA_IMAGE_LINE_RE regex in src/media/parse.ts (DRY)

Co-Authored-By: Claude <[email protected]>
- Import MEDIA_IMAGE_LINE_RE from src/media/parse.ts instead of
  duplicating the regex locally in chat.ts (DRY).
- Use case-insensitive regex for MEDIA: line filtering in tool-cards.ts
  to stay consistent with the rest of the pipeline.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Shows both the TUI (Docker terminal with iTerm2 protocol) and WebUI
(OpenClaw Control dashboard) rendering the same cat image inline after
the agent executed `sh /app/view-image.sh`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
… gate, TOCTOU guard

- Add base64 content dedup to flush path in chat.ts (mirrors main injection)
- Gate MEDIA line filter on willRenderImages so non-image terminals preserve
  path text as fallback
- Add post-read size check in tool-execution.ts (mirrors server-side
  readImageAsBase64 defense-in-depth)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
…xtensions

IMAGE_PATH_IN_COMMAND_RE used \b after the extension group, which allowed
greedy backtracking to match e.g. `/tmp/photo.png` from `photo.png.txt`
(\b succeeds between 'g' and '.'). Replace \b with (?!\.) negative
lookahead to reject matches followed by a dot.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Greptile flagged that the TUI's validateMediaPath accepted relative paths
while the server-side extractMediaImagePaths requires absolute paths.
Close the asymmetry for defense-in-depth consistency.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The collection loop's byte budget check only reflected already-injected
bytes, not pending ones. In runs with many MEDIA: paths before the next
assistant message, files could be read and base64-encoded only to be
discarded at injection time. Track pendingBytes alongside pendingImages
so the budget gate accounts for both committed and pending data.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- pi-embedded-subscribe.tools.ts: replace ad-hoc /^MEDIA:/gm with
  shared MEDIA_IMAGE_LINE_RE for consistency with gateway + TUI detection.
  Prevents counting MEDIA: text inside code fences and limits matching
  to image-extension paths only.
- grouped-render.ts: tighten sanitizeDataUrl regex from [a-z+]+ to
  [a-z][a-z0-9+\-]* so degenerate MIME subtypes like "image/+++" are
  rejected at the regex level (defense-in-depth; ALLOWED_IMAGE_MIME_TYPES
  allowlist already catches these).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
1. Restructure budget-exhausted check in injectMediaImagesIntoHistory so
   already-pending images still attach to the correct assistant message
   instead of flushing at end-of-history to an unrelated message.

2. Fix oxlint no-useless-escape: remove unnecessary \- in character class
   in grouped-render.ts sanitizeDataUrl regex.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
extractMediaImagePaths now mirrors the shared splitMediaFromOutput parser
by using parseFenceSpans to skip MEDIA: tokens inside Markdown fenced
code regions, preventing accidental image injection from documentation
snippets in tool output.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Mirrors the gateway-side fence-skipping fix in extractMediaImagePaths.
Uses parseFenceSpans to avoid treating MEDIA: lines inside Markdown
code fences as renderable image paths.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Not a feature asset — process noise that doesn't belong in the PR.
@ademczuk
ademczuk force-pushed the feat/tui-inline-image-rendering branch from ecfceb5 to e09f616 Compare March 7, 2026 09:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e09f6167fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +288 to +289
if (Array.isArray(entry.content)) {
const updated = entry.content.map((nested: unknown) => sanitizeChatHistoryContentBlock(nested));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep nested image data when no MEDIA path can rehydrate

In the chat.history flow (sanitizeChatHistoryMessages then injectMediaImagesIntoHistory), this recursive sanitization now strips data from nested tool_result image blocks too, but the injector only rebuilds images from MEDIA: file paths or exec-command paths. For URL/data-image tool results (which have inline base64 but no local path), reload loses the only renderable image payload, so WebUI can no longer display those images after finalization.

Useful? React with 👍 / 👎.

Comment thread src/gateway/server-methods/chat.ts Resolved
@ademczuk

ademczuk commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

@ademczuk ademczuk closed this Mar 7, 2026
@ademczuk
ademczuk deleted the feat/tui-inline-image-rendering branch March 7, 2026 11:22
ademczuk added a commit to ademczuk/openclaw that referenced this pull request Mar 18, 2026
Tools emit images as [TEXT with MEDIA:path, IMAGE with base64] pairs.
When a MEDIA text block is rendered from file, the immediately following
image block (base64 duplicate) is now skipped via lastMediaRenderedFromFile
flag. Orphan image blocks without a preceding MEDIA path still render
from base64. This dedup logic is from the original PR openclaw#36740.

Also restores data field on ToolResultContent type so image content
blocks with inline base64 can be rendered as a fallback when no
preceding MEDIA path exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant