Skip to content

Conversation

@prosdev
Copy link
Contributor

@prosdev prosdev commented Dec 8, 2025

Summary

Major refactor to simplify the CLI and improve maintainability of the extract package.

CLI Changes

  • Removed Ink (React-based CLI framework) in favor of simpler tools:
    • ora for spinners
    • prompts for interactive input
    • chalk for colors
    • @lytics/kero for structured logging
  • Kero logs now visible in terminal (were swallowed by Ink)
  • LOG_LEVEL=debug support for debugging extraction flow
  • Smaller bundle (14KB vs 30KB)

Extract Package Changes

  • Split monolithic index.ts into modules:
    • types.ts - StreamChunk, StreamCallback types
    • schemas.ts - Zod schemas with flexible field mapping
    • mime.ts - MIME type detection
    • pdf.ts - PDF to image conversion (scale 3 for quality)
    • ocr.ts - Tesseract.js OCR
    • providers/ollama.ts - Ollama extraction with kero logging
    • providers/gemini.ts - Gemini extraction
    • extract.ts - Main orchestrator
  • Flexible schema mapping for model variations:
    • store_name/merchant/business_namevendor
    • total/total_amountamount
  • Date normalization: both date (ISO) and dateRaw (original)
  • Higher PDF resolution (scale 3) for better OCR

Core Changes

  • Added dateRaw field to DocumentData for audit trail

Testing

  • All 87 tests pass
  • Lint & format clean

- types.ts: StreamChunk, StreamCallback, ExtractOptions types
- schemas.ts: Zod schemas with flexible field mapping
- mime.ts: MIME type detection helper
- pdf.ts: PDF to image conversion (scale 3 for quality)
- ocr.ts: Tesseract.js OCR with progress callbacks
- providers/ollama.ts: Ollama extraction with kero logging
- providers/gemini.ts: Gemini extraction (unchanged)
- extract.ts: Main extraction orchestrator
- index.ts: Barrel export

Improves testability and maintainability.
BREAKING: Removed React-based Ink UI in favor of simpler CLI tools.

Removed:
- components/: ExtractApp, OllamaStatus, StreamingOutput, etc.
- hooks/: useOllama, useExtraction
- contexts/: OllamaContext, ExtractionContext
- Dependencies: ink, ink-spinner, react, @types/react

Added:
- commands/extract.ts: New extraction command with ora spinners
- Dependencies: ora, prompts, chalk, @lytics/kero

Benefits:
- Simpler architecture (no React overhead)
- Kero logging visible in terminal (was swallowed by Ink)
- LOG_LEVEL=debug support for debugging
- Smaller bundle size (14KB vs 30KB)
- date: Normalized ISO format (YYYY-MM-DD) for querying
- dateRaw: Original date string from document for audit trail
- vitest.config.ts: Exclude barrel exports from coverage
- packages/extract/package.json: Add kero dependency
- pnpm-lock.yaml: Updated lockfile
- Test vendor field alternatives (store_name, merchant, business_name)
- Test amount field alternatives (total, total_amount)
- Test date normalization and dateRaw preservation
@prosdev prosdev merged commit 2eb612f into main Dec 8, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants