Skip to content

Developing packages

These are the tools for building a package against a real clock on your bench. You test the package offline. You run it against the clock with live reload. You capture what the clock sends and turn the captures into tests. That way a package is proven against real traffic before it reaches production.

TaskCommand or file
Run the scenarios, with coveragehourctl pkg test
Print the payload a command buildshourctl pkg render
Run a gateway against a bench clock, with live reloadhourd dev
Start every session with the same peopledev/seed.toml in the package
Describe your own clock, kept out of version controldev.local.toml
Empty a clock and keep it connectedhourd dev --reset (the standard action wipe)
Record what a clock sendshourctl wire --save
Replay a capture offline and accept it as a testhourctl pkg replay [--watch] [--accept] [--json]
Build and shiphourctl pkg build, hourctl pkg push

The dev tools work with any vendor’s clock. Anything they do to a clock goes through what the package declares, its seed and its wipe action.

A package is a folder with package.toml, main.lua and tests/*.toml (writing packages). Its scenarios are scripted conversations with a device. They run through the real gateway pipeline, with no sockets and no hardware (scenario tests).

Terminal window
hourctl pkg test # every package under .\packages, with coverage
hourctl pkg test push-2.4 # only scenarios whose package id or path contains "push-2.4"
hourctl pkg test -p path\to\packages # another packages folder
hourctl pkg render zk-push@2.4 delete_user user_id=7

hourctl pkg test [FILTER] [-p PACKAGES] [--allow-untested]

ArgumentDefaultEffect
-p, --packagespackagesThe packages folder. Every package under it is loaded and its tests/*.toml run.
FILTERnoneRuns only the scenarios whose package id ([email protected]) or file path contains this text. Coverage is not checked.
--allow-untestedoffUntested routes, commands, actions or sync declarations do not fail the run.

Each scenario prints ok with its step count, or FAIL with what went wrong. Without a filter, a coverage table follows. It lists what is untested in each package. The command exits 1 when a scenario fails. Without --allow-untested, it also exits 1 when any route, command, action or sync declaration is untested (coverage).

A scenario runs at one fixed instant, and time.now inside the package returns it. So you can expect a payload that carries the time exactly.

hourctl pkg render [-p PACKAGES] <PACKAGE> <COMMAND> [key=value ...]

render prints the payload that one of the package’s commands builds from the parameters you give. It is handy while you write a scenario’s expected payload.

  • PACKAGE is a name, a line or a version: zk-push, [email protected], [email protected].
  • COMMAND is one of the package’s commands, not an action.
  • Each parameter is key=value, and every value is given as text. The parameters are checked against the command’s declaration the same way the gateway checks them. A missing or out-of-range parameter is an error.
  • The command is built with no endpoint options and an empty device info.
  • Text payloads print as they are. Any other payload prints as base64: followed by the payload in base64.
> hourctl pkg render [email protected] delete_user user_id=7
DATA DELETE USERINFO PIN=7

The example packages repository, hour-advantage-examples, has editor types in _types. _types/host.lua declares the host API. That is the request and context tables, the effects and the helpers. _types/lib/*.lua declares the shared library’s modules, so require("template") and the others resolve in the editor. The repository’s own .luarc.json points the Lua language server at them. The Lua language server is LuaLS, the “Lua” extension in VS Code. For a packages folder of your own, copy _types into it. Put this .luarc.json in that folder:

{
"runtime.version": "Lua 5.4",
"runtime.builtin": { "io": "disable", "os": "disable", "package": "disable" },
"workspace.library": ["_types"]
}

io, os and package are disabled because the sandbox has none of them. The editor then gives completion, hover and wrong-argument warnings without a running gateway. Folders whose names start with _ are never packages, so _types is not built. The types describe one release’s host API. So take _types from the release that matches your Hour Advantage programs.

host_api in package.toml is the host API that the package is written for (host API versions). The commands on this page (test, render, dev, replay, pkg build) refuse a package whose host API this version does not run. They say which host APIs it runs.

hourd dev runs the whole gateway. That is the listeners, the admin API, actions, sync groups, events and the live views. hourctl drives the admin API as it drives any other gateway. hourd dev runs the packages in a folder exactly as they are on disk.

Terminal window
hourd dev init # writes .\dev.toml and .\.vscode\tasks.json
notepad dev.toml # uncomment the endpoint of the package you work on
hourd dev # packages from .\packages, or: hourd dev path\to\packages
CommandEffect
hourd dev init [PACKAGES]Writes a commented dev.toml in the current folder. It has one HTTP listener, devices on 127.0.0.1:8080. Only this machine reaches that address. To open it to the clock, set listen = "0.0.0.0:8080" in dev.local.toml or dev.toml. For each package that loads, it also has an endpoint that is commented out, with any options the package requires. Also adds dev.local.toml to the folder’s .gitignore (made if there is none). Writes .vscode/tasks.json unless one is there already. Fails when dev.toml exists.
hourd dev [PACKAGES]Runs the gateway on the packages folder (default packages) with the setup in ./dev.toml and ./dev.local.toml. Runs until you press Ctrl-C.
--database-url URLKeeps devices, commands and the sync registry in this Postgres database instead of memory.
HOURADVANTAGE_ATTEND=onRuns Time and Attendance beside the gateway on the memory store (nothing is kept). Use it to try a clock’s punch to a timecard with no database (From a clock to a timecard). Refused with --database-url.
--resetWipes each [[device]] in the config before the seed goes in (below).
--jsonPrints each exchange as one JSON object per line on stdout. Everything else goes to stderr.

dev init writes three VS Code tasks (Terminal > Run Task). Each runs on the packages folder that init was given:

TaskRuns
devhourd dev <packages>
testhourctl pkg test --packages <packages>
replayhourctl pkg replay <the file open in the editor> <packages>

dev.toml uses the layout of the setup file that hourctl apply takes: [[listener]], [[endpoint]], [[sink]] and [[sync_group]]. The plural spellings ([[listeners]] and so on) mean the same. Nothing is made up for you. When the config has no endpoint, dev says so and stops. Packages of one vendor usually speak the same paths, so an endpoint for every package would collide. Uncomment only the endpoints you work on. Give each one a listener (a port) or a path of its own.

[[listener]]
id = "devices"
type = "http"
listen = "127.0.0.1:8080" # "0.0.0.0:8080" lets a clock on the network reach it
[[endpoint]]
id = "zk-push-2-4"
listener = "devices"
package = "[email protected]"
new_devices = "allow"
options = { timezone = "America/Chicago" }

A dev gateway takes any clock that calls it (new_devices = "allow"). On a shared network, use "hold" and list your clock as a [[device]] in dev.local.toml.

The config may also give the vars and secrets that packages read with vars.get and secrets.get (environments):

TableValues
[vars]Vars for every package: names and text values.
[secrets]Secrets for every package. Only allowed in dev.local.toml.
[package.<name>.vars], [package.<name>.secrets]Values for one package, by package name. These take precedence over the shared ones. Secrets are only allowed in dev.local.toml.

dev refuses to start when dev.toml gives a secret.

By default everything is kept in memory, and every start is a fresh gateway. With --database-url postgres://..., devices, commands and the sync registry are kept across restarts. Give dev a database of its own. Dev writes its setup into the database and runs the folder’s packages, whatever revisions are active there. Secrets and templates kept in a database are sealed, so set HOURADVANTAGE_SECRET_KEY as well.

The admin API listens on HOURADVANTAGE_ADMIN_LISTEN, the same as hourd run. The default is 127.0.0.1:9090. An address other than a loopback address needs the admin login (HOURADVANTAGE_ADMIN_USERNAME and HOURADVANTAGE_ADMIN_PASSWORD_HASH). hourctl reaches http://127.0.0.1:9090 unless you give it --admin URL or set HOURADVANTAGE_ADMIN_URL. If you move dev’s admin listener, point hourctl at the new address too.

dev watches the packages folder. Saving a package’s files, or a vendor module above it, recompiles each package that changed and swaps it in whole. A message that is already being handled finishes on the version it started with. A package that no longer loads keeps running its last good version. The error names the file and line:

error D:\clocks\packages\zk\push-2.4 (still running the last good [email protected])
compiling zk-push/main.lua: D:\clocks\packages\zk\push-2.4\main.lua:10: Expected identifier when parsing expression, got '='

A save that loads but does not fit the dev config is refused the same way. One example is a save that makes an option required that the endpoint does not give. A save under a package’s dev/ folder writes its seed again.

At start, dev prints a banner. It shows the packages folder, the config files it read, the store, the admin address, and each listener, endpoint and seed. After that, it shows each exchange with a device as one block. The block holds the request, the route that took it, the package’s log lines, the events it stored, the commands it handed out, and the reply. Times are in UTC.

09:00:57 zk-push-2-4/BENCH1 POST /iclock/cdata?SN=BENCH1&table=ATTLOG&Stamp=1 (35 B) 1 ms
route upload_attlog
event punch {"local_time":"2026-10-02 09:00:00","state_name":"check_in","user_id":"1001",...}
sent #12 add_user sent
reply 200 OK
  • command lines show commands as they are queued by anyone (a seed, hourctl, a sync group). They also show commands as they are cancelled, skipped or go unanswered.
  • sent lines under an exchange show the commands that it handed out or that were answered in it.
  • -- device lines show a device’s status when it changes.
  • A Lua error names the file and line.
  • Sensitive payloads show as <redacted N bytes>.

The gateway’s own log goes to stderr at level warn. Set RUST_LOG to change the level.

With --json, each exchange is one JSON object on its own line instead. Use it with jq or a script. The object is the traffic record as hourctl stream has it (seq, at, endpoint, device, route, remote_ip, method, path, query, request_body, request_bytes, status, response_body, duration_ms). It adds four more fields:

  • logs: the package’s log lines, each { level, message }.
  • events: the events stored.
  • commands: the commands handed out or answered.
  • error: the error, with the file and line named, or null.

Only exchanges go to stdout. The banner and everything else go to stderr.

A package may ship dev/seed.toml. A seed holds synthetic people (and schedules, work codes and messages). They are shaped the way the package’s clocks take them, so that every bench session starts from the same data. Include the cases worth seeing on a real clock:

  • An ordinary user with a card, a keypad PIN or password.
  • An admin.
  • A name longer than the clock holds.
  • A card or id the clock cannot hold.

Seeds are not part of a bundle.

description = "zk-push 2.4: card, password, admin, cut name, schedule, work code"
[[row]] # a sync registry row, as a batch upserts it
domain = "people"
kind = "person"
key = "1001"
fields = { name = "Ann Example", role = "user", cards = [{ number = "100001", format = "raw" }] }
secrets = { password = "4321" }
[[row]]
domain = "access"
kind = "schedule"
key = "office-hours"
fields = { name = "Office hours", days = { mon = [["08:00", "17:00"]] } }
[[action]] # sent to each dev device the first time it calls in, every run
name = "upsert_user"
params = { user_id = "2001", name = "Eve Vendorparams", x_verify_mode = 0 }
Key
descriptionWhat the seed holds. Shown in the dev banner.
[[row]]A row of the sync registry: domain (people, access, lists or settings), kind, key, fields, and optional secrets. These are the shapes a sync group batch takes.
[[action]]An action or command the package offers: name, params.
  • Dev sync group. dev puts an endpoint into a dev sync group for its package when two things hold. The endpoint has no sync_group, and its package has a seed with rows. The group is named dev-<package line> (dev-zk-push-2-4). The group keeps the domains the seed has rows of. The rows are the group’s desired state. The group gives them to the clock and keeps them there, so an edit made at the clock is put back.
  • Rows. Rows are written the way a batch writes them, so writing the same rows again changes nothing. The seed is written at every start and every time you save it. A seed only adds and changes rows. To start from nothing, use --reset.
  • Actions. [[action]] entries are not state. Each one is queued for a device the first time the device calls in successfully during a run, as an operator’s action would be. Use them for what a group does not carry, such as a package’s own x_ parameters. A user that an action adds is one the group did not create. So the group takes it as a person enrolled at the clock, unlinked and kept on that clock alone (hourctl sync people dev-zk-push-2-4).
  • No biometric templates in a seed, synthetic or not. Give seed people the templates you capture yourself, in dev.local.toml.

dev.local.toml sits next to dev.toml. It holds your clock’s serial, its key, your port, your secrets and your own templates. Keep it out of version control (hourd dev init adds it to .gitignore). dev lays it over dev.toml with these rules:

  • A [[listener]], [[endpoint]], [[sink]] or [[sync_group]] with an id that dev.toml already has changes only the fields it gives. An entry with a new id is added.
  • A [[device]] with the same endpoint and serial changes the one already there. A [[credential]] with the same user_id, kind and slot changes the one already there.
  • A table merges key by key. Any other value replaces the value in dev.toml.
[[listener]]
id = "devices"
listen = "0.0.0.0:8081" # your port
[[device]] # registered and allowed when dev starts
endpoint = "zk-push-2-4"
serial = "<your clock's serial>"
# key = "<the key it presents>"
[[credential]] # a template you captured, for a seed person
user_id = "1001"
kind = "fingerprint"
slot = 6
format = "zk:fingerprint:10" # as the biometric event gave it
file = "captures/1001-finger6.b64"
[secrets]
api_key = "<a test key>"
TableFields
[[device]]endpoint, serial, and optional key (the key the device presents). dev registers and allows the device at start.
[[credential]]user_id (a person in the package’s seed; credentials for anyone else are ignored), kind (fingerprint, face, face_photo, palm, finger_vein, iris or photo), slot (default 0), format (the format tag the biometric event carried), and file. The file holds base64 text or the raw bytes. Its path is relative to the config file.

To capture your own templates:

  1. Let the endpoint collect biometrics. In dev.local.toml, set options = { biometrics = true, ... } on the endpoint.

  2. Enroll your finger or face at the clock, or start enrolment from the gateway:

    Terminal window
    hourctl action zk-push-2-4 <serial> enroll_biometric user_id=1001 kind=fingerprint index=6
  3. Take the template from the biometric event. data.template holds the base64, and data.format holds the format:

    Terminal window
    hourctl events --type biometric --json
  4. Save data.template to a file under captures/, and name the file in a [[credential]].

When a seed person is given a credential, the dev group also keeps people and carries biometrics.

wipe is a standard action. It removes the people with their cards, credentials and photos, the punches, and the access and list data. It keeps every network, server and other setting, so the device stays connected to the gateway as an empty member. Each package builds wipe from its own clear commands. No step changes a setting. Where a protocol cannot clear something, the package’s description of wipe says what stays (ZK). A package that cannot clear its people does not offer wipe.

hourd dev --reset works through each [[device]] in the config in three steps:

  1. It queues the package’s wipe for the device, ahead of other work.
  2. It has the device’s sync group send the device everything again.
  3. It writes the seed.

The clock ends up holding exactly the seed. dev reports a device whose package does not offer wipe and leaves that device as it is.

Outside --reset, wipe is an ordinary management action (hourctl action <endpoint> <serial> wipe, audited). Like any other direct write, it is refused while the device’s sync group keeps people, access or lists. Dev groups keep people, so use --reset on a device that is in one.

Terminal window
hourctl wire --device <serial> --for 10m --save captures\bench-enroll.toml

hourctl wire shows every byte that devices send and receive, live, on every instance.

OptionDefaultEffect
--device SERIALallOnly the requests that name this device, and their replies.
--endpoint IDallOnly the requests for this endpoint, and their replies.
--for DURATION15mHow long to watch: 90s, 15m, 2h. The most is 2h. The capture also ends after 64 MiB, or when you press Ctrl-C.
--save FILEnoneAlso writes the exchanges to FILE as a capture.
--hexoffShows each record’s bytes as a hex dump instead of escaped text. Cannot be combined with --save.

--save writes each exchange (a request and its reply) to the file as it completes, so a capture cut short with Ctrl-C is still a whole file. The file is written on the machine where hourctl runs. The gateway itself stores nothing. --save works against hourd dev and against a production gateway, for HTTP listeners only. MQTT traffic is not in the wire capture. A saved file holds what the devices sent (serials, keys, PINs, cards). So on Unix it is written readable by its owner alone (mode 0600).

--hex shows bytes the way hexdump -C does: the offset, 16 bytes in hex, and the printable ones beside them. Use it for binary protocols and bytes that do not print.

09:00:57.389 gw-1 #3 192.0.2.9:5100 zk-push-2-4 tx 18
00000000 4f 4b 00 ff 0d 0a 48 45 4c 4c 4f 2c 20 57 4f 52 |OK....HELLO, WOR|
00000010 4c 44 |LD|

A capture file is a scenario in the format of tests/*.toml (scenario tests). Each exchange is a [[step]] holding the request as the device sent it. The reply the device got is the step’s expectation.

description = "captured from endpoint zk-push-2-4, device BENCH1"
now = "2026-10-02T09:00:57.389Z" # the first exchange: a replay runs at this instant
package = "[email protected]" # the package that answered
[endpoint.options] # the endpoint's options
timezone = "UTC"
[[step]]
name = "09:00:57.389"
method = "GET"
path = "/iclock/getrequest" # without the endpoint's path prefix, as the package sees it
query = "SN=BENCH1"
headers = { host = "192.0.2.5:8080", user-agent = "iClock Proxy/1.09" }
# body = "..." (text) or body_base64 = "..." (anything else)
[step.expect] # the reply the device got
status = 200
body = "OK"

A capture holds what the device sent, exactly as it was sent: its serial, keys, PINs, cards and templates. Keep captures private. Keep them out of version control (add captures/ to .gitignore).

hourctl pkg replay <CAPTURE> [PACKAGES] [--watch] [--accept] [--json]

Terminal window
hourctl pkg replay captures\bench-enroll.toml # against .\packages
hourctl pkg replay captures\bench-enroll.toml packages --watch
hourctl pkg replay captures\bench-enroll.toml --accept

replay runs a capture against the package as it is in the folder, offline, at the instant the capture was recorded. PACKAGES is a packages folder (default packages). The package that the capture names is looked up in it. PACKAGES can also be one package’s folder. Each exchange is shown the way hourd dev shows it, with the package’s log lines. replay points out each reply that differs from the recorded one:

step 2 (09:00:57.389) GET /iclock/getrequest?SN=BENCH1 (0 B) (BENCH1)
route heartbeat
reply 200 C:967669001:SET OPTION DaylightSavingTimeOn=0
differs from the recording (- recorded, + now):
- OK
+ C:967669001:SET OPTION DaylightSavingTimeOn=0

replay exits 1 when a reply differs from the recording. A replay starts with nothing queued, so a reply that hands out commands differs from a recording made while commands were waiting.

OptionEffect
--watchReplays again on every save under the packages folder, until you press Ctrl-C.
--acceptMakes the capture a test of the package (see below).
--jsonPrints each exchange as one JSON object per line on stdout. Everything else goes to stderr.

Each --json object has these fields: step, request, request_bytes, device, route, logs, events, error, status, reply, reply_bytes, and differs. differs holds the diff lines, or null when the reply is the recorded one.

--accept writes the capture as tests/<capture name>.toml in the package’s folder. The test has the same requests. It expects what the package answers now: the status, body, route and stored events. From then on, hourctl pkg test runs it and fails when the package answers differently. When the package is meant to answer differently, replay the capture and accept it again. Command ids in replies are written as {command:N} (the Nth command queued in the scenario), because ids differ from one run to the next. A capture’s serial, keys, PINs and cards stay in the test, so on Unix it is written readable by its owner alone (mode 0600). Take them out before you commit it.

hourctl peers and the “applied on N/N instances” a change reports work against hourd dev as against any gateway. There, it is one instance.

Terminal window
hourctl pkg build packages -o bundles # compiled, checked, scenarios run; one bundle per package
hourctl pkg push bundles\zk-push-2.4.1.tar.gz --activate

A package whose scenarios fail is not built. A bundle never holds the package’s dev/ folder, so seeds are not pushed with it. Packages covers pushing, revisions, activation and rolling back.