feat: KB Accelerator — convert KB articles into interactive flows

Full-stack implementation of the KB Accelerator feature that converts
static MSP knowledge base articles into interactive troubleshooting
and procedural flows using AI.

Backend:
- Migrations 054/055: kb_imports, kb_import_nodes tables + plan_limits KB columns
- SQLAlchemy models with relationships and self-referential node hierarchy
- Text extraction service (txt, paste, docx with structural metadata)
- AI conversion service with MSP-specialist prompts for both flow types
- 8 API endpoints: upload, get, list, convert, edit node, commit, delete, quota
- Tier-gated access via plan_limits (free: 3 lifetime, pro/team: unlimited)
- 8 integration tests covering upload, get/list, quota, commit, delete

Frontend:
- TypeScript types and API client for all KB Accelerator endpoints
- Multi-step wizard page: upload → processing → review → success
- Upload screen with paste/file tabs, drag-drop, target type selector
- Two-panel review screen with source highlighting and node cards
- Per-node actions: approve, edit, regenerate, insert, delete
- Confidence color indicators (green/amber/red)
- Sidebar navigation with Sparkles icon
- Code-split lazy-loaded route at /kb-accelerator

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Michael Chihlas
2026-03-10 20:56:28 -04:00
parent c65aa4f0b7
commit 71ff4a8c35
27 changed files with 4426 additions and 2 deletions

View File

@@ -0,0 +1,520 @@
# RESOLUTIONFLOW — KB Accelerator
## Feature Design Document
*Transform static KB articles into interactive troubleshooting and procedural flows with AI-powered document analysis.*
| Field | Value |
|-------|-------|
| **Document** | KB Accelerator — Feature Design & Architecture |
| **Version** | 1.0 — Draft |
| **Date** | March 2026 |
| **Author** | ResolutionFlow LLC |
| **Status** | Design Phase |
---
## Table of Contents
1. Executive Summary
2. Problem Statement & Market Opportunity
3. Feature Overview
4. System Architecture
5. AI Processing Pipeline
6. Data Model
7. API Design
8. Frontend Design
9. Supported Input Formats
10. Conversion Intelligence
11. Pricing & Tier Integration
12. Build Phases & Roadmap
13. Risk Analysis
14. Success Metrics
---
## 1. Executive Summary
KB Accelerator is a new feature for ResolutionFlow that allows MSP teams to upload their existing knowledge base articles and automatically convert them into interactive troubleshooting flows and procedural flows. This solves the cold-start adoption problem, transforms passive documentation into active troubleshooting tools, and delivers immediate value from day one.
> **Core Value Proposition**
>
> MSPs have years of institutional knowledge trapped in static Word docs, PDFs, and wiki articles that nobody reads mid-ticket. KB Accelerator transforms that content into the interactive, branching flows that ResolutionFlow is built around — turning dead documentation into living troubleshooting intelligence.
### Key Capabilities
- Upload KB articles in multiple formats (DOCX, PDF, HTML, Markdown, plain text, copy-paste)
- AI-powered analysis that detects sequential steps, decision points, prerequisites, and resolution outcomes
- Automatic mapping to ResolutionFlow's existing tree schema (troubleshooting flows) and procedural schema (procedure flows)
- Intelligent detection of implicit branching logic buried in prose documentation
- Draft flow output that lands directly in the flow editor for human review and refinement
- Confidence scoring on each generated node so users know where AI interpretation needs attention
- Batch import capability for migrating entire KB libraries
### Strategic Impact
| Impact Area | Description |
|---|---|
| **Adoption** | Eliminates cold-start problem. New users get a library of draft flows on day one instead of building from scratch. |
| **Retention** | Users who import existing KB articles are investing their institutional knowledge into the platform, increasing switching costs. |
| **Revenue** | Pro/Team-gated feature that directly justifies subscription pricing. AI processing costs are per-conversion, aligning expense with usage. |
| **Differentiation** | No competing MSP documentation tool offers AI-powered conversion from static docs to interactive decision trees. |
| **Thesis Validation** | Proves the core ResolutionFlow thesis: documentation and troubleshooting should be the same activity. |
---
## 2. Problem Statement & Market Opportunity
### 2.1 The KB Problem in MSPs
Every MSP has knowledge base articles. They live in ConnectWise, IT Glue, Hudu, SharePoint, Confluence, or simply as Word documents on a shared drive. These articles represent years of accumulated troubleshooting experience and process documentation. The problem is that this content is fundamentally passive. It exists as prose that a technician has to read, interpret, and mentally convert into action steps while simultaneously working a live ticket.
The result is predictable: technicians don't read the KB articles. They ask a senior engineer instead, or they fumble through the issue on their own. The documentation exists but delivers no value because the format doesn't match the workflow.
### 2.2 The Cold-Start Problem
ResolutionFlow solves the format problem by making documentation interactive. But it introduces a new problem: a new ResolutionFlow customer has zero flows. Building troubleshooting trees from scratch is time-consuming. The customer has to invest significant effort before they see value, and most MSPs don't have that patience.
> **The Gap**
>
> MSPs have the knowledge (in KB articles). ResolutionFlow has the format (interactive flows). KB Accelerator bridges the gap by converting one into the other automatically.
### 2.3 Competitive Landscape
No MSP-focused tool currently offers AI-powered conversion from static documentation to interactive troubleshooting workflows. IT Glue and Hudu offer structured documentation but no interactive execution. ConnectWise's KB is search-based and static. This is a genuine whitespace opportunity.
---
## 3. Feature Overview
### 3.1 User Journey
1. User navigates to KB Accelerator from the ResolutionFlow dashboard (dedicated tab or sidebar action).
2. User uploads a file (DOCX, PDF, HTML, MD, TXT) or pastes raw text content directly.
3. System analyzes the document structure and displays a preview of detected elements: title, problem statement, steps, decision points, prerequisites, and resolution outcomes.
4. User selects target flow type: Troubleshooting Flow (branching decision tree) or Procedure Flow (linear steps with optional intake form).
5. AI processing pipeline generates a draft flow mapped to ResolutionFlow's schema.
6. User reviews the draft in a side-by-side view: original document on the left, generated flow preview on the right.
7. User can accept, edit, or regenerate individual nodes before finalizing.
8. Finalized flow is saved and appears in the user's flow library, ready for use or further editing in the standard flow editor.
### 3.2 Two Conversion Modes
**Troubleshooting Flow Conversion**
Best for: diagnostic articles, if/then troubleshooting guides, articles with multiple resolution paths.
- AI identifies the root question or symptom being diagnosed
- Decision nodes are created at each branching point ("if X, try Y; otherwise try Z")
- Resolution nodes capture final outcomes and fix instructions
- The branching tree maps to the existing node/option schema in the trees table
**Procedure Flow Conversion**
Best for: step-by-step guides, setup procedures, onboarding checklists, runbooks.
- AI extracts sequential steps in order
- Variable placeholders are detected (server names, IPs, usernames) and mapped to `[VAR:name]` tokens
- An intake form schema is auto-generated from detected variables
- Steps are enriched with detected warnings, time estimates, and verification checks
- Output uses the procedural `tree_type` with the `intake_form` JSONB schema from migration 035
---
## 4. System Architecture
### 4.1 High-Level Architecture
KB Accelerator integrates into the existing ResolutionFlow stack without introducing new infrastructure. It leverages the FastAPI backend for orchestration, the existing AI service (same infrastructure as the assistant chat) for document analysis, and outputs directly into the existing tree/node schema.
**Processing Pipeline Overview**
```
1. UPLOAD → 2. EXTRACT → 3. ANALYZE → 4. GENERATE → 5. REVIEW
File upload or Text extraction AI analysis of Map to tree/ Side-by-side
text paste via from DOCX/PDF/ structure, steps, node schema or review, edit,
API endpoint HTML/MD/TXT decision points procedure schema and finalize
```
### 4.2 Component Responsibilities
| Component | Responsibility | Integration Point |
|---|---|---|
| **Upload Service** | File validation, format detection, size limits, virus scanning hook | FastAPI endpoint, S3/local temp storage |
| **Extraction Service** | Convert uploaded files to normalized plain text with structural metadata | python-docx, PyMuPDF, BeautifulSoup, markdown-it |
| **AI Analysis Service** | Prompt engineering pipeline that identifies document structure and converts to flow schema | Anthropic API (Claude), existing AI service infrastructure |
| **Flow Generator** | Maps AI analysis output to tree/node database records with proper relationships | SQLAlchemy models, existing tree/node CRUD services |
| **Review UI** | Side-by-side document vs. flow preview with per-node editing | React frontend, existing flow editor components |
| **Batch Processor** | Queue-based processing for multi-article imports | Celery/Redis or async FastAPI background tasks |
---
## 5. AI Processing Pipeline
The AI pipeline is the core intelligence of KB Accelerator. It operates in two phases: structural analysis (understanding the document) and flow generation (converting that understanding into a ResolutionFlow-compatible schema). This two-phase approach allows for human review between analysis and generation.
### 5.1 Phase 1: Document Analysis
The first AI call analyzes the extracted text and returns a structured JSON document describing what was found. The prompt is carefully engineered to identify MSP-specific patterns.
**Analysis Prompt Strategy**
- System prompt establishes the AI as an MSP documentation specialist that understands IT troubleshooting workflows
- The extracted text is provided with any structural metadata (headings, lists, numbered steps) preserved
- AI is instructed to return a strict JSON schema identifying: document type, title, problem statement, prerequisites, sequential steps, decision points, resolution outcomes, and detected variables
**Detection Targets**
| Element | What AI Looks For | Example in KB Article |
|---|---|---|
| **Document Type** | Whether the article is diagnostic (troubleshooting) or procedural (step-by-step) | *"Troubleshooting Outlook connectivity" vs "Setting up a new domain controller"* |
| **Problem Statement** | The root issue or task being addressed | *"Users report that Outlook keeps disconnecting from Exchange"* |
| **Prerequisites** | Things that must be true before starting | *"Ensure you have Domain Admin credentials and the server is on the network"* |
| **Sequential Steps** | Ordered instructions that must happen in sequence | *"Step 1: Open Server Manager. Step 2: Add Roles and Features..."* |
| **Decision Points** | Conditional logic, if/then/else branches | *"If the user is on Windows 10, check the registry. On Windows 11, go to Settings..."* |
| **Variables** | Instance-specific values that change per execution | *Server names, IP addresses, usernames, license types, domain names* |
| **Warnings/Cautions** | Risk indicators or critical notes | *"WARNING: This will restart the DNS service and cause brief connectivity loss"* |
| **Resolution Outcomes** | End states that indicate the problem is solved | *"Outlook should now maintain a persistent connection to Exchange"* |
| **Verification Steps** | How to confirm a step or procedure worked | *"Run nslookup to verify DNS resolution is working correctly"* |
### 5.2 Phase 2: Flow Generation
The second AI call takes the structured analysis from Phase 1 and generates the actual flow structure, mapped directly to ResolutionFlow's schema. The output format differs based on the target flow type.
**Troubleshooting Flow Output**
- Root node with the problem statement as the question text
- Decision nodes with options array matching the existing node schema (question, options with label and next_node_id)
- Resolution nodes at leaf positions with solution text and tags from the six-dimension tagging system
- Each node includes a `confidence_score` (0.01.0) indicating how certain the AI is about the mapping
**Procedure Flow Output**
- Ordered steps array with rich metadata (type, content, warnings, time estimates, verification checks)
- Auto-generated `intake_form` schema from detected variables, with field types inferred (text for names, ip_address for IPs, select for known enumerations)
- `[VAR:name]` tokens injected into step content wherever variables were detected
- Section headers generated from logical groupings in the source document
### 5.3 Confidence Scoring
Every generated node includes a confidence score that communicates how certain the AI is about its interpretation. This is critical for the review step — it tells the user exactly where to focus their attention.
| Score Range | Label | UI Indicator | Meaning |
|---|---|---|---|
| **0.9 1.0** | High Confidence | Green left accent | Direct mapping from explicit steps or clear logic in the source |
| **0.7 0.89** | Medium Confidence | Amber left accent | Reasonable inference, but some ambiguity in the source material |
| **0.5 0.69** | Low Confidence | Red left accent | Significant interpretation required; user should carefully review |
| **< 0.5** | Needs Review | Red left accent + flag icon | AI made a best guess but recommends manual editing |
> **Design Note: Left Accent Border Pattern**
>
> The confidence indicators use the left accent border pattern established in the ResolutionFlow design system. This provides visual consistency with step status indicators and documentation callouts already in the UI.
---
## 6. Data Model
KB Accelerator introduces two new database tables and extends the existing tree model. All new tables follow the existing migration pattern and use the same base model infrastructure.
### 6.1 New Table: `kb_imports`
| Column | Type | Nullable | Description |
|---|---|---|---|
| **id** | UUID | No | Primary key (gen_random_uuid) |
| **organization_id** | UUID FK | No | Foreign key to organizations table |
| **created_by** | UUID FK | No | Foreign key to users table (who initiated the import) |
| **source_filename** | VARCHAR(500) | Yes | Original filename if file upload (null for text paste) |
| **source_format** | VARCHAR(20) | No | Enum: docx, pdf, html, md, txt, paste |
| **source_text** | TEXT | No | Extracted plain text content from the source document |
| **source_metadata** | JSONB | Yes | Structural metadata from extraction (headings, lists, etc.) |
| **analysis_result** | JSONB | Yes | Phase 1 AI analysis output (detected elements) |
| **target_type** | VARCHAR(20) | No | Enum: troubleshooting, procedural |
| **generated_flow** | JSONB | Yes | Phase 2 AI generation output (flow schema before commit) |
| **tree_id** | UUID FK | Yes | Foreign key to trees table (set after user finalizes) |
| **status** | VARCHAR(20) | No | Enum: uploaded, extracting, analyzing, reviewed, generating, completed, failed |
| **confidence_avg** | FLOAT | Yes | Average confidence score across all generated nodes |
| **error_message** | TEXT | Yes | Error details if status = failed |
| **processing_time_ms** | INTEGER | Yes | Total processing time in milliseconds |
| **created_at** | TIMESTAMPTZ | No | Auto-set on creation |
| **updated_at** | TIMESTAMPTZ | No | Auto-updated on modification |
### 6.2 New Table: `kb_import_nodes`
Stores individual generated nodes/steps before the user commits them to the actual tree. This allows per-node editing during the review phase without touching the live flow data.
| Column | Type | Nullable | Description |
|---|---|---|---|
| **id** | UUID | No | Primary key |
| **kb_import_id** | UUID FK | No | Foreign key to kb_imports |
| **node_order** | INTEGER | No | Position in the generated flow (0-indexed) |
| **node_type** | VARCHAR(20) | No | Enum: question, resolution, step, section_header, warning |
| **content** | JSONB | No | Node content (question text, step text, options, etc.) |
| **source_excerpt** | TEXT | Yes | The specific text from the source document that this node was derived from |
| **confidence_score** | FLOAT | No | AI confidence in this node's accuracy (0.01.0) |
| **user_edited** | BOOLEAN | No | Whether the user manually modified this node during review |
| **user_approved** | BOOLEAN | No | Whether the user explicitly approved this node |
### 6.3 Tree Model Extension
The existing trees table gets one new nullable column to link back to the import that created it. This enables analytics and provenance tracking.
**New column:** `kb_import_id` (UUID FK, nullable) — references `kb_imports.id`. Null for manually-created trees.
---
## 7. API Design
All KB Accelerator endpoints live under the `/api/v1/kb-accelerator` prefix and follow existing authentication, organization scoping, and error handling patterns.
### 7.1 Endpoints
| Method | Endpoint | Description |
|---|---|---|
| **POST** | `/api/v1/kb-accelerator/upload` | Upload a file or submit pasted text. Returns kb_import_id and starts extraction. |
| **GET** | `/api/v1/kb-accelerator/{id}` | Get import status, analysis results, and generated flow data. |
| **GET** | `/api/v1/kb-accelerator` | List all imports for the current organization with pagination and status filter. |
| **POST** | `/api/v1/kb-accelerator/{id}/analyze` | Trigger Phase 1 AI analysis on extracted text. Async — poll status via GET. |
| **POST** | `/api/v1/kb-accelerator/{id}/generate` | Trigger Phase 2 flow generation from analysis results. Requires target_type. |
| **PATCH** | `/api/v1/kb-accelerator/{id}/nodes/{node_id}` | Edit a specific generated node during review (content, approve, reject). |
| **POST** | `/api/v1/kb-accelerator/{id}/commit` | Finalize the import: create actual tree and node records from generated data. |
| **DELETE** | `/api/v1/kb-accelerator/{id}` | Cancel and clean up an in-progress or abandoned import. |
| **POST** | `/api/v1/kb-accelerator/batch` | Submit multiple files for batch processing. Returns array of kb_import_ids. |
### 7.2 Upload Endpoint Detail
**POST /api/v1/kb-accelerator/upload**
Accepts multipart/form-data for file uploads or application/json for text paste. Validates file size (max 10MB), format, and performs basic content extraction before returning.
**Request Body (File Upload)**
- **file**: UploadFile (required) — the KB article file
- **target_type**: string (optional) — "troubleshooting" or "procedural" (can be set later)
**Request Body (Text Paste)**
- **content**: string (required) — raw text content
- **title**: string (optional) — suggested title for the import
- **target_type**: string (optional) — "troubleshooting" or "procedural"
**Response (201 Created)**
- **id**: UUID — the new kb_import record ID
- **status**: "uploaded" or "extracting" (extraction may start immediately)
- **source_format**: detected format of the uploaded content
---
## 8. Frontend Design
### 8.1 Entry Points
KB Accelerator is accessible from two locations in the existing UI to maximize discoverability:
- **Dashboard action button:** a prominent "Import KB Article" button in the flow library header, next to "Create New Flow"
- **Sidebar navigation:** dedicated "KB Accelerator" item in the main navigation with a sparkle/lightning icon to communicate AI-powered functionality
### 8.2 Upload Screen
Clean, focused upload interface with two input modes:
- Drag-and-drop zone for file uploads with format badges showing supported types (DOCX, PDF, HTML, MD, TXT)
- Text paste tab with a full-width textarea and title field for direct content entry
- Target type selector (Troubleshooting Flow / Procedure Flow) with visual cards showing the difference
- "Let AI decide" option for target type that uses the analysis phase to recommend the best fit
### 8.3 Analysis Preview Screen
After Phase 1 analysis completes, the user sees a breakdown of what the AI detected:
- Document title and detected type with AI recommendation badge
- Detected elements displayed as color-coded cards: steps (blue), decision points (amber), warnings (red), variables (green), resolutions (emerald)
- Source text excerpts linked to each detected element so the user can see exactly what triggered the detection
- "Proceed to Generation" and "Re-analyze" action buttons
### 8.4 Review Screen (Core Experience)
The review screen is the most important UI in KB Accelerator. It's where the user validates AI output and builds trust in the system.
**Layout: Two-Panel Side-by-Side**
- Left panel: Original document text with detected elements highlighted inline (color-matched to the generated nodes)
- Right panel: Generated flow preview showing the tree structure (for troubleshooting) or step list (for procedures)
- Clicking a node in the right panel highlights its source excerpt in the left panel, and vice versa
- Each node shows its confidence score via the left accent border pattern (green/amber/red)
**Per-Node Actions**
- **Approve** (checkmark): Marks the node as reviewed and accepted
- **Edit** (pencil): Opens inline editing for the node's content, question text, options, etc.
- **Regenerate** (refresh): Re-runs AI generation for just this node with optional user guidance
- **Delete** (trash): Removes the node from the generated flow
- **Add Node** (plus): Insert a manual node between existing ones
**Bulk Actions**
- "Approve All High Confidence" — one-click approval for all nodes scoring 0.9+
- "Commit to Library" — finalizes the flow and creates the actual tree record
> **UI Principle**
>
> The review screen should feel like a code review, not a form. The user is reviewing AI-generated work with the power to accept, modify, or reject each piece. The side-by-side layout with source attribution builds trust by showing the AI's reasoning.
---
## 9. Supported Input Formats
| Format | Library | Structure Preserved | Notes |
|---|---|---|---|
| **DOCX** | python-docx | Headings, lists, tables, bold/italic emphasis | Most common format for MSP KB articles in SharePoint and shared drives |
| **PDF** | PyMuPDF (fitz) | Text extraction with layout awareness, headings via font size | Second most common; handles scanned docs with OCR fallback via Tesseract |
| **HTML** | BeautifulSoup | Full semantic structure (h1-h6, ul/ol, tables, code blocks) | Covers Confluence, IT Glue, and web-based KB exports |
| **Markdown** | markdown-it | Headings, lists, code blocks, emphasis, links | Common in developer-oriented documentation and GitHub repos |
| **Plain Text** | Built-in | Line breaks and indentation only; AI infers structure | Lowest fidelity but important for copy-paste and email-sourced docs |
| **Paste** | Built-in | None — AI infers all structure from content | Zero-friction entry point for quick conversions |
> **Extraction Quality Hierarchy**
>
> DOCX and HTML provide the richest structural metadata, giving the AI the most to work with. PDF extraction is good but lossy (formatting information is approximate). Plain text and paste require the AI to infer all structure from content alone, which reduces confidence scores but still produces usable output for well-written articles.
---
## 10. Conversion Intelligence
This section details the specific AI patterns and heuristics used to convert different types of KB content into flows. This is where KB Accelerator's real value lives — the ability to interpret messy, inconsistent MSP documentation and produce structured, actionable flows.
### 10.1 Detecting Implicit Branch Logic
The hardest challenge is identifying decision points that aren't explicitly written as if/then statements. MSP KB articles often bury branching logic in prose.
**Pattern Examples**
| KB Article Text | AI Interpretation |
|---|---|
| *"For Windows 10 machines, navigate to Settings > Update. For Windows 11, go to Settings > Windows Update."* | Decision node: "What Windows version?" with two branches leading to different step sequences |
| *"If the issue persists after restarting the service, escalate to Tier 2."* | Decision node after the restart step: "Did the restart resolve the issue?" with Yes (resolution) and No (escalation) paths |
| *"Note: Domain-joined computers use Group Policy. Workgroup computers need manual configuration."* | Decision node: "Is the computer domain-joined?" with two parallel procedure paths |
| *"Try clearing the DNS cache first. If that doesn't work, check the hosts file."* | Sequential diagnostic flow: DNS cache clear > verification > hosts file check, with early exit if first step resolves |
### 10.2 Variable Detection
For procedure flow conversion, the AI identifies values that would change between executions and maps them to `[VAR:name]` tokens with appropriate intake form field types.
| Detected Pattern | Variable Name | Form Field Type | Example Value |
|---|---|---|---|
| IP addresses (192.168.x.x) | `[VAR:ip_address]` | ip_address | 192.168.1.10 |
| Server/computer names | `[VAR:server_name]` | text | DC01 |
| Domain names | `[VAR:domain_name]` | text | contoso.local |
| Usernames/email | `[VAR:username]` | text | jsmith@contoso.com |
| License types | `[VAR:license_type]` | select (enum) | E3, E5, F1 |
| OU paths | `[VAR:ou_path]` | text | OU=Users,DC=contoso,DC=local |
| Port numbers | `[VAR:port]` | number | 443 |
| Subnet masks | `[VAR:subnet_mask]` | ip_address | 255.255.255.0 |
---
## 11. Pricing & Tier Integration
KB Accelerator is a premium feature that justifies Pro and Team subscription pricing. The AI processing has a real per-conversion cost (Anthropic API usage), so tiering aligns expense with revenue.
| Capability | Free | Pro ($19/mo) | Team ($15/user/mo) |
|---|---|---|---|
| **Single article import** | 3 lifetime conversions | Unlimited | Unlimited |
| **Batch import** | Not available | Up to 10 articles | Up to 50 articles |
| **Text paste** | Included in 3 conversions | Unlimited | Unlimited |
| **Target type selection** | AI decides only | Manual + AI | Manual + AI |
| **Review & edit** | Basic (approve/reject) | Full (edit, regenerate, add) | Full + team review |
| **Confidence scoring** | Shown | Shown + filter/sort | Shown + filter/sort |
| **Import history** | Last 3 only | Full history | Full history + audit log |
| **Supported formats** | TXT and paste only | All formats | All formats |
> **Free Tier Strategy**
>
> The free tier offers 3 lifetime conversions with limited formats. This is enough for a user to experience the value and see KB Accelerator work on their actual documentation. The restriction to TXT/paste on free tier also reduces extraction library dependencies for free-tier infrastructure cost optimization.
---
## 12. Build Phases & Roadmap
### Phase 1: Foundation (Weeks 13)
Core pipeline with single-article import and basic review.
- Database migrations: `kb_imports` and `kb_import_nodes` tables, tree model extension
- Upload endpoint with text paste and TXT file support
- Text extraction service (plain text only in Phase 1)
- AI analysis prompt engineering and Phase 1 pipeline
- AI generation prompt engineering and Phase 2 pipeline (troubleshooting flow output only)
- Basic review UI: list view of generated nodes with approve/reject
- Commit endpoint that creates actual tree/node records
### Phase 2: Rich Formats & Procedures (Weeks 46)
Full format support and procedure flow conversion.
- DOCX extraction via python-docx with structural metadata
- PDF extraction via PyMuPDF with layout analysis
- HTML extraction via BeautifulSoup
- Markdown extraction via markdown-it
- Procedure flow generation with variable detection and intake form generation
- Side-by-side review UI with source-to-node linking
- Per-node editing and regeneration in the review screen
- Confidence scoring visualization with left accent borders
### Phase 3: Polish & Scale (Weeks 79)
Batch import, UX refinement, and tier enforcement.
- Batch upload endpoint and queue processing
- Import history dashboard with status tracking
- Tier gating enforcement (free tier limits, format restrictions)
- "Approve All High Confidence" bulk action
- Analytics: conversion success rate, average confidence, most-used source formats
- Drag-and-drop file upload zone with format badges
- "Let AI decide" target type recommendation
### Phase 4: Advanced Intelligence (Future)
Stretch goals and post-launch enhancements.
- OCR fallback for scanned PDFs via Tesseract
- Multi-article correlation: detect when multiple KB articles describe the same issue from different angles and suggest merging
- Incremental re-import: detect when a source KB article has been updated and suggest flow updates
- ConnectWise/IT Glue/Hudu direct API integration for pulling articles without manual export
- Tag auto-assignment using the six-dimension tagging system based on article content analysis
- Template marketplace: share anonymized, high-confidence converted flows with the ResolutionFlow community
---
## 13. Risk Analysis
| Risk | Severity | Impact | Mitigation |
|---|---|---|---|
| **Poor quality KB input** | Medium | AI produces low-confidence flows that require extensive manual editing, reducing perceived value | Confidence scoring sets expectations. "Needs Review" flags prevent silent bad output. Free tier lets users test before committing. |
| **AI hallucination in flow logic** | High | Generated flows contain incorrect troubleshooting paths that could lead technicians astray | Mandatory review step before commit. Source attribution shows exact text the AI based each node on. No auto-publish. |
| **API cost overruns** | Medium | High usage of AI analysis burns through API budget faster than subscription revenue covers | Per-conversion cost tracking. Tier limits on batch size. Prompt optimization to minimize token usage. |
| **Extraction library maintenance** | Low | python-docx, PyMuPDF, etc. may have breaking changes or security issues | Pin versions. Phase 1 starts with text-only to defer library dependency. Each format is an independent module. |
| **User trust gap** | High | Users don't trust AI-generated flows and abandon the feature after trying it once | Side-by-side source view builds trust. Confidence scoring is transparent. Start with high-quality conversion on well-structured articles to build initial trust. |
| **Scope creep** | Medium | Feature grows to include direct PSA integration, real-time sync, and other complex functionality before core is proven | Phased roadmap with clear scope boundaries. Phase 4 items are explicitly deferred until post-launch data validates demand. |
---
## 14. Success Metrics
These KPIs determine whether KB Accelerator is delivering value to users and justifying its development investment.
| Metric | Target | Why It Matters |
|---|---|---|
| **Conversion completion rate** | > 70% | Percentage of started imports that reach "committed" status. Below 70% suggests the review step is too burdensome or quality is too low. |
| **Average confidence score** | > 0.75 | Across all generated nodes. Indicates the AI pipeline is producing reliably accurate output. |
| **Time from upload to commit** | < 10 minutes | The full cycle should feel fast. If users are spending 30+ minutes editing, the AI isn't saving enough time. |
| **Free-to-Pro conversion rate** | > 15% | Users who use their 3 free conversions and then upgrade. This validates that experiencing the feature drives subscription revenue. |
| **Repeat usage (Pro/Team)** | > 3 imports/month | Users who import once and never again didn't find sustained value. Repeat usage indicates the feature is part of their workflow. |
| **Node edit rate** | < 30% | Percentage of generated nodes that users edit before committing. Lower is better — means AI output is usable as-is. |
| **Imported flow usage rate** | > 50% | Percentage of committed flows that get used in actual troubleshooting sessions within 30 days. Unused flows mean the conversion produced shelfware. |
---
*End of Document*
ResolutionFlow LLC — March 2026

View File

@@ -0,0 +1,628 @@
# KB Accelerator — Merged Implementation Plan
## Document Context
| Field | Value |
|-------|-------|
| **Document** | KB Accelerator — Merged Implementation Plan |
| **Version** | 1.0 |
| **Date** | March 2026 |
| **Status** | Approved for Implementation |
| **Source Plans** | Claude Code design review + Codex implementation plan |
| **Design Doc** | `docs/plans/KB-Accelerator-Design-Document.md` |
This plan merges the best elements of two independent implementation plans produced by Claude Code and Codex against the KB Accelerator design document. Where the plans conflicted, explicit decisions were made and are documented below.
---
## 1. Summary of Decisions
### Agreed by Both Plans (Carry Forward As-Is)
- Dedicated KB Accelerator frontend experience — own route (`/kb-accelerator`), own sidebar nav item, own screens
- `account_id` tenancy everywhere — all design doc references to "organization" map to existing `account_id`
- Text + paste + DOCX in Phase 1; PDF, HTML, Markdown in Phase 2
- Both flow types (troubleshooting + procedural) supported from Phase 1
- Single-phase AI conversion by default; optional detailed analysis for Pro/Team
- 3 lifetime conversions for free tier, enforced per account (not per user)
- Hard server-side tier enforcement via PlanLimits columns
- Store extracted text + metadata only — raw uploaded files are not persisted
- File validation + pluggable scan hook interface (no-op default, AV integration ready)
- Per-node review actions: approve, edit, delete, regenerate, insert, plus bulk approve
- Side-by-side two-panel review UI with confidence indicators (green/amber/red left accent borders)
- `import_metadata` JSONB on trees table for provenance — no new FK column on trees
- HTTP polling for progress tracking (no SSE, no WebSockets)
- Multipart `files[]` + shared options for batch upload request shape (Phase 3)
- Auto-advance pipeline: upload → extraction → AI conversion → land on review screen (no manual stage gates)
- Auto-commit as draft for batch imports (Phase 3)
- Feature-flagged analysis preview screen (Pro/Team only)
- Basic shared visibility for Team tier (view/read, not collaborative editing)
- Sidebar nav item + "Import KB Article" CTA in flow library header
### Conflict Resolutions
| Decision | Chosen Approach | Rationale |
|---|---|---|
| **AI Infrastructure** | **Codex: Dedicated KB module** consuming shared AI service layer (model routing, token tracking, quota). NOT coupled to `AIChatSession`. | A KB import is a document conversion, not a chat session. Coupling to `AIChatSession` muddies analytics, session history, and data model semantics. Using shared AI *services* without coupling to the AI *data model* is the right separation. |
| **Per-node staging** | **Codex: Dedicated `kb_import_nodes` table** with proper columns for confidence, source excerpt, approval status. | Queryable (e.g., "all nodes below 0.7 confidence across imports"), normalized, clean PATCH semantics. Avoids the `_kb_meta` JSONB prefix hack which is fragile and risks junk data in production trees if stripping is missed. |
| **Batch import** | **Claude Code: Defer to Phase 3.** | Core single-article conversion must be validated first. Batch adds queue management, partial failure handling, and batch status UI — significant complexity for a feature nobody has requested yet. |
| **Conversational refinement** | **Claude Code's idea, Codex's architecture. Defer to Phase 2.** Built as a scoped chat panel in the review screen, NOT coupled to `AIChatSession`. | High-value feature, but Phase 1 must nail the core loop (upload → convert → review → commit). Refinement panel in Phase 2 uses a dedicated KB chat endpoint scoped to the import context. |
| **Step Library matching** | **Defer to Phase 2.** | Same reasoning — nail the core loop first, then layer on matching. |
| **Status values** | **Claude Code: Simplified to 4**`processing`, `ready`, `committed`, `failed`. | With single-phase AI and auto-advance, granular statuses (uploaded, extracting, analyzing, generating, reviewed) add complexity without user value. |
---
## 2. Architecture Overview
### Backend: Dedicated KB Module + Shared AI Services
KB Accelerator is a self-contained backend module with its own tables, endpoints, services, and business logic. It does NOT create or depend on `AIChatSession` records.
When AI processing is needed, the KB module calls the existing shared AI service layer:
- **Model routing** via `get_model_for_action()` — add `kb_convert` and `kb_analyze` to `ACTION_MODEL_MAP`
- **Token tracking** via existing token counting utilities
- **Quota enforcement** via `ai_quota_service` (`check_ai_quota`, `record_ai_usage`)
- **Cost tracking** via existing cost recording patterns
- **Anthropic API calls** via existing `AsyncAnthropic` client patterns
The KB module owns its own prompt engineering, extraction logic, pipeline orchestration, and data persistence.
### Frontend: Dedicated KB Accelerator Experience
The frontend is a standalone multi-step wizard UI under `/kb-accelerator`. Users never see "AI Chat" branding or feel like they've left KB Accelerator. The conversational refinement panel (Phase 2) is visually integrated into the KB review screen — it reuses `EditorAIPanel` component internals but is branded and scoped to the KB context.
### Processing Pipeline
```
User uploads file/paste
┌─────────────────┐
│ 1. UPLOAD │ Validate format, size, tier permissions
│ & EXTRACT │ Extract text + structural metadata
└────────┬────────┘
┌─────────────────┐
│ 2. CONVERT │ Single AI call → tree structure + confidence scores
│ (AI) │ OR two-phase (Pro/Team optional): analyze → generate
└────────┬────────┘
┌─────────────────┐
│ 3. REVIEW │ Side-by-side UI, per-node actions, edit/approve/delete
│ (User) │ + Conversational refinement panel (Phase 2)
└────────┬────────┘
┌─────────────────┐
│ 4. COMMIT │ Create Tree record, set import_metadata, strip staging data
│ │ Step Library match suggestions (Phase 2)
└─────────────────┘
```
---
## 3. Data Model
### New Table: `kb_imports` (Migration 054)
| Column | Type | Nullable | Description |
|---|---|---|---|
| `id` | UUID PK | No | Primary key (`gen_random_uuid()`) |
| `account_id` | UUID FK → accounts | No | Tenancy scoping |
| `created_by` | UUID FK → users | No | Who initiated the import |
| `source_filename` | VARCHAR(500) | Yes | Original filename (null for paste) |
| `source_format` | VARCHAR(20) | No | Enum: `txt`, `paste`, `docx` (Phase 1); `pdf`, `html`, `md` (Phase 2) |
| `source_text` | TEXT | No | Extracted plain text content |
| `source_metadata` | JSONB | Yes | Structural metadata from extraction (headings, lists, emphasis) |
| `target_type` | VARCHAR(20) | No | Enum: `troubleshooting`, `procedural` |
| `status` | VARCHAR(20) | No | Enum: `processing`, `ready`, `committed`, `failed` |
| `confidence_avg` | FLOAT | Yes | Average confidence across all generated nodes |
| `error_message` | TEXT | Yes | Error details if status = `failed` |
| `processing_time_ms` | INTEGER | Yes | Total processing time in milliseconds |
| `ai_tokens_input` | INTEGER | Yes | Total input tokens used for AI processing |
| `ai_tokens_output` | INTEGER | Yes | Total output tokens used for AI processing |
| `tree_id` | UUID FK → trees | Yes | Set after user commits (null until then) |
| `batch_id` | UUID | Yes | Groups batch imports together (Phase 3) |
| `created_at` | TIMESTAMPTZ | No | Auto-set on creation |
| `updated_at` | TIMESTAMPTZ | No | Auto-updated on modification |
**Indexes:** `account_id`, `status`, `batch_id`, `created_by`, `created_at DESC`.
### New Table: `kb_import_nodes` (Migration 054)
Stores individual generated nodes/steps during the review phase. Each row represents one node in the AI-generated flow before the user commits it to an actual tree.
| Column | Type | Nullable | Description |
|---|---|---|---|
| `id` | UUID PK | No | Primary key |
| `kb_import_id` | UUID FK → kb_imports | No | Parent import |
| `node_order` | INTEGER | No | Position in the generated flow (0-indexed) |
| `node_type` | VARCHAR(20) | No | Enum: `question`, `resolution`, `step`, `section_header`, `warning` |
| `content` | JSONB | No | Node content (question text, step text, options array, etc.) |
| `parent_node_id` | UUID FK → kb_import_nodes | Yes | Parent node (for tree structure) |
| `source_excerpt` | TEXT | Yes | Exact text from source document this node was derived from |
| `confidence_score` | FLOAT | No | AI confidence in this node's accuracy (0.01.0) |
| `user_edited` | BOOLEAN | No | Default `false`. Set `true` when user modifies content |
| `user_approved` | BOOLEAN | No | Default `false`. Set `true` when user explicitly approves |
| `created_at` | TIMESTAMPTZ | No | Auto-set on creation |
| `updated_at` | TIMESTAMPTZ | No | Auto-updated on modification |
**Indexes:** `kb_import_id`, `confidence_score`.
### Tree `import_metadata` JSONB Schema (Set on Commit)
When a user commits a KB Accelerator flow, the resulting tree's `import_metadata` column is populated:
```json
{
"source": "kb_accelerator",
"kb_import_id": "uuid-here",
"source_filename": "Exchange-Troubleshooting.docx",
"source_format": "docx",
"confidence_avg": 0.85,
"node_count": 12,
"converted_at": "2026-03-10T14:30:00Z"
}
```
### PlanLimits Extensions
Add the following columns to the existing `plan_limits` table (and corresponding `account_limit_overrides`, admin schemas, subscription schemas, and frontend types):
| Column | Type | Description |
|---|---|---|
| `kb_accelerator_enabled` | BOOLEAN | Whether KB Accelerator is available on this plan |
| `kb_max_lifetime_conversions` | INTEGER, nullable | Lifetime cap (null = unlimited). Free = 3. |
| `kb_batch_max_size` | INTEGER, nullable | Max files per batch upload (null = disabled). Phase 3. |
| `kb_allowed_formats` | JSONB | Array of allowed format strings. Free = `["txt", "paste"]`. Pro/Team = all. |
| `kb_detailed_analysis` | BOOLEAN | Whether optional two-phase analysis is available |
| `kb_conversational_refinement` | BOOLEAN | Whether AI refinement panel is available (Phase 2) |
| `kb_step_library_matching` | BOOLEAN | Whether Step Library matching is available (Phase 2) |
| `kb_history_limit` | INTEGER, nullable | Max visible import history entries (null = unlimited). Free = 3. |
**Seed defaults:**
| Plan | enabled | lifetime_cap | batch_max | formats | detailed_analysis | refinement | step_matching | history_limit |
|---|---|---|---|---|---|---|---|---|
| **Free** | true | 3 | null | `["txt", "paste"]` | false | false | false | 3 |
| **Pro** | true | null | 5 | `["txt", "paste", "docx", "pdf", "html", "md"]` | true | true | true | null |
| **Team** | true | null | 10 | `["txt", "paste", "docx", "pdf", "html", "md"]` | true | true | true | null |
---
## 4. API Design
All endpoints under `/api/v1/kb-accelerator`. All require authentication. All records scoped to `account_id`. Role enforcement: `require_engineer_or_admin`.
### Endpoints
| Method | Endpoint | Description | Phase |
|---|---|---|---|
| `POST` | `/upload` | Upload file or paste text. Creates `kb_import`, starts extraction, triggers auto-convert. Returns `kb_import_id`. | 1 |
| `GET` | `/{id}` | Get import status, source text preview, generated nodes, confidence stats. | 1 |
| `GET` | `/` | List imports for current account. Pagination + status filter. Respects `kb_history_limit`. | 1 |
| `POST` | `/{id}/convert` | Manually trigger or re-trigger AI conversion. For retry/regeneration scenarios. | 1 |
| `PATCH` | `/{id}/nodes/{node_id}` | Edit a specific node. Operations: `approve`, `reject`, `edit`, `delete`, `regenerate`, `insert_after`. | 1 |
| `POST` | `/{id}/commit` | Finalize: create Tree record from reviewed nodes, populate `import_metadata`, update status to `committed`. | 1 |
| `DELETE` | `/{id}` | Cancel and clean up an in-progress or abandoned import. | 1 |
| `GET` | `/quota` | Return current plan KB entitlements, usage counts, and UI flags (detailed_analysis, refinement, etc.). | 1 |
| `POST` | `/{id}/analyze` | (Pro/Team) Trigger detailed two-phase analysis before generation. | 2 |
| `POST` | `/{id}/refine` | Send a refinement message scoped to this import's context. Returns updated nodes. | 2 |
| `POST` | `/batch` | Submit multiple files. Returns `batch_id` + array of `kb_import_id`s. | 3 |
| `GET` | `/batch/{batch_id}` | Get grouped batch status and per-import outcomes. | 3 |
| `GET` | `/metrics` | KPI dashboard data: conversion rate, avg confidence, format usage, etc. | 3 |
### Upload Endpoint Detail
**`POST /api/v1/kb-accelerator/upload`**
Accepts `multipart/form-data` (file upload) or `application/json` (text paste).
**Request — File Upload:**
- `file`: UploadFile (required) — the KB article file
- `target_type`: string (optional) — `"troubleshooting"` or `"procedural"`. If omitted, AI decides.
**Request — Text Paste:**
- `content`: string (required) — raw text content
- `title`: string (optional) — suggested title
- `target_type`: string (optional)
**Validation:**
- Max file size: 10MB
- Format whitelist: `.txt`, `.docx` (Phase 1); `.pdf`, `.html`, `.md` (Phase 2)
- MIME type verification (content matches extension)
- Tier format check against `kb_allowed_formats`
- Lifetime conversion count check against `kb_max_lifetime_conversions`
**Response (201 Created):**
```json
{
"id": "uuid",
"status": "processing",
"source_format": "docx"
}
```
**Pipeline behavior:** After successful upload and extraction, the auto-convert pipeline triggers immediately. Frontend polls `GET /{id}` until status changes from `processing` to `ready` (or `failed`).
### Node Edit Endpoint Detail
**`PATCH /api/v1/kb-accelerator/{id}/nodes/{node_id}`**
Supports a union of operations:
- **`approve`**: Sets `user_approved = true`
- **`reject`**: Sets `user_approved = false`
- **`edit`**: Updates `content` JSONB, sets `user_edited = true`
- **`delete`**: Removes the node, reorders remaining nodes
- **`regenerate`**: Re-runs AI generation for this single node with optional user guidance text. Uses shared AI service.
- **`insert_after`**: Creates a new node after this one, shifts `node_order` for subsequent nodes
### Commit Endpoint Detail
**`POST /api/v1/kb-accelerator/{id}/commit`**
1. Validate all nodes are reviewed (or allow commit with unreviewed nodes — user's choice)
2. Build `tree_structure` JSONB from `kb_import_nodes` rows
3. Create Tree record with appropriate `tree_type` (`troubleshooting` or `procedural`)
4. For procedural flows: include generated `intake_form` schema from detected variables
5. Set `import_metadata` JSONB with provenance data
6. Update `kb_import.status` to `committed`, set `kb_import.tree_id`
7. Run best-effort RAG indexing on the new tree
8. Record audit event
**Batch behavior (Phase 3):** Successful batch items auto-commit as draft trees. Failed items retain `failed` status with error details.
---
## 5. AI Pipeline
### Single-Phase Conversion (Default)
One AI call that takes extracted text and returns a complete tree structure.
**System Prompt establishes:**
- AI role as MSP documentation specialist
- Target flow type (troubleshooting or procedural)
- ResolutionFlow tree schema with examples (reuse patterns from `ai_chat_service.py`)
- Confidence scoring instructions (0.01.0 per node with criteria)
- Source excerpt attribution requirement (every node must cite its source text)
- Variable detection instructions for procedural flows (`[VAR:name]` tokens)
**User message contains:**
- Extracted text with structural metadata (headings, lists, emphasis markers)
- Source filename and format for context
**Expected response:** Strict JSON matching the structure needed to populate `kb_import_nodes` rows, including `node_type`, `content`, `confidence_score`, `source_excerpt`, and parent-child relationships.
**Model routing:** Add `kb_convert` to `ACTION_MODEL_MAP` → maps to Sonnet (standard tier).
**Token tracking:** Record `ai_tokens_input` and `ai_tokens_output` on the `kb_import` record. Also call `record_ai_usage` for quota/cost tracking through the shared service.
### Two-Phase Analysis + Generation (Optional, Pro/Team)
**Phase 1 — Analysis:** AI returns structured JSON of detected elements (document type, problem statement, prerequisites, sequential steps, decision points, variables, warnings, resolutions, verification steps). Stored in `kb_import.source_metadata` or a dedicated analysis column.
**Phase 2 — Generation:** Takes Phase 1 analysis + original text → generates tree structure (same output as single-phase).
**Model routing:** Add `kb_analyze` to `ACTION_MODEL_MAP`.
### Confidence Scoring
| Score Range | Label | UI Indicator |
|---|---|---|
| 0.9 1.0 | High Confidence | Green left accent border |
| 0.7 0.89 | Medium Confidence | Amber left accent border |
| 0.5 0.69 | Low Confidence | Red left accent border |
| < 0.5 | Needs Review | Red left accent border + flag icon |
### Procedural Flow: Variable Detection
For procedural target type, the AI identifies instance-specific values and maps them to `[VAR:name]` tokens:
| Pattern | Variable Name | Form Field Type |
|---|---|---|
| IP addresses | `[VAR:ip_address]` | ip_address |
| Server/computer names | `[VAR:server_name]` | text |
| Domain names | `[VAR:domain_name]` | text |
| Usernames/email | `[VAR:username]` | text |
| License types | `[VAR:license_type]` | select |
| OU paths | `[VAR:ou_path]` | text |
| Port numbers | `[VAR:port]` | number |
| Subnet masks | `[VAR:subnet_mask]` | ip_address |
An `intake_form` JSONB schema is auto-generated from detected variables and stored on the committed tree.
---
## 6. Frontend Design
### Route: `/kb-accelerator`
Multi-step wizard with 3-4 screens, all within the existing app shell (sidebar + topbar). Uses the current design system: dark theme, cyan brand color, glass morphism, IBM Plex Sans / Bricolage Grotesque / JetBrains Mono fonts.
### Screen 1: Upload
- Drag-and-drop zone for files with format badges (DOCX, TXT in Phase 1)
- Tab switch to "Paste Text" with full-width textarea + title field
- Target type selector: two visual cards (Troubleshooting Flow / Procedure Flow) + "Let AI decide" option
- Primary action: "Convert" button (`bg-gradient-brand`)
- Pro/Team users see additional "Detailed Analysis" button alongside "Convert"
- Container: `.glass-card-static`
- Tier gating: free users see format restrictions and remaining conversion count
### Screen 2: Analysis Preview (Phase 2, Pro/Team Only, Feature-Flagged)
- Shows detected elements as color-coded cards: steps (blue), decision points (amber), warnings (red), variables (green), resolutions (emerald)
- Source text excerpts linked to each detection
- "Proceed to Generation" and "Re-analyze" action buttons
- Only accessible when user clicks "Detailed Analysis" on the upload screen
### Screen 3: Review (Core Experience)
**Two-Panel Side-by-Side Layout:**
- **Left panel:** Original document text with detected elements highlighted inline (color-matched to generated nodes)
- **Right panel:** Generated flow preview — tree visualization for troubleshooting, step list for procedures
- Clicking a node in the right panel highlights its source excerpt in the left panel, and vice versa
- Each node shows confidence score via left accent border pattern (green/amber/red)
**Per-Node Actions:**
- **Approve** (checkmark): Sets `user_approved = true`
- **Edit** (pencil): Opens inline editing for content, question text, options
- **Regenerate** (refresh): Re-runs AI for just this node with optional guidance
- **Delete** (trash): Removes node from generated flow
- **Add Node** (plus): Insert a manual node after this one
**Bulk Actions:**
- "Approve All High Confidence" — one-click approval for all nodes scoring ≥ 0.9
- "Commit to Library" — finalizes the flow
**AI Refinement Panel (Phase 2):** Slide-in panel on the review screen for conversational refinement. User types natural language instructions ("Add a warning about DNS propagation after step 4", "Split this decision point"). Scoped to the KB import context — NOT the general FlowPilot chat. Reuses `EditorAIPanel` component internals with KB-specific branding.
**Step Library Suggestions (Phase 2):** For procedural flows, matched steps show a "Link to Library" badge. Clicking shows the library step content and lets the user swap the generated step for the library step.
### Screen 4: Success
- Confirmation with link to the new flow in the editor
- "Convert Another" button
- Stats: average confidence score, node count, processing time
### Navigation
- **Sidebar:** "KB Accelerator" nav item with sparkle/lightning icon
- **Flow library header:** "Import KB Article" button next to "Create New Flow"
---
## 7. Tier Gating
| Capability | Free | Pro ($19/mo) | Team ($15/user/mo) |
|---|---|---|---|
| **Conversions** | 3 lifetime (account-wide) | Unlimited | Unlimited |
| **Formats** | TXT + paste only | All formats | All formats |
| **Target type selection** | AI decides only | Manual + AI | Manual + AI |
| **Detailed analysis** | No | Yes | Yes |
| **Conversational refinement** | No | Yes (Phase 2) | Yes (Phase 2) |
| **Step Library matching** | No | Yes (Phase 2) | Yes (Phase 2) |
| **Review actions** | Approve / Edit / Delete | Full (+ regenerate, insert, bulk approve) | Full (+ regenerate, insert, bulk approve) |
| **Import history** | Last 3 only | Full history | Full history + audit log |
| **Batch import** | No | Up to 5 articles (Phase 3) | Up to 10 articles (Phase 3) |
| **Team visibility** | N/A | N/A | Shared read access to imports |
**Enforcement:** Hard server-side checks on every endpoint. Check `subscription.plan``PlanLimits` columns. Free tier lifetime count = `COUNT(*) FROM kb_imports WHERE account_id = ? AND status = 'committed'`.
---
## 8. Build Phases
### Phase 1: Core Pipeline (Target: 23 Weeks)
The goal is a complete, working single-article conversion loop for text, paste, and DOCX inputs producing both troubleshooting and procedural flows.
**Backend:**
- Migration 054: `kb_imports` and `kb_import_nodes` tables
- Migration 055: `PlanLimits` KB Accelerator columns + seed defaults
- Upload endpoint — text, paste, DOCX extraction (python-docx)
- Single-phase AI conversion — prompt engineering, structured JSON parsing, node creation
- Node edit endpoint — approve, reject, edit, delete, regenerate, insert_after
- Commit endpoint — create Tree, set `import_metadata`, strip staging data, RAG indexing
- List/get import endpoints with pagination and status filter
- Quota endpoint — return plan entitlements and usage counts
- Delete/cancel endpoint
- Hard tier gating — format checks, lifetime conversion count, review action restrictions
- Add `kb_convert` to `ACTION_MODEL_MAP`
- Extraction service module (TXT, paste, DOCX) with pluggable architecture for Phase 2 formats
- Upload validation service — extension, MIME, size, pluggable scan hook (no-op default)
**Frontend:**
- Upload screen — drag-drop zone, paste tab, target type cards, "Let AI decide"
- Review screen — two-panel layout, confidence indicators, per-node actions, source highlighting
- Success screen — confirmation, stats, "Convert Another"
- Sidebar nav item + flow library CTA button
- KB Accelerator API client module (`kbAccelerator.ts`)
- TypeScript types (`kbAccelerator.ts`)
- HTTP polling for processing status
- Tier gating UI — format restrictions shown, remaining conversions shown, upgrade prompts for locked features
**Both flow types** (troubleshooting + procedural) supported from Phase 1 start.
### Phase 2: Rich Formats & Refinement (Target: 23 Weeks)
Layer on additional formats, the power-user analysis preview, conversational refinement, and Step Library matching.
**Backend:**
- PDF extraction via PyMuPDF with extraction preview/correction endpoint (user verifies extracted text before AI processing)
- HTML extraction via BeautifulSoup
- Markdown extraction via markdown-it-py
- Detailed analysis endpoint — two-phase AI (analyze → generate), Pro/Team gated
- Conversational refinement endpoint — scoped chat for the KB import context, uses shared AI service, NOT `AIChatSession`
- Step Library matching service — compare generated procedural steps against user's Step Library (text similarity or pgvector embeddings)
- Add `kb_analyze` and `kb_refine` to `ACTION_MODEL_MAP`
**Frontend:**
- PDF extraction preview screen — shows extracted text, highlights potential issues, user can edit before AI processing
- Analysis preview screen — feature-flagged for Pro/Team, shows detected elements as color-coded cards
- AI refinement slide-in panel on review screen — reuses `EditorAIPanel` internals with KB branding
- Step Library match suggestions — "Link to Library" badges on matched procedural steps
- "Approve All High Confidence" bulk action button
### Phase 3: Scale & Polish (Future)
Batch import, history dashboard, and analytics.
**Backend:**
- Batch upload endpoint — multipart `files[]` + shared options, returns `batch_id` + import IDs
- Batch status endpoint
- FastAPI background jobs for batch processing (DB-based job queue)
- Auto-commit as draft for successful batch items
- Import history dashboard endpoint
- Metrics/analytics endpoint — conversion rate, avg confidence, format usage, time trends
**Frontend:**
- Batch upload UI — multi-file drag-drop with per-file status indicators
- Batch results view — shows auto-committed drafts and failed items
- Import history dashboard with filters and search
- Analytics visualizations (conversion trends, confidence distributions)
---
## 9. Files to Create and Modify
### New Files
| File | Purpose |
|---|---|
| `backend/alembic/versions/054_add_kb_imports.py` | Migration: `kb_imports` + `kb_import_nodes` tables |
| `backend/alembic/versions/055_add_kb_plan_limits.py` | Migration: PlanLimits KB columns + seed defaults |
| `backend/app/models/kb_import.py` | SQLAlchemy models: `KBImport`, `KBImportNode` |
| `backend/app/schemas/kb_accelerator.py` | Pydantic schemas: request/response DTOs |
| `backend/app/api/endpoints/kb_accelerator.py` | API endpoints |
| `backend/app/core/kb_extraction_service.py` | Text extraction (TXT, paste, DOCX; extensible for Phase 2 formats) |
| `backend/app/core/kb_conversion_service.py` | AI prompt orchestration, JSON parsing, node creation |
| `backend/tests/test_kb_accelerator.py` | Integration tests |
| `frontend/src/api/kbAccelerator.ts` | API client module |
| `frontend/src/types/kbAccelerator.ts` | TypeScript types |
| `frontend/src/pages/KBAcceleratorPage.tsx` | Main page (multi-step wizard) |
| `frontend/src/components/kb-accelerator/UploadScreen.tsx` | Upload UI component |
| `frontend/src/components/kb-accelerator/ReviewScreen.tsx` | Two-panel review UI component |
| `frontend/src/components/kb-accelerator/SuccessScreen.tsx` | Post-commit confirmation component |
| `frontend/src/components/kb-accelerator/NodeCard.tsx` | Individual node display with confidence + actions |
| `frontend/src/components/kb-accelerator/SourcePanel.tsx` | Left panel: source text with highlights |
### Modified Files
| File | Change |
|---|---|
| `backend/app/models/__init__.py` | Import `KBImport`, `KBImportNode` |
| `backend/alembic/env.py` | Import KB models for migration detection |
| `backend/app/api/router.py` | Register `kb_accelerator` router |
| `backend/app/core/config.py` | Add `kb_convert` (Phase 1), `kb_analyze`, `kb_refine` (Phase 2) to `ACTION_MODEL_MAP` |
| `backend/app/models/plan_limits.py` | Add KB Accelerator limit columns |
| `frontend/src/router.tsx` | Add `/kb-accelerator` route |
| `frontend/src/components/layout/AppLayout.tsx` or `Sidebar.tsx` | Add KB Accelerator sidebar nav item |
| `frontend/src/types/index.ts` | Export KB Accelerator types |
| `frontend/src/api/index.ts` | Export KB Accelerator API client |
### Existing Files Reused (Not Modified)
| File | What's Reused |
|---|---|
| `backend/app/core/ai_chat_service.py` | Prompt patterns, structured output parsing examples |
| `backend/app/core/ai_quota_service.py` | `check_ai_quota()`, `record_ai_usage()` |
| `backend/app/core/ai_provider_service.py` | `get_model_for_action()`, Anthropic client patterns |
| `frontend/src/components/tree-editor/EditorAIPanel.tsx` | Component internals reused for refinement panel (Phase 2) |
---
## 10. Test Plan
### Backend Integration Tests
**Upload & Extraction:**
- Upload text/paste → verify `kb_import` created with status `processing`
- Upload DOCX → verify extraction produces `source_text` and `source_metadata`
- Upload unsupported format → verify 400 rejection
- Upload exceeding 10MB → verify 413 rejection
- Upload DOCX on free tier → verify 403 (format not in plan)
- Upload when lifetime limit reached → verify 403 with upgrade message
**AI Conversion:**
- Convert troubleshooting article → verify `kb_import_nodes` created with correct types, confidence scores, source excerpts
- Convert procedural article → verify step nodes created with `[VAR:name]` tokens and `intake_form` data
- Convert with AI failure → verify status set to `failed` with error message
- Verify token counts recorded on `kb_import`
- Verify `record_ai_usage` called through shared service
**Node Review Actions:**
- Approve node → verify `user_approved = true`
- Edit node → verify `content` updated, `user_edited = true`
- Delete node → verify removed, `node_order` resequenced
- Regenerate node → verify AI called, node content replaced, new confidence score
- Insert after → verify new node created with correct `node_order`, subsequent nodes shifted
**Commit:**
- Commit troubleshooting import → verify Tree created with correct `tree_type`, `tree_structure`, `import_metadata`
- Commit procedural import → verify Tree created with `intake_form` populated
- Verify `kb_import.status` = `committed`, `tree_id` set
- Verify committed tree appears in flow library
- Verify RAG indexing triggered (best-effort)
**Tier Enforcement:**
- Free tier: 4th conversion rejected (account-scoped lifetime count)
- Free tier: DOCX upload rejected, paste accepted
- Pro tier: unlimited conversions, all formats accepted
- Team tier: other account members can view import (shared visibility)
### Frontend Tests
- Upload flow: file drag-drop, paste, target type selection, validation messages
- Polling: status transitions from `processing` to `ready`
- Review screen: node display, confidence colors, source highlighting, click-to-highlight linking
- Node actions: inline edit, approve, delete — optimistic UI updates
- Commit flow: success screen, link to editor works
- Tier gating: free tier sees upgrade prompts, format restrictions shown, conversion count displayed
### E2E Smoke Test
1. Paste a sample KB article text
2. Select "Troubleshooting Flow"
3. Click "Convert"
4. Wait for processing → land on review screen
5. Verify nodes displayed with confidence indicators
6. Edit one low-confidence node
7. Approve all high-confidence nodes
8. Click "Commit to Library"
9. Verify flow appears in library
10. Open flow in tree editor — verify structure is correct
---
## 11. Success Metrics (Post-Launch)
| Metric | Target | Why It Matters |
|---|---|---|
| **Conversion completion rate** | > 70% | Imports reaching `committed` status. Below 70% = review too burdensome or quality too low. |
| **Average confidence score** | > 0.75 | Across all generated nodes. Indicates AI pipeline accuracy. |
| **Time from upload to commit** | < 10 minutes | Full cycle should feel fast. 30+ minutes = AI not saving enough time. |
| **Free-to-Pro conversion rate** | > 15% | Users who exhaust 3 free conversions then upgrade. Validates feature drives revenue. |
| **Repeat usage (Pro/Team)** | > 3 imports/month | Sustained usage indicates feature is part of workflow, not a one-time novelty. |
| **Node edit rate** | < 30% | Percentage of nodes edited before commit. Lower = AI output more usable as-is. |
| **Imported flow usage rate** | > 50% | Committed flows used in sessions within 30 days. Low = conversion producing shelfware. |
---
*End of Plan*
*ResolutionFlow LLC — March 2026*