Breaking: a job with a raw element prints only with a token issued with uberbringer token --raw. Every other token, every existing one included, gets 403 token_scope for it, with the raw elements in details, and keeps every other route. The notify module prints a notification card from a title, message, priority and tags, with topic, click, up to three actions, image, markdown and time as options; it decodes strictly and refuses a payload over its length caps. The ntfy module takes one ntfy message as ntfy sends it, such as the ntfy client's $NTFY_RAW, ignores fields it does not know, cuts text over the caps, and answers 204 for other events and binary bodies. Both print every message plain: one message cannot tell the first of a sequence from a replacement, since a publisher may choose the sequence ID. internal/pkg/ntfy holds ntfy's message types. Both print the same card. The priority picks the form: a dark URGENT rule and a double box, a double box headed HIGH, a single box with the title in its border, or a rule with no box. Tags print as markers in front of the title, the rest on a Tags row; links print as QR codes with their labels; attached PNG, JPEG, GIF and WebP images print after the card. A line-level markdown subset is laid out without a dependency, keeping marks inside code spans and URLs, and emoji are removed after a few typed ones become markers. A card that cannot be laid out prints as a plain receipt, and the server logs the fault once at ERROR and reports it to Sentry once. [ntfy.format] and [ntfy.markers] shape the cards; the markers table is a setting with the user's own keys, also settable as UBERBRINGER_NTFY_MARKERS=name=value,... uberbringer token --modules issues a token limited to those modules' print and preview routes, job status and the module list; each route in the table says which tokens it takes, and a scope claim that could read as absent makes the token invalid. image elements take optional, which also shrinks a too-wide image to the paper; a QR code that could be too wide for the paper prints with smaller modules; box takes title_bold. Submit takes a Meta whose source shows in job status and, with a copy of the request ID, in every worker log line of the job. The four ntfy cards passed on the TM-T88IV, posted as the client recipe posts them, and their bytes are pinned in TestPaperReceipts. docs/api.md describes the modules, the card and the client recipe, with tokens read from a header file; docs/swagger.json is regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9.0 KiB
Überbringer
Notes for agents working in this repository. Überbringer is a single Go
binary. It takes JSON print jobs over a REST API (Fiber v3) and queues them in
memory. It renders each job to ESC/POS and sends it over TCP port 9100 to one
Epson receipt printer. It ships in two forms: as release tarballs, which
install.sh installs behind Caddy, and as the Alpine image built from the
root Dockerfile.
Read first
- Coding rules:
R:\Current Storage\Projects\AI-Memory\Golang-Programming-Standards.md. Every change follows it..gitea/workflows/,packaging/, the rootDockerfileandinstall.shtake the place of the standards'build/andscripts/, and the generateddocs/swagger.jsontakes the place ofapi/. docs/api.mdis the reference for the API: routes, elements, blocks and error codes.README.mdcovers installing, configuration, the command line and the package layout.docs/swagger.json, the OpenAPI 3.1 document, is generated (go generate ./..., which runstools/genopenapi) from the route table ininternal/app/uberbringer/server/routes.goand the Go types it names: theirjsonandjsonschematags and their doc comments. The server registers its routes from the same table. Never edit the file by hand; regenerate it in the same commit as any change to a route or to a request or response type.docs/design.mdexplains why the daemon is shaped as it is and lists what is deferred. Change it in the same commit as any code that departs from it.docs/plans/<feature>.mdholds a feature until it ships. A decision made while planning goes into design.md at once. Once the feature is done, delete the plan.
Layout
cmd/uberbringer is a thin main. internal/app/uberbringer holds the CLI and
the wiring, and server/ holds the HTTP API. internal/pkg/* holds the
libraries. README § Development lists them. tools/genopenapi writes
docs/swagger.json; the docs package embeds it, and internal/app hands
it to the server in its config, so the generator never builds the package
that embeds its own output. The module path is the bare
uberbringer, so imports read uberbringer/internal/.... Imports point down:
- server → modules, printqueue, receipt, printer, escpos
- modules → receipt, ntfy
- printqueue → receipt
- receipt → escpos, raster
- printer → escpos
- internal/app → docs, server and the libraries
- tools/genopenapi → server, printqueue, receipt
Only internal/app reads config or wires in safehttp. Packages under
internal/pkg take plain values, and escpos knows nothing of JSON or HTTP.
Gate
There is no make and no docker on this workstation. Run the steps of
make check directly, in PowerShell. The race detector needs cgo, which
works from PowerShell and fails from Git Bash.
gofmt -l . # must print nothing (fix: gofmt -w .)
go tool goimports -l . # must print nothing (fix: go tool goimports -w .)
go mod tidy -diff
go vet ./...
go tool staticcheck ./...
go generate ./... && git diff --exit-code -- docs/swagger.json # the OpenAPI document is up to date
go test -race -timeout 5m ./... *> "$env:TEMP\uberbringer-test.txt"; "exit $LASTEXITCODE"
go tool govulncheck ./... # after any dependency or toolchain change, and before a tag
goreleaser release --snapshot --clean # into dist/; after a change to .goreleaser.yaml or packaging/
Read the test output back from the file. The per-package -timeout 5m makes a
hung test fail with every goroutine's stack. Without it, the tool's own time
limit would kill the run first. staticcheck, goimports and govulncheck are
pinned as tools in go.mod, so never install them separately.
.gitea/workflows/test.yml runs the same gate, with goreleaser check in
place of the snapshot, on every branch push. It builds no binaries: only
release.yml does, for v* tags on main. security.yml runs govulncheck
weekly and on pushes to main. A change is done when the gate passes and the
docs (README.md or docs/api.md) and CHANGELOG.md say what changed.
Go version
- The
goline ingo.mod(1.27.4) names the latest Go release, and there is notoolchainline. That release is the minimum and the build Go: CI tests, scans and releases with it, and a local Go that is older switches to it. README § Development says the same. - Bump the go line to each new Go release, patch releases included, since
govulncheck flags standard-library fixes. Bump the tool modules
(golang.org/x/tools, golang.org/x/vuln, honnef.co/go/tools) in the same
commit. From PowerShell, run
go mod edit -go=…in Git Bash: PowerShell splits the flag. - goreleaser is pinned to the same version in
test.ymlandrelease.yml. Move both together.
Rules
- Nothing reaches the printer unless the whole receipt rendered. The order is validate, render in full, then send.
- Text is transcoded to the configured code page and stripped of control
characters, so data can never become printer commands. Only the
rawelement sends bytes as given. - Layout comes from the printer profile's dots and glyph widths. Never hard-code 42 or 512.
- The printer takes one TCP connection at a time, and it can report a passing
problem while it cuts or feeds. A status read cut short by our own deadline
is a timeout, never a printer fault. Anything that acts on status re-checks
first, as
/healthzdoes. - Every refusal is an
apiErrorwith a code fromserver/errors.go. A code is part of the API: never rename one, and add a new code to the table indocs/api.md. Refusals are not logged as failures. An unexpected error is logged and sent to Sentry once. - Print contents, tokens and the API secret never reach logs or Sentry. The
root
config.tomlis untracked and holds the secret. Never commit it, and never echo its secret. - These changes land in one commit with their docs:
- A config key:
internal/pkg/config(the default and the validation),configs/config.example.tomland README § Configuration. - A route, element field, status or error code: its code, its tests,
docs/api.mdand the regenerateddocs/swagger.json. A route is an entry in the table inserver/routes.go, never a directapp.Get/Post; it also needs its case inTestRoutesConform, which fails for a route without one, andTestRegisteredRoutesAreTheTablefails for a route registered outside the table. - An enum value or a limit goes into the field's
jsonschematag. The tests inreceipt/schema_test.go,printqueue/schema_test.goandserver/schema_test.gohold the tags to validation, to the Go constants and to the values the handlers send. The enums list the canonical spellings; validation also takes other letter case and a few aliases. - A schema description is the first paragraph of the type's or field's
doc comment. Write it for API readers; notes for Go readers go after a
blank
//line.
- A config key:
- Dependencies are at their latest stable release when added or bumped.
- Commit, push, tag or release only when the owner asks. Releases are
vX.Y.Ztags onmain;release.ymlrefuses a tag whose commit is not onmain.
Comments and docs
- Code comments describe the code only: what it does and why. They never mention docs, plans, other repositories or history ("pre-refactor", "the old format"). This holds for Go, shell, YAML, TOML, the systemd unit, the Dockerfile and the Makefile.
docs/stays tidy. When something there is finished or superseded, delete it or fold it in. Keep no "was considered" history and no answered question lists.CHANGELOG.md: every user-visible change gets an entry under## [Unreleased], which becomes the version's section when the tag is cut. A change that breaks an existing caller, config or install goes under Breaking.
Testing on the printer
Unit tests run against fakes and pin command bytes. Passing tests do not prove a change to what prints, such as layout, wrapping, code pages, images, barcodes, QR codes or cuts, or a change to how status is read. Only the paper proves it.
- The printer is an Epson TM-T88IV at 192.168.1.245:9100. Its model is
tm-t88: 512 dots, 42 Font A and 56 Font B columns, CP437. A TM-T88VII and a TM-m50II are planned, with the same geometry. - It is live and uses real paper. Ask the owner before printing anything. Say what to look for (line breaks, characters, image edges, the cut), print one short receipt at a time, and wait for his report or photo.
- Judge by what printed and by
/healthz, never by a log line or a202. - To print:
go run ./cmd/uberbringerreads the rootconfig.toml, andgo run ./cmd/uberbringer tokenprints a token. Write the job to a file outside the repository, then send it:curl.exe -H "Authorization: Bearer <token>" -H "Content-Type: application/json" --data-binary "@job.json" http://127.0.0.1:8080/api/v1/print - Once the owner passes a receipt, pin its rendered bytes in a receipt test,
so that a later change to them shows up in
go test.