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 (agy): refuse a cd against a live agent run instead of typing it in
[._.]/ Adam Eivyb008718ee95e
diff --git a/server/services/shell.js b/server/services/shell.jsindex 117dd09933..d5a91bf16e 100644--- a/server/services/shell.js+++ b/server/services/shell.js@@ -590,11 +590,17 @@ export function submitToSession(sessionId, line) {** @param {string} sessionId* @param {string} dirPath- * @returns {boolean} false when the session is unknown+ * @returns {boolean} false when the session is unknown or is an external TUI run*/export function changeSessionDirectory(sessionId, dirPath) {const session = shellSessions.get(sessionId);if (!session) return false;+ // An external (TUI-run) session has no shell reading that line: the bytes land in+ // the agent as typed text and the trailing Enter posts them as a message. Refuse+ // rather than type into someone else's run — socket.js turns this into an error the+ // Shell page shows. Its `cwd` also stays pinned to the repo the RUN was spawned in,+ // which is what workspaceContext groups runs by.+ if (session.external) return false;if (!submitToSession(sessionId, buildCdCommand(dirPath, session.shell))) return false;// Track the cd optimistically so the Shell tab label and the Workspace Contexts// widget follow the session instead of staying pinned to its spawn directory.@@ -602,13 +608,8 @@ export function changeSessionDirectory(sessionId, dirPath) {// come from the managed-apps list, so they exist. Asking the PTY for its REAL cwd// would need a per-platform probe plus a round-trip, which is not worth it for a// label; a rejected path just leaves the label wrong until the next cd.- // …but only for an interactive shell. An external (TUI-run) session has no shell- // reading that line — the bytes land in the agent as typed text — and its `cwd` is- // the repo the RUN was spawned in, which is what workspaceContext groups runs by.- if (!session.external) {- session.cwd = dirPath;- broadcastSessionList();- }+ session.cwd = dirPath;+ broadcastSessionList();return true;}diff --git a/server/services/shell.test.js b/server/services/shell.test.jsindex 6d85a4e5b5..8d32d0800a 100644--- a/server/services/shell.test.js+++ b/server/services/shell.test.js@@ -412,14 +412,15 @@ describe('changeSessionDirectory', () => {shell.unsubscribeSessionList(observer);});- it('leaves an external TUI run cwd pinned to the repo it was spawned in', () => {- // A cd typed at an agent TUI is text the agent reads, not a shell directory- // change — and workspaceContext groups runs by the repo they were spawned in.+ it('refuses an external TUI run rather than typing the cd into the agent', () => {+ // The run's PTY has no shell reading that line — it would post as a message —+ // and workspaceContext groups runs by the repo they were spawned in.const sock = makeSocket('sock-ext');const pty = makeFakePty();shell.registerExternalSession('run-1', pty, { cwd: '/home/user/example', label: 'Claude Code TUI' });- expect(shell.changeSessionDirectory('run-1', '/home/user/example-app')).toBe(true);+ expect(shell.changeSessionDirectory('run-1', '/home/user/example-app')).toBe(false);+ expect(pty.write).not.toHaveBeenCalled();expect(shell.listAllSessions(sock).find(s => s.sessionId === 'run-1').cwd).toBe('/home/user/example');});diff --git a/server/services/socket.js b/server/services/socket.jsindex 2bc0128633..a3ce087088 100644--- a/server/services/socket.js+++ b/server/services/socket.js@@ -684,7 +684,13 @@ export function initSocket(io) {const validated = validateSocketData(shellCdSchema, rawData, socket, 'shell:cd');if (!validated) return;if (!shellService.changeSessionDirectory(validated.sessionId, validated.path)) {- socket.emit('shell:error', { sessionId: validated.sessionId, error: 'Session not found' });+ // Two different refusals: the session is gone, or it is a live agent run+ // whose PTY would read the `cd` as a typed message rather than a command.+ const isRun = shellService.getSession(validated.sessionId)?.external;+ socket.emit('shell:error', {+ sessionId: validated.sessionId,+ error: isRun ? 'This is a live agent run, not a shell — cd is unavailable here' : 'Session not found'+ });}});diff --git a/server/services/socket.test.js b/server/services/socket.test.jsindex 8d8574f9f7..2feb4b68df 100644--- a/server/services/socket.test.js+++ b/server/services/socket.test.js@@ -38,6 +38,7 @@ vi.mock('./shell.js', () => ({listAllSessions: vi.fn(() => []),writeToSession: vi.fn(),changeSessionDirectory: vi.fn(() => true),+ getSession: vi.fn(() => null),resizeSession: vi.fn(),killSession: vi.fn(),unsubscribeSessionList: vi.fn(),@@ -399,6 +400,19 @@ describe('socket.js — initSocket', () => {expect(err[1].sessionId).toBe('gone');});+ it('shell:cd says WHY when the target is a live agent run, not a dead session', () => {+ const socket = makeSocket('shell-cd-run');+ io.connect(socket);+ shellService.changeSessionDirectory.mockReturnValueOnce(false);+ shellService.getSession.mockReturnValueOnce({ external: true });++ socket.handlers['shell:cd']({ sessionId: 'run-1', path: '/home/user/example-app' });++ const err = socket.emitted.find(([ev]) => ev === 'shell:error');+ expect(err[1].sessionId).toBe('run-1');+ expect(err[1].error).toMatch(/live agent run/i);+ });+// ===========================================================================// shell:attach claim semantics — auto-pick paths must not displace another tab// ===========================================================================