Skip to content

refactor(airc-bash): extract cmd_send + cmd_ping — Phase 0 monolith split#215

Merged
joelteply merged 1 commit intocanaryfrom
refactor/extract-cmd-send
Apr 28, 2026
Merged

refactor(airc-bash): extract cmd_send + cmd_ping — Phase 0 monolith split#215
joelteply merged 1 commit intocanaryfrom
refactor/extract-cmd-send

Conversation

@joelteply
Copy link
Copy Markdown
Contributor

Summary

Splits the outbound-message verbs (cmd_send + cmd_ping, 361 lines) out of the airc bash monolith into `lib/airc_bash/cmd_send.sh`.

```
airc: 3504 → 3153 lines (-351)
lib/airc_bash/cmd_send.sh: +383
```

Stacks alongside #213 (cmd_connect, merged), #214 (cmd_daemon, merged).

Phase 0 cumulative progress

File Before #213 Now
airc 5265 3153 (-40%)
lib/airc_bash/ 617 2664

cmd_X functions still inline in airc: cmd_reminder, cmd_rename, cmd_away, cmd_identity, cmd_whois, cmd_kick, cmd_rooms, cmd_part, cmd_send_file, cmd_invite, cmd_peers, cmd_teardown, cmd_disconnect, cmd_update, cmd_channel, cmd_version, cmd_status, cmd_logs.

Test plan

  • CI: clean-install smoke matrix
  • CI: integration suite

🤖 Generated with Claude Code

Pulls the outbound-message verbs (cmd_send + cmd_ping, 361 lines) out
of the airc top-level into lib/airc_bash/cmd_send.sh, sourced via the
same lib-dir resolver as cmd_connect / cmd_daemon / cmd_doctor.

  airc:                     3504 → 3153 lines (-351)
  lib/airc_bash/cmd_send.sh:  +383 (361 body + 22 header)

cmd_send and cmd_ping are conceptually one group (ping is just send
with a [PING:] marker that older clients gracefully degrade on); both
go through the same envelope construction + queue-on-failure path,
so they belong together.

Behavior unchanged. Cross-references resolve at call-time:
  - cmd_send.sh calls airc top-level helpers (die, ensure_init,
    get_config_val, set_config_val, relay_ssh, get_host, …)
  - airc dispatch calls cmd_send / cmd_ping defined in cmd_send.sh

Verified:
  - bash -n on both files
  - test/integration.sh tabs: 19/0 (one timing-flake on rename marker
    propagation that resolves on re-run; identical to canary HEAD
    behavior, not introduced here)

Phase 0 progress (post this PR):
  airc top-level:     5265 → 3153 (-2112, -40%)
  lib/airc_bash:        +2664 across cmd_connect / cmd_daemon /
                        cmd_doctor / cmd_send / platform_adapters

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 28, 2026 15:56
@joelteply joelteply merged commit 74cd738 into canary Apr 28, 2026
6 checks passed
@joelteply joelteply deleted the refactor/extract-cmd-send branch April 28, 2026 15:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the bash airc monolith by extracting the outbound messaging verbs (cmd_send + cmd_ping) into a dedicated sourced module, continuing the ongoing “monolith split” work in lib/airc_bash/.

Changes:

  • Added lib/airc_bash/cmd_send.sh containing cmd_send and cmd_ping.
  • Removed the inline cmd_send / cmd_ping implementations from airc.
  • Updated airc to source cmd_send.sh via the existing lib-dir resolver mechanism.

Reviewed changes

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

File Description
lib/airc_bash/cmd_send.sh New extracted module implementing outbound message send + ping verbs.
airc Sources the new module and deletes the inline implementations.

💡 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 +90 to +96
# Strip any sibling suffix from current scope to get the project
# scope path. e.g. /path/.airc.general → /path/.airc
local _project_scope="$AIRC_WRITE_DIR"
case "$_project_scope" in
*.airc.*)
_project_scope="${_project_scope%.*}" ;;
esac
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

--room reroute computes _project_scope by matching *.airc.* and stripping the last .*. This breaks when the scope dir isn’t literally named .airc (e.g., tests and some users set AIRC_HOME to paths like /tmp/.../state and sidecars become state.general). In those cases, reroute will build the wrong sibling scope path. Prefer using the existing _primary_scope_for "$AIRC_WRITE_DIR" helper (defined in airc) to resolve the primary scope reliably, then derive the sibling scope from that.

Copilot uses AI. Check for mistakes.
Comment thread lib/airc_bash/cmd_send.sh
# payload cannot break the single-quoted remote echo.
local out err
err=$(mktemp -t airc-send-err.XXXXXX)
out=$(printf '%s\n' "$full_msg" | relay_ssh "$host_target" "cat >> $rhome/messages.jsonl && echo __APPENDED__" 2>"$err" || true)
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The remote append command interpolates $rhome without quoting: cat >> $rhome/messages.jsonl .... This will fail when the remote home path contains spaces (common on Windows /c/Users/First Last/...) and also creates unnecessary shell-injection risk if host_airc_home is ever set to a path with shell metacharacters. Quote the remote path in the command string so it’s treated as a single filename (while still allowing $HOME expansion on the remote).

Suggested change
out=$(printf '%s\n' "$full_msg" | relay_ssh "$host_target" "cat >> $rhome/messages.jsonl && echo __APPENDED__" 2>"$err" || true)
out=$(printf '%s\n' "$full_msg" | relay_ssh "$host_target" "cat >> \"$rhome/messages.jsonl\" && echo __APPENDED__" 2>"$err" || true)

Copilot uses AI. Check for mistakes.
Comment thread lib/airc_bash/cmd_send.sh
Comment on lines +5 to +7
# Handles --room, --to, queueing on host failure (pending.jsonl
# + [QUEUED] mirror in messages.jsonl), and the "speak as" rewrite
# for sidecar scopes.
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The header comment says cmd_send “Handles --room, --to … and the "speak as" rewrite for sidecar scopes”, but this implementation only supports --room and @peer addressing (no --to flag) and doesn’t appear to implement any sidecar “speak as” rewrite. Please update the comment to match the actual behavior (or implement the documented flags/logic).

Suggested change
# Handles --room, --to, queueing on host failure (pending.jsonl
# + [QUEUED] mirror in messages.jsonl), and the "speak as" rewrite
# for sidecar scopes.
# Handles --room, @peer addressing, and queueing on host
# failure (pending.jsonl + [QUEUED] mirror in messages.jsonl).

Copilot uses AI. Check for mistakes.
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