Skip to content
BaruchEricPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

scan-it

Open-source ScanSnap iX500 document-scanning stack for macOS: SANE-driven bash CLIs that turn ADF paper stacks into dated, ordered PDFs over USB — built because Fujitsu/PFU dropped ScanSnap Manager on modern macOS.

TL;DR

  • What: Restores a full scan-to-PDF workflow for the Fujitsu ScanSnap iX500 on current macOS using only open-source software, over USB.
  • How: SANE's scanimage drives the scanner; the CLI tools in bin/ handle acquisition, PDF assembly, check normalization, and manifest-driven filing.
  • Stack: bash · SANE/sane-backends · img2pdf + qpdf · ImageMagick + poppler · jq · optional ocrmypdf · NAPS2 (GUI). No build step. bun runs the live dashboard; its package.json only holds dev tooling and task shortcuts.
  • Install: symlink bin/* onto your PATH (they already live in ~/bin on this machine).
  • Run it: scan-batch scans a mixed stack into local staging; Claude classifies each sheet and writes a manifest; batch-file files every document into the Google Drive filing root ~/My Drive/scans/<entity>/<type>/[<YYYY>/].
  • Read side: scan-catalog merges the sidecars into a catalog, lists open follow-ups (Drive copies, QuickBooks attachments, reminders, medical records), and renders the HTML dashboards.
  • Live dashboard: scan-catalog serve runs a local server on http://127.0.0.1:7820/ with scanner status, batches in progress, and buttons that run the tools (scan, stop, resume, file, diagnose, restart the Brother services).
  • Auto-scan: with the Brother card's Auto-scan switch on, the server watches the paper sensor and starts scan-batch itself when paper lands. See "Auto-scan".
  • Run and deploy: bun run dev serves the dashboard with mock scanners on http://127.0.0.1:7830/ and restarts on edits; bun run deploy puts this checkout live at https://scans.beric.ca and on the tailnet. See "Run locally and deploy".
  • Diagnose: scan-diag runs every dependency check and prints pass/fail with a fix hint per failure.
  • Where it runs (since 2026-11-09): the Brother is on USB at the Proxmox host pve, and scan-it runs in CT 150 scan-it there. See "Scan host: CT 150 on pve". The macOS path below still works on a Mac with the scanner attached.

Scan host: CT 150 on pve

Brother ADS-4300N ──USB──> pve (192.168.1.12): ipp-usb, eSCL on localhost:60000 (loopback only)
   ──ssh -L (scan-it-escl.service)──> CT 150 scan-it (192.168.1.71, Orbi reservation): localhost:60000
CT 150: scan-it-dashboard (127.0.0.1:7820 main, :7821 edge), user eric, ~/scan-it
   ──ssh -R (scan-it-tunnel)──> mini 127.0.0.1:7822 <── tailscale serve :8445
                               mini 127.0.0.1:7823 <── beric-mini Cloudflare tunnel <── scans.beric.ca
CT 150 ~/My Drive ──scan-mirror (rsync)──> NAS Backups/scan-it/mirror ──push (rclone)──> Google Drive
  • Container: Debian 13, unprivileged, 2 cores, 2 GB, 32 GB on ssd-thin, starts at boot. Packages: img2pdf, qpdf, imagemagick, poppler-utils, jq, ocrmypdf + tesseract, libjpeg-turbo-progs, bats, rsync, bun 1.4.4 in /usr/local/bin.
  • Settings: ~/.config/scan-it/env (plain KEY=value; the user units load it, and ~/.profile and ~/.bashrc export it): ESCL_SCAN_ENDPOINT=http://localhost:60000/eSCL, SCAN_SCANNER_HOST=root@192.168.1.12, SCAN_TUNNEL_FREE=command, SCAN_MIRROR_HOST=nas-scan-it.
  • Units: scan-it-escl.service (system, runs as eric) holds the eSCL forward. scan-it-dashboard.service and scan-it-tunnel.service are user units written by scan-catalog serve --install; linger keeps them up. Logs: journalctl --user -u scan-it-dashboard.
  • Keys: CT 150's eric key is pinned to a forced command at each end. On pve (/usr/local/sbin/scan-it-host) it runs status and restart for ipp-usb and may forward only to localhost:60000. On the mini (~/.local/bin/scan-it-tunnel-gate) it may listen only on 127.0.0.1:7822 and :7823, and its one command frees those ports. On the NAS (Backups/scan-it/receiver.sh, source in this repo at nas/receiver.sh) it uploads into mirror/ by rsync (no delete, no download), runs push and status, and runs queue-prune, which may remove only batch-YYYYMMDD-HHMMSS.pdf files in mirror/scans/_queue. All three accept it only from 192.168.1.0/24.
  • ipp-usb needs Host: localhost: a request to 127.0.0.1:60000 gets a 302 to localhost.
  • Filing root: local, ~/My Drive/scans, so the defaults need no SCAN_ROOT. Drive gets a copy through scan-mirror: rsync to the NAS, then the NAS's push runs rclone copy into the gdrive-scans remote. Neither step deletes, so a file moved or removed here stays where it was in Drive. The one exception is scans/_queue/: queue-prune drops the previews scan-it no longer queues, and push runs rclone sync on that folder alone, so a filed or discarded batch leaves Drive's _queue/ (into Drive's trash) on the next run. push refuses until Backups/scan-it/imported exists on the NAS, because the first push would replace Drive's dashboard.html files with a catalog missing everything filed before the move.
  • Not on Linux: Show in Finder and Open scans folder (hidden), and the Push Scan Tool checks (scan-diag and the dashboard check ipp-usb on pve instead). Restart on the Brother card restarts ipp-usb on pve.

Overview

Fujitsu/PFU discontinued ScanSnap Manager support on recent macOS, leaving the iX500 without vendor software. scan-it replaces it entirely with the open-source SANE stack plus a set of small, composable bash tools. There is no application to run — the tools are ordinary CLIs you invoke against a stack of paper in the automatic document feeder (ADF).

Three workflows are supported:

  1. Plain documents — scan2pdf acquires an ADF stack into one dated multi-page PDF.
  2. Paychecks — scan-checks / checks-split / checks-normalize / checks-report produce one uniform, check-number-ordered PDF per paydate, capturing front + endorsement back.
  3. Mixed batches — scan-batch continuously scans a heterogeneous stack into per-page images; a reader (Claude) classifies each page and writes a JSON manifest; batch-file validates it and files every document into typed folders with JSON sidecars.

A GUI path (NAPS2) is also documented for point-and-click scanning.

Tech stack

  • bash — every tool except scan-organize (python3 stdlib), set -euo pipefail. No compiled code, no dependencies bundled.
  • bun — runs share/server.ts, the live dashboard server behind scan-catalog serve. Only that command needs it. bun install adds typescript and @types/bun for bun run typecheck (strict); nothing at runtime depends on them.
  • SANE / sane-backends — scanimage (acquisition) and sane-find-scanner (probe); the fujitsu backend drives the iX500 over USB.
  • img2pdf — assemble page images into PDFs (the primary assembler).
  • qpdf — page-level PDF merge / split / append without re-encoding existing pages.
  • ImageMagick (magick) — check normalization: guarded backing trim, deskew, rotate portrait backs to landscape.
  • poppler (pdftoppm) — render PDF pages back to images for the normalization pass.
  • jq — parse and validate the JSON manifests that drive batch-file and checks-split.
  • ocrmypdf — optional searchable text layer on filed PDFs (filing works without it).
  • ghostscript (gs) — optional, and installed with ocrmypdf: the 200 dpi rendering batch-file writes when a Drive copy is over SCAN_COPY_MAX_MB. Without it the copy goes out full size and the sidecar says so.
  • NAPS2 (/Applications/NAPS2.app) — GUI scanning via the SANE driver.
  • bats — dev-only test suites under test/ (not required to run the tools).

All runtime dependencies are CLI tools installed via Homebrew; the repo itself ships only bash scripts.

Getting started

1. Install dependencies

brew install sane-backends img2pdf qpdf imagemagick poppler jq
brew install ocrmypdf          # optional: searchable text layer on filed PDFs
brew install --cask naps2      # optional: GUI scanning path

Ensure the fujitsu backend is enabled in SANE:

grep -n fujitsu "$(brew --prefix)/etc/sane.d/dll.conf"   # must exist, uncommented

2. Install the tools

There is no installer — the tools are symlinked from bin/ onto your PATH:

mkdir -p ~/bin
for f in "$PWD"/bin/*; do ln -sf "$f" ~/bin/; done   # ensure ~/bin is on PATH

3. Verify the stack

scan-diag        # USB presence, toolchain, SANE probe, backend, conflicting software

Green across the board means you're ready. See TROUBLESHOOTING.md for any failure, and ENVIRONMENT.md for the recorded machine/scanner baseline.

4. Scan

scan-batch                            # → ~/.cache/scan-it/batches/batch-<ts>/ (local staging)
                                      #   and, once it ends, ~/My Drive/scans/_queue/batch-<ts>.pdf
batch-file <staging-dir>              # → ~/My Drive/scans/<entity>/<type>/...
scan2pdf taxes                        # raw one-off → ~/My Drive/scans/_inbox/taxes-<ts>.pdf

Configuration

  • Filing root: SCAN_ROOT, default ~/My Drive/scans (Google Drive). Layout: <entity>/<type-folder>/[<YYYY>/]<name>.pdf plus a .json sidecar; year folders for receipts, invoices, statements, taxes (tax year) and paychecks. Also _queue/ (a 150 dpi preview PDF of every batch scanned but not filed yet, plus queue.json; see scan-queue), _review/, _index/<user>@<host>.jsonl (one append-only log per filer, so two machines never write one file), _inbox/ (raw scan2pdf output), _originals/ (scan-organize sources), and dashboard.html at the root and in each entity folder.
  • Staging: SCAN_STAGING, default ~/.cache/scan-it/batches. Page JPEGs stay off Drive.
  • Registries in the filing root: entities.json (slug, legal name, kind, aliases, notes, "quickbooks": true, and "copies": {"tax": "8328 De Soto Ave/Tax/{year}/Tax Supporting Docs"} paths relative to the Drive root, SCAN_DRIVE_ROOT, default the filing root's parent) and profiles.json (users with login accounts, scanners, and per user+scanner profiles carrying a default_entity).
  • Scan defaults: duplex, color, 300 dpi; flip with -s (simplex), -g (gray), -r N (dpi).
  • scan-batch env vars: SCAN_BATCH_SCANIMAGE (path to scanimage), SCAN_BATCH_POLL_SECS (paper-sensor poll interval, default 2), plus --idle N (end batch after N idle seconds, default 60).
  • Live server: scan-catalog serve --install keeps it running at login as the LaunchAgent ca.beric.scan-it-dashboard (log ~/Library/Logs/scan-it-dashboard.log; --uninstall removes it and the tunnel agent). For other devices see "Reaching it from other devices" below; bun run deploy installs it with every flag that needs. Run by hand: scan-catalog serve --port N (default 7820), --no-open, --mock (or SCAN_SERVE_MOCK=1: simulated scanners, batches and jobs). It honors SCAN_ROOT, SCAN_STAGING, SCAN_DASHBOARD_TEMPLATE, SCAN_BATCH_ESCL and SCAN_BATCH_SCANIMAGE. Job logs go to <staging>/.logs/, page thumbnails to <staging>/.thumbs/.
  • Auto-scan: settings live in ~/.config/scan-it/auto.json (SCAN_AUTO_FILE), one entry per scanner slug: {"brother": {"enabled": true, "user": "eric", "duplex": true, "gray": false, "idle": 60}}. The server reads the file on every look, so a hand edit needs no restart. SCAN_AUTO_POLL_SECS (default 3) is how often it reads the paper sensor.
  • Who and what: scan-batch --user <slug> (or SCAN_USER, or an account match in profiles.json) and the detected scanner go into batch.json and from there into every sidecar.

Scripts / commands

All live in bin/ and are symlinked onto PATH.

Tool What it does
scan2pdf Scan an ADF stack to a dated multi-page PDF. Duplex/color/300 dpi by default; -s simplex, -g gray, -r N dpi, -o DIR outdir, -p lossless PNG intermediates, -k keep page images, -x ARG pass-through to scanimage, --open opens the PDF. Exit codes: 0 success · 1 no scanner · 2 empty ADF · 3 PDF assembly failure.
scan-checks Scan employee paychecks duplex (front + endorsement back) into one PDF per paydate (checksYYYYMMDD.pdf), pages in check-number order. Wraps scan2pdf; re-running a paydate appends, --replace starts over, --staging scans an unsorted stack for the manifest workflow.
checks-split Split a duplex staging PDF into per-paydate PDFs from a manifest (front/back page, check number, date, rotations), sorted by check number and validated before writing. Normalizes each check individually before assembly, so output pages are already uniform; appends to existing paydate PDFs without re-encoding their pages.
checks-normalize Make check pages uniform: guarded scanner-backing trim (border must read as backing, box must be sheet-sized, crop must remove ≥15%), deskew, rotate portrait backs to landscape (bank-image convention). --page <in> <out.jpg> <front|back> normalizes one rendered page (used by checks-split); PDF mode rebuilds an existing PDF in place, passing already-normalized pages through untouched so re-runs are stable.
checks-report Per-paydate summary from a data file (<check_number> <paydate> <amount> <signed>): check counts, number sequences, missing numbers, period totals, unsigned checks, grand total. -o FILE also writes the report to a file.
scan-diag Diagnostics for the iX500 + SANE stack — colored pass/fail summary with a fix hint per failure. Read-only; safe to run any time.
scan-batch Continuously scan a heterogeneous stack in chunks (paper sensor auto-resumes between chunks; press Enter or wait for --idle seconds to end). Pages accumulate as per-page JPEGs in a timestamped staging dir. batch.json records why the run ended (ended). --auto-started is what the dashboard's auto-scan passes: batch.json then carries "auto": true, meaning nobody chose the user. Exit codes: 0 success · 1 no scanner / device lost / jam · 2 no pages · 64 usage · 66 bad --resume dir · 130 interrupted.
batch-file Validate, rotate, merge, rename, and file the staged pages produced by scan-batch, driven by <staging>/manifest.json. Writes nothing unless every scanned page is accounted for exactly once and every document has an entity. Files entity first, writes sidecars (fields, OCR text, scanner/user provenance, follow-ups), runs the Drive copies entities.json maps (a copy over SCAN_COPY_MAX_MB, default 50, goes out as a 200 dpi rendering, because MedicalRecords is a git repo and GitHub refuses files over 100 MB; the filed PDF is never changed; 0 never downsamples), writes paydate check reports, appends the per-filer index, refreshes the dashboards. --no-text-layer, --no-dashboard, --keep-staging, --drive-root DIR, -o DIR. Exit codes: 0 success · 1 validation failure · 2 assembly failure · 64 usage · 66 not a staging dir.
scan-catalog Read side of the filing tree. build [--entity SLUG] prints the merged catalog (no OCR text); pending [WORKFLOW] [--json] lists open follow-ups (copy, quickbooks, calendar, vault, check_report); mark <file> <workflow> <status> records an outcome in the sidecar; dashboard [--open] renders share/dashboard.html into the root and each entity folder; serve [--port N] [--no-open] [--mock] [--public-url URL --allow-login LOGINS] [--edge-url URL --edge-allow EMAILS [--edge-port N]] runs the live dashboard (see below).
scan-tunnel scan-tunnel HOST [LOCAL[:REMOTE]]...: reverse SSH tunnels that put the live dashboard's listeners on HOST's loopback, for tailscale serve or a Cloudflare tunnel there. Frees ports a dead session still holds (SCAN_TUNNEL_FREE=command when HOST pins the key to a forced command), then runs ssh -N -R in the foreground. scan-catalog serve --install --tunnel HOST [--tunnel-map L:R]... keeps it running.
scan-mirror Copy the local filing tree to Google Drive through the NAS: scan-queue sync, rsync to its mirror, queue-prune, then its push (rclone copy, plus rclone sync of scans/_queue). Deletes nothing outside _queue/. --rsync-only, --status. Needs SCAN_MIRROR_HOST.
scan-queue Keep <root>/_queue/ in step with staging: sync writes a 150 dpi preview PDF (SCAN_QUEUE_DPI) for every staged batch whose scanning has ended, drops the previews of filed and discarded batches, rewrites queue.json and refreshes the dashboards. list [--json] prints the queue, also from Drive's copy on the Mac. kick starts scan-it-mirror.service without waiting; scan-batch and batch-file call it when they finish, and so does the dashboard's Discard. SCAN_QUEUE_KICK=0 turns kicks off.
scan-organize Split an already-scanned PDF into per-document PDFs from a plan JSON (python3 stdlib); moves the source into _originals/.
escl-scan Direct eSCL client for the Brother ADS-4300N through the Push Scan Tool's localhost bridge. Runs jpeg-check --repair on each page as it lands and lists damaged pages in <outdir>/.damaged (ESCL_SCAN_CHECK=0 turns that off).
jpeg-check jpeg-check [--repair] FILE... (bun). Reads a scanner JPEG's restart markers without decoding: ok; truncated (the paper ended before the requested height, which the Brother still declares; --repair crops it losslessly with jpegtran); damaged (the marker sequence skips, so rows are missing mid-page: rescan); unknown (no markers, left alone). Exit codes: 0 nothing damaged · 4 a damaged file · 1 unreadable or crop failed · 64 usage.

Paycheck workflow

Mixed / unsorted stack (the usual case):

scan-checks --staging                 # any order, orientation, or side
# A reader writes a manifest, one line per check:
#   <front_page> <back_page> <check_number> <YYYYMMDD> <front_rot> <back_rot>
checks-split <staging.pdf> <manifest> # → checksYYYYMMDD.pdf per paydate, each check normalized

Single known paydate, pre-sorted stack:

scan-checks 2026-06-05                # → checks20260605.pdf directly
checks-normalize checks20260605.pdf   # raw (never-split) scans still need this pass

The sort is physical: stack checks face up, lowest number on top, then flip the whole stack face-down into the feeder, top edge first (the iX500 feeds from the bottom).

Mixed-batch workflow

scan-batch                            # feed in chunks; auto-resumes; Enter / idle ends it
# A reader classifies each page and writes <staging>/manifest.json
batch-file <staging-dir>              # validates, files each document, refuses on any gap

Output lands under ~/My Drive/scans/<entity>/ in typed folders (receipts/, invoices/, contracts/, statements/, letters/, medical/, taxes/, misc/, paychecks/), year folders where the type has one, review items in _review/. Each PDF has a .json sidecar (OCR text, extracted fields, scanner/user provenance, follow-ups). Then scan-catalog pending lists the follow-ups and scan-catalog dashboard renders the dashboards.

GUI: NAPS2

/Applications/NAPS2.app. One-time profile: Profiles → New Profile → Driver SANE → device ScanSnap iX500 → ADF Duplex, 300 dpi, Color → save as default. Then stack → Scan → Save PDF.

Architecture

Each tool is a self-contained bash script (set -euo pipefail) that shells out to the CLI stack — nothing is imported or linked. Data flows in one direction:

paper → scanimage (SANE) → page images → img2pdf/qpdf → PDF
                                    ↘ (checks)  pdftoppm → magick normalize → qpdf assemble
                                    ↘ (batch)   staging dir → manifest.json (jq) → batch-file → typed folders + sidecars
  • Deterministic vs. judgement. The bash tools do only deterministic work — acquisition, geometry, PDF assembly, validation, filing. Anything requiring reading a page (which paydate a check belongs to, what type a mixed-batch page is) is delegated to a reader that emits a JSON manifest; the tools never guess. batch-file and checks-split refuse to write unless the manifest fully accounts for every scanned page.
  • Guarded transforms. checks-normalize only ever removes backing/edge fuzz, never content: trims run under multiple guards (border must read as gray backing, box sheet-sized, crop ≥15%, edge cleanup keeps ≥97% of both dimensions), and pages with nothing to trim pass through untouched — so re-runs are idempotent.
  • Device discovery. The SANE device name embeds the scanner's serial; tools auto-discover it via scanimage -L on each run, so a changed serial only matters for hand-typed commands.
  • State on disk. No database — filing state is the filesystem: typed folders, per-document .json sidecars, entities.json, and an append-only index.jsonl.

Live dashboard server

share/server.ts (bun, no dependencies) serves the dashboard template with the catalog and a live config injected, and adds a JSON API the page polls:

  • GET /api/status: scanners (eSCL ScannerStatus via escl-scan --status and pgrep of the Brother services; scanimage -L and -A for the iX500; ioreg for USB presence; cached 5 s, skipped for a scanner mid-batch), staged batches with their state and allowed actions, and jobs.
  • The static dashboards list the batches in _queue/ under "Waiting to be filed", each linking its preview. The live page leaves that group out, since its batch list shows the same batches with their buttons.
  • Batch state comes from the staging dir: a live .pid means scanning (.stop present: stopping), else .filed means filed, else manifest.json means ready, else staged.
  • "Copy Claude prompt" puts a prompt naming the batch's staging dir on the clipboard; the server never classifies paper. With two or more batches staged ("Needs analysis"), "Copy Claude prompt for all N" in the section header names every one of them, so Claude analyzes the pile in one review and still writes one manifest per batch.
  • POST /api/scan, /api/batches/<id>/{stop,resume,file,discard,reveal}, /api/diag, /api/brother/restart, /api/dashboard/refresh start the matching tool as a detached job. The server checks each action against the batch state first, and allows one Brother restart at a time (Diagnose waits for it too). Discard moves the staging dir to ~/.Trash.
  • POST /api/auto with {"scanner": "brother", "enabled": true} switches auto-scan on or off. user, duplex, gray and idle in the same body set what its batches use; a field left out keeps its value.
  • GET /files/<path> serves PDFs from the filing root only; GET /api/batches/<id>/thumb/<n> serves a sips thumbnail.
  • Local only: it binds 127.0.0.1, refuses other Host headers (DNS rebinding) and cross-origin POSTs, and every POST must carry the per-launch token the page embeds. With --edge-url it opens a second loopback listener for the Cloudflare tunnel (below).

Auto-scan

The Brother card has an Auto-scan switch. On, the server reads the scanner's paper sensor every 3 seconds (escl-scan --status, one eSCL request) and starts scan-batch --auto-started when paper is in the feeder. Nobody has to open the dashboard. The batch ends after the idle time with no paper, and the next feed starts a new batch.

  • One batch per feed. scan-batch writes why it ended into batch.json ("ended": idle, stop, jam, lost or interrupted). After idle its own last look found the feeder empty, so paper there now starts the next batch. After anything else the paper may be what that batch left behind, and it starts nothing until the watcher has seen the feeder empty: the card says to take it out and load it again, or press Scan.
  • Who it is recorded as. Nobody picks a name when paper just lands, so auto-scan's Settings hold the person, sides, color and idle time. batch.json gets "auto": true, and the batch card shows "(auto-scan)" after the name. To scan as someone else, press Scan and pick the name before loading the paper: the watcher stays out while a batch runs.
  • Paper already waiting when the switch goes on, or when the server starts with it on, counts as a feed.
  • Brother only. The iX500's paper sensor takes a full SANE option dump to read, over a USB link that drops under load.
  • The watcher pauses while Diagnose or a restart of the Brother services runs, and probes nothing while the switch is off. Each start shows under Jobs as "Auto-scan on ...", and the server log gets an auto-scan: line.
  • The scanner has to stay powered. If it turns itself off, the card shows it offline and nothing scans until it is back.

Reaching it from other devices

The server never listens on the network. Two routes reach it, and bun run deploy sets up both:

URL Path Who gets in
https://scans.beric.ca beric.ca edge gate (Cloudflare Worker), then the beric-mini Cloudflare tunnel to the mini's 127.0.0.1:7823, then a reverse SSH tunnel to the edge listener, 127.0.0.1:7821 on CT 150 the beric.ca sign-ins in --edge-allow: Eric, Elsa, Ariel and Jose (the deploy default)
https://macmini-2018.tail2d2c60.ts.net:8445 tailscale serve on the mini to 127.0.0.1:7822, then a reverse SSH tunnel to 127.0.0.1:7820 on CT 150 the tailnet logins in --allow-login (baruchhub@gmail.com)

Each listener trusts one identity header and ignores the other. The edge Worker deletes any X-Gate-* header a caller sends and sets X-Gate-User from the gate's own check, so the edge listener reads only that one. It serves only the --edge-url Host, so a request through Cloudflare can't claim a tailnet login. The main port never reads X-Gate-User, because tailscale serve passes it through untouched. The gate alone admits every full-access beric.ca account; --edge-allow is the list the dashboard itself accepts, so an account added to the gate later stays out until it is added here too. The 403 names the identity that arrived, which helps when a trusted-device session shows up as tailnet:<device> instead of an email.

The scans.beric.ca side lives in the homelab repo: the ingress rule in services/tunnels/mini/config.yml (copied to /opt/stacks/tunnel/config.yml on the mini, then docker restart beric-mini-tunnel), the DNS route from bun run tunnel route beric-mini scans.beric.ca, and the offline-page label in services/beric-gate/edge/hosts.ts. Until 2026-11-09 it ran from the Mac through beric-mac.

The tailnet route by hand: publish it with tailscale serve on a machine that is always on, and carry it there over a reverse SSH tunnel:

browser ──https──> tailscale serve on HOST :8445 ──> HOST 127.0.0.1:7820
                   ──ssh -R (scan-tunnel)──> this Mac 127.0.0.1:7820 (server.ts)
  1. On HOST: sudo tailscale serve --bg --https=8445 http://127.0.0.1:7820.
  2. On the Mac: scan-catalog serve --install --public-url https://HOST.TAILNET.ts.net:8445 --allow-login you@example.com --tunnel HOST. That writes the dashboard LaunchAgent with the two flags and a second one, ca.beric.scan-it-tunnel, that runs scan-tunnel HOST (log ~/Library/Logs/scan-it-tunnel.log).

Requests for the public URL must carry a Tailscale-User-Login in the --allow-login list. tailscale serve sets that header for the signed-in tailnet user and drops any copy the client sent. Tagged nodes get none, so they are refused. The login is the real gate, since anyone who can load the page gets its token. Restrict the port in the tailnet policy as well. The server won't start with --public-url and no --allow-login. From the public URL, Show in Finder and Open scans folder are hidden and refused, because they open Finder on the Mac. SCAN_SERVE_PUBLIC_URL and SCAN_SERVE_ALLOW_LOGINS (comma-separated) are the environment equivalents.

When the Mac sleeps, HOST's sshd can keep the dead session's port bound for hours. So scan-tunnel frees the port before each connect, killing only a listening sshd-session owned by the same user. That lookup needs passwordless sudo on HOST. While the Mac is asleep or away, the public URL returns 502.

The static dashboard.html copies in Drive keep their no-network CSP. Their live block is null, so they show the scanner list and a link to the live page.

Run locally and deploy

package.json holds the tasks. Run bun install once for the typecheck.

Task What it does
bun run dev share/server.ts --mock on http://127.0.0.1:7830/, restarted by bun --watch on every save. Mock scanners, batches and jobs; the catalog is the real filing root. dashboard.html is read per request, so a reload shows template edits.
bun run start scan-catalog serve: the real server on 7820, or the running LaunchAgent's page if it is already up.
bun run typecheck strict tsc over share/server.ts.
bun run test every bats suite (bats test/). Not bun test, which is bun's own runner.
bun run deploy scripts/deploy.sh: copies this checkout to CT 150 as ~/scan-it.new, runs the typecheck and test/serve.bats there, swaps it in as ~/scan-it, then scan-catalog serve --install with both routes and --tunnel mini --tunnel-map 7820:7822 --tunnel-map 7821:7823. Then it checks the edge listener (allowed and refused), both reverse tunnels from the mini, and that scans.beric.ca answers 401 signed out. It reaches CT 150 through SCAN_DEPLOY_JUMP (default macmini-ts; mini-host from a canopy container, with SCAN_DEPLOY_MINI=mini-host). Other SCAN_DEPLOY_* variables override the target, URLs, logins and ports; SCAN_DEPLOY_SKIP_CHECKS=1 skips the tests.
bun run logs follow the server and tunnel logs.

The server runs from the copy in CT 150's ~/scan-it (its REVISION file names the commit), so a deploy is a copy plus a restart.

Repo layout

bin/                        # the CLI tools (symlinked into ~/bin)
share/dashboard.html        # dashboard template scan-catalog renders
share/server.ts             # live dashboard server (scan-catalog serve)
scripts/deploy.sh           # bun run deploy: reinstall the LaunchAgents, check every route
package.json, tsconfig.json # task shortcuts and the strict typecheck (dev only)
docs/                       # device-options.txt (full scanimage dump), superpowers/ plans & specs
test/                       # bats suites + stubs/ (fake scanimage) + helpers/ (fake eSCL scanner, JPEG cutter): scan-batch, batch-file, checks-normalize, scan-catalog, serve, jpeg-check
ENVIRONMENT.md              # machine + scanner baseline recorded at preflight
PRD-ix500-mac-scanning.md   # original product requirements
TROUBLESHOOTING.md          # failure modes and fixes

Status

In active use for document, paycheck, and mixed-batch scanning. The check workflow (scan → manifest → split → normalize → report) and the mixed-batch workflow (scan-batch + batch-file) both shipped 2026-06-11; per-check normalization inside checks-split and the entity registry landed 2026-06-12. Dev-only bats suites cover batch-file, scan-batch, checks-normalize, scan-catalog, jpeg-check and the live server (98 tests). Run them with bun run test. macOS + iX500 specific; validated on the single machine recorded in ENVIRONMENT.md.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages