Show agent terminals created in workspace subdirectories (#1245)

Terminals were bucketed and looked up by exact cwd, so a terminal an
agent opened in a subdirectory of the workspace never appeared in the
workspace panel and its live updates were dropped — the panel only ever
queried and subscribed the exact root.

getTerminals(root) now aggregates every bucket at or below the root, and
the session controller delivers a subdirectory change to each subscribed
root above it, keyed by that root and carrying the full aggregated list.
Keying by the root with the complete set is what keeps the client's
cache replacement from dropping the terminals that live at the root.
This commit is contained in:
Mohamed Boudra
2026-05-31 12:29:05 +08:00
committed by GitHub
parent 41cb1af036
commit c8ca503cc3
5 changed files with 155 additions and 20 deletions
@@ -6,6 +6,7 @@ import {
} from "./terminal.js";
import { captureTerminalLines, type CaptureTerminalLinesResult } from "./terminal-capture.js";
import { resolve, sep, win32, posix } from "node:path";
import { isSameOrDescendantPath } from "../server/path-utils.js";
export interface TerminalListItem {
id: string;
@@ -169,7 +170,16 @@ export function createTerminalManager(): TerminalManager {
async getTerminals(cwd: string): Promise<TerminalSession[]> {
assertAbsolutePath(cwd);
return terminalsByCwd.get(cwd) ?? [];
// Terminals are bucketed by exact cwd, but an agent can open a terminal in
// a subdirectory of the workspace. A query for the workspace root must
// surface those too, so aggregate every bucket at or below `cwd`.
const sessions: TerminalSession[] = [];
for (const [bucketCwd, bucketSessions] of terminalsByCwd) {
if (isSameOrDescendantPath(cwd, bucketCwd)) {
sessions.push(...bucketSessions);
}
}
return sessions;
},
async createTerminal(options: {