monoblok docs
Docs menu · Use Claude or Codex

Patchbay

Write patchbays with Claude or Codex

Patchbay is small enough to fit in a coding agent's context. Install the Patchbay authoring skill, describe the stream you have and the stream you want, and it can write the rules, validate them and show you what they do with sample messages.

The portable skill#

The patchbay-authoring skill teaches Codex and Claude Code the actual DSL: forms, state, runtime differences, YAML/JSON spellings, idioms, and validation. One package serves both agents, with references loaded as needed. It works outside the Monoblok repository.

Install without a checkout#

Download patchbay-authoring.zip. The archive contains a patchbay-authoring/ directory with SKILL.md, references, and assets. Extract the whole directory, not just SKILL.md.

Run these commands in the project where you want to author patchbays. Choose the installation for your agent:

shell
curl -fL https://raw.githubusercontent.com/lexvicacom/monoblok/main/site/downloads/patchbay-authoring.zip \
  -o /tmp/patchbay-authoring.zip

# Codex: project installation
mkdir -p .agents/skills
unzip /tmp/patchbay-authoring.zip -d .agents/skills

# Claude Code: project installation
mkdir -p .claude/skills
unzip /tmp/patchbay-authoring.zip -d .claude/skills

For a personal installation available across projects, extract into ~/.agents/skills for Codex or ~/.claude/skills for Claude Code instead. Install in one scope per agent to avoid duplicate entries. To update, download the current archive and replace the installed patchbay-authoring directory. Restart the agent if the skill does not appear.

The ZIP is rebuilt from the skill source whenever the docs site is built. For a version-pinned copy, use a checkout at the desired release or commit instead.

Use the skill#

In Codex, mention $patchbay-authoring. In Claude Code, invoke /patchbay-authoring. Both agents can also select it automatically when the request matches its description.

For example, in Codex:

text
$patchbay-authoring
Target Monoblok. Write patchbay.edn for sensors.*.temp with numeric payloads.
Round to one decimal place and publish only changed values to <subject>.stable.
Validate it and show a soundcheck with repeated, changed, and negative readings.

For Claude Code, use the same brief after /patchbay-authoring. Specify Tinyblok/Patchbay Lite when targeting firmware, and request YAML or JSON when wanted; EDN is the default.

Give the agent concrete input subjects, representative payloads, desired outputs, and thresholds or windows. Ask for an explanation or review in ordinary prose; ask for a file-only response when you want only the configuration text.

If you need to discover the input shape, install the NATS CLI on the agent's machine and ask it to sample live messages. Supply a subject filter, message count, and an existing CLI profile (NATS calls these contexts), so credentials stay in your CLI configuration:

text
$patchbay-authoring
Use NATS CLI profile plant-readonly to sample up to 100 messages from sensors.>
for at most 30 seconds. Summarize the subjects and payload shapes, then use those
inputs to write sensors.edn, rounding temperature readings to one decimal place
and publishing changed values to <subject>.stable. Validate and soundcheck it.

The agent passes the profile with nats --context plant-readonly sub ... without changing your default context. Sampling observes new Core NATS traffic; it does not replay JetStream history or consume a durable consumer. A quiet feed may yield fewer messages. The skill requires an installed nats command for this optional workflow and does not install it automatically.

Install Monoblok on the same machine so the agent can run monoblok --validate and monoblok --soundcheck. Inside a Monoblok checkout it uses ./build/monoblok; Tinyblok projects should use their firmware host validator. The skill itself installs no binary or dependencies. If tools are unavailable, the agent should say so and give you the check commands.

Read generated rules before deploying them. Validation checks well-formedness; a soundcheck transcript covers only the messages supplied. Check real timing and request-reply behavior against a running target when those matter.

Use from a checkout#

The canonical package is .agents/skills/patchbay-authoring. Codex discovers it in this repository. Claude Code discovers the same package through .claude/skills/patchbay-authoring, a relative symlink. No global install is needed for work in this tree.

To install from a checkout into another project, copy the whole canonical patchbay-authoring directory into that project's .agents/skills/ or .claude/skills/. Copy the canonical directory rather than the Claude symlink, which points back into this repository.

For a tool without skill discovery, extract the ZIP and ask it to read patchbay-authoring/SKILL.md, following the relevant reference links while working on your rules. This file is now the usage guide; the former standalone prompt has moved into the skill's references.

See Codex skill documentation and Claude Code skill documentation for discovery locations and invocation details.

What to ask for#

Describe the messages, not the forms. A good brief has four things:

  • The input subjects, with their shape: coldstore.<site>.<unit>.
  • A sample payload, copied from the real stream if you can.
  • What you want out, in plain words: "only when it changes", "one alert and one all-clear", "a count".
  • The numbers: thresholds, window sizes, decimal places.

Then ask it to prove the result: "validate it, run a soundcheck with sample rows, and show me the transcript."

A worked example#

The brief:

text
Freezers publish JSON on coldstore.<site>.<unit>, like
{"temp":-18.2,"door":"closed"}.

Write a patchbay that gives me:
1. the temperature to one decimal place, only when it changes
2. a "warm" alert when the average of the last five readings reaches
   -15, and a "cold" all-clear once it is back down to -17
3. a running count of door openings

Validate it and show me a soundcheck transcript.

Claude wrote this file from that brief with the instructions loaded:

examples/cold-store.edn
;; Cold-store monitoring, written by a coding agent from a plain-English
;; brief with docs/AGENTS_PATCHBAY.md loaded (see the "Writing patchbays
;; with an agent" docs page for the prompt).
;;
;; Each freezer publishes one JSON frame on coldstore.<site>.<unit>:
;;   {"temp":-18.2,"door":"closed"}

;; Break the frame into scalar subjects so the other rules stay simple:
;;   coldstore.leeds.f1.temp  -18.2
;;   coldstore.leeds.f1.door  closed
(on "coldstore.*.*" :reentrant true
  (json-demux! "temp" "door" payload))

;; Dashboard stream: one decimal place, only when the value changes.
(on "coldstore.*.*.temp"
  (-> payload-float
      (round 1)
      (squelch)
      (publish! (subject-append "stable") :dp 1)))

;; Warm alert on the average of the last five readings. Turns on at -15
;; and off only at -17, so a freezer hovering near the limit does not
;; flap.
(on "coldstore.*.*.temp"
  (transition (hysteresis -17 -15 (moving-avg 5 payload-float))
    (publish! (subject-append "alert") "warm")
    (publish! (subject-append "ok") "cold")))

;; Count door openings: one per closed-to-open change, not one per frame
;; while the door stays open.
(on "coldstore.*.*.door"
  (count! :subject (subject-append "opened") (rising-edge (= payload "open"))))

It picked the idioms the instructions recommend: json-demux! at the head so the other rules work on scalars, round into squelch for the dashboard stream, hysteresis inside transition for an alert that does not flap, and rising-edge so a door held open counts once.

Then the two checks. The first confirms the file loads:

shell
monoblok --validate examples/cold-store.edn

The second runs sample rows through the rules with no server. Each row is SUBJECT|payload; in lines are the rows fed in, out lines are everything the rules published, including the scalars that json-demux! breaks out:

shell
printf '%s\n' \
  'coldstore.leeds.f1|{"temp":-18.21,"door":"closed"}' \
  'coldstore.leeds.f1|{"temp":-18.24,"door":"closed"}' \
  'coldstore.leeds.f1|{"temp":-12.5,"door":"open"}' \
  | monoblok --soundcheck --soundcheck-label --soundcheck-linger-ms 0 examples/cold-store.edn

The transcript for a longer run, generated by this site's build from the same command:

soundcheck · examples/cold-store.edn
in   coldstore.leeds.f1  {"temp":-18.21,"door":"closed"}
out  coldstore.leeds.f1.temp  -18.21
out  coldstore.leeds.f1.temp.stable  -18.2
out  coldstore.leeds.f1.door  closed
in   coldstore.leeds.f1  {"temp":-18.24,"door":"closed"}
out  coldstore.leeds.f1.temp  -18.24
out  coldstore.leeds.f1.door  closed
in   coldstore.leeds.f1  {"temp":-12.5,"door":"open"}
out  coldstore.leeds.f1.temp  -12.5
out  coldstore.leeds.f1.temp.stable  -12.5
out  coldstore.leeds.f1.door  open
out  coldstore.leeds.f1.door.opened  1
in   coldstore.leeds.f1  {"temp":-9.0,"door":"open"}
out  coldstore.leeds.f1.temp  -9
out  coldstore.leeds.f1.temp.stable  -9.0
out  coldstore.leeds.f1.temp.alert  warm
out  coldstore.leeds.f1.door  open
in   coldstore.leeds.f1  {"temp":-8.5,"door":"closed"}
out  coldstore.leeds.f1.temp  -8.5
out  coldstore.leeds.f1.temp.stable  -8.5
out  coldstore.leeds.f1.door  closed
in   coldstore.leeds.f1  {"temp":-19.0,"door":"closed"}
out  coldstore.leeds.f1.temp  -19
out  coldstore.leeds.f1.temp.stable  -19.0
out  coldstore.leeds.f1.door  closed
in   coldstore.leeds.f1  {"temp":-22.0,"door":"open"}
out  coldstore.leeds.f1.temp  -22
out  coldstore.leeds.f1.temp.stable  -22.0
out  coldstore.leeds.f1.door  open
out  coldstore.leeds.f1.door.opened  2
in   coldstore.leeds.f1  {"temp":-22.5,"door":"closed"}
out  coldstore.leeds.f1.temp  -22.5
out  coldstore.leeds.f1.temp.stable  -22.5
out  coldstore.leeds.f1.door  closed
in   coldstore.leeds.f1  {"temp":-22.5,"door":"closed"}
out  coldstore.leeds.f1.temp  -22.5
out  coldstore.leeds.f1.temp.ok  cold
out  coldstore.leeds.f1.door  closed

Reading it against the brief: the second frame rounds to the same -18.2 and publishes nothing; warm arrives on the fourth frame, when the five-reading average reaches -15; the door count goes to 1 and then 2, and the frame where the door stays open does not count again; cold arrives on the last frame, once the average is back at -17.

Read every line#

A patchbay decides which messages reach your subscribers, so treat a generated one as you would any generated configuration: scrutinise every line before it runs anywhere that matters. A file that validates is well-formed, not correct. The agent can misread the brief, and the transcript only covers the rows it chose to feed in.

Things to check by hand:

  • Filters. Does each on filter match the subjects you publish, and nothing else? * is one token and > is one or more.
  • Numbers. Are the thresholds, windows and decimal places yours, or values the agent assumed? In the example above, the brief said "last five readings", and the rule says (moving-avg 5 ...).
  • Output subjects. Where does each publish! go, and does anything export or subscribe to it?
  • :reentrant true. Every rule with it feeds its output back into the rules. Make sure that is intended.
  • Cardinality. Stateful forms keep one slot per subject. A wildcard over many subjects is many slots.
  • The cases the transcript skipped. Feed your own rows through --soundcheck: the boundary values, a malformed payload, the message that must not get through.
  • Wall-clock behaviour. Soundcheck rows arrive in one burst, so :ms windows, hold-off and throttle need a run against a real server.

If a rule is hard to read, ask the agent to explain that line, or to rewrite it more plainly. Rules that gate or filter what leaves a system (Filtering and privacy) deserve the closest reading of all.

Going further#

  • Ask for a pump script as well: a small program that publishes realistic sample traffic, so you can watch the rules against a running server. The skill includes a template for one.
  • Ask for the same file in YAML or JSON, and compare the two with the same soundcheck rows.
  • Two much larger generated patchbays are walked through in Large patchbays, with a recorded session of a coding assistant building one.

MIT licensed · © 2026 Alex Reid
Lexvica offers solutions built with monoblok.