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
mods/diff: the docked pane draws as the built-in panel does (every file's hunks under an eight-row list, rows that scroll to their file, no focus or close mark of its own, /diff's transcript line) and the inline pane as its dialog
poteat38dc1e4b6953
diff --git a/mods/diff/README.md b/mods/diff/README.mdindex d2330afe..e7f297e1 100644--- a/mods/diff/README.md+++ b/mods/diff/README.md@@ -1,16 +1,19 @@# diffThe diff pane as a plugin: `/diff` opens the session's uncommitted changes-beside the transcript, one row per changed file and the selected file's-hunks beneath, and closes it again. The pane refreshes as Claude edits,-runs shell commands and finishes turns, and while it is open it polls the-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). On a-terminal under 110 columns `/diff` answers with the built-in's line asking-for a wider terminal and opens nothing; a pane opened wider that the surface-then seats inline shows only that line. A file's+beside the transcript, one row per changed file and every file's hunks+beneath, a row's click scrolling to its file, and closes it again; each+toggle leaves `Diff panel shown` or `Diff panel hidden` in the transcript.+The pane refreshes as Claude edits, runs shell commands and finishes turns,+and while it is open it polls the 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). On a terminal under 110 columns `/diff` answers with the+built-in's line asking for a wider terminal and opens nothing; a pane the+surface seats inline on a terminal that wide shows only that line, and on a+wider one (a session without the fullscreen layout) the built-in dialog's+layout: the rows round the selected file and that file's hunks. A file'sask button arms that file: its hunks ride the next prompt as context, once.The pane compares the working tree against HEAD, split at the session's@@ -18,9 +21,10 @@ start (the default), against HEAD plainly, or against the merge-base withthe default branch; the choice is kept per repository in the plugin'sstore. A second picker shows one earlier turn's edits instead of theworking tree, read from the session's messages. Files that changed before-the session started, and noise (lockfiles, generated and test files), are-listed apart and folded until asked for. Outside a git repository `/diff`-says so and does nothing else.+the session started (by their timestamp, among the paths already dirty at+the start), and noise (lockfiles, generated and test files), are listed+apart and folded until asked for; a rename lists as git prints it. Outside+a git repository `/diff` says so and does nothing else.`hooks/register.ts` is the module; everything under `hooks/` is its parts.@@ -30,8 +34,9 @@ says so and does nothing else.| --- | --- || `session.start` | Binds the engine once, registers `/diff` (a session where another `/diff` is listed leaves the plugin idle), and pins the repository. || `ui.render` of `PromptHint` | Reads the terminal's width, which decides whether the first edit opens the pane. |-| `ui.render` of `Pane` | Draws the pane: header, the file list, the toggles, the base and source pickers, and the selected file's hunks. |-| `command.run` of `diff` | Opens or closes the pane and remembers the choice. |+| `ui.render` of `Pane` | Draws the pane: header, the base and source pickers, the file list, the toggles, and the files' hunks. |+| `command.run` of `diff` | Opens or closes the pane, says which, and remembers the choice. |+| `ui.close` of the pane | Remembers the person's close as `/diff`'s. || `command.run` of `clear`, `resume` | Closes the pane and forgets the session's state. || `tool.call` of `Edit`, `Write`, `NotebookEdit` | After the edit, refreshes an open pane; the session's first successful edit opens it. || `tool.call` of `Bash`, `PowerShell` | After the command, refreshes an open pane. |@@ -40,10 +45,10 @@ says so and does nothing else.## What it calls on `$`-`clock.after`, `clock.every`, `clock.now`, `clock.sleep`, `command.register`,-`fs.list`, `fs.read`, `fs.stat`, `process.run` (git, read-only), `session.messages`,+`clock.after`, `clock.every`, `clock.now`, `command.register`, `fs.list`,+`fs.read`, `fs.stat`, `process.run` (git, read-only), `session.messages`,`store.get`, `store.set`, `telemetry.log`, `telemetry.mark`, `ui.close`,-`ui.invalidate`, `ui.log`, `ui.open`, `ui.resolve`, `ui.status`.+`ui.invalidate`, `ui.log`, `ui.open`, `ui.resolve`, `ui.scroll`, `ui.status`.`$.telemetry` is the telemetry plugin's noun; where it is absent the rowsare dropped and nothing else changes.diff --git a/mods/diff/hooks/drawn-files-of/drawn-files-of.ts b/mods/diff/hooks/drawn-files-of/drawn-files-of.tsnew file mode 100644index 00000000..3944253c--- /dev/null+++ b/mods/diff/hooks/drawn-files-of/drawn-files-of.ts@@ -0,0 +1,31 @@+import type Git from '../git'+import Limits from '../limits'+import PaneState from '../pane-state'++/**+ * The files whose bodies the pane draws now, in drawing order: the listed+ * session rows, then the pre-session rows while their section is open.+ *+ * Past PRE_SESSION_BODY_CAP pre-session files only their legend shows, so+ * none of their bodies is wanted.+ *+ * @param model the pane's state: its fetch and its two toggles+ * @returns the rows, none without a fetch+ */+export function drawnFilesOf(+ model: Pick<+ PaneState.PaneModel,+ 'data' | 'isNoiseShown' | 'isPreSessionShown'+ >,+): readonly Git.FileStat[] {+ const partition = PaneState.partitionOf(+ model.data?.files ?? [],+ model.isNoiseShown ? 'shown' : 'hidden',+ )++ const isBodied =+ model.isPreSessionShown &&+ partition.preSession.length <= Limits.PRE_SESSION_BODY_CAP++ return [...partition.shown, ...(isBodied ? partition.preSession : [])]+}diff --git a/mods/diff/hooks/drawn-files-of/index.ts b/mods/diff/hooks/drawn-files-of/index.tsnew file mode 100644index 00000000..8f9a4dfb--- /dev/null+++ b/mods/diff/hooks/drawn-files-of/index.ts@@ -0,0 +1,3 @@+export * from './drawn-files-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/host/host.ts b/mods/diff/hooks/host/host.tsindex a4f918b4..f58e451b 100644--- a/mods/diff/hooks/host/host.ts+++ b/mods/diff/hooks/host/host.ts@@ -9,6 +9,7 @@ import type {ProcessRunResult,SessionMessage,TimerCall,+ UiScrollResult,} from 'claude-code'/**@@ -31,11 +32,6 @@ export type Host = {*/every: TimerCall- /**- * `$.clock.sleep`, no signal.- */- sleep: (ms: number) => Promise<void>-/*** `$.process.run`.*/@@ -99,6 +95,12 @@ export type Host = {*/closePane: (pane: PaneCloseArgs) => Promise<void>+ /**+ * `$.ui.scroll` to one of the pane's own keyed elements, its top at the+ * window's top.+ */+ scrollTo: (key: string) => Promise<UiScrollResult>+/*** `$.command.register`; rejects while another `/diff` is listed.*/diff --git a/mods/diff/hooks/index.ts b/mods/diff/hooks/index.tsindex 42177844..66550f5f 100644--- a/mods/diff/hooks/index.ts+++ b/mods/diff/hooks/index.ts@@ -4,12 +4,15 @@ export * from './backend'export * from './classify'export * from './command-spec'export * from './count-of'+export * from './drawn-files-of'export * from './entry-kinds-of'export * from './git'export * from './host'export * from './is-on-pane-surface'export * from './is-record'+export * from './kept-of'export * from './limits'+export * from './map-limited'export * from './message-of'export * from './mtime-of'export * from './names'diff --git a/mods/diff/hooks/kept-of/index.ts b/mods/diff/hooks/kept-of/index.tsnew file mode 100644index 00000000..679992a3--- /dev/null+++ b/mods/diff/hooks/kept-of/index.ts@@ -0,0 +1,3 @@+export * from './kept-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/kept-of/kept-of.ts b/mods/diff/hooks/kept-of/kept-of.tsnew file mode 100644index 00000000..e5743b5e--- /dev/null+++ b/mods/diff/hooks/kept-of/kept-of.ts@@ -0,0 +1,9 @@+/**+ * The items that are there: nulls dropped, so a part may answer null for+ * "nothing here" and the whole lists what is left.+ *+ * @param items values or nulls+ * @returns the values, in order+ */+export const keptOf = <T>(items: readonly (T | null)[]): T[] =>+ items.filter((item): item is T => item !== null)diff --git a/mods/diff/hooks/limits/sizes/index.ts b/mods/diff/hooks/limits/sizes/index.tsindex 4890ab60..a43c2f83 100644--- a/mods/diff/hooks/limits/sizes/index.ts+++ b/mods/diff/hooks/limits/sizes/index.ts@@ -4,7 +4,7 @@ export * from './max-files-for-details.js'export * from './max-lines-per-file.js'export * from './max-listed-directories.js'export * from './max-untracked-probes.js'-export * from './pane-top-pad-rows.js'+export * from './pane'export * from './prompt-context-max-chars.js'export * as default from '.'diff --git a/mods/diff/hooks/limits/sizes/pane/body-fetch-concurrency.ts b/mods/diff/hooks/limits/sizes/pane/body-fetch-concurrency.tsnew file mode 100644index 00000000..fe43ae42--- /dev/null+++ b/mods/diff/hooks/limits/sizes/pane/body-fetch-concurrency.ts@@ -0,0 +1,5 @@+/**+ * How many files' hunks are read from the backend at once while the pane+ * loads its bodies.+ */+export const BODY_FETCH_CONCURRENCY = 6diff --git a/mods/diff/hooks/limits/sizes/pane/index.ts b/mods/diff/hooks/limits/sizes/pane/index.tsnew file mode 100644index 00000000..a7d56af7--- /dev/null+++ b/mods/diff/hooks/limits/sizes/pane/index.ts@@ -0,0 +1,7 @@+export * from './body-fetch-concurrency.js'+export * from './max-dialog-rows.js'+export * from './max-summary-rows.js'+export * from './pane-top-pad-rows.js'+export * from './pre-session-body-cap.js'++export * as default from '.'diff --git a/mods/diff/hooks/limits/sizes/pane/max-dialog-rows.ts b/mods/diff/hooks/limits/sizes/pane/max-dialog-rows.tsnew file mode 100644index 00000000..c132ae8c--- /dev/null+++ b/mods/diff/hooks/limits/sizes/pane/max-dialog-rows.ts@@ -0,0 +1,5 @@+/**+ * How many file rows the inline pane's list shows at once, around the+ * selected one (the built-in dialog's window).+ */+export const MAX_DIALOG_ROWS = 5diff --git a/mods/diff/hooks/limits/sizes/pane/max-summary-rows.ts b/mods/diff/hooks/limits/sizes/pane/max-summary-rows.tsnew file mode 100644index 00000000..bc454761--- /dev/null+++ b/mods/diff/hooks/limits/sizes/pane/max-summary-rows.ts@@ -0,0 +1,5 @@+/**+ * How many file rows the docked pane's list shows at once (the built-in+ * panel's window); the rest are counted on a dim row under them.+ */+export const MAX_SUMMARY_ROWS = 8diff --git a/mods/diff/hooks/limits/sizes/pane-top-pad-rows.ts b/mods/diff/hooks/limits/sizes/pane/pane-top-pad-rows.tssimilarity index 100%rename from mods/diff/hooks/limits/sizes/pane-top-pad-rows.tsrename to mods/diff/hooks/limits/sizes/pane/pane-top-pad-rows.tsdiff --git a/mods/diff/hooks/limits/sizes/pane/pre-session-body-cap.ts b/mods/diff/hooks/limits/sizes/pane/pre-session-body-cap.tsnew file mode 100644index 00000000..e46db0d5--- /dev/null+++ b/mods/diff/hooks/limits/sizes/pane/pre-session-body-cap.ts@@ -0,0 +1,5 @@+/**+ * How many pre-session files get their bodies drawn once that section is+ * open (the built-in panel's cap); past it only their legend is listed.+ */+export const PRE_SESSION_BODY_CAP = 20diff --git a/mods/diff/hooks/limits/timing/index.ts b/mods/diff/hooks/limits/timing/index.tsindex 07008be6..6a9c4d91 100644--- a/mods/diff/hooks/limits/timing/index.ts+++ b/mods/diff/hooks/limits/timing/index.ts@@ -1,6 +1,5 @@export * from './git-timeout-ms.js'export * from './head-poll-ms.js'-export * from './open-probe-ms.js'export * from './redraw-coalesce-ms.js'export * from './refresh-debounce-ms.js'diff --git a/mods/diff/hooks/limits/timing/open-probe-ms.ts b/mods/diff/hooks/limits/timing/open-probe-ms.tsdeleted file mode 100644index b25647da..00000000--- a/mods/diff/hooks/limits/timing/open-probe-ms.ts+++ /dev/null@@ -1,5 +0,0 @@-/**- * How long `/diff` waits for the pane to draw after an invalidate before it- * takes the pane as closed by the person and opens it again.- */-export const OPEN_PROBE_MS = 120diff --git a/mods/diff/hooks/map-limited/index.ts b/mods/diff/hooks/map-limited/index.tsnew file mode 100644index 00000000..45383b7e--- /dev/null+++ b/mods/diff/hooks/map-limited/index.ts@@ -0,0 +1,3 @@+export * from './map-limited.js'++export * as default from '.'diff --git a/mods/diff/hooks/map-limited/map-limited.ts b/mods/diff/hooks/map-limited/map-limited.tsnew file mode 100644index 00000000..c8d11b71--- /dev/null+++ b/mods/diff/hooks/map-limited/map-limited.ts@@ -0,0 +1,30 @@+/**+ * Maps every item through an async function, a bounded number of them in+ * flight at once, and resolves to the results in the items' order.+ *+ * @param items the inputs+ * @param limit how many may run at once, at least one+ * @param fn the work for one item+ * @returns the results, in order+ */+export async function mapLimited<T, R>(+ items: readonly T[],+ limit: number,+ fn: (item: T) => Promise<R>,+): Promise<R[]> {+ const results: R[] = []++ let next = 0++ async function worker(): Promise<void> {+ for (let at = next++; at < items.length; at = next++) {+ results[at] = await fn(items[at] as T)+ }+ }++ await Promise.all(+ Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, worker),+ )++ return results+}diff --git a/mods/diff/hooks/names/focused-pane/focused-pane.ts b/mods/diff/hooks/names/focused-pane/focused-pane.tsdeleted file mode 100644index 32f8533c..00000000--- a/mods/diff/hooks/names/focused-pane/focused-pane.ts+++ /dev/null@@ -1,9 +0,0 @@-import type { PaneOpenArgs } from 'claude-code'--/**- * The part of `$.ui.open`'s argument that asks the surface for the- * person's keyboard: what `/diff` adds and the first-edit open leaves out.- */-export const FOCUSED_PANE: Pick<PaneOpenArgs, 'focus'> = Object.freeze({- focus: true,-})diff --git a/mods/diff/hooks/names/focused-pane/index.ts b/mods/diff/hooks/names/focused-pane/index.tsdeleted file mode 100644index d5e82936..00000000--- a/mods/diff/hooks/names/focused-pane/index.ts+++ /dev/null@@ -1,3 +0,0 @@-export * from './focused-pane.js'--export * as default from '.'diff --git a/mods/diff/hooks/names/index.ts b/mods/diff/hooks/names/index.tsindex bcf08ba9..7192f90e 100644--- a/mods/diff/hooks/names/index.ts+++ b/mods/diff/hooks/names/index.ts@@ -1,6 +1,5 @@export * from './command-description.js'export * from './command-name.js'-export * from './focused-pane'export * from './keys'export * from './pane-id.js'export * from './pane-title.js'diff --git a/mods/diff/hooks/names/texts/index.ts b/mods/diff/hooks/names/texts/index.tsindex 2059ea0e..b161b67c 100644--- a/mods/diff/hooks/names/texts/index.ts+++ b/mods/diff/hooks/names/texts/index.ts@@ -1,6 +1,7 @@export * from './builtin-holds-pattern.js'export * from './git-unanswered-text.js'export * from './not-in-repository-text.js'+export * from './panel-toggle'export * from './register-failed-text-of.js'export * from './resize-terminal-text.js'export * from './untracked-withheld-text-of.js'diff --git a/mods/diff/hooks/names/texts/panel-toggle/index.ts b/mods/diff/hooks/names/texts/panel-toggle/index.tsnew file mode 100644index 00000000..2e370937--- /dev/null+++ b/mods/diff/hooks/names/texts/panel-toggle/index.ts@@ -0,0 +1,4 @@+export * from './panel-hidden-text.js'+export * from './panel-shown-text.js'++export * as default from '.'diff --git a/mods/diff/hooks/names/texts/panel-toggle/panel-hidden-text.ts b/mods/diff/hooks/names/texts/panel-toggle/panel-hidden-text.tsnew file mode 100644index 00000000..85bb37e2--- /dev/null+++ b/mods/diff/hooks/names/texts/panel-toggle/panel-hidden-text.ts@@ -0,0 +1,5 @@+/**+ * `/diff`'s transcript line once it closed the pane, worded as the built-in+ * words its own.+ */+export const PANEL_HIDDEN_TEXT = 'Diff panel hidden'diff --git a/mods/diff/hooks/names/texts/panel-toggle/panel-shown-text.ts b/mods/diff/hooks/names/texts/panel-toggle/panel-shown-text.tsnew file mode 100644index 00000000..2375f17f--- /dev/null+++ b/mods/diff/hooks/names/texts/panel-toggle/panel-shown-text.ts@@ -0,0 +1,5 @@+/**+ * `/diff`'s transcript line once it opened the pane, worded as the built-in+ * words its own.+ */+export const PANEL_SHOWN_TEXT = 'Diff panel shown'diff --git a/mods/diff/hooks/names/texts/untracked-withheld-text-of.ts b/mods/diff/hooks/names/texts/untracked-withheld-text-of.tsindex 588934e7..8c1d5e31 100644--- a/mods/diff/hooks/names/texts/untracked-withheld-text-of.ts+++ b/mods/diff/hooks/names/texts/untracked-withheld-text-of.ts@@ -1,14 +1,14 @@-import type Backend from '../../backend'+import type PaneState from '../../pane-state'/*** The pane's word for a fetch whose untracked listing the backend did not* give whole: the tracked rows stand, the new files are not counted.*- * @param words the backend's words, naming the program that lists them+ * @param model the pane's state, its words naming the program that lists them* @returns the note*/export const untrackedWithheldTextOf = (- words: Pick<Backend.BackendWords, 'lister'>,+ model: Pick<PaneState.PaneModel, 'words'>,) =>- `Untracked files unavailable (${words.lister} could not list them); ` ++ `Untracked files unavailable (${model.words.lister} could not list them); ` +'not counted'diff --git a/mods/diff/hooks/pane-state/after-new-session/new-session-fields/new-session-fields.ts b/mods/diff/hooks/pane-state/after-new-session/new-session-fields/new-session-fields.tsindex 6895ebe7..c7e72d7f 100644--- a/mods/diff/hooks/pane-state/after-new-session/new-session-fields/new-session-fields.ts+++ b/mods/diff/hooks/pane-state/after-new-session/new-session-fields/new-session-fields.ts@@ -1,11 +1,12 @@+import { NO_BODIES } from '../../no-bodies'+/*** What `/clear` and `/resume` reset: the pick, the source, the turns and- * the body; the fetch itself stays.+ * the bodies; the fetch itself stays.*/export const NEW_SESSION_FIELDS = Object.freeze({selectedPath: null,source: Object.freeze({ kind: 'current' }),turns: Object.freeze([]),- body: null,- bodyState: 'idle',+ bodies: NO_BODIES,} as const)diff --git a/mods/diff/hooks/pane-state/base-label-of.ts b/mods/diff/hooks/pane-state/base-label-of.tsdeleted file mode 100644index e91cb986..00000000--- a/mods/diff/hooks/pane-state/base-label-of.ts+++ /dev/null@@ -1,44 +0,0 @@-import { modeLabelOf } from './mode-label-of'-import type { PaneModel } from './pane-model'--/**- * The dim line under the header naming what the diff compares against- * (ReplDiffSidebar diffBaseLabel), or null for none.- *- * Hidden in settled session mode and before any fetch; the requested mode- * with an ellipsis while its fetch is pending; on an unborn HEAD with- * rows, what the rows are instead.- *- * @param model the mode the person picked, the last good fetch, and the- * backend's words- * @param filesCount the header's session file count- * @returns the line, or null- */-export function baseLabelOf(- model: Pick<PaneModel, 'requestedMode' | 'data' | 'words'>,- filesCount: number,-): string | null {- const { requestedMode, data } = model-- if (!data) {- return null- }-- if (data.isUnborn) {- const hasRows = filesCount > 0-- return hasRows ? 'no commits yet — showing staged and new files' : null- }-- const isPending = requestedMode !== data.mode- const isSettledSession = !isPending && requestedMode === 'session'-- if (isSettledSession) {- return null- }-- const phase = isPending ? 'pending' : 'settled'- const label = modeLabelOf(model, data.source, phase)-- return isPending ? `${label}…` : label-}diff --git a/mods/diff/hooks/pane-state/bodies/bodies.ts b/mods/diff/hooks/pane-state/bodies/bodies.tsnew file mode 100644index 00000000..91cfcf08--- /dev/null+++ b/mods/diff/hooks/pane-state/bodies/bodies.ts@@ -0,0 +1,7 @@+import type Git from '../../git'++/**+ * The file bodies the pane has read, by path: the parsed hunks, or null+ * where the backend could not read them; a path not in it is still loading.+ */+export type Bodies = ReadonlyMap<string, Git.FileHunks | null>diff --git a/mods/diff/hooks/pane-state/bodies/index.ts b/mods/diff/hooks/pane-state/bodies/index.tsnew file mode 100644index 00000000..81ce6a52--- /dev/null+++ b/mods/diff/hooks/pane-state/bodies/index.ts@@ -0,0 +1,3 @@+export type * from './bodies.js'++export * as default from '.'diff --git a/mods/diff/hooks/pane-state/body-state/body-state.ts b/mods/diff/hooks/pane-state/body-state/body-state.tsdeleted file mode 100644index 7224e104..00000000--- a/mods/diff/hooks/pane-state/body-state/body-state.ts+++ /dev/null@@ -1,5 +0,0 @@-/**- * Where the selected file's body stands: nothing selected, being read, git- * could not read it, or in hand.- */-export type BodyState = 'idle' | 'loading' | 'failed' | 'ready'diff --git a/mods/diff/hooks/pane-state/body-state/index.ts b/mods/diff/hooks/pane-state/body-state/index.tsdeleted file mode 100644index a56b3a84..00000000--- a/mods/diff/hooks/pane-state/body-state/index.ts+++ /dev/null@@ -1,3 +0,0 @@-export type * from './body-state.js'--export * as default from '.'diff --git a/mods/diff/hooks/pane-state/dialog-title-of.ts b/mods/diff/hooks/pane-state/dialog-title-of.tsnew file mode 100644index 00000000..84cf4805--- /dev/null+++ b/mods/diff/hooks/pane-state/dialog-title-of.ts@@ -0,0 +1,37 @@+import type { DialogTitle } from './dialog-title'+import type { PaneModel } from './pane-model'+import { pickedTurnOf } from './picked-turn-of'+import { turnTitleOf } from './turn-title-of'++/**+ * The inline pane's heading (DiffDialog's title): the picked turn and its+ * prompt's opening words, or what the working tree is compared with.+ *+ * An unborn HEAD lists staged and new files; a branch diff names its base;+ * anything else is the uncommitted changes against HEAD.+ *+ * @param model the pane's state+ * @returns the title and its dim subtitle+ */+export function dialogTitleOf(model: PaneModel): DialogTitle {+ const turn = pickedTurnOf(model)+ const source = model.data?.source+ const isUnborn = model.data?.isUnborn === true+ const isBranch = source?.kind === 'branch'++ function currentOf(): DialogTitle {+ switch (true) {+ case isUnborn:+ return { title: 'Staged and new files', subtitle: '(no commits yet)' }+ case isBranch && source?.kind === 'branch':+ return {+ title: 'Branch changes',+ subtitle: `(vs ${source.baseBranch})`,+ }+ default:+ return { title: 'Uncommitted changes', subtitle: '(git diff HEAD)' }+ }+ }++ return turn ? turnTitleOf(turn) : currentOf()+}diff --git a/mods/diff/hooks/pane-state/dialog-title/dialog-title.ts b/mods/diff/hooks/pane-state/dialog-title/dialog-title.tsnew file mode 100644index 00000000..451d87a9--- /dev/null+++ b/mods/diff/hooks/pane-state/dialog-title/dialog-title.ts@@ -0,0 +1,8 @@+/**+ * The inline pane's first line, as the built-in dialog heads itself: what+ * the rows are, then in dim what they are compared with.+ */+export type DialogTitle = {+ title: string+ subtitle: string+}diff --git a/mods/diff/hooks/pane-state/dialog-title/index.ts b/mods/diff/hooks/pane-state/dialog-title/index.tsnew file mode 100644index 00000000..cbe34f5c--- /dev/null+++ b/mods/diff/hooks/pane-state/dialog-title/index.ts@@ -0,0 +1,3 @@+export type * from './dialog-title.js'++export * as default from '.'diff --git a/mods/diff/hooks/pane-state/empty-state-of.ts b/mods/diff/hooks/pane-state/empty-state-of.tsindex 08f7c35c..81fa94ad 100644--- a/mods/diff/hooks/pane-state/empty-state-of.ts+++ b/mods/diff/hooks/pane-state/empty-state-of.ts@@ -1,7 +1,6 @@-import type Backend from '../backend'-import type Git from '../git'import Names from '../names'import type { EmptyState } from './empty-state'+import type { PaneModel } from './pane-model'/*** The headline that replaces the count when nothing is listed, worded as@@ -11,16 +10,16 @@ import type { EmptyState } from './empty-state'* "Diff unavailable"; no tracked rows while the untracked listing was* withheld claims nothing about new files.*- * @param data the last good fetch, or null when none ever settled+ * @param model the last good fetch (null when none ever settled), the words* @param filesCount the header's session file count- * @param words the backend's words* @returns the empty state, or null*/export function emptyStateOf(- data: Git.DiffData | null,+ model: Pick<PaneModel, 'data' | 'words'>,filesCount: number,- words: Backend.BackendWords,): EmptyState | null {+ const { data, words } = model+if (!data) {return {headline: 'Diff unavailable',@@ -37,7 +36,7 @@ export function emptyStateOf(if (data.isUntrackedWithheld) {return {headline: 'No tracked changes',- hint: Names.untrackedWithheldTextOf(words),+ hint: Names.untrackedWithheldTextOf(model),}}diff --git a/mods/diff/hooks/pane-state/index.ts b/mods/diff/hooks/pane-state/index.tsindex 8a952ba9..858f4270 100644--- a/mods/diff/hooks/pane-state/index.ts+++ b/mods/diff/hooks/pane-state/index.ts@@ -1,8 +1,9 @@export * from './after-fetch'export * from './after-new-session'-export * from './base-label-of.js'export * from './base-mode-of'-export * from './body-state'+export * from './bodies'+export * from './dialog-title'+export * from './dialog-title-of.js'export * from './empty-state'export * from './empty-state-of.js'export * from './header-totals'@@ -10,13 +11,16 @@ export * from './header-totals-of.js'export * from './initial-model'export * from './listed-of.js'export * from './mode-label-of'+export * from './no-bodies'export * from './pane-model'export * from './partition'export * from './partition-of.js'export * from './picked-turn-of'export * from './selection-of'export * from './source'+export * from './turn-title-of'export * from './turn-totals-of'+export * from './unborn-note-of.js'export * from './zero-totals'export * as default from '.'diff --git a/mods/diff/hooks/pane-state/initial-model/initial-model.ts b/mods/diff/hooks/pane-state/initial-model/initial-model.tsindex b0add10c..aab63e1a 100644--- a/mods/diff/hooks/pane-state/initial-model/initial-model.ts+++ b/mods/diff/hooks/pane-state/initial-model/initial-model.ts@@ -1,9 +1,10 @@import Git from '../../git'+import { NO_BODIES } from '../no-bodies'import type { PaneModel } from '../pane-model'/*** The pane before anything happened: session mode, nothing fetched,- * nothing picked, the current source, git's words.+ * nothing picked, no body read, the current source, git's words, docked.*/export const INITIAL_MODEL: PaneModel = Object.freeze({words: Git.GIT_WORDS,@@ -18,9 +19,8 @@ export const INITIAL_MODEL: PaneModel = Object.freeze({isPreSessionShown: false,source: Object.freeze({ kind: 'current' }),turns: Object.freeze([]),- body: null,- bodyState: 'idle',+ bodies: NO_BODIES,todos: Object.freeze({ done: 0, total: 0 }),armedPath: null,- isFocused: false,+ placement: 'dock',})diff --git a/mods/diff/hooks/pane-state/mode-label-of/mode-label-of.ts b/mods/diff/hooks/pane-state/mode-label-of/mode-label-of.tsindex 6f00b619..eef63f9d 100644--- a/mods/diff/hooks/pane-state/mode-label-of/mode-label-of.ts+++ b/mods/diff/hooks/pane-state/mode-label-of/mode-label-of.ts@@ -2,34 +2,43 @@ import type Git from '../../git'import type { PaneModel } from '../pane-model'/**- * A requested mode's name for the base line.+ * One base mode's name in the picker, worded as the built-in's base line+ * (diffBaseLabel) words the mode it shows.*- * Branch mode names its base branch from the data, or says what stands in- * while none is known. A working-tree diff names its own base (`HEAD`, a- * short sha); anything else falls back to the backend's word for it.+ * Branch mode names its base branch from the data, or once its own fetch+ * settled without one says what stands in; uncommitted names the working+ * tree's base. The requested mode carries an ellipsis while pending.*- * @param model the mode the person picked, and the backend's words- * @param source what the data on screen compares- * @param phase `pending` while the requested mode's fetch has not landed- * @returns the label without its pending ellipsis+ * @param mode the mode to name+ * @param model the mode the person picked, the last good fetch, the words+ * @returns the label*/export function modeLabelOf(- model: Pick<PaneModel, 'requestedMode' | 'words'>,- source: Git.DiffSource,- phase: 'pending' | 'settled',-) {- const base = source.kind === 'working-tree' ? source.base : model.words.base+ mode: Git.BaseMode,+ model: Pick<PaneModel, 'requestedMode' | 'data' | 'words'>,+): string {+ const { data } = model+ const source = data?.source+ const isPending = data !== null && model.requestedMode !== data.mode+ const isRequested = mode === model.requestedMode+ const suffix = isRequested && isPending ? '…' : ''+ const base = source?.kind === 'working-tree' ? source.base : model.words.base+ const isSettledBranch = isRequested && !isPending && data?.mode === 'branch'- switch (model.requestedMode) {- case 'session':- return 'this session'- case 'uncommitted':- return `uncommitted (vs ${base})`- case 'branch':- if (source.kind === 'branch') {- return `branch vs ${source.baseBranch}`- }+ function nameOf(): string {+ switch (mode) {+ case 'session':+ return 'this session'+ case 'uncommitted':+ return `uncommitted (vs ${base})`+ case 'branch':+ if (source?.kind === 'branch') {+ return `branch vs ${source.baseBranch}`+ }- return phase === 'pending' ? 'branch diff' : `vs ${base} (no base branch)`+ return isSettledBranch ? `vs ${base} (no base branch)` : 'branch'+ }}++ return `${nameOf()}${suffix}`}diff --git a/mods/diff/hooks/pane-state/no-bodies/index.ts b/mods/diff/hooks/pane-state/no-bodies/index.tsnew file mode 100644index 00000000..43ea111f--- /dev/null+++ b/mods/diff/hooks/pane-state/no-bodies/index.ts@@ -0,0 +1,3 @@+export * from './no-bodies.js'++export * as default from '.'diff --git a/mods/diff/hooks/pane-state/no-bodies/no-bodies.ts b/mods/diff/hooks/pane-state/no-bodies/no-bodies.tsnew file mode 100644index 00000000..9bf8be4c--- /dev/null+++ b/mods/diff/hooks/pane-state/no-bodies/no-bodies.ts@@ -0,0 +1,7 @@+import type { Bodies } from '../bodies'++/**+ * No body read yet: the pane's bodies before a fetch, and after one whose+ * base moved.+ */+export const NO_BODIES: Bodies = new Map()diff --git a/mods/diff/hooks/pane-state/pane-model/pane-model.ts b/mods/diff/hooks/pane-state/pane-model/pane-model.tsindex b662566f..c2763cfc 100644--- a/mods/diff/hooks/pane-state/pane-model/pane-model.ts+++ b/mods/diff/hooks/pane-state/pane-model/pane-model.ts@@ -2,15 +2,15 @@ import type Backend from '../../backend'import type Git from '../../git'import type Todos from '../../todos'import type Turns from '../../turns'-import type { BodyState } from '../body-state'+import type { Bodies } from '../bodies'import type { Source } from '../source'/*** Everything one drawing of the pane reads.*- * The last good fetch, what the person picked, the selected file's body,- * the transcript's turns and todos, and the pinned backend's words and- * base modes (git's until one is pinned).+ * The last good fetch, what the person picked, the files' bodies read so+ * far, the transcript's turns and todos, where the surface seated the pane+ * last, and the pinned backend's words and base modes (git's until pinned).*/export type PaneModel = {words: Backend.BackendWords@@ -25,9 +25,8 @@ export type PaneModel = {isPreSessionShown: booleansource: Sourceturns: readonly Turns.TurnDiff[]- body: Git.FileHunks | null- bodyState: BodyState+ bodies: Bodiestodos: Todos.TodoProgressarmedPath: string | null- isFocused: boolean+ placement: 'dock' | 'inline'}diff --git a/mods/diff/hooks/pane-state/partition-of.ts b/mods/diff/hooks/pane-state/partition-of.tsindex d2a5ed83..4173c367 100644--- a/mods/diff/hooks/pane-state/partition-of.ts+++ b/mods/diff/hooks/pane-state/partition-of.ts@@ -1,10 +1,10 @@import Classify from '../classify'-import type Git from '../git'+import Git from '../git'import type { Partition } from './partition'/**- * A fetch's rows split the way ReplDiffSidebar splits them: pre-session- * rows apart, tests and generated files counted and hidden unless shown.+ * A fetch's rows split as ReplDiffSidebar splits them, in its order (by+ * name): pre-session apart, tests and generated files hidden unless shown.** No read-deny bucket: the pane feeds nothing to the model on its own.*@@ -16,8 +16,12 @@ export function partitionOf(files: readonly Git.FileStat[],noise: 'shown' | 'hidden',): Partition {- const preSession = files.filter(file => file.isPreSession)- const session = files.filter(file => !file.isPreSession)+ const sorted = [...files].sort((a, b) =>+ Git.displayPathOf(a).localeCompare(Git.displayPathOf(b)),+ )++ const preSession = sorted.filter(file => file.isPreSession)+ const session = sorted.filter(file => !file.isPreSession)const quiet = session.filter(file => !Classify.isNoiseFile(file.path))return {diff --git a/mods/diff/hooks/pane-state/turn-title-of/index.ts b/mods/diff/hooks/pane-state/turn-title-of/index.tsnew file mode 100644index 00000000..0d068ba1--- /dev/null+++ b/mods/diff/hooks/pane-state/turn-title-of/index.ts@@ -0,0 +1,3 @@+export * from './turn-title-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/pane-state/turn-title-of/turn-title-of.ts b/mods/diff/hooks/pane-state/turn-title-of/turn-title-of.tsnew file mode 100644index 00000000..92db84d1--- /dev/null+++ b/mods/diff/hooks/pane-state/turn-title-of/turn-title-of.ts@@ -0,0 +1,16 @@+import type Turns from '../../turns'+import type { DialogTitle } from '../dialog-title'++/**+ * A picked turn's heading, as the built-in dialog titles its tab: the+ * turn's number, then its prompt's opening words in quotes when it has any.+ *+ * @param turn the turn+ * @returns the title and its dim subtitle+ */+export const turnTitleOf = (+ turn: Pick<Turns.TurnDiff, 'index' | 'preview'>,+): DialogTitle => ({+ title: `Turn ${turn.index}`,+ subtitle: turn.preview === '' ? '' : `"${turn.preview}"`,+})diff --git a/mods/diff/hooks/pane-state/unborn-note-of.ts b/mods/diff/hooks/pane-state/unborn-note-of.tsnew file mode 100644index 00000000..2ff674fd--- /dev/null+++ b/mods/diff/hooks/pane-state/unborn-note-of.ts@@ -0,0 +1,22 @@+import type { PaneModel } from './pane-model'++/**+ * The dim line under the header on an unborn HEAD that still lists rows:+ * what the rows are, since no comparison runs before the first commit.+ *+ * ReplDiffSidebar's no-commits qualifier; null with commits or no rows.+ *+ * @param model the last good fetch+ * @param filesCount the header's session file count+ * @returns the line, or null+ */+export function unbornNoteOf(+ model: Pick<PaneModel, 'data'>,+ filesCount: number,+): string | null {+ const isUnbornListing = model.data?.isUnborn === true && filesCount > 0++ return isUnbornListing+ ? 'no commits yet — showing staged and new files'+ : null+}diff --git a/mods/diff/hooks/pane-toggle/pane-belief/pane-belief.ts b/mods/diff/hooks/pane-toggle/pane-belief/pane-belief.tsindex e77d0e3d..e965cc1f 100644--- a/mods/diff/hooks/pane-toggle/pane-belief/pane-belief.ts+++ b/mods/diff/hooks/pane-toggle/pane-belief/pane-belief.ts@@ -1,11 +1,11 @@/*** What the plugin knows of its pane when `/diff` runs.*- * Whether it opened it and never closed it, whether it drew when a redraw- * was asked, and the terminal's width as last drawn (null before any draw).+ * Whether the pane is open (it opened it, and no close of any origin has+ * gone through since), and the terminal's width as last drawn (null before+ * any draw).*/export type PaneBelief = {- isBelievedOpen: boolean- wasDrawnWhenProbed: boolean+ isOpen: booleancolumns: number | null}diff --git a/mods/diff/hooks/pane-toggle/pane-toggle-of.ts b/mods/diff/hooks/pane-toggle/pane-toggle-of.tsindex 475c5f7b..0960ff10 100644--- a/mods/diff/hooks/pane-toggle/pane-toggle-of.ts+++ b/mods/diff/hooks/pane-toggle/pane-toggle-of.ts@@ -2,23 +2,20 @@ import Limits from '../limits'import type { PaneBelief } from './pane-belief'/**- * What `/diff` does, the one place its toggle is decided: close only when- * the plugin opened the pane and it still draws; otherwise open, focused.+ * What `/diff` does, the one place its toggle is decided: close the open+ * pane; otherwise open it, unless the terminal is too narrow.** Narrower than the built-in panel shows on, it answers the resize line- * (`too-narrow`). The person's close raises nothing it hooks, so a pane- * believed open is probed with a redraw first; a width not drawn yet opens.+ * (`too-narrow`); a width not drawn yet opens.*- * @param pane the plugin's belief, the probe's answer and the width+ * @param pane whether the pane is open, and the width* @returns `close`, `open` or `too-narrow`*/export function paneToggleOf(pane: PaneBelief,): 'open' | 'close' | 'too-narrow' {- const isClosing = pane.isBelievedOpen && pane.wasDrawnWhenProbed-const isTooNarrow =pane.columns !== null && pane.columns < Limits.OPEN_MIN_COLUMNS- return isClosing ? 'close' : isTooNarrow ? 'too-narrow' : 'open'+ return pane.isOpen ? 'close' : isTooNarrow ? 'too-narrow' : 'open'}diff --git a/mods/diff/hooks/register.ts b/mods/diff/hooks/register.tsindex 86fbe141..f213db70 100644--- a/mods/diff/hooks/register.ts+++ b/mods/diff/hooks/register.ts@@ -3,11 +3,13 @@ import type { On, ResultOf, SessionMessage, Timer } from 'claude-code'import Ask from './ask'import Backend from './backend'import { COMMAND_SPEC } from './command-spec'+import { drawnFilesOf } from './drawn-files-of'import { entryKindsOf } from './entry-kinds-of'import type Git from './git'import type { Host } from './host'import { isOnPaneSurface } from './is-on-pane-surface'import Limits from './limits'+import { mapLimited } from './map-limited'import { messageOf } from './message-of'import { mtimeOf } from './mtime-of'import Names from './names'@@ -36,13 +38,15 @@ export function register(on: On) {let hasAutoOpened = falselet columns: number | null = nulllet shownSessionId: string | null = null- let wasDrawnSinceProbe = falselet armed: Ask.ArmedAsk | null = nulllet carrying: Ask.ArmedAsk | null = nulllet isRefreshing = falselet isRefreshQueued = falselet generation = 0- let bodyKey: string | null = null+ let bodyStamp: string | null = null+ let bodyBase: string | null = null++ const bodyLoads = new Map<string, Promise<Git.FileHunks | null>>()const polled = { toplevel: '', headKey: '' }@@ -151,49 +155,70 @@ export function register(on: On) {)}- const selectedOf = (): Git.FileStat | null =>- PaneState.selectionOf(- PaneState.listedOf(- PaneState.partitionOf(- model.data?.files ?? [],- model.isNoiseShown ? 'shown' : 'hidden',- ),- model.isPreSessionShown ? 'shown' : 'hidden',- ),- model.selectedPath,- )-- async function loadBody(engine: Host): Promise<boolean> {+ async function loadBodies(engine: Host): Promise<boolean> {const { data } = model- const selected = selectedOf()+ const pinned = backend- if (!data || !selected || !backend) {- bodyKey = null- model = { ...model, body: null, bodyState: 'idle' }+ if (!data || !pinned) {+ bodyStamp = null+ bodyBase = null+ bodyLoads.clear()+ model = { ...model, bodies: PaneState.NO_BODIES }return false}- const key = `${generation}|${data.baseRef}|${selected.path}`+ const stamp = bodyStampOf(data)+ const isNewBase = data.baseRef !== bodyBase- if (key === bodyKey) {- return false+ if (stamp !== bodyStamp) {+ bodyStamp = stamp+ bodyLoads.clear()}- bodyKey = key- model = { ...model, body: null, bodyState: 'loading' }- redraw(engine)+ if (isNewBase) {+ bodyBase = data.baseRef+ model = { ...model, bodies: PaneState.NO_BODIES }+ redraw(engine)+ }- const body = await backend.fetchFileHunks(data, selected)+ return fetchBodies(engine, pinned, data)+ }- if (bodyKey !== key) {- return body === null- }+ const bodyStampOf = (data: Git.DiffData) => `${generation}|${data.baseRef}`- model = { ...model, body, bodyState: body ? 'ready' : 'failed' }- redraw(engine)+ async function fetchBodies(+ engine: Host,+ pinned: Backend.Backend,+ data: Git.DiffData,+ ): Promise<boolean> {+ const stamp = bodyStampOf(data)++ function loadOf(file: Git.FileStat): Promise<Git.FileHunks | null> {+ const load = pinned.fetchFileHunks(data, file)+ bodyLoads.set(file.path, load)++ return load.then(body => {+ if (bodyStamp === stamp) {+ model = {+ ...model,+ bodies: new Map(model.bodies).set(file.path, body),+ }++ redraw(engine)+ }- return body === null+ return body+ })+ }++ return (+ await mapLimited(+ drawnFilesOf(model).filter(file => !bodyLoads.has(file.path)),+ Limits.BODY_FETCH_CONCURRENCY,+ loadOf,+ )+ ).includes(null)}function startPoll(engine: Host, pinned: Backend.Backend) {@@ -274,7 +299,7 @@ export function register(on: On) {break}- const hasHunksFailed = await loadBody(engine)+ const hasHunksFailed = await loadBodies(engine)if (outcome.kind === 'data') {record.mark(@@ -318,9 +343,8 @@ export function register(on: On) {engine: Host,trigger: (typeof Record.SHOWN_TRIGGERS)[number],): Promise<void> {- const pane = { id: Names.PANE_ID, title: Names.PANE_TITLE }- const isManual = trigger === 'manual'- await engine.openPane(isManual ? { ...pane, ...Names.FOCUSED_PANE } : pane)+ model = { ...model, selectedPath: null }+ await engine.openPane({ id: Names.PANE_ID, title: Names.PANE_TITLE })isPaneOpen = trueconst sessionId = await engine.sessionId().catch(() => null)@@ -345,14 +369,6 @@ export function register(on: On) {})}- async function wasDrawnWhenProbed(engine: Host): Promise<boolean> {- wasDrawnSinceProbe = false- engine.invalidate()- await engine.sleep(Limits.OPEN_PROBE_MS)-- return wasDrawnSinceProbe- }-async function openOnFirstEdit(engine: Host): Promise<void> {const isTaken = () => isPaneOpen || hasAutoOpened@@ -393,17 +409,21 @@ export function register(on: On) {const actionsOf = (engine: Host): Views.PaneActions => ({selectFile: path => {model = { ...model, selectedPath: path }- void loadBody(engine)++ if (model.placement === 'dock') {+ void engine.scrollTo(Views.bodyKeyOf(path)).catch(() => undefined)+ }+redraw(engine)},toggleNoise: () => {model = { ...model, isNoiseShown: !model.isNoiseShown }- void loadBody(engine)+ void loadBodies(engine)redraw(engine)},togglePreSession: () => {model = { ...model, isPreSessionShown: !model.isPreSessionShown }- void loadBody(engine)+ void loadBodies(engine)redraw(engine)},chooseBase: value => {@@ -413,8 +433,7 @@ export function register(on: On) {return}- bodyKey = null- model = { ...model, requestedMode: mode, body: null, bodyState: 'idle' }+ model = { ...model, requestedMode: mode }Record.recorderOf(engine).mark(Record.FEATURES.baseSwitch, {kind: 'ok',@@ -441,7 +460,6 @@ export function register(on: On) {: { kind: 'current' }model = { ...model, source, selectedPath: null }- void loadBody(engine)redraw(engine)},toggleAsk: path => {@@ -454,12 +472,6 @@ export function register(on: On) {arm(engine, path)},- close: () => {- void closePane(engine)- .then(() => markTabSwitch(engine, 'convo'))- .then(() => engine.storeSet(Names.STORE_OPEN_KEY, false))- .catch(() => undefined)- },})function arm(engine: Host, path: string) {@@ -467,7 +479,7 @@ export function register(on: On) {path,PaneState.pickedTurnOf(model)?.files.find(file => file.path === path)?.hunks ??- model.body?.hunks ??+ model.bodies.get(path)?.hunks ??[],)@@ -505,7 +517,6 @@ export function register(on: On) {now: () => $.clock.now(),after: (ms, fn) => $.clock.after(ms, fn),every: (ms, fn) => $.clock.every(ms, fn),- sleep: ms => $.clock.sleep(ms),run: (argv, init) => $.process.run(argv, init),stat: path => $.fs.stat(path),listDir: path => $.fs.list(path),@@ -518,6 +529,8 @@ export function register(on: On) {uiLog: text => $.ui.log(text),openPane: pane => $.ui.open(pane),closePane: pane => $.ui.close(pane),+ scrollTo: key =>+ $.ui.scroll({ to: { key }, in: Names.PANE_ID, block: 'start' }),registerCommand: spec => $.command.register(spec),sessionId: () => $.session.id(),mark: entry => $.telemetry.mark(entry),@@ -542,9 +555,8 @@ export function register(on: On) {const { Box, Text, Button, Select, Code } = await $.ui.resolve(e)- wasDrawnSinceProbe = truecolumns = e.viewport?.columns ?? columns- model = { ...model, isFocused: e.props.isFocused }+ model = { ...model, placement: e.props.placement }return Views.paneView({@@ -554,7 +566,7 @@ export function register(on: On) {rows: e.props.scroll.bodyRows,},model,- e.props.placement,+ { placement: e.props.placement, terminalColumns: columns },)})@@ -573,11 +585,7 @@ export function register(on: On) {}}- const toggle = PaneToggle.paneToggleOf({- isBelievedOpen: isPaneOpen,- wasDrawnWhenProbed: isPaneOpen && (await wasDrawnWhenProbed(host)),- columns,- })+ const toggle = PaneToggle.paneToggleOf({ isOpen: isPaneOpen, columns })if (toggle === 'too-narrow') {return { text: Names.RESIZE_TERMINAL_TEXT }@@ -588,7 +596,26 @@ export function register(on: On) {markTabSwitch(host, isOpening ? 'diff' : 'convo')await host.storeSet(Names.STORE_OPEN_KEY, isOpening).catch(() => undefined)- return {}+ return {+ text: isOpening ? Names.PANEL_SHOWN_TEXT : Names.PANEL_HIDDEN_TEXT,+ }+ })++ on('ui.close', { id: Names.PANE_ID }, async ($, e, next) => {+ const result = await next(e)+ const isClosed = result.deny === undefined+ const isPersons = isClosed && e.origin.kind === 'person'++ if (isClosed) {+ isPaneOpen = false+ }++ if (isPersons && host) {+ markTabSwitch(host, 'convo')+ await host.storeSet(Names.STORE_OPEN_KEY, false).catch(() => undefined)+ }++ return result})on('command.run', { command: ['clear', 'resume'] }, async ($, e, next) => {@@ -600,7 +627,9 @@ export function register(on: On) {}hasAutoOpened = false- bodyKey = null+ bodyStamp = null+ bodyBase = null+ bodyLoads.clear()disarm(host)model = PaneState.afterNewSession(model)}diff --git a/mods/diff/hooks/views/current-pane/current-pane.tsx b/mods/diff/hooks/views/current-pane/current-pane.tsxindex 733839a9..dcbc691e 100644--- a/mods/diff/hooks/views/current-pane/current-pane.tsx+++ b/mods/diff/hooks/views/current-pane/current-pane.tsx@@ -6,21 +6,23 @@ import type { RenderElement } from 'claude-code'import type Git from '../../git'import Names from '../../names'import PaneState from '../../pane-state'-import Detail from '../detail'+import Entries from '../entries'import type { Kit } from '../kit'import Layout from '../layout'+import { preludeOf } from '../prelude-of'import Sections from '../sections'-import { fileRowOf } from './file-row-of'+import { selectedDetailOf } from '../selected-detail-of'+import { dialogRowsOf } from './dialog-rows-of'import { listBodyOf } from './list-body-of'import { messagePaneOf } from './message-pane-of'/**- * The pane over the repository's diff now (ReplDiffSidebarBody, one file's- * body at a time): header, base line, todo bar, pickers, rows, detail.+ * The inline pane over the repository's diff now (DiffDialog): header,+ * pickers, todo bar, the rows round the selected file, that file's detail.** The toggle sits above the rows; the elision count, withheld-untracked- * note and pre-session line below, with blank rows as the built-in leaves.- * With nothing to list, messagePaneOf draws the body, the header a close.+ * note and pre-session line below. With nothing to list, messagePaneOf+ * draws the body.** @param kit the elements, the handlers, the width, the rows* @param model the pane's state@@ -32,19 +34,10 @@ export function currentPane(): RenderElement {const { Box } = kit.uiconst { data } = model+ const prelude = preludeOf(kit, model)- if (model.isOutsideRepository) {- return <Box>{Sections.dimNote(kit, Names.NOT_IN_REPOSITORY_TEXT)}</Box>- }-- if (!data && !model.hasSettled) {- return messagePaneOf(kit, {- top: [Sections.headerView(kit, null)],- message: ['Loading diff…'],- controls: null,- earlier: null,- rest: [],- })+ if (prelude) {+ return prelude}const noise = model.isNoiseShown ? 'shown' : 'hidden'@@ -55,18 +48,14 @@ export function currentPane(? PaneState.headerTotalsOf(data, partition): PaneState.ZERO_TOTALS- const empty = PaneState.emptyStateOf(data, totals.filesCount, model.words)- const baseLabel = PaneState.baseLabelOf(model, totals.filesCount)+ const empty = PaneState.emptyStateOf(model, totals.filesCount)const selected = PaneState.selectionOf(PaneState.listedOf(partition, preSession),model.selectedPath,)- const rowOf = (file: Git.FileStat): RenderElement =>- Sections.fileRow(kit, fileRowOf(file, selected?.path ?? null), () =>- kit.actions.selectFile(file.path),- )+ const selectedPath = selected?.path ?? nullconst noteOf = (text: string | null): RenderElement | null =>text === null ? null : Sections.dimNote(kit, Layout.sanitizeName(text))@@ -97,72 +86,62 @@ export function currentPane(const isEarlierListed = earlierFiles.length > 0const earlierRows = isEarlierListed- ? [<Box height={1} />, ...earlierFiles.map(rowOf)]+ ? [<Box height={1} />, ...dialogRowsOf(kit, earlierFiles, selectedPath)]: []const isUntrackedNoted = data?.isUntrackedWithheld === true && !emptyconst listed = listBodyOf(kit, { data, partition, totals, empty })- const notes = listed.filter(line => typeof line === 'string')- const hasRows = notes.length < listed.length++ const notes = listed.flatMap(line => (typeof line === 'string' ? [line] : []))++ const rows = listed.filter(+ (line): line is Git.FileStat => typeof line !== 'string',+ )++ const hasRows = rows.length > 0const message = empty ? [empty.headline, ...notes] : hasRows ? [] : notes- const header = Sections.headerView(kit, empty ? null : totals)+ const header = Sections.headerView(kit, empty ? null : totals, null)+ const subline = noteOf(PaneState.unbornNoteOf(model, totals.filesCount))const notShownNote = noteOf(totals.notShown > 0 ? `${totals.notShown} not shown` : null,)const untrackedNote = noteOf(- isUntrackedNoted ? Names.untrackedWithheldTextOf(model.words) : null,+ isUntrackedNoted ? Names.untrackedWithheldTextOf(model) : null,)- const detail = selected- ? [- Sections.divider(kit),- Detail.detailView(- kit,- {- words: model.words,- path: selected.path,- renamedFrom: selected.renamedFrom,- isUntracked: selected.isUntracked,- isBinary: selected.isBinary,- body: model.body,- bodyState: model.bodyState,- isArmed: model.armedPath === selected.path,- },- () => kit.actions.toggleAsk(selected.path),- ),- ]- : []+ const detail = selectedDetailOf(+ kit,+ selected ? Entries.bodyEntryOf(selected, model) : null,+ model,+ )++ const top = Sections.present([+ Sections.titleRow(kit, PaneState.dialogTitleOf(model)),+ header,+ subline,+ Sections.controlsView(kit, model),+ Sections.todoBar(kit, model),+ noiseToggle,+ ])const isMessageShown = message.length > 0return isMessageShown ? (messagePaneOf(kit, {- top: Sections.present([- header,- noteOf(baseLabel),- Sections.todoBar(kit, model),- noiseToggle,- notShownNote,- untrackedNote,- ]),+ top: Sections.present([...top, notShownNote, untrackedNote]),message,- controls: Sections.controlsView(kit, model),+ controls: null,earlier: earlierToggle,rest: [...earlierRows, ...detail],})) : (<Box flexDirection="column">{Sections.present([- header,- noteOf(baseLabel),- Sections.todoBar(kit, model),- Sections.controlsView(kit, model),- noiseToggle,- ...listed.map(line =>- typeof line === 'string' ? noteOf(line) : rowOf(line),- ),+ ...top,+ ...dialogRowsOf(kit, rows, selectedPath),+ ...notes.map(noteOf),notShownNote,untrackedNote,hasEarlier ? <Box height={1} /> : null,diff --git a/mods/diff/hooks/views/current-pane/dialog-rows-of/dialog-rows-of.tsx b/mods/diff/hooks/views/current-pane/dialog-rows-of/dialog-rows-of.tsxnew file mode 100644index 00000000..9a22851f--- /dev/null+++ b/mods/diff/hooks/views/current-pane/dialog-rows-of/dialog-rows-of.tsx@@ -0,0 +1,61 @@+/* @jsxRuntime classic */+/* @jsx h */+/* @jsxFrag Fragment */+import type { RenderElement } from 'claude-code'++import Git from '../../../git'+import Limits from '../../../limits'+import type { Kit } from '../../kit'+import Layout from '../../layout'+import Sections from '../../sections'+import { fileRowOf } from '../file-row-of'++/**+ * The inline list (DiffFileList): MAX_DIALOG_ROWS rows round the selected+ * file, the pointer on it, and over a longer list a dim count each side.+ *+ * A side with no file out of the window keeps its row, blank.+ *+ * @param kit the elements, the handlers, the width+ * @param files the listed files, in order+ * @param selectedPath the selected file's path, or null+ * @returns the rows+ */+export function dialogRowsOf(+ kit: Kit,+ files: readonly Git.FileStat[],+ selectedPath: string | null,+): RenderElement[] {+ const selected = Math.max(+ 0,+ files.findIndex(file => file.path === selectedPath),+ )++ const isPaged = files.length > Limits.MAX_DIALOG_ROWS++ const last = Math.min(+ files.length,+ Math.max(0, selected - Math.floor(Limits.MAX_DIALOG_ROWS / 2)) ++ Limits.MAX_DIALOG_ROWS,+ )++ const first = Math.max(0, last - Limits.MAX_DIALOG_ROWS)+ const above = first+ const below = files.length - last++ const edgeOf = (count: number, arrow: string): RenderElement =>+ Sections.dimNote(+ kit,+ count > 0 ? ` ${arrow} ${Layout.plural(count, 'more file')}` : ' ',+ )++ const rows = files+ .slice(first, last)+ .map(file =>+ Sections.dialogFileRow(kit, fileRowOf(file, selectedPath), () =>+ kit.actions.selectFile(file.path),+ ),+ )++ return isPaged ? [edgeOf(above, '↑'), ...rows, edgeOf(below, '↓')] : rows+}diff --git a/mods/diff/hooks/views/current-pane/dialog-rows-of/index.ts b/mods/diff/hooks/views/current-pane/dialog-rows-of/index.tsnew file mode 100644index 00000000..83b6efe1--- /dev/null+++ b/mods/diff/hooks/views/current-pane/dialog-rows-of/index.ts@@ -0,0 +1,3 @@+export * from './dialog-rows-of.jsx'++export * as default from '.'diff --git a/mods/diff/hooks/views/current-pane/file-row-of/file-row-of.ts b/mods/diff/hooks/views/current-pane/file-row-of/file-row-of.tsindex c1b50c85..4be84434 100644--- a/mods/diff/hooks/views/current-pane/file-row-of/file-row-of.ts+++ b/mods/diff/hooks/views/current-pane/file-row-of/file-row-of.ts@@ -1,9 +1,9 @@-import type Git from '../../../git'+import Git from '../../../git'import Sections from '../../sections'/**- * A fetched row as the list draws it: its counts, or a note in their- * place (`untracked`, `Binary file`, `renamed`), and selection.+ * A fetched row as the inline list draws it (DiffFileList FileItem): its+ * counts or a note for them (`untracked`, `Binary file`), name, selection.** @param file the row* @param selectedPath the selected file's path, or null@@ -13,19 +13,16 @@ export function fileRowOf(file: Git.FileStat,selectedPath: string | null,): Sections.FileRowModel {- const isRenamed = file.renamedFrom !== null-const note = file.isUntracked? 'untracked': file.isBinary? 'Binary file'- : isRenamed- ? 'renamed'- : null+ : nullreturn {key: Sections.fileKeyOf(file.path),path: file.path,+ displayPath: Git.displayPathOf(file),added: file.added,removed: file.removed,note,diff --git a/mods/diff/hooks/views/current-pane/index.ts b/mods/diff/hooks/views/current-pane/index.tsindex 30ac292e..dbc7d425 100644--- a/mods/diff/hooks/views/current-pane/index.ts+++ b/mods/diff/hooks/views/current-pane/index.ts@@ -1,4 +1,5 @@export * from './current-pane.jsx'+export * from './dialog-rows-of'export * from './file-row-of'export * from './list-body-of'export * from './message-pane-of'diff --git a/mods/diff/hooks/views/detail/body-budget/body-budget.ts b/mods/diff/hooks/views/detail/body-budget/body-budget.tsnew file mode 100644index 00000000..3f10b5d4--- /dev/null+++ b/mods/diff/hooks/views/detail/body-budget/body-budget.ts@@ -0,0 +1,12 @@+import { MAX_BODY_CHARS } from '../max-body-chars'+import { MAX_BODY_NODES } from '../max-body-nodes'+import type Types from '../types'++/**+ * The room the pane's file bodies start from at each drawing, spent file by+ * file in drawing order.+ */+export const BODY_BUDGET: Types.BodyRoom = Object.freeze({+ chars: MAX_BODY_CHARS,+ nodes: MAX_BODY_NODES,+})diff --git a/mods/diff/hooks/views/detail/body-budget/index.ts b/mods/diff/hooks/views/detail/body-budget/index.tsnew file mode 100644index 00000000..2fba2bd1--- /dev/null+++ b/mods/diff/hooks/views/detail/body-budget/index.ts@@ -0,0 +1,3 @@+export * from './body-budget.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/detail/code-blocks-of/code-blocks-of.ts b/mods/diff/hooks/views/detail/code-blocks-of/code-blocks-of.tsindex dd679669..cd28e59e 100644--- a/mods/diff/hooks/views/detail/code-blocks-of/code-blocks-of.ts+++ b/mods/diff/hooks/views/detail/code-blocks-of/code-blocks-of.ts@@ -1,82 +1,62 @@import Git from '../../../git'-import { HUNK_DIVIDER } from '../hunk-divider'-import { HUNK_DIVIDER_NODES } from '../hunk-divider-nodes'import { hunkSourceOf } from '../hunk-source-of'import { leadingHunkOf } from '../leading-hunk-of'-import { MAX_BODY_CHARS } from '../max-body-chars'-import { MAX_BODY_NODES } from '../max-body-nodes'import { MAX_CODE_CHARS } from '../max-code-chars'import { subHunksOf } from '../sub-hunks-of'import type Types from '../types'import { drawnLineOf } from './drawn-line-of'/**- * A file's hunks as the sources of `Code` blocks, each at most- * MAX_CODE_CHARS, hunks sharing a block (the engine's ellipsis between).+ * A file's hunks as the sources of `Code` blocks, one a hunk, stacked with+ * nothing between as the built-in stacks a file's hunks.*- * A new block at a hunk gets HUNK_DIVIDER; a hunk too long for one is split- * (subHunksOf) into blocks stacked with none. The body stops, truncated, at- * the whole lines MAX_BODY_CHARS and MAX_BODY_NODES hold, as the host counts.+ * A hunk longer than MAX_CODE_CHARS is split (subHunksOf) into several. The+ * body stops, truncated, at the whole lines the room holds as the host+ * counts, a block a node; the room left comes back.** @param hunks the file's hunks- * @returns the blocks in order, and whether any line was left out or cut+ * @param room the characters and nodes the pane's bodies have left+ * @returns the sources in order, whether any line was left out or cut, and+ * the room after them*/-export function codeBlocksOf(hunks: readonly Git.Hunk[]): Types.CodeBody {- const blocks: Types.CodeBlock[] = []+export function codeBlocksOf(+ hunks: readonly Git.Hunk[],+ room: Types.BodyRoom,+): Types.CodeBody {+ const sources: string[] = []let chars = 0- let nodes = 0let isTruncated = false+ const left = (): Types.BodyRoom => ({+ chars: room.chars - chars,+ nodes: room.nodes - sources.length,+ })+for (const hunk of hunks) {const lines = hunk.lines.filter(Git.isBodyLine).map(drawnLineOf)const split = subHunksOf({ ...hunk, lines }, MAX_CODE_CHARS)isTruncated ||= split.isTruncated- for (const [at, piece] of split.hunks.entries()) {- const last = blocks.at(-1)- const source = hunkSourceOf(piece)- const isHunkStart = at === 0-- const isJoining =- isHunkStart &&- last !== undefined &&- last.source.length + 1 + source.length <= MAX_CODE_CHARS-- const hasDivider = isHunkStart && !isJoining && last !== undefined- const overhead = isJoining ? 1 : hasDivider ? HUNK_DIVIDER.length : 0-- const addedNodes = isJoining- ? 0- : 1 + (hasDivider ? HUNK_DIVIDER_NODES : 0)-- const room = MAX_BODY_CHARS - chars - overhead- const fitted = source.length <= room ? piece : leadingHunkOf(piece, room)- const isOverNodes = nodes + addedNodes > MAX_BODY_NODES+ for (const piece of split.hunks) {+ const fits = room.chars - chars+ const isWhole = hunkSourceOf(piece).length <= fits+ const fitted = isWhole ? piece : leadingHunkOf(piece, fits)+ const isOverNodes = sources.length + 1 > room.nodesif (isOverNodes || fitted.lines.length === 0) {- return { blocks, isTruncated: true }+ return { sources, isTruncated: true, room: left() }}const text = hunkSourceOf(fitted)-- if (isJoining) {- blocks.pop()- }-- blocks.push({- source: isJoining ? `${last.source}\n${text}` : text,- hasDivider: isJoining ? last.hasDivider : hasDivider,- })-- chars += overhead + text.length- nodes += addedNodes+ sources.push(text)+ chars += text.lengthif (fitted.lines.length < piece.lines.length) {- return { blocks, isTruncated: true }+ return { sources, isTruncated: true, room: left() }}}}- return { blocks, isTruncated }+ return { sources, isTruncated, room: left() }}diff --git a/mods/diff/hooks/views/detail/detail-model/detail-model.ts b/mods/diff/hooks/views/detail/detail-model/detail-model.tsindex d49c2009..4b26558a 100644--- a/mods/diff/hooks/views/detail/detail-model/detail-model.ts+++ b/mods/diff/hooks/views/detail/detail-model/detail-model.ts@@ -1,20 +1,19 @@import type Backend from '../../../backend'import type Git from '../../../git'-import type PaneState from '../../../pane-state'/**- * The selected file as its body draws it.+ * One file as its body draws it.*- * The path, what kind of row it is, its hunks once read, whether it is armed- * for the next prompt, and the backend's words for an untracked row's note.+ * Its name as listed, what kind of row it is, its hunks once read (undefined+ * while they load, null when the backend could not read them), whether it is+ * armed for the next prompt, and the backend's words for an untracked note.*/export type DetailModel = {words: Pick<Backend.BackendWords, 'untrackedNoteOf'>path: string- renamedFrom: string | null+ displayPath: stringisUntracked: booleanisBinary: boolean- body: Git.FileHunks | null- bodyState: PaneState.BodyState+ body: Git.FileHunks | null | undefinedisArmed: boolean}diff --git a/mods/diff/hooks/views/detail/detail-view.tsx b/mods/diff/hooks/views/detail/detail-view.tsxindex 73025ed3..dbf4271f 100644--- a/mods/diff/hooks/views/detail/detail-view.tsx+++ b/mods/diff/hooks/views/detail/detail-view.tsx@@ -1,49 +1,53 @@/* @jsxRuntime classic *//* @jsx h *//* @jsxFrag Fragment */-import type { RenderElement } from 'claude-code'-import type { Kit } from '../kit'import Layout from '../layout'import Sections from '../sections'import { codeBlocksOf } from './code-blocks-of'import type { DetailModel } from './detail-model'-import { HUNK_DIVIDER } from './hunk-divider'+import { FILE_FRAME_NODES } from './file-frame-nodes'import { MAX_CODE_CHARS } from './max-code-chars'import { placeholderOf } from './placeholder-of'+import type Types from './types'/**- * The selected file under the list: its bold path and asides, the ask+ * One file's detail (DiffDetailView): its bold name and aside, the ask* Button, the built-in's dim rule under them, the body.*- * Each name is cut from its start to the width. The body is a placeholder,- * or the hunks as the engine's diff `Code` blocks (codeBlocksOf), a dim- * divider where two meet, then the footer when anything was cut.+ * The name is cut from its start to the width. The body is a placeholder,+ * or the hunks as the engine's diff `Code` blocks (codeBlocksOf) within the+ * room given, then a footer when anything was cut; the room left over.** @param kit the elements and the width- * @param detail the selected file- * @param onToggleAsk arms or disarms the file for the next prompt- * @returns the detail element+ * @param detail the file+ * @param draw the room the bodies have left, and the ask's press+ * @returns the detail element and the room after it*/export function detailView(kit: Kit,detail: DetailModel,- onToggleAsk: () => void,-): RenderElement {+ draw: Types.DetailDraw,+): Types.DrawnDetail {const { Box, Text, Button, Code } = kit.ui+ const { room, onToggleAsk } = drawconst placeholder = placeholderOf(detail)- const code = codeBlocksOf(placeholder ? [] : (detail.body?.hunks ?? []))- const isTruncated = detail.body?.isTruncated === true || code.isTruncated- const path = Layout.sanitizeName(detail.path).slice(-MAX_CODE_CHARS)+ const name = Layout.sanitizeName(detail.displayPath)- const nameOf = (name: string) =>- Layout.truncateStart(Layout.sanitizeName(name), kit.columns)+ const framed: Types.BodyRoom = {+ chars: room.chars - name.length,+ nodes: room.nodes - FILE_FRAME_NODES,+ }- const renamedFrom =- detail.renamedFrom === null ? null : nameOf(detail.renamedFrom)+ const code = codeBlocksOf(+ placeholder ? [] : (detail.body?.hunks ?? []),+ framed,+ )++ const isTruncated = detail.body?.isTruncated === true || code.isTruncated+ const path = Layout.sanitizeName(detail.path).slice(-MAX_CODE_CHARS)const asides = [- renamedFrom === null ? null : `renamed from ${renamedFrom}`,detail.isUntracked ? 'untracked' : null,isTruncated ? 'truncated' : null,].filter(word => word !== null)@@ -53,7 +57,7 @@ export function detailView(const ask = placeholder? []: [- <Button key="ask" onPress={onToggleAsk}>+ <Button key={Sections.askKeyOf(detail.path)} onPress={onToggleAsk}>{detail.isArmed ? 'asked ✓' : 'ask'}</Button>,]@@ -72,18 +76,17 @@ export function detailView(</Text>))- const hunks = code.blocks.flatMap(block => [- ...(block.hasDivider ? [<Text dimColor>{HUNK_DIVIDER}</Text>] : []),- <Code source={block.source} format="diff" path={path} />,- ])+ const hunks = code.sources.map(source => (+ <Code source={source} format="diff" path={path} />+ ))- return (+ const element = (<Box flexDirection="column">{[<Box flexDirection="row">{[<Text bold wrap="truncate-start">- {nameOf(detail.path)}+ {Layout.truncateStart(name, kit.columns)}</Text>,<Text dimColor>{aside}</Text>,<Box flexGrow={1} />,@@ -96,4 +99,6 @@ export function detailView(]}</Box>)++ return { element, room: code.room }}diff --git a/mods/diff/hooks/views/detail/file-frame-nodes/file-frame-nodes.ts b/mods/diff/hooks/views/detail/file-frame-nodes/file-frame-nodes.tsnew file mode 100644index 00000000..64f919bf--- /dev/null+++ b/mods/diff/hooks/views/detail/file-frame-nodes/file-frame-nodes.ts@@ -0,0 +1,5 @@+/**+ * The tree nodes one file's detail costs before any `Code` block: its box,+ * the name row and its parts, the two rules, a note or footer.+ */+export const FILE_FRAME_NODES = 16diff --git a/mods/diff/hooks/views/detail/file-frame-nodes/index.ts b/mods/diff/hooks/views/detail/file-frame-nodes/index.tsnew file mode 100644index 00000000..ebec2484--- /dev/null+++ b/mods/diff/hooks/views/detail/file-frame-nodes/index.ts@@ -0,0 +1,3 @@+export * from './file-frame-nodes.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/detail/hunk-divider-nodes/hunk-divider-nodes.ts b/mods/diff/hooks/views/detail/hunk-divider-nodes/hunk-divider-nodes.tsdeleted file mode 100644index b116ae29..00000000--- a/mods/diff/hooks/views/detail/hunk-divider-nodes/hunk-divider-nodes.ts+++ /dev/null@@ -1,4 +0,0 @@-/**- * The nodes one HUNK_DIVIDER costs the tree: its Text and its string.- */-export const HUNK_DIVIDER_NODES = 2diff --git a/mods/diff/hooks/views/detail/hunk-divider-nodes/index.ts b/mods/diff/hooks/views/detail/hunk-divider-nodes/index.tsdeleted file mode 100644index e038d0df..00000000--- a/mods/diff/hooks/views/detail/hunk-divider-nodes/index.ts+++ /dev/null@@ -1,3 +0,0 @@-export * from './hunk-divider-nodes.js'--export * as default from '.'diff --git a/mods/diff/hooks/views/detail/hunk-divider/hunk-divider.ts b/mods/diff/hooks/views/detail/hunk-divider/hunk-divider.tsdeleted file mode 100644index 3400a544..00000000--- a/mods/diff/hooks/views/detail/hunk-divider/hunk-divider.ts+++ /dev/null@@ -1,5 +0,0 @@-/**- * The dim text between two `Code` blocks that meet at a hunk boundary: the- * ellipsis the engine draws between the hunks of one `Code`.- */-export const HUNK_DIVIDER = '...'diff --git a/mods/diff/hooks/views/detail/hunk-divider/index.ts b/mods/diff/hooks/views/detail/hunk-divider/index.tsdeleted file mode 100644index 69c6a933..00000000--- a/mods/diff/hooks/views/detail/hunk-divider/index.ts+++ /dev/null@@ -1,3 +0,0 @@-export * from './hunk-divider.js'--export * as default from '.'diff --git a/mods/diff/hooks/views/detail/index.ts b/mods/diff/hooks/views/detail/index.tsindex 0f3f5b48..79cacdb7 100644--- a/mods/diff/hooks/views/detail/index.ts+++ b/mods/diff/hooks/views/detail/index.ts@@ -1,8 +1,8 @@+export * from './body-budget'export * from './code-blocks-of'export * from './detail-model'export * from './detail-view.jsx'-export * from './hunk-divider'-export * from './hunk-divider-nodes'+export * from './file-frame-nodes'export * from './hunk-header-of'export * from './hunk-source-of'export * from './leading-hunk-of'diff --git a/mods/diff/hooks/views/detail/max-body-chars/max-body-chars.ts b/mods/diff/hooks/views/detail/max-body-chars/max-body-chars.tsindex 77296c3b..cfddef7b 100644--- a/mods/diff/hooks/views/detail/max-body-chars/max-body-chars.ts+++ b/mods/diff/hooks/views/detail/max-body-chars/max-body-chars.ts@@ -1,6 +1,6 @@/**- * The most characters a file's drawn body holds, its `Code` sources and- * dividers in all.+ * The most characters the drawn file bodies hold between them, their+ * `Code` sources and dividers in all.** Under the host's whole-tree cap (100 000), with room for the pane's rest.*/diff --git a/mods/diff/hooks/views/detail/max-body-nodes/max-body-nodes.ts b/mods/diff/hooks/views/detail/max-body-nodes/max-body-nodes.tsindex 8980b3e7..0969c55d 100644--- a/mods/diff/hooks/views/detail/max-body-nodes/max-body-nodes.ts+++ b/mods/diff/hooks/views/detail/max-body-nodes/max-body-nodes.ts@@ -1,7 +1,8 @@/**- * The most nodes a file's drawn body holds, a `Code` one and a divider two.+ * The most nodes the drawn file bodies hold between them, a hunk's `Code`+ * one, a file's frame FILE_FRAME_NODES.*- * Under the host's whole-tree cap (2 000), with room for the list and the- * pane's rest.+ * Under the host's whole-tree cap (2 000), with room for the list, the+ * pre-session legend and the pane's rest.*/-export const MAX_BODY_NODES = 1_200+export const MAX_BODY_NODES = 1_500diff --git a/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts b/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.tsindex 0ae29a76..406efcdd 100644--- a/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts+++ b/mods/diff/hooks/views/detail/placeholder-of/placeholder-of.ts@@ -9,7 +9,7 @@ import { SAFE_PATHSPEC_PATTERN } from './safe-pathspec-pattern'* letters, digits and `._/@+-`), binary, loading, unreadable, large, or* empty.*- * @param detail the selected file+ * @param detail the file* @returns the lines, or null*/export function placeholderOf(detail: DetailModel): readonly string[] | null {@@ -24,11 +24,11 @@ export function placeholderOf(detail: DetailModel): readonly string[] | null {return ['Binary file - cannot display diff']}- if (detail.bodyState === 'idle' || detail.bodyState === 'loading') {+ if (detail.body === undefined) {return ['Loading diff…']}- if (detail.bodyState === 'failed' || !detail.body) {+ if (detail.body === null) {return ['Diff unavailable']}diff --git a/mods/diff/hooks/views/detail/types/body-room/body-room.ts b/mods/diff/hooks/views/detail/types/body-room/body-room.tsnew file mode 100644index 00000000..5b8632ab--- /dev/null+++ b/mods/diff/hooks/views/detail/types/body-room/body-room.ts@@ -0,0 +1,8 @@+/**+ * What is left of the pane's budget for file bodies: characters of `Code`+ * source and tree nodes, both counted as the host counts a tree.+ */+export type BodyRoom = {+ chars: number+ nodes: number+}diff --git a/mods/diff/hooks/views/detail/types/body-room/index.ts b/mods/diff/hooks/views/detail/types/body-room/index.tsnew file mode 100644index 00000000..3ca015ea--- /dev/null+++ b/mods/diff/hooks/views/detail/types/body-room/index.ts@@ -0,0 +1,3 @@+export type * from './body-room.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/detail/types/code-block/code-block.ts b/mods/diff/hooks/views/detail/types/code-block/code-block.tsdeleted file mode 100644index 953360d7..00000000--- a/mods/diff/hooks/views/detail/types/code-block/code-block.ts+++ /dev/null@@ -1,8 +0,0 @@-/**- * One `Code` element of a file's body: its unified-diff source, and whether- * a divider stands above it (it opens a hunk after another block).- */-export type CodeBlock = {- source: string- hasDivider: boolean-}diff --git a/mods/diff/hooks/views/detail/types/code-block/index.ts b/mods/diff/hooks/views/detail/types/code-block/index.tsdeleted file mode 100644index dd3f6adf..00000000--- a/mods/diff/hooks/views/detail/types/code-block/index.ts+++ /dev/null@@ -1,3 +0,0 @@-export type * from './code-block.js'--export * as default from '.'diff --git a/mods/diff/hooks/views/detail/types/code-body/code-body.ts b/mods/diff/hooks/views/detail/types/code-body/code-body.tsindex 7706a3a8..cb52a965 100644--- a/mods/diff/hooks/views/detail/types/code-body/code-body.ts+++ b/mods/diff/hooks/views/detail/types/code-body/code-body.ts@@ -1,10 +1,11 @@-import type { CodeBlock } from '../code-block'+import type { BodyRoom } from '../body-room'/**- * A file's hunks as the body draws them: the `Code` blocks in order, and- * whether the body's budget or a source's cap left any of a line out.+ * A file's hunks as the body draws them: one `Code` source per hunk in+ * order, whether any of a line was left out, and the room after them.*/export type CodeBody = {- blocks: readonly CodeBlock[]+ sources: readonly string[]isTruncated: boolean+ room: BodyRoom}diff --git a/mods/diff/hooks/views/detail/types/detail-draw/detail-draw.ts b/mods/diff/hooks/views/detail/types/detail-draw/detail-draw.tsnew file mode 100644index 00000000..6161bd00--- /dev/null+++ b/mods/diff/hooks/views/detail/types/detail-draw/detail-draw.ts@@ -0,0 +1,14 @@+import type { BodyRoom } from '../body-room'++/**+ * What drawing one file's detail takes besides the file: the room the+ * pane's bodies have left, and the press that arms or disarms its ask.+ */+export type DetailDraw = {+ room: BodyRoom++ /**+ * Arms the file for the next prompt, or disarms it.+ */+ onToggleAsk: () => void+}diff --git a/mods/diff/hooks/views/detail/types/detail-draw/index.ts b/mods/diff/hooks/views/detail/types/detail-draw/index.tsnew file mode 100644index 00000000..6c463cbd--- /dev/null+++ b/mods/diff/hooks/views/detail/types/detail-draw/index.ts@@ -0,0 +1,3 @@+export type * from './detail-draw.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/detail/types/drawn-detail/drawn-detail.ts b/mods/diff/hooks/views/detail/types/drawn-detail/drawn-detail.tsnew file mode 100644index 00000000..c831c8f3--- /dev/null+++ b/mods/diff/hooks/views/detail/types/drawn-detail/drawn-detail.ts@@ -0,0 +1,11 @@+import type { RenderElement } from 'claude-code'++import type { BodyRoom } from '../body-room'++/**+ * One file's detail as drawn, and the room left for the files after it.+ */+export type DrawnDetail = {+ element: RenderElement+ room: BodyRoom+}diff --git a/mods/diff/hooks/views/detail/types/drawn-detail/index.ts b/mods/diff/hooks/views/detail/types/drawn-detail/index.tsnew file mode 100644index 00000000..2baa5aab--- /dev/null+++ b/mods/diff/hooks/views/detail/types/drawn-detail/index.ts@@ -0,0 +1,3 @@+export type * from './drawn-detail.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/detail/types/index.ts b/mods/diff/hooks/views/detail/types/index.tsindex d36f9e46..adf880c0 100644--- a/mods/diff/hooks/views/detail/types/index.ts+++ b/mods/diff/hooks/views/detail/types/index.ts@@ -1,4 +1,6 @@-export * from './code-block'+export * from './body-room'export * from './code-body'+export * from './detail-draw'+export * from './drawn-detail'export * as default from '.'diff --git a/mods/diff/hooks/views/entries/body-entry-of/body-entry-of.ts b/mods/diff/hooks/views/entries/body-entry-of/body-entry-of.tsnew file mode 100644index 00000000..e2c9ba4b--- /dev/null+++ b/mods/diff/hooks/views/entries/body-entry-of/body-entry-of.ts@@ -0,0 +1,24 @@+import Git from '../../../git'+import type PaneState from '../../../pane-state'+import type { BodyEntry } from '../body-entry'++/**+ * A fetched row as the pane draws it, its body looked up in what the pane+ * has read.+ *+ * @param file the row+ * @param model the pane's state, holding the bodies read so far+ * @returns the entry+ */+export const bodyEntryOf = (+ file: Git.FileStat,+ model: Pick<PaneState.PaneModel, 'bodies'>,+): BodyEntry => ({+ path: file.path,+ displayPath: Git.displayPathOf(file),+ added: file.added,+ removed: file.removed,+ isUntracked: file.isUntracked,+ isBinary: file.isBinary,+ body: model.bodies.get(file.path),+})diff --git a/mods/diff/hooks/views/entries/body-entry-of/index.ts b/mods/diff/hooks/views/entries/body-entry-of/index.tsnew file mode 100644index 00000000..2fae4424--- /dev/null+++ b/mods/diff/hooks/views/entries/body-entry-of/index.ts@@ -0,0 +1,3 @@+export * from './body-entry-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/entries/body-entry/body-entry.ts b/mods/diff/hooks/views/entries/body-entry/body-entry.tsnew file mode 100644index 00000000..f90261e1--- /dev/null+++ b/mods/diff/hooks/views/entries/body-entry/body-entry.ts@@ -0,0 +1,15 @@+import type Git from '../../../git'++/**+ * One file as the pane lists and draws it: its row's counts and name, its+ * kind, and its hunks so far (undefined loading, null unreadable).+ */+export type BodyEntry = {+ path: string+ displayPath: string+ added: number+ removed: number+ isUntracked: boolean+ isBinary: boolean+ body: Git.FileHunks | null | undefined+}diff --git a/mods/diff/hooks/views/entries/body-entry/index.ts b/mods/diff/hooks/views/entries/body-entry/index.tsnew file mode 100644index 00000000..57e0a215--- /dev/null+++ b/mods/diff/hooks/views/entries/body-entry/index.ts@@ -0,0 +1,3 @@+export type * from './body-entry.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/entries/detail-model-of/detail-model-of.ts b/mods/diff/hooks/views/entries/detail-model-of/detail-model-of.tsnew file mode 100644index 00000000..f6f21bf6--- /dev/null+++ b/mods/diff/hooks/views/entries/detail-model-of/detail-model-of.ts@@ -0,0 +1,24 @@+import type PaneState from '../../../pane-state'+import type Detail from '../../detail'+import type { BodyEntry } from '../body-entry'++/**+ * A listed file as its detail draws it: the entry, whether it is the armed+ * one, and the backend's words for its notes.+ *+ * @param entry the file+ * @param model which file is armed, and the backend's words+ * @returns the detail model+ */+export const detailModelOf = (+ entry: BodyEntry,+ model: Pick<PaneState.PaneModel, 'armedPath' | 'words'>,+): Detail.DetailModel => ({+ words: model.words,+ path: entry.path,+ displayPath: entry.displayPath,+ isUntracked: entry.isUntracked,+ isBinary: entry.isBinary,+ body: entry.body,+ isArmed: model.armedPath === entry.path,+})diff --git a/mods/diff/hooks/views/entries/detail-model-of/index.ts b/mods/diff/hooks/views/entries/detail-model-of/index.tsnew file mode 100644index 00000000..de2d84c5--- /dev/null+++ b/mods/diff/hooks/views/entries/detail-model-of/index.ts@@ -0,0 +1,3 @@+export * from './detail-model-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/entries/index.ts b/mods/diff/hooks/views/entries/index.tsnew file mode 100644index 00000000..c0fbc61e--- /dev/null+++ b/mods/diff/hooks/views/entries/index.ts@@ -0,0 +1,6 @@+export * from './body-entry'+export * from './body-entry-of'+export * from './detail-model-of'+export * from './turn-entry-of'++export * as default from '.'diff --git a/mods/diff/hooks/views/entries/turn-entry-of/index.ts b/mods/diff/hooks/views/entries/turn-entry-of/index.tsnew file mode 100644index 00000000..626047cf--- /dev/null+++ b/mods/diff/hooks/views/entries/turn-entry-of/index.ts@@ -0,0 +1,3 @@+export * from './turn-entry-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/entries/turn-entry-of/turn-entry-of.ts b/mods/diff/hooks/views/entries/turn-entry-of/turn-entry-of.tsnew file mode 100644index 00000000..92210d02--- /dev/null+++ b/mods/diff/hooks/views/entries/turn-entry-of/turn-entry-of.ts@@ -0,0 +1,19 @@+import type Turns from '../../../turns'+import type { BodyEntry } from '../body-entry'++/**+ * A turn's file as the pane draws it: its hunks come from the transcript,+ * so its body is always in hand.+ *+ * @param file the turn's file+ * @returns the entry+ */+export const turnEntryOf = (file: Turns.TurnFile): BodyEntry => ({+ path: file.path,+ displayPath: file.path,+ added: file.added,+ removed: file.removed,+ isUntracked: false,+ isBinary: false,+ body: { hunks: file.hunks, isTruncated: file.isTruncated, isLarge: false },+})diff --git a/mods/diff/hooks/views/index.ts b/mods/diff/hooks/views/index.tsindex fa2aa8f1..d0620904 100644--- a/mods/diff/hooks/views/index.ts+++ b/mods/diff/hooks/views/index.ts@@ -1,11 +1,16 @@export * from './current-pane'export * from './detail'+export * from './entries'export * from './inset-of'export * from './kit'export * from './layout'export * from './pane-actions'+export * from './pane-seat'export * from './pane-view.jsx'+export * from './prelude-of'export * from './sections'+export * from './selected-detail-of'+export * from './sidebar-pane'export * from './turn-pane'export * as default from '.'diff --git a/mods/diff/hooks/views/layout/index.ts b/mods/diff/hooks/views/layout/index.tsindex b9c5deb5..520e4ad4 100644--- a/mods/diff/hooks/views/layout/index.ts+++ b/mods/diff/hooks/views/layout/index.ts@@ -1,5 +1,6 @@export * from './cell-width'export * from './charged-width'+export * from './pad-end'export * from './plural'export * from './sanitize-line'export * from './sanitize-name'diff --git a/mods/diff/hooks/views/layout/pad-end/index.ts b/mods/diff/hooks/views/layout/pad-end/index.tsnew file mode 100644index 00000000..aa07fddf--- /dev/null+++ b/mods/diff/hooks/views/layout/pad-end/index.ts@@ -0,0 +1,3 @@+export * from './pad-end.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/layout/pad-end/pad-end.ts b/mods/diff/hooks/views/layout/pad-end/pad-end.tsnew file mode 100644index 00000000..bca69de6--- /dev/null+++ b/mods/diff/hooks/views/layout/pad-end/pad-end.ts@@ -0,0 +1,12 @@+import { chargedWidth } from '../charged-width'++/**+ * A sanitized text with spaces after it up to a width in cells, counted by+ * chargedWidth; unchanged when it is that wide already.+ *+ * @param text the text+ * @param cells the width to reach+ * @returns the padded text+ */+export const padEnd = (text: string, cells: number) =>+ `${text}${' '.repeat(Math.max(0, cells - chargedWidth(text)))}`diff --git a/mods/diff/hooks/views/pane-actions/pane-actions.ts b/mods/diff/hooks/views/pane-actions/pane-actions.tsindex 5e505dd5..8d35d5f8 100644--- a/mods/diff/hooks/views/pane-actions/pane-actions.ts+++ b/mods/diff/hooks/views/pane-actions/pane-actions.ts@@ -4,7 +4,8 @@*/export type PaneActions = {/**- * Shows this file's body under the list.+ * Docked, scrolls the body to this file's hunks; inline, selects the file+ * so its body shows under the list.*/selectFile: (path: string) => void@@ -33,10 +34,4 @@ export type PaneActions = {* Arms this file's diff for the next prompt, or disarms it.*/toggleAsk: (path: string) => void-- /**- * Closes the pane as `/diff` closes it, the choice kept for the next- * first edit.- */- close: () => void}diff --git a/mods/diff/hooks/views/pane-seat/index.ts b/mods/diff/hooks/views/pane-seat/index.tsnew file mode 100644index 00000000..e42ed895--- /dev/null+++ b/mods/diff/hooks/views/pane-seat/index.ts@@ -0,0 +1,3 @@+export type * from './pane-seat.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/pane-seat/pane-seat.ts b/mods/diff/hooks/views/pane-seat/pane-seat.tsnew file mode 100644index 00000000..2b735254--- /dev/null+++ b/mods/diff/hooks/views/pane-seat/pane-seat.ts@@ -0,0 +1,11 @@+/**+ * Where the surface put the pane for one drawing (`props.placement`), and+ * how wide the terminal is (`viewport.columns`; null before it measured).+ *+ * Inline on a terminal the dock would fit (OPEN_MIN_COLUMNS) means the+ * session draws no fullscreen layout, where the built-in shows its dialog.+ */+export type PaneSeat = {+ placement: 'dock' | 'inline'+ terminalColumns: number | null+}diff --git a/mods/diff/hooks/views/pane-view.tsx b/mods/diff/hooks/views/pane-view.tsxindex 81dde4fa..3f0a983e 100644--- a/mods/diff/hooks/views/pane-view.tsx+++ b/mods/diff/hooks/views/pane-view.tsx@@ -9,44 +9,53 @@ import PaneState from '../pane-state'import { currentPane } from './current-pane'import { insetOf } from './inset-of'import type { Kit } from './kit'+import type { PaneSeat } from './pane-seat'import Sections from './sections'+import { sidebarPane } from './sidebar-pane'import { turnPane } from './turn-pane'/**- * The diff pane's body for one `ui.render`: the repository's diff now, or- * the picked turn's edits while that turn still exists (a rewind drops it).+ * The diff pane's body for one `ui.render`: docked, the built-in panel's+ * layout (sidebarPane); inline, its dialog's, or its wider-terminal line.*- * Seated inline, only the built-in's wider-terminal line, as it shows no- * panel there; docked, the built-in's blank row above the header and blank- * last column, so rows sit and wrap where the built-in's do.+ * Inline for want of width (under OPEN_MIN_COLUMNS) the built-in shows no+ * panel, only that line; inline on a wider terminal there is no fullscreen+ * layout, where it shows its dialog. Docked, its blank top row and column.** @param kit the elements, the handlers, the width* @param model the pane's state- * @param placement where the surface seated the pane (`props.placement`)+ * @param seat where the surface seated the pane, and the terminal's width* @returns the tree*/export function paneView(kit: Kit,model: PaneState.PaneModel,- placement: 'dock' | 'inline',+ seat: PaneSeat,): RenderElement {const { Box } = kit.ui- const turn = PaneState.pickedTurnOf(model)- const isCurrent = turn === undefined+ const isDocked = seat.placement === 'dock'- if (placement === 'inline') {- return <Box>{Sections.dimNote(kit, Names.RESIZE_TERMINAL_TEXT)}</Box>- }+ const isNarrow =+ seat.terminalColumns !== null &&+ seat.terminalColumns < Limits.OPEN_MIN_COLUMNS++ function dialogOf(): RenderElement {+ const turn = PaneState.pickedTurnOf(model)- const inset = insetOf(kit)+ return turn ? turnPane(kit, model, turn) : currentPane(kit, model)+ }- return (+ return isDocked ? (<BoxflexDirection="column"paddingTop={Limits.PANE_TOP_PAD_ROWS}paddingRight={Limits.PANE_RIGHT_PAD_COLUMNS}>- {isCurrent ? currentPane(inset, model) : turnPane(inset, model, turn)}+ {sidebarPane(insetOf(kit), model)}</Box>+ ) : isNarrow ? (+ <Box>{Sections.dimNote(kit, Names.RESIZE_TERMINAL_TEXT)}</Box>+ ) : (+ <Box flexDirection="column">{dialogOf()}</Box>)}diff --git a/mods/diff/hooks/views/prelude-of/index.ts b/mods/diff/hooks/views/prelude-of/index.tsnew file mode 100644index 00000000..aabd6997--- /dev/null+++ b/mods/diff/hooks/views/prelude-of/index.ts@@ -0,0 +1,3 @@+export * from './prelude-of.jsx'++export * as default from '.'diff --git a/mods/diff/hooks/views/prelude-of/prelude-of.tsx b/mods/diff/hooks/views/prelude-of/prelude-of.tsxnew file mode 100644index 00000000..30a114fe--- /dev/null+++ b/mods/diff/hooks/views/prelude-of/prelude-of.tsx@@ -0,0 +1,48 @@+/* @jsxRuntime classic */+/* @jsx h */+/* @jsxFrag Fragment */+import type { RenderElement } from 'claude-code'++import Names from '../../names'+import type PaneState from '../../pane-state'+import CurrentPane from '../current-pane'+import type { Kit } from '../kit'+import Sections from '../sections'++/**+ * What the pane draws before it has a diff to lay out: the line saying the+ * directory is in no repository, or the first fetch's `Loading diff…`.+ *+ * Null once a fetch settled (or a turn is picked), when the layout draws.+ *+ * @param kit the elements, the width, the rows+ * @param model the pane's state+ * @returns the early tree, or null+ */+export function preludeOf(+ kit: Kit,+ model: Pick<+ PaneState.PaneModel,+ 'isOutsideRepository' | 'data' | 'hasSettled' | 'source' | 'turns'+ >,+): RenderElement | null {+ const { Box } = kit.ui+ const isLoading = model.data === null && !model.hasSettled++ const outside = (+ <Box>{Sections.dimNote(kit, Names.NOT_IN_REPOSITORY_TEXT)}</Box>+ )++ const loadingOf = (): RenderElement =>+ CurrentPane.messagePaneOf(kit, {+ top: [Sections.headerView(kit, null, null)],+ message: ['Loading diff…'],+ controls: null,+ earlier: null,+ rest: [],+ })++ const settled = isLoading ? loadingOf() : null++ return model.isOutsideRepository ? outside : settled+}diff --git a/mods/diff/hooks/views/sections/ask-key-of/ask-key-of.ts b/mods/diff/hooks/views/sections/ask-key-of/ask-key-of.tsnew file mode 100644index 00000000..b8354567--- /dev/null+++ b/mods/diff/hooks/views/sections/ask-key-of/ask-key-of.ts@@ -0,0 +1,10 @@+import Layout from '../../layout'++/**+ * A file's ask Button address: the path made printable, under `ask:`, so+ * each file's Button in the body has its own.+ *+ * @param path the file's path as git or the transcript gave it+ * @returns the key+ */+export const askKeyOf = (path: string) => `ask:${Layout.sanitizeName(path)}`diff --git a/mods/diff/hooks/views/sections/ask-key-of/index.ts b/mods/diff/hooks/views/sections/ask-key-of/index.tsnew file mode 100644index 00000000..7d6b428c--- /dev/null+++ b/mods/diff/hooks/views/sections/ask-key-of/index.ts@@ -0,0 +1,3 @@+export * from './ask-key-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/body-key-of/body-key-of.ts b/mods/diff/hooks/views/sections/body-key-of/body-key-of.tsnew file mode 100644index 00000000..ce08eaec--- /dev/null+++ b/mods/diff/hooks/views/sections/body-key-of/body-key-of.ts@@ -0,0 +1,10 @@+import Layout from '../../layout'++/**+ * The key of a file's block in the docked body, under `body:`: what a row's+ * press scrolls to (`$.ui.scroll({ to: { key } })`).+ *+ * @param path the file's path as git or the transcript gave it+ * @returns the key+ */+export const bodyKeyOf = (path: string) => `body:${Layout.sanitizeName(path)}`diff --git a/mods/diff/hooks/views/sections/body-key-of/index.ts b/mods/diff/hooks/views/sections/body-key-of/index.tsnew file mode 100644index 00000000..4974e437--- /dev/null+++ b/mods/diff/hooks/views/sections/body-key-of/index.ts@@ -0,0 +1,3 @@+export * from './body-key-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/close-button/close-button.tsx b/mods/diff/hooks/views/sections/close-button/close-button.tsxdeleted file mode 100644index 3a8cc7fc..00000000--- a/mods/diff/hooks/views/sections/close-button/close-button.tsx+++ /dev/null@@ -1,33 +0,0 @@-/* @jsxRuntime classic */-/* @jsx h */-/* @jsxFrag Fragment */-import type { RenderElement } from 'claude-code'--import type { Kit } from '../../kit'--/**- * The pane's close control (ReplDiffSidebar's PanelCloseButton): a `✕` at- * the header's right edge that closes the pane as `/diff` does.- *- * Bold under the pointer, as the built-in's is. The built-in's rest style,- * dim, is not a Button's to take: its label's only style is `hover`.- *- * @param kit the drawing's kit; its handlers close the pane- * @returns the control, in the keyed Box its hover needs- */-export function closeButton(kit: Kit): RenderElement {- const { Box, Button } = kit.ui-- return (- <Box key="close">- <Button- key="close"- plain- hover={{ bold: true }}- onPress={kit.actions.close}- >- {'✕'}- </Button>- </Box>- )-}diff --git a/mods/diff/hooks/views/sections/close-button/index.ts b/mods/diff/hooks/views/sections/close-button/index.tsdeleted file mode 100644index 92f8d806..00000000--- a/mods/diff/hooks/views/sections/close-button/index.ts+++ /dev/null@@ -1,3 +0,0 @@-export * from './close-button.jsx'--export * as default from '.'diff --git a/mods/diff/hooks/views/sections/controls-view.tsx b/mods/diff/hooks/views/sections/controls-view.tsxindex 006b4afb..7b1fe027 100644--- a/mods/diff/hooks/views/sections/controls-view.tsx+++ b/mods/diff/hooks/views/sections/controls-view.tsx@@ -3,7 +3,7 @@/* @jsxFrag Fragment */import type { RenderElement } from 'claude-code'-import type PaneState from '../../pane-state'+import PaneState from '../../pane-state'import type { Kit } from '../kit'import { present } from './present'@@ -13,7 +13,7 @@ import { present } from './present'** The source picker draws only when a turn exists, as DiffDialog hides its* tabs; the base picker is ctrl+x b's cycle as a Select over the backend's- * modes, uncommitted naming the base as the base line does (modeLabelOf).+ * modes, each worded as the built-in's base line (modeLabelOf) it replaces.** @param kit the elements and the handlers* @param model what is picked now and the turns to pick from@@ -47,26 +47,15 @@ export function controlsView() : nullconst isCurrent = source.kind === 'current'- const fetchedSource = model.data?.source- const isWorkingTree = fetchedSource?.kind === 'working-tree'- const base = isWorkingTree ? fetchedSource.base : model.words.baseconst basePicker = isCurrent ? (<Selectkey="base"label="base"- options={model.baseModes.map(mode => {- const isUncommitted = mode === 'uncommitted'- const isSession = mode === 'session'-- const label = isUncommitted- ? `uncommitted (vs ${base})`- : isSession- ? 'this session'- : mode-- return { value: mode, label }- })}+ options={model.baseModes.map(mode => ({+ value: mode,+ label: PaneState.modeLabelOf(mode, model),+ }))}value={model.requestedMode}onSelect={value => kit.actions.chooseBase(value)}/>diff --git a/mods/diff/hooks/views/sections/file-row/file-row.tsx b/mods/diff/hooks/views/sections/dialog-file-row/dialog-file-row.tsxsimilarity index 56%rename from mods/diff/hooks/views/sections/file-row/file-row.tsxrename to mods/diff/hooks/views/sections/dialog-file-row/dialog-file-row.tsxindex 6ff7f374..2b7988df 100644--- a/mods/diff/hooks/views/sections/file-row/file-row.tsx+++ b/mods/diff/hooks/views/sections/dialog-file-row/dialog-file-row.tsx@@ -5,30 +5,31 @@ import type { RenderElement } from 'claude-code'import type { Kit } from '../../kit'import Layout from '../../layout'+import { DIALOG_PATH_FLOOR } from '../dialog-path-floor'+import { DIALOG_PATH_RESERVE } from '../dialog-path-reserve'import { diffStat } from '../diff-stat'import type { FileRowModel } from '../file-row-model'+import { listRow } from '../list-row'import { POINTER } from '../pointer'-import { STAT_CELLS } from '../stat-cells'/**- * One file of the list (ReplDiffSidebar FileSummaryRow): a plain Button- * with the start-truncated path, its counts or note at the right.- *- * The pointer marks the selected one.+ * One file of the inline list (DiffFileList FileItem): the pointer before+ * the selected one, the start-truncated name, its counts or note right.** @param kit the elements, the handlers, the width* @param row the file* @param onPress selects the file* @returns the row element*/-export function fileRow(+export function dialogFileRow(kit: Kit,row: FileRowModel,onPress: () => void,): RenderElement {- const { Box, Text, Button } = kit.ui- const room = Math.max(kit.columns - STAT_CELLS, STAT_CELLS)+ const { Text } = kit.ui+ const room = Math.max(DIALOG_PATH_FLOOR, kit.columns - DIALOG_PATH_RESERVE)const mark = row.isSelected ? POINTER : ' '+ const name = Layout.truncateStart(Layout.sanitizeName(row.displayPath), room)const note = (<Text dimColor italic>@@ -39,13 +40,5 @@ export function fileRow(const hasNote = row.note !== nullconst tail = hasNote ? note : diffStat(kit, row.added, row.removed)- return (- <Box flexDirection="row">- <Button key={row.key} plain onPress={onPress}>- {`${mark} ${Layout.truncateStart(Layout.sanitizeName(row.path), room)}`}- </Button>- <Box flexGrow={1} />- {tail}- </Box>- )+ return listRow(kit, { key: row.key, label: `${mark} ${name}`, onPress }, tail)}diff --git a/mods/diff/hooks/views/sections/dialog-file-row/index.ts b/mods/diff/hooks/views/sections/dialog-file-row/index.tsnew file mode 100644index 00000000..4e60674b--- /dev/null+++ b/mods/diff/hooks/views/sections/dialog-file-row/index.ts@@ -0,0 +1,3 @@+export * from './dialog-file-row.jsx'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/dialog-path-floor/dialog-path-floor.ts b/mods/diff/hooks/views/sections/dialog-path-floor/dialog-path-floor.tsnew file mode 100644index 00000000..2ec5a384--- /dev/null+++ b/mods/diff/hooks/views/sections/dialog-path-floor/dialog-path-floor.ts@@ -0,0 +1,5 @@+/**+ * The fewest cells an inline file row gives its path, however narrow the+ * pane (DiffFileList's 20).+ */+export const DIALOG_PATH_FLOOR = 20diff --git a/mods/diff/hooks/views/sections/dialog-path-floor/index.ts b/mods/diff/hooks/views/sections/dialog-path-floor/index.tsnew file mode 100644index 00000000..618af5dc--- /dev/null+++ b/mods/diff/hooks/views/sections/dialog-path-floor/index.ts@@ -0,0 +1,3 @@+export * from './dialog-path-floor.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/dialog-path-reserve/dialog-path-reserve.ts b/mods/diff/hooks/views/sections/dialog-path-reserve/dialog-path-reserve.tsnew file mode 100644index 00000000..ada8ca20--- /dev/null+++ b/mods/diff/hooks/views/sections/dialog-path-reserve/dialog-path-reserve.ts@@ -0,0 +1,5 @@+/**+ * The cells an inline file row keeps off its path (DiffFileList's 16 for+ * the counts, 3 for the pointer, 4 for the frame).+ */+export const DIALOG_PATH_RESERVE = 23diff --git a/mods/diff/hooks/views/sections/dialog-path-reserve/index.ts b/mods/diff/hooks/views/sections/dialog-path-reserve/index.tsnew file mode 100644index 00000000..55e2f8ad--- /dev/null+++ b/mods/diff/hooks/views/sections/dialog-path-reserve/index.ts@@ -0,0 +1,3 @@+export * from './dialog-path-reserve.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/file-row-model/file-row-model.ts b/mods/diff/hooks/views/sections/file-row-model/file-row-model.tsindex 541f1a1d..482a71cc 100644--- a/mods/diff/hooks/views/sections/file-row-model/file-row-model.ts+++ b/mods/diff/hooks/views/sections/file-row-model/file-row-model.ts@@ -1,10 +1,11 @@/**- * One listed file as its row draws it: the Button's address, the path, the- * counts or a dim note in their place, and whether its body shows.+ * One listed file as its row draws it: the Button's address, the path and+ * the name listed, the counts or (inline) a dim note for them, selection.*/export type FileRowModel = {key: stringpath: string+ displayPath: stringadded: numberremoved: numbernote: string | nulldiff --git a/mods/diff/hooks/views/sections/file-row/file-row.ts b/mods/diff/hooks/views/sections/file-row/file-row.tsnew file mode 100644index 00000000..e833ae5a--- /dev/null+++ b/mods/diff/hooks/views/sections/file-row/file-row.ts@@ -0,0 +1,42 @@+import type { RenderElement } from 'claude-code'++import type { Kit } from '../../kit'+import Layout from '../../layout'+import { diffStat } from '../diff-stat'+import type { FileRowModel } from '../file-row-model'+import { listRow } from '../list-row'+import { PATH_FLOOR } from '../path-floor'+import { STAT_CELLS } from '../stat-cells'+import { statTextOf } from '../stat-text-of'++/**+ * One file of the docked list (ReplDiffSidebar FileSummaryRow): the+ * start-truncated name as a plain Button, its counts at the right.+ *+ * Nothing at the right at 0/0 (an untracked or binary file). The label is+ * padded up to the counts, so the whole row before them presses.+ *+ * @param kit the elements, the handlers, the width+ * @param row the file+ * @param onPress scrolls the body to the file+ * @returns the row element+ */+export function fileRow(+ kit: Kit,+ row: FileRowModel,+ onPress: () => void,+): RenderElement {+ const label = Layout.padEnd(+ Layout.truncateStart(+ Layout.sanitizeName(row.displayPath),+ Math.max(kit.columns - STAT_CELLS, PATH_FLOOR),+ ),+ kit.columns - statTextOf(row.added, row.removed).length,+ )++ return listRow(+ kit,+ { key: row.key, label, onPress },+ diffStat(kit, row.added, row.removed),+ )+}diff --git a/mods/diff/hooks/views/sections/file-row/index.ts b/mods/diff/hooks/views/sections/file-row/index.tsindex 2e7f25d4..1394b6f6 100644--- a/mods/diff/hooks/views/sections/file-row/index.ts+++ b/mods/diff/hooks/views/sections/file-row/index.ts@@ -1,3 +1,3 @@-export * from './file-row.jsx'+export * from './file-row.js'export * as default from '.'diff --git a/mods/diff/hooks/views/sections/header-view.tsx b/mods/diff/hooks/views/sections/header-view.tsxindex ee10e5bf..a8dd0d0d 100644--- a/mods/diff/hooks/views/sections/header-view.tsx+++ b/mods/diff/hooks/views/sections/header-view.tsx@@ -6,40 +6,39 @@ import type { RenderElement } from 'claude-code'import type PaneState from '../../pane-state'import type { Kit } from '../kit'import Layout from '../layout'-import { closeButton } from './close-button'import { diffStat } from './diff-stat'+import { present } from './present'/*** The pane's first line (ReplDiffSidebar's header row): `N files changed- * +A -R`, or nothing over an empty state.+ * +A -R`, nothing over an empty state, and the pickers at its right edge.*- * The close `✕` sits at the right edge either way.+ * The pickers sit where the built-in draws its close mark, so every row+ * below lands where the built-in's does; this pane's mark is the engine's.** @param kit the drawing's kit; its elements draw the line* @param totals the header's counts, or null when there is nothing to count+ * @param controls the pickers (Sections.controlsView), or null for none* @returns the line*/export function headerView(kit: Kit,totals: PaneState.HeaderTotals | null,+ controls: RenderElement | null,): RenderElement {const { Box, Text } = kit.ui+ const countOf = (counted: PaneState.HeaderTotals): RenderElement => (+ <Text wrap="truncate-end">+ <Text bold>{Layout.plural(counted.filesCount, 'file')}</Text>+ {' changed '}+ {diffStat(kit, counted.linesAdded, counted.linesRemoved)}+ </Text>+ )+return (- <Box flexDirection="row">- {[- ...(totals- ? [- <Text wrap="truncate-end">- <Text bold>{Layout.plural(totals.filesCount, 'file')}</Text>- {' changed '}- {diffStat(kit, totals.linesAdded, totals.linesRemoved)}- </Text>,- ]- : []),- <Box flexGrow={1} />,- closeButton(kit),- ]}+ <Box flexDirection="row" height={1}>+ {present([totals && countOf(totals), <Box flexGrow={1} />, controls])}</Box>)}diff --git a/mods/diff/hooks/views/sections/index.ts b/mods/diff/hooks/views/sections/index.tsindex 8e8c4c46..d56a8ba2 100644--- a/mods/diff/hooks/views/sections/index.ts+++ b/mods/diff/hooks/views/sections/index.ts@@ -1,5 +1,9 @@-export * from './close-button'+export * from './ask-key-of'+export * from './body-key-of'export * from './controls-view.jsx'+export * from './dialog-file-row'+export * from './dialog-path-floor'+export * from './dialog-path-reserve'export * from './diff-stat'export * from './dim-note'export * from './divider.jsx'@@ -7,10 +11,15 @@ export * from './file-key-of'export * from './file-row'export * from './file-row-model'export * from './header-view.jsx'+export * from './keyed-pressable'+export * from './list-row'+export * from './path-floor'export * from './pointer'export * from './present'export * from './pressable'export * from './stat-cells'+export * from './stat-text-of'+export * from './title-row.jsx'export * from './todo-bar.jsx'export * from './todo-bar-cells'export * from './todo-bar-reserve'diff --git a/mods/diff/hooks/views/sections/keyed-pressable/index.ts b/mods/diff/hooks/views/sections/keyed-pressable/index.tsnew file mode 100644index 00000000..ddcdd6dd--- /dev/null+++ b/mods/diff/hooks/views/sections/keyed-pressable/index.ts@@ -0,0 +1,3 @@+export type * from './keyed-pressable.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/keyed-pressable/keyed-pressable.ts b/mods/diff/hooks/views/sections/keyed-pressable/keyed-pressable.tsnew file mode 100644index 00000000..621e2493--- /dev/null+++ b/mods/diff/hooks/views/sections/keyed-pressable/keyed-pressable.ts@@ -0,0 +1,8 @@+import type { Pressable } from '../pressable'++/**+ * A plain Button's face, press and address: a list row's Button.+ */+export type KeyedPressable = Pressable & {+ key: string+}diff --git a/mods/diff/hooks/views/sections/list-row/index.ts b/mods/diff/hooks/views/sections/list-row/index.tsnew file mode 100644index 00000000..0bb830e5--- /dev/null+++ b/mods/diff/hooks/views/sections/list-row/index.ts@@ -0,0 +1,3 @@+export * from './list-row.jsx'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/list-row/list-row.tsx b/mods/diff/hooks/views/sections/list-row/list-row.tsxnew file mode 100644index 00000000..3555da42--- /dev/null+++ b/mods/diff/hooks/views/sections/list-row/list-row.tsx@@ -0,0 +1,34 @@+/* @jsxRuntime classic */+/* @jsx h */+/* @jsxFrag Fragment */+import type { RenderElement } from 'claude-code'++import type { Kit } from '../../kit'+import type { KeyedPressable } from '../keyed-pressable'++/**+ * One row of a file list: a plain Button under its key, then whatever the+ * row shows at its right edge (its counts, a note).+ *+ * @param kit the elements+ * @param row the Button's key, label and press+ * @param tail the element at the right edge+ * @returns the row element+ */+export function listRow(+ kit: Kit,+ row: KeyedPressable,+ tail: RenderElement,+): RenderElement {+ const { Box, Button } = kit.ui++ return (+ <Box flexDirection="row">+ <Button key={row.key} plain onPress={row.onPress}>+ {row.label}+ </Button>+ <Box flexGrow={1} />+ {tail}+ </Box>+ )+}diff --git a/mods/diff/hooks/views/sections/path-floor/index.ts b/mods/diff/hooks/views/sections/path-floor/index.tsnew file mode 100644index 00000000..c5c14fbf--- /dev/null+++ b/mods/diff/hooks/views/sections/path-floor/index.ts@@ -0,0 +1,3 @@+export * from './path-floor.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/path-floor/path-floor.ts b/mods/diff/hooks/views/sections/path-floor/path-floor.tsnew file mode 100644index 00000000..630017b6--- /dev/null+++ b/mods/diff/hooks/views/sections/path-floor/path-floor.ts@@ -0,0 +1,5 @@+/**+ * The fewest cells a docked file row gives its path, however narrow the+ * pane (ReplDiffSidebar's 8).+ */+export const PATH_FLOOR = 8diff --git a/mods/diff/hooks/views/sections/present/present.ts b/mods/diff/hooks/views/sections/present/present.tsindex 04f8a099..2332d640 100644--- a/mods/diff/hooks/views/sections/present/present.ts+++ b/mods/diff/hooks/views/sections/present/present.ts@@ -1,5 +1,7 @@import type { RenderElement } from 'claude-code'+import { keptOf } from '../../../kept-of'+/*** The children that are there: nulls dropped, so a part may answer null for* "nothing to draw" and the parent lists it all the same.@@ -9,5 +11,4 @@ import type { RenderElement } from 'claude-code'*/export const present = (children: readonly (RenderElement | null)[],-): RenderElement[] =>- children.filter((child): child is RenderElement => child !== null)+): RenderElement[] => keptOf(children)diff --git a/mods/diff/hooks/views/sections/stat-cells/stat-cells.ts b/mods/diff/hooks/views/sections/stat-cells/stat-cells.tsindex 133ba8a4..4bc6692b 100644--- a/mods/diff/hooks/views/sections/stat-cells/stat-cells.ts+++ b/mods/diff/hooks/views/sections/stat-cells/stat-cells.ts@@ -1,5 +1,5 @@/**- * The cells a file row keeps for its `+N -M` (ReplDiffSidebar's 12) and the- * selection pointer before the path.+ * The cells a docked file row keeps for its `+N -M` (ReplDiffSidebar's 12):+ * the path is cut from its start to the rest.*/-export const STAT_CELLS = 14+export const STAT_CELLS = 12diff --git a/mods/diff/hooks/views/sections/stat-text-of/index.ts b/mods/diff/hooks/views/sections/stat-text-of/index.tsnew file mode 100644index 00000000..11204da2--- /dev/null+++ b/mods/diff/hooks/views/sections/stat-text-of/index.ts@@ -0,0 +1,3 @@+export * from './stat-text-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sections/stat-text-of/stat-text-of.ts b/mods/diff/hooks/views/sections/stat-text-of/stat-text-of.tsnew file mode 100644index 00000000..a5ff21ff--- /dev/null+++ b/mods/diff/hooks/views/sections/stat-text-of/stat-text-of.ts@@ -0,0 +1,15 @@+import { keptOf } from '../../../kept-of'++/**+ * `+N -M` as diffStat draws it, as plain text: what a row measures to know+ * where its counts start; empty at 0/0.+ *+ * @param added lines added+ * @param removed lines removed+ * @returns the text+ */+export const statTextOf = (added: number, removed: number) =>+ keptOf([+ added > 0 ? `+${added}` : null,+ removed > 0 ? `-${removed}` : null,+ ]).join(' ')diff --git a/mods/diff/hooks/views/sections/title-row.tsx b/mods/diff/hooks/views/sections/title-row.tsxnew file mode 100644index 00000000..438fca44--- /dev/null+++ b/mods/diff/hooks/views/sections/title-row.tsx@@ -0,0 +1,33 @@+/* @jsxRuntime classic */+/* @jsx h */+/* @jsxFrag Fragment */+import type { RenderElement } from 'claude-code'++import type PaneState from '../../pane-state'+import type { Kit } from '../kit'+import Layout from '../layout'++/**+ * The inline pane's heading (DiffDialog's title line): the title, then+ * its subtitle in dim after a space.+ *+ * @param kit the elements and the width+ * @param heading the title and subtitle+ * @returns the row+ */+export function titleRow(+ kit: Kit,+ heading: PaneState.DialogTitle,+): RenderElement {+ const { Text } = kit.ui+ const hasSubtitle = heading.subtitle !== ''++ return (+ <Text wrap="truncate-end">+ {Layout.sanitizeName(heading.title)}+ <Text dimColor>+ {hasSubtitle ? ` ${Layout.sanitizeName(heading.subtitle)}` : ''}+ </Text>+ </Text>+ )+}diff --git a/mods/diff/hooks/views/selected-detail-of/index.ts b/mods/diff/hooks/views/selected-detail-of/index.tsnew file mode 100644index 00000000..beb1060c--- /dev/null+++ b/mods/diff/hooks/views/selected-detail-of/index.ts@@ -0,0 +1,3 @@+export * from './selected-detail-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/selected-detail-of/selected-detail-of.ts b/mods/diff/hooks/views/selected-detail-of/selected-detail-of.tsnew file mode 100644index 00000000..d9bf1ab7--- /dev/null+++ b/mods/diff/hooks/views/selected-detail-of/selected-detail-of.ts@@ -0,0 +1,33 @@+import type { RenderElement } from 'claude-code'++import type PaneState from '../../pane-state'+import Detail from '../detail'+import Entries from '../entries'+import type { Kit } from '../kit'+import Sections from '../sections'++/**+ * The inline pane's one body: a rule, then the selected file's detail with+ * the whole body budget to itself; nothing when no file is selected.+ *+ * @param kit the elements, the handlers, the width+ * @param entry the selected file, or null+ * @param model which file is armed, and the backend's words+ * @returns the rule and the detail, or none+ */+export function selectedDetailOf(+ kit: Kit,+ entry: Entries.BodyEntry | null,+ model: Pick<PaneState.PaneModel, 'armedPath' | 'words'>,+): RenderElement[] {+ if (!entry) {+ return []+ }++ const drawn = Detail.detailView(kit, Entries.detailModelOf(entry, model), {+ room: Detail.BODY_BUDGET,+ onToggleAsk: () => kit.actions.toggleAsk(entry.path),+ })++ return [Sections.divider(kit), drawn.element]+}diff --git a/mods/diff/hooks/views/sidebar-pane/body-frame/body-frame.ts b/mods/diff/hooks/views/sidebar-pane/body-frame/body-frame.tsnew file mode 100644index 00000000..4acfaff6--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/body-frame/body-frame.ts@@ -0,0 +1,17 @@+import type PaneState from '../../../pane-state'+import type Detail from '../../detail'++/**+ * What drawing a run of file bodies takes besides the files: the pane's+ * state they read, the room left, and whether a blank row parts the files.+ */+export type BodyFrame = {+ model: Pick<PaneState.PaneModel, 'armedPath' | 'words' | 'isPreSessionShown'>+ room: Detail.BodyRoom++ /**+ * True in the session's body, whose files the built-in parts with a blank+ * row; false among the pre-session bodies, which it stacks flush.+ */+ isSpaced: boolean+}diff --git a/mods/diff/hooks/views/sidebar-pane/body-frame/index.ts b/mods/diff/hooks/views/sidebar-pane/body-frame/index.tsnew file mode 100644index 00000000..f9524fc3--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/body-frame/index.ts@@ -0,0 +1,3 @@+export type * from './body-frame.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sidebar-pane/drawn-blocks/drawn-blocks.ts b/mods/diff/hooks/views/sidebar-pane/drawn-blocks/drawn-blocks.tsnew file mode 100644index 00000000..84b8d200--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/drawn-blocks/drawn-blocks.ts@@ -0,0 +1,11 @@+import type { RenderElement } from 'claude-code'++import type Detail from '../../detail'++/**+ * A run of file bodies as drawn, and the room left for whatever follows.+ */+export type DrawnBlocks = {+ blocks: RenderElement[]+ room: Detail.BodyRoom+}diff --git a/mods/diff/hooks/views/sidebar-pane/drawn-blocks/index.ts b/mods/diff/hooks/views/sidebar-pane/drawn-blocks/index.tsnew file mode 100644index 00000000..a7084d27--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/drawn-blocks/index.ts@@ -0,0 +1,3 @@+export type * from './drawn-blocks.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sidebar-pane/earlier-section-of/earlier-section-of.tsx b/mods/diff/hooks/views/sidebar-pane/earlier-section-of/earlier-section-of.tsxnew file mode 100644index 00000000..152fb915--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/earlier-section-of/earlier-section-of.tsx@@ -0,0 +1,87 @@+/* @jsxRuntime classic */+/* @jsx h */+/* @jsxFrag Fragment */+import type { RenderElement } from 'claude-code'++import Limits from '../../../limits'+import type Entries from '../../entries'+import type { Kit } from '../../kit'+import Layout from '../../layout'+import Sections from '../../sections'+import type { BodyFrame } from '../body-frame'+import { fileBlocksOf } from '../file-blocks-of'++/**+ * The pre-session section after the body (PreSessionSection): its toggle+ * line, and once open a dim legend of every file, then their bodies.+ *+ * Past PRE_SESSION_BODY_CAP files a line says the bodies are hidden and+ * the legend alone lists them.+ *+ * @param kit the elements, the handlers, the width+ * @param entries the pre-session files, in order; none draws nothing+ * @param frame whether the section is open, the armed file, the room left+ * @returns the section's rows, none without pre-session files+ */+export function earlierSectionOf(+ kit: Kit,+ entries: readonly Entries.BodyEntry[],+ frame: BodyFrame,+): RenderElement[] {+ const { Box, Text } = kit.ui++ if (entries.length === 0) {+ return []+ }++ const face = frame.model.isPreSessionShown ? 'hide' : 'show'+ const count = Layout.plural(entries.length, 'file')++ const toggle = Sections.toggleRow(kit, 'presession', {+ label: `+${count} edited before this session (${face})`,+ onPress: kit.actions.togglePreSession,+ })++ if (!frame.model.isPreSessionShown) {+ return [toggle]+ }++ const nameRoom = Math.max(+ kit.columns - Sections.STAT_CELLS,+ Sections.PATH_FLOOR,+ )++ const legend = entries.map(entry => (+ <Box flexDirection="row">+ {[+ <Text dimColor wrap="truncate-end">+ {Layout.truncateStart(+ Layout.sanitizeName(entry.displayPath),+ nameRoom,+ )}+ </Text>,+ <Box flexGrow={1} />,+ Sections.diffStat(kit, entry.added, entry.removed),+ ]}+ </Box>+ ))++ const isCapped = entries.length > Limits.PRE_SESSION_BODY_CAP++ const bodies = isCapped+ ? [+ Sections.dimNote(+ kit,+ `diffs hidden above ${Limits.PRE_SESSION_BODY_CAP} files`,+ ),+ ]+ : fileBlocksOf(kit, entries, { ...frame, isSpaced: false }).blocks++ return [+ toggle,+ <Box flexDirection="column" marginTop={1}>+ {legend}+ </Box>,+ ...bodies,+ ]+}diff --git a/mods/diff/hooks/views/sidebar-pane/earlier-section-of/index.ts b/mods/diff/hooks/views/sidebar-pane/earlier-section-of/index.tsnew file mode 100644index 00000000..3e8c4677--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/earlier-section-of/index.ts@@ -0,0 +1,3 @@+export * from './earlier-section-of.jsx'++export * as default from '.'diff --git a/mods/diff/hooks/views/sidebar-pane/file-blocks-of/file-blocks-of.tsx b/mods/diff/hooks/views/sidebar-pane/file-blocks-of/file-blocks-of.tsxnew file mode 100644index 00000000..8b5a4c12--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/file-blocks-of/file-blocks-of.tsx@@ -0,0 +1,54 @@+/* @jsxRuntime classic */+/* @jsx h */+/* @jsxFrag Fragment */+import type { RenderElement } from 'claude-code'++import Detail from '../../detail'+import Entries from '../../entries'+import type { Kit } from '../../kit'+import Sections from '../../sections'+import type { BodyFrame } from '../body-frame'+import type { DrawnBlocks } from '../drawn-blocks'++/**+ * Every listed file's detail, one under the other as ReplDiffSidebar's+ * body stacks them: a rule, the file (Detail.detailView), a gap if spaced.+ *+ * Each block is keyed (Sections.bodyKeyOf) so a row's press scrolls to it.+ * The bodies share one budget in drawing order; a file it runs out on+ * draws truncated, as its footer says.+ *+ * @param kit the elements, the handlers, the width+ * @param entries the files, in drawing order+ * @param frame the pane's state the details read, and the room they share+ * @returns the blocks, and the room left after the last+ */+export function fileBlocksOf(+ kit: Kit,+ entries: readonly Entries.BodyEntry[],+ frame: BodyFrame,+): DrawnBlocks {+ const { Box } = kit.ui+ const blocks: RenderElement[] = []+ const gap = frame.isSpaced ? [<Box height={1} />] : []++ let { room } = frame++ for (const entry of entries) {+ const drawn = Detail.detailView(+ kit,+ Entries.detailModelOf(entry, frame.model),+ { room, onToggleAsk: () => kit.actions.toggleAsk(entry.path) },+ )++ room = drawn.room++ blocks.push(+ <Box key={Sections.bodyKeyOf(entry.path)} flexDirection="column">+ {[Sections.divider(kit), drawn.element, ...gap]}+ </Box>,+ )+ }++ return { blocks, room }+}diff --git a/mods/diff/hooks/views/sidebar-pane/file-blocks-of/index.ts b/mods/diff/hooks/views/sidebar-pane/file-blocks-of/index.tsnew file mode 100644index 00000000..4ca0e7f3--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/file-blocks-of/index.ts@@ -0,0 +1,3 @@+export * from './file-blocks-of.jsx'++export * as default from '.'diff --git a/mods/diff/hooks/views/sidebar-pane/index.ts b/mods/diff/hooks/views/sidebar-pane/index.tsnew file mode 100644index 00000000..f34ff9ec--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/index.ts@@ -0,0 +1,8 @@+export * from './body-frame'+export * from './drawn-blocks'+export * from './earlier-section-of'+export * from './file-blocks-of'+export * from './list-rows-of'+export * from './sidebar-pane.jsx'++export * as default from '.'diff --git a/mods/diff/hooks/views/sidebar-pane/list-rows-of/index.ts b/mods/diff/hooks/views/sidebar-pane/list-rows-of/index.tsnew file mode 100644index 00000000..eeb6c402--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/list-rows-of/index.ts@@ -0,0 +1,3 @@+export * from './list-rows-of.js'++export * as default from '.'diff --git a/mods/diff/hooks/views/sidebar-pane/list-rows-of/list-rows-of.ts b/mods/diff/hooks/views/sidebar-pane/list-rows-of/list-rows-of.tsnew file mode 100644index 00000000..2096ef82--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/list-rows-of/list-rows-of.ts@@ -0,0 +1,57 @@+import type { RenderElement } from 'claude-code'++import { keptOf } from '../../../kept-of'+import Limits from '../../../limits'+import type Entries from '../../entries'+import type { Kit } from '../../kit'+import Layout from '../../layout'+import Sections from '../../sections'++/**+ * The docked list (ReplDiffSidebar's summary rows): MAX_SUMMARY_ROWS files+ * as rows that scroll the body to their file, then a dim count of the rest.+ *+ * The rest are the rows below the window and the files past the row cap.+ * The built-in moves this window with the wheel over it or a chord; a pane+ * has neither, so the window stays at the top and names no key.+ *+ * @param kit the elements, the handlers, the width+ * @param entries the listed files, in order+ * @param notShown how many session files fell past the row cap+ * @returns the rows+ */+export function listRowsOf(+ kit: Kit,+ entries: readonly Entries.BodyEntry[],+ notShown: number,+): RenderElement[] {+ const shown = entries.slice(0, Limits.MAX_SUMMARY_ROWS)+ const moreBelow = entries.length - shown.length++ const rows = shown.map(entry =>+ Sections.fileRow(+ kit,+ {+ key: Sections.fileKeyOf(entry.path),+ path: entry.path,+ displayPath: entry.displayPath,+ added: entry.added,+ removed: entry.removed,+ note: null,+ isSelected: false,+ },+ () => kit.actions.selectFile(entry.path),+ ),+ )++ const counts = keptOf([+ moreBelow > 0 ? `${moreBelow} more below` : null,+ notShown > 0 ? `${notShown} not shown` : null,+ ])++ const lead = moreBelow > 0 ? '↓ ' : '… '+ const hasCounts = counts.length > 0+ const more = Layout.sanitizeName(`${lead}${counts.join(' · ')}`)++ return hasCounts ? [...rows, Sections.dimNote(kit, more)] : rows+}diff --git a/mods/diff/hooks/views/sidebar-pane/sidebar-pane.tsx b/mods/diff/hooks/views/sidebar-pane/sidebar-pane.tsxnew file mode 100644index 00000000..0e3d846c--- /dev/null+++ b/mods/diff/hooks/views/sidebar-pane/sidebar-pane.tsx@@ -0,0 +1,145 @@+/* @jsxRuntime classic */+/* @jsx h */+/* @jsxFrag Fragment */+import type { RenderElement } from 'claude-code'++import Names from '../../names'+import PaneState from '../../pane-state'+import CurrentPane from '../current-pane'+import Detail from '../detail'+import Entries from '../entries'+import type { Kit } from '../kit'+import Layout from '../layout'+import { preludeOf } from '../prelude-of'+import Sections from '../sections'+import { earlierSectionOf } from './earlier-section-of'+import { fileBlocksOf } from './file-blocks-of'+import { listRowsOf } from './list-rows-of'++/**+ * The docked pane (ReplDiffSidebarBody): header, pickers, todo bar, the+ * list, then every listed file's hunks stacked, the pre-session after.+ *+ * A row's press scrolls the body to its file. Over a picked turn the rows+ * and bodies are that turn's edits. With nothing to list, messagePaneOf+ * centers the empty state under the pickers.+ *+ * @param kit the elements, the handlers, the width, the rows+ * @param model the pane's state+ * @returns the pane's tree+ */+export function sidebarPane(+ kit: Kit,+ model: PaneState.PaneModel,+): RenderElement {+ const { Box } = kit.ui+ const { data } = model+ const turn = PaneState.pickedTurnOf(model)++ const prelude = preludeOf(kit, model)++ if (prelude) {+ return prelude+ }++ const noise = model.isNoiseShown ? 'shown' : 'hidden'+ const partition = PaneState.partitionOf(data?.files ?? [], noise)++ const totals = turn+ ? PaneState.turnTotalsOf(turn)+ : data+ ? PaneState.headerTotalsOf(data, partition)+ : PaneState.ZERO_TOTALS++ const empty = turn ? null : PaneState.emptyStateOf(model, totals.filesCount)++ const noteOf = (text: string | null): RenderElement | null =>+ text === null ? null : Sections.dimNote(kit, Layout.sanitizeName(text))++ const subline = turn+ ? noteOf(`Turn ${turn.index} "${turn.preview}"`)+ : noteOf(PaneState.unbornNoteOf(model, totals.filesCount))++ const entries = turn+ ? turn.files.map(Entries.turnEntryOf)+ : partition.shown.map(file => Entries.bodyEntryOf(file, model))++ const earlier = turn+ ? []+ : partition.preSession.map(file => Entries.bodyEntryOf(file, model))++ const listed = turn+ ? entries+ : CurrentPane.listBodyOf(kit, { data, partition, totals, empty })++ const notes = listed.flatMap(line => (typeof line === 'string' ? [line] : []))+ const hasRows = notes.length < listed.length+ const message = empty ? [empty.headline, ...notes] : hasRows ? [] : notes++ const header = Sections.headerView(+ kit,+ empty ? null : totals,+ Sections.controlsView(kit, model),+ )++ const hasNoise = !turn && partition.noiseCount > 0+ const noiseFace = model.isNoiseShown ? 'hide' : 'show'++ const noiseToggle = hasNoise+ ? Sections.toggleRow(kit, 'noise', {+ label:+ `${Layout.plural(partition.noiseCount, 'test')}/generated ` ++ `(${noiseFace})`,+ onPress: kit.actions.toggleNoise,+ })+ : null++ const isUntrackedNoted =+ !turn && data?.isUntrackedWithheld === true && empty === null++ const untrackedNote = noteOf(+ isUntrackedNoted ? Names.untrackedWithheldTextOf(model) : null,+ )++ const body = fileBlocksOf(kit, hasRows ? entries : [], {+ model,+ room: Detail.BODY_BUDGET,+ isSpaced: true,+ })++ const earlierRows = earlierSectionOf(kit, earlier, {+ model,+ room: body.room,+ isSpaced: false,+ })++ const top = Sections.present([header, subline, Sections.todoBar(kit, model)])++ const isMessageShown = message.length > 0++ if (isMessageShown) {+ return CurrentPane.messagePaneOf(kit, {+ top: Sections.present([...top, noiseToggle, untrackedNote]),+ message,+ controls: null,+ earlier: earlierRows[0] ?? null,+ rest: earlierRows.slice(1),+ })+ }++ const list = (+ <Box flexDirection="column" marginTop={1} marginBottom={1}>+ {Sections.present([+ ...listRowsOf(kit, entries, totals.notShown),+ untrackedNote,+ noiseToggle,+ ])}+ </Box>+ )++ return (+ <Box flexDirection="column">+ {[...top, list, ...body.blocks, ...earlierRows]}+ </Box>+ )+}diff --git a/mods/diff/hooks/views/turn-pane/turn-pane.tsx b/mods/diff/hooks/views/turn-pane/turn-pane.tsxindex f0505d6e..179f68b7 100644--- a/mods/diff/hooks/views/turn-pane/turn-pane.tsx+++ b/mods/diff/hooks/views/turn-pane/turn-pane.tsx@@ -5,13 +5,13 @@ import type { RenderElement } from 'claude-code'import PaneState from '../../pane-state'import type Turns from '../../turns'-import Detail from '../detail'+import Entries from '../entries'import type { Kit } from '../kit'-import Layout from '../layout'import Sections from '../sections'+import { selectedDetailOf } from '../selected-detail-of'/**- * The pane over one past turn's edits (DiffDialog's T<n> tab): the turn's+ * The inline pane over one past turn's edits (DiffDialog's T<n> tab): its* counts, its prompt's opening words, the pickers, its files, one body.** @param kit the elements, the handlers, the width@@ -32,11 +32,12 @@ export function turnPane(nullconst rows = turn.files.map(file =>- Sections.fileRow(+ Sections.dialogFileRow(kit,{key: Sections.fileKeyOf(file.path),path: file.path,+ displayPath: file.path,added: file.added,removed: file.removed,note: null,@@ -46,38 +47,17 @@ export function turnPane(),)- const detail = selected- ? [- Sections.divider(kit),- Detail.detailView(- kit,- {- words: model.words,- path: selected.path,- renamedFrom: null,- isUntracked: false,- isBinary: false,- body: {- hunks: selected.hunks,- isTruncated: selected.isTruncated,- isLarge: false,- },- bodyState: 'ready',- isArmed: model.armedPath === selected.path,- },- () => kit.actions.toggleAsk(selected.path),- ),- ]- : []+ const detail = selectedDetailOf(+ kit,+ selected ? Entries.turnEntryOf(selected) : null,+ model,+ )return (<Box flexDirection="column">{Sections.present([- Sections.headerView(kit, PaneState.turnTotalsOf(turn)),- Sections.dimNote(- kit,- `Turn ${turn.index} "${Layout.sanitizeName(turn.preview)}"`,- ),+ Sections.titleRow(kit, PaneState.dialogTitleOf(model)),+ Sections.headerView(kit, PaneState.turnTotalsOf(turn), null),Sections.controlsView(kit, model),...rows,...detail,