Skip to content

fix(argv): -h/--help intercept on cmd_send / cmd_kick / cmd_whois - #231

Merged
joelteply merged 1 commit into
canaryfrom
fix/help-flag-intercept-on-cmd-x
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/help-flag-intercept-on-cmd-x

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Stops 'airc msg --help' from broadcasting the literal '--help' to the room (and similar shape for kick/whois). Each cmd_X argv parser now intercepts -h/--help before positional processing.

Verification: tabs 19/0, kick 12/0, whois 5/0; manually exercised airc msg/kick/whois --help.

Bug found by ideem-local-4bef during canary QA (B1 in their report
2026-04-28): \`airc msg --help\` broadcast the literal "--help" to the
room because cmd_send had no help-flag intercept; any --flag-looking-
token fell through to positional args and became message body.

Same shape for cmd_kick (rejected --help with the unhelpful "must not
start with '-'" peer-validation error) and cmd_whois.

## Fix

Each cmd_X argv parser now intercepts -h / --help BEFORE positional
processing and prints a real usage block.

  cmd_send:  full Phase 2B usage (--channel + --room alias + --internal)
  cmd_kick:  one-line "kick <peer> [reason]" + host-only note
  cmd_whois: one-line self / peer forms

## Verification

  airc msg --help, airc kick --help, airc whois --help — all print
  usage instead of broadcasting / erroring.

  test/integration.sh tabs:  19/0 ✓
  test/integration.sh kick:  12/0 ✓
  test/integration.sh whois: 5/0  ✓

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 28, 2026 19:04
@joelteply
joelteply merged commit 147c0fc into canary Apr 28, 2026
@joelteply
joelteply deleted the fix/help-flag-intercept-on-cmd-x branch April 28, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents --help/-h from being treated as a positional argument for send/kick/whois, avoiding cases like airc msg --help accidentally broadcasting the literal --help to a room.

Changes:

  • Add -h|--help interception to cmd_send before positional message handling.
  • Add -h|--help (and empty-argv) usage handling to cmd_kick.
  • Add -h|--help interception to cmd_whois to avoid failing peer-name validation with an unhelpful error.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
lib/airc_bash/cmd_send.sh Adds --help handling in the send/msg argv parser to prevent accidental broadcasts.
lib/airc_bash/cmd_kick.sh Adds help/usage handling for kick before validating the target peer name.
lib/airc_bash/cmd_identity.sh Adds a help-flag intercept to cmd_whois so --help shows usage instead of triggering validation errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/airc_bash/cmd_send.sh
Comment on lines +62 to +66
-h|--help)
echo "Usage:"
echo " airc send <message> broadcast to default channel"
echo " airc send @peer <message> DM peer"
echo " airc send --channel <name> <msg> stamp channel field"

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd_send now treats -h/--help as a global flag anywhere in argv. That prevents users from sending a literal message token of --help / -h (e.g. airc send -- --help is not supported because -- isn’t handled). Consider adding a standard -- end-of-options marker (and/or only honoring -h/--help before the first positional) so help interception fixes the accidental case without removing the ability to send those strings as chat content.

Copilot uses AI. Check for mistakes.
Comment thread lib/airc_bash/cmd_send.sh
local positional=()
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s integration coverage for airc send behaviors (queueing, --room routing, etc.), but the new --help interception path isn’t exercised. Adding an integration assertion that airc msg/send --help exits 0 and does not append to messages.jsonl would guard against regressions (the original bug was that it broadcast the literal --help).

Copilot uses AI. Check for mistakes.
Comment thread lib/airc_bash/cmd_kick.sh
Comment on lines +28 to +33
case "$target" in
-h|--help|"")
echo "Usage: airc kick <peer> [reason]"
echo " Host-only. Removes peer's SSH pubkey + peer file."
[ -z "$target" ] && return 1
return 0 ;;

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The integration suite already exercises airc kick in scenario_kick, but it doesn’t cover the new kick --help / kick -h path. Adding a small assertion for help output + exit code (and that it does not attempt peer validation) would lock in the behavior this PR is fixing.

Copilot uses AI. Check for mistakes.
Comment on lines +193 to +202
# Help-flag intercept — without this, --help flowed into target and
# got rejected by _validate_peer_name with the unhelpful "must not
# start with '-'" error.
case "$target" in
-h|--help)
echo "Usage:"
echo " airc whois show own identity"
echo " airc whois <peer> show peer's identity (paired or via host)"
return 0 ;;
esac

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is integration coverage for whois behavior (e.g., scenario_whois*), but the new whois --help interception path isn’t asserted. Adding a test that airc whois --help exits 0 and prints usage (rather than the peer-name validation error) would prevent regression back to the original issue.

Copilot uses AI. Check for mistakes.
joelteply added a commit that referenced this pull request Apr 28, 2026
…-help) (#236)

fix(argv): -h/--help intercept on cmd_part — was actually parting on --help

Same anti-pattern as #231 fixed for cmd_send / cmd_kick / cmd_whois,
missed in cmd_part. Found the hard way 2026-04-28 by airc-96dd
during follow-up testing: ran 'airc part --help' to check the help
text, the --help fell through, cmd_part treated it as "no specific
channel" and parted the current room — disconnecting the monitor.

## Fix

cmd_rooms.sh::cmd_part: case statement intercepting -h / --help
BEFORE ensure_init or any state mutation. Prints usage describing
the host vs joiner branches.

## Verification

  bash -n: clean
  Manual: 'airc part --help' / 'airc part -h' both print usage
          without touching scope state.
  test/integration.sh tabs: 19/0 ✓
  test/integration.sh room: 14/0 ✓

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Apr 28, 2026
…ep) (#237)

fix(argv): -h/--help intercept on all remaining cmd_X — class-wide sweep

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]>
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.

2 participants