Record the owner's acceptance of the printers plan
The owner accepted every proposed default of docs/plans/printers.md on 2026-12-01. Its open questions become numbered decisions, without the alternatives, and design.md's Planned next item 2 records them. Decisions 6, 10 and 17 keep the wording that the remote-printers and templates plans had already settled. Decision 14 amends the owner's earlier wording: a rule that fails to compile stops the start rather than being skipped. The plan's acceptance edits are made, and its list of them goes. formatters.md loses its open question, which the routing example answers, and points to this plan for a second printer and per-model line spacing, without the printer pool's tests. job-store.md points to these decisions for the deliveries array, the stored route, failover after a sending mark, the lanes and their content bound, and a printer removed from the config. Its invariant 2 speaks of the job's bytes, since an anycast check sends DLE EOT before the mark. Its findings confirm the TM-m50II's command list and the power-on part of the automatic-status side finding. Phase 2b, phases 3c and 4 and phase 5 say how they meet several printers. The other plans cite printers decisions in place of questions, and templates decision 1 now follows printers decisions 12, 14, 15 and 17 rather than leaning on assumed defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f302b76ef4
commit
68bce4db59
6 files changed
+224
-263
No files matched your search
+11
-11
@@ -1,6 +1,6 @@
|
||||
# Plan: templates and rules in Expr, for ntfy and webhooks
|
||||
|
||||
Status: **planned; nothing is built.** The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item 5 records them. Each stage runs in its own session, briefed from its section: stage 1 follows decisions 1-11, stage 2 decisions 12-17, stage 3 decision 18, and stage 4 decisions 19-29. The stages run in order, except that stage 3 needs only stage 2, and stage 4 needs stages 1 and 2. This plan shares Expr with docs/plans/printers.md, whose questions still await the owner; where a stage leans on one of its assumed defaults, the decision here says so. Stage 4 leans on docs/plans/job-store.md in the same way, on its stage 1c and decision 10's duplicate check (decision 22). Every receipt printed on the live printer needs the owner's OK. Whichever stage finishes last deletes this plan, its findings with it, and design.md's Planned next item 5.
|
||||
Status: **planned; nothing is built.** The owner accepted every proposed default on 2026-12-01 (Decisions), and design.md's Planned next item 5 records them. Each stage runs in its own session, briefed from its section: stage 1 follows decisions 1-11, stage 2 decisions 12-17, stage 3 decision 18, and stage 4 decisions 19-29. The stages run in order, except that stage 3 needs only stage 2, and stage 4 needs stages 1 and 2. This plan shares Expr with docs/plans/printers.md; where a stage builds on one of its decisions, the decision here says so. Stage 4 builds on docs/plans/job-store.md in the same way, on its stage 1c and decision 10's duplicate check (decision 22). Every receipt printed on the live printer needs the owner's OK. Whichever stage finishes last deletes this plan, its findings with it, and design.md's Planned next item 5.
|
||||
|
||||
## Decisions (owner, 2026-11-30)
|
||||
|
||||
@@ -15,9 +15,9 @@ The owner accepted the details below on 2026-12-01. They are numbered, so the re
|
||||
|
||||
For stage 1:
|
||||
|
||||
1. **Who adds Expr and the shared engine.** printers.md adds Expr and `internal/pkg/rules` in its stage 2a, which may not have shipped when this plan starts. Whichever stage comes first adds Expr, at its latest stable release (v1.18.1, 2026-11-22, at the time of writing), with govulncheck, as printers.md question 10 plans. The licence notices and the binary's size, recorded in design.md, follow in the first commit that links Expr into the binary, since the notices come from what `./cmd/uberbringer` links (design.md:296-300). Stage 1 needs only the compile options both share, `rules.Options` (name assumed); stage 2 needs the engine. If printers stage 2a has not shipped by then, stage 2 builds `internal/pkg/rules` as printers.md's Architecture, ROUTING RULES, describes it, and printers stage 2a reuses it. If printers stage 2a has shipped with its options inline, stage 1's first commit moves them into `rules.Options` with no change in behaviour.
|
||||
- This leans on printers.md's assumed defaults for rule order (its question 12), compile errors (14), runtime errors (15) and compile options (17). An answer there that differs changes stage 2 here the same way.
|
||||
- Trade-off: the engine's interface is fixed here before the owner has answered printers.md. The first plan to ship carries the 5.3-5.8 MB that Expr adds.
|
||||
1. **Who adds Expr and the shared engine.** printers.md adds Expr and `internal/pkg/rules` in its stage 2a, which may not have shipped when this plan starts. Whichever stage comes first adds Expr, at its latest stable release (v1.18.1, 2026-11-22, at the time of writing), with govulncheck, as printers.md decision 10 plans. The licence notices and the binary's size, recorded in design.md, follow in the first commit that links Expr into the binary, since the notices come from what `./cmd/uberbringer` links (design.md:296-300). Stage 1 needs only the compile options both share, `rules.Options` (name assumed); stage 2 needs the engine. If printers stage 2a has not shipped by then, stage 2 builds `internal/pkg/rules` as printers.md's Architecture, ROUTING RULES, describes it, and printers stage 2a reuses it. If printers stage 2a has shipped with its options inline, stage 1's first commit moves them into `rules.Options` with no change in behaviour.
|
||||
- This follows printers.md's decisions on rule order (its decision 12), compile errors (14), runtime errors (15) and compile options (17).
|
||||
- Trade-off: the first plan to ship carries the 5.3-5.8 MB that Expr adds.
|
||||
2. **What a template is.** A template is one Expr expression, in one of two forms.
|
||||
- `card`: the expression returns a map of a notification's fields (`title`, `message`, `markdown`, `priority`, `tags`, `topic`, `time`, `links`, `image` and `file`), and the existing card lays it out, as for the `notify` and `ntfy` modules: the priority's form, links as QR codes, markers, and every cap a card applies (design.md:116-176). On a subscription, the card is marked `(updated)` from what the subscriber knows, as today's card is.
|
||||
- `elements`: the expression returns a list of elements, as a `/print` job's `elements` array. Expr's map and list literals and its `map`, `filter`, `concat` and `flatten` build it, so a template can lay out any receipt the blocks can.
|
||||
@@ -27,7 +27,7 @@ For stage 1:
|
||||
3. **Where templates live.** Templates live in the config file, as a list of tables, `[[templates]]`, read from the file only, as `[[ntfy.subscriptions]]` is. Each has `name`, `description`, `input` (`json` or `ntfy`, decision 5), `form` (`card` or `elements`), `expr`, the expression, best written as a TOML multi-line literal string so that quotes need no escaping, and `sample`, a sample payload in JSON, which is required.
|
||||
- A list of tables builds on the subscriptions' loader, so this plan does not wait for the named tables printers stage 1a adds, and `config get` already refuses to print one (config/value.go:28-30), samples included.
|
||||
- The sample needs only the fields the template reads, so a payload of many kilobytes can be cut down to a few lines.
|
||||
- No variable sets `[[templates]]`, nor, from later stages, `[[ntfy.rules]]` or `[webhooks]`. At start one WARN line names any `UBERBRINGER_TEMPLATES_*` or `UBERBRINGER_WEBHOOKS_*` variable, never its value, as printers.md question 2 does for its sections.
|
||||
- No variable sets `[[templates]]`, nor, from later stages, `[[ntfy.rules]]` or `[webhooks]`. At start one WARN line names any `UBERBRINGER_TEMPLATES_*` or `UBERBRINGER_WEBHOOKS_*` variable, never its value, as printers.md decision 2 does for its sections.
|
||||
- Trade-off: long templates make the config long, and the config holds `api.secret`, so whoever edits templates can read it.
|
||||
4. **Templates and the existing modules.** Every template is also a module. It appears in `GET /api/v1/modules` with its description, prints at `POST /api/v1/print/<name>` and previews at `POST /api/v1/preview/<name>`, with the same query (`copies`, `printer`), answers and token scopes as `note`, `notify` and `ntfy`. A `json` template takes a JSON object as its body, as the module routes document it (server/handlers_modules.go:21-23); an `ntfy` template takes one ntfy message object, decoded leniently as the `ntfy` module does.
|
||||
- Template names share the modules' namespace and pattern, `^[a-z][a-z0-9-]{0,31}$` (modules/registry.go:96). A template named like a built-in module is a config error.
|
||||
@@ -41,7 +41,7 @@ For stage 1:
|
||||
- Numbers: a body is decoded with `UseNumber`, and a whole number that fits 64 bits becomes an int, any other a float. Expr's `string()` prints a float in exponent form, so order 1234567 would print as `1.234567e+06`, and a 64-bit ID would lose digits. Expr's own `fromJSON` is replaced by one that decodes the same way.
|
||||
- Two helper functions: `cut(s, n)`, which keeps at most `n` characters and ends a cut string with `...`, as titles are cut; and `stamp(t)`, which formats a time in `format.timezone` with `format.time_layout`, as cards print times.
|
||||
- Trade-off: a template cannot read anything outside its payload, such as a printer's state or a value from another message.
|
||||
6. **Compile options and Expr's limits.** The options of printers.md question 17, shared through `rules.Options`: `now()` and `$env` turned off, `Timezone` set to `format.timezone` once it is known to load, and Expr's default node limit (10,000) and memory budget (1,000,000 per run). `now` is injected: the time the payload was received, so a dry-run and the tests reproduce any output. Expr does no I/O. Turning off `$env` needs v1.18 or later: v1.17.8's checker ignores it.
|
||||
6. **Compile options and Expr's limits.** The options of printers.md decision 17, shared through `rules.Options`: `now()` and `$env` turned off, `Timezone` set to `format.timezone` once it is known to load, and Expr's default node limit (10,000) and memory budget (1,000,000 per run). `now` is injected: the time the payload was received, so a dry-run and the tests reproduce any output. Expr does no I/O. Turning off `$env` needs v1.18 or later: v1.17.8's checker ignores it.
|
||||
- Expr counts no steps, and its VM takes no context, so a run cannot be stopped from outside (Investigation findings, EXPR). The text it loops over need not be the owner's: an issue's body or a commit message comes from whoever wrote it, and a `json` template on a module route takes a body from a token limited to modules. A predicate inside another, or `in` on a list inside a predicate, is quadratic in that text.
|
||||
- So a run has a budget of 1,000,000 iterations. A `Patch` visitor (name of the guard assumed) wraps the list of every predicate builtin (`map`, `filter`, `all`, `any`, `none`, `one`, `count`, `sum`, `find`, `groupBy`, `sortBy`, `reduce` and the like) and the right side of `in` in a guard that charges the list's length, passed through `WithContext`. A nested predicate is charged on each pass of the outer one, so the bound is the total. A run past the budget fails, as any run that fails (decisions 8 and 15).
|
||||
- A run still going after 1 s is logged at WARN with the template's or rule's name, from a timer, so even a run that never ends is seen.
|
||||
@@ -53,7 +53,7 @@ For stage 1:
|
||||
- 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.
|
||||
- Trade-off: a commit message over 4,096 bytes fails the receipt unless the template cuts it. A template cannot make an image required.
|
||||
8. **A template that fails on a module route.** A run fails when Expr returns an error or the result fails decision 7's checks. The route answers `422` with a new code, `template_failed`, whose `details` give the template's name and, for an Expr error, the line and column, never Expr's message. The failure is logged once at WARN with the template's name and position, and reported to Sentry once per template per run, without the message, as printers.md question 15 does for a rule. A result that fails validation gives its problems' paths only, such as `elements[2] (kv)`, since a problem's text can quote the payload.
|
||||
8. **A template that fails on a module route.** A run fails when Expr returns an error or the result fails decision 7's checks. The route answers `422` with a new code, `template_failed`, whose `details` give the template's name and, for an Expr error, the line and column, never Expr's message. The failure is logged once at WARN with the template's name and position, and reported to Sentry once per template per run, without the message, as printers.md decision 15 does for a rule. A result that fails validation gives its problems' paths only, such as `elements[2] (kv)`, since a problem's text can quote the payload.
|
||||
- Expr's messages quote values from the env, such as `invalid operation: int(alerts-door)` (printers.md, Investigation findings, EXPR), and the env holds print contents.
|
||||
- The error type lives in `modules` (`TemplateError`, name assumed), so the server matches it without importing templates or Expr (invariant 7).
|
||||
- `module_failed` stays for a built-in module's bug, which is a fault of the code; a template's failure is a fault of the config.
|
||||
@@ -68,7 +68,7 @@ For stage 1:
|
||||
|
||||
For stage 2:
|
||||
|
||||
12. **Where ntfy rules live, and their shape.** They live in `[[ntfy.rules]]`, a list of tables read from the file only, as `[[ntfy.subscriptions]]` is. Each rule has `name`, `order`, `when`, `action`, `template`, `bypass` (decision 16) and `enabled`, as printers.md's rules have (its questions 11 and 12): a unique name by the subscriptions' rule; a unique, required `order`, lower first, disabled rules included; and the first match wins. `when` sees decision 5's `ntfy` environment, `subscription` and `updated` included, so one list serves every subscription. `template` names a template whose `input` is `ntfy`; the config refuses one that does not.
|
||||
12. **Where ntfy rules live, and their shape.** They live in `[[ntfy.rules]]`, a list of tables read from the file only, as `[[ntfy.subscriptions]]` is. Each rule has `name`, `order`, `when`, `action`, `template`, `bypass` (decision 16) and `enabled`, as printers.md's rules have (its decisions 11 and 12): a unique name by the subscriptions' rule; a unique, required `order`, lower first, disabled rules included; and the first match wins. `when` sees decision 5's `ntfy` environment, `subscription` and `updated` included, so one list serves every subscription. `template` names a template whose `input` is `ntfy`; the config refuses one that does not.
|
||||
- Trade-off: a rule for one subscription says so in `when`.
|
||||
13. **The actions, and today's settings.** There are three actions.
|
||||
- `print`: print the message, through `template` if it names one, or as today's card if it is empty;
|
||||
@@ -77,7 +77,7 @@ For stage 2:
|
||||
- The rules run after the server's `min_priority` filter and after `updates = "skip"`, so a skipped update reaches no rule. `drop` and `digest` end there. `print` goes on through quiet hours, then the paper budget and `bypass_priority` (ntfy/subscriber.go:497-534). So the rules decide what prints and how, and the subscription's settings still decide when. A message no rule matches prints as today.
|
||||
- A rule does not route. Which printer prints stays with printers.md's `[routing]` rules; where both have shipped, the routing environment gains `template`, the template's name or empty, so a routing rule can send by template.
|
||||
- Trade-off: a dropped message counts nowhere but the DEBUG line, and two rule lists decide one message's fate.
|
||||
14. **What an ntfy rule sees, and its errors.** Unlike a routing rule, which sees routing facts only (printers.md question 16), an ntfy rule sees the message's title and text, since choosing by them is the point. Its runtime error is handled as printers.md question 15 has it: the rule does not match, the next is tried, and a WARN line gives the subscription, the rule's name and Expr's position, never the message, at most once a minute per rule. A rule's `Explain` output goes to the terminal only.
|
||||
14. **What an ntfy rule sees, and its errors.** Unlike a routing rule, which sees routing facts only (printers.md decision 16), an ntfy rule sees the message's title and text, since choosing by them is the point. Its runtime error is handled as printers.md decision 15 has it: the rule does not match, the next is tried, and a WARN line gives the subscription, the rule's name and Expr's position, never the message, at most once a minute per rule. A rule's `Explain` output goes to the terminal only.
|
||||
- A panic while the environment is built, a rule runs or a template's result is walked is recovered, since on the subscription's goroutine it would end the daemon: logged at ERROR, reported once, and then the rule does not match, or the card prints.
|
||||
- Trade-off: a rule can now read print contents, which raises the stakes of a log line that quotes it; the tests send a sentinel through every path (stage 2, Tests).
|
||||
15. **A template that fails on an ntfy message.** The message prints as today's card instead, so a broken template loses nothing. The failure is logged at WARN with the subscription, the template and the position, and reported once per template per run, as decision 8. A template that returns `nil` prints nothing, as a `drop` does.
|
||||
@@ -87,9 +87,9 @@ For stage 2:
|
||||
- Without `bypass`, a held message prints as a digest row, as today; docs/templates.md warns of it.
|
||||
- A rule's decision is made each time the subscription offers a message, and never stored. A message offered again after a full queue is decided again.
|
||||
- Trade-off: a `bypass` rule can print more than the budget allows, which is what `bypass_priority` already does by priority. A reload between two offers can change the decision.
|
||||
17. **Reloading.** Once printers stage 2b ships, SIGHUP swaps `[[templates]]`, `[[ntfy.rules]]` and, from stage 4, `[webhooks]` together with `[routing]`, as one snapshot behind one `atomic.Pointer`. A file that fails keeps the old snapshot, as printers.md question 20 has it. Until then, a change needs a restart.
|
||||
17. **Reloading.** Once printers stage 2b ships, SIGHUP swaps `[[templates]]`, `[[ntfy.rules]]` and, from stage 4, `[webhooks]` together with `[routing]`, as one snapshot behind one `atomic.Pointer`. A file that fails keeps the old snapshot, as printers.md decision 20 has it. Until then, a change needs a restart.
|
||||
- Each message and each request loads the snapshot once. The subscriber's decision carries an opaque handle to the compiled template, which ntfy hands back to `Handler.Message` untouched, so a reload between the two cannot leave a decision naming a template the snapshot lacks. A webhook's handler takes one value bound to one snapshot, its preset, secret, rules and templates, and uses only that.
|
||||
- Templates compile with the running `format.timezone` and lay out cards with the running card options, as printers.md question 20 compiles its rules, so `stamp`, `date()` and the cards agree. A reload resets the once-per-run reports, so a template fixed and broken again is reported again.
|
||||
- Templates compile with the running `format.timezone` and lay out cards with the running card options, as printers.md decision 20 compiles its rules, so `stamp`, `date()` and the cards agree. A reload resets the once-per-run reports, so a template fixed and broken again is reported again.
|
||||
- Trade-off: this plan adds no reload of its own.
|
||||
|
||||
For stage 3:
|
||||
|
||||
Reference in new issue
Block a user