AI Copilot
What. A side-drawer assistant that reads the current entity, chats about it, and proposes artifacts (CAPAs, controls, modules, approval chains) you approve before they land in the system. Where. Inline buttons throughout the app (Draft CAPA, Suggest Controls, Generate Checklist, etc.) and the Approval Center at
/ai/approvals.
Two surfaces
1. The Copilot drawer
Opens contextually:
- On a Finding: Analyze Root Cause, Draft CAPA, Find Similar.
- On a Requirement: Suggest Controls, Suggest Evidence.
- On an Audit: Generate Checklist, Suggest Evidence, Draft Report.
- On a Standard module page: Build Module with AI.
- On a Process / Document: Summarize, Check Compliance, Suggest Improvements.
Inside the drawer:
- A scrolling chat with prior messages.
- An input box at the bottom for free-form questions.
- Inline action buttons rendered by the AI when it has a structured proposal ready.
2. The Approval Center (/ai/approvals)
Every AI proposal queues here. Filter by status: All / Pending / Approved / Rejected / Executed / Failed.
Each card shows: title, risk level, action count, created date. Click into the card → detail view with the proposed payload (you can edit fields), then Approve (writes to DB) or Reject (closes without writing).
Provenance. Every artifact created by an approved AI proposal stores
source_proposal_idlinking back to the original proposal row. So a CAPA created via Copilot links back to the Copilot session that proposed it.
Common flows
Draft a CAPA from a Finding
- Open the finding detail.
- AI Assistant strip → Draft CAPA.
- Drawer opens with a chat showing the AI's analysis: title, description, root cause draft, corrective + preventive action.
- The AI says: "I've prepared 1 action(s) for your approval: 1. Create CAPA: …"
- Open
/ai/approvals→ click the new pending proposal. - Review the payload (title, priority, root cause, actions, due date). Edit any field.
- Click Approve. CAPA materializes in
/capawithsource_proposal_id = <proposal.id>.
Suggest controls for a requirement
- Open
/library→ drill to a requirement. - Suggest controls in the drawer.
- The AI proposes 1-N control specs, each with title, description, frequency, evidence template.
- Approve in
/ai/approvals→ controls land in/controls, linked to the requirement.
Build a module with AI
- Open
/library→ Build module with AI. - Upload the standard PDF/DOCX. The drawer extracts text and asks for a module name.
- The AI returns a structured outline of clauses + requirements.
- Approve → a new entry in
module_drafts. Click into it, review each clause, optionally edit, then Publish module to move into the liverequirements_modulesso it shows in the library.
Generate audit checklist
- Open an audit detail.
- Generate Checklist under AI Assistant.
- The AI looks at the audit's standard + scope, proposes one checklist item per relevant requirement.
- Approve → items inserted with
result='pending'.
Risk levels
Every proposal has a risk level (low / medium / high) that determines:
- Card color in
/ai/approvals(green / blue / red) - Whether the proposal requires elevated role to approve
Risk is the AI's estimate of impact-if-applied; trust but verify.
Tool calls (internal)
Under the hood, the Copilot has a set of write-tools the agent can propose (it cannot directly execute):
propose_capapropose_controls_for_requirementpropose_evidencepropose_approval_chaincreate_module
All proposals route to ai_action_proposals with actions_json describing
the intended writes. The Apply step in the Approval Center deserializes
actions_json and runs each write inside an RLS-protected SQL block.
Test it
- On a finding, click Draft CAPA. Drawer shows AI thinking → draft → "1 action(s) for your approval".
- Open
/ai/approvals. Pending tab shows the proposal. - Click into the proposal → review payload → click Approve.
- CAPA materializes in
/capawith source_proposal_id set. - Reject a different proposal. Status = Rejected. No artifact created.
- On a Requirement, Suggest controls → proposal queues →
approve → controls appear in
/controls. - On a Standard, Build module with AI → upload sample PDF → preview shows extracted clauses → Apply → module draft created.