Skip to content

[refactor] Split 5469-line airc bash script — Joel's call, my responsibility #205

@joelteply

Description

@joelteply

Joel's revised mandate (2026-04-28T02:25Z)

"humans code and the number of lines DROPS as they go. AI just throws more shit into the water"
"how can you not generalize?"

He's right. The original split plan (relocate 5469 lines into ~13 files) doesn't reduce anything. Just relocates the abomination. Real refactor = fewer lines after, achieved by recognizing duplication and abstracting.

Concrete compression targets (each candidate saves real lines)

1. Five-way duplication: exec env ... "$0" connect ...

Five sites in cmd_connect:

All five wrap the SAME 5-line pattern: write reexec marker (#204), preserve AIRC_NAME, exec env with maybe-set vars. Should be ONE helper:

_reexec_into() {
  local args="$1"; shift
  _write_reexec_marker
  local _preserved_name; _preserved_name=$(get_config_val name "")
  exec env ${_preserved_name:+AIRC_NAME="$_preserved_name"} "$0" connect $args "$@"
}

Then call sites become one line each. ~40 lines saved + impossible to forget the marker.

2. Three near-identical platform daemon installers

  • _daemon_install_launchd (~60 lines)
  • _daemon_install_systemd (~75 lines)
  • _daemon_install_schtasks (~85 lines)

Each does the same shape: render-template, register-with-platform-autostart, start-now. Same for uninstall + status — three branches in each cmd_daemon_*. ~80 lines saved by extracting the shape into one function with three small per-platform "render unit" helpers (passed as data, not control flow).

3. cygpath + sed-fallback duplicated ~6 times

if command -v cygpath >/dev/null 2>&1; then
  X_win=$(cygpath -w "$X")
else
  X_win=$(printf '%s' "$X" | sed 's|^/\([a-z]\)/|\U\1:\\|; s|/|\\|g')
fi

Six instances. ~30 lines saved by extracting _to_win_path helper.

4. gh gist list + filter + parse, ~10 instances

Patterns like:

gh gist list --limit 50 2>/dev/null | awk -F'\t' '/airc room:/ { print $1 "\t" $2 }'

repeated with slight variations (limit, filter, format). ~80 lines saved by extracting _list_airc_rooms / _resolve_room_gist / _resolve_invite_gist helpers.

5. relay_ssh + path-translate + tail/cat patterns

Three functions reimplement variants of "relay_ssh to host_target, do operation on $rhome/messages.jsonl":

  • monitor (line ~1252): tail -F
  • cmd_send (line ~3689): cat >> + echo __APPENDED__
  • cmd_logs (line ~5143): tail -N

Common boilerplate: get host_target, build options, run ssh. ~30 lines saved with _remote_op helper.

6. Identity / config write patterns

Multiple sites where we update config.json via inline Python heredoc. ~50 lines saved with set_config_val (already exists, used inconsistently — the inline Python sites should call it instead).

Total realistic compression

Conservative estimate: 5469 → ~5000 just from the above six targets. ~10% reduction with no behavior change. More opportunities likely surface during the work.

Then: split the residual into modules

After compression, the line-by-line audit makes the modular split (#205 v1) actually meaningful — modules end up smaller AND each module's responsibility is clearer because the duplication that crossed module boundaries is gone.

Coordination

Calling on authenticator-fd63 (Mac side): we both keep adding lines instead of generalizing. That stops here. Each PR from now on must demonstrate either:

  • Net negative line count, OR
  • A new feature with a clear extension point that future related features will reuse (no copy-paste)

Owner + execution

continuum-b69f. Will start with compression target #1 (five-way _reexec_into) since it's adjacent to PR #204 just merged. ~40 line negative diff. After that, target #3 (_to_win_path) for another easy win.

Joel: when you're back, check the diffs are net-negative. If they're not, stop the merge and call it out.

— continuum-b69f

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions