Skip to content

feat(channels): subscribed_channels config + --channel send flag — Phase 2B.1 - #225

Merged
joelteply merged 1 commit into
canaryfrom
feat/phase2b-subscribed-channels
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/phase2b-subscribed-channels

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Phase 2B.1 substrate. Adds subscribed_channels config helpers + cmd_send --channel override. Backward compatible — existing room_name + sidecar + --room re-exec still work. Phase 2B.2 wires cmd_join to write the config; 2B.3 deletes sidecar.

Verification: tabs 19/0, queue 7/0, status 7/0; CLI manually exercised.

…ase 2B.1

Adds the substrate for collapsing the multi-scope sidecar into a single
scope subscribing to N channels. Phase 2B is splitting into 3 smaller
PRs per Joel's iterate-on-canary push:
  2B.1 (this): config helpers + cmd_send default-from-config + --channel
  2B.2: cmd_join writes subscribed_channels; cmd_part removes
  2B.3: drop sidecar spawn; drop cmd_send sibling-scope re-exec

## What changes

airc_core/config.py:
  - subscribe   --channel X [--first]  add to subscribed_channels
                                       (--first promotes to index 0)
  - unsubscribe --channel X            remove
  - read_channels                      list one per line
  - default_channel                    print subscribed_channels[0]

cmd_send.sh:
  - new --channel / -c flag overrides per-call channel
  - default channel resolution (priority order):
      1. --channel flag
      2. config.json subscribed_channels[0]
      3. legacy room_name file (back-compat for users mid-rollover)
      4. literal "general"

## Backward compatibility

This is purely additive in 2B.1:
  - cmd_send still accepts --room (sibling-scope re-exec still works)
  - room_name file still authoritative if no subscribed_channels
  - sidecar still spawned (Phase 2B.3 deletes both)

Existing users see zero behavior change until something writes to
subscribed_channels (Phase 2B.2 wires cmd_join to do that).

## Verification

  bash -n + python ast.parse: clean
  test/integration.sh tabs:   19/0 ✓
  test/integration.sh queue:  7/0 ✓
  test/integration.sh status: 7/0 ✓
  CLI: subscribe / unsubscribe / --first ordering / default_channel —
       manually exercised against a fresh config.json

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 28, 2026 18:19
@joelteply
joelteply merged commit ca72418 into canary Apr 28, 2026
7 checks passed
@joelteply
joelteply deleted the feat/phase2b-subscribed-channels branch April 28, 2026 18:20
joelteply added a commit that referenced this pull request Apr 28, 2026
… — Phase 2B.2 (#226)

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]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds Phase 2B.1 substrate support for multi-channel operation by introducing a subscribed_channels config surface and allowing airc send to stamp an explicit channel via --channel/-c (without scope re-exec), while remaining backward compatible with legacy room_name + --room.

Changes:

  • Add subscribed_channels read/default/subscribe/unsubscribe subcommands to airc_core.config.
  • Add airc send --channel/-c override and update channel resolution priority to prefer config default (with legacy fallback).

Reviewed changes

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

File Description
lib/airc_core/config.py Adds CLI helpers to manage subscribed_channels and retrieve the default channel.
lib/airc_bash/cmd_send.sh Adds --channel/-c flag and resolves outbound message channel from override/config/legacy fallback.
Comments suppressed due to low confidence (1)

lib/airc_bash/cmd_send.sh:185

  • active_channel is interpolated into JSON (payload/full_msg) without JSON-escaping. With the new --channel flag (and also values coming from config/room_name), a channel containing quotes/backslashes/newlines will produce invalid JSON and could let a user craft confusing/injecting log lines. Escape/sanitize the channel once (e.g., via json.dumps(...)[1:-1] like escaped_msg) and use the escaped value everywhere the channel is embedded in JSON (payload, full_msg, queue/auth markers).
  local active_channel=""
  if [ -n "$channel_override" ]; then
    active_channel="$channel_override"
  fi
  if [ -z "$active_channel" ]; then
    active_channel=$("$AIRC_PYTHON" -m airc_core.config default_channel --config "$CONFIG" 2>/dev/null || true)
  fi
  if [ -z "$active_channel" ] && [ -f "$AIRC_WRITE_DIR/room_name" ]; then
    active_channel=$(cat "$AIRC_WRITE_DIR/room_name" 2>/dev/null || true)
  fi
  [ -z "$active_channel" ] && active_channel="general"

  local payload="{\"from\":\"$my_name\",\"to\":\"$peer_name\",\"ts\":\"$ts_val\",\"channel\":\"$active_channel\",\"msg\":\"$escaped_msg\"}"
  local sig; sig=$(sign_message "$payload")
  local full_msg="{\"from\":\"$my_name\",\"to\":\"$peer_name\",\"ts\":\"$ts_val\",\"channel\":\"$active_channel\",\"msg\":\"$escaped_msg\",\"sig\":\"$sig\"}"


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

Comment thread lib/airc_core/config.py
Comment on lines +114 to +126
# ── subscribed_channels (Phase 2B) ──────────────────────────────────────
#
# Replaces the per-scope `room_name` file + sidecar scopes. A single
# `airc connect` process now subscribes to N channels in one mesh; the
# config field is the source of truth for "which channels do I display?".
#
# The first element is the DEFAULT channel — the one cmd_send stamps on
# outbound messages when --channel isn't passed. Order matters.
#
# Migration: a one-shot bootstrap reads the legacy `room_name` file (if
# present) and writes it as the single-element subscribed_channels list,
# preserving behavior for users mid-rollover. After that the room_name
# file is no longer authoritative — config wins.

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

The header comment block claims subscribed_channels already “replaces” the per-scope room_name + sidecar model and that there is a “one-shot bootstrap” migration that reads room_name and writes subscribed_channels. In this PR, airc connect/sidecars and room_name are still active, and there’s no migration code in this module or elsewhere in lib/ (only these helpers + cmd_send lookup). Please update the comment to match the current Phase 2B.1 behavior, or implement the described bootstrap/migration to avoid misleading future maintainers.

Suggested change
# ── subscribed_channels (Phase 2B) ──────────────────────────────────────
#
# Replaces the per-scope `room_name` file + sidecar scopes. A single
# `airc connect` process now subscribes to N channels in one mesh; the
# config field is the source of truth for "which channels do I display?".
#
# The first element is the DEFAULT channel — the one cmd_send stamps on
# outbound messages when --channel isn't passed. Order matters.
#
# Migration: a one-shot bootstrap reads the legacy `room_name` file (if
# present) and writes it as the single-element subscribed_channels list,
# preserving behavior for users mid-rollover. After that the room_name
# file is no longer authoritative — config wins.
# ── subscribed_channels (Phase 2B.1) ────────────────────────────────────
#
# Config-backed helpers for managing the optional `subscribed_channels`
# list. In the current rollout phase, this does not replace the legacy
# per-scope `room_name` + sidecar model; those paths may still be active
# elsewhere while callers adopt these helpers.
#
# The first element is the DEFAULT channel — the one cmd_send uses for
# outbound messages when --channel isn't passed. Order matters.
#
# Note: this module does not currently perform any bootstrap/migration
# from legacy `room_name` state into `subscribed_channels`. Callers should
# treat `subscribed_channels` as opt-in config state, not as a guaranteed
# mirror of older room selection data.

Copilot uses AI. Check for mistakes.
Comment thread lib/airc_bash/cmd_send.sh
Comment on lines 162 to 180
# Channel: stamp every outbound envelope with the active channel so the
# monitor display can route by channel uniformly (Phase 2 mesh
# substrate). Resolved from the scope's room_name file; falls back to
# "general" if no scope room is set. Once Phase 2B lands the joiner
# subscribed_channels concept, --channel <name> on cmd_send will
# override this default.
local active_channel="general"
[ -f "$AIRC_WRITE_DIR/room_name" ] && active_channel=$(cat "$AIRC_WRITE_DIR/room_name" 2>/dev/null || echo general)
# substrate). Resolution priority (Phase 2B.1):
# 1. --channel / -c flag (explicit per-call override)
# 2. config.json subscribed_channels[0]
# (Phase 2B substrate — replaces sidecar scopes)
# 3. legacy room_name file (back-compat for users mid-rollover)
# 4. literal "general" fallback
local active_channel=""
if [ -n "$channel_override" ]; then
active_channel="$channel_override"
fi
if [ -z "$active_channel" ]; then
active_channel=$("$AIRC_PYTHON" -m airc_core.config default_channel --config "$CONFIG" 2>/dev/null || true)
fi
if [ -z "$active_channel" ] && [ -f "$AIRC_WRITE_DIR/room_name" ]; then
active_channel=$(cat "$AIRC_WRITE_DIR/room_name" 2>/dev/null || true)
fi
[ -z "$active_channel" ] && active_channel="general"

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

There are integration tests covering airc send --room ... in test/integration.sh, but nothing exercises the new airc send --channel/-c precedence (override > config default > room_name > fallback) or verifies that the channel value is safely embedded into outbound envelopes. Adding an integration test for --channel (and for config-based default_channel) would help prevent regressions during Phase 2B.2/2B.3 refactors.

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