Skip to content

Start the auto-spawned terminal in the departing pane's cwd - #698

Draft
nedtwigg wants to merge 4 commits into
mainfrom
preserve-dir
Draft

nedtwigg wants to merge 4 commits into
mainfrom
preserve-dir

Conversation

@nedtwigg

Copy link
Copy Markdown
Member

When the last pane in a Workspace is killed or minimized, the auto-spawned replacement now starts in that pane's local cwd, the same way a split does. It used to start in the shell's default directory.

  • Refill (lib/src/components/Wall.tsx): the store subscription already diffs leaf ids, so a commit that empties the tree hands the departed id to refillEmptyTree, which reads that pane's cwd. A remote cwd (OSC 7 over ssh) is not inherited.
  • Kill ordering: the kill finalizer now disposes the Session after removeLeaf, so the pane state holding the cwd is still there when the refill reads it. The subscribers that run synchronously on that commit are the Wall's own effect, a timer-scheduled persistence save, and awaitWallEmpty (which resolves through a promise); none of them reads the departed Session.
  • Shared helpers: getInheritableCwd(id) in terminal-state-store.ts replaces the four inline copies of the local-cwd rule (manual split, dor split/ensure, Helper terminals, refill); stageDefaultShell in Wall.tsx replaces the three copies of the default-shell staging.
  • Spec: docs/specs/layout.md → "Auto-spawn refill".

Test: Wall.test.tsx → "starts the refill after Minimize/Kill of the last pane in that pane's cwd". The Kill case fails if the old dispose-before-remove order comes back.

🤖 Generated with Claude Code

nedtwigg and others added 3 commits September 17, 2026 18:06
Minimizing the last terminal in a Workspace auto-spawns a replacement; it now
inherits the minimized Surface's local cwd, as a split does. The local-cwd
derivation shared by splits, dor split/ensure, and the refill moves into one
helper.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A kill disposes the Session's state before removing the leaf, so the cwd is
read first and handed to the refill across the removal commit, the same way
minimize hands it across doorLeaf.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The store subscription already knows which leaf a tree-emptying commit took,
so the refill reads that pane's cwd itself; a kill now disposes the Session
after removing its leaf so the state is still there to read. This drops the
ref handed across both commits. The local-cwd rule moves into the terminal
state store, shared with Helper terminals, and the default-shell staging the
refill and both split paths repeated becomes one helper.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 18, 2026

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 86f6329
Status: ✅  Deploy successful!
Preview URL: https://d9e529af.mouseterm.pages.dev
Branch Preview URL: https://preserve-dir.mouseterm.pages.dev

View logs

@dormouse-bot dormouse-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback on work in progress, not a merge verdict — marking the PR ready requests the full review.

docs/specs/layout.md → "Split cwd inheritance" now names a read that no longer happens. That paragraph says the source cwd is read from getTerminalPaneState(sourceId).cwd and then states the never-inherit-a-remote-cwd rule; both moved into getInheritableCwd, which reads paneStates directly and is now the single owner of that rule across all four split sites plus the refill. Per AGENTS.md → "Specs" ("When code covered by a spec changes, change the spec"), the sentence should name getInheritableCwd in lib/src/lib/terminal-state-store.ts instead. The substitution is word-neutral, so layout.md's budget is unaffected. The line sits outside this diff's hunks, so it is prose here rather than a suggestion — I can push the edit once the PR is out of draft if you'd rather not hand-apply it.

One more point inline, on helper-terminal.ts.

Comment thread lib/src/lib/helper-terminal.ts Outdated
The Helper's spawn already dropped a remote parent cwd, but the launched
command's record still took the unfiltered ssh path, so the helper claimed a
local cwd it was not in. Both now use the same inheritable cwd. The layout spec
names getInheritableCwd as the split's cwd read.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@nedtwigg

Copy link
Copy Markdown
Member Author

Review-body finding fixed in 86f6329: docs/specs/layout.md → "Split cwd inheritance" now names getInheritableCwd(sourceId) as the read (word-neutral; spec lint passes at the existing budget). git grep finds no other spec or comment naming the old getTerminalPaneState(…).cwd read for cwd inheritance.

@dormouse-bot

Copy link
Copy Markdown
Collaborator

Both confirmed against 86f6329 — thanks.

The spec line now names getInheritableCwd(sourceId) with the never-inherit-a-remote-cwd rule still stated beside it, and git grep getTerminalPaneState -- docs/ is empty, so nothing else names the old read.

On the helper: worth recording where the remote case lands downstream, since that was the concern behind the finding. seedLaunchedCommand only pushes a cwd event when it gets a path, so a remote parent now leaves the helper with no recorded cwd at all. In TerminalContext.tsx that makes mismatch false (it requires both cwds) and instead surfaces the "Directory comparison unavailable" warning until the helper reports its own OSC 7. That is the honest reading — the helper really is in the host default and has not said so yet — rather than the false mismatch the cwdFromManualPath seed produced.

I did not run the suite locally; Build & Test was still in flight at that head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants