Repository navigation
fix(argv): -h/--help intercept on all remaining cmd_X (class-wide sweep) - #237
Conversation
Verb-fuzz from vhsm-d1f4 + continuum-b741 + ideem-local-4bef on 2026-04-28 caught the same anti-pattern as #231/#236 in additional verbs: DESTRUCTIVE on --help (mutated state): airc away --help → set status to "--help" airc reminder --help → wrote "--help" as the reminder interval airc channel --help → set channel preference to "--help" (would brick next 'airc update'!) NON-DESTRUCTIVE but no help text: airc status --help, airc connect --help, airc teardown --help, airc daemon --help, airc doctor --help, airc update --help ## Fix Class-wide sweep: every cmd_X (and key helpers) now intercepts -h/--help BEFORE state mutation and prints a real usage block. Also added defense-in-depth in cmd_channel and cmd_reminder: - cmd_channel: refuses any flag-shaped value (case "$target" in -*) - cmd_reminder: refuses non-numeric arg (catches --foo, --bar etc) These guard against the same class of bug for flags we don't enumerate. ## Coverage After this PR: every cmd_X in lib/airc_bash/ has a -h/--help intercept. Audit: `for f in lib/airc_bash/cmd_*.sh; do grep -qE -- "-h\\|--help" "$f" || echo "MISSING: $f"; done` returns nothing. ## Verification bash -n on all 8 changed files: clean Manual: airc {reminder,channel,away,connect,doctor,daemon,update,status, teardown} --help all print usage; none mutate. test/integration.sh tabs: 19/0 ✓ test/integration.sh room: 14/0 ✓ test/integration.sh general_sidecar_default: 10/0 ✓ test/integration.sh away: 5/0 ✓ ## Bug pattern + future hardening The recurring shape: bash function takes positional arg, doesn't validate it, writes it to a state file as the new value. Anyone running `cmd --help` expecting usage gets state mutation instead. Three fixes share design: 1. -h/--help intercept BEFORE any state-touching code 2. Reject flag-shaped tokens (-*) when the value should be a name/number 3. Default action prints help, not "save whatever was passed" Worth porting (1) + (2) to airc.ps1 too — same shape, untested. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR hardens the bash CLI command surface against destructive or silent -h/--help handling by adding consistent help-flag intercepts across remaining cmd_* modules and by rejecting “flag-shaped” values in a couple of state-writing commands.
Changes:
- Add
-h/--helpinterception blocks to multiplecmd_*handlers to prevent help tokens from being treated as real arguments. - Prevent invalid/flag-shaped values from being persisted by
airc channelandairc reminder. - Add/standardize usage output for affected commands.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| lib/airc_bash/cmd_update.sh | Adds airc update help output; hardens airc channel against --help being persisted and rejects flag-shaped channel names. |
| lib/airc_bash/cmd_teardown.sh | Adds -h/--help usage intercept to avoid running teardown when help is requested. |
| lib/airc_bash/cmd_status.sh | Adds -h/--help usage intercept for status. |
| lib/airc_bash/cmd_reminder.sh | Adds -h/--help usage intercept and validates reminder interval input before persisting. |
| lib/airc_bash/cmd_identity.sh | Adds -h/--help intercept to cmd_away to prevent --help being written as status text. |
| lib/airc_bash/cmd_doctor.sh | Adds -h/--help usage intercept for doctor. |
| lib/airc_bash/cmd_daemon.sh | Adds `-h/--help |
| lib/airc_bash/cmd_connect.sh | Adds -h/--help usage intercept to connect argument parsing. |
Comments suppressed due to low confidence (1)
lib/airc_bash/cmd_update.sh:52
cmd_update --channel <name>currently accepts flag-shaped values (e.g.airc update --channel --help). That value flows intogit fetch origin "$channel"/git checkout "$channel"where--helpwill be interpreted as an option (potentially hanging in a pager) and, if the update completes, will be persisted to.channel, recreating the same “bricked update” class of bug. Consider rejecting anyrequested_channelthat starts with '-' (or using--when passing the ref to git, plus validation) before running git/install.sh and before persisting to.channel.
--channel|-c)
requested_channel="${2:-}"
[ -z "$requested_channel" ] && die "Usage: airc update --channel <name>"
shift 2
;;
--canary) requested_channel="canary"; shift ;;
--main) requested_channel="main"; shift ;;
*) shift ;;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| echo "$arg" > "$reminder_file" | ||
| echo " Reminder every ${arg}s if no messages." |
There was a problem hiding this comment.
The new validation accepts values like "00" (digits-only) and writes them to the reminder file, but the rest of the system treats only the exact string "0" as paused/off and requires interval -gt 0 to actually fire reminders. That leaves a confusing state where airc reminder status prints "Reminder every 00s" while reminders never fire. Consider normalizing input to a canonical base-10 integer (e.g., parse with arithmetic and rewrite) and explicitly rejecting any value that evaluates to 0 (including "00", "000", etc.).
| echo "$arg" > "$reminder_file" | |
| echo " Reminder every ${arg}s if no messages." | |
| local normalized | |
| normalized=$((10#$arg)) | |
| if [ "$normalized" -le 0 ]; then | |
| echo " Refusing to set reminder interval to '$arg' — must be a positive integer (seconds)." >&2 | |
| echo " Try: airc reminder --help" >&2 | |
| return 2 | |
| fi | |
| echo "$normalized" > "$reminder_file" | |
| echo " Reminder every ${normalized}s if no messages." |
…rsion/ping/tests (round 2) (#251) fix(argv): -h/--help intercept on cmd_peers/disconnect/quit/invite/version/ping/tests continuum-b741's verb-fuzz round 2 against canary HEAD found 4 regressions / wart that #237's sweep missed: - airc peers --help: ignored (no intercept) - airc disconnect / quit --help: EXECUTED the disconnect (their monitor died) - airc invite (no-args dispatch): --help fell through to invite logic - airc version (no-args dispatch): same - airc ping --help: exited 1 not 0 - airc tests --help: exited 2 inconsistently ## Fix Added -h/--help intercepts to: cmd_peers, cmd_disconnect, cmd_invite, cmd_version, cmd_ping, _doctor_run_tests. Plus dispatch fixes in airc top-level: invite/version/disconnect/quit case branches now `shift; cmd_X "$@"` so flags reach the function. Previously they called cmd_X with no args, so --help on the cmdline never reached the function-level intercept. Verification: tabs 19/0; manual exercise of all 7 --help paths.
QA verb-fuzz from vhsm-d1f4 / continuum-b741 / ideem-local-4bef caught 3 destructive --help bugs (away, reminder, channel — last would brick airc update) plus 6 silent ones (status, connect, teardown, daemon, doctor, update). Class-wide sweep adds -h/--help intercepts to all + flag-shape rejection in cmd_channel/cmd_reminder.
After this: every lib/airc_bash/cmd_*.sh has the intercept.
Verification: tabs 19/0, room 14/0, general_sidecar_default 10/0, away 5/0; manual exercise of every --help.