Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 50 additions & 135 deletions .agents/skills/verify-gbat/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
---
name: verify-gbat
description: Verify gbat's real macOS/Linux battery CLI and macOS Raycast script with isolated PTY runs, version checks, hardware-aware feature journeys, and retained command evidence. Use after changing CLI output, HID behavior, or Raycast integration.
description: Verify gbat's real macOS/Linux battery CLI and macOS Raycast script with isolated PTY runs and retained evidence. Use after changing CLI output, HID behavior, or Raycast integration.
---

# Verify gbat

Read [the feature map](features/README.md), then the relevant journey. The primary
surface is a one-shot Rust CLI; the secondary surface is the macOS Raycast Script
Command `Logitech Mouse Battery`. No service, port, login, database, migrations,
or seed data is involved. An empty working directory is sufficient for version
checks; successful battery reads require a real awake Logitech mouse.
Choose the journey that covers the change:

## Launch
- [Version identity](features/version.md) covers the checkout and installed executables.
- [Battery and charging](features/battery.md) covers receiver, direct USB, and charging state.
- [Failure and recovery](features/failure-recovery.md) covers absent devices, offline mice, Linux permissions, and recovery.
- [Raycast integration](features/raycast.md) covers binary selection, missing executables, and the native Script Command.

Run from this checkout using Rust/rustup (the version is pinned in
`rust-toolchain.toml`) and `uv`. The helper uses Python 3.12, provisioned by `uv`
if necessary; Python is a verification dependency, not an app dependency.
On Linux the native hidraw backend needs a C compiler/linker, not `libudev-dev`
or `libusb`. Build as your regular user.
## Launch

Keep these variables in one shell across launch, doctor, drive, and cleanup:
Build as the regular user with the pinned Rust toolchain. The [PTY helper](scripts/capture.py)
uses Python 3.12 through `uv`. Keep these variables in one shell:

```sh
REPO="$(git rev-parse --show-toplevel)"
Expand All @@ -30,150 +26,69 @@ HARNESS="$REPO/.agents/skills/verify-gbat/scripts/capture.py"
mkdir -p "$REPO/target/verification-evidence"
EVIDENCE="$(mktemp -d "$REPO/target/verification-evidence/run.XXXXXX")"
SCRATCH="$(mktemp -d "${TMPDIR:-/tmp}/gbat-verify.XXXXXX")"
printf 'Evidence: %s\nScratch: %s\n' "$EVIDENCE" "$SCRATCH"
trap 'rmdir -- "$SCRATCH"' EXIT
```

The build must succeed before driving. A successful doctor below establishes
CLI readiness and the manifest version. It does not establish hardware
readiness. There is no persistent app process: start each action with the helper
in its own PTY, which exits and is reaped before the next action. Teardown is
the Cleanup section; run it after failures too.

Hardware queries cannot be isolated by working directory: interfaces are shared,
requests use one software ID, and input reports are flushed. Never run two
battery queries concurrently against the same receiver, including Raycast
refreshes or another agent's run. If another driver is active, defer the query;
do not kill or commandeer it. Version-only runs can coexist. There is no device
selector: multiple Logitech devices can make the reading belong to another
device. Establish the intended device/connection before claiming GPW2 proof.

## Doctor

This is the read-only instance check. It invokes the exact local binary without
opening HID, requires the version in `Cargo.toml`, and records its SHA-256:
After a successful build, verify the exact executable against the manifest.
Only `--version` as the first CLI argument skips HID initialization.

```sh
uv run --no-project --python 3.12 "$HARNESS" \
--evidence "$EVIDENCE/doctor" --cwd "$SCRATCH" --binary "$BINARY" \
--feature version-local --expect version -- "$BINARY" --version
```

Require helper exit `0`, `result.json` `passed: true`, exact version stdout,
and empty stderr. The helper records a binary hash on every action: compare it
with the doctor hash to detect a build replaced during verification. Version
alone cannot establish freshness, so always build this checkout first. If
anything looks off, repeat this check in a new evidence directory, retaining
the failed attempt. On Linux this command needs no `sudo`.
Require helper exit `0` and `passed: true` in `result.json`. Compare the binary
SHA-256 in subsequent actions with the doctor's hash for the same executable.

## Drive

The executable [PTY helper](scripts/capture.py) accepts exact commands after
`--`; it never runs them through a shell. Every invocation requires a new
evidence subdirectory and an existing, disposable scratch directory. Stdout and
stdin use a private controlling PTY; stderr is redirected to its own proof file
so channel assertions remain possible. It supplies no interactive input. The
default deadline is 30 seconds, not the internal six-second discovery budget;
use `--timeout 60` only for a justified slow host.

For a real battery read on macOS:

```sh
uv run --no-project --python 3.12 "$HARNESS" \
--evidence "$EVIDENCE/battery-terminal" --cwd "$SCRATCH" --binary "$BINARY" \
--feature battery-terminal --expect battery -- "$BINARY"
```

For the corresponding Linux action, use `-- sudo -n "$BINARY"` instead.
Build first as a regular user. If `sudo -n` needs authentication, use the
environment's secret-delivery mechanism; do not put passwords into commands,
artifacts, or this skill. A sudo error is a failed prerequisite, not a gbat
failure-path pass. Do not change udev rules or device permissions for a run.

Follow the map for charging, offline/recovery, and Raycast actions. A missing
mouse or required charging state is a failed journey with its unmet precondition,
not a successful substitute. Only the first CLI argument exactly equal to
`--version` avoids HID. There is no `--help`, dry-run, or device-list mode;
unknown arguments execute a battery query. The Raycast script does not forward
arguments, so `mouse-battery.sh --version` also queries hardware.
Run each relevant journey with a fresh evidence subdirectory per action. The
helper launches the argv after `--` in a private PTY, captures stderr separately,
and enforces a 30-second deadline by default. To inspect all options, run
`uv run --no-project --python 3.12 "$HARNESS" --help`.

For successful battery queries, identify the intended awake GPW2 and connection.
The CLI can select any responding Logitech device. Serialize queries on the same
receiver, including Raycast refreshes. They send HID++ requests using a shared
software ID and flush input reports. On Linux, use `-- sudo -n "$BINARY"` in
battery examples when elevated device access is needed. Handle authentication
outside the capture. Keep device permissions unchanged.

`--expect battery` checks the percentage and allows an optional charging suffix.
Check the suffix against the observed charging state. `--expect error` checks a
family of CLI errors. Inspect stderr for the specific failure in the selected
journey. Record unavailable hardware or permissions as unmet preconditions.
Native Raycast verification requires the visible Script Command invocation and
result. The terminal wrapper ignores arguments, including `--version`.

## Evidence

Keep proof in `$REPO/target/verification-evidence/run.XXXXXX`, outside scratch.
`target/` is already ignored by Git. Copy evidence elsewhere before `cargo clean`
or deleting the checkout. Each action contains:

- `action.json`: feature/entry-point ID, exact argv, working directory, UTC time,
platform, binary path/hash, manifest version, expected behavior, scratch before.
- `terminal.bin` and `events.jsonl`: raw stdout PTY bytes and timed output chunks.
- `stdout.txt` and `stderr.txt`: stdout with terminal CRLF normalized to LF and
separately captured stderr.
- `result.json`: actual app exit code, timeout/interruption/capture error,
assertion result, scratch after,
and whether scratch files stayed unchanged. Helper exit `0` means all its
checks passed; app exit code is recorded separately.

Record connection mode, intended device identity, wake/charging conditions,
manual actions, and feature outcomes in `$EVIDENCE/notes.md`. Capture the action
and resulting state through the real user entry point. For hardware queries,
compare charging suffix with independently observed cable/charging conditions;
do not require an exact historical battery percentage. A command that merely
prints a plausible battery line cannot prove device identity or charging state.

Observe relevant side effects alongside output: the helper compares scratch
file contents; it does not audit the whole filesystem or network. gbat has no
documented state files, network calls, or browser launches, but battery queries
send real HID++ writes before reading replies. Do not call them pure device
reads. `--version` returns before HID initialization. No mock battery provider,
replacement executable, or internal test setter proves real hardware behavior.
Existing protocol tests are useful supplementary checks, not CLI/hardware proof.

For Raycast UI proof, retain the actual invocation and visible compact result
using available native-app capture tooling; terminal execution of its script is
a separate path. Do not reuse the historical README GIF/WebP as fresh evidence.
Do not run `docs/record-demo.sh` for routine verification: it replaces
`assets/demo.gif`.

## Cleanup
Keep evidence under the ignored `target/verification-evidence/` directory.
Use a new directory for retries so earlier outcomes remain available.

The helper waits for its child and closes its PTY. On timeout, SIGINT, or SIGTERM
it kills only the process group it created and reaps the child. Never kill by
process name. No server remains to stop. Close only UI windows opened by the
run and restore any device state changed specifically for a journey.
- `action.json` records argv, working directory, timestamp, platform, binary path
and hash, manifest version, expectation, and the initial scratch snapshot.
- `terminal.bin` and `events.jsonl` hold raw PTY output and timed chunks.
`stdout.txt` normalizes terminal CRLF to LF. `stderr.txt` captures stderr.
- `result.json` records the child exit code, timeout, interruption, capture
errors, assertion, and final scratch snapshot. A pass requires the expected
exit and output, a completed capture, and unchanged scratch entries.
- Record the device identity, connection, wake/charging conditions, manual
actions, and feature outcomes in `$EVIDENCE/notes.md`.

After every attempt, including a failed one, remove only that run's scratch:

```sh
rmdir -- "$SCRATCH"
trap - EXIT
test ! -e "$SCRATCH"
test -s "$EVIDENCE/doctor/action.json"
test -s "$EVIDENCE/doctor/result.json"
test -s "$EVIDENCE/doctor/stdout.txt"
printf 'Retained proof: %s\n' "$EVIDENCE"
```

Also confirm the driven feature's `action.json`, `result.json`, stdout/stderr,
and terminal evidence survive. Never remove `$EVIDENCE` in cleanup. For a failed
build before scratch exists, no instance was launched and there is nothing to
terminate. Scratch should be empty: if `rmdir` fails, inspect it and remove only
the run-created files before retrying; do not recursively delete an uninspected
path. Do not erase failed evidence when retrying. SIGKILL or machine termination
cannot be handled; such runs may retain partial evidence and need inspection.

## Helpers
## Cleanup

All invocations above run `scripts/capture.py` through `uv`; it is also directly
executable. Inspect its options without touching HID with:
The helper reaps its child when it exits. After successes and failures, restore
device state changed for the journey, close windows opened for the run, and
remove the empty scratch directory:

```sh
uv run --no-project --python 3.12 "$HARNESS" --help
rmdir -- "$SCRATCH" && trap - EXIT
```

`--expect version` requires the current manifest version; `battery` requires one
valid `Battery: N%` line with an optional charging suffix; `error` requires app
exit `1`, empty stdout, and a known gbat error prefix; `missing-binary` requires
the Raycast wrapper's exact missing-executable message. Every expectation also
requires no timeout and unchanged scratch file contents. `error` recognizes a
family of failures: read stderr to assert the specific scenario in the map.
The helper cannot certify hardware setup or native Raycast UI behavior.
If scratch contains unexpected entries, inspect them against the captured
snapshot before removal. Retain the action and result files, including failed
runs. Copy evidence elsewhere before cleaning the Cargo target directory.
42 changes: 0 additions & 42 deletions .agents/skills/verify-gbat/features/README.md

This file was deleted.

17 changes: 8 additions & 9 deletions .agents/skills/verify-gbat/features/raycast.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ Preconditions:
Require valid battery stdout, empty stderr and app exit `0`.
- **Automatic discovery entry.** Run
`uv run --no-project --python 3.12 "$HARNESS" --evidence "$EVIDENCE/raycast-discovery" --cwd "$SCRATCH" --binary "$BINARY" --feature raycast-discovery --expect battery -- env -u GBAT_BINARY PATH="$REPO/target/release:$PATH" "$REPO/raycast/mouse-battery.sh"`.
This proves the PATH entry with this checkout's build. Search order after PATH
is `/opt/homebrew/bin/gbat`, `/usr/local/bin/gbat`, `$HOME/.local/bin/gbat`, then
the repository's `target/release/gbat`. When modifying fallback discovery,
exercise each affected location on an appropriately configured host; do not
overwrite installed binaries or claim all fallbacks from the PATH case.
This exercises the PATH entry with this checkout's build. When modifying
fallback discovery, exercise each affected location in the
[documented order](../../../../README.md#raycast) on an appropriately
configured host. Preserve the user's installed binaries.
- **Missing configured executable.** Confirm `test ! -e "$SCRATCH/no-gbat"`.
Run
`uv run --no-project --python 3.12 "$HARNESS" --evidence "$EVIDENCE/raycast-missing" --cwd "$SCRATCH" --binary "$BINARY" --feature raycast-missing --expect missing-binary -- env GBAT_BINARY="$SCRATCH/no-gbat" "$REPO/raycast/mouse-battery.sh"`.
Require app exit `1`, empty stdout and exact stderr
`gbat binary not found. Build it with: cargo build --release` plus a newline.
A bad explicit override must not fall back to an installed binary. This case
requires no hardware and invokes the real script without a fake executable.
Repeat with `GBAT_BINARY="$SCRATCH"` and `raycast-directory` as the evidence
directory and feature. A searchable directory also has its execute bit set.
Both cases should reach the same missing-executable diagnostic even when
a working gbat is on PATH.
- **Native UI entry.** Using available native-app control, open Raycast, search
the exact command `Logitech Mouse Battery`, and execute it. Capture the action
and visible compact battery result in `$EVIDENCE/raycast-ui/`, with connection
Expand All @@ -58,5 +59,3 @@ Preconditions:

- The script ignores its arguments, including `--version`; it queries hardware.
- Invalid `GBAT_BINARY` takes precedence even when a working gbat is on PATH.
- Linux CLI support does not imply Raycast support; Linux cannot prove this map.
- The original Raycast WebP is historical evidence, not proof of the current build.
Loading
Loading