Skip to content

Lab: set up lab/main, the base for lab builds (#92) - #103

Open
dayfine wants to merge 69 commits into
mainfrom
lab/main
Open

dayfine wants to merge 69 commits into
mainfrom
lab/main

Conversation

@dayfine

@dayfine dayfine commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

lab/main is the base every lab build on consoles A and B merges, and it has grown things worth having on main. This brings them over: the Command File Runner (a developer program that runs text command files against the live console: press, dpad, stick, wait, shot, detect, wait_for, expect, state, walk until the screen holds still, history, close_game, with games able to register their own commands), its parsing unit tests and README, and the unit test runner using the configured build directory. The two settings defaults it also carried go to main on their own in #104; once that merges and main is merged back here, they leave this diff. Tested on the fork CI and in daily use on both lab consoles since 2026-10-29. Merging this makes fork #58 (the CFR alone) redundant.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

dayfine and others added 4 commits October 31, 2026 09:21
* Add Command File Runner, a developer program driven by text command files

Answering "does this detector fire on that screen?" meant a rebuild and a
full program run. Command File Runner runs .txt files dropped into
<folder>/inbox against the live console, one command per line (press,
dpad, stick, wait, shot/shots, detect, wait_for/expect, state, close_game,
help, stop), and writes a timed result file with screenshots to
<folder>/outbox, stopping a file at its first failing line.

Options set the command folder and whether to stop once the inbox is
empty. Games can register their own commands and detectors. README.md
next to the code documents the file format and every command; like the
other testing programs it has no page on the documentation site.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Command File Runner: unit tests for reading command files

Moves the line splitting, button and D-pad names and the inbox order into
their own file, unchanged, and tests them without a console.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Command File Runner: replace CommandLine with free functions

A command line is now just its words: split_command_line() returns them,
and required_arg(), optional_number() and optional_duration() read
arguments from them, with the same error messages. All definitions move
to the .cpp. Adds a unit test for the argument readers and checks the
error messages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Command File Runner: read numbers with strtod() instead of std::stod()

On the macOS Intel CI build, the std::invalid_argument from std::stod()
escapes the catch (std::exception&), so the "argument errors" test failed
with "Unknown exception". strtod() reports a bad number without
throwing; the error message is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Command File Runner: walk until the screen holds still, and report how long it moved

A timed stick hold moves a different number of tiles from one try to the
next, so a map measured with holds is not measured. "walk x y" holds the
left stick in 200 ms slices and stops when two slices in a row barely
change the screen (a wall, a sign, someone in the way).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Command File Runner: 'history label' saves the console's recent video

With Stream History on, a lab script can keep the video of a program run
that just ended (the RNG reset and launch) by running this right after.
Ported from beceebc on lab/frlg-nav-cfr to the free-function command
signature.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
* Code health: skip nested and detail classes in the single-method interface check (#82)

A class nested in another class, or in a detail or anonymous namespace, is an
implementation detail such as a type-erasure base, not an interface others
implement. MoveOnlyFunction's private Callable base was flagged.


Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Code health: lexical C++ style checks on added lines (#94)

* Code health: skip nested and detail classes in the single-method interface check

A class nested in another class, or in a detail or anonymous namespace, is an
implementation detail such as a type-erasure base, not an interface others
implement. MoveOnlyFunction's private Callable base was flagged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Code health: lexical C++ style checks on added lines

Check the lines a change adds for the upstream bans (std::filesystem,
std::thread, std::mutex, std::async), control-flow brace formatting, and
the Abseil tips adopted in the fork's C++ style notes: mutable globals
(#103), new/delete (#126), std::bind (#108), return std::move(local)
(#120), top-level const by-value header parameters (#109), bool
parameters (#94), header using-directives (#153) and forward
declarations. A comment that describes a neighbouring function is an
advisory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* code_health: match functions to their base by name, not by signature (#95)

Changing a parameter's type (std::function to MoveOnlyFunction in #90) changed
the function's key, so an existing 133-line constructor was held to the new
limit of 50 instead of its base length. Functions now match on their qualified
name without parameters; messages still show the full signature.


Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* Settings: default audio display and collapsed console settings

Two global settings for people who run many programs on one lab machine:
"Default Audio Display" (Audio Pipeline group) is what a program's console
shows for its audio until that console's own setting is saved, so a new
panel no longer opens with the frequency bars; and "Start with console
settings collapsed" folds each program's "Console N Settings" box at
creation, so the video is at the top. Both default to today's behavior.

AudioOption takes its initial display type from the global setting
instead of a fixed FREQ_BARS; a panel's saved value still wins.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
(cherry picked from commit 92d1ed3c6f6fa0468827ab15c51ec3cc71f01d32)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
dayfine added a commit that referenced this pull request Nov 1, 2026
…104)

* Code health: skip nested and detail classes in the single-method interface check (#82)

A class nested in another class, or in a detail or anonymous namespace, is an
implementation detail such as a type-erasure base, not an interface others
implement. MoveOnlyFunction's private Callable base was flagged.

Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E



* Code health: lexical C++ style checks on added lines (#94)

* Code health: skip nested and detail classes in the single-method interface check

A class nested in another class, or in a detail or anonymous namespace, is an
implementation detail such as a type-erasure base, not an interface others
implement. MoveOnlyFunction's private Callable base was flagged.


Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Code health: lexical C++ style checks on added lines

Check the lines a change adds for the upstream bans (std::filesystem,
std::thread, std::mutex, std::async), control-flow brace formatting, and
the Abseil tips adopted in the fork's C++ style notes: mutable globals
(#103), new/delete (#126), std::bind (#108), return std::move(local)
(#120), top-level const by-value header parameters (#109), bool
parameters (#94), header using-directives (#153) and forward
declarations. A comment that describes a neighbouring function is an
advisory.


Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

---------



* code_health: match functions to their base by name, not by signature (#95)

Changing a parameter's type (std::function to MoveOnlyFunction in #90) changed
the function's key, so an existing 133-line constructor was held to the new
limit of 50 instead of its base length. Functions now match on their qualified
name without parameters; messages still show the full signature.

Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E



* Settings: default audio display and collapsed console settings

Two global settings for people who run many programs on one lab machine:
"Default Audio Display" (Audio Pipeline group) is what a program's console
shows for its audio until that console's own setting is saved, so a new
panel no longer opens with the frequency bars; and "Start with console
settings collapsed" folds each program's "Console N Settings" box at
creation, so the video is at the top. Both default to today's behavior.

AudioOption takes its initial display type from the global setting
instead of a fixed FREQ_BARS; a panel's saved value still wins.


Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
(cherry picked from commit 92d1ed3c6f6fa0468827ab15c51ec3cc71f01d32)

---------


(cherry picked from commit 0e737fb)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
dayfine and others added 4 commits October 31, 2026 21:12
When <user files>/LabControl/ exists, the main window polls it every
500 ms. A "start" or "stop" file does what clicking Start/Stop Program
does and is then deleted; "state" holds the program state and the
selected program's identifier. Nothing changes when the folder is absent.

The button's handler moves into start_or_stop_program() so both paths
share it.

Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f6f658f)
The folder, the start/stop files, the state file's lines and when the
error line appears were described only in LabControl.h's header and in
the lab scripts that use it. This says it next to the code, with the
shell sequence a script uses.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
(cherry picked from commit 953ae68)
Answering "does this detector fire on that screen?" or "how far does a
hold move?" meant a rebuild and a full program run. The Command File
Runner runs .txt files dropped into <folder>/inbox against the live
console, one command per line (press, dpad, stick, wait, walk until the
screen holds still, shot, shots, history, detect, wait_for, expect, state,
close_game, help, stop), and writes a timed result file with screenshots
to <folder>/outbox, stopping a file at its first failing line. Games can
register their own commands and detectors. README.md next to the code
documents the file format and every command; unit tests cover the
parsing. Squashed from fork lab/main (fork PRs #58, #84, #92).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
…recipes

How a console automation segment goes from idea to three passes in a row:
define, code, observe, hypothesize, verify by hand with one CFR batch per
question, fix one thing, rerun; the Switch as an external machine, hard
stops, what to measure before fixing, and the CFR recipes (launch to a
save from HOME, count tiles by taps, find a wall, talk and answer prompts,
record a human walk, measure a threshold, recover). From the fork's
agents branch (fork PRs #96, #101). Under skills/ because .claude/ is
ignored in this repo.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
dayfine and others added 18 commits October 31, 2026 21:26
…om the shell

Three portable sh scripts under devtools/lab that speak the app's two file
protocols: lablock.sh holds one console for one command (a "train") and
hands its token down, so a stray script from an old run cannot touch what
the current run drives; labctl.sh starts, stops and reads the selected
program through the Lab Control folder; cfrun.sh sends one Command File
Runner batch and prints its .out, stopping only the lab's own keep-awake
and refusing any other running program. The README explains the three,
the one-train rule, the folders they use, and the gap that stays out:
the app has no way to select a program from a script.

Tested without a console: sh -n on each, and dry runs against a fake app
that plays both folder protocols (lock nesting, refusal, waiting and
stale clearing; start/stop/state; a passing batch, a failing line, a busy
console, a wrong selected program, keep-awake and the select hook).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
The skill described the loop through one game's lab: checkpoint names,
run ids, map names, a traps section and the scripts of one lab folder.
Now it is the loop for any console automation segment, with each rule's
reason kept as one generic clause. The CFR recipes section is gone;
where the loop uses the Command File Runner or the Lab Control folder it
says so inline (read the state file to see what runs, one batch per
question, the lock, the HOME-tile check before a reload) and leaves the
command table to the CFR README and the folder protocol to LabControl.md.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
The lab channel will run the same commands from a worker thread with no
program running, so the runner's line runner is reachable through free
functions (run_command_file_line, command_file_command_kind, the error
screenshot and help) instead of living inside the program's loop. The
command session takes a console and a controller context rather than a
program environment. Splitting lines, finding the next inbox file and the
two journal lines move to CommonFramework/Windows/LabRequest, which the
channel shares; the journal's failure line is now "error <line> (...)".
Also ports the lab's "taps" command (D-pad taps, each measured against the
frame before it) with its argument parsing and test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
…lder

Scripts drove the app through two mechanisms: the LabControl/ folder for
start and stop, and the Command File Runner's inbox for presses and
detectors, which needed that program selected and running. The lab channel
is one folder, <profile>/Lab/, independent of the selected program. A
request is inbox/<name>.txt, one command per line, run in order from a
worker thread and moved to done/; its journal outbox/<name>.out has one
"ok"/"error" line per command and ends with "end"; "state" is rewritten
after every request and whenever the program state changes, with seq,
state, program and the last error.

Commands: start, stop, state, help, and every Command File Runner command.
Presses run only while no program runs; screenshots and detectors any
time. The window actions run on the UI thread through LabChannelHost; the
console commands come from a LabConsoleCommands implementation per console
type (SwitchLabCommands), wired in Main.cpp. A panel change cancels the
command running on the old panel before it is destroyed. LabControl is
removed; its tests move to the channel's, which cover the request and
journal formats and the state text.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
"select GAME:PROGRAM" shows that program as clicking it in the program list
does (ProgramSelect::select_program looks the identifier up across the
game lists, PanelListDescriptor exposes its entries for that), and the
request fails if the window did not switch. "set KEY JSON" sets one option
of the selected panel by its key in the settings file, live: the panel's
JSON is taken, the key (a dotted path for groups) replaced, and loaded
back without the ConsoleSetup section, which would reconnect the devices;
the journal prints the value the panel then holds, so a clamped or refused
value is visible. Both are refused while a program runs, and both run on
the UI thread.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Two scripts driving one console interleave their presses, and the lab ran
a Prevent Sleep program between runs just to keep the console awake.
"owner claim TOKEN" claims the channel; after that every request that
changes anything (select, set, start, stop, keepawake, presses) must start
with the line "owner TOKEN" or is refused naming the holder, while
state, help and the screen-reading commands stay open to all. "owner
release" with the token frees it; the lock lives in memory and dies with
the app. "keepawake on|off [seconds]" has the worker press B every N
seconds (default 15) while no program runs, through the console commands'
keep_awake(); a running program pauses it. "state" gains the owner line.
Tests cover the owner line of a request, the lock's rules and the
schedule.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Lab.md documents the channel in one place: turning it on, the request,
journal and state formats, every channel and console command with its
defaults, the detectors, the owner rule, a shell session that launches the
app on a profile, claims the channel, selects a program, sets two options,
starts it, waits for STOPPED and releases, with the request and the
journal it produces, and what remains of the Command File Runner program.
The runner's README keeps its program-specific parts and points at Lab.md
for the commands; LabControl.md says where the old folder went.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
labctl.sh sends one channel request per call and prints its journal:
state, start, stop, select ID, set KEY JSON, owner claim/release,
keepawake, and send NAME for any request from stdin; LAB_OWNER puts the
owner line first. cfrun.sh is the lock plus labctl.sh send: no program
has to be selected or started for a batch any more, and the Prevent Sleep
handling goes (keepawake replaces it), so the CFRUN_SELECT gap closes.
lablock.sh is unchanged. The README follows: the channel instead of the
two folders, a worked run of a program with nothing clicked, how to run a
lab app beside the live app (a second bundle id, open -n, --profile), and
probing between runs. The skill points at Lab.md. Dry-run against a fake
app serving the Lab folder: every command, a failing batch, the lock
refusal and the no-app timeouts behave as documented.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
The repo's C++ style asks for std::format where a message has several
parts, instead of "+" / std::to_string chains or an ostringstream. Converts
the journal lines, the argument errors, the screenshot labels, the walk
report's change list and the test messages in the runner and the lab
channel: 18 std::to_string sites and one ostringstream, with the same text
as before ({:f} keeps to_string's six decimals). The two ostringstreams
that collect a request's journal stay: they are the std::ostream the
commands print to, not a message.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Lab.md's "Changes from the lab control folder" section already says where
the old folder went; a pointer file next to it is one more place to read.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
start_or_stop_program() reports the ProgramSession's error to the UI
listeners and returns nothing, so a start that check_validity() refused
was journaled as "ok" and the request went on with the program still
STOPPED. The channel now calls start_program()/stop_program() itself and
returns their error, which becomes the request's error line.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
…text

The words of a line are split on spaces and cut at '#', so "set KEY
\"a  b\"" reached parse_json() as "a b" and a string with a space and a
'#' was cut into invalid JSON. strip_comment() now respects JSON quotes
(with '\' escapes) and the line's words are split after it; "set" takes
its value from the line itself, line_after_words(), with spaces and '#'
intact. Tests cover both, and "set KEY" without a value is an error.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Main.cpp is back to upstream's and MainWindow's public surface is
unchanged: the window keeps one private member, created by
LabChannel::start_if_enabled() with two callbacks (the current panel, and
select by identifier) and told of panel changes. The call returns nullptr
when "<user files>/Lab/" does not exist at startup, so an app without the
folder starts no worker and polls nothing; the folder is created before
launch (Lab.md, labctl.sh say so). The worker is a pool task whose
completion the destructor waits for, instead of a Thread, whose join()
does not wait under the Qt thread-adoption workaround and could leave the
worker touching a destroyed channel.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
A screenshot or detector request while a program ran waited for the
controller's queue to drain, i.e. for the program's own presses, before
taking a frame; a long hold delayed the read, and the stop request queued
behind it. The command session now says whether a frame waits for the
controller: the channel sets it only for commands that drive the console
(where a screenshot must show the state after the press before it); the
Command File Runner program keeps waiting, as before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
mkdir publishes the lock before its pid file is written, and a concurrent
caller took the pid-less directory for a dead owner's, cleared it and
took the lock itself: with 20 concurrent callers, 5 or 6 were admitted
and their work overlapped. A lock without a pid now counts as held while
it is younger than 5 s (an owner still writing it) and as stale after
that; the pid is written last, and the exit trap removes the lock only
while its token is ours. lablock_test.sh runs the race: 20 callers, one
admitted, 19 refused, no overlap, three times in a row (the old script
fails it).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
dayfine and others added 30 commits November 3, 2026 13:43
Run the existing test database through a dedicated QCoreApplication executable with isolated logs and no settings or device scans. Support name filters and listing while preserving the GUI test mode exit status.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
* Fail closed on unsafe lab startup and isolate explicit test launches

* Fix startup source paths in the application build

* Extract application shutdown without changing startup behavior

* Separate general startup validation from lab identity policy

* Keep device shutdown initialization out of persisted test mode

* Group Main.cpp helpers in one anonymous namespace

* Nest file-local helpers in PokemonAutomation without a using directive
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
* Lab: seed isolated profiles and validate staged app identity

* Lab: seed settings under the runtime UserSettings path

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Lab: seed isolated profiles and validate staged app identity

* Lab: seed settings under the runtime UserSettings path

* Lab: enforce profile and device leases before hardware opens

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…emonAutomation#1857)

* PokemonSV: add test for DialogArrowDetector::locate_dialog_arrow

Adds a simple ImageUnitTest that runs locate_dialog_arrow() on a screenshot
and passes if the arrow is detected. Test image:
CommandLineTests/PokemonSV/DialogArrowDetector/ParadiseProtectionProtocol_BattleStart-20261106-130450.png
(needs the corresponding CommandLineTests PR merged).

* fix failing test

---------

Co-authored-by: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com>
Co-authored-by: jw098 <justin.wong098@gmail.com>
…ation#1612)

* Python: basic pybind11 interface to the microcontroller

Adds _pa_core, a pybind11 module (new PA_PYTHON_BINDINGS cmake option, OFF
by default) that wraps the existing CoreLib class
NintendoSwitch::PybindSwitchProController so Python can act as a Nintendo
Switch controller through a PABotBase2 serial device: status, queued button /
d-pad / stick commands, flush and cancel, button/d-pad constants, and
log-to-stderr/file controls. C++ exceptions surface as RuntimeError;
blocking calls release the GIL.

The pokemon_automation Python package sits on top of it:
SwitchController (button names instead of bitfields), button parsing,
list_serial_ports(), a hardware-free FakeController, a hardware self-test,
and a pytest suite. See SerialPrograms/Source/PythonBindings/README.md.

A new CI workflow builds the GUI-free core plus the module on Ubuntu and
runs the pytest suite. PR PokemonAutomation#1519 is used as a reference.

* Python: stop committing pip egg-info leftovers

* Python: switch to cancel_all_and_wait(); stop miniz.c warnings breaking CoreLib

The rebased branch picked up AbstractController::cancel_all_and_wait()
(cancel + wait for the device to acknowledge the neutral state, returns a
bool), which replaced the old fire-and-forget cancel_all_commands(). Update
the _pa_core binding, the pokemon_automation API (cancel_all_and_wait() now
returns whether the device confirmed; close() uses it to guarantee a neutral
state), the fake controller, the tests, and the docs.

Also compile the third-party 3rdParty-Core/miniz-3.1.1/miniz.c with warnings
off (/W0 on MSVC, -w on GCC/Clang): it is compiled straight into CoreLib, and
newer compilers emit warnings in it that -Werror / /WX turn into build errors.
It includes miniz.h from its own directory, so a SYSTEM include directory
cannot shield it; suppressing the file itself is the portable fix.

* Move the miniz.c warning suppression into pa_apply_base_target_properties()

The old copy in CMakeLists.txt only runs in the full build: with
PA_CORE_ONLY the configure returns before reaching it, so miniz.c was still
compiled with -Werror / /WX in core-only builds. Setting the source property
from pa_apply_base_target_properties() (cmake/CoreLib.cmake) covers both build
modes and every target that uses it; the two now-redundant copies are removed.
Use if(MSVC) instead of if(WIN32) - the flag choice follows the compiler's
command-line dialect (true for cl and for clang-cl), and COMPILE_OPTIONS
instead of the deprecated COMPILE_FLAGS.

* Put the miniz.c warning suppression in the base CMakeLists.txt, before PA_CORE_ONLY

miniz.c is compiled into every target that uses CORE_LIBRARY_SOURCES -
CoreLib in both build modes, and SerialProgramsLib in the full build (which
compiles its own copy of the core sources), so the fix belongs in the base
CMakeLists.txt, not CoreLib.cmake. It must also run before the PA_CORE_ONLY
early return, which is where the old copy at the bottom of the file (from
PokemonAutomation#1098) was, and why core-only builds still failed. Source properties are
global, so one set_source_files_properties() covers all targets; verified
that in a full build both CoreLib's and SerialProgramsLib's miniz.c compile
lines carry the suppression.

* update pybind README

* Python bindings README: small fixes

- 'simulatenously' -> 'simultaneously'
- selftest code block: [port] is not shell syntax; show the optional
  argument as a real example instead
- rename 'Running the test file' to 'Hardware self-test' (the pytest suite
  lives in tests/) and add the missing 'Running the unit tests' section,
  which the Layout section advertises but nothing in the file explained
- add wait() to the method list (it is used in the example)
- drop trailing whitespace

* more README updates

* pybind CI

* update CI

* rename selftest to controller_test

* rename files

* Python: label where the Python code references the C++ code

Add comments naming the C++ source each Python definition mirrors or
depends on (repo-relative paths): the BUTTON_BITS/DPAD_POSITIONS constants
and check_against_core() vs the enums in
NintendoSwitch_ControllerButtons.h; the ControllerBackend protocol,
status/flush/cancel_all_and_wait and press() vs
PybindSwitchProController / AbstractController; the fake and the _core
loader vs the module source and the wrapped class; and the test headers.
Also note that DEFAULT_HOLD_MS/DEFAULT_RELEASE_MS are Python-side defaults
(the C++ issue_buttons() takes explicit durations).

* minor update to switch_connection_test.py

* add comments

* minor update to switch_connection_test.py

* add comments

* Python: name SwitchController commands after the backend methods

The command methods of SwitchController now match the names of the
_p a_core.Controller methods they wrap (and thus the C++
PybindSwitchProController methods):

- press()       -> push_button() / push_dpad() (mixed combos now go to
                   controller_state(); each method rejects the other kind
                   with a pointer to the right method)
- hold()        -> controller_state() (duration_ms first, like the C++
                   signature; no implicit release wait)
- stick(side)   -> push_left_joystick() / push_right_joystick()
- flush()       -> wait_for_all_requests()
- status()      -> current_status()
- name()        -> controller_name()
- wait(), cancel_all_and_wait(), is_ready() and close() already matched.

Button-name parsing is unchanged; _pa_core and FakeController are
untouched. Updated examples in the package docstrings, README,
switch_connection_test.py and the tests (31 tests now, including
rejection of mixed inputs in push_button()/push_dpad()).

* Python: drop the repeat option from push_button()/push_dpad()

Each call now queues exactly one tap, matching the single-command
semantics of the C++ layer; repeated presses are just repeated calls
(or a controller_state() with a longer hold).

* add comments

* Python tests: add a short docstring to every test function

* add comments

* update comments

* Python tests: drop test_matches_cpp_enum, duplicate of test_python_constants_match_cpp

Both tests just call buttons.check_against_core() with the module's
BUTTONS/DPAD_POSITIONS dicts. Keep the one in test_core.py (the
compiled-module file, skipped wholesale when _pa_core is not built).

* add comments

* rename variables

* Python: follow the duration_ms/hold_ms/bitfield renames through all call sites

Two call sites still used the old push_left_joystick(duration_ms=...)
keyword, which now raises TypeError:

- the quick start in pokemon_automation/__init__.py
- the example in the README

Also rename the FakeController parameters to the new backend names
(button_bitfield, dpad_position) so it matches the ControllerBackend
protocol, and fix two stale 'delay = duration + release' docstrings in
test_fake_controller.py.

* Align pybind/Python controller API with the PBF API

Argument order now matches NintendoSwitch_Commands_PushButtons.h
(input first, then timing, no context parameter):

- push_button(button_bitfield, delay_ms, hold_ms, release_ms)
- push_dpad(dpad_position, delay_ms, hold_ms, release_ms)
- push_left_joystick(joystick_position, delay_ms, hold_ms, release_ms)
- push_right_joystick(joystick_position, delay_ms, hold_ms, release_ms)
- controller_state(button_bitfield, dpad_position, left_x, left_y,
  right_x, right_y, duration_ms)  (duration last, like pbf_controller_state)

The pybind controller keeps delay_ms (pbf_*() always uses
delay = hold + release; that combination is what the Python layer
queues). The joysticks take a single (x, y) joystick_position tuple
instead of separate x/y arguments, and the Python
push_left_joystick()/push_right_joystick() only accept coordinates
(parse_stick_position(), no direction-name strings); parse_stick()
keeps string support for controller_state()'s left/right.

* push_*_joystick(): back to separate x, y arguments

On request, the joysticks take separate x, y arguments again instead of
a single (x, y) joystick_position tuple:

- C++: push_left_joystick(x, y, delay_ms, hold_ms, release_ms)
- module: py::arg("x"), py::arg("y"), ...
- Python: sw.push_left_joystick(0.0, 1.0, hold_ms=1500)

No parsing step is needed anymore (x, y are plain numbers; the C++
binding enforces numeric types), so parse_stick_position() was removed
and parse_stick() keeps its (x, y)-pair helper for
controller_state()'s left/right.

* Python push_*_joystick(): accept an (x, y) joystick_position tuple

The Python layer now takes the stick position as a single (x, y)
tuple/list argument, joystick_position, for both push_left_joystick()
and push_right_joystick(). The pair is unpacked at the
ControllerBackend boundary, so _pa_core (and FakeController) keep the
C++-shaped separate x, y arguments:

    sw.push_left_joystick(joystick_position=(0.0, 1.0), hold_ms=1500)

The pair validator is promoted from _parse_stick_pair to a public
parse_stick_pair() (two numbers, in [-1, 1], no strings/None), reused
by parse_stick() and exported from the package.

* update comments. add kwargs

* Python controller_state(): left_joystick/right_joystick as (x, y) tuples

controller_state() now takes the sticks as (x, y) tuples, renamed from
left=/right= to left_joystick=/right_joystick= to match
push_*_joystick(). None (the default) releases the stick; direction-name
strings are no longer accepted there (parse_stick_pair() validates, so
the same error messages as joystick_position apply). The pairs are
unpacked at the ControllerBackend boundary, so _pa_core keeps the
C++-shaped separate left_x/left_y/right_x/right_y arguments.

Also tighten the joystick_position annotations from Sequence[float] to
tuple[float, float] (lists still work at runtime; the annotation now
says exactly what is expected).

* Python controller_state(): split buttons and dpad; push_dpad arg -> dpad

controller_state() now takes buttons and dpad as separate arguments,
matching pbf_controller_state() and the C++ backend
(button_bitfield, dpad_position, ...):

    sw.controller_state("B", "up", left_joystick=(0.0, 1.0), duration_ms=2000)

The buttons argument rejects d-pad directions (and the dpad argument
rejects buttons) with an error pointing at the other argument - the same
rules push_button()/push_dpad() already enforce. The one-string mixed
form ("ZL+up") is no longer accepted.

push_dpad()'s argument is renamed position -> dpad. _pa_core /
FakeController are unchanged (the backend already has them separate).

* update comments

* minor fix

* update switch_connection_test.py

* update comments

* update README

* update comments

* update comments

* update pybind CI

* PythonBindings.cmake: do not download pybind11; error with install steps

Drop the FetchContent fallback. If pybind11 is not found (system
package or pip-installed for the target interpreter), configure now
fails with a FATAL_ERROR that names the interpreter and gives the
install commands, instead of silently git-cloning a pinned pybind11
release during configure. Builds no longer reach the network on their
own. README updated to match.

* update pybind CI

* update comments

* Python bindings: fix doc typos and stale example kwargs

- controller.py: cancel_all_and_wait() docstring cited the old C++\n  parameter name (timeout_millis -> timeout_ms).\n- README: 'insid' -> 'inside', 'run the all tests' -> 'run all the tests',\n  queue examples used a nonexistent duration kwarg (now hold_ms, which is\n  what push_left_joystick() actually takes), and mkdir bin -> mkdir -p bin\n  so the instructions work on a re-run.\n- test_push_right_joystick now actually passes a [x, y] list, matching its\n  docstring (lists are accepted via parse_stick_pair).

* Fix bug: close() serialization
close() no longer lets a command slip in after the cancel: the closed
flag is set under the command lock, and every command method re-checks it
while holding the lock before sending, so commands starting while the
cancel is in flight are rejected.

* fix Empty port name: SerialPABotBase2_Descriptor::open_connection() returns
nullptr for an empty name, leaving m_connection null and crashing
current_status(). The constructor, destructor, controller() and
current_status() now tolerate a null connection ("No connection."), and
SwitchController rejects an empty port up front with a ValueError.

* Fix review bugs: destruction race, empty port

#1 Destruction race (PybindSwitchController.cpp): the connection thread is
joined only when m_connection is destroyed, i.e. after m_controller, m_cv
and m_lock already were. Destroying the controller while a connection is
still establishing (e.g. SwitchController's timeout path) let the connect
thread write to destroyed members. The destructor now resets m_connection
first, so the thread is joined before any member is destroyed.

#2 Empty port name: SerialPABotBase2_Descriptor::open_connection() returns
nullptr for an empty name, leaving m_connection null and crashing
current_status(). The constructor, destructor, controller() and
current_status() now tolerate a null connection ("No connection."), and
SwitchController rejects an empty port up front with a ValueError.

* update README

* update README

* Rename SwitchController to SwitchProController

Matches the C++ class it wraps (PybindSwitchProController) and the
device's controller type (the Pro Controller / wired controller).
No backwards-compat alias: the package is pre-release (0.1.0).

* add comments

* buttons.py: remove the BUTTON_ALIASES table

START/SELECT/L3/LS/R3/RS and the "+"/"-" spellings no longer map to
PLUS/MINUS/LCLICK/RCLICK. "+" remains a separator (a lone "+" parses to
no input), and "-" and the former alias names are now unknown buttons
with the usual ValueError. Removed the now-dead "+"/"-" special cases
in _split()/parse_buttons(), the __init__ export, and the docs; the alias
test now pins the new behavior.

* fix comment

* update comments

* minor update to error message

* update comments

* minor fixes

---------

Co-authored-by: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com>
Co-authored-by: jw098 <justin.wong098@gmail.com>
…mation#1847)

* Build: add an opt-in macOS ccache preset

New worktrees and branch switches on Mac rebuild everything from scratch.
The macos-ccache preset is RelWithDebInfo plus a shared 10 GB ccache with
checkout-relative paths, so worktrees reuse each other's compiles. A short
guide is linked from the Mac build instructions. Other presets and CI are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Set up ccache in CMake and add it to the Mac build guide

Address review on PokemonAutomation#1767.

- Add cmake/Ccache.cmake, included from CMakeLists.txt. With
  -DPA_USE_CCACHE=ON (default OFF) and ccache 4.8+ installed, every compile
  runs through ccache:
  - PA_CCACHE_CONFIG: ccache settings passed on every compile's command
    line. The default keeps this project's cache in a "PA-Arduino-Source"
    folder inside ccache's own cache folder, and sets base_dir to the
    checkout's root folder, so all worktrees share one cache without
    changing ccache's global config.
  - PA_CCACHE_DEBUG_PATHS (default ON): adds -fdebug-prefix-map and
    -fdebug-compilation-dir to Debug and RelWithDebInfo builds, so builds
    with debug info share the cache across worktrees too.
  - Stops with an error if a compiler launcher is also given, or if ccache
    is older than 4.8.
- Mac build guide: install ccache as a normal step, turn it on in the
  CMake command, and add "Part 7: Tuning ccache".
- Remove the macos-ccache preset and Build-Mac-CompilerCache.md: the
  preset's settings are now in cmake/Ccache.cmake, and the guide covers
  the rest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: dayfine <difancpa@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Gin <>
* FRLG BoxSorter LivingDex

* Fix build after rebase

* cleanup
…els. (PokemonAutomation#1854)

Follow-up to the [0,255] -> [-1,1] joystick / ticks -> ms refactor (Dec 2025).
(The Segment_38 u8 joystick values were fixed in PokemonAutomation#1850.)

- NintendoSwitch_Commands_PushButtons.h: the y-axis doc was flipped. The migration
  preserved the old raw-value meaning (old u8 0 = 'up' maps to +1; the send path
  maps +1 back to raw 0, see PABotBase2_WiredController). +1 is up/forward, -1 is
  down, matching the PushJoySticks UI labels.
- Update stale comments still documenting the u8 API / ticks:
  PokemonSV_AutoStoryTools.h (realign_player + forward_ticks lines),
  PokemonSV_WorldNavigation.h (walk_forward_while_clear_front_path),
  NintendoSwitch_PushJoySticks.cpp.
- Update option help text that still said 'ticks' for Milliseconds options:
  PokemonLA_PostMMOSpawnReset, PokemonLA_FroslassFinder,
  PokemonSwSh_DateSpam-BerryFarmer2.

Co-authored-by: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com>
…ation#1856)

use_qt_ui() (added in PokemonAutomation#1843 to replace the USE_QT_UI global) distinguished
the GUI executable from the command-line one. Since the CLI executable now
links only the Qt-free CoreLib, no code that calls use_qt_ui() ever compiles
into a non-GUI executable: the two call sites in SerialPABotBase2_Connection
are inside #ifdef QT_CORE_LIB and only compile into SerialProgramsLib, which
is only ever linked into the GUI app, where use_qt_ui() is always true.

Delete the function and its definitions, take the always-true branches, and
drop the dead manual QSerialPortInfo lookup. The #ifdef QT_CORE_LIB guard
remains: it is what compiles the Qt-free CoreLib without Qt.

Co-authored-by: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com>
…tion#1748)

Convert load_full_audio() to run a QEventLoop directly to decode full audio.
This bypasses any QThread bug.

Previously this function reads the audio in another thread but wait till
the thread finishes. So the new code has no functional change.

Also did some minor edits to the audio file loader code.

Added two tests: an mp3 audio loading test, and a missing audio file handling test.

Co-authored-by: Gin <>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts: CMakeLists.txt keeps both the lab device-access test runner and
upstream's Python bindings block; Main.cpp drops use_qt_ui() as upstream
PokemonAutomation#1856 removed it and all its callers, keeping lab's namespace layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…reads) (#256)

* Lab channel: start the console's inference threads for each command

Game commands that watch the screen with run_until (frlg_route's walker)
crashed the app on a null inference pivot: a program's environment starts
those threads, the lab console did not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Lab channel: popups lists the app's message boxes, popups close presses their default button

A failed program leaves a modal Error box that nothing at the keyboard
closes on a lab console.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Lab channel: popups compiles (QPushButton include)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

* Lab: start waits for the controller; state shows controller=

After a program switch the app reconnects the controller, which can stall.
A start in that window ran the program, which then failed with
"Incompatible Controller ... Actual: (none)". The state file now has
controller=ready|none from the panel's ControllerSession, and start waits up
to SECONDS (default 30) for it, refusing with "controller not connected".
labctl.sh passes a wait shorter than its own request timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
lab-B refused its audio input every 5 s with "Device is not allowlisted",
which didn't say which device. The allowlist was right: the BDSP AutoStory
panel (and a few others) selected console A's capture audio
(...USB Video:1112100:3), and both cards are listed as "USB Digital Audio".
The refusal now names the kind and ID, decoding hex capture IDs.


Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Takes --list from the runner; keeps lab/main's CMake options and the
structured bindings in unit_test_names(); drops the runner's use_qt_ui()
stub, since lab/main has no use_qt_ui().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

game:shared Shared or game-neutral code lab-tooling Lab channel, CFR, scripts, run records, build

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants