Feature: URL and document context attachments

Merged
SL
5mo ago
+1265-14

Summary

  • add an explicit /api/context-preview endpoint for URL and local document context previews
  • support bounded previews for HTTP(S), markdown, text, JSON, and small text-based PDFs before send
  • wire reviewed context attachments into the composer, optimistic sends, pending sends, and /api/send prompt context

Files

  • apps/codex-claw/src/server/context-attachments.ts - bounded preview/extraction, send-time validation, and prompt assembly
  • apps/codex-claw/src/routes/api/context-preview.ts - preview API route
  • apps/codex-claw/src/routes/api/send.ts - includes reviewed context attachments in prompt context
  • apps/codex-claw/src/screens/chat/components/context-attachment-picker.tsx - URL/document preview and attach UI
  • apps/codex-claw/src/screens/chat/components/chat-composer.tsx - composer state and toolbar integration
  • apps/codex-claw/src/screens/chat/chat-screen.tsx and pending send files - payload carryover into sends
  • apps/codex-claw/src/server/context-attachments.test.ts - extraction, rejection, and prompt assembly coverage

Testing

  • pnpm -C apps/codex-claw lint
  • pnpm -C apps/codex-claw test
  • pnpm -C apps/codex-claw build

Risk

  • URL previews are explicit and bounded, but still perform server-side HTTP(S) fetches for the requested preview.
  • PDF extraction is intentionally limited to small text-based PDFs; scanned/compressed PDFs return an actionable error.

Closes #92


Summary by cubic

Adds URL and document context attachments with safe, bounded previews and sends them as prompt context so users can attach web pages or files to a chat. Includes a composer UI to preview and attach up to six items, plus server-side extraction, validation, and tests.

  • New Features

    • Added POST /api/context-preview to preview URL or document context.
    • Supports HTTP(S) pages, markdown, text, JSON, and small text-based PDFs; returns clear errors for unsupported/large content.
    • New composer controls to preview, add/remove, and summarize attachments; optimistic and pending sends carry contextAttachments.
    • /api/send parses reviewed attachments and builds a prompt block via server utilities, merged with repository context when present.
    • Server enforces size/token bounds, strips scripts/styles and normalizes HTML; extracts basic PDF text; full test coverage.
  • Bug Fixes

    • Hardened HTML filtering for URL previews to handle malformed tags and prevent content bleed.