Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

feat: enhance image path detection in input processing (#189)

Thomasbe7e3fd37732
diff --git a/codex-cli/src/components/chat/terminal-chat-input.tsx b/codex-cli/src/components/chat/terminal-chat-input.tsx
index ae107077a6..8fd0c63aab 100644
--- a/codex-cli/src/components/chat/terminal-chat-input.tsx
+++ b/codex-cli/src/components/chat/terminal-chat-input.tsx
@@ -234,13 +234,34 @@ export default function TerminalChatInput({
return;
}
+ // detect image file paths for dynamic inclusion
const images: Array<string> = [];
- const text = inputValue
- .replace(/!\[[^\]]*?\]\(([^)]+)\)/g, (_m, p1: string) => {
+ let text = inputValue;
+ // markdown-style image syntax: ![alt](path)
+ text = text.replace(/!\[[^\]]*?\]\(([^)]+)\)/g, (_m, p1: string) => {
+ images.push(p1.startsWith("file://") ? fileURLToPath(p1) : p1);
+ return "";
+ });
+ // quoted file paths ending with common image extensions (e.g. '/path/to/img.png')
+ text = text.replace(
+ /['"]([^'"]+?\.(?:png|jpe?g|gif|bmp|webp|svg))['"]/gi,
+ (_m, p1: string) => {
images.push(p1.startsWith("file://") ? fileURLToPath(p1) : p1);
return "";
- })
- .trim();
+ },
+ );
+ // bare file paths ending with common image extensions
+ text = text.replace(
+ // eslint-disable-next-line no-useless-escape
+ /\b(?:\.[\/\\]|[\/\\]|[A-Za-z]:[\/\\])?[\w-]+(?:[\/\\][\w-]+)*\.(?:png|jpe?g|gif|bmp|webp|svg)\b/gi,
+ (match: string) => {
+ images.push(
+ match.startsWith("file://") ? fileURLToPath(match) : match,
+ );
+ return "";
+ },
+ );
+ text = text.trim();
const inputItem = await createInputItem(text, images);
submitInput([inputItem]);