From e22feb0215b8e52eb42b77450008989d0ae6d6ed Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 8 Oct 2026 17:59:49 +0900 Subject: [PATCH] feat(attachments): allow Office documents as outbound attachments Bots had to zip .pptx decks because the outbound allowlist only covered images, audio/video, pdf, zip and plain-text files. Add docx/xlsx/pptx (checked for the ZIP local-file-header signature) and legacy doc/xls/ppt (checked for the OLE2 compound-file signature). The 8MB cap and the allowed-directory rules are unchanged. Prompt format lists are updated so agents stop zipping these files. Co-Authored-By: Claude Opus 5.5 --- prompts/claude-platform.md | 2 +- prompts/codex-platform.md | 2 +- prompts/owner-common-platform.md | 2 +- src/outbound-attachments.test.ts | 43 ++++++++++++++++++++++++++++++++ src/outbound-attachments.ts | 25 +++++++++++++++++++ 5 files changed, 71 insertions(+), 3 deletions(-) diff --git a/prompts/claude-platform.md b/prompts/claude-platform.md index e52ff54..6364a75 100644 --- a/prompts/claude-platform.md +++ b/prompts/claude-platform.md @@ -25,7 +25,7 @@ When a locally generated image, screenshot, video, audio, or document should app MEDIA:/absolute/path/preview.mp4 ``` -`MEDIA:` lines are hidden from the visible message and uploaded as native Discord attachments. Use absolute local paths only, do not repeat the same path in the visible text, and do not use generic markdown links or plain file paths as attachment directives. Supported formats include PNG, JPEG, GIF, WebP, BMP, MP4, MOV, WebM, MP3, WAV, OGG, M4A, FLAC, PDF, ZIP, TXT, Markdown, CSV, and JSON. SVG is not accepted. +`MEDIA:` lines are hidden from the visible message and uploaded as native Discord attachments. Use absolute local paths only, do not repeat the same path in the visible text, and do not use generic markdown links or plain file paths as attachment directives. Supported formats include PNG, JPEG, GIF, WebP, BMP, MP4, MOV, WebM, MP3, WAV, OGG, M4A, FLAC, PDF, ZIP, DOCX, XLSX, PPTX, DOC, XLS, PPT, TXT, Markdown, CSV, and JSON. SVG is not accepted. ## Making channel registration live (never fake a restart) diff --git a/prompts/codex-platform.md b/prompts/codex-platform.md index d507690..0e9fb43 100644 --- a/prompts/codex-platform.md +++ b/prompts/codex-platform.md @@ -40,7 +40,7 @@ MEDIA:/absolute/path/preview.mp4 - URLs and relative paths are ignored - Do not repeat the same file path elsewhere in the visible text - Do not use generic markdown links or plain file paths as attachment directives -- Supported formats include PNG, JPEG, GIF, WebP, BMP, MP4, MOV, WebM, MP3, WAV, OGG, M4A, FLAC, PDF, ZIP, TXT, Markdown, CSV, and JSON. SVG is not accepted. +- Supported formats include PNG, JPEG, GIF, WebP, BMP, MP4, MOV, WebM, MP3, WAV, OGG, M4A, FLAC, PDF, ZIP, DOCX, XLSX, PPTX, DOC, XLS, PPT, TXT, Markdown, CSV, and JSON. SVG is not accepted. - Use this for generated images, e2e screenshots, previews, audio samples, and documents; the Discord channel validates and uploads the file ## CI 감시 (watch_ci) diff --git a/prompts/owner-common-platform.md b/prompts/owner-common-platform.md index 5f4642d..f6df4cf 100644 --- a/prompts/owner-common-platform.md +++ b/prompts/owner-common-platform.md @@ -31,7 +31,7 @@ MEDIA:/absolute/path/preview.mp4 - `MEDIA:` lines are hidden from the visible message and uploaded as native Discord attachments - Use absolute local paths only, and do not repeat the same path elsewhere in the visible text - Do not rely on generic markdown links or plain file paths for attachments -- Supported formats include PNG, JPEG, GIF, WebP, BMP, MP4, MOV, WebM, MP3, WAV, OGG, M4A, FLAC, PDF, ZIP, TXT, Markdown, CSV, and JSON. SVG is not accepted. +- Supported formats include PNG, JPEG, GIF, WebP, BMP, MP4, MOV, WebM, MP3, WAV, OGG, M4A, FLAC, PDF, ZIP, DOCX, XLSX, PPTX, DOC, XLS, PPT, TXT, Markdown, CSV, and JSON. SVG is not accepted. - The channel harness validates and uploads attachments from these media directives ## CI monitoring (watch_ci) diff --git a/src/outbound-attachments.test.ts b/src/outbound-attachments.test.ts index 4fd6429..54d85b2 100644 --- a/src/outbound-attachments.test.ts +++ b/src/outbound-attachments.test.ts @@ -20,6 +20,9 @@ const MINIMAL_MP4 = Buffer.from([ ]); const MINIMAL_PDF = Buffer.from('%PDF-1.4\n', 'ascii'); const MINIMAL_ZIP = Buffer.from([0x50, 0x4b, 0x03, 0x04, 0x14, 0x00]); +const MINIMAL_OLE2 = Buffer.from([ + 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1, 0x00, 0x00, +]); const cleanupDirs: string[] = []; const cleanupFiles: string[] = []; @@ -178,6 +181,46 @@ describe('validateOutboundAttachments', () => { }, ]); }); + it('accepts Office documents with matching container signatures', () => { + const dir = makeTempDir(os.tmpdir(), 'ejclaw-office-'); + const names = [ + ['report.docx', MINIMAL_ZIP], + ['table.xlsx', MINIMAL_ZIP], + ['slides.pptx', MINIMAL_ZIP], + ['legacy.doc', MINIMAL_OLE2], + ['legacy.xls', MINIMAL_OLE2], + ['legacy.ppt', MINIMAL_OLE2], + ] as const; + const paths = names.map(([name, content]) => writeFile(dir, name, content)); + + const result = validateOutboundAttachments( + paths.map((filePath) => ({ path: filePath })), + ); + + expect(result.rejected).toEqual([]); + expect(result.files.map((file) => file.name)).toEqual( + names.map(([name]) => name), + ); + }); + + it('rejects Office documents whose signature does not match', () => { + const dir = makeTempDir(os.tmpdir(), 'ejclaw-office-bad-'); + const fakePptx = writeFile(dir, 'fake.pptx', MINIMAL_OLE2); + const fakePpt = writeFile(dir, 'fake.ppt', MINIMAL_ZIP); + const textPptx = writeFile(dir, 'text.pptx', 'not a deck\n'); + + expect( + validateOutboundAttachments([ + { path: fakePptx }, + { path: fakePpt }, + { path: textPptx }, + ]).rejected, + ).toEqual([ + { path: fakePptx, reason: 'invalid-file-signature' }, + { path: fakePpt, reason: 'invalid-file-signature' }, + { path: textPptx, reason: 'invalid-file-signature' }, + ]); + }); }); describe('validateOutboundAttachments policy checks', () => { diff --git a/src/outbound-attachments.ts b/src/outbound-attachments.ts index e2ec5aa..a1b93ac 100644 --- a/src/outbound-attachments.ts +++ b/src/outbound-attachments.ts @@ -35,6 +35,14 @@ const SUPPORTED_ATTACHMENT_MIMES: Record = { '.flac': 'audio/flac', '.pdf': 'application/pdf', '.zip': 'application/zip', + '.docx': + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + '.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + '.pptx': + 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + '.doc': 'application/msword', + '.xls': 'application/vnd.ms-excel', + '.ppt': 'application/vnd.ms-powerpoint', '.txt': 'text/plain', '.md': 'text/markdown', '.csv': 'text/csv', @@ -222,6 +230,23 @@ function detectSupportedMime(filePath: string): string | null { header.subarray(0, 4).equals(Buffer.from([0x50, 0x4b, 0x07, 0x08])) ? expectedMime : null; + // Office Open XML files are ZIP containers and always start with a local + // file header. + case '.docx': + case '.xlsx': + case '.pptx': + return header.subarray(0, 4).equals(Buffer.from([0x50, 0x4b, 0x03, 0x04])) + ? expectedMime + : null; + // Legacy Office files use the OLE2 compound file signature. + case '.doc': + case '.xls': + case '.ppt': + return header + .subarray(0, 8) + .equals(Buffer.from([0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1])) + ? expectedMime + : null; case '.txt': case '.md': case '.csv':