# AI Conversation Memory

## Objective

Carry durable preferences between AI conversations without replaying every past message.

A reviewable store of durable facts and preferences, scoped by user and workspace, retrieved selectively into new conversations.

## 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. Define what qualifies as memory before writing any of it: stable preferences, standing instructions, and settled facts about how this user or workspace works. A one-off request inside a single conversation is not memory.
2. Give the user a screen listing everything remembered, in plain sentences, with the ability to edit, delete, and turn memory off entirely. A store the user cannot inspect will be assumed to contain more than it does.
3. Scope every entry to a user, a workspace, and the assistant it applies to, and enforce that scope on retrieval. One person's preference must never surface in a colleague's conversation, and a workspace fact must not follow the user elsewhere.
4. Retrieve only the entries relevant to the current conversation and show which ones were applied. Injecting the whole store into every request costs tokens, dilutes the context, and drags in preferences that do not apply.
5. Do not write memory silently. Surface a proposed entry for confirmation, or at minimum notify the user that something was remembered with a one-click undo, so an inference never becomes a permanent fact without their knowledge.

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

- Passing detail does not belong in long-term memory. Exclude anything transient, anything sensitive such as health, financial, or credential information, and anything scoped to a single task, and apply a retention window so unused entries expire.
- Every entry must be visible, editable, and deletable individually, and deleting one must remove it from retrieval immediately rather than at the next background rebuild.
- Scope is enforced at retrieval, not just at write time. A memory written in one workspace must be unreachable from another even when the same person is signed in.
- The model will infer things that are not true. Do not promote an inference into memory on its own; require a direct statement from the user or an explicit confirmation, and record which it was.
- Retrieve a bounded, relevant subset per conversation and show the user which memories were applied to a given answer, so a surprising response can be traced to the entry that caused it.
- Memories conflict as preferences change. Prefer the most recent, flag the contradiction for the user, and never apply two opposing entries in the same request.
- When retrieval is unavailable or the store is empty, the assistant must still answer normally without memory rather than failing or apologising for missing context.
- Deleting an account or workspace must remove its memories along with everything else, and an export of personal data must include them.

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

- [ ] Only durable, non-sensitive facts and preferences are stored, and entries expire after a defined period of disuse.
- [ ] Users can view, edit, and delete every remembered item and disable memory entirely.
- [ ] Memories are scoped by user, workspace, and assistant, and the scope is enforced on retrieval.
- [ ] No entry is written from a model inference without user confirmation.
- [ ] Only a bounded, relevant subset is retrieved per conversation, and the applied entries are shown.
- [ ] Conflicting entries resolve to the most recent and are surfaced to the user.
- [ ] The assistant functions normally when the memory store is empty or 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.
