Repository navigation
feat(peers): aggregate across primary + sidecar scopes with [#room] tags - #124
Conversation
Pre-fix: 'airc peers' walked only the current scope's peers/ dir, so a tab in primary (#useideem) couldn't see who was in the #general lobby without manually 'cd'ing into .airc.general/. Multi-room presence is meaningless if the operator can't see who's in each room from one query. Post-fix: cmd_peers detects sibling sidecar scopes by walking the parent dir for entries matching the primary scope's prefix (.airc.<room> / state.<room> / etc — convention-flexible). Merges peer records by (name, host) across scopes, tagging each peer with the rooms they appear in. Same peer in both rooms folds into one line: authenticator-fd63 → [email protected] [#useideem, #general] vhsm-d1f4 → [email protected] [#useideem] continuum-b741 → [email protected] [#general] Operator perspective is consistent regardless of which scope they invoke 'airc peers' from — the aggregation walks the same set of sibling scopes either way. Test: scenario_peers_cross_scope synthesizes primary + sidecar scopes with shared / primary-only / sidecar-only peers; asserts merged output shows all three with correct room tags from both scope perspectives. 4/4 pass. Implementation note: the '.airc' literal is NOT hardcoded; prefix detection strips a trailing .<word> from the current scope's basename. Works for .airc/.airc.general (production) AND state/state.general (test ad-hoc paths) without convention coupling. Defensive guards on room_name + peers/ presence keep unrelated sibling dirs (.airc-old, .airc.bak) out of the listing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds cross-scope peer aggregation so airc peers shows a unified roster across the current scope and sibling sidecar room scopes, annotating each peer with [#room] tags.
Changes:
- Update
cmd_peersto scan the primary scope plus sibling sidecar scopes and merge peer records by(name, host), rendering combined room tags. - Add an integration test scenario (
peers_cross_scope) to verify cross-scope visibility and tagging from both primary and sidecar scopes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
airc |
Reworks cmd_peers to aggregate peers across sibling scopes and print room-tag annotations. |
test/integration.sh |
Adds scenario_peers_cross_scope and wires it into the runner/all mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| python3 -c " | ||
| import json, os, sys, re | ||
|
|
||
| primary_scope = os.path.expanduser('$AIRC_WRITE_DIR') |
There was a problem hiding this comment.
The inline Python source interpolates $AIRC_WRITE_DIR directly into a quoted Python string. If the path contains a single quote (or other problematic characters), this will produce invalid Python and fail the command; it also unnecessarily expands the attack surface for code injection via crafted env vars. Prefer reading paths from os.environ (and passing them via env vars) instead of embedding shell-expanded values into the Python program text.
| primary_scope = os.path.expanduser('$AIRC_WRITE_DIR') | |
| primary_scope = os.path.expanduser(os.environ['AIRC_WRITE_DIR']) |
| echo "$out" | grep -qE 'shared.*[email protected].*\[#myproject.*#general\]|shared.*[email protected].*\[#general.*#myproject\]' \ | ||
| && pass "shared peer shows tagged with BOTH rooms" \ | ||
| || fail "shared peer missing dual-room tag (got: $(echo "$out" | grep shared))" | ||
|
|
There was a problem hiding this comment.
This scenario validates that the shared peer has both room tags, but it doesn’t assert that the shared peer was actually merged into a single output line (duplicates would still satisfy the grep). Consider adding an assertion that shared appears exactly once in the output to ensure the de-duplication behavior is covered.
| [ "$(echo "$out" | grep -c 'shared')" -eq 1 ] \ | |
| && pass "shared peer appears exactly once in merged output" \ | |
| || fail "shared peer was not de-duplicated to a single line (got: $(echo "$out" | grep shared))" |
| rn_file = os.path.join(scope, 'room_name') | ||
| room = '(?)' | ||
| if os.path.isfile(rn_file): | ||
| try: room = open(rn_file).read().strip() | ||
| except Exception: pass | ||
| for f in sorted(os.listdir(peers_dir)): | ||
| if not f.endswith('.json'): continue | ||
| try: | ||
| d = json.load(open(os.path.join(peers_dir, f))) | ||
| except Exception: | ||
| continue | ||
| key = (d.get('name', f[:-5]), d.get('host', '')) | ||
| peers_by_id.setdefault(key, []).append(room) | ||
|
|
||
| if not peers_by_id: | ||
| print(' No peers yet.') | ||
| sys.exit(0) | ||
|
|
||
| # Render. Each peer once, with room annotations sorted + deduped. | ||
| for (name, host), rooms in sorted(peers_by_id.items()): | ||
| seen = set(); ordered = [] | ||
| for r in rooms: | ||
| if r not in seen: | ||
| ordered.append(r); seen.add(r) | ||
| tags = ', '.join('#' + r for r in ordered) | ||
| print(f' {name} → {host} [{tags}]') |
There was a problem hiding this comment.
In legacy/no-room scopes where room_name is missing or empty, this prints tags like "[#(?)]" or even "[#]" (if room_name file exists but is blank). Consider omitting room tags when room is unknown/empty (or falling back to the pre-change output format) to avoid confusing/invalid room annotations and to preserve compatibility in 1:1 invite mode.
| candidates = [] | ||
| if os.path.isdir(parent): | ||
| for entry in sorted(os.listdir(parent)): | ||
| if entry == prefix or entry.startswith(prefix + '.'): | ||
| candidates.append(os.path.join(parent, entry)) | ||
| scopes = [s for s in candidates | ||
| if os.path.isfile(os.path.join(s, 'room_name')) | ||
| and os.path.isdir(os.path.join(s, 'peers'))] | ||
| # Always include primary even if it doesn't have room_name yet — that's | ||
| # the legacy 1:1 invite mode case (use_room=0). | ||
| if primary_scope not in scopes and os.path.isdir(os.path.join(primary_scope, 'peers')): | ||
| scopes.insert(0, primary_scope) | ||
|
|
||
| # Build {(name, host): [room1, room2, ...]} by walking each scope's peers/. | ||
| peers_by_id = {} | ||
| for scope in scopes: | ||
| peers_dir = os.path.join(scope, 'peers') | ||
| if not os.path.isdir(peers_dir): | ||
| continue | ||
| rn_file = os.path.join(scope, 'room_name') | ||
| room = '(?)' | ||
| if os.path.isfile(rn_file): | ||
| try: room = open(rn_file).read().strip() | ||
| except Exception: pass | ||
| for f in sorted(os.listdir(peers_dir)): | ||
| if not f.endswith('.json'): continue | ||
| try: | ||
| d = json.load(open(os.path.join(peers_dir, f))) | ||
| except Exception: | ||
| continue |
There was a problem hiding this comment.
This Python block can still raise (e.g., permission errors on parent/scopes/peers directories, transient races during listdir/open), which will make airc peers exit non-zero under set -e. Wrap directory walks (os.listdir) and file reads in try/except and skip problematic scopes/files so a single unreadable sibling scope can’t break the whole peers listing.
Pre-fix: cmd_whois only consulted the primary scope's host / local-peer-file / cross-peer-via-host SSH lookups. A peer in the #general sidecar but not the primary project room returned "no record" — even after airc peers (post-#124) already showed them across rooms. JOIN events in the sidecar emitted names the IRC-style mental model said should be reachable, but whois 404'd. Post-fix: cmd_whois walks sibling scopes (.airc + .airc.<room>) using the same prefix-detection pattern cmd_peers uses. Each scope tries its own host / local-peer-file / cross-peer-via-host lookups; first hit wins. Per-scope logic factored into _whois_in_scope so primary and siblings share one code path. The cross-peer-via-host SSH path uses the SCOPE's identity/ssh_key (not the primary scope's), so a sidecar joiner can authenticate to its sidecar host even when the primary scope is paired with a different host on different keys. Test (scenario_whois_cross_scope) covers: - sidecar local peer found from primary scope (the vhsm bug) - sidecar HOST resolved from primary scope - primary host still resolves (no regression) - unknown peer still 404s after exhausting all scopes - symmetric: sidecar→primary lookup also works No wire-format change; backward compatible with single-scope users.
Summary
Follow-up to #122. Pre-fix: `airc peers` walked only the current scope's `peers/` dir, so a tab in #useideem couldn't see who was in #general without `cd`'ing into `.airc.general/`. Multi-room presence is meaningless if the operator can't get a unified roster.
Post-fix: `cmd_peers` detects sibling sidecar scopes (any sibling dir matching `.` with `room_name` + `peers/`), merges peer records by (name, host) across scopes, tags each peer with their rooms:
```
authenticator-fd63 → [email protected] [#useideem, #general]
vhsm-d1f4 → [email protected] [#useideem]
continuum-b741 → [email protected] [#general]
```
Operator perspective stays consistent regardless of which scope invokes `airc peers`.
Test plan
🤖 Generated with Claude Code