From bac898d96b2858bcb655f3f6aabaac546064a6b7 Mon Sep 17 00:00:00 2001 From: Fabian Meyer <44942030+dinooo13@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:02:05 +0100 Subject: [PATCH 1/3] Scripts: every script answers --help, checked on Ubuntu overlay-demo.sh, make-screenshots.sh, make-fixtures.sh and make-site-media.sh took --help for a normal run and built, recorded or synthesised, and the release scripts exited non-zero on it, so an agent could not safely ask a script what it does. Each one now prints its header comment and exits 0 when any argument is -h or --help, before it changes directory, reads an argument or builds. cask.sh and the two checks get the Usage line they lacked. scripts.yml runs --help, -h and "x --help" for every scripts/*.sh with a 5 s timeout, requires a "Usage: scripts/.sh" line and a clean tree afterwards, and fails on an executable in scripts/ that is not a .sh, which the loop would miss. On Linux a script that builds or records before its check fails for want of swift, say or screencapture. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/scripts.yml | 38 +++++++++++++++++++++++++++++++++++ scripts/appcast.sh | 3 +++ scripts/bundle.sh | 3 +++ scripts/cask.sh | 6 +++++- scripts/changelog.sh | 3 +++ scripts/check-doc-pointers.sh | 5 +++++ scripts/check-site-numbers.sh | 5 +++++ scripts/make-fixtures.sh | 3 +++ scripts/make-screenshots.sh | 6 +++++- scripts/make-site-media.sh | 3 +++ scripts/overlay-demo.sh | 3 +++ scripts/release.sh | 3 +++ 12 files changed, 79 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts.yml b/.github/workflows/scripts.yml index 5a9ab1a..c3136fc 100644 --- a/.github/workflows/scripts.yml +++ b/.github/workflows/scripts.yml @@ -21,5 +21,43 @@ jobs: run: | # Commands only: a comment may name what not to do. if grep -rnE '^[^#]*(pkill -x Pladder|killall Pladder)' scripts; then exit 1; fi + - name: Every script answers --help and does nothing else + # One that builds, launches or records before reading --help fails + # here: on the 5 s timeout, on a missing say or screencapture, or on + # the files it leaves behind. + run: | + for file in scripts/*; do + if [[ -x "$file" && "$file" != *.sh ]]; then + echo "::error file=$file::$file is executable but not a .sh, so no --help check covers it" + exit 1 + fi + done + count=0 + for script in scripts/*.sh; do + count=$((count + 1)) + if [[ ! -x "$script" ]]; then + echo "::error file=$script::$script is not executable" + exit 1 + fi + for args in "--help" "-h" "x --help"; do + read -r -a argv <<<"$args" + if ! out=$(timeout 5 "$script" "${argv[@]}" 2>&1); then + echo "::error file=$script::$script $args did not exit 0" + echo "$out" + exit 1 + fi + if ! grep -q "^Usage: $script" <<<"$out"; then + echo "::error file=$script::$script $args printed no \"Usage: $script\" line" + echo "$out" + exit 1 + fi + done + done + if [[ -n "$(git status --porcelain --ignored)" ]]; then + echo "::error::a --help run left files behind" + git status --porcelain --ignored + exit 1 + fi + echo "$count scripts answer --help" - name: ShellCheck run: shellcheck scripts/*.sh diff --git a/scripts/appcast.sh b/scripts/appcast.sh index a8c4895..bd0f72b 100755 --- a/scripts/appcast.sh +++ b/scripts/appcast.sh @@ -15,6 +15,9 @@ # DMG_URL default: the DMG of the tag v; a local test # feed points it elsewhere set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" diff --git a/scripts/bundle.sh b/scripts/bundle.sh index 4e1d43d..c59b444 100755 --- a/scripts/bundle.sh +++ b/scripts/bundle.sh @@ -18,6 +18,9 @@ # BUILD_NUMBER CFBundleVersion of the bundled Info.plist; default: the # commit count set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" diff --git a/scripts/cask.sh b/scripts/cask.sh index 04566f0..c431f72 100755 --- a/scripts/cask.sh +++ b/scripts/cask.sh @@ -4,9 +4,13 @@ # Pladder.dmg. Without a SHA-256 it reads the release's Pladder.dmg.sha256. # See INSTALL.md, "Homebrew". # -# ./scripts/cask.sh 0.1.2 > ../homebrew-tap/Casks/pladder.rb +# Usage: scripts/cask.sh [] +# scripts/cask.sh 0.1.2 > ../homebrew-tap/Casks/pladder.rb set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done cd "$(dirname "$0")/.." version=${1:?usage: cask.sh []} diff --git a/scripts/changelog.sh b/scripts/changelog.sh index 9704c49..061ffe7 100755 --- a/scripts/changelog.sh +++ b/scripts/changelog.sh @@ -11,6 +11,9 @@ # # Plain bash 3.2 and POSIX awk, so it runs the same on macOS and ubuntu. set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" diff --git a/scripts/check-doc-pointers.sh b/scripts/check-doc-pointers.sh index 60e9763..52e15c7 100755 --- a/scripts/check-doc-pointers.sh +++ b/scripts/check-doc-pointers.sh @@ -5,9 +5,14 @@ # outside code fences, with backticks removed. A bare `docs/X.md` is fine as # long as the file exists. # +# Usage: scripts/check-doc-pointers.sh +# # Plain bash 3.2 and POSIX awk, so it runs the same on macOS and ubuntu. set -eo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done cd "$(dirname "$0")/.." headings=$(mktemp) diff --git a/scripts/check-site-numbers.sh b/scripts/check-site-numbers.sh index 47abc81..37070b4 100755 --- a/scripts/check-site-numbers.sh +++ b/scripts/check-site-numbers.sh @@ -10,9 +10,14 @@ # It also fails when a page names a release, a version or a SHA-256: the # download is always the latest release, so a pinned one would go stale. # +# Usage: scripts/check-site-numbers.sh +# # Plain bash 3.2 and POSIX awk, so it runs the same on macOS and ubuntu. set -eo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done cd "$(dirname "$0")/.." sections=$(mktemp) diff --git a/scripts/make-fixtures.sh b/scripts/make-fixtures.sh index 29e630b..e060d43 100755 --- a/scripts/make-fixtures.sh +++ b/scripts/make-fixtures.sh @@ -15,6 +15,9 @@ # sentence order, wrapping around for the long fixtures, until the estimated # duration reaches the target, so each file is a whole number of sentences. set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" OUT="${1:-$ROOT/bench/fixtures}" diff --git a/scripts/make-screenshots.sh b/scripts/make-screenshots.sh index 6d978ab..5737292 100755 --- a/scripts/make-screenshots.sh +++ b/scripts/make-screenshots.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # Renders the pictures the README shows into docs/images with the app's own # views: the real overlay pill on a stand-in desktop, light and dark. The -# social preview is drawn by scripts/make-icon.swift. Needs Screen Recording for the terminal that runs it. +# social preview is drawn by scripts/make-icon.swift. Needs Screen Recording +# for the terminal that runs it. # The app it launches never starts the hotkey, the microphone or the engine, # so it is safe to run while another Pladder is in use; it shows a few # windows for a second or two. @@ -14,6 +15,9 @@ # --menu the real menu of a status item of its own, opened in-process; the copy then exits # --managed any of the above under a sample managed policy: every managed control disabled set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" diff --git a/scripts/make-site-media.sh b/scripts/make-site-media.sh index e129687..c4283a0 100755 --- a/scripts/make-site-media.sh +++ b/scripts/make-site-media.sh @@ -6,6 +6,9 @@ # # Usage: scripts/make-site-media.sh [poster second, default 6] set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" IN="${1:?usage: scripts/make-site-media.sh [poster second]}" diff --git a/scripts/overlay-demo.sh b/scripts/overlay-demo.sh index f767fae..2b6bae4 100755 --- a/scripts/overlay-demo.sh +++ b/scripts/overlay-demo.sh @@ -15,6 +15,9 @@ # [--reduce-motion] # (default dir: /tmp/pladder-overlay-demo) set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" diff --git a/scripts/release.sh b/scripts/release.sh index 4a60911..48e26d5 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -14,6 +14,9 @@ # either `xcrun notarytool store-credentials pladder-notary` or the API key. # Nothing secret is read from the repo. set -euo pipefail +for arg in "$@"; do + case "$arg" in -h | --help) sed -n '2,${/^#/!q;s/^# \{0,1\}//;p;}' "$0"; exit 0 ;; esac +done ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT" From d040c0de6d6d43eebcb41f045d4b2ce73f7fc7c4 Mon Sep 17 00:00:00 2001 From: Fabian Meyer <44942030+dinooo13@users.noreply.github.com> Date: Wed, 25 Nov 2026 20:02:05 +0100 Subject: [PATCH 2/3] pladder-cli: --help prints the usage and exits 0 It printed the usage to stderr and exited 2, as for a mistake, so a script or an agent asking for it saw a failure. -h or --help anywhere now prints it to stdout and exits 0; no arguments and bad arguments still print it to stderr and exit 2. Co-Authored-By: Claude Opus 5.5 --- Sources/PladderCLI/main.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sources/PladderCLI/main.swift b/Sources/PladderCLI/main.swift index 2a1ba98..db29fd5 100644 --- a/Sources/PladderCLI/main.swift +++ b/Sources/PladderCLI/main.swift @@ -5,8 +5,8 @@ import PladderEngines // Developer tool. Commands and flags: docs/ARCHITECTURE.md, "pladder-cli". Each // command lives in a file of its own; shared helpers are in Support.swift. -func usage() -> Never { - eprint(""" +func usageText() -> String { + """ usage: pladder-cli