Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
TypeScript
diff: the first edit opens the pane only where the layout docks it (#94653)
Alice T'Poteatb782847db9a1
diff --git a/mods/diff/README.md b/mods/diff/README.mdindex 7e660973..cc754bd3 100644--- a/mods/diff/README.md+++ b/mods/diff/README.md@@ -14,8 +14,11 @@ through Buttons that declare the engine's own actions. The pane refreshesas Claude edits and runs shell commands, and while it is open it pollsthe repository's HEAD so a commit or checkout made elsewhere shows too.The first successful edit of a session opens the pane by itself where the-terminal is wide enough (144 columns when the person never chose, 110 when-they kept it open before; a person who closed it is left alone).+layout docks it beside the transcript (the fullscreen layout, which each+drawing's `viewport` says) and the terminal is wide enough (144 columns+when the person never chose, 110 when they kept it open before; a person+who closed it is left alone); where the surface does not say, nothing+opens by itself.Under the fullscreen layout a terminal under 110 columns gets thebuilt-in's line asking for a wider one and nothing opens. Without that@@ -58,7 +61,7 @@ moved file by.| event | what the hook does || --- | --- || `session.start` | Binds the engine once and registers `/diff` (a session where another `/diff` is listed leaves the plugin idle); asks nothing of the repository, which `/diff` or the first edit pins when it comes. |-| `ui.render` of `PromptHint` | Reads the terminal's width, which decides whether the first edit opens the pane. |+| `ui.render` of `PromptHint` | Reads the terminal's width and whether its layout docks a pane, which decide whether the first edit opens the pane. || `ui.render` of `Pane` | Draws the pane: docked, the header, base line, source picker, file list and toggles over the window of hunks; inline, the dialog. || `command.run` of `diff` | Pins the repository when none is, opens or closes the pane (focused and closing on Escape without the fullscreen layout), says which, and remembers the choice. || `ui.close` of the pane | Backs out of the dialog's detail view instead of closing; else remembers the person's close as `/diff`'s. |diff --git a/mods/diff/hooks/pane-state/pane-model/pane-model.ts b/mods/diff/hooks/pane-state/pane-model/pane-model.tsindex 47964078..905a6f6a 100644--- a/mods/diff/hooks/pane-state/pane-model/pane-model.ts+++ b/mods/diff/hooks/pane-state/pane-model/pane-model.ts@@ -9,8 +9,9 @@ import type { Source } from '../source'* Everything one drawing of the pane reads.** The last good fetch, what the person picked, the bodies read so far, the- * turns and todos, how the surface seated it, whether fullscreen (once- * `/diff` said), the dialog's view, and the docked scroll in its last box.+ * turns and todos, how the surface seated it, whether the layout docks a+ * pane (once a drawing or `/diff` said), the dialog's view, and the docked+ * scroll in its last box.*/export type PaneModel = {words: Backend.BackendWordsdiff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.tsindex 54d9095c..019db9dd 100644--- a/mods/diff/hooks/register.ts+++ b/mods/diff/hooks/register.ts@@ -452,7 +452,7 @@ export function register(on: On) {const hasRoom =preference !== false &&- model.isFullscreen !== false &&+ model.isFullscreen === true &&columns !== null &&columns >= floor@@ -622,6 +622,11 @@ export function register(on: On) {on('ui.render', { component: 'PromptHint' }, ($, e, next) => {if (isOnPaneSurface(e)) {columns = e.viewport?.columns ?? columns++ model = {+ ...model,+ isFullscreen: e.viewport?.isFullscreen ?? model.isFullscreen,+ }}return next(e)diff --git a/mods/diff/tests/fixtures/hint-at.ts b/mods/diff/tests/fixtures/hint-at.tsindex 4f0e0b96..485a149f 100644--- a/mods/diff/tests/fixtures/hint-at.ts+++ b/mods/diff/tests/fixtures/hint-at.ts@@ -3,13 +3,17 @@ import type { RenderInput } from 'claude-code'import { HINT } from './hint.js'/**- * The prompt's hint on a terminal so many columns wide: drawing it is how- * the plugin learns the width.+ * The prompt's hint on a fullscreen terminal so many columns wide: drawing+ * it is how the plugin learns the width.** @param columns the terminal's width* @returns the `ui.render` input*/export const hintAt = (columns: number): RenderInput<'PromptHint'> => ({...HINT,- viewport: { columns, rows: HINT.viewport?.rows ?? columns },+ viewport: {+ columns,+ rows: HINT.viewport?.rows ?? columns,+ isFullscreen: true,+ },})diff --git a/mods/diff/tests/fixtures/hint.ts b/mods/diff/tests/fixtures/hint.tsindex 0948b81d..1205ef8c 100644--- a/mods/diff/tests/fixtures/hint.ts+++ b/mods/diff/tests/fixtures/hint.ts@@ -1,13 +1,14 @@import type { RenderInput } from 'claude-code'/**- * The prompt's hint on a 160-column terminal: drawing it is how the plugin- * learns how wide the terminal is.+ * The prompt's hint on a 160-column terminal under the fullscreen layout:+ * drawing it is how the plugin learns how wide the terminal is and whether a+ * pane docks beside the transcript there.*/export const HINT: RenderInput<'PromptHint'> = {component: 'PromptHint',surface: 'terminal',requestId: 'hint',- viewport: { columns: 160, rows: 40 },+ viewport: { columns: 160, rows: 40, isFullscreen: true },props: { isDraft: false, isWorking: false, hint: '' },}diff --git a/mods/diff/tests/fixtures/index.ts b/mods/diff/tests/fixtures/index.tsindex 27c2b669..aa751507 100644--- a/mods/diff/tests/fixtures/index.ts+++ b/mods/diff/tests/fixtures/index.ts@@ -25,6 +25,7 @@ export * from './in-repository.js'export * from './inline-pane.js'export * from './keeping.js'export * from './kind-walk-of'+export * from './main-screen-hint.js'export * from './many-file-count.js'export * from './many-files.js'export * from './mode-label-of'@@ -51,6 +52,7 @@ export * from './truncate-start'export * from './turn-diffs-of'export * from './two-files.js'export * from './typed-prompt-of.js'+export * from './unsaid-hint.js'export * from './vs-main.js'export * from './wheel-over-list.js'export * from './wheel-tick.js'diff --git a/mods/diff/tests/fixtures/main-screen-hint.ts b/mods/diff/tests/fixtures/main-screen-hint.tsnew file mode 100644index 00000000..fab2a36f--- /dev/null+++ b/mods/diff/tests/fixtures/main-screen-hint.ts@@ -0,0 +1,12 @@+import type { RenderInput } from 'claude-code'++import { HINT } from './hint.js'++/**+ * The prompt's hint on the same wide terminal on its main screen+ * (`CLAUDE_CODE_NO_FLICKER=0`), where nothing docks and a pane opens inline.+ */+export const MAIN_SCREEN_HINT: RenderInput<'PromptHint'> = {+ ...HINT,+ viewport: { columns: 160, rows: 40, isFullscreen: false },+}diff --git a/mods/diff/tests/fixtures/unsaid-hint.ts b/mods/diff/tests/fixtures/unsaid-hint.tsnew file mode 100644index 00000000..d70bcfb4--- /dev/null+++ b/mods/diff/tests/fixtures/unsaid-hint.ts@@ -0,0 +1,13 @@+import type { RenderInput } from 'claude-code'++import { HINT } from './hint.js'++/**+ * The prompt's hint from a surface that measured its size but did not say+ * whether it docks a pane: an engine that predates the word, or a remote+ * surface that has not reported it.+ */+export const UNSAID_HINT: RenderInput<'PromptHint'> = {+ ...HINT,+ viewport: { columns: 160, rows: 40 },+}diff --git a/mods/diff/tests/register.test.ts b/mods/diff/tests/register.test.tsindex db708b29..19967e14 100644--- a/mods/diff/tests/register.test.ts+++ b/mods/diff/tests/register.test.ts@@ -348,6 +348,70 @@ describe('register', () => {expect(world.opened.map(pane => pane.id)).toEqual(['diff'])})+ test('on the main screen the first edit opens nothing, and /diff still opens the dialog', async ($, on) => {+ const world = Fixtures.inRepository(on)++ on('tool.call', () => ({ result: 'edited' }))++ await $.session.start(Fixtures.SESSION)+ await $.ui.render(Fixtures.MAIN_SCREEN_HINT)++ await $.tool.call({+ tool: 'Edit',+ file_path: '/work/app.ts',+ old_string: '1',+ new_string: '2',+ })++ await world.clock.advance(Fixtures.SETTLE_MS)++ expect(world.opened, 'a pane there would be an unasked dialog').toEqual([])+ expect(world.runs, 'so nothing was asked of the repository').toEqual([])++ expect(await $.command.run(Fixtures.DIALOG_DIFF)).toEqual({})++ expect(+ world.opened[0],+ "the person's /diff opens the dialog, not dismisses one",+ ).toMatchObject({ id: 'diff', focus: true })+ })++ test('a surface that does not say whether it docks a pane opens nothing at the first edit', async ($, on) => {+ const world = Fixtures.inRepository(on)++ on('tool.call', () => ({ result: 'edited' }))++ await $.session.start(Fixtures.SESSION)+ await $.ui.render(Fixtures.UNSAID_HINT)++ await $.tool.call({+ tool: 'Edit',+ file_path: '/work/app.ts',+ old_string: '1',+ new_string: '2',+ })++ await world.clock.advance(Fixtures.SETTLE_MS)++ expect(world.opened, 'unknown is not a dock').toEqual([])++ await $.ui.render(Fixtures.HINT)++ await $.tool.call({+ tool: 'Edit',+ file_path: '/work/app.ts',+ old_string: '2',+ new_string: '3',+ })++ await world.clock.advance(Fixtures.SETTLE_MS)++ expect(+ world.opened.map(pane => pane.id),+ 'once a drawing says the layout docks, the next edit opens it',+ ).toEqual(['diff'])+ })+test('an edit that failed or was refused opens nothing', async ($, on) => {const world = Fixtures.inRepository(on)diff --git a/mods/types/claude-code.d.ts b/mods/types/claude-code.d.tsindex 9b44f347..d7d40736 100644--- a/mods/types/claude-code.d.ts+++ b/mods/types/claude-code.d.ts@@ -1,4 +1,4 @@-// Written by Claude Code 2.1.271.+// Written by Claude Code 2.1.273.// Claude Code function hooks: the plugin API's TypeScript declarations.//// EARLY ACCESS: this surface may change between releases without notice.@@ -634,9 +634,9 @@ declare module 'claude-code' {* The props of `Button`, every surface's pressable leaf: an address, a* label, the closure a press runs, and the label styles a hover overrides.*- * The terminal draws `[ label ]` (or `1: label` when `plain`), a desktop a- * native button; a click, a `hotkey`, the chord for its `action`, or Enter- * while it has the focus raises `ui.press`, whose bottom is `onPress`.+ * The terminal draws `[ label ]` (when `plain`, `1: label` or the label+ * alone), a desktop a native button; a click, a `hotkey`, the chord for its+ * `action`, or Enter under the focus raises `ui.press`, its bottom `onPress`.*/export type ButtonProps = {/**@@ -668,7 +668,11 @@ declare module 'claude-code' {action?: string;/*** Drawn without chrome: the hotkey in the accent color, a colon, the- * label (`1: Yes`), as a survey's row reads.+ * label (`1: Yes`), as a survey's row reads; no `hotkey`, the label alone.+ *+ * A one-glyph label (`'\u{1F50A}'`, a speaker) is then a control by+ * itself: the focus and the pointer still invert it, `dimColor` and `hover`+ * still apply. A desktop draws its native button either way.*/plain?: true;/**@@ -2147,7 +2151,7 @@ declare module 'claude-code' {repo: () => Promise<SessionRepo | null>;/*** Returns every surface the session draws on, each once: `terminal` under- * the REPL first, then `desktop` and `mobile` in the order they attached.+ * the REPL first, then the remote ones in the order they attached.** A session may draw on several at once (a terminal and two phones):* clients attach (`session.attach`) and detach, and a render hook still@@ -2714,9 +2718,9 @@ declare module 'claude-code' {* The element constructors each surface draws, by `e.surface`: what* `$.ui.resolve(e)` returns and a `ui.resolve` hook passes on; no globals.*- * All carry `Box`, `Text`, `Button`, `Link`, `Code`; terminal and desktop add- * `Input`, `Select`, `Client`; desktop and mobile `Svg`; terminal `Raster`.- * Narrowed on `e.surface`, that table; unnarrowed, the union; else fragments.+ * All carry `Box`, `Text`, `Button`, `Link`, `Code`; every remote surface+ * `Svg`; all but mobile `Input` and `Select`; terminal and desktop `Client`;+ * terminal `Raster`. Narrowed on `e.surface`, that table; else the union.*/export type Elements = {terminal: {@@ -2755,6 +2759,23 @@ declare module 'claude-code' {Link: ElementConstructor<LinkProps>;Code: ElementConstructor<CodeProps>;};+ /**+ * The desktop's table without `Client`: a remote `Client`'s module, presses+ * and posts (ui_client_module, ui_client_press, ui_message) name no surface.+ *+ * They are the desktop's alone today, not a limit of the editor's webview:+ * the table gains `Client` when those asks name a surface.+ */+ vscode: {+ Box: ElementConstructor<BoxProps>;+ Text: ElementConstructor<TextProps>;+ Button: ElementConstructor<ButtonProps>;+ Input: ElementConstructor<InputProps>;+ Select: ElementConstructor<SelectProps>;+ Svg: ElementConstructor<SvgProps>;+ Link: ElementConstructor<LinkProps>;+ Code: ElementConstructor<CodeProps>;+ };};/**@@ -5963,11 +5984,11 @@ declare module 'claude-code' {action?: string;/*** Drawn without chrome: the hotkey in the accent color, a colon,- * then the label (`1: Yes`), as a survey's row reads.+ * then the label (`1: Yes`); without a `hotkey`, the label alone.*- * In JSX the label may be the one string child- * (`<Button hotkey="1" plain onPress={...}>Yes</Button>`); the key- * defaults to the label.+ * The focus still inverts it. In JSX the label may be the one string+ * child (`<Button hotkey="1" plain onPress={...}>Yes</Button>`); the+ * key defaults to the label.*/plain?: true;/**@@ -6136,8 +6157,8 @@ declare module 'claude-code' {children?: undefined;} | {/**- * A vector drawing, the desktop and mobile surfaces' alone: the SVG- * markup is the element's data, drawn in an isolated box, off the page.+ * A vector drawing, the remote surfaces' alone: the SVG markup is the+ * element's data, drawn in an isolated box, off the page.** A leaf: hooks above wrap or replace it whole, nothing reaches inside;* a press other plugins should see goes on an enclosing Button. On a@@ -6624,23 +6645,25 @@ declare module 'claude-code' {/*** Where a render event's component is drawn: `terminal` is Ink, which draws- * the hook's whole tree; `desktop` (Claude Code Desktop) and `mobile` (the- * Claude mobile app) are remote surfaces that draw the tree themselves.+ * the hook's whole tree; the rest are remote surfaces drawing it themselves.*- * A remote surface asks over the wire (ui_render), draws with the props the- * hook handed core and draws the tree where it has a slot for it. Each- * surface's ask is its own evaluation, since a tree may hold an element only- * some surfaces draw (Svg, Client).+ * `desktop` is Claude Code Desktop, `mobile` the Claude mobile app, `vscode`+ * Claude Code for VS Code. A remote surface asks over the wire (ui_render),+ * draws with the props the hook handed core, and draws the tree where it has+ * a slot for it.+ *+ * Each surface's ask is its own evaluation, since a tree may hold an element+ * only some surfaces draw (Svg, Client).*/- export type RenderSurface = 'terminal' | 'desktop' | 'mobile';+ export type RenderSurface = 'terminal' | 'desktop' | 'mobile' | 'vscode';/*** The size of what a surface draws into, in character cells of the- * surface's monospace metric: on the terminal, the conversation's columns and- * screen rows; on a remote surface, the pane's width and height divided by the- * advance and line height of its code font. A pixel-sized companion- * arrives with the first element that lays out in pixels; until then- * every element on every surface is cell-based, and so is this.+ * surface's monospace metric, and whether its layout docks a pane.+ *+ * On the terminal, the conversation's columns and screen rows; on a remote+ * surface, the pane's width and height over the advance and line height of+ * its code font. Cell-based until the first element lays out in pixels.*/export type RenderViewport = {/**@@ -6650,10 +6673,24 @@ declare module 'claude-code' {columns: number;/*** Cells down the whole surface, not the room left for this component.+ ** Informational: a change of height alone re-draws nothing and keys no* new evaluation, so a hook reads it as of the last width or props change.*/rows: number;+ /**+ * Whether this surface docks a pane beside the transcript, so a pane a+ * plugin opens unasked is a sidebar, not a takeover; absent is unknown.+ *+ * What `command.run`'s `presentation.isFullscreen` says. The terminal always+ * says: `true` fullscreen, `false` on the main screen, fixed per session; a+ * remote surface once its client reports it with the size, absent before.+ *+ * @remarks The desktop and VS Code report it once they place panes; the+ * mobile app, which has no dock, `false`. A change re-draws the sites.+ * @example if (e.viewport?.isFullscreen === true) void $.ui.open({ id })+ */+ isFullscreen?: boolean;};/**@@ -7681,13 +7718,12 @@ declare module 'claude-code' {};/**- * The props of `Svg`, the desktop and mobile surfaces' vector leaf: the- * markup is the element's data, as a string is a Text's, drawn isolated.+ * The props of `Svg`, the remote surfaces' vector leaf: the markup is the+ * element's data, as a string is a Text's, drawn isolated.** A leaf: no children. The surface never lets the markup reach the page- * (the engine bounds it; the desktop draws it as an image, or in a- * sandboxed frame when `isInteractive`; the mobile app in a sandboxed web- * view).+ * (the engine bounds it; the desktop and the editor draw it as an image, or+ * in a sandboxed frame when `isInteractive`; the mobile app in a web view).*/export type SvgProps = {/**