Breaking: a job reads done only once the printer has confirmed that it ran it, and holds the printer's connection until then. A job written in full that the printer does not confirm within printer.write_timeout now reads uncertain and is not sent again; before, it read done. Before each job, nothing is sent until the printer answers that it can print, so with its cover open or no paper a job is retried and fails, with no sent_at, as when the printer is unreachable, where before it read done. Receipts that take longer than write_timeout to print need a larger one. With confirmation the daemon also turns the printer's automatic status off (GS a 0) before each job and before its confirmation, so another client that relies on automatic status from the same printer stops getting it. printer.confirm = false keeps the old meaning of done and sends none of this. The third paper check of the job store showed why: with the TM-T88IV's cover open, Windows took all of a 128 KB receipt into its send buffer, so the job read done; the daemon stopped, and once the cover closed only the first third printed, without its cut. The printer was then left inside the image command, waiting for the rest, until it was switched off and on. The daemon now turns on the printer client's confirmation. The queue treats an unconfirmed send as written but unknown: it records the delivery uncertain, with an error that says the printer did not confirm it and that it may have printed in full, in part or not at all, logs it at WARN with the printer, and neither retries it nor reports it as a failure. Its commit is not synced: lost, it rolls back to sending, which the next start turns uncertain too. A printer that is not ready gives a plain error before the sending mark, which the queue retries as a failed dial. The new key printer.confirm, on by default, turns confirmation off for a printer that does not answer GS r with bits 4 and 7 clear, or does not answer DLE EOT on receipt; only the TM-T88IV is checked. The key's comments in config.go and the example config say what it sends and needs. docs/api.md warns that raw bytes which make the printer answer can be taken for the confirmation, and says that /healthz answers 503 timeout while a job holds the connection. It and design.md say that each job waits about 200 ms for answers still owed, for DLE EOT 1 to say that the printer is online, and for no answer to come late. design.md says why each connection opens with DLE EOT 1, GS a 0 and GS r 1, and names what stays open: a raw job holding a command answered with bits 4 and 7 clear, such as GS r, GS I, ESC v or ESC u 0, with printing after it, and an answer taken for the ready answer that is not it, one still queued when the fence arrived or one owed from before a late DLE EOT answer that stood in for the fence, followed by a pause of more than 100 ms while the printer reads online, as might happen during the TM-m50II's feed and cut at cover close. It relies on the printer answering DLE EOT on receipt and running GS a 0 in order, unverified beyond the TM-T88IV until stage 4a's raw-byte probe, and now says a send that fails part-way can print a whole receipt twice. The unit and install.md give the stop timeout with and without state.dir: without it the job being sent runs on from its rendering, image fetches included, up to the job's 2-minute cap, so such hosts keep systemd's default or set state.dir. configuration.md says the online check can add 2 s to write_timeout. The printers plan says what Send now does before a job, and its table of what a failed send can mean gains the ready wait and the confirmation. The tests' fake printers answer DLE EOT 1 and GS r 1 as an online printer with paper does; a test runs the daemon against one that answers that it is ready but never confirms the job. On paper, a receipt read done 884 ms after it was written, when the printer answered, and a receipt whose daemon was killed while it waited, with the cover open, read uncertain after the restart and printed once, cut short. With GS a 0 and DLE EOT 1, a receipt printed once with nothing extra and read done 888 ms after it was written; after a power cycle, with /healthz polled every 250 ms, one sent with the cover open waited 15.7 s with nothing sent and printed once, cut once, when the cover closed. With the fence, a receipt printed once with nothing extra and read done 921 ms after it was written. Part of stage 1d of docs/plans/job-store.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
206 lines
11 KiB
Markdown
206 lines
11 KiB
Markdown
# Ü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 or, with a state directory, in a SQLite job store on disk. 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 root
|
|
`Dockerfile` and `install.sh` take the place of the standards' `build/` and
|
|
`scripts/`, and the generated `docs/swagger.json` takes the place of
|
|
`api/`.
|
|
- `docs/api.md` is the reference for the API: routes, elements, blocks and
|
|
error codes. `README.md` is a short overview that links to the other docs
|
|
under `docs/`: `install.md` (install.sh), `docker.md`, `configuration.md`
|
|
(every config key and the logs), `security.md` (the secret, tokens and
|
|
their scopes), `ntfy.md` (the ntfy subscriptions), `cli.md` (the command
|
|
line) and `development.md` (the Go version, the gate, the package layout,
|
|
CI and releases). The release archives carry all of them but
|
|
`development.md`; `.goreleaser.yaml` lists each file.
|
|
- `docs/swagger.json`, the OpenAPI 3.1 document, is generated
|
|
(`go generate ./...`, which runs `tools/genopenapi`) from the route table in
|
|
`internal/app/uberbringer/server/routes.go` and the Go types it names: their
|
|
`json` and `jsonschema` tags 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.
|
|
- `THIRD-PARTY-LICENSES.md` and its copy `internal/app/uberbringer/licenses_embed.md`,
|
|
which the binary embeds and `uberbringer licenses` prints, are generated
|
|
(`go generate ./...`, which runs `tools/genlicenses`) from the license and
|
|
notice files of the Go distribution and of the modules that
|
|
`./cmd/uberbringer` links on each release platform. Never edit them by
|
|
hand; regenerate them in the same commit as any dependency change.
|
|
- `docs/design.md` explains 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>.md` holds 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. `docs/development.md` 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. `tools/genlicenses` writes
|
|
`THIRD-PARTY-LICENSES.md` and the copy beside `internal/app/uberbringer`'s
|
|
`licenses.go`; it imports nothing from the module and learns the linked
|
|
modules from `go list`. `tools/libcpin` checks the libc pin from
|
|
`go mod graph` and imports nothing from the module either. 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
|
|
- jobstore → printqueue
|
|
- 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.
|
|
printqueue defines its `Store` and imports no database; jobstore implements
|
|
it on SQLite, so the server and tools/genopenapi never compile SQLite.
|
|
|
|
## 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 run ./tools/libcpin # modernc.org/libc is the version modernc.org/sqlite requires
|
|
go vet ./...
|
|
go tool staticcheck ./...
|
|
go generate ./... && git diff --exit-code -- docs/swagger.json THIRD-PARTY-LICENSES.md internal/app/uberbringer/licenses_embed.md # generated files are up to date
|
|
go test -race -timeout 5m ./... *> "$env:TEMP\uberbringer-test.txt"; "exit $LASTEXITCODE"
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -o /dev/null ./cmd/uberbringer # in Git Bash
|
|
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o /dev/null ./cmd/uberbringer # in Git Bash
|
|
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. The ARM builds set their variables inline,
|
|
which PowerShell cannot; they need no cgo, so Git Bash runs them.
|
|
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 keeps no binaries: only `release.yml` builds release binaries, 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 under `docs/` (or
|
|
`README.md`) and CHANGELOG.md say what changed.
|
|
|
|
## Go version
|
|
|
|
- The `go` line in `go.mod` (1.27.4) names the latest Go release, and there
|
|
is no `toolchain` line. 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. `docs/development.md` 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.yml` and `release.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 `raw`
|
|
element 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 `/healthz` does.
|
|
- A write that returned proves only that the operating system holds the
|
|
bytes. A job is `done` only once the printer answers the `GS r 1` sent
|
|
after it (`printer.confirm`); one written in full without that answer is
|
|
`uncertain` and never sent again. Nothing of a job is sent until the
|
|
printer has answered a `GS r 1` asked alone, which also drops late
|
|
answers to earlier requests.
|
|
- Every refusal is an `apiError` with a code from `server/errors.go`. A code is
|
|
part of the API: never rename one, and add a new code to the table in
|
|
`docs/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.toml` is 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.toml` and `docs/configuration.md`.
|
|
- A route, element field, status or error code: its code, its tests,
|
|
`docs/api.md` and the regenerated `docs/swagger.json`. A route is an
|
|
entry in the table in `server/routes.go`, never a direct
|
|
`app.Get`/`Post`; it also needs its case in `TestRoutesConform`, which
|
|
fails for a route without one, and `TestRegisteredRoutesAreTheTable`
|
|
fails for a route registered outside the table.
|
|
- An enum value or a limit goes into the field's `jsonschema` tag. The
|
|
tests in `receipt/schema_test.go`, `printqueue/schema_test.go` and
|
|
`server/schema_test.go` hold 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.
|
|
- Dependencies are at their latest stable release when added or bumped.
|
|
The one exception is `modernc.org/libc`, which stays at the exact version
|
|
`modernc.org/sqlite` requires and moves only with it (owner, 2026-12-01;
|
|
design.md, Stack choices). `go get -u` would move it, so after one run
|
|
`go run ./tools/libcpin`, which fails until libc is back at that version.
|
|
- Commit on main, land a branch, push, tag or release only when the owner
|
|
asks. Releases are `vX.Y.Z` tags on `main`; `release.yml` refuses a tag
|
|
whose commit is not on `main`.
|
|
|
|
## 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 a `202`.
|
|
- To print: `go run ./cmd/uberbringer` reads the root `config.toml`, and
|
|
`go run ./cmd/uberbringer token` prints 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`.
|