Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(remote): revoke (unpin + onRevoke kill hook) — unpinning alone is insufficient

enes13941d12f38f
diff --git a/src/main/remote/revocation.test.ts b/src/main/remote/revocation.test.ts
new file mode 100644
index 000000000..4d4a39d35
--- /dev/null
+++ b/src/main/remote/revocation.test.ts
@@ -0,0 +1,64 @@
+import { describe, it, expect } from 'vitest'
+import { revoke, createRevoker, type RevocationDeps } from './revocation'
+import { pinDevice, isPinned, type ApprovedDevices } from './approved-devices-core'
+
+describe('pure revoke', () => {
+ it('removes the pin (idempotent)', () => {
+ const store = pinDevice({ pubkeys: [] }, 'peerKey')
+ const after = revoke(store, 'peerKey')
+ expect(isPinned(after, 'peerKey')).toBe(false)
+ expect(revoke(after, 'peerKey')).toEqual(after) // idempotent
+ })
+})
+
+describe('createRevoker: unpins AND fires the kill hook', () => {
+ it('persists the unpin, then fires onRevoke(peerId) so 4c can cut the live session', async () => {
+ let store: ApprovedDevices = pinDevice({ pubkeys: [] }, 'peerKey')
+ const order: string[] = []
+ const killed: string[] = []
+ const deps: RevocationDeps = {
+ load: async () => store,
+ save: async (s) => {
+ order.push('save')
+ store = s
+ },
+ // Fake teardown standing in for 4c's "close relay conn + PtyManager.dropClient + presenceHub.leave".
+ onRevoke: (peerId) => {
+ order.push('onRevoke')
+ killed.push(peerId)
+ }
+ }
+ const revoker = createRevoker(deps)
+ await revoker.revoke('peerKey')
+
+ expect(isPinned(store, 'peerKey')).toBe(false) // unpinned on disk
+ expect(killed).toEqual(['peerKey']) // hook fired exactly once, with the peer id
+ // Unpin must be PERSISTED before the live session is cut, so a reconnect racing the kill is
+ // already refused by the pin check. (Unpin alone would leave the open socket fully privileged.)
+ expect(order).toEqual(['save', 'onRevoke'])
+ })
+
+ it('still fires the kill hook even if the key was never pinned (defensive)', async () => {
+ const killed: string[] = []
+ const revoker = createRevoker({
+ load: async () => ({ pubkeys: [] }),
+ save: async () => {},
+ onRevoke: (id) => killed.push(id)
+ })
+ await revoker.revoke('ghost')
+ expect(killed).toEqual(['ghost']) // a live-but-unpinned session must still be killable
+ })
+
+ it('fires the kill hook even when persistence fails (the kill must not depend on the disk)', async () => {
+ const killed: string[] = []
+ const revoker = createRevoker({
+ load: async () => pinDevice({ pubkeys: [] }, 'peerKey'),
+ save: async () => {
+ throw new Error('disk full')
+ },
+ onRevoke: (id) => killed.push(id)
+ })
+ await expect(revoker.revoke('peerKey')).resolves.toBeUndefined()
+ expect(killed).toEqual(['peerKey'])
+ })
+})
diff --git a/src/main/remote/revocation.ts b/src/main/remote/revocation.ts
new file mode 100644
index 000000000..c30b1a8ee
--- /dev/null
+++ b/src/main/remote/revocation.ts
@@ -0,0 +1,53 @@
+// Peer revocation for the relay trust layer.
+//
+// THE CRITICAL PROPERTY: unpinning a peer's key is NOT enough. Unpinning only refuses the NEXT
+// handshake; the currently-open relay socket keeps full shell access (an interactive shell, files,
+// canvas) until it drops on its own — i.e. "the person I just removed is still sitting in my
+// terminal, typing". So revocation MUST also cut the live session. Anyone tempted to "simplify" this
+// module into a pin-store delete would silently reintroduce exactly that hole.
+//
+// 4d ships the pure unpin + the hook contract; 4c implements the teardown body:
+// onRevoke(peerId) = close the peer's relay connection
+// → PtyManager.dropClient(clientId) (drop its pty subscriptions)
+// → presenceHub.leave(clientId) (remove it from the facepile)
+// which is the same teardown `peer-registry.ts` runs when a peer sink unregisters.
+//
+// (peerId is the peer's stable box public key, base64 — the same identity the pin store and 4c's
+// live-session registry key on.)
+import { unpinDevice, type ApprovedDevices } from './approved-devices-core'
+
+/** Pure: return a store with the peer's pin removed. Idempotent. */
+export function revoke(store: ApprovedDevices, peerKeyB64: string): ApprovedDevices {
+ return unpinDevice(store, peerKeyB64)
+}
+
+/** 4c implements this to KILL the live session (see file header). */
+export type OnRevoke = (peerId: string) => void
+
+export interface RevocationDeps {
+ load(): Promise<ApprovedDevices>
+ save(store: ApprovedDevices): Promise<void>
+ onRevoke: OnRevoke
+}
+
+/**
+ * Build the revoke controller. `revoke(peerKeyB64)` unpins the device on disk FIRST (so a crash
+ * between the two steps, or a reconnect racing the teardown, still leaves the peer refused by the
+ * pin check), THEN fires `onRevoke` to cut the open socket. The kill hook fires even when the key
+ * was not pinned — a live, never-pinned session must still be killable — and even when the disk
+ * write failed: a persistence error must never leave a revoked peer connected.
+ */
+export function createRevoker(deps: RevocationDeps): { revoke(peerKeyB64: string): Promise<void> } {
+ return {
+ async revoke(peerKeyB64) {
+ try {
+ const store = await deps.load()
+ await deps.save(revoke(store, peerKeyB64))
+ } catch {
+ // Non-fatal for the KILL: fall through to onRevoke regardless. (Worst case the pin survives
+ // a crash and the operator must revoke again — but the peer is off the wire either way.)
+ }
+ deps.onRevoke(peerKeyB64)
+ }
+ }
+}