Formatters plan: record phase 3 and 4 decisions
Security / Vulnerability check (push) Successful in 52s
Test / Lint and test (push) Successful in 2m6s

Every link prints as a QR code, image attachments and edited messages
print, the ntfy paper budget defaults to 5 receipts per 10 minutes with
priority 5 bypassing it, and quiet hours move into phase 4 as a morning
digest. The private-network image exception is dropped because the ntfy
server is public. The open questions left are an assumed default, config
values, the calibration check and the second printer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-11-30 00:24:41 -06:00
1 parent 853e8a9910
commit 9fdea32b4f
1 file changed
+53 -41
+53 -41
View File
@@ -1,12 +1,12 @@
# Plan: CP437 blocks, modules and ntfy printing # Plan: CP437 blocks, modules and ntfy printing
Status: **draft.** Phase 1 can start; the remaining open questions only affect phases 3-5. Nothing here is built yet. Each phase runs in its own session, briefed from its section. Status: **phase 1 in progress.** Every design decision for phases 1-4 is made; the open questions left are an assumed default, config values, a calibration check and the second printer. Each phase runs in its own session, briefed from its section.
## Decisions (owner, 2026-11-29) ## Decisions (owner, 2026-11-29)
- **ntfy server:** self-hosted at a public URL. The subscriber authenticates - **ntfy server:** self-hosted at a public URL. The subscriber authenticates
with a token. Attachments come from a public host, so no safehttp with a token. Attachments come from a public host, so no private-network
PrivateHosts exception is needed; drop it from phase 4. exception in safehttp is needed.
- **Which priorities print:** configurable per subscription (minimum priority, - **Which priorities print:** configurable per subscription (minimum priority,
and whether priorities 1-2 print in the compact form). Default: all and whether priorities 1-2 print in the compact form). Default: all
priorities, 1-2 compact. priorities, 1-2 compact.
@@ -17,6 +17,21 @@ Status: **draft.** Phase 1 can start; the remaining open questions only affect p
lines'). Footer time zone and format come from config, default local time lines'). Footer time zone and format come from config, default local time
and "02 Jan 15:04". and "02 Jan 15:04".
## Decisions (owner, 2026-11-30)
- **Links:** every link prints as a QR code: the click URL and the view
actions, deduplicated, at most 3. `[ntfy.format] qr` defaults to "all".
- **Image attachments** print (`images = true`).
- **Edited messages** print again, marked "(updated)" (`updates = "print"`).
- **Paper budget:** 5 receipts per 10 minutes per subscription by default,
configurable; the rest fold into one digest receipt. Priority 5 always
prints.
- **Quiet hours:** wanted, as a morning digest, and part of phase 4. During
a configured window only priority 5 prints; everything else is held and
printed as one digest receipt when the window ends. Window, days and time
zone come from config (default 22:00-07:00 every day, local time); off
unless configured.
## Overview ## Overview
FOUNDATION FOUNDATION
@@ -25,14 +40,14 @@ The plan starts from Design 1 (components): layout blocks inside the existing el
- list in phase 2 - list in phase 2
Ideas taken from the other designs: Ideas taken from the other designs:
- From Design 2 (templates): fit boxes, a hand-written markdown subset with no new dependency, a plain fallback receipt, a since=<time> cursor, token scopes, and '?' warnings in preview. - From Design 2 (templates): fit boxes, a hand-written markdown subset with no new dependency, a plain fallback receipt, a since=<time> cursor, token scopes, and '?' warnings in preview.
- From Design 3 (sources): a simple Notice input (the notify module), images marked optional, a cursor taken from ntfy server time, a narrow safehttp PrivateHosts exception, the time/tzdata import, and Submit Meta for traceability. - From Design 3 (sources): a simple Notice input (the notify module), images marked optional, a cursor taken from ntfy server time, the time/tzdata import, and Submit Meta for traceability.
WHAT SHIPS WHEN (about 12-13 developer days to the end of phase 4) WHAT SHIPS WHEN (about 12-13 developer days to the end of phase 4)
1. Boxes and preview, 3-4 days. One /print element gives the single or double CP437 boxes the owner liked. POST /api/v1/preview and `uberbringer preview` show the exact output without using paper. 1. Boxes and preview, 3-4 days. One /print element gives the single or double CP437 boxes the owner liked. POST /api/v1/preview and `uberbringer preview` show the exact output without using paper.
2. Notes and modules, 2 days. POST /api/v1/print/note {title, text, items} prints a boxed checklist. 2. Notes and modules, 2 days. POST /api/v1/print/note {title, text, items} prints a boxed checklist.
3. Notifications, 3 days. POST /api/v1/print/notify {title, message, priority, tags} is for scripts and phone shortcuts. POST /api/v1/print/ntfy takes the ntfy CLI's $NTFY_RAW unchanged. After this phase, ntfy printing needs only a client.yml entry and no jq. 3. Notifications, 3 days. POST /api/v1/print/notify {title, message, priority, tags} is for scripts and phone shortcuts. POST /api/v1/print/ntfy takes the ntfy CLI's $NTFY_RAW unchanged. After this phase, ntfy printing needs only a client.yml entry and no jq.
4. Built-in ntfy subscriber, 4 days. You only change the config. It reconnects safely, removes duplicates, caps the backlog and folds floods into a digest receipt. 4. Built-in ntfy subscriber, 5 days. You only change the config. It reconnects safely, removes duplicates, caps the backlog, folds floods into a digest receipt, and holds non-urgent messages during quiet hours for a morning digest.
5. Later, on demand: quiet hours, the second-printer pool, user templates, an ntfy-compatible publish endpoint, table/banner/spans, and webhooks. 5. Later, on demand: the second-printer pool, user templates, an ntfy-compatible publish endpoint, table/banner/spans, and webhooks.
BACKWARD COMPATIBILITY BACKWARD COMPATIBILITY
- Every existing element, field and response keeps its meaning, and /print stays strictly decoded. - Every existing element, field and response keeps its meaning, and /print stays strictly decoded.
@@ -46,38 +61,28 @@ WHERE THE JUDGES DISAGREED, AND WHAT THIS PLAN CHOSE
- Geometry checks in the HTTP handler (Renderer.Check): rejected. Layout never fails on a valid job, preview shows the result and line count synchronously, and each module caps its own length. - Geometry checks in the HTTP handler (Renderer.Check): rejected. Layout never fails on a valid job, preview shows the result and line count synchronously, and each module caps its own length.
- Tight line spacing: off by default until a calibration print has been checked. - Tight line spacing: off by default until a calibration print has been checked.
- Scoped tokens: in phase 3, before any integration token is handed out. - Scoped tokens: in phase 3, before any integration token is handed out.
- Quiet hours: phase 5 unless you want them sooner (open question 5). - Quiet hours: phase 4, as a morning digest (owner decision).
## Open questions ## Open questions
Before phase 3: Before phase 3 (assumed unless the owner says otherwise):
1. Topics and auth: which topics should print? A dedicated read-only ntfy 1. Integration tokens: tokens created with --modules can only use module
user with an access token is assumed. routes, while existing tokens keep full access including raw ESC/POS.
2. Card extras: should the click link print as a QR code (first, all or
none)? Should image attachments print? Should ntfy updates (sequence_id)
print again marked '(updated)', or be skipped?
3. Integration tokens: is it OK that tokens created with --modules can only
use module routes, while existing tokens keep full access including raw
ESC/POS?
Before phase 4: Before phase 4 (config, not design):
4. Paper budget: how many receipts per window before messages fold into a 2. Topics and auth: which topics and quiet-hours window to configure. A
digest (the plan assumes 10 per 10 minutes)? Should priority 5 always dedicated read-only ntfy user with an access token is assumed.
bypass the limit?
5. Quiet hours: wanted? If so: the window, the days, the priority that still
prints, and whether held messages print as a morning digest or are
dropped. A yes moves this into phase 4.
After phase 1's calibration print: After phase 1's calibration print:
6. Are the small gaps in vertical borders acceptable, or should boxes use 3. Are the small gaps in vertical borders acceptable, or should boxes use
tighter line spacing (box_line_spacing)? tighter line spacing (box_line_spacing)?
When the second printer arrives: When the second printer arrives:
7. Which jobs and ntfy topics go to which printer, and should urgent messages 4. Which jobs and ntfy topics go to which printer, and should urgent messages
print on both? print on both?
## Mockups (42 columns, CP437) ## Mockups (42 columns, CP437)
@@ -440,7 +445,7 @@ Job status:
[ntfy.format] # phase 3 [ntfy.format] # phase 3
style = "auto" # auto | box | compact style = "auto" # auto | box | compact
max_lines = 40 max_lines = 40
qr = "first" # first | all | none qr = "all" # all | first | none
images = true images = true
markdown = true markdown = true
updates = "print" # print | skip (sequence_id updates) updates = "print" # print | skip (sequence_id updates)
@@ -455,10 +460,17 @@ Job status:
token_file = "/etc/uberbringer/ntfy.token" # or user + password_file; exactly one token_file = "/etc/uberbringer/ntfy.token" # or user + password_file; exactly one
min_priority = 3 # sent to ntfy as ?priority=3,4,5 min_priority = 3 # sent to ntfy as ?priority=3,4,5
max_backlog = "1h" # 12h at most (the ntfy cache) max_backlog = "1h" # 12h at most (the ntfy cache)
rate_limit = 10 # receipts per rate_window; the rest go into one digest rate_limit = 5 # receipts per rate_window; the rest go into one digest
rate_window = "10m" rate_window = "10m"
bypass_priority = 5 bypass_priority = 5
keepalive = "45s" keepalive = "45s"
[ntfy.subscriptions.quiet] # optional; quiet hours are off without this table
start = "22:00"
end = "07:00" # may cross midnight
days = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
timezone = "Local"
min_priority = 5 # prints during the window; the rest are held
action = "digest" # digest | drop; digest prints the held messages when the window ends
GET /healthz (phase 4) adds a field. The HTTP status still depends only on the printer: GET /healthz (phase 4) adds a field. The HTTP status still depends only on the printer:
"ntfy":[{"name":"home","state":"connected","connected_since":"2026-11-29T20:58:01Z","last_message_at":"2026-11-29T21:04:05Z","printed":12,"digested":2,"last_error":""}] "ntfy":[{"name":"home","state":"connected","connected_since":"2026-11-29T20:58:01Z","last_message_at":"2026-11-29T21:04:05Z","printed":12,"digested":2,"last_error":""}]
@@ -671,8 +683,8 @@ Footer
Links Links
- The links are the click URL plus view actions (http or https), with duplicates removed, at most 3. - The links are the click URL plus view actions (http or https), with duplicates removed, at most 3.
- qr = first (default): the first link prints as a centred QR code (size 5, correction M) with a Font B caption, the action's label or else host/path. The others print as "» label" plus the URL. - qr = all (default): every link prints as a centred QR code (size 5, correction M) with a Font B caption, the action's label or else host/path.
- qr = all prints every link as a QR code; qr = none prints them all as text. - qr = first prints only the first link as a QR code and the others as "» label" plus the URL; qr = none prints them all as text.
- http, broadcast and copy actions are never printed, because their headers and body can hold secrets. - http, broadcast and copy actions are never printed, because their headers and body can hold secrets.
Attachments Attachments
@@ -715,8 +727,11 @@ Rate limit
- Messages over the limit go into one digest receipt, printed when tokens return. The digest holds 50 rows; after that, messages are only counted. - Messages over the limit go into one digest receipt, printed when tokens return. The digest holds 50 rows; after that, messages are only counted.
- Messages at or above bypass_priority skip the bucket. - Messages at or above bypass_priority skip the bucket.
Quiet hours
- During a subscription's quiet window, messages below quiet.min_priority are held (action = digest) or dropped (action = drop). Held messages share the digest buffer and print as one "Overnight" digest when the window ends.
Images and logging Images and logging
- The subscription's own server host is added to safehttp Options.PrivateHosts, so images.allow_private_networks stays off. - Attachment images are fetched through safehttp like any image URL; the ntfy server is public, so no private-network exception is needed.
- Logs carry the source, ntfy id and job id, never the message text. No notification content goes to Sentry, matching sentryMiddleware's existing rule of attaching no bodies. - Logs carry the source, ntfy id and job id, never the message text. No notification content goes to Sentry, matching sentryMiddleware's existing rule of attaching no bodies.
## Phases ## Phases
@@ -991,9 +1006,9 @@ internal/pkg/printqueue
- A token from `uberbringer token --modules ntfy` gets 403 on /api/v1/print. - A token from `uberbringer token --modules ntfy` gets 403 on /api/v1/print.
- The full gate passes (CLAUDE.md lists it). - The full gate passes (CLAUDE.md lists it).
### Phase 4: Built-in ntfy subscriber (4 days) ### Phase 4: Built-in ntfy subscriber (5 days)
**Goal.** No client code and no extra programs: add [[ntfy.subscriptions]] to the config and the phone's ntfy app becomes the only client. Restarts and outages must not lose a flood's worth of paper or reprint old messages. **Goal.** No client code and no extra programs: add [[ntfy.subscriptions]] to the config and the phone's ntfy app becomes the only client. Restarts and outages must not lose a flood's worth of paper or reprint old messages, and nothing but urgent messages prints during quiet hours.
**Work.** **Work.**
@@ -1004,13 +1019,11 @@ internal/pkg/ntfy
- Run(ctx, handle). - Run(ctx, handle).
- state.go: the cursor plus the 512-id dedupe ring, written atomically (temp file, fsync, rename), at most once a second and on shutdown. - state.go: the cursor plus the 512-id dedupe ring, written atomically (temp file, fsync, rename), at most once a second and on shutdown.
- ratelimit.go: the token bucket plus the digest buffer, with an injectable clock. - ratelimit.go: the token bucket plus the digest buffer, with an injectable clock.
- quiet.go: quiet hours. During the window, messages below min_priority are held (action = digest) or dropped (action = drop); held messages print as one digest when the window ends, sharing the digest buffer and its 50-row cap. Boundaries are computed with time.Date in the configured zone, so windows cross midnight and handle DST. Held messages are persisted with the cursor state, so a restart during the night does not lose them.
- status.go: snapshots for /healthz. - status.go: snapshots for /healthz.
internal/pkg/modules internal/pkg/modules
- digest.go: the digest card (mockup 12). - digest.go: the digest card (mockup 12), titled "ntfy digest · N held" for rate-limit overflow and "Overnight · N held" for quiet hours.
internal/pkg/safehttp
- Options.PrivateHosts: exact hosts that may resolve to private addresses without switching on allowlist-only mode. It is filled with the server hosts of subscriptions that have images enabled.
internal/app/uberbringer internal/app/uberbringer
- serve.go: one group.Go(sub.Run) per subscription. - serve.go: one group.Go(sub.Run) per subscription.
@@ -1025,7 +1038,8 @@ internal/pkg/config
- the topic regex, at most 150 topics - the topic regex, at most 150 topics
- exactly one of token, token_file, or user + password_file - exactly one of token, token_file, or user + password_file
- max_backlog of 12h or less - max_backlog of 12h or less
- rate_limit greater than 0 - rate_limit greater than 0 (default 5 per 10m)
- quiet: start and end as HH:MM, known day names, a loadable time zone, min_priority 1-5, action digest or drop
- a warning when the token file can be read by group or others - a warning when the token file can be read by group or others
internal/app/uberbringer/server internal/app/uberbringer/server
@@ -1053,9 +1067,7 @@ Use an httptest server that streams NDJSON open, keepalive and message events. C
- multi-topic URLs - multi-topic URLs
- min_priority is sent as the priority filter - min_priority is sent as the priority filter
- the rate limit sends overflow to a digest, priority 5 bypasses it, and the digest caps at 50 rows - the rate limit sends overflow to a digest, priority 5 bypasses it, and the digest caps at 50 rows
- quiet hours: a window crossing midnight, a DST change night, priority 5 printing during the window, held messages printed as one digest at the window's end, action = drop, and held messages surviving a restart
internal/pkg/safehttp
- PrivateHosts admits only the exact host.
internal/pkg/config internal/pkg/config
- Table tests for every validation rule. - Table tests for every validation rule.
@@ -1072,6 +1084,7 @@ Logs
- Stopping uberbringer for 30 minutes while messages are published, then starting it, prints each missed message once (or one digest), with no reprints. - Stopping uberbringer for 30 minutes while messages are published, then starting it, prints each missed message once (or one digest), with no reprints.
- A stored cursor older than max_backlog never replays older messages. - A stored cursor older than max_backlog never replays older messages.
- A wrong token shows state 'unauthorized' in /healthz while printing keeps working. - A wrong token shows state 'unauthorized' in /healthz while printing keeps working.
- With quiet hours set a few minutes ahead, a priority 3 message published inside the window prints only in the digest at its end, while a priority 5 message prints at once.
- A 24-hour run shows no leaked goroutines. - A 24-hour run shows no leaked goroutines.
- The full gate passes (CLAUDE.md lists it). - The full gate passes (CLAUDE.md lists it).
@@ -1081,7 +1094,6 @@ Logs
**Work.** **Work.**
- Quiet hours (or move them into phase 4 if the owner wants them now). Config: [ntfy.subscriptions.quiet] start, end, days, timezone, min_priority, action = digest | drop. Boundaries are computed with time.Date in the zone, so they cross midnight and handle DST correctly.
- Second printer, for the TM-T88VII and TM-m50II: - Second printer, for the TM-T88VII and TM-m50II:
- a printqueue Pool with one Queue and worker per printer - a printqueue Pool with one Queue and worker per printer
- [printers.<name>] config decoded through toml.Primitive onto the defaults, with the old [printer] table becoming "default" and strict unknown-key checks kept - [printers.<name>] config decoded through toml.Primitive onto the defaults, with the old [printer] table becoming "default" and strict unknown-key checks kept