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
84 changes: 84 additions & 0 deletions .github/workflows/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,89 @@ jobs:
exit 1
fi
echo "$count scripts answer --help"
- name: lock.sh holds one run at a time and gives the lock back
run: |
export PLADDER_LOCK_DIR="$RUNNER_TEMP/locks"
mkdir -p "$PLADDER_LOCK_DIR"
L=scripts/lock.sh
LOCK="$PLADDER_LOCK_DIR/pladder-ane.lock"
fail() { echo "::error file=$L::$*"; exit 1; }
taken() {
for _ in $(seq 50); do
if grep -q '^command-pid=' "$LOCK/owner" 2>/dev/null; then return 0; fi
sleep 0.1
done
fail "the lock was never taken"
}

s=0; "$L" ane -- sh -c 'exit 7' || s=$?
[[ $s -eq 7 ]] || fail "a command's exit 7 came back as $s"
[[ ! -e "$LOCK" && "$("$L" --status ane)" == "ane: free" ]] || fail "a failed command left the lock held"

"$L" ane -- sh -c 'echo a >>"$1"; sleep 2; echo b >>"$1"' sh "$RUNNER_TEMP/order" & first=$!
taken
status=$("$L" --status ane)
for part in "held by $PWD" "pid $first" "sh -c echo a"; do
grep -qF "$part" <<<"$status" || fail "--status says \"$status\", without \"$part\""
done
s=0; "$L" --wait 0 ane -- true || s=$?
[[ $s -eq 75 ]] || fail "--wait 0 on a held lock exited $s, not 75"
"$L" ane -- sh -c 'echo c >>"$1"; echo d >>"$1"' sh "$RUNNER_TEMP/order"
wait "$first"
[[ "$(paste -s -d ' ' "$RUNNER_TEMP/order")" == "a b c d" ]] || fail "two runs interleaved: $(paste -s -d ' ' "$RUNNER_TEMP/order")"

sh -c 'exit 0' & dead=$!; wait "$dead"
mkdir "$LOCK"
printf 'pid=%s\nstarted=Mon Jan 1 00:00:00 2000\n' "$dead" >"$LOCK/owner"
grep -q "left by pid $dead (gone)" <<<"$("$L" --status ane)" || fail "--status missed a gone holder"
"$L" --wait 5 ane -- true || fail "a gone holder's lock was not taken over"
[[ ! -e "$LOCK" && ! -e "$LOCK.takeover" ]] || fail "the takeover left a lock behind"

mkdir "$LOCK"
echo "measuring by hand" >"$LOCK/owner"
s=0; "$L" --wait 2 ane -- true || s=$?
[[ $s -eq 75 && -f "$LOCK/owner" ]] || fail "a lock taken by hand was taken over (exit $s)"
grep -q "held by hand: measuring by hand" <<<"$("$L" --status ane)" || fail "--status missed a lock taken by hand"
rm -r "$LOCK"

"$L" ane -- sleep 2 & held=$!
taken
kill -TERM "$held"
s=0; wait "$held" || s=$?
[[ $s -eq 143 && ! -e "$LOCK" ]] || fail "SIGTERM exited $s and left the lock: $(ls "$PLADDER_LOCK_DIR")"

timeout 10 "$L" screen -- "$L" screen -- true || fail "a lock.sh inside the same lock did not just run"
[[ "$("$L" ane -- sh -c 'printf "%s\n" "$1"' sh --help)" == "--help" ]] || fail "--help after -- did not reach the command"

mkdir "$LOCK" "$LOCK.takeover"
printf 'pid=%s\nstarted=Mon Jan 1 00:00:00 2000\n' "$dead" >"$LOCK/owner"
s=0; timeout 10 "$L" --wait 2 ane -- true || s=$?
[[ $s -eq 75 ]] || fail "a fresh takeover left by another run did not end in the wait's timeout (exit $s)"
touch -t 200001010000 "$LOCK.takeover"
"$L" --wait 5 ane -- true || fail "a takeover left over a minute ago was not cleared"
[[ ! -e "$LOCK" && ! -e "$LOCK.takeover" ]] || fail "a stale takeover left a lock behind"
echo "lock.sh: exit codes, --status, order, --wait 0, takeover, by hand, SIGTERM, nesting, a stale takeover"
- name: test-copy.sh picks a chord the copy in use never reacts to
run: |
fail() { echo "::error file=scripts/test-copy.sh::$*"; exit 1; }
home() { # <name> <settings.json or nothing>
h="$RUNNER_TEMP/homes/$1"
mkdir -p "$h/Library/Application Support/Pladder"
if [[ -n "$2" ]]; then printf '%s' "$2" >"$h/Library/Application Support/Pladder/settings.json"; fi
echo "$h"
}
expect() { # <name> <settings.json or nothing> <keyCodes>
out=$(HOME=$(home "$1" "$2") scripts/test-copy.sh --dry-run) || fail "$1: exited non-zero"
grep -qF "\"hotkey\":{\"keyCodes\":[$3]}" <<<"$out" || fail "$1: wanted [$3], got $out"
}
expect none "" "17,55,58,59"
expect defaults '{"hotkey":{"keyCodes":[49,58]},"toggleHotkey":{"keyCodes":[]},"submitKey":{"keyCodes":[9]}}' "17,55,58,59"
expect fn-hold '{"hotkey":{"keyCodes":[63]},"toggleHotkey":{"keyCodes":[49,58]},"submitKey":{"keyCodes":[59]}}' "17,55,58,59"
expect right-command '{"hotkey":{"keyCodes":[54]}}' "17,56,58,59"
expect taken '{"hotkey":{"keyCodes":[17,55,58,59]}}' "5,55,58,59"
for bad in '{"hotkey":' '{"hotkey":{"kind":"modifier","keyCode":54}}' '[]'; do
if HOME=$(home bad "$bad") scripts/test-copy.sh --dry-run >/dev/null 2>&1; then fail "launched on $bad"; fi
done
echo "test-copy.sh: chords for no file, the defaults, fn, Right Command and a taken T; unreadable files refused"
- name: ShellCheck
run: shellcheck scripts/*.sh
22 changes: 16 additions & 6 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Before and after any change that touches the code between `recordingStopped` and
swift build # debug build of everything
swift test # unit tests, well under a second
./scripts/bundle.sh [--run] [--install] [--dev-modes] # release build → dist/Pladder.app, signed
./scripts/test-copy.sh [--stop | --dry-run] # bundle dist/Pladder.app and launch it beside the copy in use, with its own settings file and chord; --stop stops it
./scripts/lock.sh [--wait <s>] <screen|ane> -- <command> # run a command holding the screen, or the Neural Engine and GPU, one worktree at a time; --status names the holder
./scripts/release.sh <version> # Developer ID, notarised, stapled → dist/release/Pladder.dmg; publishes nothing
./scripts/changelog.sh <last tag> [<ref>] # the release notes release.yml publishes, from the commit subjects
./scripts/appcast.sh <app> <dmg> <notes.md> # sign the DMG for Sparkle and print the release's appcast.xml
Expand Down Expand Up @@ -120,11 +122,11 @@ swift run -c release pladder-cli polish-set docs/polish-set.json --model s1-mini

The developer dictates with a running Pladder all day, often into Claude sessions, and several worktrees may each have their own `dist/Pladder.app`.

- Never `pkill -x Pladder` or `killall Pladder`: that also kills the copy in use, mid-recording, and the text is lost. Stop only the copy you launched: `pkill -f "$PWD/dist/Pladder.app"`. SIGTERM quits the normal way, so a copy stopped like this gives back the speakers and the clipboard first. `bundle.sh --install` stops only `/Applications/Pladder.app`, and CI fails on a script that kills every copy.
- Never `pkill -x Pladder` or `killall Pladder`: that also kills the copy in use, mid-recording, and the text is lost. Stop only the copy you launched: `scripts/test-copy.sh --stop` for a test copy, `pkill -f "$PWD/dist/Pladder.app"` for one you started some other way. SIGTERM quits the normal way, so a copy stopped like this gives back the speakers and the clipboard first. `bundle.sh --install` stops only `/Applications/Pladder.app`, and CI fails on a script that kills every copy.
- Do not post synthetic hotkey events unless the user has asked for a live UI test. Every running copy reacts to them, so they start, cut short, or paste the user's recordings.
- To see an overlay change, run `scripts/overlay-demo.sh` and read its contact sheets. It drives the real coordinator and pill with stand-ins for the engine, microphone, paste and hotkey, so nothing reaches a running copy.
- Do not edit `~/Library/Application Support/Pladder/settings.json`; it is the live configuration.
- A copy launched for testing gets its own settings file with `PLADDER_SETTINGS_PATH=/tmp/<branch>/settings.json "$PWD/dist/Pladder.app/Contents/MacOS/Pladder"`, and a different chord from the copy in use, so the two never fire together. Launched as the bare binary so the environment reaches it; its command line still contains `$PWD/dist/Pladder.app`, so the `pkill -f` above stops it.
- A copy for testing comes from `scripts/test-copy.sh`: it bundles `dist/Pladder.app`, launches the bare binary with a settings file of its own, `/tmp/<branch>/settings.json`, and a chord the copy in use never reacts to, chosen from the live settings file, which it only reads, and prints the PID. Stop it with `scripts/test-copy.sh --stop` as soon as you are done with it; that stops this worktree's test copy and nothing else.
- To test an update, the copy needs a bundle ID of its own (Sparkle's defaults and the grants are per bundle ID), `LSEnvironment` in its Info.plist for `PLADDER_SETTINGS_PATH` (Sparkle relaunches it through LaunchServices, without your shell's environment), a feed on `http://127.0.0.1` and a throwaway key, signed with `appcast.sh` and `SPARKLE_ED_KEY`; never the real key.

## Verify
Expand All @@ -136,19 +138,27 @@ Proof is what you saw in this session: a command's output, a picture, a contact
| Any Swift | `swift build`, with no new warning, and `swift test` | the terminal |
| Core logic: the coordinator, a tracker, the settings | a test that fails without the change | the terminal |
| A processor, the dictionary | `swift run -c release pladder-cli <audio file> --process --verbose` | `RAW:` and `TEXT:` on stdout |
| Between `recordingStopped` and `inserted`, a processor, the engine | the critical-path rule: `pladder-cli bench`, `pladder-cli bench --paced`, `pladder-cli bench-coordinator`, `pladder-cli bench-release` or `pladder-cli bench-process`, before and after | tables on stdout, both in the pull request |
| Polish, a model or its prompt | `pladder-cli polish-set docs/polish-set.json --model …` | error rate, exact matches and timings on stdout |
| Between `recordingStopped` and `inserted`, a processor, the engine | the critical-path rule, under `scripts/lock.sh ane --`: `pladder-cli bench`, `pladder-cli bench --paced`, `pladder-cli bench-coordinator`, `pladder-cli bench-release` or `pladder-cli bench-process`, before and after | tables on stdout, both in the pull request |
| Polish, a model or its prompt | `scripts/lock.sh ane -- swift run -c release pladder-cli polish-set docs/polish-set.json --model …` | error rate, exact matches and timings on stdout |
| The pill, the coordinator's states | `scripts/overlay-demo.sh <dir>`, then with `--style minimal`, `--style liveTranscript` and `--reduce-motion` | `<dir>/sheet-*.png`, `demo.mov`, `demo.log` |
| Settings | `scripts/make-screenshots.sh <dir> --settings-scene`, then `--settings-scene --get-started`, `--settings-scene --accessibility`, and any of them with `--managed`; `--settings` for each tab alone | `<dir>/scene-<tab>-light.png` and `-dark.png`, `accessibility-<tab>.txt`, `settings-<tab>-light.png` and `-dark.png` |
| The menu | `scripts/make-screenshots.sh <dir> --menu` | `<dir>/menu.png`, in the system's appearance |
| The README's pictures | `scripts/make-screenshots.sh` with no `<dir>` | `docs/images/styles-light.png` and `-dark.png`, committed |
| The bundle, signing, the icon, the catalogs in the app | `scripts/bundle.sh`, then your own copy with its own settings file | `dist/Pladder.app` |
| The bundle, signing, the icon, the catalogs in the app | `scripts/test-copy.sh`, then `scripts/test-copy.sh --stop` | `dist/Pladder.app`, the copy's PID on stdout, its log in `/tmp/<branch>/test-copy.log` |
| A script | `shellcheck scripts/*.sh`, and its `--help` | the terminal |
| Docs, the site | `scripts/check-doc-pointers.sh`, `scripts/check-doc-commands.sh`, `scripts/check-site-numbers.sh`; `site/index.html` at phone and desktop widths | the terminal |

`<dir>` is yours, `/tmp/<branch>/…`, one per run, and comes first: each run of the same mode replaces the last one's pictures. Without it `make-screenshots.sh` writes into `docs/images`, which is committed, and `overlay-demo.sh` into one directory every worktree shares. `scripts/overlay-demo.sh` and `scripts/make-screenshots.sh` build their own copy with the developer modes in (`-DPLADDER_DEV_MODES`, in `.build/dev-modes`); a plain `swift build` or `scripts/bundle.sh` build, and every release, has no `--overlay-demo` or `--screenshots`. Both put windows or the pill on the screen while they run and need Screen Recording for the terminal that runs them, so look at the pictures before quoting them. `pladder-cli --process` reads the live settings file and never writes it; `PLADDER_SETTINGS_PATH` names another. The fixtures come from `scripts/make-fixtures.sh`, once per worktree, into `bench/fixtures`.

One at a time. Anything that records the screen (`scripts/overlay-demo.sh`, `scripts/make-screenshots.sh`) runs under `/tmp/pladder-screen.lock`: take it with `mkdir /tmp/pladder-screen.lock`, write an owner file inside (the worktree and the time), `rm -r` it when the run ends, and never remove a lock someone else took; wait instead. A benchmark has no lock, but one that ran beside another build or benchmark is not a result; `pladder-cli bench`, `pladder-cli bench-coordinator` and `pladder-cli bench-release` print the load average, and docs/BENCHMARKS.md, "Procedure", says what counts.
One at a time. Every worktree shares the screen and the Neural Engine and GPU, and `scripts/lock.sh` gives each to one run at a time: `screen` to anything that records the screen, `ane` to anything that measures. `scripts/overlay-demo.sh` and `scripts/make-screenshots.sh` take `screen` themselves, once their build is done; a benchmark or a polish timing runs under `ane`, after `swift build -c release --product pladder-cli`, so the build stays outside the lock:

```sh
scripts/overlay-demo.sh /tmp/<branch>/demo
scripts/lock.sh ane -- swift run -c release pladder-cli bench-coordinator
scripts/lock.sh --status
```

A run that finds the lock held says who holds it and waits up to an hour (`--wait` changes that), so start it in the background. The lock goes back when the command ends, however it ends, and the next run takes over one whose holder is gone. Never remove `/tmp/pladder-*.lock` while its holder is alive; `--status` says whether it is. The lock keeps benchmarks apart, not builds: one that ran beside another build is still not a result; `pladder-cli bench`, `pladder-cli bench-coordinator` and `pladder-cli bench-release` print the load average, and docs/BENCHMARKS.md, "Procedure", says what counts.

The hard states: light and dark; every pill style and Reduce Motion; every path the demo plays, the clipboard hint and the two polish paths among them; the General tab at its tallest; every managed control; what VoiceOver is given; a recording longer than one 15 s window, which `bench --paced` checks byte for byte.

Expand Down
25 changes: 16 additions & 9 deletions docs/BENCHMARKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ benchmark reports the actual length.
1. Close other heavy work and check that `uptime` shows a low load average.
Numbers jitter with thermal state and other load.
2. Generate the fixtures once: `./scripts/make-fixtures.sh`
3. Run: `swift run -c release pladder-cli bench bench/fixtures`. It takes
about seven minutes; leave the machine alone while it runs.
3. Build first, then run under the `ane` lock, which every worktree on the
Mac shares, so no other benchmark or polish timing runs beside it:
`swift build -c release --product pladder-cli`, then
`scripts/lock.sh ane -- swift run -c release pladder-cli bench bench/fixtures`.
It takes about seven minutes; leave the machine alone while it runs. A
run that finds the lock held waits for it, up to an hour. Every command
below runs the same way.
4. Runs never overlap, and every run is preceded by ten seconds of idle so
it starts from the same state a real dictation does, rather than with
warm clocks and residual heat from the previous run. `--pause` changes
Expand All @@ -78,7 +83,9 @@ benchmark reports the actual length.
keeps ten and takes about twelve minutes.
6. The tool prints the one-minute load average at start and end and tags
any run during which the chip left its normal thermal state. A run with
a thermal tag or a load average well above one is not comparable.
a thermal tag or a load average well above one is not comparable. The
lock keeps benchmarks apart, not builds, so a build in another worktree
still shows here, and the load average still decides.
7. A difference under roughly ten percent is noise. If a change lands near
that line, run again.

Expand All @@ -94,7 +101,7 @@ timed. That is the part left
on the release-to-paste path.

```sh
swift run -c release pladder-cli bench bench/fixtures --paced --runs 2 --pause 2
scripts/lock.sh ane -- swift run -c release pladder-cli bench bench/fixtures --paced --runs 2 --pause 2
```

Pacing takes as long as the audio, so fixtures under 13 s are skipped: below
Expand All @@ -117,7 +124,7 @@ every two seconds. `--paced --live` models exactly that: a second task calls
cancelled just before the release, as the coordinator's feed loop is.

```sh
swift run -c release pladder-cli bench bench/fixtures --paced --live --runs 2 --pause 2
scripts/lock.sh ane -- swift run -c release pladder-cli bench bench/fixtures --paced --live --runs 2 --pause 2
```

Two things come out of it. The run line and two extra table columns report how
Expand All @@ -137,7 +144,7 @@ release-to-paste path (the feed hand-over, `endRecording`, the hops between
stages on the main actor), has a number of its own here:

```sh
swift run -c release pladder-cli bench-coordinator [--runs N] [--hold S] [--engine-latency MS] [--paste-latency MS] [--polish] [--live]
scripts/lock.sh ane -- swift run -c release pladder-cli bench-coordinator [--runs N] [--hold S] [--engine-latency MS] [--paste-latency MS] [--polish] [--live]
```

It builds the real `DictationCoordinator` with the app's processors on a
Expand Down Expand Up @@ -183,7 +190,7 @@ never shows that, because its releases always come straight after a feed.
`bench-release` releases where you ask:

```sh
swift run -c release pladder-cli bench-release bench/fixtures/30s.wav --at 15.1,15.3,28.3,28.4 --uniform 2-30:20
scripts/lock.sh ane -- swift run -c release pladder-cli bench-release bench/fixtures/30s.wav --at 15.1,15.3,28.3,28.4 --uniform 2-30:20
```

It builds the real coordinator and processors around the real engine, plays
Expand Down Expand Up @@ -462,7 +469,7 @@ inputs are hand-written in the shape Parakeet produces, with fillers left
in; real dictation mostly arrives with numbers already as digits.

```sh
swift run -c release pladder-cli polish-set docs/polish-set.json --model apple|s1-mini|s1-mini-8bit
scripts/lock.sh ane -- swift run -c release pladder-cli polish-set docs/polish-set.json --model apple|s1-mini|s1-mini-8bit
```

runs the app's processors over each input, then the model, warm, and prints
Expand Down Expand Up @@ -521,7 +528,7 @@ median of 31 runs, M1. "Typical" has a filler in every sentence; "worst" adds
a spoken question mark to every sentence.

```sh
swift run -c release pladder-cli bench-process bench/fixtures [--runs N]
scripts/lock.sh ane -- swift run -c release pladder-cli bench-process bench/fixtures [--runs N]
```

reads each fixture's script, puts "um," after the first word of every
Expand Down
Loading