diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-09 00:06:56 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-09 00:06:56 +0100 |
| commit | 08e1265f7df43b6e600559b55b7bc0394f1ebbb4 (patch) | |
| tree | 66e784b78dfd53203d6ef5dace009b371a031f8c | |
| parent | eb85087d1a0874bbccc0bdedc3395433416d6266 (diff) | |
| download | desktop-assistant-08e1265f7df43b6e600559b55b7bc0394f1ebbb4.tar.gz desktop-assistant-08e1265f7df43b6e600559b55b7bc0394f1ebbb4.zip | |
docs: redact tool design
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| -rw-r--r-- | docs/superpowers/specs/2026-11-09-redact-tool-design.md | 108 |
1 files changed, 108 insertions, 0 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 new file mode 100644 index 0000000..080d752 --- /dev/null +++ b/docs/superpowers/specs/2026-11-09-redact-tool-design.md @@ -0,0 +1,108 @@ +# PII redaction tool: design + +Date: 2026-11-09. Status: approved, not implemented. + +## Goal + +Ask the assistant to black out personal data in an attached PDF or image +and get a redacted copy beside the original. The original is never +touched. Text PDFs, scanned PDFs and images are all handled. + +## Tool + +`examples/tools/redact.toml` and `examples/tools/redact.py` (stdlib only, +like `updates.py`), installed to `~/.config/desktop-assistant/tools/`. + +```toml +description = "Redact personal data (PII) from a PDF or image: writes a copy with black boxes, '<name>-redacted.<ext>' beside the original, and opens it for the user to check. Emails, phone numbers, IBANs, codici fiscali and card numbers are always found. Pass in items every other piece of personal data you see in the document: names, addresses, account or document numbers, exactly as written there. The original is not changed." +command = ["redact.py", "{path}", "{items}"] +cloud = ["hetzner"] +timeout = 120 + +[params.path] +type = "string" +description = "Absolute path of the attached file, as shown in its file block." + +[params.items] +type = "string" +description = "Extra strings to black out, one per line, exactly as they appear in the document. Empty if none." +``` + +## Detection + +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. +- **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. + +## Word boxes + +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. + +Renders use the attachment rule: 150 dpi, lowered to fit 1600 px. + +## Output + +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 + only: no text layer, no metadata, nothing under the boxes survives. +- Image in: same format out. + +Written as `<name>-redacted.<ext>` beside the original, `-redacted-2`, +`-3`... if taken. Opened with `xdg-open`, detached, for the user to +review every page. + +The script prints counts per kind and pages touched, for example +`redacted 7 on 3 pages: 2 email, 1 iban, 4 items. Not found: "Via Roma 3"`. +Matched values are never printed; items that were not found are, so the +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. +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 + 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 + strings. In `answer()`, a cloud chat is offered a tool when its `cloud` + is `true` or contains the chat's provider (the part of the model id + before `:`). `redact` lists only `hetzner`, a no-retention provider: a + provider added later gets nothing until named. + +## 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. + +## 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. + +## 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. +- The model decides the free-form items; a 12B model can miss some. |
