Repository navigation
Conversation
7d053d4 to
61d26d2
Compare
Greptile SummaryThis PR implements an end-to-end inline image rendering pipeline: the image tool emits The implementation is thorough and carefully engineered, with comprehensive security guards ( One remaining inconsistency to address:
Confidence Score: 4/5
Last reviewed commit: 3cc443e |
There was a problem hiding this comment.
💡 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".
|
@codex review |
|
@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:
|
There was a problem hiding this comment.
💡 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".
|
@joshavant Would you be open to reviewing this PR? It spans gateway ( |
3985d81 to
a2f9397
Compare
There was a problem hiding this comment.
💡 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".
131392a to
6e270f8
Compare
There was a problem hiding this comment.
💡 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".
|
All bot review findings from the latest round (commits Fixed in
Replied (no code change needed):
Bot comment tally: 18 root comments, 18 answered (0 unanswered). |
There was a problem hiding this comment.
💡 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".
cbb033c to
670c132
Compare
There was a problem hiding this comment.
💡 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".
3cc443e to
ecfceb5
Compare
There was a problem hiding this comment.
💡 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)) { |
There was a problem hiding this comment.
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 👍 / 👎.
|
The Rebase cleanup (latest):
|
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]>
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]>
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.
ecfceb5 to
e09f616
Compare
There was a problem hiding this comment.
💡 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".
| if (Array.isArray(entry.content)) { | ||
| const updated = entry.content.map((nested: unknown) => sanitizeChatHistoryContentBlock(nested)); |
There was a problem hiding this comment.
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 👍 / 👎.
|
Closing in favor of a Discussion first. |
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.
Summary
view-image,imgcat), the resulting images are invisible — TUI shows only text output, WebUI shows nothing.MEDIA:<path>text blocks +{type:"image"}base64 blocks → gateway detects markers and injects images intochat.historyresponses → TUI renders via iTerm2 graphics protocol → WebUI renders inline after history reload.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
caps: ["tool-events"]).Screenshots
TUI (Docker terminal) + WebUI (OpenClaw Control) — 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)
readImageAsBase64function has multiple guards: (1) path traversal check on raw input BEFOREpath.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
Steps
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
118 tests across 6 test files:
Human Verification (required)
Changed Files
Compatibility / Migration
Failure Recovery (if this breaks)
Risks and Mitigations
Risk: Gateway memory spike when processing many large images (base64 encoding ~33% overhead).
Risk: MEDIA_IMAGE_LINE_RE regex drift between shared constant and inline usage.
Risk: TOCTOU between lstat (symlink check) and readFile in readImageAsBase64.
Test Plan
Supersedes #36641 (closed for clean commit history and fresh bot review).