The owner decided that the daemon never reprints a job by itself. It
cannot tell a receipt that printed from one that is missing: an
uncertain job may have printed, and in two narrow cases a job reads
done before it has printed. A reprint when the cover closes would not
reach the second of those, whose job reads done, and it would print
duplicates, since the printer resumes its own buffer when the cover
closes, as stage 1d's third paper check showed; after a cut-short image
the printer can also still be inside the image command. So those cases
stay as they are, by design.
A person reprints instead, through the API, by ID or by category.
POST /api/v1/jobs/{id}/reprint reprints one stored job, as often as
asked. In place of the ID, last reprints the last completed job, one
that read done and never one still waiting or printing; failed retries
the last failed print; and uncertain reprints every uncertain job. A
job a category reprints is marked, so no category takes it again, and
each answer names the new job, so a person can print it again by its
ID. A reprint takes a job from any source: a print or module route, an
ntfy card or digest, and later a webhook. The routes take no query
parameters: every input goes in the JSON body, an empty body or none
means the defaults, and the printer, with several, is a body field. No
message a source receives, an ntfy message included, makes the daemon
print a job again.
design.md records the decision beside the confirmation and rewords the
open cases as accepted choices; its Planned next item 1 names the
routes and says their questions await the owner. docs/plans/job-store.md
gains decision 24 in phase 2 and open questions 25-39 on its details,
each with an assumed default and its trade-off: last after a reprint,
which failed jobs failed takes, the order of uncertain reprints, when a
job is marked, an age limit for uncertain, several printers, an empty
category, the answer, which jobs an ID may name, the tokens, pruned
content, repeats and the duplicate check, a REPRINT mark, a CLI command
and clearing the printer first. The Status line, the overview and phase
2, its tests and paper check included, take them in, and phase 5 no
longer lists a reprint route. docs/plans/templates.md says that a
webhook replay is the sender's resend, not a reprint command. No code,
route or API document changes until phase 2 builds the routes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 KiB
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; 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)
- Templates and rule actions for webhooks and ntfy subscriptions are
written in Expr (
github.com/expr-lang/expr), as in Kanrisha's policy engine, and share the routing engine that docs/plans/printers.md sets out (internal/pkg/rules). - Webhooks come after templates, since a webhook needs a template to become a receipt.
The owner accepted the details below on 2026-12-01. They are numbered, so the rest of the plan can refer to them.
For stage 1:
- Who adds Expr and the shared engine. printers.md adds Expr and
internal/pkg/rulesin 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/uberbringerlinks (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 buildsinternal/pkg/rulesas 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 intorules.Optionswith 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.
- 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,imageandfile), and the existing card lays it out, as for thenotifyandntfymodules: 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/printjob'selementsarray. Expr's map and list literals and itsmap,filter,concatandflattenbuild it, so a template can lay out any receipt the blocks can.- A template that returns
nilprints 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
elementsresult is checked only when it runs, not when it compiles: a JSON body has no Go type, so Expr typesbodyasany. Decision 9 runs every template on its sample at load to catch most mistakes early.
- 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 hasname,description,input(jsonorntfy, decision 5),form(cardorelements),expr, the expression, best written as a TOML multi-line literal string so that quotes need no escaping, andsample, 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 getalready 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 anyUBERBRINGER_TEMPLATES_*orUBERBRINGER_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.
- A list of tables builds on the subscriptions' loader, so this plan does not wait for the named tables printers stage 1a adds, and
- Templates and the existing modules. Every template is also a module. It appears in
GET /api/v1/moduleswith its description, prints atPOST /api/v1/print/<name>and previews atPOST /api/v1/preview/<name>, with the same query (copies,printer), answers and token scopes asnote,notifyandntfy. Ajsontemplate takes a JSON object as its body, as the module routes document it (server/handlers_modules.go:21-23); anntfytemplate takes one ntfy message object, decoded leniently as thentfymodule 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 <name>limits it to that template, and the preview route is the dry-run over HTTP (decision 10).uberbringer tokenreads 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,dataandbase64are left as they are. Thenotemodule keeps printing them as?. GET /api/v1/moduleslists 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.
- Template names share the modules' namespace and pattern,
- What a template sees. A template sees a typed environment per input, a Go struct whose
exprtags name the variables, as printers.md'srouting.Envis. Architecture, THE ENVIRONMENTS, lists them.json:body, the decoded body; andnow. Stage 4 adds a webhook'shook,event,deliveryandheaders, which are empty on a module route.ntfy: a message's fields, thoseFromNtfyuses (modules/ntfy.go:85-119), the subscription's name andnow.http,broadcastandcopyactions 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'sstring()prints a float in exponent form, so order 1234567 would print as1.234567e+06, and a 64-bit ID would lose digits. Expr's ownfromJSONis replaced by one that decodes the same way. - Two helper functions:
cut(s, n), which keeps at mostncharacters and ends a cut string with..., as titles are cut; andstamp(t), which formats a time informat.timezonewithformat.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.
- Compile options and Expr's limits. The options of printers.md decision 17, shared through
rules.Options:now()and$envturned off,Timezoneset toformat.timezoneonce it is known to load, and Expr's default node limit (10,000) and memory budget (1,000,000 per run).nowis injected: the time the payload was received, so a dry-run and the tests reproduce any output. Expr does no I/O. Turning off$envneeds 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
jsontemplate on a module route takes a body from a token limited to modules. A predicate inside another, orinon a list inside a predicate, is quadratic in that text. - So a run has a budget of 1,000,000 iterations. A
Patchvisitor (name of the guard assumed) wraps the list of every predicate builtin (map,filter,all,any,none,one,count,sum,find,groupBy,sortBy,reduceand the like) and the right side ofinin a guard that charges the list's length, passed throughWithContext. 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.
- 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
- 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. Acardresult 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
HEXkey fillshex.rawis refused wherever it stands, at the top, in a box or, once blocks.md stage 5 has shipped, in a group, and so is ahexfield on any element, whatever the token. design.md's "Modules build ordinary jobs" holds: payload text only lands in string fields. - One walker visits every string field of the decoded job by reflection, with a list of the fields it leaves alone (
url,data,base64,hex); a test fails whenElementgains 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;cutkeeps a string inside the limit.datakeeps validation's limits, andbase64the 256 KiB. Acardresult is cut to the card's caps instead, as an ntfy card is. - Every
imagea template builds isoptional, as a card's are (modules/card.go:233). Itsurlmay come from the payload. It is fetched by the worker throughsafehttp, like every image, so it cannot reach the host's own network unlessimages.*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_linesfails 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.
- The result is encoded as JSON and decoded by the strict job decoder (
- 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
422with a new code,template_failed, whosedetailsgive 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 aselements[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_failedstays 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(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.
- Expr's messages quote values from the env, such as
- Checking templates at load. At start, in
config getand inpreview, 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 touberbringer template <name>, since a sample may be a captured payload with private data.- So
config getandpreviewfail 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.
- So
- The dry-run and the preview. A command,
uberbringer template <name> [payload.json|-], reads the config, runs the template on the payload, or on its sample without one, and prints the text preview, or with--jsonthe 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/<name>previews a template with any payload (decision 4).uberbringer preview --module <name>works too, since a template is a module.- Trade-off: two commands overlap;
templatealone shows Expr's message and the job.
- Trade-off: two commands overlap;
- The
groupblock. 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'sconcatandflattenturn 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'srawcheck then walks it.- Trade-off: a template that wants a heading and a shared font for each item sets them on each element itself.
For stage 2:
- 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 hasname,order,when,action,template,bypass(decision 16) andenabled, as printers.md's rules have (its decisions 11 and 12): a unique name by the subscriptions' rule; a unique, requiredorder, lower first, disabled rules included; and the first match wins.whensees decision 5'sntfyenvironment,subscriptionandupdatedincluded, so one list serves every subscription.templatenames a template whoseinputisntfy; the config refuses one that does not.- Trade-off: a rule for one subscription says so in
when.
- Trade-off: a rule for one subscription says so in
- The actions, and today's settings. There are three actions.
print: print the message, throughtemplateif 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 (decision 18).- The rules run after the server's
min_priorityfilter and afterupdates = "skip", so a skipped update reaches no rule.dropanddigestend there.printgoes on through quiet hours, then the paper budget andbypass_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 gainstemplate, 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.
- 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
Explainoutput 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).
- 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
nilprints nothing, as adropdoes.- Trade-off: a broken template's messages print in the wrong shape until someone reads the log.
- 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: theshop-orderexample's text is JSON, so its row would read{"number": 42, …and the order's lines would never print.- A
printrule may setbypass = true: the message skips the paper budget, as one atbypass_prioritydoes. During quiet hoursquiet.min_prioritystill 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
bypassrule can print more than the budget allows, which is whatbypass_priorityalready does by priority. A reload between two offers can change the decision.
- A
- Reloading. Once printers stage 2b ships, SIGHUP swaps
[[templates]],[[ntfy.rules]]and, from stage 4,[webhooks]together with[routing], as one snapshot behind oneatomic.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.Messageuntouched, 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.timezoneand lay out cards with the running card options, as printers.md decision 20 compiles its rules, sostamp,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.
- 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
For stage 3:
- The
digestaction. 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(default1h, 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, 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.
- The rule's digest prints once its oldest message has waited
For stage 4:
- 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 besideAuthandNoStore(server/routes.go:34-38;Hook, name assumed): no bearer token andCache-Control: no-store. It has its own case inTestRoutesConform. Hooks are[[webhooks.hooks]], a list of tables read from the file only, each with anameby 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/forgeand spend the owner's budget with refused deliveries; GitHub never retries the real ones it then refuses. - Refused requests (
401,404and415) count per client in a limiter of their own, atwebserver.rate_limitperrate_window(60 a minute by default, config.go:363-364). A client over it gets429before any hashing, which bounds the HMAC work and the log lines. - An unknown name answers
404with a new code,hook_not_found, before the body is parsed or hashed. It cannot come before the body is read: fasthttp reads the whole body, up towebserver.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:
404and401tell a stranger which names exist. A name is not a secret; the hook's secret is. Valid deliveries have no rate limit (decision 28).
- 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
- Authentication. Every hook has a secret,
secretorsecret_file, exactly one, read as the subscriptions' credential files are; a hook without one is a config error. Itspresetsays how the sender proves it holds the secret (Architecture, WEBHOOKS, gives the table):github,giteaandforgejosign the body with HMAC-SHA256 in hex;gitlabandstandardsign the message ID, a timestamp and the body, in base64, as the Standard Webhooks specification has it;headercompares 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 withhmac.Equal.headercompares 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 answers401with a new code,invalid_signature, and no detail. gitlabandstandardpass over a signature of another version in the header, such asv1a, and check everyv1one it lists. Awhsec_secret that is not base64, or gives fewer than 24 bytes, is a config error.headertakesAuthorizationorX-Gitlab-Tokenonly, and withAuthorizationthe secret is the whole value, scheme included, as Gitea and Forgejo send what was typed. Caddy redactsAuthorizationin its access log by default, but notX-Gitlab-Token, so install.sh's log filter deletes that header too.- A secret never goes in the URL, where proxies log it, so no preset reads one from the query.
config getprints 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,forgejoandheader, 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. Forgitlabandstandard, 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 withopenssl -hmacon the command line. - Trade-off:
headersends the secret itself on every request, so it is only as safe as TLS to the proxy and the proxy's log.
- The signature is checked on the body's bytes as they came, Fiber's
- Bodies and content types. A hook takes a JSON object only, as on the module routes, sent as
application/jsonor a+jsontype in UTF-8, decoded withUseNumberand refused with trailing data, as thentfymodule refuses it (modules/ntfy.go:54-63). Anything else answers415with 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 aContent-Encodingother thanidentity, before any hashing: Fiber'sBodywould 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 is400invalid_payload. The body limit iswebserver.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_limitis raised for the whole server.
- Trade-off: a GitHub event larger than 4 MiB (GitHub caps them at 25 MB) is refused unless
- Replays and repeats.
gitlabandstandardrefuse a timestamp more than 5 minutes from the host's clock,401invalid_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:<name>. 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 a204, so a repeat gets the same answer. After any other answer it is released, so a retry runs again. - Until job-store stage 1c has shipped, each hook keeps its last 512 IDs in memory. Once it has, hook jobs join its duplicate check (job-store decision 10), which runs in
Submitunder the submit lock and replaces the memory for jobs that were queued. - This follows job-store decision 10, 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
gitlabandstandardsign theirs. - A replay is the sender's own resend, not a reprint command; the daemon has none in-band, and a receipt is printed again through
POST /api/v1/jobs/{id}/reprint, or by category through/jobs/last/reprint,/jobs/failed/reprintand/jobs/uncertain/reprint(docs/plans/job-store.md, decision 24). - Trade-off: without the job store, a restart forgets the IDs.
- Webhook rules. They are
[[webhooks.rules]], shaped as[[ntfy.rules]](decision 12) lessbypass, seeing decision 5'sjsonenvironment withhook,event,deliveryandheadersset. Actions areprint, which needstemplate, anddrop. A hook's owntemplatekey 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, andevent == "push"picks Gitea's pushes out of everything else.templatenames a template whoseinputisjson.headersholds a list of allowed headers by lowercased name:content-type,user-agent, and the senders' ownx-github-*,x-gitea-*,x-gogs-*,x-forgejo-*andx-gitlab-*headers andwebhook-id, less every signature and token header among them. The header aheaderhook 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.
- What a sender is answered.
202with the job andLocation, as/printanswers;204when nothing prints: adrop, no match, a template that returnsnil, or an event the preset answers itself after the signature passed, GitHub'sping.- 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. 400invalid_payload;401invalid_signature;404hook_not_found;413body_too_large;415unsupported_media_type;429rate_limited;503queue_fullorshutting_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
503there is lost unless someone redelivers it.
- Token scopes. No new claim is added. A template is a module, so a
modclaim 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.
- Trade-off: a sender that can send a bearer token but cannot sign uses the template's module route, not
- 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.
- 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
401lines;uberbringer rules hook(stage 4) does not check signatures, so a mismatched secret is found by comparing it by hand.
- Trade-off: a sender whose signatures fail shows only
- A hook's paper budget and quiet hours. A hook has neither. It prints at once, as
/printdoes;droprules oneventorbodythin 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.
- 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.
Investigation findings
Research ran on 2026-12-01: the repository at 8b9e838, Kanrisha's internal/policy, Expr's source at v1.18.1, fasthttp and Fiber from the module cache, and each webhook sender's own documents. Two independent reviews then checked the draft against the code, one for its engineering and one against the owner's rules; one ran a probe against Expr v1.17.8 from the module cache. Nothing contacted the printer, no config.toml was read, and nothing was built in the repository.
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 avm.VMcan 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).WithContextpasses 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 as1.234567e+06. The probe also gaveinvalid 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,timezoneandnow(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).letandif/elseexist, as do?.and??for missing fields.
KANRISHA
- Rules return a bool and carry an
Actionfrom a fixed list, with typedActionParamswhose keys are checked by reflection over their JSON tags (policy.go:22-179).deleteis a recognised action that no rule may be created with, so a dangerous action needs a person (policy.go:65-82). - The engine itself is as printers.md's findings describe. Its runtime error log quotes Expr's message (engine.go:236-245), which this plan does not copy.
THE REPOSITORY
- A module turns a body into a
receipt.Job(modules/registry.go:72-87). The module routes answer204forErrSkipand422module_failedfor an invalid built job, with the problems' text (server/handlers_modules.go:90-118). They never callcheckRaw, which only/printdoes. - The subscriber's order (ntfy/subscriber.go:497-534): skip by
min_priority; skip an update ifupdates = "skip"; quiet hours drop or hold; the budget holds unlessbypass_priority, and so does a digest already waiting (line 518); thenHandler.Message. An error from the handler stops reading and offers the message again. Held messages print as soon as the budget has room, or when quiet hours end (ntfy/subscriber.go:616-628). A digest row is a message's title, or its text's first line cut to 256 bytes (ntfy/ratelimit.go:113-139). - internal/app turns a message into a card and submits it; a card that fails validation is logged, reported and dropped (internal/app/uberbringer/ntfy.go:165-206).
checkRawwalks top-level elements only (server/auth.go:135-150), so a job built elsewhere must refuserawitself.- Routes under
/api/v1sit behind the limiter and the bearer token in one group (server/server.go:177-187); the table registers them (server/routes.go:329-351). - fasthttp reads a request's whole body before any handler, up to the body limit, unless
StreamRequestBodyis set (fasthttp v1.80.0, server.go:2762-2767). The server does not set it (server/server.go:151-162), and Fiber v3.7.0 already uses fasthttp'sHeaderReceivedhook itself (app.go:1949). Fiber'sBodyinflates a compressed body and returns a decoding error's text in its place (req.go:189-240);BodyRawdoes not. config getrefusesapi.secretby name before it loads (internal/app/uberbringer/cli.go:103), refuses a list of tables (config/value.go:28-30), and prints any other map withfmt.Sprint(value.go:42-43). Each request is logged with its path, never its query or body (docs/configuration.md:214-216).uberbringer tokenchecks--modulesnames against the built-in modules before it reads the config (internal/app/uberbringer/cli.go:156-161).
WEBHOOK SENDERS
| Sender | Signature | Signed | Delivery ID | A redelivery | Types |
|---|---|---|---|---|---|
| GitHub | X-Hub-Signature-256: sha256=<hex>, HMAC-SHA256 |
the body | X-GitHub-Delivery, unsigned |
keeps the ID | JSON or form |
| Gitea | X-Gitea-Signature: <hex>, HMAC-SHA256; also X-Hub-Signature-256 and X-Gogs-Signature |
the JSON payload: the body, or a form's payload field |
X-Gitea-Delivery, per attempt; also X-GitHub-Delivery |
a new ID | JSON or form (payload) |
| Forgejo | X-Forgejo-Signature: <hex>, HMAC-SHA256 |
the body | X-Forgejo-Delivery |
not checked | JSON or form |
| GitLab 19.1+ | webhook-signature: v1,<base64>, HMAC-SHA256 |
ID, timestamp and body | webhook-id |
keeps the ID | JSON |
| GitLab, older | X-Gitlab-Token, the secret itself |
nothing | X-Gitlab-Event-UUID |
not checked | JSON |
| Standard Webhooks | webhook-signature: v1,<base64> |
id.timestamp.body |
webhook-id |
keeps the ID; new timestamp | any, JSON advised |
- GitHub sends the SHA-1
X-Hub-Signaturetoo, for legacy use, and gives a secret, a payload and the signature they must give, which the tests use. It caps payloads at 25 MB, counts an answer slower than 10 s as failed, and never retries a failed delivery by itself. Its best-practice page advisesX-GitHub-Deliveryagainst replays. - Gitea's replay creates a new task with a new UUID (models/webhook/hooktask.go:121-122 and 153-170 at v28.4.0, its latest release). It signs the payload it stores, whether it sends it as the body or in a form's
payloadfield (services/webhook/deliver.go:39-100 at v28.4.0). Gitea and Forgejo can also send a configuredAuthorizationheader with every delivery. - GitLab's signing token came in 19.0 behind a flag and is generally available in 19.1. It keeps
webhook-idandIdempotency-Keyacross retries, and disables a hook for a while after four failures in a row. Its docs call the plainX-Gitlab-Tokennot recommended for new hooks. - Standard Webhooks 1.0.0: the secret is 24-64 random bytes, base64-encoded after
whsec_; the signature header may hold several, space-separated, for key rotation, andv1ais a deprecated version; the timestamp must be within a tolerance the specification leaves open. - Caddy's access log redacts
Cookie,Set-Cookie,AuthorizationandProxy-Authorizationand logs every other request header as sent.
WHERE THE FINDINGS ARE UNSURE
- Forgejo's headers: its docs' example only, not its source.
- GitLab's
Content-Type; whetherwebhook-timestampstays the same across its retries; and whether its signing token takes thewhsec_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 decision 6's guard can wrap every predicate.
- How long a nested predicate over a large webhook body runs: not measured.
SOURCES
- Expr: https://proxy.golang.org/github.com/expr-lang/expr/@latest; at tag v1.18.1,
expr.go,conf/config.go,vm/vm.go,builtin/builtin.go,builtin/lib.go,checker/checker.goandparser/parser.gounder https://github.com/expr-lang/expr. - Kanrisha:
internal/policy/engine.goandpolicy.go. - fasthttp v1.80.0 and Fiber v3.7.0, from the module cache.
- GitHub: https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries, https://docs.github.com/en/webhooks/webhook-events-and-payloads, https://docs.github.com/en/webhooks/using-webhooks/best-practices-for-using-webhooks, https://docs.github.com/en/webhooks/using-webhooks/handling-failed-webhook-deliveries.
- Gitea: https://docs.gitea.com/usage/webhooks; at tag v28.4.0, https://github.com/go-gitea/gitea/blob/v28.4.0/services/webhook/deliver.go and https://github.com/go-gitea/gitea/blob/v28.4.0/models/webhook/hooktask.go.
- Forgejo: https://forgejo.org/docs/latest/user/webhooks/.
- GitLab: https://docs.gitlab.com/user/project/integrations/webhooks/.
- Standard Webhooks: https://github.com/standard-webhooks/standard-webhooks/blob/main/spec/standard-webhooks.md.
- Caddy: https://caddyserver.com/docs/caddyfile/options,
log_credentials.
Overview
WHAT SHIPS WHEN
- Stage 1: templates in Expr,
cardandelements, each a module with its routes, checked on its sample at load, anduberbringer template. - Stage 2:
[[ntfy.rules]], which print a message through a template, as today's card, or drop it. - Stage 3: the
digestaction anddigest_wait. - Stage 4: webhooks at
/hooks/{name}, with signature presets,[[webhooks.rules]]and repeats answered once.
COMPATIBILITY
- Nothing breaks. Every key, route and code is new, and a config without
[[templates]],[[ntfy.rules]]or[webhooks]behaves as today. The CHANGELOG lists each user-visible commit under Added. GET /api/v1/moduleslists the templates with the built-in modules, sorted by name as today.- A downgrade refuses the new sections as unknown keys. After stage 3 it keeps the ntfy state: an older binary ignores the new fields, and the messages a rule held are lost.
- What prints does not change: no block or card code changes, so TestRenderCompat and TestPaperReceipts keep passing.
INVARIANTS
- Nothing reaches the printer unless the whole receipt rendered. A template builds a
receipt.Job, which is validated, queued and rendered in full before it is sent, as every job is. - A template never sends printer commands. Its output takes the strict decoder;
rawandhexare refused on the decoded job, wherever they stand; text is transcoded and stripped of control characters when it renders. - Print contents never reach logs, Sentry, job status or an error answer: not an ntfy message, a webhook's body or headers, a template's environment or output, nor Expr's or the JSON decoder's messages, which quote them. Logs give names and positions.
- Expr reads nothing outside its environment: no clock, no variables, no I/O.
nowis injected. A run is bounded in nodes, memory and iterations. - A webhook's signature is checked on the body's bytes as they came, before the body is parsed, in constant time. A hook without a secret does not start.
- Each message and each request uses one snapshot of templates, rules and hooks, from the decision to the job.
- printqueue, server and config never import Expr (printers.md invariant 9), and ntfy imports neither modules, templates nor Expr.
- 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.
Architecture
PACKAGES
internal/pkg/rules(printers.md): stage 1 addsOptions(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, thecardform's mapping ontomodules.Notice, andModule, which wraps a template as amodules.Module. Imports: Expr, rules, modules, receipt.internal/pkg/modulesgainsTemplateError(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 withhooksand passes the request to aHooksinterface that internal/app implements with templates and rules, so server never imports templates or Expr. Template modules reach server through the existingModulesinterface, 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 (decisions 5, 12 and 23)
| Variable | Type | Input | Value |
|---|---|---|---|
body |
any | json | the decoded object: maps, lists, strings, whole numbers as ints, other numbers as floats, bools and nil |
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 (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 |
priority |
int | ntfy | 1-5, 3 when it has none |
tags |
list | ntfy | its tags |
time |
time | ntfy | when ntfy received it |
links |
list | ntfy | the click URL and view actions, each {label, url} |
attachment |
map or nil | ntfy | {name, type, size, url} |
updated |
bool | ntfy | an earlier message of its sequence printed, with updates = "mark" (subscriber only) |
now |
time | both | when the payload was received, in format.timezone |
A template on /api/v1/print/<name> sees the hook fields empty, so one written for a hook can be tried there.
TEMPLATES IN THE CONFIG (stage 1)
[[templates]]
name = "gitea-push"
description = "A Gitea push: the repository, the branch and each commit"
input = "json"
form = "elements"
expr = '''
let commits = take(body.commits ?? [], 20);
concat(
[{type: "box", title: cut(body.repository.full_name, 40), children: [
{type: "kv", pairs: [
{key: "Branch", value: trimPrefix(body.ref, "refs/heads/")},
{key: "By", value: body.pusher.login}]}]}],
len(commits) == 0 ? [] :
[{type: "list", items: map(commits, cut(split(.message, "\n")[0], 200))}]
)
'''
sample = '''
{"ref": "refs/heads/main", "repository": {"full_name": "owner/uberbringer"},
"pusher": {"login": "owner"}, "commits": [{"message": "Feed blank lines before the cut"}]}
'''
[[templates]]
name = "shop-order"
description = "An order sent as JSON in an ntfy message"
input = "ntfy"
form = "card"
expr = '''
let order = fromJSON(message);
{title: "Order " + string(order.number), priority: priority, tags: tags,
message: join(map(order.lines, string(.qty) + " x " + .name), "\n")}
'''
sample = '''{"topic": "shop", "priority": 4, "message": "{\"number\": 42, \"lines\": [{\"qty\": 2, \"name\": \"Flat white\"}]}"}'''
- The names, fields and values are examples, checked against the language when stage 1 tests them.
- Each entry is checked by the loader like a subscription: an unknown key is an error,
inputandformare enums, andname,exprandsampleare required.
NTFY RULES (stages 2 and 3)
[[ntfy.rules]]
name = "orders"
order = 10
when = 'subscription == "shop" && "order" in tags'
action = "print"
template = "shop-order"
bypass = true
[[ntfy.rules]]
name = "no-tests"
order = 20
when = 'title startsWith "[test]"'
action = "drop"
[[ntfy.rules]]
name = "stars-later"
order = 30
when = 'topic == "forge" && "star" in tags'
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 toHandler.Messageuntouched, so ntfy imports nothing new. A nilDecidekeeps today's behaviour. - In
deliver,Decideruns after themin_priorityand updates checks (decision 13). Adigestholds the message in the rule's own held set (stage 3). - internal/app's
Messageruns the template, or prints the card when it fails (decision 15), then submits as today.
WEBHOOKS (stage 4)
[[webhooks.hooks]]
name = "forge"
preset = "gitea"
secret_file = "/etc/uberbringer/hook-forge.secret"
template = "gitea-push"
[[webhooks.rules]]
name = "pushes-to-main-only"
order = 10
when = 'hook == "forge" && event == "push" && body.ref != "refs/heads/main"'
action = "drop"
| Preset | Header checked | Signed | Event | Delivery ID |
|---|---|---|---|---|
github |
X-Hub-Signature-256, sha256= and hex |
the body | X-GitHub-Event |
X-GitHub-Delivery |
gitea |
X-Gitea-Signature, hex |
the body | X-Gitea-Event |
X-Gitea-Delivery |
forgejo |
X-Forgejo-Signature, hex |
the body | X-Forgejo-Event |
X-Forgejo-Delivery |
gitlab |
webhook-signature, v1, and base64 |
webhook-id, webhook-timestamp and the body |
X-Gitlab-Event |
webhook-id |
standard |
webhook-signature, v1, and base64 |
the same | none | webhook-id |
header |
Authorization or X-Gitlab-Token, equal to the secret |
nothing | none | none |
A request runs in this order:
- The name (
404). A client over its count of refused requests gets429first (decision 19). - The content type and
Content-Encoding(415). - The signature on
BodyRaw, and the timestamp (401). - The delivery ID: reserved, or a repeat answered with the first delivery's answer (decision 22).
- A preset's own event, such as
ping(204). - The body as a JSON object (
400). - The snapshot's rules, first match, then the hook's
template(204for nothing). - The template; a failure prints the fallback receipt (decision 24).
- The job's preview and
Submit, with the sourcehook:<name>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:<name>,ntfy:<subscription>orhook:<name>), 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 templateanduberbringer rules.
Phases
Every commit below that changes behaviour carries its own tests, docs, regenerated docs/swagger.json where a route or type changes, and its own CHANGELOG entry under Added. A stage's last commit marks the stage built in the Status line.
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. Decisions 1-11.
Work.
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 (decision 6). Its first step checks, on v1.18.1, that the guard wraps every predicate builtin andin, and that a nested predicate is charged on each pass.
internal/pkg/modules
TemplateError(decision 8).
internal/pkg/templates (new)
- template.go:
Template,CompileandRun, with decision 7's checks, the walker, forcedoptionalimages and the timer. - env.go: the
jsonandntfyenvironments, without stage 4's fields; the body decoded withUseNumber;fromJSON,cutandstamp. - card.go: the
cardform ontomodules.Notice, decoded strictly. - module.go:
Module, a template as amodules.Module.
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 anyUBERBRINGER_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 (decision 9), at start, in
config getand inpreview. - modules.go: the registry gains the templates; a name clash is a config error.
- cli.go:
uberbringer tokenreads the config, builds the registry with its templates, then checks--modules. - serve.go: the WARN for
UBERBRINGER_TEMPLATES_*variables; each built job is previewed beforeSubmit(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.
Docs
- docs/templates.md (new): templates, their forms, environments, numbers, limits and helpers, the module routes, and the Gitea example.
- docs/configuration.md: § templates, pointing to docs/templates.md; § Environment variables,
[[templates]]among the sections with no variable. configs/config.example.toml: a commented template. - docs/api.md: Modules says templates are modules;
template_failedin the errors table. docs/swagger.json regenerated. - docs/cli.md:
uberbringer template;config getandpreviewfail on a broken template;token --modulestakes a template's name. - docs/security.md: templates never produce raw ESC/POS; a
modtoken can be limited to one template; the module list shows every template to any token; § What is never logged, a template's environment, output and Expr's messages. - docs/development.md § Package layout:
internal/pkg/templates, andinternal/pkg/rulesif this stage adds it. - docs/docker.md: templates come from the file only, so a container that uses them mounts a config.
- README: the feature list and the documentation table. CLAUDE.md: "Read first", the layout and the imports.
.goreleaser.yaml: docs/templates.md in the archives. - design.md: a decision "Templates build ordinary jobs", beside "Modules build ordinary jobs"; the stack choices, with Expr's version and size, unless printers stage 2a has recorded them, and
[[templates]]with no variable.
Tests.
internal/pkg/rules
- The guard: a nested predicate over two lists of 2,000 fails with the budget spent;
inon a list inside a predicate is charged; a template within the budget runs unchanged.
internal/pkg/templates
- Compile: a syntax error, an unknown name,
now()and$envrefused, with positions; the node limit. - Run: each form on its sample; a nil field through
?.and??;nilreturned;cutandstamp;nowinjected, in a zone with clock changes; 1234567 and a 64-bit ID print whole, frombodyand fromfromJSON. - Refused output:
rawat the top and in a box;hex,HEXandHexon atext; an unknown key; a wrong type; a text field over 4,096 bytes; a result over 256 KiB; the memory budget spent. Each is a*modules.TemplateErrorwith a position or path and no payload text. - An image is made
optional; a result overformat.max_linesfails before it is queued. - A sentinel string in the payload, used as a value and as a map key, never appears in an error's text.
- The walker places every string field of
Element. Runfrom 100 goroutines under-race.- A fuzz target over the output path: any Expr value (maps, lists, strings, numbers, keys in any letter case) through the encoding, decoding, checks and walker never panics, never yields an accepted job with
raworhex, and never puts its input in an error's text. - The job each example template builds from its sample is pinned as a JSON golden.
internal/pkg/config
[[templates]]: names by pattern and unique; unknown keys; enums; required keys; no variable; aUBERBRINGER_TEMPLATES_*variable named for the WARN.
internal/app/uberbringer
- A template that fails to compile, or fails on its sample, fails the start and
config get, naming it; the sample's failure gives no data.config get templatesprints nothing. - A template named like a built-in module is refused.
uberbringer token --modules gitea-pushgives a token whosemodclaim names it; an unknown name still fails.uberbringer template: golden outputs for the examples, and Expr's full message for a failing payload.- server, printqueue and config do not depend on Expr.
internal/app/uberbringer/server
/api/v1/print/<template>,/api/v1/preview/<template>andGET /api/v1/modules; amodtoken for one template;template_failedwith no payload text in the answer or the logs; schema_test holds the new code.
Commits.
- Add the compile options shared by Expr rules and templates
- Add Expr templates that build receipts
- Serve each template as a module
- Add the template command
Commit 1 carries the Expr dependency in go.mod and go.sum, unless printers stage 2a added it; nothing links it yet, so the licence notices do not change. If printers stage 2a has shipped with its options inline, commit 1 is "Share the Expr compile options with templates", with no change in behaviour. Commit 2 is library code with its tests. Commit 3 is the first user-visible change: the config, the check at load, the module routes, token --modules, the regenerated licence notices and the size Expr adds. Its load error names the template and position only. Commit 4 adds uberbringer template and the pointer to it in that error.
Done when.
- The full gate passes; govulncheck is clean; the snapshot builds, and the size Expr adds is recorded if this stage added it.
- Paper, with the owner's OK: the Gitea example's sample, sent to
/api/v1/print/gitea-pushwith the token in a curl header file (-H @file), never on the command line. Look at the box and its title, the key-value rows, the list's line breaks and the cut. Judge by the paper and/healthz, never by a log line or the202. Wait for the owner's report. Once the owner passes it, its job joins receipt's testdata/paper and its bytes are pinned in TestPaperReceipts astemplate-gitea-push.hex, folded into commit 3.
Stage 2: Rules for ntfy messages
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 (decision 1).
- internal/pkg/ntfy:
Options.Decideand the decision with its opaque handle;deliverruns it after the updates check;bypassskips the budget;Handler.Messagetakes the decision;droplogs at DEBUG; a panic inDecideis recovered. - internal/pkg/config:
[[ntfy.rules]], each entry from a default withenabledtrue; validation of names,order, actions (digestrefused until stage 3),bypassonprintonly, andtemplateagainstntfytemplates. - internal/app/uberbringer: compile the rules against the
ntfyenvironment at load;Decidefrom the snapshot;Messageruns the template or prints the card (decision 15), with panics recovered;uberbringer rules ntfy <subscription> [message.json|-](name assumed) prints the environment, each rule's result and the decision, then the preview. - Docs: docs/templates.md § ntfy rules,
bypassand 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.
- The order: a
dropspends no budget; aprintstill waits in quiet hours and counts in the budget; abypassrule skips the budget but notquiet.min_priority;updates = "skip"skips an update before any rule. - A rule failing at run time: the next rule decides, one WARN line with the position and no message text, at most once a minute.
- A template failing on a message, or panicking: the card prints, one WARN or ERROR line, one report per template per run.
- A template returning
nilprints nothing. - A held message prints as a digest row, not through its template.
- A reload between
DecideandMessage, simulated by swapping the snapshot, still prints through the templateDecidechose. - A sentinel title, message and tag sent through a printed, dropped, failing and held message: no log line, Sentry event or job status holds it.
- The synctest soak (design.md, "The subscriber is tested on a virtual clock") runs with rules that print, drop, bypass and fail.
Commits.
- Add the Expr rules engine
- Let the subscriber's caller decide how each message prints
- Print or drop ntfy messages by rules
- Add the ntfy rules dry-run
Commit 1 only if printers stage 2a has not built the engine. Commit 2 is ntfy's Options.Decide, nil keeping today's behaviour, with its tests; nothing a user sees changes, so it has no docs or CHANGELOG entry.
Done when.
- The full gate passes.
- Paper, with the owner's OK: one ntfy message through the
shop-orderexample, published to a test topic. Look at the title, the order lines and their wrapping, the priority's form and the cut. Judge by the paper and/healthz, never by a log line. Wait for the owner's report, then pin its bytes astemplate-shop-order.hex, folded into commit 3.
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. 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;
flushAtwaits fordigest_waitfor 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_waitper subscription, its default and range;digestallowed in[[ntfy.rules]]. - 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.
Commits.
- Hold ntfy messages for a digest by rule
Done when.
- The full gate passes. Nothing new prints: a rule's digest is laid out as today's digest.
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. 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). - internal/pkg/templates: the
jsonenvironment's stage 4 fields. - internal/pkg/config:
[[webhooks.hooks]](name,preset,secret,secret_file,header,template) and[[webhooks.rules]]; validation, file only, awhsec_secret's form; the names of anyUBERBRINGER_WEBHOOKS_*variables, for the WARN. - internal/app/uberbringer/server:
- routes.go: the
Hookflag;registerRoutesregisters it outsideBasePathwithnoStoreand the limiter of refused requests;DocumentedErrorsaddsrate_limitedfor it; the signature, timestamp, event and delivery headers as headerParams. - 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_signatureandunsupported_media_type. - the
Hooksinterface, whose lookup gives one value bound to one snapshot.
- routes.go: the
- tools/genopenapi: a
Hookroute has no bearer security. - internal/app/uberbringer: the hooks into the snapshot, secrets read at load;
Hooks; the fallback receipt (decision 24);uberbringer rules hook <name> [--headers file] [body.json|-](name assumed), which skips the signature and reads headers from a file, oneName: valuea 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-Tokenrequest header. - printqueue:
Status.Source's doc comment nameshook:<name>, so docs/swagger.json changes for it. - Docs:
- docs/templates.md § webhooks: each preset and its sender's settings; making a secret into a file; a test request signed by a script that reads the secret from the file; the clock on a Pi.
- docs/api.md: the route table, the route and its answers, the new codes, the opening paragraph (a hook proves itself by its signature, not a token), the no-store sentence, and the job source
hook:<name>with the delivery's ID as its reference. docs/swagger.json regenerated. - docs/security.md: hook secrets, what each preset proves, replays, the proxy's log, and § What is never logged, webhook bodies and headers.
- docs/configuration.md: § webhooks and § Environment variables; § Logs, the source
hook:<name>. configs/config.example.toml. - docs/cli.md:
uberbringer rules hook, and never a secret in--headers' file. - docs/docker.md: a hook's
secret_filemounted read-only, owned by 10001, mode 600, as token files are; an operator's own proxy passes/hooks/and keepsX-Gitlab-Tokenout of its log. - docs/install.md: the Caddy log filter.
- docs/development.md § Package layout:
internal/pkg/hooks. - README's feature list. CLAUDE.md's layout and imports.
- design.md: a decision for webhooks; "Jobs remember their source" names
hook:<name>and the delivery's ID;[webhooks]has no variable.
Tests.
internal/pkg/hooks
- Each preset against its documented scheme: GitHub's test values; a Gitea and a Forgejo signature made by the test; a Standard Webhooks message signed with a
whsec_secret; several signatures in one header, av1aone passed over; a stale timestamp; a wrong, missing or malformed signature;headerwithAuthorizationand withX-Gitlab-Token; a delivery ID that fails its form check. - The allowed headers leave out every signature, token and
headersecret. - A fuzz target: any headers and body never panic.
internal/app/uberbringer/server
- TestRoutesConform's case for
/hooks/{name}; TestRegisteredRoutesAreTheTable with it; the generated document gives it no bearer security. - An unknown name answers
404without hashing the body, seen through a countingVerifygiven to the server; a form body, and a gzip body,415, nothing inflated; a bad signature401; a client past its refused count429, while a valid delivery from it still prints. - Repeats: two concurrent deliveries with one ID give one job; a repeat after a
202gets the same job, after a204the204, after a503a new attempt. pinganswers204; adropand no match204; a template failure prints the fallback receipt, with no body text, and answers202;queue_full503.- A reload between the signature check and the template, simulated, uses one snapshot.
- A sentinel in the body and in a header: no log line, Sentry event, job status or answer holds it.
- schema_test holds the new codes.
internal/pkg/config
[[webhooks.hooks]]: a hook without a secret, with both kinds, with an unknown preset, aheaderother than the two, a badwhsec_secret, a repeated name, or atemplatewhose input is notjson, is refused.config get webhooks.hooksprints nothing.
Commits.
- Add webhook signature checks for common senders
- Print signed webhooks through templates
- Answer a repeated webhook delivery once
- Add the webhook rules dry-run
Commit 1 is library code with its tests. Commit 2 also carries install.sh's log filter, since the header preset needs it.
Done when.
- The full gate passes; the snapshot builds, since install.sh changed.
- Paper, with the owner's OK: one test delivery from the owner's Gitea to a hook behind Caddy, through the
gitea-pushexample. Look at the repository, the branch, the commit lines and the cut. Judge by what printed, the job's status and/healthz, never by a log line or the202. Wait for the owner's report.