# AI Record Summaries

## Objective

Turn a long record and its history into a short overview of what matters now.

A generated overview of a single record's current state and recent history, marked as interpretation and regenerated when the record changes.

## 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. Assemble the input by reading the record through the same authorization path the detail page uses, at generation time, so the summary reflects current values rather than a cached copy.
2. Pass factual values — dates, amounts, statuses, counts, identifiers — through unchanged and render them from the record itself rather than from the generated text, so a rounding or transcription error is impossible.
3. Label the summary clearly as generated interpretation, and keep the underlying fields visible on the same screen so a reader can check any statement against the source.
4. Regenerate when a field that materially changes the picture is written — status, owner, amount, stage — and mark the existing summary stale in the meantime rather than showing it as current.
5. Thread and message summarisation belongs to AI Conversation Summaries. This feature covers the record's fields and activity history; do not summarise attached discussions here.

## 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

- A summary built from a stale cache will describe a status the record no longer has. Read live at generation time and record which version of the record produced the text.
- Numbers and dates must be exact. Do not let the model restate a figure in prose; render the real value and let the narrative reference it.
- Interpretation presented as fact is the main risk in this feature. Separate what the record says from what the model concludes, and mark the second as such.
- When a material field changes, the old summary becomes misleading. Mark it stale immediately and regenerate in the background rather than leaving it looking fresh.
- Internal notes, restricted fields, and audit entries a viewer cannot open must never appear in the summary text, including paraphrased.
- Records with almost no content produce padded, meaningless summaries. Set a content threshold and show the record plainly instead.
- Regenerating on every write is expensive on busy records. Debounce, cap regenerations per record per day, and skip when only cosmetic fields changed.
- When the model is unavailable or refuses, the record page renders normally with the summary area showing an unavailable state.

## 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

- [ ] Summaries are generated from a live authorized read and record the record version they describe.
- [ ] Dates, amounts, and statuses shown alongside the summary come from the record, not from generated text.
- [ ] The summary is labelled as interpretation and sits beside the underlying fields.
- [ ] A material field change marks the summary stale and queues a regeneration.
- [ ] Restricted fields and internal notes never appear in the summary, including in paraphrase.
- [ ] Regeneration is debounced and capped per record, and cosmetic edits do not trigger it.
- [ ] The record page is fully usable when the model is unavailable.
- [ ] 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.
