refactor(airc-bash): extract cmd_send + cmd_ping — Phase 0 monolith split#215
refactor(airc-bash): extract cmd_send + cmd_ping — Phase 0 monolith split#215
Conversation
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>
There was a problem hiding this comment.
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.shcontainingcmd_sendandcmd_ping. - Removed the inline
cmd_send/cmd_pingimplementations fromairc. - Updated
aircto sourcecmd_send.shvia 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.
| # 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 |
There was a problem hiding this comment.
--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.
| # 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) |
There was a problem hiding this comment.
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).
| 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) |
| # Handles --room, --to, queueing on host failure (pending.jsonl | ||
| # + [QUEUED] mirror in messages.jsonl), and the "speak as" rewrite | ||
| # for sidecar scopes. |
There was a problem hiding this comment.
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).
| # 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). |
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
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
🤖 Generated with Claude Code