From c778c3f98306e58493211f751f3a1b9c56bc9d7a Mon Sep 17 00:00:00 2001 From: William Gill Date: Tue, 1 Dec 2026 09:30:08 -0600 Subject: [PATCH] Record the owner's acceptance of the templates plan The owner accepted every proposed default of docs/plans/templates.md on 2026-12-01. Its open questions become numbered decisions, without the alternatives, and design.md's Planned next item 5 records them. The plan's acceptance edits are made: formatters.md's phase 5 points to the plan for user templates and webhook sources; printers.md's rules package also exports the shared compile options, its environment gains template and the source hook:, and its rule-visibility and reload questions name the templates plan; blocks.md says templates do not need the group; job-store.md's duplicate check takes webhook deliveries. Co-Authored-By: Claude Opus 5.5 --- docs/design.md | 29 +++++- docs/plans/blocks.md | 4 +- docs/plans/formatters.md | 8 +- docs/plans/job-store.md | 3 +- docs/plans/printers.md | 7 +- docs/plans/templates.md | 189 ++++++++++++++++----------------------- 6 files changed, 111 insertions(+), 129 deletions(-) diff --git a/docs/design.md b/docs/design.md index fe3a6c2..24b8255 100644 --- a/docs/design.md +++ b/docs/design.md @@ -519,10 +519,31 @@ not yet written is described here until it is. example receipt prints with the owner's OK and is pinned once he passes it. 5. **Templates and rules for webhooks and ntfy subscriptions**: - `docs/plans/templates.md` (written; its open questions await the - owner). Templates and rule actions use Expr, as in Kanrisha, sharing - the routing engine. Webhooks come after templates, since a webhook - needs a template to become a receipt. + `docs/plans/templates.md` (written; the owner accepted every proposed + default, 2026-12-01). Templates and rule actions use Expr, as in + Kanrisha, sharing the routing engine. Webhooks come after templates, + since a webhook needs a template to become a receipt. + - A template is one Expr expression in `[[templates]]`, checked at load + on the sample payload it carries. It returns a notification card's + fields or a list of elements, and every template is also a module, + with its own print and preview routes. + - Expr reads no clock, variable or file, and a run is bounded in nodes, + memory and iterations. Its output takes the strict job decoder: `raw` + and `hex` are refused, images are optional, and each job is laid out + before it is queued. Expr's messages quote the payload and are never + logged. + - `[[ntfy.rules]]` print a message through a template or as today's + card, drop it, or hold it for a digest of its own after `digest_wait`. + They run after the updates check; quiet hours and the paper budget + still apply, unless a rule sets `bypass`. A template that fails + prints the card instead. A rule's digest does not hold later + messages, which narrows the paper budget decision from stage 3 on. + - Webhooks arrive at `POST /hooks/{name}`, outside `/api/v1`. Each hook + has a secret and a preset for its sender's signature (`github`, + `gitea`, `forgejo`, `gitlab`, `standard` or `header`), checked on the + raw body first. A repeated delivery gets its first answer, and a + template that fails prints a fallback receipt. + - Templates do not need the `group` block. 6. **ntfy**: `docs/plans/ntfy.md` (not yet written). - The subscriber prefers ntfy's WebSocket endpoint (`//ws`), falls back to the JSON stream, and the transport is chosen per diff --git a/docs/plans/blocks.md b/docs/plans/blocks.md index fa1b347..9efd8c4 100644 --- a/docs/plans/blocks.md +++ b/docs/plans/blocks.md @@ -116,7 +116,7 @@ For stage 4, inline spans: For stage 5, the group: 22. **What a group holds.** `{"type": "group", "title": "Kitchen", "children": [...]}`. Its children are at least one element of any top-level type but `group`, `raw` and `cut`. They have no limit of their own, as a box's children have none: children of a group and children of a box inside it count toward the 500-element limit. `children` is shared with a box, so a limit of a group's own could not go into its tag. A group cannot go inside a box. It prints its heading, then each child as if it stood at the top level. - - The templates plan (the templates item of design.md's Planned next, docs/plans/templates.md) gets a container: one template value, such as one step of an `each`, can become several elements. + - Templates do not need it: Expr's `concat` and `flatten` turn one value into several elements of a flat list (docs/plans/templates.md, decision 11). A group gives a heading and a shared font where one is wanted. - `raw` is refused because the token scope is checked on top-level elements only (server/auth.go:135-150); stage 5 makes that check walk groups too, so the refusal does not rest on validation alone. `cut` is refused so that a group is never split by a cut. - Trade-off: no group inside a group. 23. **Keep-together.** A group adds nothing beyond what every receipt has. A job renders to one stream and is sent on one connection (design.md:39-46), so no other job's lines can come between a group's lines, and a receipt has no pages to break across. A group refuses `cut` (decision 22), so no cut falls inside one. The plan names keep-together only to record that it means nothing more on a receipt. @@ -186,7 +186,7 @@ Five blocks, each built alone when a need appears. Suggested order, when needs a 2. **Table** (stage 2): the block the owner described in most detail, and the one an order or a status list needs. The largest stage. 3. **Banner** (stage 3): small, and a candidate for the urgent card. 4. **Inline spans** (stage 4): touches the text path that every receipt uses, so its refactor is proven alone first. -5. **Group** (stage 5): most useful with templates (the templates item of design.md's Planned next), so best built when that plan needs it. +5. **Group** (stage 5): a heading and a shared font over several elements, built when one is wanted. Templates do not need it (docs/plans/templates.md, decision 11). What prints, on cp437 and a TM-T88 at size 1: diff --git a/docs/plans/formatters.md b/docs/plans/formatters.md index 2584896..67e17b1 100644 --- a/docs/plans/formatters.md +++ b/docs/plans/formatters.md @@ -42,15 +42,11 @@ INVARIANTS (all match the current code) - ?printer= on print, preview and modules; printer = "name" per subscription; optional priority routes - /healthz per printer, with the status still following the default printer - Jobs stay printer-neutral, so nothing in the block or module code changes. -- User templates (Design 2's safety model): - - JSON files with a typed payload schema - - text/template only inside string values; if and each keys - - element keys checked by reflection; templated hex rejected; output capped per field and per job - - every template's example run through Format and Validate at startup +- User templates: planned in docs/plans/templates.md. - An ntfy-compatible publish endpoint, POST /ntfy/{topic} and POST /ntfy, outside /api/v1. Auth is a Bearer JWT, or Basic with an empty user and the JWT as password. Tools that send to an ntfy server URL could then print directly. - More blocks: planned in docs/plans/blocks.md. - Queue.Cancel so message_delete can cancel a still-queued job. -- Webhook sources: /hooks/{name}, with auth always required, HMAC compared with hmac.Equal, and an unknown name rejected with 404 before the body is read. +- Webhook sources: planned in docs/plans/templates.md. - Default line spacing per model in escpos.Profile, once calibrated on each model. **Tests.** diff --git a/docs/plans/job-store.md b/docs/plans/job-store.md index 589afc2..35e9dc2 100644 --- a/docs/plans/job-store.md +++ b/docs/plans/job-store.md @@ -73,7 +73,8 @@ Before stage 1c: - An age limit, for privacy, would be another key. 10. **ntfy replays after a crash.** A subscription saves its state within a second of queueing a message. Today a job lost in a crash is replaced by the replay. Once queued jobs resume, a crash in that second would print the message twice. Assumed: - A `Submit` whose source and reference the queue already holds, from an ntfy subscription, returns the earlier job and queues nothing. Only ntfy jobs take part: on the HTTP routes the reference is a request ID, which a client may set, so a check on it could answer a new request with an old job. - - The queue keeps the last 512 (source, reference) pairs of each subscription with their job IDs, apart from the statuses, so `queue.history = 0` cannot defeat the check. + - Webhook jobs with a delivery ID take part too (docs/plans/templates.md, decision 22). The ID is the sender's, read only after the delivery's signature passed. + - The queue keeps the last 512 (source, reference) pairs of each subscription and each hook with their job IDs, apart from the statuses, so `queue.history = 0` cannot defeat the check. - A digest gets a reference of its own, a TypeID with the prefix `digest`, in place of the fixed `digest`, minted when the digest is made. The subscriber saves the digest with its reference before it submits it, so a restart submits the same digest under the same reference. The window also exists today, for a digest that printed in that second; stage 1c closes it. The saved digest is kept apart from messages held after it: were they added to a digest whose job was queued before the crash, the duplicate check would answer with that job, and they would never print. - Trade-off: a digest can cost one more state save, two fsyncs. 11. **A store write that fails after start** (disk full, an I/O error, corruption found mid-run). Assumed: the daemon stops. diff --git a/docs/plans/printers.md b/docs/plans/printers.md index 9b2e245..325da70 100644 --- a/docs/plans/printers.md +++ b/docs/plans/printers.md @@ -121,6 +121,7 @@ Before stage 2a: - A digest's `priority` is its highest row's, and its `topics` and `tags` the union of its rows'. - `topic`, `topics` and `tags` also print on a card, and a topic can be a secret. They are in the env because routing notifications by them is the main use. The facts are used at `Submit` only: they are never kept in the job's status, logged, stored or sent to Sentry, and neither is the env or an Expr run-time message (question 15). - Printer readiness stays out. Reading it at `Submit` would wait for each printer's connection slot, and flap with the passing states Epson printers report while cutting. It would come at the wrong moment, since the job prints later, and give another answer in a dry-run or after a restart. Only anycast acts on it, when it sends (questions 23 and 24). + - The rules of docs/plans/templates.md, for ntfy messages and webhooks, see print contents (its decision 14). A routing rule still sees routing facts only. - Trade-off: no rule can say "multicast when the kitchen is out of paper". - Alternative: content in the env too, for routing by what a job says. Expr's messages and a dry-run would then quote it, and a 4 MiB body in a string builtin can exceed Expr's memory budget, so the same rule would fail only on big jobs. 17. **Compile options and the clock.** Assumed: `expr.Env(routing.Env{})`, `expr.AsBool()`, `expr.DisableBuiltin("now")`, `expr.DisableBuiltin("$env")` and the default node limit. `expr.Timezone` takes `format.timezone` once validation has loaded the zone, since it panics on an unknown name. The clock is injected: `now` is the job's acceptance time in `format.timezone`, so a dry-run with `--at` and the tests reproduce any decision. No guard against literal ranges, since rules are trusted config. @@ -149,6 +150,7 @@ Before stage 2b: - Deliveries already queued keep their routes. - The unit gains `ExecReload`, so `systemctl reload uberbringer` works; a container takes `docker kill --signal HUP`; Windows, for development only, has no reload. Viper's `WatchConfig` is not used: it fires on an editor's partial saves. - With these checks, `Submit`'s guard for a printer with no lane cannot fire; it stays for a bug (Architecture, ROUTING RULES). + - The reload also swaps docs/plans/templates.md's templates, ntfy rules and webhooks, in one snapshot with `[routing]` (its decision 17). - Trade-off: more code and tests than a restart. A new printer, and a rule for it, need a restart. Until job-store stage 1d, a restart fails the waiting jobs, which a reload does not. - Alternative: no reload, which goes against the owner's decision ("swaps the rule set atomically on reload"). @@ -501,7 +503,7 @@ HEALTH (stage 1b) ROUTING RULES (stages 2a-2c) - Packages: - - `internal/pkg/rules` (new): a generic engine, importing only Expr. `Rule[A]` (`Name`, `Order`, `When`, `Enabled`, `Action`). `Compile[E, A]` compiles every rule against `E`'s zero value with question 17's options and joins every error, each naming its rule and position. `Set.Match(env)` returns the first enabled rule in `order` whose `when` is true, with the runtime errors of the rules before it. `Set.Explain(env)` gives every rule's result, error or "disabled", for the dry-run. `Engine` holds the current set behind an `atomic.Pointer`, with `Swap`, `Match` and `Explain`. Templates share it later (design.md, Planned next item 5). + - `internal/pkg/rules` (new): a generic engine, importing only Expr. `Rule[A]` (`Name`, `Order`, `When`, `Enabled`, `Action`). `Compile[E, A]` compiles every rule against `E`'s zero value with question 17's options and joins every error, each naming its rule and position. `Set.Match(env)` returns the first enabled rule in `order` whose `when` is true, with the runtime errors of the rules before it. `Set.Explain(env)` gives every rule's result, error or "disabled", for the dry-run. `Engine` holds the current set behind an `atomic.Pointer`, with `Swap`, `Match` and `Explain`. It also exports `Options`, the compile options and the iteration guard that docs/plans/templates.md shares; whichever of this stage and that plan's stages comes first builds what it needs of the package (its decision 1). - `internal/pkg/routing` (new): `Env` and how it is built; the action (`Mode`, `To`) and its resolution against the printers and groups; the `printqueue.Router` it implements. - printqueue defines `Route` and `Router`; it, the server and config never import Expr. Imports: routing → rules, printqueue, receipt; rules → Expr; internal/app → routing. - config checks structure only: names, `order`, modes, `to`. The load helper in internal/app compiles the rules, so `config get` fails on a bad rule before install.sh restarts the daemon. @@ -567,7 +569,7 @@ THE ENVIRONMENT (stages 2a and 2c; question 16) | Variable | Type | Stage | Value | |---|---|---|---| -| `source` | string | 2a | `print`, `module:` or `ntfy:`, as job status shows it | +| `source` | string | 2a | `print`, `module:`, `ntfy:` or, from docs/plans/templates.md stage 4, `hook:`, as job status shows it | | `module` | string | 2a | the module's name on a module route; else empty | | `subscription` | string | 2a | the subscription's name for its jobs; else empty | | `copies` | int | 2a | the copies the job prints, 1-5 | @@ -584,6 +586,7 @@ THE ENVIRONMENT (stages 2a and 2c; question 16) | `priority` | int | 2c | 1-5 for a notification (3 when it gives none); a digest's highest row's; 0 for other jobs | | `tags` | list | 2c | a notification's tags; the tags of a digest's rows; else empty | | `digest` | bool | 2c | true for a digest | +| `template` | string | 2c | the template the job was built through, by its module route, an ntfy rule or a webhook, once docs/plans/templates.md stage 1 has shipped (its decision 13); else empty | Rules the probe compiled and ran against this env: `source == "ntfy:alerts"`; `source startsWith "ntfy:" && priority >= 4`; `"urgent" in tags || priority == 5`; `weekday in ["sat", "sun"] || clock >= "22:00" || clock < "07:00"`; `"image" in types && bytes > 100000`; `now.Hour() >= 22`; `any(tags, # startsWith "kitchen")`; `topic matches "^alerts-"`; `module == "note" && copies > 1`. diff --git a/docs/plans/templates.md b/docs/plans/templates.md index d652487..4ece981 100644 --- a/docs/plans/templates.md +++ b/docs/plans/templates.md @@ -1,6 +1,6 @@ # Plan: templates and rules in Expr, for ntfy and webhooks -Status: **planning; nothing is built.** Each stage runs in its own session, briefed from its section, once the owner has answered the questions listed for it or accepted their assumed defaults: stage 1 needs questions 1-11, stage 2 needs 12-17, stage 3 needs 18, and stage 4 needs 19-29. Each answer goes into design.md at once and leaves this list. 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 question here says so. Stage 4 leans on docs/plans/job-store.md in the same way, on its stage 1c and question 10's duplicate check (question 22). Every receipt printed on the live printer needs the owner's OK. When the owner accepts the plan, the edits under Overview, ON ACCEPTANCE, are made. 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, 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 question 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) @@ -11,125 +11,104 @@ Status: **planning; nothing is built.** Each stage runs in its own session, brie - **Webhooks come after templates,** since a webhook needs a template to become a receipt. -## Open questions +The owner accepted the details below on 2026-12-01. They are numbered, so the rest of the plan can refer to them. -Each has the default the plan assumes unless the owner says otherwise. +For stage 1: -Before 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. Assumed: 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. +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. - - Alternative: wait for printers stage 2a before stage 2. -2. **What a template is.** Assumed: one Expr expression, in one of two forms. +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. - A template that returns `nil` prints nothing, so it can pass over a payload it has no receipt for. - A template builds a `receipt.Job`, which takes the same path as any job: validation, the queue, then rendering in full before anything is sent. - - Trade-off: the shape of an `elements` result is checked only when it runs, not when it compiles: a JSON body has no Go type, so Expr types `body` as `any`. Question 9 runs every template on its sample at load to catch most mistakes early. - - Alternatives: a JSON or TOML skeleton of elements with Expr only in its values, plus `each` and `if` keys (formatters.md's "User templates" item with Expr in place of `text/template`), which fixes the structure at load but needs its own walker and a marker that tells an expression from a literal; or the `card` form alone, the smallest, which cannot print a table of commits or an order. -3. **Where templates live.** Assumed: 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`, question 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. + - Trade-off: the shape of an `elements` result is checked only when it runs, not when it compiles: a JSON body has no Go type, so Expr types `body` as `any`. Decision 9 runs every template on its sample at load to catch most mistakes early. +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. - Trade-off: long templates make the config long, and the config holds `api.secret`, so whoever edits templates can read it. - - Alternatives: named tables, `[templates.]`, on printers stage 1a's key kind; a directory of files (`templates.dir`, one `.toml` each, holding the same keys), which keeps the config short but adds a second loader and a second place to reload from; or `sample_file`, a path, beside `sample`. -4. **Templates and the existing modules.** Assumed: every template is also a module. It appears in `GET /api/v1/modules` with its description, prints at `POST /api/v1/print/` and previews at `POST /api/v1/preview/`, 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. +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/` and previews at `POST /api/v1/preview/`, 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. - - So a script that can send a bearer token uses a template without a webhook, a token from `uberbringer token --modules ` limits it to that template, and the preview route is the dry-run over HTTP (question 10). `uberbringer token` reads the config before it checks the names, which today it checks against the built-in modules only (internal/app/uberbringer/cli.go:156-161). + - So a script that can send a bearer token uses a template without a webhook, a token from `uberbringer token --modules ` limits it to that template, and the preview route is the dry-run over HTTP (decision 10). `uberbringer token` reads the config before it checks the names, which today it checks against the built-in modules only (internal/app/uberbringer/cli.go:156-161). - Emoji are removed from the text fields of what a template returns (`text`, `title`, `footer`, `key`, `value`, list items and the card's fields), as on the notification path (design.md:134-138), rather than printed as `?`. `url`, `data` and `base64` are left as they are. The `note` module keeps printing them as `?`. - `GET /api/v1/modules` lists every template's name and description to any token, those limited to other modules included. docs/security.md says so. - Trade-off: the module list now depends on the config, and a later release whose new built-in module takes a template's name refuses that config at start, which is **Breaking** for it. - - Alternatives: templates reachable only through ntfy rules and webhooks, with no route of their own; or a list that shows a limited token only the modules it names. -5. **What a template sees.** Assumed: a typed environment per input, a Go struct whose `expr` tags name the variables, as printers.md's `routing.Env` is. Architecture, THE ENVIRONMENTS, lists them. +5. **What a template sees.** A template sees a typed environment per input, a Go struct whose `expr` tags name the variables, as printers.md's `routing.Env` is. Architecture, THE ENVIRONMENTS, lists them. - `json`: `body`, the decoded body; and `now`. Stage 4 adds a webhook's `hook`, `event`, `delivery` and `headers`, which are empty on a module route. - `ntfy`: a message's fields, those `FromNtfy` uses (modules/ntfy.go:85-119), the subscription's name and `now`. `http`, `broadcast` and `copy` actions stay out, since their headers, bodies and values can hold secrets (ntfy/message.go:104-116). - 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. - - Alternative: no helpers; Expr's string slicing and `t.Format(...)` do the same with more care from the author. -6. **Compile options and Expr's limits.** Assumed: printers.md question 17's options, 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 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. - 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 (questions 8 and 15). + - 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. - 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. - - Alternatives: no guard, trusting the owner's templates; a visitor that refuses a predicate inside another, which also fails templates that are fine on small bodies; or each run on its own goroutine with a deadline, which ends the wait but not the run, and leaks it. -7. **What a template's output may hold.** Assumed: +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. - 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. - Trade-off: a commit message over 4,096 bytes fails the receipt unless the template cuts it. A template cannot make an image required. - - Alternative: cut text fields over the limit instead of failing. -8. **A template that fails on a module route.** A run fails when Expr returns an error or the result fails question 7's checks. Assumed: 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 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. - 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. - - Trade-off: the answer does not say what went wrong; `uberbringer template` (question 10) does, on the terminal. A sender whose payloads vary, so that some lack a field the template reads, sends one Sentry event per template per run. - - Alternative: print a plain fallback receipt naming the template, as a webhook does (question 24). -9. **Checking templates at load.** Assumed: at start, in `config get` and in `preview`, each template compiles, runs on its sample, and its result passes question 7's checks and renders in full through the text preview, which fetches nothing. Any failure is a config error naming the template. A compile error gives Expr's position and message, which quotes the template, not data. A failure on the sample gives the position only and points to `uberbringer template `, since a sample may be a captured payload with private data. + - Trade-off: the answer does not say what went wrong; `uberbringer template` (decision 10) does, on the terminal. A sender whose payloads vary, so that some lack a field the template reads, sends one Sentry event per template per run. +9. **Checking templates at load.** At start, in `config get` and in `preview`, each template compiles, runs on its sample, and its result passes decision 7's checks and renders in full through the text preview, which fetches nothing. Any failure is a config error naming the template. A compile error gives Expr's position and message, which quotes the template, not data. A failure on the sample gives the position only and points to `uberbringer template `, since a sample may be a captured payload with private data. - So `config get` and `preview` fail on any broken template, even for a job that uses none. docs/cli.md says so. - Trade-off: a template whose sample is not representative still fails on real payloads. - - Alternative: compile only, and let the first payload find the rest. -10. **The dry-run and the preview.** Assumed: a command, `uberbringer template [payload.json|-]`, reads the config, runs the template on the payload, or on its sample without one, and prints the text preview, or with `--json` the built job. It prints Expr's message in full, on the terminal only. It sends nothing and fetches nothing. Over HTTP, `POST /api/v1/preview/` previews a template with any payload (question 4). `uberbringer preview --module ` works too, since a template is a module. +10. **The dry-run and the preview.** A command, `uberbringer template [payload.json|-]`, reads the config, runs the template on the payload, or on its sample without one, and prints the text preview, or with `--json` the built job. It prints Expr's message in full, on the terminal only. It sends nothing and fetches nothing. Over HTTP, `POST /api/v1/preview/` previews a template with any payload (decision 4). `uberbringer preview --module ` works too, since a template is a module. - Trade-off: two commands overlap; `template` alone shows Expr's message and the job. - - Alternative: only `preview --module`, with a flag for the full message. -11. **The `group` block.** blocks.md expects the group to be built with templates (its decision 22). Assumed: templates do not need it. This changes the reason blocks.md decision 22 gives for the group, an accepted decision; accepting this default amends that bullet and blocks.md's Overview item 5. Expr's `concat` and `flatten` turn one value into several elements of a flat list, which is what decision 22 names the group for. A group still comes with blocks.md stage 5 when a heading or a shared font is wanted, and question 7's `raw` check then walks it. +11. **The `group` block.** blocks.md expects the group to be built with templates (its decision 22). Templates do not need it. This changes the reason blocks.md decision 22 gives for the group, and that bullet and blocks.md's Overview item 5 say so. Expr's `concat` and `flatten` turn one value into several elements of a flat list, which is what decision 22 names the group for. A group still comes with blocks.md stage 5 when a heading or a shared font is wanted, and decision 7's `raw` check then walks it. - Trade-off: a template that wants a heading and a shared font for each item sets them on each element itself. - - Alternative: build the group first, so that templates can return one per item. -Before stage 2: +For stage 2: -12. **Where ntfy rules live, and their shape.** Assumed: `[[ntfy.rules]]`, a list of tables read from the file only, as `[[ntfy.subscriptions]]` is. Each rule has `name`, `order`, `when`, `action`, `template`, `bypass` (question 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 question 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 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. - Trade-off: a rule for one subscription says so in `when`. - - Alternative: a list in each subscription, `[[ntfy.subscriptions.rules]]`, which needs a second level of per-entry defaults in the loader. -13. **The actions, and today's settings.** Assumed: three actions. +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; - `drop`: leave the message out, with a DEBUG line naming the rule; - - `digest` (stage 3): hold the message for a digest of its own (question 18). + - `digest` (stage 3): hold the message for a digest of its own (decision 18). - 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. - - Alternative: a `to` on these rules that names a printer or group and skips `[routing]`. -14. **What an ntfy rule sees, and its errors.** Assumed: 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 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. - 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). - - Alternative: rules on topic, priority and tags only, which cannot drop a test message by its title. -15. **A template that fails on an ntfy message.** Assumed: 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 question 8. A template that returns `nil` prints nothing, as a `drop` does. +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. - Trade-off: a broken template's messages print in the wrong shape until someone reads the log. - - Alternative: drop the message, or hold it for the digest. -16. **Held messages, `bypass`, and offers again.** Today a message the budget or quiet hours hold prints as a row of the digest: its title, or the first line of its text cut to 256 bytes (ntfy/ratelimit.go:113-139). A templated message's body is often the point: the `shop-order` example's text is JSON, so its row would read `{"number": 42, …` and the order's lines would never print. Assumed: +16. **Held messages, `bypass`, and offers again.** Today a message the budget or quiet hours hold prints as a row of the digest: its title, or the first line of its text cut to 256 bytes (ntfy/ratelimit.go:113-139). A templated message's body is often the point: the `shop-order` example's text is JSON, so its row would read `{"number": 42, …` and the order's lines would never print. - A `print` rule may set `bypass = true`: the message skips the paper budget, as one at `bypass_priority` does. During quiet hours `quiet.min_priority` still decides first, as design.md's paper budget decision has it. - 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. - - Alternatives: no `bypass`, so that a templated subscription sets `bypass_priority` at or below its messages' priority; or store the template's name with each held message and print the digest's rows through it, which digest rows cannot hold. -17. **Reloading.** Assumed: 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 question 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. - Trade-off: this plan adds no reload of its own. - - Alternative: a reload here, before printers stage 2b, which would then build on it. -Before stage 3: +For stage 3: -18. **The `digest` action.** Today a held message prints as soon as the budget has room (ntfy/subscriber.go:616-628), so a message a rule holds would print at once as a digest of one. Assumed: a new subscription key, `digest_wait` (default `1h`, 1 minute to 24 hours), and rule-held messages kept apart from those the budget and quiet hours hold. +18. **The `digest` action.** Today a held message prints as soon as the budget has room (ntfy/subscriber.go:616-628), so a message a rule holds would print at once as a digest of one. So a new subscription key, `digest_wait` (default `1h`, 1 minute to 24 hours), sets how long a rule holds them, and rule-held messages are kept apart from those the budget and quiet hours hold. - The rule's digest prints once its oldest message has waited `digest_wait`, then as the budget and quiet hours allow, as one budgeted receipt. - - Today a waiting digest holds every later message below `bypass_priority`, so that they print in order (ntfy/subscriber.go:518; design.md, "The paper budget is a strict window"). That check counts only the messages the budget and quiet hours hold, so a message no rule matches still prints as today. This narrows the owner's decision that later messages join a waiting digest to the digests the budget and quiet hours make; accepting this default amends it. + - Today a waiting digest holds every later message below `bypass_priority`, so that they print in order (ntfy/subscriber.go:518; design.md, "The paper budget is a strict window"). That check counts only the messages the budget and quiet hours hold, so a message no rule matches still prints as today. This narrows the owner's decision that later messages join a waiting digest to the digests the budget and quiet hours make, from stage 3 on. - The saved state keeps the rule's held messages and when the first came, as new fields of the state file's version 1, which an older binary ignores (ntfy/state.go:22-23), so a restart keeps the wait. - Trade-off: one more key and a second held set; a budget digest and a rule digest can print close together as two receipts. - - Alternatives: one held set, as today, where the next message held for any reason ends the wait and prints as a row of the digest; a time of day, `digest_at`, like a morning paper; or no `digest` action until one is asked for. -Before stage 4: +For stage 4: -19. **The route, and its rate limit.** Assumed: `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. +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). - 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 (question 28). - - Alternatives: `/api/v1/hooks/{name}`, which would need the bearer middleware to step aside for one route; `401` for an unknown name too; or `/api/v1`'s limiter in front, as for every other route. -20. **Authentication.** Assumed: 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. + - 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. - The signature is checked on the body's bytes as they came, Fiber's `BodyRaw`, before the body is parsed, and compared with `hmac.Equal`. `header` compares SHA-256 digests of the two in constant time, so the comparison does not tell the secret's length. A missing, malformed or wrong signature answers `401` with a new code, `invalid_signature`, and no detail. - `gitlab` and `standard` pass over a signature of another version in the header, such as `v1a`, and check every `v1` one it lists. A `whsec_` secret that is not base64, or gives fewer than 24 bytes, is a config error. - `header` takes `Authorization` or `X-Gitlab-Token` only, and with `Authorization` the secret is the whole value, scheme included, as Gitea and Forgejo send what was typed. Caddy redacts `Authorization` in its access log by default, but not `X-Gitlab-Token`, so install.sh's log filter deletes that header too. @@ -137,11 +116,9 @@ Before stage 4: - `config get` prints no hook: `[[webhooks.hooks]]` is a list of tables, which it refuses (config/value.go:28-30), and a test holds that. - For `github`, `gitea`, `forgejo` and `header`, a secret is made straight into a 0600 file, `umask 077; uberbringer secret > /etc/uberbringer/hook-forge.secret`, and pasted into the sender's settings from that file. For `gitlab` and `standard`, the sender makes the secret, `whsec_` and 24-64 random bytes in base64, and it is written into the file with an editor, never on a command line. docs/templates.md signs its test request with a script that reads the secret from the file, never with `openssl -hmac` on the command line. - Trade-off: `header` sends the secret itself on every request, so it is only as safe as TLS to the proxy and the proxy's log. - - Alternatives: also a bearer token with a new claim naming hooks (question 25); `header` with any header name, each to be kept out of the proxy's log by hand; or `header` left out, which shuts out senders that cannot sign, such as GitLab before 19.1. -21. **Bodies and content types.** Assumed: a JSON object only, as on the module routes, sent as `application/json` or a `+json` type in UTF-8, decoded with `UseNumber` and refused with trailing data, as the `ntfy` module refuses it (modules/ntfy.go:54-63). Anything else answers `415` with a new code, `unsupported_media_type`, whose message says to choose JSON in the sender's settings; GitHub and Gitea can send a form instead. So does a `Content-Encoding` other than `identity`, before any hashing: Fiber's `Body` would inflate a compressed body first, and on a broken one return the error's text as the body. None of the senders compresses. A body that is not a JSON object is `400` `invalid_payload`. The body limit is `webserver.body_limit` (4 MiB), applied before routing, by Caddy too. +21. **Bodies and content types.** A hook takes a JSON object only, as on the module routes, sent as `application/json` or a `+json` type in UTF-8, decoded with `UseNumber` and refused with trailing data, as the `ntfy` module refuses it (modules/ntfy.go:54-63). Anything else answers `415` with a new code, `unsupported_media_type`, whose message says to choose JSON in the sender's settings; GitHub and Gitea can send a form instead. So does a `Content-Encoding` other than `identity`, before any hashing: Fiber's `Body` would inflate a compressed body first, and on a broken one return the error's text as the body. None of the senders compresses. A body that is not a JSON object is `400` `invalid_payload`. The body limit is `webserver.body_limit` (4 MiB), applied before routing, by Caddy too. - Trade-off: a GitHub event larger than 4 MiB (GitHub caps them at 25 MB) is refused unless `body_limit` is raised for the whole server. - - Alternatives: also take the form encoding: for GitHub, verify the raw form body; for Gitea and Forgejo, decode the form and verify its `payload` field, which is what they sign. Or a limit per hook, which fasthttp cannot apply before it has read the body. -22. **Replays and repeats.** Assumed: +22. **Replays and repeats.** - `gitlab` and `standard` refuse a timestamp more than 5 minutes from the host's clock, `401` `invalid_signature`. The specification leaves the window open. A Raspberry Pi without a clock that boots with the wrong time refuses them until its clock is set; docs/templates.md says to start the daemon after the time is synced. - A delivery's ID, where its preset has one, becomes the job's reference, with the source `hook:`. An ID longer than 128 bytes, or with a byte that is not visible ASCII, is ignored, and the ID and the header values are copied out of fasthttp's buffers, as the request ID is. - The ID is reserved under a lock before the rules run, so a second delivery with it, sent while the first is in hand, waits and gets the first's answer. It is recorded with the job's ID after a `202`, and as "nothing printed" after a `204`, so a repeat gets the same answer. After any other answer it is released, so a retry runs again. @@ -149,34 +126,26 @@ Before stage 4: - This leans on job-store question 10's assumed default, which leaves the HTTP routes' jobs out because a client chooses their reference. A hook's ID is read only after its signature passed, which is why hook jobs may join. - What it covers: a GitHub redelivery keeps its ID, and so do a Standard Webhooks retry and GitLab's retries, so none prints twice. Gitea and Forgejo give each attempt a new ID, a manual replay included, so a replay prints again, as the person replaying asked. GitHub's ID is not signed, so someone who captured a whole request could send it again under a new ID; only `gitlab` and `standard` sign theirs. - Trade-off: without the job store, a restart forgets the IDs. - - Alternative: a timestamp header of our own, which no sender sends. -23. **Webhook rules.** Assumed: `[[webhooks.rules]]`, shaped as `[[ntfy.rules]]` (question 12) less `bypass`, seeing question 5's `json` environment with `hook`, `event`, `delivery` and `headers` set. Actions are `print`, which needs `template`, and `drop`. A hook's own `template` key is what prints when no rule matches; a hook without one prints nothing then. So a hook for one kind of event needs no rule, and `event == "push"` picks Gitea's pushes out of everything else. `template` names a template whose `input` is `json`. +23. **Webhook rules.** They are `[[webhooks.rules]]`, shaped as `[[ntfy.rules]]` (decision 12) less `bypass`, seeing decision 5's `json` environment with `hook`, `event`, `delivery` and `headers` set. Actions are `print`, which needs `template`, and `drop`. A hook's own `template` key is what prints when no rule matches; a hook without one prints nothing then. So a hook for one kind of event needs no rule, and `event == "push"` picks Gitea's pushes out of everything else. `template` names a template whose `input` is `json`. - `headers` holds a list of allowed headers by lowercased name: `content-type`, `user-agent`, and the senders' own `x-github-*`, `x-gitea-*`, `x-gogs-*`, `x-forgejo-*` and `x-gitlab-*` headers and `webhook-id`, less every signature and token header among them. The header a `header` hook compares is never in it, so no template can print a secret. Repeated headers are joined with `, `. - The rules sit in `[webhooks]` beside the hooks, as printers.md's sit in `[routing]` beside its groups, so a hook can be named anything. - Trade-off: two places say which template prints. - - Alternative: rules only, with no `template` key on a hook. -24. **What a sender is answered.** Assumed: +24. **What a sender is answered.** - `202` with the job and `Location`, as `/print` answers; `204` when nothing prints: a `drop`, no match, a template that returns `nil`, or an event the preset answers itself after the signature passed, GitHub's `ping`. - - A template that fails on a hook prints a short fallback receipt that quotes nothing of the delivery: the hook, the event, the delivery's ID, the template's name and its position. It answers `202`, logs at WARN and reports once per template per run, as question 8. GitHub never retries a failed delivery, and GitLab turns a hook off for a while after four failures in a row, so an event the template does not handle, such as a branch deleted with no commits, would otherwise lose that delivery or every later one. - - `400` `invalid_payload`; `401` `invalid_signature`; `404` `hook_not_found`; `413` `body_too_large`; `415` `unsupported_media_type`; `429` `rate_limited`; `503` `queue_full` or `shutting_down`. A repeat gets the first delivery's answer (question 22). - - Nothing waits for the printer, so an answer takes as long as the template's run, which question 6's budget bounds: well inside GitHub's 10-second limit. + - A template that fails on a hook prints a short fallback receipt that quotes nothing of the delivery: the hook, the event, the delivery's ID, the template's name and its position. It answers `202`, logs at WARN and reports once per template per run, as decision 8. GitHub never retries a failed delivery, and GitLab turns a hook off for a while after four failures in a row, so an event the template does not handle, such as a branch deleted with no commits, would otherwise lose that delivery or every later one. + - `400` `invalid_payload`; `401` `invalid_signature`; `404` `hook_not_found`; `413` `body_too_large`; `415` `unsupported_media_type`; `429` `rate_limited`; `503` `queue_full` or `shutting_down`. A repeat gets the first delivery's answer (decision 22). + - Nothing waits for the printer, so an answer takes as long as the template's run, which decision 6's budget bounds: well inside GitHub's 10-second limit. - Trade-off: a broken template prints a fallback for each delivery until it is fixed. GitHub does not retry, so a `503` there is lost unless someone redelivers it. - - Alternatives: `422` `template_failed` and nothing printed, as on a module route; or a `2xx` with nothing printed and a WARN line. -25. **Token scopes.** Assumed: no new claim. A template is a module, so a `mod` claim names it (question 4). A hook takes no bearer token: its secret is its scope, and opens that hook alone. Agent tokens (docs/plans/remote-printers.md decision 6) are bearer tokens and open nothing here. +25. **Token scopes.** No new claim is added. A template is a module, so a `mod` claim names it (decision 4). A hook takes no bearer token: its secret is its scope, and opens that hook alone. Agent tokens (docs/plans/remote-printers.md decision 6) are bearer tokens and open nothing here. - Trade-off: a sender that can send a bearer token but cannot sign uses the template's module route, not `/hooks`. - - Alternative: a `hook` claim listing hooks a bearer token may call, as `mod` lists modules. -26. **Presets for common senders.** Assumed: the signature presets of question 20 ship, each tested against its sender's documented scheme, GitHub's test values included. No template ships: docs/templates.md shows one for a Gitea push, the owner's own forge. +26. **Presets for common senders.** The signature presets of decision 20 ship, each tested against its sender's documented scheme, GitHub's test values included. No template ships: docs/templates.md shows one for a Gitea push, the owner's own forge. - Trade-off: everyone writes their own template. - - Alternative: shipped templates for GitHub and Gitea pushes, issues and releases, each a receipt to check on paper and to keep in step with the senders' payloads. -27. **Privacy.** Assumed: a webhook's body and headers are print contents. They never reach logs, Sentry, job status or an error answer, and neither does a template's output. The request line logs the path, so the hook's name, as it does for module names. A refused signature is a refusal, logged by the request line only and never sent to Sentry. +27. **Privacy.** A webhook's body and headers are print contents. They never reach logs, Sentry, job status or an error answer, and neither does a template's output. The request line logs the path, so the hook's name, as it does for module names. A refused signature is a refusal, logged by the request line only and never sent to Sentry. - Trade-off: a sender whose signatures fail shows only `401` lines; `uberbringer rules hook` (stage 4) does not check signatures, so a mismatched secret is found by comparing it by hand. - - Alternative: a WARN line per refused signature naming the hook, which a flood would fill. -28. **A hook's paper budget and quiet hours.** Assumed: none. A hook prints at once, as `/print` does; `drop` rules on `event` or `body` thin it out. - - Trade-off: a sender that floods with valid deliveries prints every one, and nothing slows it but the rules, since question 19 puts no limit in front of a valid signature. - - Alternatives: a limit per hook on valid deliveries, answered `429`, which GitHub would not retry; a `rate_limit`, `rate_window` and `quiet` per hook with a digest, as subscriptions have, which needs the subscriber's held set and state file outside ntfy; or a `digest` action for hooks. -29. **Where it is documented.** Assumed: a new page, docs/templates.md: templates, their environments and forms, ntfy rules, webhooks and their presets, with the Gitea example. docs/configuration.md lists the keys and points there; docs/api.md gets `/hooks/{name}`, the new codes and templates under Modules. README's documentation table, CLAUDE.md's "Read first" and `.goreleaser.yaml`'s archive files list the new page. +28. **A hook's paper budget and quiet hours.** A hook has neither. It prints at once, as `/print` does; `drop` rules on `event` or `body` thin it out. + - Trade-off: a sender that floods with valid deliveries prints every one, and nothing slows it but the rules, since decision 19 puts no limit in front of a valid signature. +29. **Where it is documented.** On a new page, docs/templates.md: templates, their environments and forms, ntfy rules, webhooks and their presets, with the Gitea example. docs/configuration.md lists the keys and points there; docs/api.md gets `/hooks/{name}`, the new codes and templates under Modules. README's documentation table, CLAUDE.md's "Read first" and `.goreleaser.yaml`'s archive files list the new page. - Trade-off: one more page in the release archives. - - Alternative: § templates and § webhooks in docs/configuration.md, as printers.md does with § routing. ## Investigation findings @@ -185,7 +154,7 @@ Research ran on 2026-12-01: the repository at 8b9e838, Kanrisha's `internal/poli EXPR - proxy.golang.org gives v1.18.1 (2026-11-22) as the latest release, as printers.md found. Its advisories and size are in printers.md's findings. - Defaults at v1.18.1 (`conf/config.go`): a node limit of 10,000 (`MaxNodes`, 0 turns it off) and a memory budget of 1,000,000 per run, which a `vm.VM` can set per run. Running out is an error, not a panic. The budget is charged for ranges, arrays, maps and sorts the run makes, not for passes over a list it already has (`vm/vm.go`). -- The VM takes no context and counts no steps (`vm/vm.go`). `WithContext` passes a context to functions that take one, which is what question 6's guard uses. +- The VM takes no context and counts no steps (`vm/vm.go`). `WithContext` passes a context to functions that take one, which is what decision 6's guard uses. - `DisableBuiltin("$env")` works at v1.18.1, whose checker reads the disabled set; at v1.17.8 it does nothing. - `string()` formats with `%v` (`builtin/lib.go`), so a float prints as `1.234567e+06`. The probe also gave `invalid operation: int(s3cr3t-value)` for a runtime error, quoting the env. - Builtins include `map`, `filter`, `concat`, `flatten`, `take`, `join`, `split`, `trim`, `trimPrefix`, `upper`, `fromJSON`, `toJSON`, `fromPairs`, `date`, `duration`, `timezone` and `now` (`builtin/builtin.go`). A map literal's key may be a bare name, so `{type: "text", text: title}` parses, or an expression in brackets, so a key can come from the payload (`parser/parser.go`, `parseMapExpression`). `let` and `if`/`else` exist, as do `?.` and `??` for missing fields. @@ -228,7 +197,7 @@ WHERE THE FINDINGS ARE UNSURE - Forgejo's headers: its docs' example only, not its source. - GitLab's `Content-Type`; whether `webhook-timestamp` stays the same across its retries; and whether its signing token takes the `whsec_` form: its docs do not say. - Gitea's own retry rules: not read. -- Expr v1.18.1 was read on GitHub, not built; the probe ran v1.17.8, and the example templates were not compiled. Stage 1's tests check them, and its first step checks that question 6's guard can wrap every predicate. +- Expr v1.18.1 was read on GitHub, not built; the probe ran v1.17.8, and the example templates were not compiled. Stage 1's tests check them, and its first step checks that decision 6's guard can wrap every predicate. - How long a nested predicate over a large webhook body runs: not measured. SOURCES @@ -266,26 +235,18 @@ INVARIANTS 7. printqueue, server and config never import Expr (printers.md invariant 9), and ntfy imports neither modules, templates nor Expr. 8. A template that fails never loses an ntfy message: the message prints as today's card. A template's job is previewed before it is queued and its images are optional, so in the worker it can fail only as any job can, at the printer. -ON ACCEPTANCE -When the owner accepts this plan, these edits are made: -- design.md: Planned next item 5 says which defaults the owner accepted, as items 3 and 4 do. -- docs/plans/formatters.md: its phase 5 items "User templates" and "Webhook sources" go, each pointing here, while that plan exists. -- docs/plans/printers.md: Architecture, ROUTING RULES: `internal/pkg/rules` also exports `Options`, the compile options templates share, and either plan may build the engine first (question 1). THE ENVIRONMENT gains `template` (question 13), and `source` gains `hook:`. Question 16's "a rule sees routing facts only" stays true of `[routing]`, while the rules here see print contents (question 14). Question 20 says a reload swaps templates, ntfy rules and webhooks too (question 17). -- docs/plans/blocks.md: decision 22's templates bullet, and Overview item 5, say templates do not need the group (question 11). -- docs/plans/job-store.md: question 10's duplicate check also takes hook jobs with a delivery ID, since only a request whose signature passed reaches `Submit` (question 22). - ## Architecture PACKAGES -- `internal/pkg/rules` (printers.md): stage 1 adds `Options(zone)`, the compile options both share, and the iteration guard (question 6); stage 2 adds the engine if printers stage 2a has not (question 1). It imports only Expr. -- `internal/pkg/templates` (new, stage 1): `Template` (name, input, form, compiled program), `Compile`, `Run(env) (receipt.Job, error)` with question 7's checks, the environments and their decoding, the helper functions, the `card` form's mapping onto `modules.Notice`, and `Module`, which wraps a template as a `modules.Module`. Imports: Expr, rules, modules, receipt. +- `internal/pkg/rules` (printers.md): stage 1 adds `Options(zone)`, the compile options both share, and the iteration guard (decision 6); stage 2 adds the engine if printers stage 2a has not (decision 1). It imports only Expr. +- `internal/pkg/templates` (new, stage 1): `Template` (name, input, form, compiled program), `Compile`, `Run(env) (receipt.Job, error)` with decision 7's checks, the environments and their decoding, the helper functions, the `card` form's mapping onto `modules.Notice`, and `Module`, which wraps a template as a `modules.Module`. Imports: Expr, rules, modules, receipt. - `internal/pkg/modules` gains `TemplateError` (name assumed): a template's name, the line and column, and the paths of its output's problems, never a message. templates returns it, and server matches it without importing templates. - `internal/pkg/hooks` (new, stage 4): the presets, `Verify(preset, secret, header, body, now)`, the delivery ID, the event and the allowed headers. Pure functions on bytes and headers: no Fiber, no Expr. - server gains the `/hooks/{name}` handler, which verifies with `hooks` and passes the request to a `Hooks` interface that internal/app implements with templates and rules, so server never imports templates or Expr. Template modules reach server through the existing `Modules` interface, whose registry internal/app gives from the snapshot. - internal/app builds the snapshot, wires the subscriber's decision function, and implements `Hooks`. - Imports: templates → rules, modules, receipt; hooks → nothing of ours; server → hooks; internal/app → templates, hooks, rules. CLAUDE.md's list gains them, and a test holds that server, printqueue and config do not depend on Expr (`go list -deps`). -THE ENVIRONMENTS (questions 5, 12 and 23) +THE ENVIRONMENTS (decisions 5, 12 and 23) | Variable | Type | Input | Value | |---|---|---|---| @@ -293,7 +254,7 @@ THE ENVIRONMENTS (questions 5, 12 and 23) | `hook` | string | json | the hook's name (stage 4); else empty | | `event` | string | json | the preset's event header, such as `push` (stage 4); else empty | | `delivery` | string | json | the delivery's ID (stage 4); else empty | -| `headers` | map | json | the allowed headers by lowercased name (question 23; stage 4); else empty | +| `headers` | map | json | the allowed headers by lowercased name (decision 23; stage 4); else empty | | `subscription` | string | ntfy | the subscription's name; empty on a module route | | `id`, `topic`, `title`, `message` | string | ntfy | the message's | | `markdown` | bool | ntfy | the message is markdown | @@ -372,8 +333,8 @@ action = "digest" ``` - The subscriber gains `Options.Decide` (name assumed), a function internal/app gives it. It returns the action, `bypass`, the rule's name and an opaque handle to the compiled template, which ntfy hands back to `Handler.Message` untouched, so ntfy imports nothing new. A nil `Decide` keeps today's behaviour. -- In `deliver`, `Decide` runs after the `min_priority` and updates checks (question 13). A `digest` holds the message in the rule's own held set (stage 3). -- internal/app's `Message` runs the template, or prints the card when it fails (question 15), then submits as today. +- In `deliver`, `Decide` runs after the `min_priority` and updates checks (decision 13). A `digest` holds the message in the rule's own held set (stage 3). +- internal/app's `Message` runs the template, or prints the card when it fails (decision 15), then submits as today. WEBHOOKS (stage 4) @@ -401,20 +362,20 @@ action = "drop" | `header` | `Authorization` or `X-Gitlab-Token`, equal to the secret | nothing | none | none | A request runs in this order: -1. The name (`404`). A client over its count of refused requests gets `429` first (question 19). +1. The name (`404`). A client over its count of refused requests gets `429` first (decision 19). 2. The content type and `Content-Encoding` (`415`). 3. The signature on `BodyRaw`, and the timestamp (`401`). -4. The delivery ID: reserved, or a repeat answered with the first delivery's answer (question 22). +4. The delivery ID: reserved, or a repeat answered with the first delivery's answer (decision 22). 5. A preset's own event, such as `ping` (`204`). 6. The body as a JSON object (`400`). 7. The snapshot's rules, first match, then the hook's `template` (`204` for nothing). -8. The template; a failure prints the fallback receipt (question 24). +8. The template; a failure prints the fallback receipt (decision 24). 9. The job's preview and `Submit`, with the source `hook:` and the delivery's ID as its reference (`202`, `503`). LOGGING AND PRIVACY -- A template's failure: one WARN line with the template's name, its position and the source (`module:`, `ntfy:` or `hook:`), reported once per template per run (questions 8, 15 and 24). A run past 1 s: one WARN line with the name, from a timer (question 6). -- A rule's runtime error: a WARN line with the rule's name and position, at most once a minute per rule (question 14). A drop: one DEBUG line with the rule's name and the message's or delivery's ID. -- Hooks: the request line, with the path, as for every request. Never a header or the body. install.sh's Caddy log leaves out `X-Gitlab-Token` (question 20). +- A template's failure: one WARN line with the template's name, its position and the source (`module:`, `ntfy:` or `hook:`), reported once per template per run (decisions 8, 15 and 24). A run past 1 s: one WARN line with the name, from a timer (decision 6). +- A rule's runtime error: a WARN line with the rule's name and position, at most once a minute per rule (decision 14). A drop: one DEBUG line with the rule's name and the message's or delivery's ID. +- Hooks: the request line, with the path, as for every request. Never a header or the body. install.sh's Caddy log leaves out `X-Gitlab-Token` (decision 20). - The env, the output and Expr's runtime messages reach the terminal only, through `uberbringer template` and `uberbringer rules`. ## Phases @@ -423,7 +384,7 @@ Every commit below that changes behaviour carries its own tests, docs, regenerat ### Stage 1: Templates, served as modules -**Goal.** Templates written in Expr, in the `card` and `elements` forms, each served as a module and checked on its sample at load. Questions 1-11. +**Goal.** Templates written in Expr, in the `card` and `elements` forms, each served as a module and checked on its sample at load. Decisions 1-11. **Work.** @@ -431,13 +392,13 @@ go.mod - Expr at its latest stable release, unless printers stage 2a has added it; govulncheck. The licence notices are regenerated in the commit that first links Expr into the binary (commit 3). internal/pkg/rules -- options.go: `Options(zone)` and the iteration guard (question 6). Its first step checks, on v1.18.1, that the guard wraps every predicate builtin and `in`, and that a nested predicate is charged on each pass. +- options.go: `Options(zone)` and the iteration guard (decision 6). Its first step checks, on v1.18.1, that the guard wraps every predicate builtin and `in`, and that a nested predicate is charged on each pass. internal/pkg/modules -- `TemplateError` (question 8). +- `TemplateError` (decision 8). internal/pkg/templates (new) -- template.go: `Template`, `Compile` and `Run`, with question 7's checks, the walker, forced `optional` images and the timer. +- template.go: `Template`, `Compile` and `Run`, with decision 7's checks, the walker, forced `optional` images and the timer. - env.go: the `json` and `ntfy` environments, without stage 4's fields; the body decoded with `UseNumber`; `fromJSON`, `cut` and `stamp`. - card.go: the `card` form onto `modules.Notice`, decoded strictly. - module.go: `Module`, a template as a `modules.Module`. @@ -446,11 +407,11 @@ internal/pkg/config - `Templates []TemplateConfig` (`templates`), a list of tables read from the file only, each entry from its defaults as a subscription's is; validation of names, enums and required keys. No Expr. The names of any `UBERBRINGER_TEMPLATES_*` variables, for the WARN. internal/app/uberbringer -- load.go (new, unless printers stage 1a has added it; name assumed): compile every template and run it on its sample (question 9), at start, in `config get` and in `preview`. +- load.go (new, unless printers stage 1a has added it; name assumed): compile every template and run it on its sample (decision 9), at start, in `config get` and in `preview`. - modules.go: the registry gains the templates; a name clash is a config error. - cli.go: `uberbringer token` reads the config, builds the registry with its templates, then checks `--modules`. -- serve.go: the WARN for `UBERBRINGER_TEMPLATES_*` variables; each built job is previewed before `Submit` (question 7). -- template.go (new): `uberbringer template` (question 10). +- serve.go: the WARN for `UBERBRINGER_TEMPLATES_*` variables; each built job is previewed before `Submit` (decision 7). +- template.go (new): `uberbringer template` (decision 10). internal/app/uberbringer/server - errors.go: `template_failed`; handlers_modules.go answers it for a `*modules.TemplateError`, with the name and position. @@ -509,13 +470,13 @@ Commit 1 carries the Expr dependency in go.mod and go.sum, unless printers stage ### Stage 2: Rules for ntfy messages -**Goal.** `[[ntfy.rules]]` print a subscription's messages through a template, as today's card, or drop them. Questions 12-17. +**Goal.** `[[ntfy.rules]]` print a subscription's messages through a template, as today's card, or drop them. Decisions 12-17. **Work.** -- internal/pkg/rules: the engine, if printers stage 2a has not built it (question 1). +- internal/pkg/rules: the engine, if printers stage 2a has not built it (decision 1). - internal/pkg/ntfy: `Options.Decide` and the decision with its opaque handle; `deliver` runs it after the updates check; `bypass` skips the budget; `Handler.Message` takes the decision; `drop` logs at DEBUG; a panic in `Decide` is recovered. - internal/pkg/config: `[[ntfy.rules]]`, each entry from a default with `enabled` true; validation of names, `order`, actions (`digest` refused until stage 3), `bypass` on `print` only, and `template` against `ntfy` templates. -- internal/app/uberbringer: compile the rules against the `ntfy` environment at load; `Decide` from the snapshot; `Message` runs the template or prints the card (question 15), with panics recovered; `uberbringer rules ntfy [message.json|-]` (name assumed) prints the environment, each rule's result and the decision, then the preview. +- internal/app/uberbringer: compile the rules against the `ntfy` environment at load; `Decide` from the snapshot; `Message` runs the template or prints the card (decision 15), with panics recovered; `uberbringer rules ntfy [message.json|-]` (name assumed) prints the environment, each rule's result and the decision, then the preview. - Docs: docs/templates.md § ntfy rules, `bypass` and the digest rows of held messages; docs/ntfy.md, the order of the checks and a pointer there; docs/configuration.md, § ntfy and § Environment variables, and the example config; docs/cli.md; docs/security.md § What is never logged, a rule's environment; README's feature list; design.md, the subscriptions' decision gains the rules, and `[[ntfy.rules]]` has no variable. **Tests.** @@ -542,12 +503,12 @@ Commit 1 only if printers stage 2a has not built the engine. Commit 2 is ntfy's ### Stage 3: The `digest` action -**Goal.** A rule holds a message for a digest of its own, which prints once the oldest has waited `digest_wait`. Question 18. +**Goal.** A rule holds a message for a digest of its own, which prints once the oldest has waited `digest_wait`. Decision 18. **Work.** - internal/pkg/ntfy: a held set for rule-held messages, apart from the budget's, with the time its first message came; `flushAt` waits for `digest_wait` for it; the check that holds later messages behind a waiting digest counts the budget's set only; the state file keeps the new set as new fields of version 1. - internal/pkg/config: `digest_wait` per subscription, its default and range; `digest` allowed in `[[ntfy.rules]]`. -- Docs: docs/templates.md, docs/ntfy.md, docs/configuration.md and the example config; design.md's paper budget decision, as question 18 amends it. +- Docs: docs/templates.md, docs/ntfy.md, docs/configuration.md and the example config; design.md's paper budget decision, as decision 18 amends it. **Tests.** - On the virtual clock: a rule-held message prints on a digest after `digest_wait`, not at once; an ordinary message after it prints at once as its own card; a budget digest and a rule digest each print; quiet hours still hold the rule's digest; a restart keeps the wait; a state file without the new fields loads as today. @@ -560,7 +521,7 @@ Commit 1 only if printers stage 2a has not built the engine. Commit 2 is ntfy's ### Stage 4: Webhooks -**Goal.** `POST /hooks/{name}` takes a signed delivery from a forge or any Standard Webhooks sender and prints it through a template. Questions 19-29. +**Goal.** `POST /hooks/{name}` takes a signed delivery from a forge or any Standard Webhooks sender and prints it through a template. Decisions 19-29. **Work.** - internal/pkg/hooks (new): the presets, `Verify`, the delivery ID and its form check, the event and the allowed headers (Architecture, WEBHOOKS). @@ -568,11 +529,11 @@ Commit 1 only if printers stage 2a has not built the engine. Commit 2 is ntfy's - internal/pkg/config: `[[webhooks.hooks]]` (`name`, `preset`, `secret`, `secret_file`, `header`, `template`) and `[[webhooks.rules]]`; validation, file only, a `whsec_` secret's form; the names of any `UBERBRINGER_WEBHOOKS_*` variables, for the WARN. - internal/app/uberbringer/server: - routes.go: the `Hook` flag; `registerRoutes` registers it outside `BasePath` with `noStore` and the limiter of refused requests; `DocumentedErrors` adds `rate_limited` for it; the signature, timestamp, event and delivery headers as header `Params`. - - the handler, in the order under Architecture, WEBHOOKS, on `BodyRaw`; the repeat check (question 22), job-store's when it has shipped. + - the handler, in the order under Architecture, WEBHOOKS, on `BodyRaw`; the repeat check (decision 22), job-store's when it has shipped. - errors.go: `hook_not_found`, `invalid_signature` and `unsupported_media_type`. - the `Hooks` interface, whose lookup gives one value bound to one snapshot. - tools/genopenapi: a `Hook` route has no bearer security. -- internal/app/uberbringer: the hooks into the snapshot, secrets read at load; `Hooks`; the fallback receipt (question 24); `uberbringer rules hook [--headers file] [body.json|-]` (name assumed), which skips the signature and reads headers from a file, one `Name: value` a line, leaving out the signature and secret headers, so that none goes on the command line. +- internal/app/uberbringer: the hooks into the snapshot, secrets read at load; `Hooks`; the fallback receipt (decision 24); `uberbringer rules hook [--headers file] [body.json|-]` (name assumed), which skips the signature and reads headers from a file, one `Name: value` a line, leaving out the signature and secret headers, so that none goes on the command line. - install.sh: Caddy's log filter deletes the `X-Gitlab-Token` request header. - printqueue: `Status.Source`'s doc comment names `hook:`, so docs/swagger.json changes for it. - Docs: