diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-09 00:58:43 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-09 00:58:43 +0100 |
| commit | 00602b3ad7d613a1f575d1e5395406eb6b319c1d (patch) | |
| tree | 9a0642330f65ba9dba7a5a2cf3ac22e9ae8792f8 /docs/superpowers | |
| parent | b4075d1857cffee11362ada550327cca92ca9bb7 (diff) | |
| download | desktop-assistant-00602b3ad7d613a1f575d1e5395406eb6b319c1d.tar.gz desktop-assistant-00602b3ad7d613a1f575d1e5395406eb6b319c1d.zip | |
docs: redact tool live check
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'docs/superpowers')
| -rw-r--r-- | docs/superpowers/specs/2026-11-09-redact-tool-design.md | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/docs/superpowers/specs/2026-11-09-redact-tool-design.md b/docs/superpowers/specs/2026-11-09-redact-tool-design.md index 080d752..34d83da 100644 --- a/docs/superpowers/specs/2026-11-09-redact-tool-design.md +++ b/docs/superpowers/specs/2026-11-09-redact-tool-design.md @@ -1,6 +1,6 @@ # PII redaction tool: design -Date: 2026-11-09. Status: approved, not implemented. +Date: 2026-11-09. Status: implemented (2026-11-09). ## Goal @@ -33,8 +33,15 @@ description = "Extra strings to black out, one per line, exactly as they appear Two sources, both always applied: - **Regex**, in the script: email, phone (Italian and international - forms), IBAN, codice fiscale, card numbers (13-19 digits passing Luhn). - Dates of birth are left out: any date would match. + forms, landlines with brackets, slashes or dashes), IBAN (mod 97), card + numbers (13-19 digits passing Luhn), and any 16-character code mixing + at least 3 letters and 3 digits, which covers a codice fiscale even + when OCR misreads it. A validated match that absorbed a neighbouring + token is retried on its longest valid sub-span. Dates of birth are left + out: any date would match. +- Consecutive single-character words are joined without a space: + letter-spaced text and per-character form boxes come out one glyph per + word. Curly apostrophes match straight ones. - **Model items**: free-form PII the model saw (names, addresses). Matched case-insensitively over runs of consecutive words, so a multi-word name spanning several boxes is found. @@ -45,9 +52,17 @@ Per page: - PDF page with text: `pdftotext -bbox-layout -f N -l N`, boxes in points, scaled to the render's pixels. -- Image, or PDF page with no text (a scan): render with `pdftoppm` (images - used as is), then `tesseract <png> - -l ita+eng tsv` for word boxes in - pixels. +- Image, or PDF page with no text (a scan): render with `pdftoppm` + (images go through `magick -auto-orient` first, since `-strip` drops + the EXIF orientation), then `tesseract <png> - -l ita+eng tsv` for word + boxes in pixels. +- PDF page with text and images (`pdfimages -list`): OCR'd as well, and + OCR words whose centre falls inside a text word's box are dropped. +- Both read the CropBox (`-cropbox`): content a viewer hides outside it + would otherwise show in the output. Output page size comes from the + render, so rotated pages keep their shape. +- Multi-frame images (GIF, TIFF) are refused: tesseract reads only the + first frame. Renders use the attachment rule: 150 dpi, lowered to fit 1600 px. @@ -56,9 +71,11 @@ Renders use the attachment rule: 150 dpi, lowered to fit 1600 px. Each page rendered to PNG, `magick` draws filled black rectangles over the matched boxes (2 px pad), then: -- PDF in: pages joined with `magick` into one PDF. The result is pixels +- PDF in: the script writes the PDF itself, one lossless RGB image per + page (ImageMagick's policy forbids PDF output). The result is pixels only: no text layer, no metadata, nothing under the boxes survives. -- Image in: same format out. +- Image in: same format out, `-strip`ped of EXIF (GPS, owner). +- Nothing matched: nothing is written, and the script says so. Written as `<name>-redacted.<ext>` beside the original, `-redacted-2`, `-3`... if taken. Opened with `xdg-open`, detached, for the user to @@ -71,14 +88,17 @@ model can tell the user what was missed. ## Errors -Unreadable path, unsupported type, missing tesseract language data -(`ita`, `eng`), or a failing helper: one-line message, nothing written. +Unreadable path, unwritable folder, multi-frame image, missing +tesseract language data (`ita`, `eng`), or a failing helper: one-line +message, nothing written. An item not found is reported, not fatal. ## Daemon changes 1. **Path in the file block.** `attach()` writes - `--- file: <name> (<abs path>) ---` in every chat. The content already + `--- file: <name> (<abs path>) ---` in every chat, and images, which + had no block, get `--- image: <name> (<abs path>) ---`. A path with a + newline is left out. The content already goes to whatever model the chat uses; the path reveals less than that. 2. **Per-provider tool trust.** A tool's `cloud` is `true` (any provider) or a list of provider names. `load_tools` accepts a bool or a list of @@ -89,20 +109,25 @@ An item not found is reported, not fatal. ## Dependencies -tesseract `ita` and `eng` traineddata, not installed now -(`/usr/share/tessdata` has none). Packaging belongs in `my-slackbuilds`; -sizes are stated before anything is downloaded. +tesseract `ita` and `eng` traineddata, standard set (tessdata, 16.0 and +23.5 MB), copied by hand into `/usr/share/tessdata/` on 2026-11-09. Not +packaged. ## Check -`examples/tools/test-redact.sh`: builds a text PDF and a PNG containing a -known email, IBAN and name, runs `redact.py` with the name as an item, -and asserts that `pdftotext` of the redacted PDF finds none of them, that -pixels at the known boxes are black, and that the original is unchanged. +`redact.py --test`, like `updates.py`: the rules on word lists, then +text, cropped, rotated, mixed text-and-image and scanned PDFs, a PNG, an +EXIF-rotated JPEG and a multi-frame GIF end to end: no text layer, black +pixels at the known boxes, original unchanged, `-redacted-2` on a second +run, errors as one line. ## Ceilings - OCR that misreads a word leaves it unredacted. The viewer review is the safety net, and the reply says what was not found. - A redacted PDF has no selectable text, by design. +- Kerned or diagonal text, and words broken at a line end (`Ros-`/`si`), + are not matched. +- OCR misreads also stop a model item from matching; it comes back as + not found. - The model decides the free-form items; a 12B model can miss some. |
