Skip to content

feat(mesh): one gist per gh account — Phase 1 substrate switch - #222

Merged
joelteply merged 1 commit into
canaryfrom
feat/one-mesh-gist-per-account
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/one-mesh-gist-per-account

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Architectural shift from per-room gists to per-account-singleton mesh. Joel 2026-04-27:

"B is the god damn correct shift. They all share the same gist, stop being stupid. one goes down first one to resolve, posts to gist. host goes down, new host, first one that posts, becomes it."

What changes

  • New `lib/airc_bash/mesh.sh` — primitives for the mesh-gist abstraction: `_mesh_desc`, `_mesh_find` (singleton lookup), `_mesh_publish`, `_mesh_update`, `_mesh_age_secs`, `_mesh_take_over` (race-aware oldest-by-created election).
  • airc top-level: sources mesh.sh; `_self_heal_stale_host` now takes only stale_id (no room_name discriminator — mesh is per-account, nothing to discriminate on).
  • cmd_connect.sh:
    • Discovery: singleton lookup via `_mesh_find` (was: per-room awk filter)
    • Host publish: description `"airc mesh"`, payload kind `"mesh"`, `channels: [$room_name]` array (replaces `.name` + `.topic`)
    • Heartbeat payload: same shape change
    • Race-loser: `_mesh_take_over` (jitter, list, oldest-by-created wins)
    • Joiner: kind `"mesh"` handled alongside legacy `"room"` for back-compat
  • cmd_rooms.sh: list display recognizes mesh (◆), room (#), invite (1:1) — three kinds during the transition.

What's deferred (intentionally)

  • Phase 2: joiners adding their own channels to the mesh gist; channel-as-message-metadata for routing.
  • Phase 3: `.general` sidecar deletion (still spawned today).
  • Phase 4: sweep of legacy `airc room: *` gists on rollover.

Verification

  • `bash -n` clean on all four files
  • `test/integration.sh status`: 7/0 ✓
  • `test/integration.sh room`: 14/0 ✓
  • `test/integration.sh general_sidecar_default`: 12/0 ✓
  • `test/integration.sh tabs`: 1/3 (rename-marker timing flake; 0/3 on pristine canary HEAD too — predates this PR)
  • `test/integration.sh platform_adapters`: 9/2 (darwin/macos rename from refactor: unify _daemon_os into detect_platform (#205, net -26) #211, unrelated)

Test plan (e2e — requires QA team)

  • CI: integration suite on push to canary
  • e2e convergence: continuum-b69f (Windows) + Mac Claude on same gh account both run `airc update && airc join` — confirm both converge on a single new `airc mesh` gist; first to publish wins; second becomes joiner.
  • e2e takeover: kill the host, confirm joiner detects stale heartbeat and becomes new host via `_mesh_take_over`.
  • migration grace: existing `airc room: *` gists left untouched; new mesh gist created alongside; `airc rooms` shows both with separate markers.

🤖 Generated with Claude Code

Architectural shift from per-room gists to per-account-singleton mesh.
Joel 2026-04-27: "B is the god damn correct shift. They all share the
same gist, stop being stupid. one goes down first one to resolve, posts
to gist. host goes down, new host, first one that posts, becomes it."

## What changes

- New `lib/airc_bash/mesh.sh` — primitives for the mesh-gist abstraction:
  _mesh_desc, _mesh_find (singleton lookup), _mesh_publish, _mesh_update,
  _mesh_age_secs, _mesh_take_over (race-aware oldest-by-created election)
- airc top-level: source mesh.sh; _self_heal_stale_host now takes only
  stale_id (no room_name discriminator — mesh is per-account, nothing
  to discriminate on)
- cmd_connect.sh:
  - Discovery: singleton lookup via _mesh_find (was: per-room awk filter)
  - Host publish: description "airc mesh", payload kind "mesh",
    channels: [\$room_name] array (replaces .name + .topic)
  - Heartbeat payload: same shape change
  - Race-loser: _mesh_take_over (jitter, list, oldest-by-created wins)
  - Joiner: kind "mesh" handled alongside legacy "room" for back-compat
    with gists that haven't rolled over yet
- cmd_rooms.sh: list display now recognizes mesh (◆), room (#), invite
  (1:1) — three kinds during the transition

## What's deferred to Phase 2/3/4

- Joiners adding their own channels to the mesh gist (currently the
  host's published channels list is set at create time and only the
  host updates it)
- Channel-as-message-metadata routing (messages still go to one log;
  per-channel filtering is local-only at display time)
- .general sidecar deletion (still spawned per spawn_general_sidecar_if_wanted)
- Sweep of legacy `airc room: *` gists on rollover

## Verification

- bash -n clean on all four files
- airc help / version / dispatch reach correct paths
- test/integration.sh tabs:    1/3 (rename-marker timing flake; 0/3 on
                                pristine canary HEAD too — not introduced
                                by this PR, predates mesh switch)
- test/integration.sh status:  7/0 ✓
- test/integration.sh room:    14/0 ✓
- test/integration.sh general_sidecar_default: 12/0 ✓
- test/integration.sh platform_adapters: 9/2 (darwin/macos rename
                                from PR #211, unrelated)

## Test plan

- [ ] CI integration suite on push to canary
- [ ] e2e: continuum-b69f (Windows) + Mac Claude on same gh account
      both run `airc update && airc join` — confirm both converge on
      a single new "airc mesh" gist; first to publish wins; second
      becomes joiner
- [ ] e2e takeover: kill the host, confirm joiner detects stale and
      becomes new host (mesh takeover via _mesh_take_over)
- [ ] migration grace: existing `airc room: *` gists left untouched;
      new mesh gist created alongside; cmd_rooms shows both with
      separate markers (◆ vs #)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 28, 2026 16:32

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

Phase 1 of the “one gist per GitHub account” mesh substrate: shifts discovery/hosting from per-room gists to a per-account singleton gist (“airc mesh”), with takeover semantics and transitional UI support for legacy room/invite gists.

Changes:

  • Add lib/airc_bash/mesh.sh with mesh gist primitives (find/publish/update/age/takeover).
  • Update cmd_connect to discover/join/publish “mesh” envelopes (with channels) and use _mesh_find / _mesh_take_over.
  • Update cmd_rooms listing to recognize mesh vs legacy room vs invite; update airc to source mesh.sh and simplify _self_heal_stale_host.

Reviewed changes

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

File Description
lib/airc_bash/mesh.sh New mesh gist abstraction helpers (singleton lookup + takeover).
lib/airc_bash/cmd_connect.sh Switch discovery + envelope kind to mesh; adjust stale-host healing call signature.
lib/airc_bash/cmd_rooms.sh List output recognizes mesh/room/invite with distinct markers.
airc Source mesh.sh; update _self_heal_stale_host to mesh singleton semantics.

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

Comment on lines +1099 to +1100
_gist_kind="mesh"
_gist_desc="$(_mesh_desc)"
Comment thread lib/airc_bash/mesh.sh
Comment on lines +51 to +52
ids=$(gh gist list --limit 50 2>/dev/null \
| awk -F'\t' -v d="$desc" '$2 == d { print $1 }')
Comment on lines +351 to +370
# ── Mesh discovery (singleton per gh account) ────────────────
# Architectural shift from the per-room model: ONE gist per gh
# account, description literal "airc mesh". Every `airc join` on
# the account converges on it. _mesh_find returns the singleton
# (oldest-by-created if multiple are present from a race).
#
# The --room flag still records the channel(s) this client wants
# to subscribe to (Phase 2 will route messages by channel), but it
# no longer drives gist discovery — every subscriber on the account
# converges on the same host.
_did_room_discovery=1
local _mesh_id; _mesh_id=$(_mesh_find)
if [ -n "$_mesh_id" ]; then
echo " Found mesh on your gh account → joining ($_mesh_id)"
target="$_mesh_id"
# fall through to gist resolver below
else
echo " No mesh found on your gh account → becoming the host."
# Race against a concurrent host attempt is handled POST-publish
# via _mesh_take_over (see host-publish path below).
# delete + publish, end up with split-brain — caught only by
# running two tabs together.
_self_heal_stale_host "$_resolved_gist_id" "$resolved_room_name"
_self_heal_stale_host "$_resolved_gist_id"
Comment on lines +70 to 72
/airc mesh/ { print "mesh\t" $1 "\t" $2 "\t" $5 }
/airc room:/ { print "room\t" $1 "\t" $2 "\t" $5 }
/airc invite for/ { print "invite\t" $1 "\t" $2 "\t" $5 }
Comment thread lib/airc_bash/mesh.sh
Comment on lines +151 to +154
if [ "$count" -le 1 ]; then
echo "winner"
return 0
fi
Comment thread lib/airc_bash/mesh.sh
[ -f "$payload_path" ] || return 1
command -v gh >/dev/null 2>&1 || return 1
local desc; desc=$(_mesh_desc)
local url; url=$(gh gist create -d "$desc" "$payload_path" 2>/dev/null | tail -1)
Comment thread lib/airc_bash/mesh.sh
sleep "$jitter"
local desc; desc=$(_mesh_desc)
local ids; ids=$(gh gist list --limit 50 2>/dev/null \
| awk -F'\t' -v d="$desc" '$2 == d { print $1 }')
Comment thread lib/airc_bash/mesh.sh
Comment on lines +18 to +20
# cmd_connect.sh calls these instead of inline `gh gist create -d "airc
# room:..."`. Single source of truth for the gist description literal,
# the singleton-lookup contract, and race-loser semantics.
# caught only by running two tabs against a stale gist
# simultaneously, NOT by the integration test).
_self_heal_stale_host "$_resolved_gist_id" "$resolved_room_name"
_self_heal_stale_host "$_resolved_gist_id"
@joelteply
joelteply merged commit 19c96df into canary Apr 28, 2026
10 checks passed
@joelteply
joelteply deleted the feat/one-mesh-gist-per-account branch April 28, 2026 18:08
joelteply added a commit that referenced this pull request Apr 28, 2026
* feat(mesh): one gist per gh account — Phase 1 mesh-substrate switch

Architectural shift from per-room gists to per-account-singleton mesh.
Joel 2026-04-27: "B is the god damn correct shift. They all share the
same gist, stop being stupid. one goes down first one to resolve, posts
to gist. host goes down, new host, first one that posts, becomes it."

## What changes

- New `lib/airc_bash/mesh.sh` — primitives for the mesh-gist abstraction:
  _mesh_desc, _mesh_find (singleton lookup), _mesh_publish, _mesh_update,
  _mesh_age_secs, _mesh_take_over (race-aware oldest-by-created election)
- airc top-level: source mesh.sh; _self_heal_stale_host now takes only
  stale_id (no room_name discriminator — mesh is per-account, nothing
  to discriminate on)
- cmd_connect.sh:
  - Discovery: singleton lookup via _mesh_find (was: per-room awk filter)
  - Host publish: description "airc mesh", payload kind "mesh",
    channels: [\$room_name] array (replaces .name + .topic)
  - Heartbeat payload: same shape change
  - Race-loser: _mesh_take_over (jitter, list, oldest-by-created wins)
  - Joiner: kind "mesh" handled alongside legacy "room" for back-compat
    with gists that haven't rolled over yet
- cmd_rooms.sh: list display now recognizes mesh (◆), room (#), invite
  (1:1) — three kinds during the transition

## What's deferred to Phase 2/3/4

- Joiners adding their own channels to the mesh gist (currently the
  host's published channels list is set at create time and only the
  host updates it)
- Channel-as-message-metadata routing (messages still go to one log;
  per-channel filtering is local-only at display time)
- .general sidecar deletion (still spawned per spawn_general_sidecar_if_wanted)
- Sweep of legacy `airc room: *` gists on rollover

## Verification

- bash -n clean on all four files
- airc help / version / dispatch reach correct paths
- test/integration.sh tabs:    1/3 (rename-marker timing flake; 0/3 on
                                pristine canary HEAD too — not introduced
                                by this PR, predates mesh switch)
- test/integration.sh status:  7/0 ✓
- test/integration.sh room:    14/0 ✓
- test/integration.sh general_sidecar_default: 12/0 ✓
- test/integration.sh platform_adapters: 9/2 (darwin/macos rename
                                from PR #211, unrelated)

## Test plan

- [ ] CI integration suite on push to canary
- [ ] e2e: continuum-b69f (Windows) + Mac Claude on same gh account
      both run `airc update && airc join` — confirm both converge on
      a single new "airc mesh" gist; first to publish wins; second
      becomes joiner
- [ ] e2e takeover: kill the host, confirm joiner detects stale and
      becomes new host (mesh takeover via _mesh_take_over)
- [ ] migration grace: existing `airc room: *` gists left untouched;
      new mesh gist created alongside; cmd_rooms shows both with
      separate markers (◆ vs #)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* feat(channels): channel field on every message envelope — Phase 2A

Stamps the active channel on every outgoing message envelope so the
monitor formatter can route display by channel uniformly, regardless
of which scope the message was emitted from. This is the substrate
for Phase 2B (collapsing the multi-scope sidecar into a single scope
with subscribed_channels).

## Envelope shape

Old (room implied by scope-level room_name file):
  {"from":"X","to":"Y","ts":"...","msg":"..."}

New (channel stamped on the line itself):
  {"from":"X","to":"Y","ts":"...","channel":"general","msg":"..."}

## Sites stamped

- cmd_send.sh: peer/broadcast envelope + sig over the new payload shape
- cmd_send.sh: queue marker (tailnet offline)
- cmd_send.sh: queue marker (network error)
- cmd_send.sh: fail marker (auth)
- airc top-level: drain marker
- handshake.py: peer-join system event

Rename markers go through cmd_send --internal and inherit the field.

## Display

monitor_formatter.py now prefers `m.get("channel")` over the scope-
level room_name when prefixing each emitted line. The scope-level
room_name remains as a fallback for pre-Phase-2 envelopes that lack
the field, so older messages still prefix correctly during rollover.

## Verification

- bash -n + python ast.parse on all four changed files
- test/integration.sh tabs:  19/0 ✓
- test/integration.sh room:  14/0 ✓
- test/integration.sh queue: 7/0 ✓

## Stacked on Phase 1

Branched off feat/one-mesh-gist-per-account (PR #222). When that
merges to canary, Phase 2A rebases cleanly. Phase 2B (sidecar
deletion + subscribed_channels config) follows.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Apr 29, 2026
…closes #152) (#262)

The PS port was 2968 lines — a parallel codebase to the bash 'airc'.
After Phase 1+2 substrate landed (PRs #222-#243+) it lagged ~100
commits behind canary because every fix had to be hand-ported and
never was. Issue #152 tracked the drift.

## Resolution

Stop maintaining a parallel codebase. Git Bash ships with Git for
Windows (install.ps1 already ensures git is installed). The new
airc.ps1 is an 80-line shim:

1. Locate bash.exe (PATH → standard Git install paths → fallback).
2. Exclude System32\bash.exe (WSL Linux bash can't see Windows paths).
3. Forward all args via @Args splat to bash 'airc'.
4. Print clear install instructions if Git Bash is missing.

## Net effect

  airc.ps1:  2968 → 80 lines  (-2888)

Windows users running 'airc' (whether via airc.cmd → pwsh → airc.ps1
or directly via airc.ps1) now execute the same bash binary as Mac/Linux
users. Zero drift forever. Every Phase 1+2 substrate fix instantly
applies on Windows.

## What this requires

- Git for Windows (provides bash.exe). install.ps1 already installs it.
- For users on the OLD airc.ps1 who haven't reinstalled: re-run
  install.ps1 (or 'curl install.sh | bash' from Git Bash) to pull
  this change.

## What this drops

The parallel PS port's value was 'works without Git Bash'. In practice
nobody ran without Git Bash because install.ps1 ships it as a hard
dep. The maintenance burden vastly exceeded the value.

Closes #152.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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