# AI Conversation Summaries

## Objective

Condense a long thread into the decisions made, questions open, and next steps.

A generated summary of a conversation, structured into decisions, open questions, and actions, shown as a draft beside the thread.

## 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. Build the summary only from messages the viewer can currently read, resolved at generation time. Deleted, redacted, and private messages must be excluded from the input, not filtered out of the output.
2. Structure the output into decisions that were confirmed, questions still open, and next steps with an owner where one is stated, and require the model to leave a section empty rather than pad it.
3. Summarise incrementally: when new messages arrive, extend the previous summary with the new material instead of regenerating from the whole thread, and carry forward earlier decisions rather than dropping them.
4. Present the summary as a draft with the generation time and a regenerate control. Do not post it into the thread or notify participants automatically.
5. AI Record Summaries covers the fields and history of a record. This feature covers message threads; if a record has both, keep them as separate summaries rather than merging them into one block.

## 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 decision and a suggestion read almost the same in a chat log. Anything not explicitly agreed must be listed as an open question, and a summary that promotes speculation to a decision is a defect.
- Attribution matters when the thread contains disagreement or commitment. Name the participant behind a decision or an action, and omit attribution rather than guessing when the thread is ambiguous.
- Incremental updates lose earlier context if the previous summary is treated as disposable. Preserve prior decisions and mark them superseded when later messages overturn them.
- Messages deleted, edited, or restricted after the fact must invalidate the summary. A quote from a retracted message surviving in a summary re-publishes what someone withdrew.
- A thread of three messages does not need a summary. Set a minimum length and say the conversation is too short rather than producing filler.
- Long threads must respect a token ceiling. State when the summary covers only part of the thread and from which point it starts.
- A truncated or malformed generation must be discarded rather than shown. Keep the previous summary in place and offer a retry.
- When the model is unavailable, the thread reads normally and the summary panel shows 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 only from messages the viewer may read at the moment of generation.
- [ ] Output is separated into confirmed decisions, open questions, and next steps, with empty sections left empty.
- [ ] New messages extend the existing summary without discarding earlier decisions.
- [ ] Deleted, edited, or newly restricted messages invalidate the summary.
- [ ] Summaries appear as timestamped drafts and are never posted into the thread automatically.
- [ ] Short threads produce an explicit not-enough-content state rather than a generated summary.
- [ ] Truncated or malformed generations are discarded and the previous summary is retained.
- [ ] 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.
