Repository navigation
fix(ui): keep a pane's lens when an agent starts or exits in it #755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
|
|
||
| import { defaultLens, PaneLenses } from "./paneLens.ts"; | ||
|
|
||
| describe("defaultLens", () => { | ||
| it("follows Settings: chat for an agent (or one not known yet), the terminal for a shell", () => { | ||
| expect(defaultLens(true, "chat", false)).toBe("chat"); | ||
| expect(defaultLens(null, "chat", false)).toBe("chat"); | ||
| expect(defaultLens(false, "chat", false)).toBe("terminal"); | ||
| expect(defaultLens(true, "terminal", true)).toBe("terminal"); | ||
| expect(defaultLens(true, "auto", false)).toBe("terminal"); | ||
| expect(defaultLens(true, "auto", true)).toBe("chat"); | ||
| expect(defaultLens(false, "auto", true)).toBe("terminal"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("PaneLenses", () => { | ||
| it("keeps a shell's terminal when an agent starts in it, with the default view on chat", () => { | ||
| const lenses = new PaneLenses("chat"); | ||
| expect(lenses.of("local/w1:p2", false, false)).toBe("terminal"); | ||
| // claude started in the split's shell: the pane in use stays on its terminal | ||
| expect(lenses.of("local/w1:p2", true, false)).toBe("terminal"); | ||
| }); | ||
|
|
||
| it("keeps an agent pane's chat when its agent exits", () => { | ||
| const lenses = new PaneLenses("chat"); | ||
| expect(lenses.of("local/w1:p1", true, false)).toBe("chat"); | ||
| expect(lenses.of("local/w1:p1", false, false)).toBe("chat"); | ||
| }); | ||
|
|
||
| it("settles nothing while the snapshot does not know the pane yet", () => { | ||
| const lenses = new PaneLenses("chat"); | ||
| expect(lenses.of("local/w1:p3", null, false)).toBe("chat"); | ||
| expect(lenses.of("local/w1:p3", false, false)).toBe("terminal"); | ||
| expect(lenses.of("local/w1:p3", true, false)).toBe("terminal"); | ||
| }); | ||
|
|
||
| it("gives a pane this page started an agent in an agent's lens, even if a snapshot first shows its shell", () => { | ||
| const lenses = new PaneLenses("chat"); | ||
| lenses.startedAgent("local/w2:p1", false); | ||
| expect(lenses.of("local/w2:p1", false, false)).toBe("chat"); | ||
| }); | ||
|
|
||
| it("keeps a moved pane's lens under the new id herdr gives it", () => { | ||
| const lenses = new PaneLenses("chat"); | ||
| expect(lenses.of("local/w1:p2", false, false)).toBe("terminal"); | ||
| lenses.move("local/w1:p2", "local/w2:p1"); | ||
| expect(lenses.of("local/w2:p1", true, false)).toBe("terminal"); | ||
| }); | ||
|
|
||
| it("keeps each pane apart", () => { | ||
| const lenses = new PaneLenses("chat"); | ||
| expect(lenses.of("local/w1:p1", true, false)).toBe("chat"); | ||
| expect(lenses.of("remote/w1:p1", false, false)).toBe("terminal"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import type { PaneView } from "./actions.ts"; | ||
| import type { DefaultView } from "./settings.ts"; | ||
|
|
||
| /** | ||
| * The lens a pane opens in when nobody picked one for it: Settings' default for every pane | ||
| * (chat needs an agent, a shell has no conversation to show), or, on Auto, the chat for an | ||
| * agent pane on a touch screen. Until the snapshot says whether the pane has an agent (null), | ||
| * it counts as one. | ||
| */ | ||
| export function defaultLens(hasAgent: boolean | null, defaultView: DefaultView, coarse: boolean): PaneView { | ||
| if (defaultView === "chat") return hasAgent !== false ? "chat" : "terminal"; | ||
| if (defaultView === "terminal") return "terminal"; | ||
| return hasAgent !== false && coarse ? "chat" : "terminal"; | ||
| } | ||
|
|
||
| /** | ||
| * The default lens of each pane this page has shown, kept once the snapshot said whether the | ||
| * pane has an agent. An agent that starts in a shell, or one that exits, leaves the pane on the | ||
| * lens it was showing: re-deriving it turned a split's terminal into a chat while it was in use. | ||
| * A new Settings default starts a new map (App), and a lens picked by hand is stored apart and | ||
| * always wins. | ||
| */ | ||
| export class PaneLenses { | ||
| private readonly settled = new Map<string, PaneView>(); | ||
| constructor(private readonly defaultView: DefaultView) {} | ||
|
|
||
| of(key: string, hasAgent: boolean | null, coarse: boolean): PaneView { | ||
| const settled = this.settled.get(key); | ||
| if (settled !== undefined) return settled; | ||
| const lens = defaultLens(hasAgent, this.defaultView, coarse); | ||
| if (hasAgent !== null) this.settled.set(key, lens); | ||
| return lens; | ||
| } | ||
|
|
||
| /** A pane herdr gave a new id (a move to another workspace) keeps the lens it was showing. */ | ||
| move(from: string, to: string): void { | ||
| const settled = this.settled.get(from); | ||
| if (settled === undefined) return; | ||
| this.settled.delete(from); | ||
| this.settled.set(to, settled); | ||
| } | ||
|
|
||
| /** A pane this page started an agent in: its lens is an agent's, whatever the first snapshot says. */ | ||
| startedAgent(key: string, coarse: boolean): void { | ||
| this.settled.set(key, defaultLens(true, this.defaultView, coarse)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.