Fold the formatters plan into design.md
Security / Vulnerability check (push) Successful in 43s
Test / Lint and test (push) Successful in 2m6s

Phases 1-4 of docs/plans/formatters.md are built and described in
design.md, and every phase 5 item now has a plan of its own, under
Planned next. So the plan goes, and what still matters moves into
design.md.

A new decision says that existing jobs keep their meaning and their
bytes: /print stays strictly decoded, TestRenderCompat and
TestPaperReceipts pin the bytes, and Renderer.Render is the only path
to printer bytes. The labels and footer settings join "Modules build
ordinary jobs". Deferred gains nested boxes and goldmark, and the
geometry checks in the HTTP handler that stay rejected. The plan's
other invariants were already design.md decisions.

The plans that cited formatters.md now cite design.md, or drop the
reference: job-store.md, printers.md, blocks.md and templates.md.
job-store.md's phase 5 list moves to design.md's Deferred section once
its other phases are done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 11:09:30 -06:00
1 parent 68bce4db59
commit 709e7904e9
6 files changed
+25 -71

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
# Plan: more blocks
Status: **planned; nothing is built.** The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item for more blocks records them. Each block is built when it is needed, one at a time, so the five stages are independent. Each runs alone in its own session, briefed from its section, in any order; the Overview suggests one. Decisions 2 and 3 apply to every stage, and decision 1 to stages 1-3, which add glyphs. Stage 1 follows decisions 4-6, stage 2 decisions 7-14, stage 3 decisions 15-17, stage 4 decisions 18-21 and stage 5 decisions 22-26. Every paper check needs the owner's OK. A stage's last commit deletes its section here, and moves the stage's decisions from that Planned next item into design.md's bullet "Blocks are laid out when the job renders". Whichever stage finishes last deletes this plan, its findings with it, design.md's Planned next item for more blocks, and formatters.md's "More blocks" item if that plan is still there.
Status: **planned; nothing is built.** The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item for more blocks records them. Each block is built when it is needed, one at a time, so the five stages are independent. Each runs alone in its own session, briefed from its section, in any order; the Overview suggests one. Decisions 2 and 3 apply to every stage, and decision 1 to stages 1-3, which add glyphs. Stage 1 follows decisions 4-6, stage 2 decisions 7-14, stage 3 decisions 15-17, stage 4 decisions 18-21 and stage 5 decisions 22-26. Every paper check needs the owner's OK. A stage's last commit deletes its section here, and moves the stage's decisions from that Planned next item into design.md's bullet "Blocks are laid out when the job renders". Whichever stage finishes last deletes this plan, its findings with it, and design.md's Planned next item for more blocks.
## Decisions (owner, 2026-11-30)
-46
View File
@@ -1,46 +0,0 @@
# Plan: CP437 blocks, modules and ntfy printing
Status: **phases 1-4 are done**: the blocks and the preview; the list block, the module layer and the note module; the notify and ntfy modules, their cards and scoped tokens; and the ntfy subscriptions, with their digest, paper budget and quiet hours. All four are built and checked on paper, and docs/api.md, README.md and design.md describe them. Phase 5 is a list of items built one at a time, each when a real need appears, in its own session briefed from its item.
## Rules for phase 5
BACKWARD COMPATIBILITY
- Every existing element, field and response keeps its meaning, and /print stays strictly decoded.
- TestRenderCompat (receipt/testdata/compat) and TestPaperReceipts pin the bytes of existing jobs; later work keeps them passing.
- Emoji are removed only on the module and ntfy paths; /print prints an emoji sequence as one '?'.
DEFERRED UNTIL A NEED APPEARS
- nested boxes and goldmark.
- Geometry checks in the HTTP handler (Renderer.Check) stay rejected: layout never fails on a valid job, preview shows the result and line count synchronously, and each module caps its own length.
INVARIANTS (all match the current code)
1. receipt.Job stays printer-neutral. Blocks are sized at render time from Options.Columns or Profile.Columns(font). The same job therefore prints correctly on a TM-T88IV, TM-T88VII or TM-m50II, and on several printers later.
2. Job.Validate stays structural and independent of geometry, so handlePrint keeps its Validate-then-Submit flow.
3. Layout never fails on a valid job. Widths clamp, titles are cut with "...", and over-long words split the way wrap() already splits them. The only render-time failure is the [format].max_lines backstop (default 2000).
4. Renderer.Render is the only path to printer bytes, and is all-or-nothing.
5. New code never emits raw ESC/POS. Payload text only ever lands in string fields of elements. The raw element stays available on /print only, to tokens issued with --raw.
6. /print stays strictly decoded (DisallowUnknownFields). A byte-compatibility test pins today's bytes.
7. Layers call only downward: server -> modules -> receipt -> escpos. ntfy never imports modules; internal/app connects the subscriptions to modules.
## Phases
### Phase 5: Later, on demand (1-3 days each; build only when a real need appears)
**Goal.** Keep the core small. Each item below is independent and waits for real demand or an owner decision.
**Work.**
- Several printers: planned in docs/plans/printers.md.
- User templates: planned in docs/plans/templates.md.
- More blocks: planned in docs/plans/blocks.md.
- Queue.Cancel so message_delete can cancel a still-queued job.
- Webhook sources: planned in docs/plans/templates.md.
- Default line spacing per model: planned in docs/plans/printers.md (decision 30).
**Tests.**
Each item ships with its own goldens and table tests in the phase 1-4 style.
**Done when.**
Each item is done when its feature has golden or preview coverage, README docs, and a real-paper check where layout changes. Nothing here blocks phases 1-4.
+2 -3
View File
@@ -544,7 +544,7 @@ DELIVERIES AND SEVERAL PRINTERS
- Anycast: a delivery's printer is chosen when it is dispatched, and its row records the printer used. Before any byte was sent, a failure fails over to the next printer at once: the delivery moves to it and no `sending` mark is written, just as a dial failure writes nothing today. After a `sending` mark, the existing retry rule on that printer runs, then failover to the next (docs/plans/printers.md decision 22). That failover can print a whole receipt on two printers (decision 23). A queued delivery restored after a restart starts again from the top of its stored list (printers decision 18).
- One store per instance. Each delivery names its printer, so one store serves every printer: one queue with a lane and a worker per printer, each loading its own unfinished deliveries (docs/plans/printers.md decision 4).
- Job IDs stay global, so `GET /api/v1/jobs/{id}` needs no printer.
- The stored job is printer-neutral (formatters invariant 1) and rendered bytes are not stored, so a queued delivery can move to another printer. A queued delivery whose printer was removed from the config fails at restore (docs/plans/printers.md decision 5).
- The stored job is printer-neutral (design.md, "Blocks are laid out when the job renders") and rendered bytes are not stored, so a queued delivery can move to another printer. A queued delivery whose printer was removed from the config fails at restore (docs/plans/printers.md decision 5).
- Acknowledgement IDs are counted per printer.
- `cancelled` comes with phase 2b, as a delivery's state; the `deliveries.state` column takes it without a schema change.
- Two instances must not share a state directory. Exclusive locking makes the second fail at start; today they would also share the `ntfy-<name>.json` files. Until one instance drives several printers, each instance gets its own directory.
@@ -854,7 +854,6 @@ Docs
- docs/api.md: the route table, a "Cancel a job" section, the `job_started` row in the error table, and the Job status section (`cancelled`).
- docs/ntfy.md: how a subscription behaves: a `message_delete` cancels the waiting receipts of its notification and drops its held digest rows, also under `min_priority` and past `max_backlog`; a `message_clear` does neither; `min_priority` is applied by the subscriber, which reads every message of its topics.
- design.md: the state machine's `cancelled`, its synced commit and the delivery lock; the ntfy subscriptions paragraph (deletes cancel, clears do not, and the subscriber filters priorities itself).
- docs/plans/formatters.md: its phase 5 item "Queue.Cancel so message_delete can cancel a still-queued job" goes, since this phase builds it.
- CHANGELOG: under **Breaking**, the `cancelled` status; under Added, `DELETE /api/v1/jobs/{id}` and cancelling by ntfy deletes; under Changed, that a subscription with `min_priority` reads every message and filters itself.
- docs/swagger.json regenerated.
@@ -998,7 +997,7 @@ Docs
**Done when.**
- A job printed earlier previews by its ID as text and as PNG.
- The full gate passes.
- Once phases 1-4, 2b included, are all done: design.md's Planned next item 1 goes, and this plan is trimmed to its phase 5 list, as formatters.md is.
- Once phases 1-4, 2b included, are all done: design.md's Planned next item 1 goes, the phase 5 list moves to design.md's Deferred section, and this plan is deleted, its findings with it.
### Phase 5: Later, on demand (build only when the owner asks)
+1 -1
View File
@@ -382,7 +382,7 @@ COMPATIBILITY
INVARIANTS
1. Nothing reaches a printer unless the whole receipt rendered for it, with its own profile and options. A failover to a printer with other options renders in full before it sends.
2. Layout comes from each printer's profile. A job stays printer-neutral (formatters invariant 1), so any delivery can go to any printer. The exception is a `raw` element, whose bytes are written for one model; a rule on `types` keeps them there.
2. Layout comes from each printer's profile. A job stays printer-neutral (design.md, "Blocks are laid out when the job renders"), so any delivery can go to any printer. The exception is a `raw` element, whose bytes are written for one model; a rule on `types` keeps them there.
3. A job no rule matches prints on the default printer, and a config without `[printers]` or `[routing]` prints as today.
4. A rule sees routing facts only, never print content, a token, a secret, a `ref` or a printer's state, its down mark included. Neither the env, the facts nor an Expr run-time message reaches logs, Sentry, the store or job status. A compile error leaves out the rule's source line.
5. A route is decided once, at `Submit`, from the job's facts, its acceptance time and the rule set, and stored. A restore never decides again.
+2 -2
View File
@@ -48,7 +48,7 @@ For stage 1:
- Trade-off: a template over a very large body can fail where it would only have been slow, and the guard is code of our own around Expr's AST.
7. **What a template's output may hold.**
- The result is encoded as JSON and decoded by the strict job decoder (`receipt.DecodeJob`, receipt/job.go:205), so an unknown key or a value of the wrong type is an error, then validated. A `card` result is decoded strictly into the notification's fields. A decoding error becomes a fixed message, `the result is not a job`, with at most a path we work out ourselves: Expr allows computed keys, such as `{(body.x): 1}`, and the decoder's own message, `unknown field "…"`, would quote the payload.
- The checks run on the decoded job, not on Expr's maps, since the decoder matches names in any letter case: a `HEX` key fills `hex`. `raw` is refused wherever it stands, at the top, in a box or, once blocks.md stage 5 has shipped, in a group, and so is a `hex` field on any element, whatever the token. formatters.md's invariant 5 holds: payload text only lands in string fields.
- The checks run on the decoded job, not on Expr's maps, since the decoder matches names in any letter case: a `HEX` key fills `hex`. `raw` is refused wherever it stands, at the top, in a box or, once blocks.md stage 5 has shipped, in a group, and so is a `hex` field on any element, whatever the token. design.md's "Modules build ordinary jobs" holds: payload text only lands in string fields.
- One walker visits every string field of the decoded job by reflection, with a list of the fields it leaves alone (`url`, `data`, `base64`, `hex`); a test fails when `Element` gains a string field the walker does not place. Each text field is at most 4,096 bytes, ntfy's message limit, and the encoded result at most 256 KiB. Over either, the run fails; `cut` keeps a string inside the limit. `data` keeps validation's limits, and `base64` the 256 KiB. A `card` result is cut to the card's caps instead, as an ntfy card is.
- Every `image` a template builds is `optional`, as a card's are (modules/card.go:233). Its `url` may come from the payload. It is fetched by the worker through `safehttp`, like every image, so it cannot reach the host's own network unless `images.*` allows it, and a broken one prints `[image unavailable]` rather than failing the job.
- Each built job is laid out by the text preview, which fetches nothing, before it is queued, so a job over `format.max_lines` fails as a template's run fails, not later in the worker.
@@ -105,7 +105,7 @@ For stage 4:
19. **The route, and its rate limit.** The route is `POST /hooks/{name}`, outside `/api/v1`, since a webhook sender sends no bearer token. It is an entry in the route table like any other, with a new flag beside `Auth` and `NoStore` (server/routes.go:34-38; `Hook`, name assumed): no bearer token and `Cache-Control: no-store`. It has its own case in `TestRoutesConform`. Hooks are `[[webhooks.hooks]]`, a list of tables read from the file only, each with a `name` by the subscriptions' rule, `^[a-z0-9][a-z0-9_-]{0,31}$`, unique.
- No per-client limit stands in front of a delivery whose signature passes. GitHub and gitlab.com send every customer's hooks from shared addresses, and `/api/v1`'s limiter counts a request before its token is read (server/server.go:177-187). With it, anyone could point their own hook at `/hooks/forge` and spend the owner's budget with refused deliveries; GitHub never retries the real ones it then refuses.
- Refused requests (`401`, `404` and `415`) count per client in a limiter of their own, at `webserver.rate_limit` per `rate_window` (60 a minute by default, config.go:363-364). A client over it gets `429` before any hashing, which bounds the HMAC work and the log lines.
- An unknown name answers `404` with a new code, `hook_not_found`, before the body is parsed or hashed. It cannot come before the body is read, as formatters.md's item asked: fasthttp reads the whole body, up to `webserver.body_limit`, before any handler runs (Investigation findings, THE REPOSITORY).
- An unknown name answers `404` with a new code, `hook_not_found`, before the body is parsed or hashed. It cannot come before the body is read: fasthttp reads the whole body, up to `webserver.body_limit`, before any handler runs (Investigation findings, THE REPOSITORY).
- Caddy, as install.sh sets it up, already proxies every path and drops query strings from its log (install.sh:381-421). An operator's own proxy in front of the Docker image must pass `/hooks/` too.
- Trade-off: `404` and `401` tell a stranger which names exist. A name is not a secret; the hook's secret is. Valid deliveries have no rate limit (decision 28).
20. **Authentication.** Every hook has a secret, `secret` or `secret_file`, exactly one, read as the subscriptions' credential files are; a hook without one is a config error. Its `preset` says how the sender proves it holds the secret (Architecture, WEBHOOKS, gives the table): `github`, `gitea` and `forgejo` sign the body with HMAC-SHA256 in hex; `gitlab` and `standard` sign the message ID, a timestamp and the body, in base64, as the Standard Webhooks specification has it; `header` compares a header with the secret.