Description
Three Rust files have grown past the point of effective code review. At these sizes, bugs hide in plain sight and the LLM-era grep-and-edit workflow degrades (navigating a 4,700-LOC file is slow for humans and for agents).
Current State
src-tauri/src/context.rs — 173 KB / 4,733 LOC — mixes query intent, employee retrieval, system prompt, org aggregates, verification, token budgeting.
src-tauri/src/lib.rs — 75 KB / 2,193 LOC — every #[tauri::command] registered in one file.
src-tauri/src/documents.rs — 53 KB / 1,534 LOC — discovery, parsing, chunking, FTS, watcher, commands.
Suggested Fix
context.rs → context/
lib.rs → commands/
documents.rs → documents/
Do NOT change behavior — pure split. Do each file in its own PR.
Verification
Automation Hints
scope: src-tauri/src/context.rs (or documents.rs, or lib.rs) → split per PR
do-not-touch: business logic
approach: extract-and-move
risk: medium-high (large diff, many imports to update)
max-files-changed: 15 per PR
blocked-by: none
bail-if: public API changes or tests break
Priority
Medium — compounding maintenance debt; do in patches over next 2-3 weeks.
Notes
needs-design-decision candidate — confirm the split before starting each one. Do lib.rs first (lowest-risk; most files but least coupled logic), context.rs last (most integration tests to verify).
Description
Three Rust files have grown past the point of effective code review. At these sizes, bugs hide in plain sight and the LLM-era grep-and-edit workflow degrades (navigating a 4,700-LOC file is slow for humans and for agents).
Current State
src-tauri/src/context.rs— 173 KB / 4,733 LOC — mixes query intent, employee retrieval, system prompt, org aggregates, verification, token budgeting.src-tauri/src/lib.rs— 75 KB / 2,193 LOC — every#[tauri::command]registered in one file.src-tauri/src/documents.rs— 53 KB / 1,534 LOC — discovery, parsing, chunking, FTS, watcher, commands.Suggested Fix
context.rs → context/
context/query.rs— intent classification,extract_mentionscontext/retrieval.rs— all DB fetch functions (batch-aware, see [MEDIUM] N+1 queries in context.rs retrieval paths — 30+ DB queries per chat message #32)context/aggregates.rs— OrgAggregates + countscontext/verification.rs—verify_responseand friendscontext/prompt.rs— Alex persona + token budgetcontext/mod.rsre-exports the public surface so call sites don't changelib.rs → commands/
commands/api_key.rs,commands/providers.rs,commands/license.rs,commands/chat.rs,commands/employees.rs,commands/documents.rs,commands/company.rs,commands/settings.rs, etc.generate_handler!-compatible bundle;lib.rscomposes them.documents.rs → documents/
documents/discovery.rs,documents/chunker.rs,documents/ingest.rs,documents/watcher.rs,documents/commands.rs.Do NOT change behavior — pure split. Do each file in its own PR.
Verification
cargo test --manifest-path src-tauri/Cargo.tomlpasses with zero diff in passing tests.cargo checkclean.git diff --statshows the refactor is nearly 1:1 (line counts preserved, structure only moved).Automation Hints
scope: src-tauri/src/context.rs (or documents.rs, or lib.rs) → split per PR
do-not-touch: business logic
approach: extract-and-move
risk: medium-high (large diff, many imports to update)
max-files-changed: 15 per PR
blocked-by: none
bail-if: public API changes or tests break
Priority
Medium — compounding maintenance debt; do in patches over next 2-3 weeks.
Notes
needs-design-decisioncandidate — confirm the split before starting each one. Do lib.rs first (lowest-risk; most files but least coupled logic), context.rs last (most integration tests to verify).