Skip to content
Open
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ TESTS.txt
TESTERGEBNISSE.txt
BUGREPORT.md
DIAGNOSE_REPORT.md
SKILL.md

# ---- Sensible Daten ----
_USER/
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ Format basiert auf [Keep a Changelog](https://keepachangelog.com/de/1.1.0/).

## [Unreleased]

### High-End Refactoring: UI-freier Domänenkern `export_core.py`, sprachunabhängiger `QueryBuilderDialog`, Policy P-022 & Size-Pre-Bucketed Deduplizierung (2026-12-06)
- **UI-freier Domänenkern & Export-Schema-Kanonisierung (`export_core.py`, `TW-UDG-05`):**
- Duplizierte Pfad-, Redaktions-, Gerätenamen-, SHA-256-Hash-, Kategorie- und Export-Logik aus `UniversalDocsGrabberV1.py` und `cli.py` in das `PySide6`-freie Kernmodul `export_core.py` extrahiert.
- Kanonisches Export-Schema über Desktop-GUI, Headless-CLI und `EXPORTFORMAT.md` auf `schema = "docsgrabber-library"` (`schema_version = "1.0"`) mit strukturierten Kategoriefeldern (`name`, `source`, `sources`, `profile_names`, `rule_count`, `document_count`) vereinheitlicht (`web_companion/library.js` behält Rückwärtskompatibilität für `docsgrabber-library-v1`).
- Schutz reservierter Windows-Gerätenamen um `CONIN$`, `CONOUT$`, `COM0`, `LPT0` sowie hochgestellte Varianten (`COM¹`..`COM³`, `LPT¹`..`LPT³`) erweitert; SHA-256-Lesepuffer auf 64 KiB angehoben.
- **Sprachunabhängiger `QueryBuilderDialog` & PySide6-`QDate`-Crashfix (`TW-UDG-04`):**
- `QueryBuilderDialog.toggle_dates()` und `QueryBuilderDialog.generate()` von deutschen `currentText()`-Vergleichen auf sprachunabhängige Indizes (`0..3`) umgestellt, automatischen `d_from > d_to` Swap-Guard ergänzt und einen PySide6-Absturz (`QDate.toPyDate` -> `_qdate_to_pydate` via `toPython()`) bei benutzerdefinierten Datumsbereichen behoben.
- Alle `QueryBuilderDialog`- und `max_emails_per_run`-Oberflächentexte über sämtliche 6 Tier-2-Sprachen (`de`, `en`, `es`, `zh`, `ja`, `ru`) in `locales/translations.json` (232 Schlüssel, 100 % Parität) lokalisiert.
- **Policy P-022 Artefakte & konfigurierbare IMAP-UID-Fensterung (`TW-UDG-06`):**
- `SKILL.md` und `llm.txt` für Dual-Use-Bedienung durch Mensch und KI-Agenten ergänzt; `llms.txt` nachgezogen.
- `DownloadSettings.max_emails_per_run` (`30` Standard für volle Rückwärtskompatibilität, `0` = unbegrenzt / alle passenden UIDs) in Datenmodell, `MainWindow`-Einstellungen, `ProfileDialog`-Override, `GrabberWorker.process_profile()`, `cli.load_data()` und Companion-Export integriert.
- **Performance- & Integritäts-Härtung in `GrabberWorker`:**
- `run_deduplication()` gruppiert reguläre Nicht-Symlink-Dateien vorab nach Dateigröße (`st_size`), überspringt Einzelgrößen ohne Disk-Read, schützt `.tmp_`- und `protected_paths`-Dateien und räumt bei Duplikaten deterministisch bereits in `self.db` indizierten Dokumenten Vorrang ein.
- `add_db()` nutzt einen $O(1)$-Pfadindex (`self._db_paths`) statt linearer Suche über `self.db`.
- **Pytest-CWD-Unabhängigkeit & Packaging (`T-20261114-932985855`):**
- Relatives `--basetemp=.pytest_temp` aus `pyproject.toml` entfernt und CWD-sicher in `conftest.py` (`config.rootpath / ".pytest_temp"`) verankert; `[tool.setuptools] py-modules` und `UniversalDocsGrabber.spec` um `export_core` und `locales` ergänzt.

### Laufzeit-/Vertragstests, lokalisierter Zeitfilter & Web-Companion Schema-Kompatibilität (2026-11-23)
- **Neue Testsuite `tests/test_runtime_and_companion_contracts.py` (11 Tests) & Erweiterung `web_companion/tests/library.test.mjs` (+2 Tests):**
- Deckt `MainWindow.run_all()` über alle 6 UI-Sprachen, Scheduler-Persistenz (`_save_scheduler`/`_apply_scheduler`) und Tick-Verhalten (`_on_scheduler_tick`), `GrabberWorker` (Account-Gruppierung, Inaktivitäts-Skip, Deduplizierung, Interrupts), Gmail-Fallback + 30-UID-Limit, `UniversalConverter.convert_to_pdf()`, `app_icon_loader`, CLI `list-documents --category --limit=0` sowie Python->Node.js-Exportverträge ab.
Expand Down
15 changes: 12 additions & 3 deletions EXPORTFORMAT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Exportformat `docsgrabber-library-v1.json`

Stand: 2026-08-12
Stand: 2026-12-06

Dieses Dokument beschreibt den umgesetzten Austauschvertrag für Desktop, Web/PWA
und spätere Plattform-Smokes. Das Format ist bewusst redigiert: Es transportiert
Expand Down Expand Up @@ -66,11 +66,20 @@ autoritative Vollversion für IMAP, OCR, Konvertierung und Dateisystemzugriff.
## Aktuell exportierte Felder

- `accounts`: redigierte `account-<hash>`-Referenzen plus Anzahl verknüpfter Profile
- `profiles`: ID, Name, Gruppe, Aktiv-Status, `account_ref`, Zielordner, Filter und effektive Download-/Auto-Kategorisierungs-Einstellungen
- `categories`: zusammengeführt aus globalen Regeln, Profil-Overrides und erkannten Dokumentpfaden
- `profiles`: ID, Name, Gruppe, Aktiv-Status, `account_ref`, Zielordner, Filter und effektive Download-/Auto-Kategorisierungs-Einstellungen (inkl. `max_emails_per_run`, `0` = unbegrenzt)
- `categories`: zusammengeführt aus globalen Regeln, Profil-Overrides und erkannten Dokumentpfaden (`name`, `source`, `sources`, `profile_names`, `rule_count`, `document_count`)
- `documents`: Profilname, Dateiname, Datum, Typ, Kategorie, `path_hint`, Status und optionale SHA-256 bei vorhandener lokaler Datei
- `run_summary`: Anzahl exportierter Profile/Dokumente, aktiver Profile, Scheduler-Intervall und Profilstatistiken

## Gemeinsamer Domänenkern (`export_core.py`)

Sowohl die Desktop-App (`UniversalDocsGrabberV1.py`) als auch die Headless-CLI
(`cli.py --export-library`) nutzen das UI-freie Modul `export_core.py` und erzeugen
identisch das kanonische Schema `"schema": "docsgrabber-library"` mit
`"schema_version": "1.0"`. Der Web/PWA-Companion (`web_companion/library.js`)
akzeptiert zur Rückwärtskompatibilität weiterhin auch ältere Dateien mit
`"docsgrabber-library-v1"` (`1.x`).

## Desktop-Auslöser

Der Export wird direkt in der Desktop-App über
Expand Down
88 changes: 88 additions & 0 deletions SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
name: universaldocsgrabber
description: Local-first desktop and headless CLI tool for IMAP/Gmail attachment harvesting, PDF conversion, OCR, SHA-256 deduplication, and redacted Web/PWA library exports.
---

# UniversalDocsGrabber — Agent & Automation Skill (Policy P-022)

`UniversalDocsGrabber` (`doc-bricks/UniversalDocsGrabber`, v1.1.7) provides dual-use access for human operators (PySide6 desktop GUI + offline Web/PWA companion) and AI agents / automation pipelines (`cli.py` + UI-free `export_core.py`) with zero cloud egress.

## Architecture & Entry Surfaces

- **Headless CLI (`cli.py`):** Display-free JSON/text inspection, redacted companion export (`docsgrabber-library` `1.0`), CSV export with CWE-1236 formula-injection protection, and stack diagnostics.
- **UI-Free Domain Core (`export_core.py`):** Pure-Python path sanitization, Windows/DOS device-name protection, buffered SHA-256 hashing, category inference, and redacted payload assembly without `PySide6`.
- **Desktop GUI (`UniversalDocsGrabberV1.py`):** PySide6 application with OS Keyring credential storage (`keyring`), IMAP `UTF8=ACCEPT` / `X-GM-RAW` search, configurable `max_emails_per_run` (`30` default, `0` = unlimited), OCR (`pytesseract` + `pdf2image`), and 6-language UI (`de`, `en`, `es`, `zh`, `ja`, `ru`).
- **Offline Web/PWA Companion (`web_companion/`):** Static zero-dependency browser viewer reading redacted `docsgrabber-library-v1.json` exports locally.

## Headless CLI Usage (`--json` Recommended for Agents)

Always pass `--json` when invoking `cli.py` from an agent or automation script so stdout emits deterministic UTF-8 JSON without interactive dialogs:

```bash
# Version inquiry
python cli.py --version

# Runtime stack & storage writability diagnostics
python cli.py --diagnose --json

# List configured search profiles or masked IMAP accounts
python cli.py --list-profiles --json
python cli.py --list-accounts --json

# Query indexed documents (supports --profile, --category, and --limit 0 for all)
python cli.py --list-documents --profile "Rechnungen" --category "Steuer" --limit 0 --json

# Generate redacted Web/PWA companion export (schema: docsgrabber-library 1.0)
python cli.py --export-library ./docsgrabber-library-v1.json --json

# Export document index as UTF-8-BOM semicolon CSV (formula-injection safe)
python cli.py --export-csv ./documents_export.csv --json
```

### Custom Multi-Tenant / Test Paths

Override the default runtime directory (`~/.univ_docs_grabber/`) explicitly via:
- `--config <path/to/config_v1.json>`
- `--documents-db <path/to/documents.json>`

### CLI Exit Codes

- `0` — Command succeeded (or `--diagnose` confirmed core stack + storage writability ready).
- `1` — Export failed due to OS I/O error or `atomic_io` protected-path guard (`PermissionError`), or `--diagnose` detected missing core components / unwritable storage.
- `2` — Invalid CLI flags or mutually exclusive action conflict (`argparse`).

## Non-Goals & Current CLI Boundaries

- **No Headless Live IMAP Fetch in `cli.py` (v1.1.7):** Live IMAP connection, credential retrieval from OS Keyring, attachment downloading, and OCR execution currently run through the desktop application (`UniversalDocsGrabberV1.py`, manual Start or built-in scheduler). Extracting a `QThread`-free `imap_core.py` for `cli.py --run-profiles` is tracked as follow-up `TW-UDG-07`.
- **One-Way Redacted Companion Export:** `web_companion/` is a read-only local viewer; there is no cloud sync and no write-back import into `config_v1.json` or `documents.json`.

## Python API (`export_core.py`)

Agents and downstream Python tools that do not need Qt can import `export_core` directly:

```python
from pathlib import Path
import export_core

payload = export_core.build_library_export_payload(
profiles=profiles,
accounts=accounts,
documents=documents,
global_settings=global_settings,
base_path=Path("./Downloads/UnivDocs"),
scheduler_interval=30,
)
```

## Safety & Governance Invariants

1. **Zero Cloud Egress (`INV-LOCAL-01`):** Never transmit documents, mail bodies, or account credentials to external APIs.
2. **Credential Protection (`INV-CRED-03` & `INV-REDACT-04`):** Passwords reside in OS Keyring; `--list-accounts` masks passwords (`***MASKED***`), and `--export-library` emits hashed `account-<sha256[:12]>` references only.
3. **Atomic Path-Protected Writes:** Internal files (`config_v1.json`, `documents.json`, `token.json`) and transient `.tmp` / `.temp.pdf` artifacts are guarded by `atomic_io` and excluded from deduplication.
4. **Configurable UID Windowing:** `DownloadSettings.max_emails_per_run` defaults to `30` (`0` = process all matching UIDs without cap).

## Further Documentation

- Machine-readable repository summary & invariants: [llms.txt](llms.txt) (pointer: [llm.txt](llm.txt))
- Redacted Web/PWA export specification: [EXPORTFORMAT.md](EXPORTFORMAT.md)
- Full user & architecture documentation: [README.md](README.md) / [README-DE.md](README-DE.md)
5 changes: 5 additions & 0 deletions UniversalDocsGrabber.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ a = Analysis(
binaries=[],
datas=[
('assets', 'assets'),
('locales', 'locales'),
('app_icon_loader.py', '.'),
('export_core.py', '.'),
('SKILL.md', '.'),
('llms.txt', '.'),
('llm.txt', '.'),
],
hiddenimports=[
'PySide6.QtWidgets',
Expand Down
Loading
Loading