Add the list block and the module layer with the note module
The list block prints items with a dot, dash, number or checkbox bullet,
wrapping a long item with a hanging indent; a checkbox list ticks its
done items as [√], or [x] on code pages without √. It stands alone or
inside a box, and its items, bullet and done fields carry their enums
and limits as jsonschema tags.
internal/pkg/modules holds modules that build ordinary jobs from their
own payloads: a registry by name, an Env with the clock, time zone and
time layout, strict payload decoding that reports every problem, ErrSkip
and PayloadError. The note module prints a boxed note with an optional
checklist and a time stamp in the footer.
Three routes join the route table: POST /api/v1/print/{module} and
POST /api/v1/preview/{module}, which take ?copies and a reserved
?printer, and GET /api/v1/modules. Print and the module route share one
submit path, and preview shares one too. New error codes:
invalid_payload, invalid_query, unknown_printer, module_not_found and
module_failed; a module that builds an invalid receipt is logged and
reported to Sentry once. [format] gains timezone and time_layout, the
binary embeds the time zone database, and uberbringer preview takes
--module.
The note receipt passed on the TM-T88IV, and its bytes are pinned in
TestPaperReceipts. docs/api.md describes the list block, the module
routes and the note payload; docs/swagger.json is regenerated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6b2e402f1a
commit
3e9779f71a
69 files changed
+3092
-262
No files matched your search
+24
-184
@@ -1,6 +1,6 @@
|
||||
# Plan: CP437 blocks, modules and ntfy printing
|
||||
|
||||
Status: **phase 1 is done**: box, rule and kv, text folding and the preview are built and checked on paper (README § Blocks, design.md). Phases 2-5 are not started. Every design decision for phases 2-4 is made; the open questions left are an assumed default, config values and the second printer. Each phase runs in its own session, briefed from its section.
|
||||
Status: **phases 1 and 2 are done**. Phase 1: box, rule and kv, text folding and the preview. Phase 2: the list block, the module layer, the note module and its routes, and `[format] timezone` and `time_layout`. Both are built and checked on paper (docs/api.md § Blocks and § Modules, design.md). Phases 3-5 are not started. Every design decision for phases 3-4 is made; the open questions left are an assumed default, config values and the second printer. Each phase runs in its own session, briefed from its section.
|
||||
|
||||
## Decisions (owner, 2026-11-29)
|
||||
|
||||
@@ -42,9 +42,9 @@ 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 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 10 developer days to the end of phase 4)
|
||||
WHAT SHIPS WHEN (about 8 developer days left to the end of phase 4)
|
||||
1. Boxes and preview: done.
|
||||
2. Notes and modules, 2 days. POST /api/v1/print/note {title, text, items} prints a boxed checklist.
|
||||
2. Notes and modules: done. 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.
|
||||
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: the second-printer pool, user templates, an ntfy-compatible publish endpoint, table/banner/spans, and webhooks.
|
||||
@@ -137,40 +137,6 @@ Prune finished
|
||||
41 snapshots kept, 3 removed.
|
||||
"Prune finished" (the title) is bold.
|
||||
|
||||
--- 5. Single box note: POST /print/note
|
||||
┌─ Shopping ─────────────────────────────┐
|
||||
│ Milk, eggs and the good bread from the │
|
||||
│ bakery on Elm St. │
|
||||
│ │
|
||||
│ [ ] Milk │
|
||||
│ [ ] Eggs │
|
||||
│ [√] Bread │
|
||||
└──────────────────────── 29 Nov 21:04 ──┘
|
||||
|
||||
--- 8. Box with kv, labelled rule and list
|
||||
┌─ NAS REPORT ───────────────────────────┐
|
||||
│ Host ........................... nas01 │
|
||||
│ Pool ................... tank (raidz2) │
|
||||
│ Used ............................. 94% │
|
||||
├── Services ────────────────────────────┤
|
||||
│ · grafana up │
|
||||
│ · offsite-backup DOWN since 19:00 │
|
||||
└──────────────────────── 29 Nov 21:04 ──┘
|
||||
A pair can set "bold" (e.g. Used 94%).
|
||||
|
||||
--- 10. kv (long value wraps) and list
|
||||
Host ............................... nas01
|
||||
Note ... The scrub finished with 0 errors.
|
||||
Next scrub Sunday 03:00.
|
||||
|
||||
· Replace drive bay 3
|
||||
· Order 2x 8 TB
|
||||
1. First item that is long enough to wrap
|
||||
with a hanging indent
|
||||
2. Second
|
||||
[√] Done item
|
||||
[ ] Open item
|
||||
|
||||
--- 12. Rate-limit digest (phase 4)
|
||||
┌─ ntfy digest · 6 held ─────────────────┐
|
||||
│ 21:05 [!] Disk almost full │
|
||||
@@ -196,61 +162,19 @@ All /api/v1 routes keep the existing Bearer JWT, rate limiter and error shape {"
|
||||
|
||||
==== Blocks in POST /api/v1/print ====
|
||||
|
||||
box, rule and kv, the preview (POST /api/v1/preview, `uberbringer preview`) and format.max_lines are built; README § Blocks and § Preview a receipt describe them. Validation problems name nested elements, e.g. elements[0].children[3] (qr). Still to come:
|
||||
|
||||
list (phase 2)
|
||||
- A block like kv: size, font and columns, and allowed as a child of a box.
|
||||
- items: 1-200 strings.
|
||||
- bullet: dot (default), dash, number or checkbox.
|
||||
- done: indexes of finished items, checkbox only. They print as [√], or [x] on code pages without √.
|
||||
box, rule, kv and list, the preview (POST /api/v1/preview, `uberbringer preview`) and format.max_lines are built; docs/api.md § Blocks and § Preview a receipt describe them. Validation problems name nested elements, e.g. elements[0].children[3] (qr). Still to come:
|
||||
|
||||
image (phase 3)
|
||||
- New field optional: true. If the image can't be fetched or decoded, the receipt prints "[image unavailable]" instead of failing the whole job.
|
||||
|
||||
Example 1: a boxed note in one element (mockup 5)
|
||||
POST /api/v1/print
|
||||
{"elements":[
|
||||
{"type":"box","title":"Shopping","footer":"29 Nov 21:04","children":[
|
||||
{"type":"text","text":"Milk, eggs and the good bread from the bakery on Elm St."},
|
||||
{"type":"feed"},
|
||||
{"type":"list","bullet":"checkbox","items":["Milk","Eggs","Bread"],"done":[2]}
|
||||
]}
|
||||
]}
|
||||
==== Modules ====
|
||||
|
||||
Example 2: status report with kv rows, a labelled divider and a list (mockup 8)
|
||||
{"elements":[
|
||||
{"type":"box","title":"NAS REPORT","footer":"29 Nov 21:04","children":[
|
||||
{"type":"kv","pairs":[{"key":"Host","value":"nas01"},{"key":"Pool","value":"tank (raidz2)"},{"key":"Used","value":"94%","bold":true}]},
|
||||
{"type":"rule","text":"Services","align":"left"},
|
||||
{"type":"list","items":["grafana up","offsite-backup DOWN since 19:00"]}
|
||||
]}
|
||||
]}
|
||||
|
||||
==== PHASE 2: modules ====
|
||||
|
||||
GET /api/v1/modules
|
||||
[{"name":"note","description":"Boxed note with an optional checklist"},
|
||||
{"name":"notify","description":"Notification card from title, message, priority and tags"},
|
||||
{"name":"ntfy","description":"One ntfy message object, e.g. the CLI's $NTFY_RAW"}]
|
||||
|
||||
POST /api/v1/print/{module}?copies=1
|
||||
- The body is the module's own payload.
|
||||
- 202: the normal job response.
|
||||
- 204: the module had nothing to print, e.g. an ntfy keepalive.
|
||||
- 400: {"error":"invalid payload for module \"note\"","details":["text: required","done[0]: index 5 is out of range"]}
|
||||
- 403: the token's scope does not include this module (phase 3).
|
||||
- 404: {"error":"module \"notx\" not found"}
|
||||
- 422: {"error":"module \"note\" built an invalid receipt","details":[...]}. This is a bug; ntfy and notify print the fallback receipt instead.
|
||||
- 429 and 503 behave as on /print.
|
||||
- ?printer= is reserved. Until several printers are configured, any value other than "default" returns 400.
|
||||
|
||||
POST /api/v1/preview/{module} takes the same payload and returns the preview response.
|
||||
|
||||
note payload (mockup 5):
|
||||
POST /api/v1/print/note
|
||||
{"title":"Shopping","text":"Milk, eggs and the good bread from the bakery on Elm St.","items":["Milk","Eggs","Bread"],"done":[2]}
|
||||
- Optional fields: style (single, double, double-h or double-v), footer (a string), stamp (default true: with no footer, the print time goes in the bottom border).
|
||||
- Decoded strictly: unknown fields are 400.
|
||||
Built in phase 2 (docs/api.md § Modules): GET /api/v1/modules, POST /api/v1/print/{module} and /api/v1/preview/{module} (202, 204 for ErrSkip, 400 invalid_payload, 404 module_not_found, 422 module_failed, 503 as on /print), ?copies, ?printer reserved for "default", and the note module. Payloads decode with modules.DecodeStrict, which reports every problem. Still to come:
|
||||
- GET /api/v1/modules also lists notify and ntfy once they are registered in newModules (internal/app/uberbringer/modules.go):
|
||||
{"name":"notify","description":"Notification card from title, message, priority and tags"},
|
||||
{"name":"ntfy","description":"One ntfy message object, e.g. the CLI's $NTFY_RAW"}
|
||||
- 403: the token's scope does not include this module (phase 3). It needs a new code in server/errors.go and docs/api.md.
|
||||
- 422 stays a module bug; ntfy and notify print the fallback receipt instead of building an invalid job.
|
||||
|
||||
==== PHASE 3: notifications ====
|
||||
|
||||
@@ -303,11 +227,10 @@ Scoped tokens:
|
||||
Job status:
|
||||
- GET /api/v1/jobs/{id} gains "source", e.g. "module:ntfy" or, in phase 4, "ntfy:home".
|
||||
|
||||
==== PHASE 3-4: configuration (strict TOML, as today) ====
|
||||
==== PHASE 3-4: configuration ====
|
||||
|
||||
Keys go through internal/pkg/config as today: strict keys in the file, an UBERBRINGER_<SECTION>_<KEY> variable for each setting, and [format] max_lines, timezone and time_layout already built.
|
||||
|
||||
[format] # max_lines is built
|
||||
timezone = "Local" # phase 2; IANA name, checked with time.LoadLocation
|
||||
time_layout = "02 Jan 15:04"
|
||||
[ntfy.format] # phase 3
|
||||
style = "auto" # auto | box | compact
|
||||
max_lines = 40
|
||||
@@ -371,19 +294,14 @@ DATA FLOW
|
||||
- /print/{module}: module.Build(body, Env) -> Validate (a failure here is a module bug, 422) -> Submit(job, Meta{Source: "module:<name>"}).
|
||||
- Subscriber (phase 4): ntfy stream -> skip, dedupe, filter, rate limit -> modules.FromNtfy -> Card -> Validate -> Submit(job, Meta{Source: "ntfy:<sub>", Ref: <ntfy id>}).
|
||||
|
||||
KEY TYPES (new or changed; the escpos interpreter, the blocks and Renderer.Preview are built)
|
||||
KEY TYPES (new or changed; the escpos interpreter, the blocks, Renderer.Preview and the module layer are built)
|
||||
|
||||
receipt
|
||||
TypeList (phase 2)
|
||||
Element gains Items []string, Done []int, Bullet (phase 2); Optional bool on image (phase 3)
|
||||
Element gains Optional bool on image (phase 3)
|
||||
func StripEmoji(s string) string (phase 3)
|
||||
|
||||
modules (phase 2; Notice and Card in phase 3)
|
||||
type Env struct{ Now time.Time; Location *time.Location; TimeLayout string; Card CardOptions }
|
||||
type Module interface{ Name() string; Description() string; Build(ctx context.Context, body []byte, env Env) (receipt.Job, error) }
|
||||
var ErrSkip = errors.New("nothing to print") // 204
|
||||
type PayloadError struct{ Problems []string } // 400
|
||||
type Registry; Get(name string) (Module, bool); List() []Info
|
||||
modules (built: Env, Module, ErrSkip, PayloadError, Registry, DecodeStrict, Note; phase 3 adds the rest)
|
||||
Env gains Card CardOptions
|
||||
type Notice struct{ ID, Topic, Title, Message string; Markdown bool; Priority int; Tags []string;
|
||||
Time time.Time; Links []Link; Image string; File *File; Updated bool }
|
||||
func FromNtfy(m ntfy.Message) (Notice, error) // ErrSkip for non-message events
|
||||
@@ -395,19 +313,13 @@ ntfy
|
||||
type Subscriber // phase 4
|
||||
func (s *Subscriber) Run(ctx context.Context, handle func(context.Context, Message) error) error
|
||||
|
||||
server
|
||||
Deps gains Modules (phase 2): Deps{Jobs, Printer, Previewer, Modules}
|
||||
|
||||
printqueue
|
||||
Submit(job receipt.Job, meta Meta) (Status, error)
|
||||
type Meta struct{ Source, Ref string }
|
||||
Status gains Source
|
||||
|
||||
BLOCK LAYOUT (receipt/blocklayout.go and receipt/glyphs.go)
|
||||
box, rule and kv are built; docs/design.md records their rules. list (phase 2) follows them: its width comes from the line at its size and font and from columns, every line it returns is exactly that width, and a narrower list is centred.
|
||||
- Bullets: "· ", "- ", "N. " (numbers right-aligned to the widest), "[ ] " and "[√] ".
|
||||
- Wrapped lines get a hanging indent.
|
||||
- √ falls back to x where the code page lacks it (cp850, cp858), chosen with CanEncode.
|
||||
box, rule, kv and list are built; docs/design.md records their rules.
|
||||
|
||||
TEXT NORMALIZATION (receipt/normalize.go)
|
||||
Built: NFC, the fold table and one '?' per emoji sequence on /print. Phase 3 adds StripEmoji for modules: it maps a few typed emoji to markers (⚠ to [!], ✅ to [√], ❌ to [x], 🚨 to (!), 👍 to (+1)), then removes the remaining emoji instead of printing '?'.
|
||||
@@ -519,80 +431,6 @@ Images and logging
|
||||
|
||||
## Phases
|
||||
|
||||
### Phase 2: Notes and the module layer (2 days)
|
||||
|
||||
**Goal.** Basic inputs print advanced layouts. POST /api/v1/print/note with {title, text, items} prints a boxed checklist, and the module layer is ready for notifications.
|
||||
|
||||
**Work.**
|
||||
|
||||
internal/pkg/receipt
|
||||
- TypeList: items, bullet, done.
|
||||
- Changes to job.go, block.go and blocklayout.go. list is allowed inside boxes.
|
||||
|
||||
internal/pkg/modules (new)
|
||||
- registry.go: the Module interface, Env, Info, Registry (Get, List), ErrSkip, PayloadError, and a strict JSON decode helper that collects every problem.
|
||||
- note.go: {title, text, items, done, style, footer, stamp} becomes a box with text, feed and a checkbox list. The default footer is Env.Now in [format].time_layout.
|
||||
|
||||
internal/app/uberbringer/server
|
||||
- Deps gains Modules.
|
||||
- Routes: POST /api/v1/print/:module, POST /api/v1/preview/:module and GET /api/v1/modules.
|
||||
- handlers_modules.go (new): route params are cloned with strings.Clone, as handleJob already does.
|
||||
- The shared s.submit(c, job) is extracted from handlePrint and keeps the queue-full (503 + Retry-After) and closed handling.
|
||||
- Error mapping: ErrSkip gives 204, PayloadError 400, unknown module 404, an invalid built job 422.
|
||||
- ?copies works on module routes. ?printer is reserved: 400 unless it is "default".
|
||||
|
||||
internal/pkg/config
|
||||
- [format] timezone (checked with time.LoadLocation) and time_layout.
|
||||
|
||||
internal/app/uberbringer
|
||||
- serve.go: builds the registry and the Env factory.
|
||||
- cli.go: `preview --module name payload.json`.
|
||||
|
||||
cmd/uberbringer/main.go
|
||||
- import _ "time/tzdata", because Windows builds have no zoneinfo.
|
||||
|
||||
Docs
|
||||
- README: a Modules section and the note payload table. Update configs/config.example.toml.
|
||||
|
||||
**Tests.**
|
||||
|
||||
internal/pkg/receipt
|
||||
- list goldens:
|
||||
- each bullet style
|
||||
- numbers 1-12, right-aligned
|
||||
- done items
|
||||
- hanging indent
|
||||
- [x] fallback on cp850
|
||||
- a list inside a box
|
||||
|
||||
internal/pkg/modules
|
||||
- note golden previews with a fixed clock in Europe/London:
|
||||
- title present and absent
|
||||
- with and without items
|
||||
- done items
|
||||
- every style
|
||||
- stamp=false
|
||||
- footer override
|
||||
- Payload validation:
|
||||
- unknown field
|
||||
- missing text
|
||||
- done index out of range
|
||||
- more than 200 items
|
||||
- Registry tests: lookup, List order, duplicate names.
|
||||
|
||||
internal/app/uberbringer/server
|
||||
- Using the fakeJobs pattern with a fake module: 202 with Location, 204, 400 with details, 404, 422, 503 when the queue is full, ?printer=office returns 400, and GET /modules.
|
||||
|
||||
internal/pkg/config
|
||||
- Rejects a bad timezone.
|
||||
|
||||
**Done when.**
|
||||
|
||||
- curl -d '{"title":"Shopping","text":"...","items":["Milk","Eggs","Bread"],"done":[2]}' /api/v1/print/note prints mockup 5.
|
||||
- /api/v1/preview/note shows the same lines.
|
||||
- GET /api/v1/modules lists note.
|
||||
- The full gate passes (CLAUDE.md lists it).
|
||||
|
||||
### Phase 3: Notifications, the notify and ntfy modules (3 days)
|
||||
|
||||
**Goal.** ntfy prints with minimal effort. The ntfy CLI posts $NTFY_RAW unchanged, and scripts can send {title, message, priority, tags}. Both print the same priority-styled card. Integration tokens can't send raw ESC/POS.
|
||||
@@ -604,7 +442,8 @@ internal/pkg/ntfy (new)
|
||||
|
||||
internal/pkg/modules
|
||||
- notice.go: the Notice type. Priority names min, low, default, high, max and urgent map to 1-5.
|
||||
- notify.go: strict decode into a Notice.
|
||||
- notify.go: strict decode with DecodeStrict into a Notice.
|
||||
- notify and ntfy are registered in newModules (internal/app/uberbringer/modules.go).
|
||||
- ntfy.go: lenient decode into ntfy.Message, then FromNtfy into a Notice. It returns ErrSkip for events other than message and for encoding=base64.
|
||||
- card.go: Card(Notice, CardOptions, Env) builds the receipt.Job using the priority ladder, title and markers, body cap, footer, links and QR, the attachment image or File row, and the updates policy.
|
||||
- markers.go: the tag and typed-emoji marker table, merged with the [ntfy.markers] overrides, then StripEmoji.
|
||||
@@ -619,7 +458,7 @@ internal/pkg/printqueue
|
||||
- Submit(job, Meta{Source, Ref}).
|
||||
- Status.Source.
|
||||
- Source and ref are added to the worker logs.
|
||||
- Callers in server and serve.go are updated.
|
||||
- The caller in server is updated: the Jobs interface and s.submit, which /print and the module routes share; module routes pass Meta{Source: "module:<name>"}.
|
||||
|
||||
internal/app/uberbringer/server
|
||||
- auth.go: parse the optional "mod" claim and enforce the allowed routes, returning 403 otherwise.
|
||||
@@ -632,7 +471,8 @@ internal/pkg/config
|
||||
- [ntfy.format] (style, max_lines, qr, images, markdown, updates) and [ntfy.markers], with validation.
|
||||
|
||||
Docs
|
||||
- README: notify and ntfy sections, the ntfy CLI recipe for Linux client.yml and Windows PowerShell, token scopes, and a warning that public ntfy.sh topics can be guessed. Update configs/config.example.toml.
|
||||
- docs/api.md: notify and ntfy sections under § Modules, the ntfy CLI recipe for Linux client.yml and Windows PowerShell, token scopes and their 403 code, and a warning that public ntfy.sh topics can be guessed.
|
||||
- README: `token --modules` under Command line and [ntfy.format] and [ntfy.markers] under Configuration. Update configs/config.example.toml.
|
||||
|
||||
**Tests.**
|
||||
|
||||
|
||||
Reference in new issue
Block a user