Files
uberbringer/CLAUDE.md
T
57_WolveandClaude Opus 5.5 9b91109550
Test / Lint, test and build (push) Successful in 3m17s
Adopt norn's CI, release, API and docs practices; bare module path
Module
- The module path is now the bare "uberbringer"; imports read
  uberbringer/internal/... The banner keeps the Gitea URL.

CI and releases
- Workflows move to .gitea/workflows: test.yml (every branch push:
  gofmt, goimports, tidy, vet, staticcheck, race tests, goreleaser
  snapshot), security.yml (govulncheck weekly and on main) and a hardened
  release.yml (v* tags on main only, tags fetched, goreleaser pinned to
  2.20.3). The broken labeler workflow is removed.
- go.mod pins toolchain go1.27.4, which fixes GO-2026-6859; workflows
  check that the running Go matches it.
- .goreleaser.yaml: tidy check that never writes, reproducible file times,
  prerelease: auto, a release header linking CHANGELOG.md, and archives
  that ship CHANGELOG.md, the example config and the systemd unit.
- Makefile mirrors the CI gate; .dockerignore is an allowlist.

API and tests
- Every error answers {"error", "code", "details"} with a stable code from
  server/errors.go; the framework's own error text is never sent.
- Panics and unexpected errors are logged and reported to Sentry once;
  refusals are not logged as failures. /healthz sends no-store.
- TestRoutesConform requires auth, rate limiting and the body limit on
  every /api/v1 route.
- Race-prone tests no longer rely on freed ports or sleeps; serve takes
  an injected listener.
- The test config uses a placeholder secret instead of a real one.

Install and packaging
- install.sh resolves the latest release through the Gitea API, verifies
  checksums, requests a certificate only when none exists, installs the
  hardened packaging/uberbringer.service and writes the first token to a
  0600 file instead of printing it. It is now executable in git.

Docs
- CLAUDE.md, CHANGELOG.md (0.2.0 with breaking changes and upgrade
  steps), docs/design.md, and docs/plans/formatters.md for the planned
  CP437 blocks, modules and ntfy printing. README updated throughout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 23:27:48 -06:00

141 lines
7.0 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. 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 nginx, 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/`.
- `README.md` is the reference for the API, elements, error codes,
configuration, command line and package layout. There is no api.md or
OpenAPI document.
- `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. README § Development lists them. The module path is the bare
`uberbringer`, so imports read `uberbringer/internal/...`. Imports point down:
- server → printqueue, receipt, printer, escpos
- printqueue → receipt
- receipt → escpos, raster
- printer → escpos
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 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 on every branch push, and
`security.yml` runs govulncheck weekly and on pushes to main. A change is done
when the gate passes and README and CHANGELOG.md say what changed.
## Go version
- The `go` line in `go.mod` (1.26.0) is the minimum Go. Raise it only when the
code needs a newer language or library feature. README § Development states
the same minimum.
- The `toolchain` line is the pinned build toolchain. CI tests, scans and
releases with it, and a local Go that is older switches to it. Bump it to
each new patch release, 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.
- 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.
- 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 README table.
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 README § Configuration.
- A route, element field, status or error code: its code, its tests and
README. A new route also needs its case in `TestRoutesConform`, which
fails for a route without one.
- 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.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`.