fix(terminal): clear the pane directory when a read says the session has none

applyPaneExits() only applied the manager's directory when it returned a
value, so after a successful read a session that was split into several
panes, or was no longer on the socket, kept its stale cwd. The manager
already keeps its map across a failed or empty read, so the server now
applies its answer as given, undefined included, and setCwd() broadcasts
the clear once.

A blank #{pane_current_path} on a single-pane session (tmux could not read
the process cwd that tick) now carries the previous entry forward in
derivePaneCurrentPaths(), so only a split or unlisted session clears.

The server tests now drive the real TmuxManager with only the tmux read
faked. docs/api-reference.md documents SessionState.cwd.
This commit is contained in:
Aamer Akhter committed 2026-10-28 15:28:59 -04:00
1 parent 1607b1e488
commit 54c1692350
5 files changed
+146 -21

No files matched your search

+6 -4
View File
@@ -2819,10 +2819,12 @@ export class WebServer extends EventEmitter {
// for such a session anyway.
if (!muxName) continue;
// The pane's live directory rides the same read: it is the base a relative
// path printed in the terminal resolves against. A session missing from
// the read keeps its last answer (a failed read reports nothing).
const cwd = getPaneCurrentPath?.(muxName);
const cwdChanged = cwd !== undefined && session.setCwd(cwd);
// path printed in the terminal resolves against. The manager's answer is
// applied as given, `undefined` included: it keeps its map across a failed
// or empty read and carries a blank `#{pane_current_path}` forward, so an
// `undefined` here means an authoritative read listed no single directory
// for the session (split into several panes, or gone from the socket).
const cwdChanged = getPaneCurrentPath ? session.setCwd(getPaneCurrentPath(muxName)) : false;
if (session.setPaneExit(getPaneExit(muxName))) {
this.persistSessionState(session);
} else if (!cwdChanged) {