# AI Secret Detection

## Objective

Find credentials in content before they are stored, shared, or sent anywhere.

A detection pass that flags API keys, tokens, passwords, and private keys in submitted content and warns before it is saved.

## 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. Find the surfaces where a user can paste an arbitrary blob: comments, notes, issue descriptions, support messages, configuration fields, and file uploads. Run detection on submit, before the content is persisted.
2. Combine three signals rather than relying on one. Match the well-known credential shapes, score high-entropy strings, and use surrounding context such as an assignment to a variable named like a secret to lift or drop confidence.
3. Show the user a warning naming what was found and where, with only a short prefix of the value. The full secret must never appear in the alert, the notification, the audit entry, or any log.
4. Give the user two paths: remove the value, or acknowledge a false positive with a reason. Record the acknowledgement so the same fixture does not warn on every edit.
5. Do not attempt to revoke or rotate the credential yourself. Detection tells someone a secret is exposed; rotation runs through whatever approved credential workflow the organization already has, because rotating a live key from a content scanner breaks production.

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

- Known credential prefixes alone miss anything custom, and raw entropy alone flags every hash and identifier. Require agreement between at least two of pattern, entropy, and context before treating a match as high confidence.
- Alerts, emails, audit records, and logs must show a masked fragment only. A detector that pastes the full key into a notification has published the secret more widely than the original message did.
- An exposed credential is still live after detection. Point the user at the organization's rotation process and track whether the exposure was resolved, but do not call any provider's revocation capability from this feature.
- Code examples, test fixtures, and documentation contain deliberate fake credentials. Support a per-path or per-record suppression with a recorded reason, so the same file does not warn on every save.
- Attachments and model-generated text need the same scan as form fields. A key pasted into an uploaded log file is the most common way this leaks.
- Detection must not block a save indefinitely if the scan is slow or the model is unavailable. Fall back to deterministic patterns, save, and flag the record for a follow-up scan.
- PII masking on outbound content is owned by AI PII Redaction. This feature owns credentials on the way in; do not build a second redaction pipeline for personal data here.
- A user who cannot see the original record must not be able to learn anything about it from the alert.

## 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 free-text and upload surface is scanned before content is persisted.
- [ ] High-confidence findings require agreement between at least two independent signals.
- [ ] No full secret value appears in any alert, notification, audit entry, or log.
- [ ] Acknowledged false positives are recorded and do not re-warn on the same content.
- [ ] Attachments and generated text are scanned alongside form fields.
- [ ] The feature never revokes or rotates a credential itself, and directs the user to the approved workflow.
- [ ] 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.
