# AI Support Triage

## Objective

Summarise each incoming support request and estimate how urgent it really is.

An automatic summary, urgency estimate, and likely problem area attached to every inbound support request, with the evidence behind each.

## 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. Run triage as a background job on arrival, using the app's existing queue and retry behaviour. The ticket must be visible and workable in its raw form the moment it lands, whether or not triage has finished.
2. Produce three separate outputs — a short summary, an urgency level, and a likely problem area — and store each with the quoted source statements from the ticket that support it, so a human can check the reasoning.
3. Define urgency in terms of business impact: who is blocked, how many, whether money or data is at risk. Compute it from what the ticket describes, not from how the writer sounds.
4. Include an explicit unknown value in every classification, and a needs-human-review state that surfaces the ticket to a person rather than letting a low-confidence guess pass as fact.
5. This brief owns the summary, urgency, and problem area only. Choosing the destination queue or specialist belongs to AI Ticket Routing, which consumes these outputs; do not write routing decisions 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

- Urgency and sentiment are different measurements. An angry message about a cosmetic issue is low urgency, and both must be modelled separately if sentiment is captured at all.
- A calm, precise report of total data loss is the most urgent ticket in the queue. Politeness must never reduce priority, and this needs a deliberate test case, not an assumption.
- A classification with no supporting quotes cannot be audited or appealed. If the model returns a level without evidence, treat the result as unknown rather than accepting it.
- Forcing a confident label on an ambiguous ticket is worse than admitting uncertainty, because it removes the ticket from human attention. Unknown must be a first-class outcome that still gets seen.
- Sensitive personal traits — inferred or stated — must never influence urgency. Exclude them from the context sent to the provider so they cannot be used implicitly.
- A truncated or malformed structured response must fail the job cleanly and leave the ticket untriaged rather than persisting a half-parsed classification.
- Ticket text is untrusted input. Instructions embedded in a customer message must never be able to change the urgency scale or the output format.
- A flood of inbound tickets must not produce an unbounded spend. Apply a per-hour ceiling and let overflow queue for later triage rather than dropping tickets or billing without limit.

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

- [ ] Every inbound ticket is workable immediately, with triage arriving asynchronously.
- [ ] Summary, urgency, and problem area are stored separately, each with supporting quotes from the ticket.
- [ ] Urgency reflects described impact and is unaffected by the tone of the message.
- [ ] Unknown and needs-human-review are supported outcomes that keep the ticket visible to a person.
- [ ] Malformed or truncated model output leaves the ticket untriaged rather than partially classified.
- [ ] Triage volume is capped per hour and degrades to an untriaged queue when the model is unavailable.
- [ ] Routing decisions are not made by this feature.
- [ ] 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.
