# Multimodal Image Analysis

## Objective

Let users ask questions about screenshots, photos, charts, and interface images.

Image input on AI conversations, with safe downscaling, grounded answers, and defined retention of derived copies.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Prepare images before they are sent: correct orientation, strip location and camera metadata, and downscale to the smallest size that still keeps small text and fine detail legible.
2. Require the answer to distinguish what is visible in the image from what is inferred, and to say when the image is too low in quality to support a conclusion.
3. Label and reference images explicitly when more than one is attached, so a question about the second chart is not answered from the first.
4. Refuse identity claims and inferences about protected or sensitive attributes from a person's appearance, and define this refusal in the app rather than relying on the provider to enforce it.
5. AI Chat Attachments owns upload, storage, scoping, and retention. This entry owns preparation and interpretation. Do not build a separate upload path for images.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Aggressive downscaling destroys exactly what users most often ask about: small interface text, axis labels, and error messages. Size against legibility, and offer a region crop rather than degrading the whole image.
- Questions inviting the model to identify a person or infer their age, ethnicity, health, or beliefs from a photograph must be refused with an explanation, not answered with a hedged guess.
- An answer that mixes what is on the pixels with what the model assumes is unfalsifiable. Require visible evidence to be stated separately from interpretation.
- With several images attached, an unlabelled reference is ambiguous. Number or name them in both the prompt and the answer so the user can tell which one is being described.
- Uploaded images and every derived copy, including thumbnails, downscaled versions, and cached crops, must inherit the conversation's access scope and be deleted on the same schedule as the original.
- Images containing credentials, personal documents, or payment details will be uploaded by users who did not think about it. Warn where it is plausible and never log image content or derived text into general application logs.
- Animated, multi-page, and very large images need a defined handling rule rather than an unhandled failure.
- When image input is unavailable, the feature must say so and fall back to text-only conversation rather than accepting the upload and ignoring it.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Images are reoriented, stripped of location and camera metadata, and downscaled without losing small text legibility.
- [ ] Answers separate what is visible in the image from what is inferred and say when the image is insufficient.
- [ ] Identity claims and sensitive-attribute inferences are refused with an explanation.
- [ ] Multiple images are labelled and referenced unambiguously in both the request and the answer.
- [ ] Derived copies inherit the conversation's access scope and are deleted with the original.
- [ ] Image content and extracted text never appear in general application logs.
- [ ] Unavailable image support degrades to text-only with a clear message rather than a silent no-op.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
