arduino
Skill2 starsChanged 25 days agoMITView on GitHub
Shared mechanics of an Arduino library's or core's build and HIL contracts (Adafruit TinyUSB Arduino, Adafruit SPIFlash, the Adafruit SAMD core) - arduino-cli builds against the checkout, prepared dependencies, the HIL build record, the HIL harness and its remote runs. Use when a library's or core's build or HIL contract names it, when adding agent build/HIL support to another Arduino library or core, or when a record, dependency or identity refusal from one of those contracts needs explaining; also before changing those libraries' C/C++ (format rules).
In this repository23 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- ci-rerunSkill
- code-sizeSkill
- coworkSkill
- debug-probeSkill
- download-docSkill
- followup-issueSkill
- headless-chiefSkill
- hil-farm-setupSkill
- hilSkill
- pr-babysitSkill
- pr-replySkill
- pr-reviewSkill
- read-docSkill
- read-pcbSkill
- repo-auditSkill
- rttSkill
- simplify-gateSkill
- target-debugSkill
- usb-kernel-debugSkill
- usb-kernel-recoverSkill
- usb-snifferSkill
- worktree-removeSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 83
Probe detach: before a flash or console reset through an openocd flasher whose args name target/rp2040.cfg or target/rp2350.cfg, the engine …
- Very specific: line 87
Locks: every library's harness takes the same physical board lock (/tmp/tinyusb-hil-locks/<name>.lock, the hil skill), so two libraries, …
- Very specific: line 189
Write the build profile: CI's matrix boards with their FQBNs, the rig boards it will run on (named as in agentrc's board registry, each …
- Distinctive: line 192
Write dedicated HIL sketches, never examples, that end each exchange with a result line tied to the host's nonce, and a restoration sketch …
- Very specific: line 199
Add the boards to test/hil/ci.json, commission each (hil_test.py commission on the board's host), run the battery on the farm …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
arduino — the shared Arduino library contract mechanics
An Arduino library has no build of its own: sketches compile against its checkout with arduino-cli. Each library
that has agent support keeps a build contract and a HIL contract; their mechanics live here, loaded from the agentrc
commit the library pins, and the library keeps only what is its own. Read the library's contracts (its AGENTS.md
names them) for usage, exits and limits; this page is what they share and how a library adopts them.
| Script | Gives |
scripts/arduino_build.py | selection, compiles, dependency and header provenance, image span checks, the HIL build record |
scripts/arduino_hil.py | record admission, flashing, DUT identity, the board lifecycle, manual sessions, commissioning, the report |
scripts/arduino_remote.py | staging a run or a session on a rig (default ci.lan) and collecting it |
scripts/arduino_ci.py | CI: a hosted runner's ci-arduino setup and packed tree per board, the rig runner's battery over them |
Each script's docstring lists the profile names a library supplies. The hil skill's rules (locks, verdicts,
retries, recovery) apply unchanged; these scripts load its hil_* scripts through hil_load.py.
A library's side
.claude/skills/hil-contract/scripts/agentrc_pin.py: a verbatim copy ofscripts/agentrc_pin.py, configured bytest/hil/agentrc.json. It selects the staged tree, CI pin or installed checkout, in that order. Its docstring defines selection, configuration and commands;hil'sagentrc_source.pyowns closure identity and drift.agentrc_pin.py testrefuses a copy that differs from the selected canonical file, naming the copy/repin remedy, then a consumer that fails its conformance check (scripts/pin_conformance.py'sproblems()docstring, loaded from the selected closure). A consumer's own tests keep only its configuration and profile wiring. A consumer reads its own sources itself (ast), never through bootstrap internals: conformance refuses anyagentrc_pinname outsidepin_conformance.py'sPUBLIC..claude/skills/build/scripts/check_build.py: the build profile (board table with CI's FQBNs from adafruit/ci-arduinoall_platforms.pyplus the rig boards, representatives per family, source classification, HIL sketches per role, VID:PID adapter, extra dependencies) andmain(), which binds it toarduino_build.py..claude/skills/hil-contract/scripts/hil_test.py: the HIL profile (tests and their host-side checks, restore test per role, report schema, roster checks) andmain();bind()refuses tables that disagree (the restore test must run the first HIL sketch).hil_remote.pyis a wrapper aroundarduino_remote.py.- Rosters
test/hil/ci.json(the farm) and a gitignoredtest/hil/local.json(a dev PC's boards); contract tests in.claude/test/, run by pre-commit throughagentrc_pin.py test.check_build.pyruns the profile'sCONTRACT_TESTSentryagentrc_pinthe same way, the bootstrap'stestfrom the checkout root, so its copy and conformance checks run there too; every other entry runs its own script (arduino_build.py'srun_tests). A farm board names its probe ("probe", thehilskill's board registry), which supplies its flasher, under the registry's name, which is its board lock; a dev PC's unregistered board keeps a flasher of its own.
What every library gets
- Builds:
arduino-cli compile --clean ... --library <checkout>; the build fails when arduino-cli takes this library from anywhere else. Sketch eligibility follows ci-arduino's.test.only/.test.skip/.skip.txtrules; a HIL sketch outsideexamples/(test/hil/<sketch>/) builds only on rig boards whose role runs it. - Selection from a diff: the profile's own rules first;
library.propertiesis shared code (itsname=anddepends=gate every build). A changed example no board may build is uncovered; each library's contract tests pinunbuildable_examples(), the examples no build here compiles. A run given--boardor--exampleisnarrowed: trueand, unless it writes a record, warns that the change's automatic selection was not verified: its pass is that command's, not the whole change's. - Dependencies: library.properties
depends=plus the profile'sEXTRA_DEPENDENCIES(CI's install list) must be installed in the user's Arduino libraries before a build; a missing one is exit 2 naming thearduino-cli lib installline. Nothing installs during builds. Every library a compile used must be this checkout, a declared dependency or one of their transitivedepends=from its resolved directory, one bundled with the core, or a prepared user copy shadowing a library the build's own core bundles (hashed before any compile and recorded withshadows); any other fails the sketch. A dependency binds its directory asarduino_build.py'stree_digest()documents, and a change to it during the run fails it. - The HIL build record: the rig's installed core need not match or exist; HIL validates the recorded images.
Git-checkout cores are content-bound, other cores have id/version provenance only. The report's
modifiedlabel means only a recordeddirty: true;arduino_hil.py'score_provenance()renders a malformed field as?ormalformed, never as a claim.arduino_build.py'splatform_git()andcontent_digest()document the binding limits. Rebuild a refused record. After an agentrc upgrade, close and reopen a session before staging records from the new closure; closing still uses its original staged restoration image and harness. - Core TinyUSB (informational): each build row's
coreTinyUSBlists, per copy of the TinyUSB an ESP32 core bundles (include/arduino_tinyusb), the headers the build's.dfiles took from it, itstusb_option.hversion and the lib-builder'sversions.txttinyusb:ref (null when unreadable). Nothing admits or refuses on it. - DUT identity: the roster
uidis the DUT's USB serial;usb_portadditionally pins its bus port.no_serial(withusb_port) is for firmware that reports no serial (ESP32 under Arduino): the serial-less device at that port.hil_test.py commissionfinds and confirms either under the restoration sketch. - Identity per USB stack: an ESP32-S3's TinyUSB and USB-Serial/JTAG share one PHY and bus port but report
different serials, so a roster
uids({"<USBMode option>": "<serial>"}, distinct serials,uidamong them, nono_serial) gives each; admission picks the one a sketch's recorded FQBNUSBModenames and refuses an image it names none for. Withoutuids,uididentifies only images built with the rig FQBN'sUSBMode; another is refused. Each serial is the one observed on the board under that image, never derived from another. Anopenocd-esp32debug route on the DUT's ownusb_portneeds auidsentry naming itsdebug.uid, andgdbrefuses a sketch whose image enumerates as another; a route on a port of its own (the P4's) runs under any image. - Probe detach: before a flash or console reset through an openocd flasher whose args name
target/rp2040.cfgortarget/rp2350.cfg, the engine clears the USB pull-up so the host sees the new image enumerate. A console reset, with no record's VID:PID and no rosterusb_port, waits only on the ports carrying the DUT's serial before the detach; a DUT found at none fails the reset without issuing the probe detach or reset. - Locks: every library's harness takes the same physical board lock (
/tmp/tinyusb-hil-locks/<name>.lock, thehilskill), so two libraries, and tinyusb or tinyuf2, exclude each other on a shared board. A run's or commission's lock ends with it: a cleanup it could not prove (a failed restore, children not proven ended) is a blocker, logged in the board's cleanup log with the board released, and the next run on the board, whatever library, reports it (previousCleanupFailure). A manual session's detached hold stays untilrestore --release,releaseorsession close; a session command that leaves a child unproven, or a restore that fails, logs the failure under it. A passing restore marks restored each open failure whose children and retained sessions are proven ended.restore --releasereleases the hold whatever the restore did: exit 0 restored, 6 restore failed (released), 5 not released;session closecounts 6 closed, and on a closed session prints its recorded exits without the rig (exit 0). After a failed close (restoreExit6, hold released), recovery takes a new hold, first stops or reports every child the session left unproven, then restores with the session's record (restoreRecord), never with the session'sresult.jsonas--report. An older engine's pending record (kindarduino-hil) is reported (previousPending), never a refusal. - Busy check: a run or commission is one
hil_lock.board_taskwhose busy check, under its lock and before any tool, is agentrchil_flash.probe_userson the board's probe; its docstring has what it covers (the probe's serial on a command line, holders of its usbfs node or esptool tty) and misses (GDB clients, DUT-side tools, anything started after the check). A probe in use refuses with nothing touched: a run's rowlocked, naming the users inprobeUsers, and a commission's exit 2, neither logging a failure; a check that cannot tell refuses the same way (a run's row not run,refused: probe check). A session command refused either way exits 2 with nothing touched, though a refusedrestoreis logged in the board's cleanup log as any refused restore is, andrestore --releasestill releases the hold and exits 6, or 5 when the release fails. A run's or commission's refusal whose lock did not end cleanly is a blocker (exit 4) instead. Session commands under one hold run one at a time, from any tree or OS user, through the hold's session mutex (hil_lock.session_mutex), taken before the hold is checked, and run the same busy check themselves. A run's cleanup verdict is failed (logged, a blocker) unless its cleanup passed, then restored when a test ran and its restore passed (open failures whose evidence is resolved marked restored), else clean; a commission that passes is a restoration.cleanup.lock(a commission'slock) names a lock that did not end as its verdict said: a blocker.
Code format
- The library's
.pre-commit-config.yamlis authoritative: its clang-format hook (v15) on C, C++ and headers minus the hook'sexcludelist; CI runs the same hook. Format through it, never aclang-formatfromPATH(another version formats differently):pre-commit run --files <changed files>rewrites them in place and reports failed when it changed any; read the rewrite. - Neither library has a
.clang-format, so clang-format falls back to LLVM style; never add one or copy tinyusb's. clang-format takes the first.clang-formatabove the file, so format only in a checkout with none above its root (~/Arduino/libraries/<lib>, its.worktrees/): one nested under tinyusb or a core'slibraries/(arduino-esp32 has its own) formats in that tree's style, and v15 cannot parse tinyusb's file. - TinyUSB Arduino's vendored TinyUSB (the paths its
AGENTS.mdnames) keeps tinyusb's format: fix it in hathach/tinyusb under tinyusb's.clang-format, then copy it back as thatAGENTS.mdsays.
A core
An Arduino core (a platform checkout such as adafruit/ArduinoCore-samd) uses the same engines in core mode: its build
profile names PLATFORM (vendor:arch) and the other optional names arduino_build.py's docstring lists. What
changes from a library:
- Builds compile through an isolated arduino-cli environment per run (
build/.arduino-cli-<pid>/): a config whose sketchbook linkshardware/<vendor>/<arch>to the checkout and holds only the prepared dependencies, the user's data dir (toolchains) unchanged. A build whose platform resolves anywhere but the checkout fails, so neither an installed copy of the core nor a~/Arduino/hardwarelink to another checkout is ever tested by mistake. Each compile appends-ffile-prefix-map=<that dir>=.arduino-clito the FQBN's resolvedcompiler.{c,cpp,S}.extra_flags(the platform's and--build-propertyvalues kept), so an image embedding__FILE__names no PID and two builds of one commit match; the core's compilers must be GCC 8 or later. - Libraries the core bundles are its own: a user copy of one is never prepared and fails a build that used it
(library mode admits such a shadow). Dependencies are the profile's
EXTRA_DEPENDENCIESand theirdepends=. - Sketches are every
*.inodir underSKETCH_ROOTS(the bundled libraries,extras/included, as a core'stools/build_all.pyscans), eligible by that script's.all.test.skip/.<platform>.test.skip/.<platform>.test.onlymarkers and the profile'sexclude(); they build under their path, since bundled libraries share example names. A changed sketch file selects that sketch before the profile's rules (in a library too). - Selection adds two effects for
classify_source:boards(every eligible sketch on the named boards, e.g. aboards.txtorplatform.txtchange on CI's matrix) andsketches(the named sketches on every representative, e.g. a bundled library's source). - One rig board, several menus: the profile's
fqbn(board, example)gives a HIL sketch its own FQBN (a USB stack menu); the record keeps each sketch's FQBN and the report names them (firmware.fqbns). A named build (featurenamed) builds one sketch dir under several names: aHIL_SKETCHESentry{name: (sketch dir, 'k=v,...')}sets those menu options on the board's FQBN, and the name keys its build dir,fqbn(), its record sketch (which also names itssource) and the test that runs it; a change to the dir builds every name it has.bind()refuses a name that is no plain file name, an id listed twice in a role and one defined two ways across roles. - Identity: a record also binds the submodules (
git submodule status --recursive) and refuses one that is not initialised, not at its gitlink or dirty (each one's own worktree, at any depth, whatever itsignoresetting),--experimentalincluded: a record's patch carries no submodule bytes. A record also refuses any untracked file (a library: undersrc/,examples/ortest/hil/; either can set its ownSOURCE_DIRS). Foreign headers are those from another copy of the core (byplatform.txtname=). - Base image (feature
base): a rig board whose sketches run only above other firmware (an nRF52's MBR, SoftDevice, bootloader and its settings) names those HEX files asBOARDS[...]['base'], with the address ranges never touched asbase_exclude(UICR). The record binds the files and their runs, which must lie outside the board's span; the harness admits them with the record and, before every J-Link flash (battery, commissioning, a manual flash or restore), verifies each run in place. Only averifybinof the check's own script that read the target after a cleanhaltand found it different is a difference: then the runs are rewritten and verified, with no reset or go before the sketch's flash, and the row'sbasesaysmatchedor which run differed. A check that proves nothing (no connection, a failed or partial read, a timeout) writes nothing and fails the step. A rewrite may erase the rest of each flash page a run touches, so those pages must be the base's. Only runs are checked: a word the boot reads that the HEX leaves unprogrammed (the MBR's bootloader address at 0xFF8) is a run of its erased value in a profile HEX, or another image's bytes there pass asmatched. The board's budget and each step's reserve grow by a check and a rewrite. Through J-Link only: a record refuses a base on any other flasher.
CI
arduino_ci.py (a library's hil_ci.py wraps it) splits a run between hosted builds and the farm's binary-only
battery. Its docstring defines setup, packing, admission, lock waits, retries, deadlines and pruning. Packed trees
pin the inner agentrc/manifest.json in the outer manifest; old bootstraps retain the outer commit/dirty identity.
Admission checks consistency, not trust: a pull request's code, harness included, runs as the rig runner's user.
The library's workflow and report comment are its own.
Adding a library
- Copy
skills/arduino/scripts/agentrc_pin.pyverbatim to.claude/skills/hil-contract/scripts/agentrc_pin.pyand configuretest/hil/agentrc.jsonas its docstring specifies. Put both files in the profile'sCONTRACT_FILESso staged trees carry them. Copy and repin together; keep profile/config tests in the consumer, with common bootstrap behavior and the staged round trip (test's conformance check) in agentrc. - Write the build profile: CI's matrix boards with their FQBNs, the rig boards it will run on (named as in agentrc's
board registry, each with its
span), representatives, classification of itssrc/tree, HIL sketches. Prove it withcheck_build.py --select-onlyon representative diffs and a full--recordbuild per rig board. - Write dedicated HIL sketches, never examples, that end each exchange with a result line tied to the host's nonce,
and a restoration sketch with no erase or write path, so the state a battery leaves survives it (name any
side effect its init still has, as SPIFlash's
flash.begin()setting a quad-enable bit). Write their host-side checks inhil_test.py. A core reuses the shared battery instead (featurebattery): itscore_cdcandcore_timingsketches answerarduino_hil.py's INFO / ECHO / TIME / DELAY protocol (its docstring), its profile names them inCORE_TESTSwith the stack INFO reports, setsECHO_LENGTHSand its tolerances, and writes only its own checks inTEST_FUNCS, built from the same pieces (an nRF52's RTOS check aftercore_timing_check). - Add the boards to
test/hil/ci.json, commission each (hil_test.py commissionon the board's host), run the battery on the farm (hil_remote.py run), and record what no board covers as the contract's Limits. - Contract tests for the profile in
.claude/test/, a pre-commit hook runningagentrc_pin.py test(the installed agentrc locally, the pin in CI) beside the clang-format hook (Code format). - Agent files with no tracked symlink: arduino-lint LS005 keeps a library release holding one out of the Library
Manager, and a core keeps the libraries' layout. A regular
AGENTS.mdnames the build and HIL contracts and, in an "Agent files" section, says the skills are in.claude/skills/<name>/SKILL.md;CLAUDE.mdholds only@AGENTS.md; no.agents. Copy SPIFlash'sno-symlinkspre-commit hook unchanged.install.py --projectlinks are untracked, so they never reach a release.
A core follows the same steps with its core-mode profile. Set features to include core, plus base for a rig
board's base image, named for named HIL builds and battery for CORE_TESTS. These are additive capabilities of
profile API 1, checked before any engine executes. A consumer that runs the shared report commenter adds
skills/hil/scripts/gh_pr_comment.py to extra_engines; one with a hil_ci.py wrapper also adds
skills/arduino/scripts/arduino_ci.py. Every entry point loaded through the bootstrap must belong to its closure.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

