feat(assistants): implement Codex rollout-based file attachment detection - #508
Conversation
…oad detection Replace broken two-pass buildAttachmentMap (wrong JSONL structure assumption) and RECENT_MESSAGES_LIMIT=2 (too narrow for real sessions with tool-result messages) with a turn-boundary backward scan that stops at the most recent assistant message. Real Claude Code JSONL has isMeta=true messages carrying both base64 attachment data and [Image: source: /path] filename text in the same message object. The old code expected base64 in a non-meta parent and filename text in a meta child, so the attachment map was never populated and zero files were returned. The scan window of 2 also broke in real sessions where tool-result messages at positions 1-2 pushed the image meta message to position 3, outside the window. EPMCDME-13907
…ude sessions The previous turn-boundary scan (stopping at type==='assistant') failed in real Claude Code JSONL because: - Bug A: the assistant tool_use entry appears *after* the user's isMeta messages for the same prompt, so the scan broke before reaching the images. - Bug B: base64 data and the [Image: source: /path] filename live in two *separate* isMeta entries (not the same one), so the old single-message pass produced the image with a fallback filename. Fix: use the promptId field that Claude Code stamps on every message in a single prompt turn. Find the most recent non-meta user message, capture its promptId, collect all isMeta messages sharing that id, gather filenames across them first, then match positionally to base64 attachment items. Also adds promptId to the ClaudeMessage interface and updates test fixtures to reflect the real split-message JSONL structure. Generated with AI Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
…t --conversation-id --conversation-id identifies the assistant chat thread (e.g. a workflow_id generated by a skill). CODEMIE_SESSION_ID identifies the Claude session whose JSONL contains uploaded file blobs. Using --conversation-id for session lookup caused detectFileUploadsFromSession to look for a non-existent session file, returning no attachments even when files were uploaded in the current Claude turn. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0162w98kuqJ7EWaA6h2FjDCK
…tion Adds detectCodexFileUploads() which discovers the active Codex rollout by scanning ~/.codex/sessions via getCodexDiscoverySessionRoots() and matching session_meta.cwd to the caller's CWD. Extracts input_image blocks from the most recent user response_item record. Wires CODEMIE_AGENT-aware dispatch in chat/index.ts: when CODEMIE_AGENT equals 'codex', the new detector runs; otherwise the existing Claude CODEMIE_SESSION_ID path is used (no regression). Also adds CodexResponseItemMessage, CodexContentBlock, and extends CodexEventMsg with images/local_images to make attachment types explicit. Generated with AI Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
- CR-001: use imageOnlyIndex (increments only on input_image) for local_images lookups; the prior localImageIndex incremented on input_file blocks too, misaligning filename resolution in mixed file+image turns - CR-002: find targetEventMsg in a second backward pass bounded to records at or before the response_item position, so a follow-up message no longer severs the filename chain from the attachment turn - CR-003: estimate decoded size with base64 length math before the size guard, avoiding a full Buffer.from allocation that could OOM and silently drop valid attachments; also reject empty data URI payloads early Generated with AI Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
Planning, review, and complexity-assessment artifacts for the Codex file attachment detection implementation (sdlc-light flow). Generated with AI Co-Authored-By: codemie-ai <codemie.ai@gmail.com>
Addresses the CLI -> Registry -> Plugin boundary review comment on the Codex upload detector: it imported plugin internals directly (codex.paths.js, session/codex-user-prompt.js). Expose getCodexDiscoverySessionRoots, isCodexInjectedUserText, CodexDiscoveryRoot, CodexResponseItemMessage and CodexContentBlock from the codex plugin's public index barrel, and repoint the detector to import only that contract. Refs: EPMCDME-13885
Disposition of the automated-review blockers from #466Pushed ① ② CLI imports Codex plugin internals — FIXED ( ③ |
Verification SummaryFeature: Codex rollout-based file-attachment detection for Verification Methods
Review-comment dispositions (verified)
VerdictVerified end-to-end, including a real Codex 0.143 rollout. Ready for review/merge. |
…eta turn message Claude Code 2.1.218 stores an uploaded image's base64 in the NON-meta user message of the prompt turn (marked "[Image #N]"), while the "[Image: source: /path]" filename text is in a separate isMeta message of the same promptId. The detector collected attachments from isMeta messages only, so on real sessions it found the filename but no base64 and returned zero attachments (silent no-op of the automatic detection this path advertises). Collect every message of the current prompt turn by promptId regardless of isMeta; promptId still bounds detection to the current turn (earlier turns are not re-sent). Add a regression test for the real 2.1.218 structure. Verified end-to-end against a real live upload: detection goes 0 -> 1. Refs: EPMCDME-13907
Summary
Tickets: Fixes EPMCDME-13885, Fixes EPMCDME-13907
Codex side (EPMCDME-13885)
src/cli/commands/assistants/chat/codexUploadsDetector.ts: scans Codex rollout JSONL by matching session cwd to the current working directory (symlink-tolerant realpath), extractsinput_imageblocks from the most-recent user turn via a two-pass scan, OOM-safe base64 size guard.src/agents/plugins/codex/codex-message-types.ts: addsCodexResponseItemMessageandCodexContentBlock; extendsCodexEventMsg.src/cli/commands/assistants/chat/index.ts:CODEMIE_AGENT === 'codex'dispatch gate; Codex sessions take the new path, Claude sessions keep theCODEMIE_SESSION_IDpath.src/agents/plugins/codex/index.ts: exposesgetCodexDiscoverySessionRoots,isCodexInjectedUserTextand related types on the public barrel so the CLI imports only the plugin's public contract.Claude side (EPMCDME-13907)
src/cli/commands/assistants/chat/claudeUploadsDetector.ts: replaces the buggyRECENT_MESSAGES_LIMIT=2window and parent/child assumption with promptId-based current-turn grouping.436a0d9): collect every message of the current prompt turn by promptId regardless ofisMeta. Claude Code 2.1.218 stores the uploaded image base64 in the NON-meta turn message (marked[Image #N]) while the[Image: source: /path]filename text is in a separateisMetamessage of the same promptId. CollectingisMeta-only detected the filename but no base64 and returned zero attachments. promptId still bounds detection to the current turn (earlier turns not re-sent). A regression test for the real 2.1.218 structure was added.Verification
input_imagewithimage_urlstartingdata:image/png;base64, the image-name/path wrapper, andevent_msg.local_images. Running the realcodemie assistants chatwithCODEMIE_AGENT=codexdetected 1 file, uploaded it, and the assistant confirmed it saw the image.Reviewer feedback from #466
options.conversationId"regression" — WON'T FIX (intended).--conversation-ididentifies the assistant chat thread;CODEMIE_SESSION_IDidentifies the Claude session whose JSONL holds the uploaded blobs. FeedingconversationIdintodetectFileUploadsFromSessionsearches a non-existent session file — the exact bug fixed by commitbfb011c.540bef1). The detector imports only the codex plugin's publicindex.tsbarrel; deep imports removed. Remaining deep imports inanalytics/*are pre-existing onmain; out of scope.CodexSessionMetadata"5 unused fields" — WON'T FIX (premise incorrect). The type pre-exists onmain(diff additions-only) and its fields are consumed by the metrics/conversations processors; stripping breaks the build.Supersedes #466 (original author is no longer working on it).