# Soi96 Legal — Build Phases

## Phase 0 — Foundation (Now)
- [ ] Gitea repo set up
- [ ] Strategy and architecture documented
- [ ] Attorney design sessions scheduled — collect domain requirements
- [ ] Define matter schema with attorney input
- [ ] Define client profile attributes with attorney input

## Phase 1 — Core Legal Layer
Built on top of bigwig-erp-v3 backend/frontend

### Matter Management
- [ ] Matter model (case record, type, status, attorneys assigned)
- [ ] Matter ↔ Contact links (client, opposing party, court contacts)
- [ ] Matter ↔ Document links
- [ ] Matter list + detail views
- [ ] Matter number generation (Thai civil procedure format)

### Court & Deadline Tracking
- [ ] Hearing record (date, court, type, outcome)
- [ ] Deadline model with warning thresholds
- [ ] Calendar view — hearings and deadlines per attorney

### Time Entry
- [ ] Time entry form (matter, date, duration, task code, description)
- [ ] Billing summary per matter
- [ ] Retainer balance display

### Conflict Check
- [ ] Cross-reference new client/opposing party against all existing records
- [ ] Flag on matter creation; log result

### Trust Accounting (Basic)
- [ ] Client retainer ledger
- [ ] Intake / disbursement entries
- [ ] Balance per client

## Phase 2 — AI Layer (Prompt Analyst + Client Manager + Comms Agent)
Can begin after 2-3 months of Phase 1 data exists. See `docs/agent-architecture.md` for full hierarchy.

### Prompt Analyst
- [ ] Natural language intent classification
- [ ] Routing logic — case/research track vs. operational track
- [ ] Structured request packaging for downstream agents
- [ ] Response assembly and attorney-facing output
- [ ] Handles both tracks simultaneously when request spans both

### Client Manager (per client)
- [ ] Per-client agent initialisation at onboarding
- [ ] Profile schema finalised (with attorney input from Phase 0/1)
- [ ] Embedding pipeline: document + profile → vector store
- [ ] Auto-brief generation at matter-open
- [ ] Profile update triggers (new document, new matter outcome → update)
- [ ] Read/write operations: notes, records, documents, matter updates

### Comms Agent
- [ ] Inbound email triage: classify → route to attorney queue
- [ ] Inbound LINE: same classification and routing logic
- [ ] Draft response generation for routine queries (Class 1)
- [ ] Attorney approval queue (1-click send)
- [ ] Document received → classify → link to matter → notify (Class 2)
- [ ] Escalation logic: urgent/sensitive → immediate alert (Class 3)
- [ ] New enquiry → conflict check trigger → lead record (Class 4)
- [ ] Operational tasks: scheduling, rescheduling, notes, reminders
- [ ] Proactive notifications: court deadline warnings (3 day / 1 day), hearing reminders, retainer balance alerts, document response overdue, matter inactivity flags
- [ ] Internal calendar: hearings, deadlines, client meetings, matter milestones — system of record
- [ ] Google Calendar integration: OAuth per user, bidirectional sync, webhook listener for attorney-side changes
- [ ] Calendar conflict detection: flags double-bookings across internal and Google
- [ ] Training loop: every approved draft feeds weekly fine-tune on Workbeast

### Case/Situation Analyst
- [ ] Receives structured requirements from Prompt Analyst
- [ ] Identifies which Client Manager(s) are relevant
- [ ] Delegates and coordinates Client Manager responses
- [ ] Calls RAG Agent when statute lookup is required
- [ ] Calls Billing Agent when financial data is required
- [ ] Aggregates multi-agent responses into single output

### Billing Agent
- [ ] Client retainer ledger
- [ ] Trust account (client funds isolated from operating funds)
- [ ] Time entry aggregation and billing summaries
- [ ] Invoice generation
- [ ] AR aging and outstanding balances
- [ ] Disbursement tracking

## Phase 3 — RAG Agent + Case Strategy
Requires sufficient closed matter history (target: after 12+ months of Phase 1)

### RAG Agent
- [ ] Statute corpus ingestion: Thai CCC, Land Code, Labour Act, Foreign Business Act, Revenue Code, BOI, Companies Act, Consumer Protection Act
- [ ] Chunking and vector indexing with section-level citations
- [ ] Retrieval API for Case/Situation Analyst only
- [ ] Corpus update process (statutes change — needs a refresh pipeline)

### Case/Situation Analyst — Strategy Mode
- [ ] Closed matter export pipeline (arguments, outcomes, timelines)
- [ ] Fine-tuning on firm's own case data
- [ ] Pattern recognition across opposing counsel, matter types, resolution paths
- [ ] New matter assessment: input matter type + client profile → strategy suggestions
- [ ] Full parallel query at matter open: Client Manager + Intelligence Agent + RAG Agent + Billing Agent → synthesised strategic brief

### Intelligence Agent
- [ ] Judge profile schema: identity, ruling tendencies, procedural preferences, behavioural patterns, firm history
- [ ] Opposing counsel profile schema: identity, litigation style, strengths/weaknesses, settlement behaviour, firm history
- [ ] Law firm profile schema: size, specialism, resourcing patterns, firm record against them
- [ ] Court support team schema: role, filing behaviour, friction points, relationship history
- [ ] Initial population workflow: attorney/partner seeding session — capture existing knowledge into structured profiles
- [ ] Public data ingestion: bar association records, published judgments, court registers
- [ ] Matter-close update pipeline: Case/Situation Analyst requests intelligence data from Client Managers → Intelligence Agent updates profiles
- [ ] Cross-matter aggregation: same judge or opposing counsel appearing across multiple client matters → single enriched profile
- [ ] Profile separation: client-specific context stays in Client Manager, only adversary/court intelligence moves to Intelligence Agent
- [ ] Strategic brief integration: Intelligence Agent output included in new matter brief alongside Client Manager, RAG Agent, Billing Agent results

## Phase 4 — Thai Language + Polish
- [ ] Thai UI translation (core legal modules)
- [ ] Thai-language document processing (OCR + classification for Thai court docs)
- [ ] Mobile view (hearing attendance)
- [ ] Matter outcome reporting
- [ ] Billing reports + AR aging

---

## Design Sessions Needed with Attorney

Before Phase 1 build starts:

1. **Matter types** — how does the firm categorise cases? What sub-types exist within corporate and family?
2. **Thai court workflow** — how do hearings progress? What are the typical phases?
3. **Document taxonomy** — what document types arrive? How should they be classified?
4. **Client profile attributes** — what do attorneys need to know about a client before opening a matter?
5. **Time entry codes** — does the firm use UTBMS or a custom system?
6. **Trust accounting rules** — what does Thai bar compliance require?
7. **Conflict check scope** — who counts as a conflicting party?
8. **Communications volume** — how many emails per day? Which are routine vs. complex?
9. **LINE usage** — how are clients currently reaching the firm via LINE?
