Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: SortSense CI & Release Build
on:
push:
branches:
- release/windows-v1
- main
- fix/sortsense-regression-restoration
pull_request:
branches:
- main
Expand All @@ -14,56 +14,55 @@ permissions:

jobs:
test:
name: Test Suite (Python ${{ matrix.python-version }})
name: Test Suite (Python 3.11)
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
python-version: "3.11"
cache: "pip"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run complete test suite
- name: Run test suite (non-GUI, non-Ollama)
run: |
pytest -v
python -m pytest -q --ignore=tests/smoke_test_live.py

build-windows:
name: Windows Desktop Packaging Verification
name: Windows Desktop Packaging
needs: test
runs-on: windows-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python 3.13
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.13"
python-version: "3.11"
cache: "pip"

- name: Install packaging dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Build PyInstaller distribution
run: |
pyinstaller sortsense.spec --noconfirm
python -m PyInstaller sortsense.spec --noconfirm

- name: Verify packaged desktop binary with smoke test
run: |
.\dist\SortSense\SortSense.exe --smoke-test
- name: Upload Windows exe artifact
uses: actions/upload-artifact@v4
with:
name: SortSense-Windows-exe
path: dist/SortSense/
if-no-files-found: error
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
venv/
.venv/
.venv*/
__pycache__/
*.pyc
*.pyo
.env
*.db
.DS_Store
build/
dist/
*.egg-info/
.pytest_cache/
pytest_*.txt
*.exe
68 changes: 68 additions & 0 deletions FIXES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# SortSense Regression Fix — Root Cause & Change Log

Branch: `fix/sortsense-regression-restoration`

## Root Cause (Confirmed by real pydantic/pytest on Windows, 279 tests)

1. **Deterministic analyzer had no subject knowledge.**
Only recognised document *types* (invoice, assignment, exam…) plus ~11 subjects (no OOPS, no Discrete
Math, DBMS only by "database/dbms/sql"). Subject only added +0.05 and only if a type already matched,
so study notes with opaque names scored 0.15–0.30 → "Review Queue, below threshold 0.85". The threshold
was correct — the evidence engine was broken.

2. **`organizer.decide()` discarded the analyzer's filename** and rebuilt it from `document_type`
(every unclassified file would be suggested as `Unclassified.txt`).

3. **GUI moved files without approval.** Used a private `_safe_move` that bypassed `SafeFileExecutor`,
so those moves had **no history and no Undo**. Review-queue moves had the same problem and could not
edit the proposed name.

4. **Status label could lie.** No "request failed" state; could say "AI Active" even after a timeout.

5. **`app/main.py` banner crashed** (`settings.watched_dir` doesn't exist; also said "FileMind").
The CLI watcher auto-moved files — bypassing approval.

6. **PDF extraction hard-required PyMuPDF.** Any environment without it failed every PDF silently.

---

## What Changed

| File | Change |
|------|--------|
| `app/topics.py` *(new)* | Weighted-lexicon topic engine: 12 subjects, distinct-term evidence, heading/filename corroboration, margin check for ambiguity, title extraction from content |
| `app/analyzer.py` | Deterministic analyzer calls `topics.py`; `OllamaServiceManager.engine_state()` → 5 honest states; request timeout; Gemma failures degrade to deterministic and are never labelled Gemma |
| `app/analysis_models.py` | Optional `evidence: list[str]` and `source: str | None` fields |
| `app/proposals.py` *(new)* | Approval-first `Proposal` + `ProposalManager`: edit name/category/destination, approve, reject, execute ONLY approved via `SafeFileExecutor` → history + Undo, partial failure |
| `app/pipeline.py` *(new)* | `process_file()`: wait-until-stable, skip `.crdownload/.part/.tmp`, ingest → analyze → Proposal. Never moves anything. |
| `app/ingestion.py` | PyMuPDF with pypdf fallback; encrypted/malformed PDFs → `error`; image-only → `empty` (no OCR); BOM/UTF-16/cp1252 text decoding |
| `app/organizer.py` | Keeps content-based filename from analyzer |
| `app/gui.py` | Pipeline produces proposals; Review Queue is approval screen (editable name, Folder…, Approve, Reject, Execute Approved); Pending = awaiting; Processed = executed only; duplicate events deduped via `_inflight`; engine status from `engine_state()`; safe observer restart in `save_settings()` |
| `app/watcher.py` | Ignores partial downloads; dedup via `_seen` dict |
| `app/main.py` | Banner corrected: "SortSense — local AI file organizer"; crash from missing `watched_dir` fixed |
| `sortsense.spec` | Added `pypdf` to `hiddenimports` (critical: without this the packaged binary crashes) |
| `requirements.txt` | Added `pypdf` |
| `.github/workflows/ci.yml` | Pinned Python 3.11; fixed test command; added artifact upload; removed headless GUI smoke test; added branch trigger |
| `.gitignore` | Added `.venv*/`, `*.pyo`, `pytest_*.txt` |
| `tests/test_user_controlled_workflow.py` *(new)* | 31 regression tests covering approval flow, 12-file scenario, safety, engine honesty |
| `tests/fixtures/regression_docs/` *(new)* | 12 fixture documents (DBMS×3, DSA×3, OOPS×3, Discrete Math×3) |
| `tests/test_packaging_lifecycle.py` | `test_low_confidence_document_routed_to_review_despite_rule_match` rewritten for proposal flow |

---

## What Was and Was NOT Verified

### Verified on Windows (this session)
- ✅ 279/279 tests pass with real pydantic 2.14.3, pypdf 7.1.0, PyMuPDF 2.1 (fresh venv)
- ✅ All 6 packaging lifecycle tests pass, including `test_low_confidence_...`
- ✅ All pydantic v2 imports clean
- ✅ `proposals.py` rule + low-confidence logic: `needs_review=True` even when a rule matches but confidence < threshold
- ✅ CI workflow corrected (artifact upload, Python 3.11, no headless smoke test)
- ✅ sortsense.spec includes `pypdf` in hiddenimports

### Not Yet Verified
- ⬜ GUI live run (requires display; tested via code inspection only)
- ⬜ 12-file scenario in running app (automated test covers it; live GUI not run)
- ⬜ Ollama states 1–5 (Ollama not running at time of this report)
- ⬜ PyInstaller build and exe smoke test
- ⬜ Clean-machine test (no clean Windows VM available)
92 changes: 92 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# SortSense — Installation & Testing Instructions

## Quick Install (Windows 10/11 x64)

### Option A: Installer (recommended)
1. Download `SortSense-Setup.exe` from the [GitHub Actions artifact](https://github.com/Minnolter12/SortSense/actions)
2. Double-click to install (no admin rights needed; installs to `%LOCALAPPDATA%\Programs\SortSense`)
3. Launch from **Start Menu → SortSense** or the Desktop shortcut

### Option B: Portable ZIP
1. Download `SortSense-Portable.zip`
2. Extract anywhere (e.g. `D:\Tools\SortSense\`)
3. Run `SortSense.exe` — no installation step

---

## First Run

1. SortSense opens the Dashboard. If running for the first time, a welcome dialog appears.
2. Go to **Settings** → set your watch folder (default: `Downloads`).
3. Set your sorted output folder (default: `Documents\SortSense-Sorted`).
4. Click **Save**.
5. Drop or save a file in the watched folder — it appears in the **Review Queue** within a few seconds.

---

## User Data Location

All user data lives in `%USERPROFILE%\.sortsense\`:

```
~\.sortsense\
config.json — watched dirs, output dir, Ollama settings
rules.json — your saved organization rules
history.json — move history (for Undo)
first_run — marker file (delete to re-trigger welcome dialog)
```

**Uninstalling does NOT delete this folder.** Your rules and history survive uninstall/reinstall.

---

## Enable Optional AI (Ollama + Gemma)

> **SortSense works fully offline without this.** Only do this if you want AI-powered suggestions.

```powershell
# 1. Download and install Ollama
# https://ollama.com/download/windows (~80 MB installer)

# 2. Pull the Gemma model (~6.6 GB — only needed once)
ollama pull gemma4:e4b

# 3. (optional) verify it works
ollama run gemma4:e4b "Hello"

# 4. Restart SortSense — it detects Ollama automatically
# Dashboard badge changes to "Gemma AI Active"
```

To stop using Ollama: just stop/uninstall Ollama. SortSense falls back to deterministic mode.

---

## Multi-PC Testing Checklist

For each test machine, verify:

- [ ] Installer runs without admin rights
- [ ] App launches from Start Menu shortcut
- [ ] App launches from Desktop shortcut
- [ ] Deterministic mode: drop a PDF/TXT into watched folder → Review Queue shows proposal within 5 s
- [ ] Proposal has a content-based filename (not the opaque original name)
- [ ] Approve + Execute moves the file and shows it in History
- [ ] Undo restores the file to its original path with its original name
- [ ] Reject leaves the file untouched
- [ ] Uninstall → `~\.sortsense\` survives → Reinstall → rules/history intact
- [ ] (If Ollama installed) Dashboard shows "Gemma AI Active" after `ollama pull gemma4:e4b`
- [ ] (If Ollama not installed) Dashboard shows "Deterministic Mode"

---

## Reporting Issues

Please include:
- Windows version (`winver`)
- SortSense version (title bar or Settings page)
- Whether Ollama is installed and which model
- Steps to reproduce
- Screenshot of the Review Queue or error dialog

Open an issue at: https://github.com/Minnolter12/SortSense/issues
103 changes: 103 additions & 0 deletions RELEASE_NOTES_DRAFT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# SortSense v0.1-beta — Release Notes Draft

> **DRAFT — Awaiting author approval before publishing.**
> This is a pre-release for multi-PC testing. Do NOT publish until explicitly approved.

---

## What is SortSense?

SortSense is a **privacy-first, offline-capable** Windows desktop file organizer.
It watches your Downloads folder (or any folder you choose), analyzes each new file, and
*suggests* where it should go — without ever moving anything until *you* approve it.

**Ollama + Gemma is entirely optional.** The app is fully useful the moment you install it,
using a built-in deterministic topic engine that recognizes 12 academic and business subjects
(DBMS, DSA, OOPS, Discrete Mathematics, NLP, Machine Learning, Operating Systems, Computer
Networks, Python, Mathematics, Physics, Chemistry) plus general document types (invoices,
assignments, research papers, certificates, etc.).

---

## Features (v0.1-beta)

### Core — Available Offline, No Setup Required
- **Automatic detection** — watches a folder; new files appear in the Review Queue instantly
- **Subject classification** — weighted evidence engine; never invents a category on thin evidence
- **Content-based filenames** — proposed names come from the document itself (headings, first line)
- **Preview before anything moves** — every proposal is shown with editable name, category, destination
- **Approval-first** — files are *never* moved until you click Approve + Execute
- **Reject** — leaves the file exactly where it is
- **Partial-download protection** — `.crdownload`, `.part`, `.tmp` files are ignored until complete
- **Collision safety** — a file named the same as one already at the destination gets a numbered copy, never an overwrite
- **History & Undo** — every move is logged; Undo restores the original path and filename
- **Saved rules** — tell SortSense "invoices always go to Finance/Invoices"; rules are matched on future files

### Organization Modes
| Mode | Description |
|------|-------------|
| **AI-Directed** | Deterministic (offline) or Gemma (if Ollama installed) suggests category + folder |
| **Manual Destination** | You pick the folder; app suggests the filename |
| **Hybrid** | You set a root folder; app suggests the subfolder based on content |

### Optional: Local AI with Ollama + Gemma
- Install [Ollama](https://ollama.com) and run `ollama pull gemma4:e4b`
- SortSense detects it automatically; the status badge on the dashboard shows the honest state
- If Ollama is unavailable or the model isn't pulled, the app falls back to deterministic mode silently — no crash, no hang
- The dashboard never shows "Gemma AI Active" unless a model is truly reachable and responding

---

## Installation

### Standard Installer (Recommended)
1. Download `SortSense-Setup.exe` from the GitHub release artifacts
2. Run it — no administrator rights required (installs to `%LOCALAPPDATA%\Programs\SortSense`)
3. Launch from Start Menu or Desktop shortcut
4. On first run, choose the folder to watch (default: `%USERPROFILE%\Downloads`)

### Portable ZIP
1. Download `SortSense-Portable.zip`
2. Extract anywhere
3. Run `SortSense.exe` — no installation needed
4. Config and history are stored in `%USERPROFILE%\.sortsense` (same as the installer)

### Enable Optional AI (after installing SortSense)
```
# 1. Install Ollama from https://ollama.com/download/windows
# 2. Pull the model (6.6 GB download):
ollama pull gemma4:e4b
# 3. Restart SortSense — it detects Ollama automatically
```

---

## Known Limitations

| Limitation | Detail |
|------------|--------|
| **No OCR** | Image-only PDFs (scanned docs with no text layer) are marked as "empty" and sent to the Review Queue with the original filename. The user must categorize them manually. |
| **Unsigned executable** | Windows SmartScreen may warn "unrecognized app". Click "More info → Run anyway". This will be resolved with code signing in a future release. |
| **No clean-machine test** | The exe was built and smoke-tested on the development machine. A fresh Windows install without Python has not been tested in this release. |
| **Ollama timeout** | On slow machines, the first Gemma response may time out (default: 120 s). Increase with `SORTSENSE_OLLAMA_TIMEOUT=300` in the environment. |
| **Windows only** | The packaging (PyInstaller exe, Inno Setup installer) targets Windows 10/11 x64. Linux/macOS: run from source. |

---

## What's New Since Last Release

This is the first public pre-release. The complete change log is in [FIXES.md](FIXES.md).

**Key additions:**
- Approval-first workflow (`app/proposals.py`) — nothing moves without your click
- Weighted topic engine (`app/topics.py`) — 12 subjects, evidence-backed confidence
- pypdf fallback for PDF extraction
- 31 new automated regression tests
- 12-file opaque-name scenario (WhatsApp downloads, scan files, etc.) verified
- 5-state honest Ollama status (Deterministic / Ollama Unavailable / Model Missing / Gemma AI Active / Request Failed)
- CI: GitHub Actions builds exe on `windows-latest` and uploads as artifact

---

*Document version: draft — awaiting approval*
*Branch: `fix/sortsense-regression-restoration`*
8 changes: 8 additions & 0 deletions app/analysis_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ class DocumentAnalysis(BaseModel):
default=None,
description="Primary date associated with the document in YYYY-MM-DD or text format."
)
evidence: list[str] = Field(
default_factory=list,
description="Short human-readable reasons (evidence from the document) supporting the classification.",
)
source: str | None = Field(
default=None,
description="Which engine produced this analysis: 'gemma' or 'deterministic'. Overwritten by SortSense, not trusted from the model.",
)
Loading
Loading