Skip to content

Scripts: a test copy of your own, and turns on the screen and the Neural Engine - #130

Merged
dinooo13 merged 2 commits into
mainfrom
t3/125-test-copy-locks
Nov 25, 2026
Merged

dinooo13 merged 2 commits into
mainfrom
t3/125-test-copy-locks

Conversation

@dinooo13

@dinooo13 dinooo13 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #125

Why

CLAUDE.md said how to launch a test copy, but agents had to type it by hand each time: PLADDER_SETTINGS_PATH, a chord of their own, the bare binary, and a pkill -f by path to stop it. "A different chord" was also not enough. The copy in use on this Mac holds fn alone, toggles on Option+Space and sends on Left Control. And a chord that Carbon cannot register falls back to Option+Space, which is the live toggle.

Worktrees also share the screen and the Neural Engine and GPU. Two overlay demos at once record each other's pill, and a benchmark run next to another agent's measures that agent's load. Until now the only guard was a hand-written mkdir rule for the screen.

Change

  • scripts/lock.sh [--wait <s>] <screen|ane> -- <command>, new. It keeps the same mkdir locks the hand-written rule used, /tmp/pladder-<resource>.lock:
    • Owner file: records the worktree, the branch, the time, the PID and the process start time, plus the command's own PID once it starts.
    • Waiting: a run waits up to an hour by default, then exits 75.
    • Exit and release: the command's exit code passes through. The lock is released on any exit: EXIT, INT, TERM and HUP.
    • Dead holders: a lock whose holder and command are both gone is taken over. A lock without a PID, taken by hand, never is.
    • --status: prints ane: held by <worktree> (<branch>), pid N, since …: <command>.
    • Nesting: a lock.sh running inside the same lock just runs its command.
    • Tests: PLADDER_LOCK_DIR points the script at a scratch directory, so tests never touch the real locks.
  • scripts/test-copy.sh [--stop | --dry-run], new.
    • Start: bundles dist/Pladder.app and writes a fresh /tmp/<branch>/settings.json. Without a settings file the app would open Settings and take focus from the paste in progress. Then it launches the bare binary and prints its PID.

    • The chord: it reads the hold, toggle and send chords from the live settings file, with jq and read only, and adds the defaults. It then takes the first chord from ⌃⌥⌘T, ⌃⌥⇧T, ⌃⇧⌘T, ⌥⇧⌘T and ⌃⇧T, then the same five with G, that passes two rules:

      • its key is in none of those chords;
      • it does not contain every modifier of a live modifier-only chord, with left and right sides counted as one.

      The chord has one regular key and no fn, so Carbon can register it, and the test copy never falls back to Option+Space. An unreadable live file launches nothing.

    • --stop: sends SIGTERM only to the process whose command line is exactly this worktree's dist binary.

    • Other worktrees: a running test copy from another worktree gets a warning, not a refusal.

  • scripts/overlay-demo.sh and scripts/make-screenshots.sh: once their build is done, they run themselves again under the screen lock, so the lock covers only the recording. make-screenshots.sh repeats bundle.sh --dev-modes inside the lock, because a test-copy.sh that ran during the wait would have put a plain bundle in the same dist.
  • .github/workflows/scripts.yml: two steps in the required scripts job.
    • The lock:
      • exit codes, --status, the order of two runs, --wait 0;
      • taking over a dead holder, and never one taken by hand;
      • a left-behind takeover directory, fresh and stale;
      • SIGTERM, nesting, and --help passed through to the command.
    • The chord: fixture homes for no file, the defaults, this Mac's shape, Right Command and a taken T. Corrupt files are refused.
  • CLAUDE.md:
    • ## Commands: a line each for the two scripts.
    • "Working on this Mac…": uses test-copy.sh and its --stop.
    • ## Verify: the bundle row runs test-copy.sh. Benchmarks and polish timings run under scripts/lock.sh ane --. "One at a time" is rewritten around the script, with a three-line example. The rule now reads "never remove a lock while its holder is alive".
    • ## Ship is untouched.
  • docs/BENCHMARKS.md:
    • "Procedure": build first, then run under the ane lock. The lock keeps benchmarks apart, not builds, so the load average still decides.
    • Every benchmark command in the file runs under the lock.

These questions were settled with the planner's recommendation:

  • Reading the live settings file, read only, is allowed.
  • The lock checks are inline in scripts.yml, not a new check-*.sh.
  • The lock rule is reworded to "while its holder is alive".
  • Another worktree's test copy gets a warning.
  • The chord is ⌃⌥⌘T.

No path the build reads changed (Sources, Package.*, Assets, scripts/bundle.sh, the entitlements).

Verified

On this Mac, beside the copy in use (/Applications/Pladder.app, pid 1430):

  • The two copies never share a chord: scripts/test-copy.sh --dry-run against the live file picked ⌃⌥⌘T, {"hotkey":{"keyCodes":[17,55,58,59]},"toggleHotkey":{"keyCodes":[]}}. The live copy holds fn alone, toggles on Option+Space and sends on Left Control.

  • --stop leaves /Applications running: a real scripts/test-copy.sh printed pid 10919. The copy ran with PLADDER_SETTINGS_PATH=/tmp/t3/125-test-copy-locks/settings.json. --stop printed "stopped test copy 10919", and pid 1430 was still running before and after.

  • Two overlay demos started at once ran one after the other: the second printed lock.sh: waiting for screen: held by … pid 12011 … overlay-demo.sh /tmp/…/demo-a. The demo.log ranges are …452 to …482 and …502 to …532, so they do not overlap. Each sheet-plain.png shows one pill.

  • --status ane names the holder, and a failed command frees the lock: during scripts/lock.sh ane -- sleep 4 it printed ane: held by …/t3-125-test-copy-locks-… (t3/125-test-copy-locks), pid 14868, since 21:29:22 (0 min): sleep 4. scripts/lock.sh ane -- false exited 1, and the lock was free afterwards.

  • A fresh agent ran ## Verify unaided: given only ## Verify and the section it refers to, a new agent produced the overlay contact sheets and a bench-coordinator table under the ane lock, without help:

    • 159 ms median total;
    • 0.10 ms coordinator share;
    • load 2.39 at the start.

    --status named it as the holder of each lock in turn. Its notes on the section were minor: a branch with a slash makes a nested /tmp directory, and the demo always writes six sheets.

  • The new CI steps: both pass under macOS /bin/bash 3.2 and on Ubuntu 26.04 (code-box, the runner's coreutils).

  • The other checks:

    • shellcheck scripts/*.sh is clean;
    • every script answers --help, -h and x --help;
    • check-doc-pointers.sh, check-doc-commands.sh and check-site-numbers.sh pass.

Not checked:

  • The other direction of the first criterion, pressing ⌃⌥⌘T while both copies run, needs a human, since no agent posts hotkey events.
  • Whether a test copy launched from an agent's shell gets Accessibility or comes up in Clipboard mode. The chord rule holds in both modes.

Follow-ups, not in this PR:

  • A test copy shares Sparkle's defaults domain with the copy in use, and can turn off the live copy's scheduled check until that copy relaunches.
  • lock.sh holds TERM until its command ends.
  • A narrow signal window between mkdir and the ownership mark.
  • test-copy.sh refuses the v1 hotkey format.

Benchmark

Only scripts, CI and docs changed, so no benchmark.

Review loop

Reviewer Round 1 Round 2 Round 3
Claude Opus 5.5 (xhigh) CHANGES CHANGES APPROVE
Kimi K3.1 Pro (max) CHANGES nits only (declined) —

Fixed:

  • a takeover directory left behind made later runs spin with no sleep or deadline;
  • the --help passthrough check failed on Ubuntu, under both GNU and uutils coreutils;
  • make-screenshots.sh could launch a plain bundle that test-copy.sh built while it waited;
  • a lock with no owner file, left when a run was killed early;
  • the demo cleared its output before it took the lock;
  • TAKING was cleared after the rmdir, not before.

Declined, listed under Follow-ups:

  • forwarding TERM to the command;
  • the v1 hotkey format;
  • the last one-step signal window.

🤖 Generated with Claude Code

dinooo13 and others added 2 commits November 25, 2026 21:51
… together

Two overlay demos at once captured each other's pill, and a benchmark
beside another agent's measured its load. The screen lock was a recipe
typed by hand from CLAUDE.md, and benchmarks had none. lock.sh runs a
command holding `screen` or `ane`, waits for the holder, gives the lock
back however the command ends, and takes over a lock whose holder is
gone, by PID and start time, never one taken by hand. overlay-demo.sh
and make-screenshots.sh take `screen` themselves after their build;
CLAUDE.md's Verify and docs/BENCHMARKS.md run benchmarks and polish
timings under `ane`. scripts.yml checks the lock's semantics on Ubuntu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r reacts to

A test copy was typed by hand from CLAUDE.md each time, and the chord it
named only avoided the default Option+Space, while the copy in use holds
fn and toggles on Option+Space. test-copy.sh reads the live settings
file without writing it, picks the first of ⌃⌥⌘T and its neighbours
whose key no live chord uses and that holds no live modifier-only chord,
bundles dist/Pladder.app, writes /tmp/<branch>/settings.json before the
launch so Settings never opens and takes the paste, and prints the PID.
--stop sends SIGTERM only to the process whose command line is this
worktree's binary. scripts.yml checks the chord against fixture homes.

Closes #125.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dinooo13
dinooo13 merged commit c3b48f7 into main Nov 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A test copy of your own, and turns on the Neural Engine, GPU and screen

1 participant