Autopilot & Diff Engine
Relevant source files
The following files were used as context for generating this wiki page:
The Autopilot & Diff Engine system is a proactive compliance monitoring suite designed to maintain the accuracy of legal documents as regulations evolve. It monitors changes in tracked regulations and automatically generates "proposals" for document updates when discrepancies are detected between current project snapshots and new regulatory requirements.
The system is built on a "propose-only" architecture. It never mutates live project data directly; instead, it generates deterministic diffs and plain-language summaries (often enhanced by AI) that users must manually review and approve via the Command Center. This ensures that legal documents remain under human supervision while significantly reducing the manual effort of regulatory tracking.
Sources: src/lib/autopilot/pipeline.ts:1-10, src/lib/autopilot/service.ts:161-165
System Architecture
The Autopilot system operates as a tiered pipeline involving regulatory monitoring, document regeneration, and user notification. It specifically targets premium users, providing them with automated oversight of their compliance packages.
Component Overview
| Component | Description |
|---|---|
| Regulation Monitor | Watches for changes in external regulatory data and records new versions in the database. |
| Regeneration Pipeline | Snapshots project inputs (framework, pixels, regions) and generates a new package using the ClauseEngine. |
| Diff Engine | Computes structural and line-based differences between stored and newly generated documents. |
| AI Summarizer | Generates human-readable, plain-language explanations of what changed and why it matters. |
| Review Queue | A UI dashboard (AutopilotPanel) where users accept or reject proposed changes. |
Sources: src/lib/autopilot/pipeline.ts:12-40, src/lib/autopilot/service.ts:184-210, src/app/dashboard/home/AutopilotPanel.tsx:18-24
Autopilot Execution Flow
The following diagram illustrates the lifecycle of an Autopilot run, from detecting a regulatory change to user approval.
This flow ensures that only relevant projects are processed based on the specific jurisdictions (regions) affected by a regulation change.
Sources: src/lib/autopilot/service.ts:161-240, src/lib/autopilot/pipeline.ts:65-90
The Regeneration Pipeline
The pipeline is responsible for taking a project's saved configuration and determining if a regulatory update necessitates a document change. It utilizes the ClauseEngine to produce a fresh CompliancePackage and compares it to the existing packageMarkdown.
Proposal Data Structure
The result of a pipeline run is a RegenerationProposal, containing:
- hasChanges: A boolean indicating if the new document differs from the stored version.
- summary: A concise explanation for non-lawyers.
- diff: A
DocumentDiffobject identifying changed sections and line counts. - packageMarkdown: The full text of the newly generated document.
- complianceScore: The updated score based on current logic.
Sources: src/lib/autopilot/pipeline.ts:42-50, src/tests/autopilot.test.ts:70-85
AI and Fallback Logic
The system attempts to use an AiClient to write neutral, precise summaries. If the AI client is unavailable or "live" mode is disabled, it falls back to a deterministic template that lists the affected sections and line changes.
function fallbackSummary(regulation: RegulationContext, diff: DocumentDiff): string {
const sections = [...diff.changedSections, ...diff.addedSections];
const detail = sections.length > 0 ? ` Affected sections: ${sections.slice(0, 6).join(", ")}.` : "";
return (
`${regulation.name} (${regulation.region}) changed, so we regenerated a proposed update to this project's ` +
`compliance package (+${diff.addedLines}/-${diff.removedLines} lines).${detail} Review and approve to apply it.`
);
}
Sources: src/lib/autopilot/pipeline.ts:59-67, src/tests/autopilot.test.ts:107-120
Diff Engine Logic
The Diff Engine provides the deterministic comparison logic used to identify specific changes in the legal text. It operates by hashing content for quick change detection and parsing Markdown headings to identify "sections."
Key Capabilities
- Deterministic Hashing: Uses
hashContentto quickly verify if two versions are identical without full string comparison. - Section Analysis: Identifies added, removed, and changed sections by parsing H1/H2/H3 headers in the legal documents.
- Line Counts: Tracks
addedLinesandremovedLinesto quantify the magnitude of the change for the user.
Sources: src/tests/autopilot.test.ts:24-60, src/lib/autopilot/pipeline.ts:98-105
Data Management & Service Layer
The autopilot/service.ts module acts as the interface between the logic engine and the database (Supabase). It manages user permissions and provides methods for interacting with proposals.
Proposal Resolution
When a user interacts with the AutopilotPanel, they can either Accept or Reject a proposal.
| Action | Logic |
|---|---|
| Accept | Updates the main projects table with the package_markdown and compliance_score from the proposal. Sets project status to 'current'. |
| Reject | Marks the proposal as 'rejected' and keeps the original project data intact. |
Sources: src/lib/autopilot/service.ts:100-125, src/app/dashboard/home/AutopilotPanel.tsx:48-60
Security and Entitlements
Autopilot features are strictly gated to Pro, Agency, and Enterprise tiers. The canUseAutopilot() function verifies user entitlements before allowing access to the proposal queue or triggering automated scans.
Sources: src/lib/autopilot/service.ts:242-246, src/app/dashboard/home/AutopilotPanel.tsx:28-35
Conclusion
The Autopilot & Diff Engine system provides a robust framework for automated legal maintenance. By combining the deterministic ClauseEngine with a sophisticated diffing and notification layer, the project ensures that compliance documents are never stale. The "propose-only" nature of the service maintains the critical requirement for human legal oversight while providing the automation necessary to scale compliance across multiple frameworks and jurisdictions.