A SwiftUI app that watches a folder and works out what each new file is (a receipt, a tax form, lecture notes, a résumé, a screenshot) using only Apple's on-device frameworks. Nothing is uploaded anywhere: text comes from Vision OCR and PDFKit, meaning comes from NaturalLanguage sentence embeddings, and the watching is done with FSEvents.
This is the native rewrite of cyphersort, the Python + Ollama version that also files results into a Cryptomator vault.
- Watch. An
FSEventStreamwith file-level events reports every file created in the chosen folder. You can also drag files onto the window or pick them. - Read. OCR (
VNRecognizeTextRequest, accurate mode with language correction) and PDF text extraction run concurrently withasync let. Each one also reports a text-quality score. - Embed and compare. The extracted text plus filename and metadata keywords goes through
NLEmbedding.sentenceEmbedding(for: .english)and is compared against a short prototype description of each category (Finance/Receipts,Finance/Taxes,School/LectureNotes,Career/Resume,Career/Offers,Development/Projects,Development/InterviewPrep,Screenshots,Documents/*). If the embedding model isn't available, a weighted keyword table takes over. - Blend with metadata. Metadata scores and embedding scores are mixed, and the weight shifts with text quality: a clean PDF trusts the text (up to 75%), a blurry screenshot leans on metadata. A few targeted rules handle the classic confusions. Documents that look like receipts or tax forms can override the blend, while ads full of prices get pushed back toward
Documents/General. - Report honestly. Confidence is clamped to 35-96%, and to at most 65% when the call rests on metadata alone, so the UI never presents a guess as certain.
Learned rules (filename pattern → category, with a minimum confidence and a success count) and a history of every decision are stored with SwiftData.
Run Tests in the app runs two suites and prints the results to the console:
- A synthetic set of labeled examples, reporting accuracy and average confidence.
- A sample of up to 20 files per class from the RVL-CDIP document dataset (
invoice→ receipts,resume→ résumé,letter→ general, and so on), run through the full pipeline including OCR. Point the app at a local copy of the dataset; it isn't included in the repo.
Open CipherSort.xcodeproj in Xcode (macOS 14+, Swift 5.9+) and run. The app is sandboxed and asks for folder access through the standard picker.
| Path | Role |
|---|---|
Watcher/FilesystemWatcher.swift |
FSEvents stream |
Analysis/OCRAnalyzer.swift, PDFAnalyzer.swift |
Text extraction plus quality scores |
Analysis/MetadataAnalyzer.swift |
Filename, extension and type signals |
Analysis/NLPClassifier.swift |
Sentence-embedding classifier with keyword fallback |
Categorization/CategorizationManager.swift |
Score blending, overrides, confidence caps |
Persistence/RuleStore.swift |
SwiftData rules and history |
App/ |
SwiftUI window, drag and drop, benchmark runners |