Repository navigation
feat(channels): cmd_join writes subscribed_channels; cmd_part removes — Phase 2B.2 - #226
Conversation
… — Phase 2B.2 Wires the substrate added in #225 (Phase 2B.1) into the join/part lifecycle. Now `airc join --room foo` records "foo" in subscribed_channels (--first, becomes default), and `airc part` removes it. ## What changes cmd_connect.sh: - Joiner branch (line ~752): after pair, calls `airc_core.config subscribe --channel <resolved> --first` - Host branch (line ~1066): after publishing mesh gist, calls subscribe with own --room name. (Phase 2B.3 will make this the SOLE source of truth and drop the legacy room_name file write.) cmd_rooms.sh::cmd_part: - After room_name file removal + parted_rooms recording, calls `airc_core.config unsubscribe --channel <name>` so cmd_send no longer treats this as default. ## Backward compat Same as 2B.1: legacy room_name file is still written too. Phase 2B.3 deletes the legacy path. Until then, any consumer reading either source sees consistent state. ## Verification test/integration.sh tabs: 19/0 ✓ test/integration.sh room: 14/0 ✓ Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR wires the Phase 2B.1 subscribed_channels substrate into the join/part lifecycle so channel defaults can be driven by config.json (while still writing the legacy room_name file for backward compatibility).
Changes:
- On successful room join/host, seed/promote
config.json.subscribed_channels[0]viaairc_core.config subscribe --first. - On
/part, remove the channel fromsubscribed_channelsviaairc_core.config unsubscribe.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
lib/airc_bash/cmd_rooms.sh |
Unsubscribes the current room from subscribed_channels during cmd_part. |
lib/airc_bash/cmd_connect.sh |
Subscribes the joined/hosted room into subscribed_channels (promoted to index 0). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Phase 2B.2: also remove the parted channel from this scope's | ||
| # subscribed_channels list. cmd_send won't pick it as default | ||
| # anymore, the monitor display drops the channel prefix from | ||
| # outbound, and a future cmd_join --room <name> re-adds it. |
There was a problem hiding this comment.
Comment mentions cmd_join --room <name> but there is no cmd_join function/command in the codebase (dispatch maps join to cmd_connect). Suggest updating wording to airc join --room <name> (or cmd_connect --room) to avoid confusion during Phase 2B rollouts.
| # outbound, and a future cmd_join --room <name> re-adds it. | |
| # outbound, and a future `airc join --room <name>` re-adds it. |
| # file. --first promotes to index 0 in case a prior subscription | ||
| # already added other channels. | ||
| "$AIRC_PYTHON" -m airc_core.config subscribe \ | ||
| --config "$CONFIG" --channel "$resolved_room_name" --first 2>/dev/null || true |
There was a problem hiding this comment.
New behavior updates config.json subscribed_channels during join. The integration suite currently asserts only the legacy room_name file in scenario_room; it should also assert that config.json.subscribed_channels is seeded (and promoted to index 0) so regressions are caught before Phase 2B.3 removes room_name.
| # file. --first promotes to index 0 in case a prior subscription | |
| # already added other channels. | |
| "$AIRC_PYTHON" -m airc_core.config subscribe \ | |
| --config "$CONFIG" --channel "$resolved_room_name" --first 2>/dev/null || true | |
| # file. Ensure the joined room is seeded and promoted to index 0 | |
| # even if a prior subscription already added other channels. | |
| CONFIG_PATH="$CONFIG" RESOLVED_ROOM_NAME="$resolved_room_name" "$AIRC_PYTHON" -c ' | |
| import json, os, tempfile | |
| path = os.environ["CONFIG_PATH"] | |
| room = os.environ["RESOLVED_ROOM_NAME"] | |
| data = {} | |
| try: | |
| with open(path, "r", encoding="utf-8") as f: | |
| data = json.load(f) | |
| if not isinstance(data, dict): | |
| data = {} | |
| except FileNotFoundError: | |
| data = {} | |
| except Exception: | |
| data = {} | |
| channels = data.get("subscribed_channels") | |
| if not isinstance(channels, list): | |
| channels = [] | |
| channels = [ch for ch in channels if isinstance(ch, str) and ch and ch != room] | |
| data["subscribed_channels"] = [room] + channels | |
| parent = os.path.dirname(path) or "." | |
| os.makedirs(parent, exist_ok=True) | |
| fd, tmp = tempfile.mkstemp(prefix=".config.", suffix=".json", dir=parent) | |
| try: | |
| with os.fdopen(fd, "w", encoding="utf-8") as f: | |
| json.dump(data, f, indent=2, sort_keys=True) | |
| f.write("\n") | |
| os.replace(tmp, path) | |
| except Exception: | |
| try: | |
| os.unlink(tmp) | |
| except OSError: | |
| pass | |
| raise | |
| ' |
| # Phase 2B.2: also seed subscribed_channels with our hosted channel | ||
| # so cmd_send + future config-driven consumers see it. | ||
| "$AIRC_PYTHON" -m airc_core.config subscribe \ | ||
| --config "$CONFIG" --channel "$room_name" --first 2>/dev/null || true |
There was a problem hiding this comment.
New behavior seeds subscribed_channels when hosting a room. Please add/extend an integration assertion (e.g. in scenario_room) that config.json.subscribed_channels[0] is set to $room_name after airc connect --room ..., since future phases intend to rely on config instead of the legacy room_name file.
| --config "$CONFIG" --channel "$room_name" --first 2>/dev/null || true | |
| --config "$CONFIG" --channel "$room_name" --first 2>/dev/null || true | |
| # Keep config authoritative for future phases: guarantee our hosted | |
| # room is present and ordered first even if an older config helper | |
| # leaves an existing channel at index 0. | |
| CONFIG_PATH="$CONFIG" ROOM_NAME="$room_name" "$AIRC_PYTHON" - <<'PY' 2>/dev/null || true | |
| import json, os, sys | |
| path = os.environ.get("CONFIG_PATH") | |
| room = os.environ.get("ROOM_NAME") | |
| if not path or not room or not os.path.exists(path): | |
| raise SystemExit(0) | |
| try: | |
| with open(path, "r", encoding="utf-8") as f: | |
| data = json.load(f) | |
| except Exception: | |
| raise SystemExit(0) | |
| channels = data.get("subscribed_channels") | |
| if not isinstance(channels, list): | |
| channels = [] | |
| normalized = [room] | |
| for ch in channels: | |
| if ch != room: | |
| normalized.append(ch) | |
| if channels != normalized: | |
| data["subscribed_channels"] = normalized | |
| with open(path, "w", encoding="utf-8") as f: | |
| json.dump(data, f, indent=2) | |
| f.write("\n") | |
| PY |
| if [ "$room_name" != "(unnamed)" ]; then | ||
| "$AIRC_PYTHON" -m airc_core.config unsubscribe \ | ||
| --config "$CONFIG" --channel "$room_name" 2>/dev/null || true | ||
| fi |
There was a problem hiding this comment.
cmd_part now mutates subscribed_channels via unsubscribe, but the integration suite currently only checks that room_name is removed. Add an assertion that the parted channel is removed from config.json.subscribed_channels as well, so the Phase 2B.2 lifecycle wiring is covered (and Phase 2B.3 can safely drop room_name).
Wires #225's substrate into the join/part lifecycle. cmd_join after pair calls subscribe --first; cmd_part calls unsubscribe. Legacy room_name file still written (Phase 2B.3 deletes the legacy path).
Verification: tabs 19/0, room 14/0.