Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (round 3): recipient-relative attached flag + tab-click switch recovery + style
[._.]/ Adam Eivyb58be7c198c8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex e8be3e76c8..8870a87459 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -28,6 +28,14 @@driving another tab. Manual tab clicks and deep-link URL navigationstill take over (intent is explicit). Prevents tab B from bootingtab A off its shell when tab B's session is killed externally.+ - **`attached` is recipient-relative.** `listAllSessions` and+ `broadcastSessionList` now personalize each subscriber's payload so+ `attached` only reports `true` when the session is bound to a+ *different* socket. Sessions bound to the recipient's own singleton+ socket (e.g. sessions opened earlier in this tab that stayed bound+ when the user navigated away and back) report `attached: false`, so+ the client's auto-pick path adopts them on return instead of leaving+ bare `/shell` disconnected.- **Pending-attach gate.** A new `pendingAttachRef` tracks the in-flightstart/attach target. While set, keystrokes and quick commands aredropped (so input doesn't land in the previous session during the@@ -39,8 +47,12 @@from a start attempt while an existing session is still alive (e.g.session limit hit), `handleShellError` no longer re-attaches andrepaints the terminal — the error stays readable. Re-attach recovery- now only triggers when the URL diverged from the active session- (switch-failure path) or when the active session is itself gone.+ now triggers when the URL diverged from the active session (URL-nav+ switch failure) OR when `pendingAttachRef` was for a different session+ at the time of error (tab-click switch failure — URL never moved+ because `activateSession` never fired). The start-failure path+ (`pendingAttachRef === 'new'`) leaves the terminal untouched so the+ error message survives.- **Layout full-width includes deep links.** `Layout.jsx` matches both`/shell` and `/shell/<id>` for full-height/overflow-hidden styling sodeep-linked terminals render edge-to-edge like the bare route.diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsxindex 6c28c99468..8cdf67716c 100644--- a/client/src/components/Layout.jsx+++ b/client/src/components/Layout.jsx@@ -982,7 +982,8 @@ export default function Layout() {location.pathname.startsWith('/universe-builder') ||location.pathname.startsWith('/writers-room') ||location.pathname.startsWith('/agents') ||- location.pathname === '/shell' || location.pathname.startsWith('/shell/') ||+ location.pathname === '/shell' ||+ location.pathname.startsWith('/shell/') ||location.pathname.startsWith('/city') ||/^\/apps\/[^/]+/.test(location.pathname);return (diff --git a/client/src/pages/Shell.jsx b/client/src/pages/Shell.jsxindex b7cec729b3..2545838506 100644--- a/client/src/pages/Shell.jsx+++ b/client/src/pages/Shell.jsx@@ -482,6 +482,7 @@ export default function Shell() {// Server rejected start/attach (e.g., session limit, session not found).// No activateSession will fire to consume the intent, so reset here.pendingNavIntentRef.current = 'replace';+ const pendingTarget = pendingAttachRef.current;pendingAttachRef.current = null;if (termInstanceRef.current) {termInstanceRef.current.writeln(`\r\n\x1b[31m[Error: ${error}]\x1b[0m`);@@ -506,13 +507,21 @@ export default function Shell() {}return;}- // Active session is still alive. Only recover when the URL diverged from it —- // that's the switch-failure path (user tried to navigate to a now-dead session,- // sessionIdRef stayed on the old one; restore URL + repaint terminal). For a- // start-failure with URL already matching (e.g. hit session limit), leave the- // terminal alone so the error message stays readable.- if (urlSessionIdRef.current && urlSessionIdRef.current !== active) {- navigateRef.current(`/shell/${active}`, { replace: true });+ // Active session is still alive. Distinguish a switch failure (re-attach so the+ // terminal that attachToSession just cleared gets repainted) from a start+ // failure with an existing session (leave the terminal as-is so the error+ // message stays readable). Two switch-failure paths:+ // • Tab-click switch: pendingAttachRef pointed at a different session id+ // than `active` when the error landed. URL didn't move because+ // activateSession never fired.+ // • URL-nav switch: urlSessionIdRef diverged from active. The new path+ // points at a now-dead session.+ const switchAttempt = pendingTarget && pendingTarget !== 'new' && pendingTarget !== active;+ const urlDiverged = urlSessionIdRef.current && urlSessionIdRef.current !== active;+ if (switchAttempt || urlDiverged) {+ if (urlDiverged) {+ navigateRef.current(`/shell/${active}`, { replace: true });+ }setTimeout(() => attachToSession(active), 100);}};diff --git a/server/services/shell.js b/server/services/shell.jsindex 2b18f279f6..be2918a09d 100644--- a/server/services/shell.js+++ b/server/services/shell.js@@ -187,21 +187,28 @@ export function unsubscribeSessionList(socket) {}function broadcastSessionList() {- const list = listAllSessions();+ // Each subscriber gets a recipient-relative list so `attached` reflects "attached+ // to a different tab" from that subscriber's POV. See listAllSessions().for (const sock of sessionListSubscribers) {- sock.emit('shell:sessions', list);+ sock.emit('shell:sessions', listAllSessions(sock));}}/*** List all active sessions with metadata*- * `attached` reflects whether the session currently has a live socket bound to it.- * Clients use this to avoid auto-attaching to a session that's already driving- * another tab — pairing the shell:detached takeover with one-tab-per-session as- * the auto-pick semantics (manual attach still steals as before).+ * When `forSocket` is provided, `attached` is recipient-relative: TRUE only if the+ * session is bound to a DIFFERENT socket than the recipient. Sessions bound to the+ * recipient's own socket — or unbound — report `attached: false`. This lets clients+ * use `attached` as a "don't auto-pick this, it belongs to someone else" signal+ * without accidentally filtering out their own live sessions when they return to+ * the page (the SocketProvider singleton keeps the socket alive across navigations,+ * so sessions opened earlier in this tab stay bound to it).+ *+ * Omitting `forSocket` returns the globally-attached view (used only by callers+ * that don't have a recipient context — currently none in PortOS).*/-export function listAllSessions() {+export function listAllSessions(forSocket = null) {const sessions = [];for (const [sessionId, session] of shellSessions.entries()) {sessions.push({@@ -212,7 +219,9 @@ export function listAllSessions() {kind: session.kind,agentId: session.agentId,command: session.command,- attached: !!session.socket+ attached: forSocket+ ? (!!session.socket && session.socket !== forSocket)+ : !!session.socket});}return sessions;diff --git a/server/services/socket.js b/server/services/socket.jsindex fc08a1fdb7..c6f63eb08b 100644--- a/server/services/socket.js+++ b/server/services/socket.js@@ -461,7 +461,7 @@ export function initSocket(io) {socket.on('shell:list', () => {shellService.subscribeSessionList(socket);- socket.emit('shell:sessions', shellService.listAllSessions());+ socket.emit('shell:sessions', shellService.listAllSessions(socket));});socket.on('shell:input', (rawData) => {