Skip to content

refactor(airc-bash): extract cmd_teardown + cmd_disconnect#216

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

refactor(airc-bash): extract cmd_teardown + cmd_disconnect#216
joelteply merged 1 commit intocanaryfrom
refactor/extract-cmd-teardown

Conversation

@joelteply
Copy link
Copy Markdown
Contributor

Pulls the leave/cleanup verbs (cmd_teardown + cmd_disconnect, 253 lines) into lib/airc_bash/cmd_teardown.sh. airc: 3153 → 2909 (-244). Stacks alongside #213/#214/#215.

…file split

Pulls the leave/cleanup verbs (cmd_teardown + cmd_disconnect, 253 lines)
out of the airc top-level into lib/airc_bash/cmd_teardown.sh.

  airc:                          3153 → 2909 lines (-244)
  lib/airc_bash/cmd_teardown.sh:           +273 (253 body + 20 header)

Both verbs share the kill loop and split on what to clear afterwards
(teardown wipes more aggressively; disconnect preserves identity +
peers + history). Logically one group.

Verified bash -n + smoke dispatch.

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:57
@joelteply joelteply merged commit b9cd72f into canary Apr 28, 2026
1 check passed
@joelteply joelteply deleted the refactor/extract-cmd-teardown branch April 28, 2026 15:57
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

Extracts the teardown/disconnect “leave/cleanup” verbs from the airc bash monolith into a dedicated sourced module, continuing the ongoing Phase 0/3 modularization of airc into lib/airc_bash/* command files.

Changes:

  • Adds lib/airc_bash/cmd_teardown.sh containing cmd_teardown and cmd_disconnect.
  • Removes the inline implementations from airc and sources the new module via _airc_lib_dir.

Reviewed changes

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

File Description
lib/airc_bash/cmd_teardown.sh New extracted module implementing cmd_teardown/cmd_disconnect.
airc Replaces inline teardown/disconnect functions with a source of the new module.

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

for lpid in $lpids; do
local cmd
cmd=$(proc_cmdline "$lpid" || true)
if echo "$cmd" | grep -q "socket.SOCK_STREAM\|socket.AF_INET"; then
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.

grep -q "socket.SOCK_STREAM\|socket.AF_INET" relies on a non-POSIX alternation escape (and the unescaped .s are regex wildcards). This can fail on some greps (notably non-GNU) and may match unintended strings. Prefer a portable fixed-string match (e.g., grep -F with multiple -e patterns) or grep -E with properly escaped dots.

Suggested change
if echo "$cmd" | grep -q "socket.SOCK_STREAM\|socket.AF_INET"; then
if echo "$cmd" | grep -F -q -e 'socket.SOCK_STREAM' -e 'socket.AF_INET'; then

Copilot uses AI. Check for mistakes.
Comment on lines +260 to +271
if [ -f "$CONFIG" ]; then
"$AIRC_PYTHON" -c "
import json
try:
c = json.load(open('$CONFIG'))
for k in ('host_target', 'host_name', 'host_airc_home', 'host_port', 'host_ssh_pub'):
c.pop(k, None)
json.dump(c, open('$CONFIG', 'w'), indent=2)
except Exception:
pass
" 2>/dev/null || true
fi
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.

cmd_disconnect edits config via an inline python -c string that interpolates $CONFIG directly into the Python source. This is quoting-fragile (paths with ' break) and duplicates the repo’s existing config helper. Use unset_config_keys (already available in airc) to clear the host-pairing keys, and include host_identity in the cleared set to fully remove cached host pairing state.

Suggested change
if [ -f "$CONFIG" ]; then
"$AIRC_PYTHON" -c "
import json
try:
c = json.load(open('$CONFIG'))
for k in ('host_target', 'host_name', 'host_airc_home', 'host_port', 'host_ssh_pub'):
c.pop(k, None)
json.dump(c, open('$CONFIG', 'w'), indent=2)
except Exception:
pass
" 2>/dev/null || true
fi
unset_config_keys \
host_target \
host_name \
host_airc_home \
host_port \
host_ssh_pub \
host_identity >/dev/null 2>&1 || true

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +13
# External cross-references (call-time): die, ensure_init, get_config_val,
# unset_config_keys, proc_airc_pids_matching, port_listeners, AIRC_HOME,
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’s “External cross-references” list appears out of sync with the actual implementation (e.g., die/ensure_init/get_config_val/unset_config_keys aren’t called in cmd_teardown, while proc_children/proc_parent/proc_cmdline are). Updating this list will keep the module’s dependency documentation accurate.

Suggested change
# External cross-references (call-time): die, ensure_init, get_config_val,
# unset_config_keys, proc_airc_pids_matching, port_listeners, AIRC_HOME,
# External cross-references (call-time): proc_airc_pids_matching,
# proc_children, proc_parent, proc_cmdline, port_listeners, AIRC_HOME,

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