Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
feat(mcp): remove the 250-column cap from resize_session
Jack Rudenko7d43b73263e7
diff --git a/ai-docs/architecture/mcp-sessions.md b/ai-docs/architecture/mcp-sessions.mdindex 1e44ed61..854fdb51 100644--- a/ai-docs/architecture/mcp-sessions.md+++ b/ai-docs/architecture/mcp-sessions.md@@ -330,7 +330,7 @@ what a caller cannot see from the model id.answers the session's current screen `{seq, cols, rows, cursor, lines, final, spans?}` (160×50 atlaunch), or `{unchanged:true, seq, final}` when `since_seq` is still current — a memory read, meantfor polling at about 1 Hz. `resize_session` answers `{session_id, cols, rows, changed, seq,-pending?}`: the size actually set after clamping to 80–250 × 24–200, and the screen `seq` once the+pending?}`: the size actually set after clamping to 80–9999 × 24–9999 and at most 4 000 000 cells, and the screen `seq` once theredraw at that size has landed, so a capture with that `since_seq` already sees it. Their errorsare a JSON `ContractError`; `resize` is the only verb that emits the two codes it added,`resize_unsupported` (the magmux has no `resize` op) and `delivery_unavailable` (magmux refused, ordiff --git a/ai-docs/architecture/pane-session.md b/ai-docs/architecture/pane-session.mdindex 0d0ce372..dda3635d 100644--- a/ai-docs/architecture/pane-session.md+++ b/ai-docs/architecture/pane-session.md@@ -482,12 +482,23 @@ inline 400 and the slot is FAILED `api_error`.**The size is the viewer's, not ours.** Every pane used to be born 160×50 and stay there, so adocked viewer either showed empty rows below the screen or cut every line. 160×50 is now only thelaunch default (`pane/pane-size.ts`); `resize_session` and `team(mode:"resize")` set it at any time,-mid-turn included, clamped to cols 80–250 × rows 24–200. The floor is not arbitrary: at 80 columns-every closed-list dialog marker still fits one row's width, and 24 rows still hold a full permission-or trust dialog, so boot and blocked-screen detection keep working. magmux's own limits (≥ 20 × 3,-≤ 10000 per side) are wider, so a clamped size can never earn its `too_small`/`too_large`. The-column cap is where the real classifier fixtures stop: above 250 columns `isBoxRule`'s cols − 1-rule is unverified, and a box it misses is a screen that never classifies.+mid-turn included, clamped to cols 80–9999 × rows 24–9999 and at most 4 000 000 cells. The floor is+claudish's and is not arbitrary: at 80 columns every closed-list dialog marker still fits one row's+width, and 24 rows still hold a full permission or trust dialog, so boot and blocked-screen+detection keep working. The ceiling is magmux's own (`mux/size.go`), so a clamped size can never+earn its `too_small`/`too_large`: the `resize` op refuses a side over 10 000, but the launch size it+parses from `COLUMNS`/`LINES` is EXCLUSIVE of 10 000, and a size requested while the pane is+starting goes through those variables, so 9 999 is the largest side valid on both paths; the+product is capped at `maxScreenCells` = 4 000 000, so `clampPaneSize` lowers `rows` to+`floor(4 000 000 / cols)` (9 999 columns leave 400 rows).++There used to be a 250-column cap, because the real screen fixtures stopped there and `isBoxRule`+found the input box by a `─` rule at least `cols − 1` long. No decision depends on the width any+more: readiness, acceptance and dialogs come from magmux's input gate, and the box is located by+the hidden cursor's row (`pane/box-locate.ts`), with no width test. Captures at 350 × 80 and+500 × 100 (Claude Code 2.1.303) show every rule spanning exactly the full width and the cursor on+the box's text row, the same as at 80–250. A very large size is flagged, not capped: 9 999 × 400 is+4 M cells in claudish's screen model and in every `capture_session` reply.**A resize is a real one.** claudish sends magmux's `resize` op (`{type:"resize", pane:0, cols,rows}` → `{rows, cols, changed, manual}`); magmux sets the PTY winsize, the child gets a genuine@@ -519,7 +530,7 @@ as `since_seq` never reads a pre-resize frame as current.at other widths its checks are width-proof: echo prefixes are `min(40, cols − 4)` long and comparedagainst box text with row breaks removed, dialog markers match the dialog region joined into onestring, and the working row tolerates a wrapped tail. They are validated on real Claude Code screens-captured at 80, 120 and 250 columns. A resize redraw moves the above-box region, which only DELAYS+captured at 80, 120 and 250 columns; `locateBox` also at 350 and 500 (`box-locate.test.ts`). A resize redraw moves the above-box region, which only DELAYSsettle and boot (it restarts their quiet clocks) and never completes them. Two places would haveread a redraw as evidence and therefore ignore it inside the quiet window, an interval[from, until) opened at the SEND (the SIGWINCH redraw can land before the reply) and extended todiff --git a/docs/usage/magmux.md b/docs/usage/magmux.mdindex 54e97262..0ccead9a 100644--- a/docs/usage/magmux.md+++ b/docs/usage/magmux.md@@ -81,7 +81,8 @@ has finished, and closes the pane when the slot or session ends.A capture carries a `seq` that grows with every visible change; pass it back as `since_seq` and anunchanged screen answers `{unchanged: true}`, so polling about once a second is cheap.-A pane starts at 160×50. A viewer can resize it at any time (cols 80–250, rows 24–200, clamped);+A pane starts at 160×50. A viewer can resize it at any time (cols 80–9999, rows 24–9999,+at most 4 000 000 cells, clamped);the next capture carries the new `cols`/`rows`. Resizing needs a magmux that ships the `resize`verb (MIN_MAGMUX_VERSION); an older magmux answers `resize_unsupported` and the pane stays 160×50.See [MCP server](mcp-server.md).diff --git a/docs/usage/mcp-server.md b/docs/usage/mcp-server.mdindex 5a133964..cd6c3a8a 100644--- a/docs/usage/mcp-server.md+++ b/docs/usage/mcp-server.md@@ -447,8 +447,9 @@ scroll region, which garbled Claude Code's input box and stopped its turns from**Parameters:**- `session_id` (required) - Session ID from `create_session`-- `cols` (required) - Columns, an integer; clamped to 80–250-- `rows` (required) - Rows, an integer; clamped to 24–200+- `cols` (required) - Columns, an integer; clamped to 80–9999+- `rows` (required) - Rows, an integer; clamped to 24–9999, then lowered so that `cols × rows` is at+ most 4 000 000 (magmux's own limits; 9999 columns leave 400 rows)**Returns:** `{ session_id, cols, rows, changed, seq, pending? }`. `cols`/`rows` are the size actuallyset, after clamping. `changed: false` means the session already had that size, or has ended (it thendiff --git a/packages/cli/src/mcp-server.ts b/packages/cli/src/mcp-server.tsindex 31e14758..f4d1f33a 100644--- a/packages/cli/src/mcp-server.ts+++ b/packages/cli/src/mcp-server.ts@@ -1497,12 +1497,14 @@ function defineTools(sessionManager: SessionManager, nested: boolean): ToolDefincols: {type: "integer",description:- "For 'resize' (required): the terminal width in columns, clamped to 80–250. The " ++ "For 'resize' (required): the terminal width in columns, clamped to 80–9999. The " +"answer {run_id, path, slot, cols, rows, changed, seq} reports the size set.",},rows: {type: "integer",- description: "For 'resize' (required): the terminal height in rows, clamped to 24–200.",+ description:+ "For 'resize' (required): the terminal height in rows, clamped to 24–9999 and to " ++ "at most 4 000 000 cells (cols × rows).",},models: {type: "array",@@ -2305,8 +2307,8 @@ function defineTools(sessionManager: SessionManager, nested: boolean): ToolDefindescription:"Set a session's terminal size: the child gets a real SIGWINCH and Claude Code reflows. " +"Allowed at any time, mid-turn included; the last call wins. The size is clamped to " +- "cols 80–250, rows 24–200 and the answer {session_id, cols, rows, changed, seq, pending?} " +- "reports the size set. `seq` is the screen's seq after the resize: the next capture_session " ++ "cols 80–9999, rows 24–9999 and at most 4 000 000 cells (magmux's limits); the answer " ++ "{session_id, cols, rows, changed, seq, pending?} reports the size set. `seq` is the screen's seq after the resize: the next capture_session " +"shows the new cols/rows. `changed:false` = already that size. `pending:true` = the pane " +"is starting or its socket is reconnecting; the size is applied then. A finished session " +"answers its last size with changed:false. Errors are a JSON ContractError " +@@ -2315,8 +2317,11 @@ function defineTools(sessionManager: SessionManager, nested: boolean): ToolDefintype: "object",properties: {session_id: { type: "string", description: "Session ID from create_session" },- cols: { type: "integer", description: "Terminal width in columns (clamped to 80–250)" },- rows: { type: "integer", description: "Terminal height in rows (clamped to 24–200)" },+ cols: { type: "integer", description: "Terminal width in columns (clamped to 80–9999)" },+ rows: {+ type: "integer",+ description: "Terminal height in rows (clamped to 24–9999 and 4 000 000 cells)",+ },},required: ["session_id", "cols", "rows"],},diff --git a/packages/cli/src/pane/box-locate.ts b/packages/cli/src/pane/box-locate.tsindex e6454e91..f78fc32b 100644--- a/packages/cli/src/pane/box-locate.ts+++ b/packages/cli/src/pane/box-locate.ts@@ -4,9 +4,11 @@** `isBoxRule` (screen-model.ts) needs a rule at least `cols − 1` cells long, so it holds* only at the widths it was captured at (80 to 250 columns). This locator anchors on the- * hidden cursor instead: in every captured REPL screen from 80 to 250 columns the cursor- * sits on the box's caret row, also while a turn is working and during a UserPromptSubmit- * hook (session research `box-dependence.md`, "Hidden cursor position"). The box is then+ * hidden cursor instead: in every captured REPL screen from 80 to 500 columns (350 × 80+ * and 500 × 100 captured on Claude Code 2.1.303) the cursor sits on the box's caret row,+ * also while a turn is working and during a UserPromptSubmit hook (session research+ * `box-dependence.md`, "Hidden cursor position"). This is why `resize_session` has no+ * width cap of its own (`pane-size.ts`). The box is then* the nearest rule row above the cursor and the nearest rule row below it.** Every rule here is a CLOSED list. A screen that does not match reads as `unknown`, neverdiff --git a/packages/cli/src/pane/contract.ts b/packages/cli/src/pane/contract.tsindex f1baa1fc..fdf65a1b 100644--- a/packages/cli/src/pane/contract.ts+++ b/packages/cli/src/pane/contract.ts@@ -262,8 +262,8 @@ export interface CaptureUnchanged {}/**- * F — `resize_session`. `cols`/`rows` are the size SET (the request clamped to cols 80–250,- * rows 24–200); `changed` = the pane's size moved; `seq` = the screen's seq after the+ * F — `resize_session`. `cols`/`rows` are the size SET (the request clamped to cols 80–9999,+ * rows 24–9999 and at most 4 000 000 cells, magmux's limits: `clampPaneSize`); `changed` = the pane's size moved; `seq` = the screen's seq after the* resize (the first capture at the new size once `changed`). `pending: true` = the socket* is reconnecting (or the pane is still starting): the size is stored and applied on the* reconnect (or at launch). A terminal session answers its last size with `changed:false`.diff --git a/packages/cli/src/pane/index.ts b/packages/cli/src/pane/index.tsindex 30943a23..e5857da8 100644--- a/packages/cli/src/pane/index.ts+++ b/packages/cli/src/pane/index.ts@@ -50,6 +50,7 @@ export {clampPaneSize,DEFAULT_PANE_COLS,DEFAULT_PANE_ROWS,+ MAX_PANE_CELLS,MAX_PANE_COLS,MAX_PANE_ROWS,MIN_PANE_COLS,diff --git a/packages/cli/src/pane/pane-size.test.ts b/packages/cli/src/pane/pane-size.test.tsindex abf9f7ab..9dd0cefa 100644--- a/packages/cli/src/pane/pane-size.test.ts+++ b/packages/cli/src/pane/pane-size.test.ts@@ -1,33 +1,79 @@import { describe, expect, test } from "bun:test";-import { MAX_PANE_COLS, clampPaneSize, samePaneSize } from "./pane-size.js";+import {+ MAX_PANE_CELLS,+ MAX_PANE_COLS,+ MAX_PANE_ROWS,+ MIN_PANE_COLS,+ MIN_PANE_ROWS,+ clampPaneSize,+ samePaneSize,+} from "./pane-size.js";describe("clampPaneSize", () => {test.each([[80, 24, 80, 24],[120, 40, 120, 40],[250, 60, 250, 60],- [500, 200, 250, 200],+ [500, 200, 500, 200],[1, 1, 80, 24],- [501, 201, 250, 200],+ [501, 201, 501, 201],[79, 60, 80, 60],- [501, 60, 250, 60],+ [501, 60, 501, 60],[250, 23, 250, 24],- [250, 201, 250, 200],- [79, 201, 80, 200],- [501, 23, 250, 24],+ [250, 201, 250, 201],+ [79, 201, 80, 201],+ [501, 23, 501, 24],+ [400, 100, 400, 100],+ [10_000, 50, 9_999, 50],+ [9_999, 9_999, 9_999, 400],+ [50, 10, 80, 24],+ [2_000, 2_001, 2_000, 2_000],+ [9_999, 50, 9_999, 50],+ [80, 9_999, 80, 9_999],+ [80, 10_000, 80, 9_999],+ [10_000, 10_000, 9_999, 400],+ [2_000, 2_000, 2_000, 2_000],+ [8_000, 500, 8_000, 500],+ [8_000, 501, 8_000, 500],+ [2_001, 2_000, 2_001, 1_999],+ [0, 0, 80, 24],+ [-1, -1, 80, 24],+ [-1, 60, 80, 60],+ [120, -1, 120, 24],])("%i × %i clamps to %i × %i", (cols, rows, expectedCols, expectedRows) => {expect(clampPaneSize(cols, rows)).toEqual({ cols: expectedCols, rows: expectedRows });});++ test.each([+ [120.9, 40.9, 120, 40],+ [79.9, 23.9, 80, 24],+ [9_999.9, 50.9, 9_999, 50],+ [80.9, 9_999.9, 80, 9_999],+ [-120.9, -40.9, 80, 24],+ ])("%s × %s truncates and clamps to %s × %s", (cols, rows, expectedCols, expectedRows) => {+ expect(clampPaneSize(cols, rows)).toEqual({ cols: expectedCols, rows: expectedRows });+ });++ test("lowers a fractional 4,000,001-cell request to 4,000,000 cells", () => {+ expect(2_000 * 2_000.0005).toBe(4_000_001);+ const size = clampPaneSize(2_000, 2_000.0005);+ expect(size).toEqual({ cols: 2_000, rows: 2_000 });+ expect(size.cols * size.rows).toBe(MAX_PANE_CELLS);+ });});-describe("M3: classifier-verified width cap", () => {- test("clamps 1000 columns to 250 and preserves 250 columns", () => {+describe("U9: magmux size bounds", () => {+ test("preserves 250 columns and widths above 250", () => {expect(clampPaneSize(250, 50).cols).toBe(250);- expect(clampPaneSize(1000, 50).cols).toBe(250);+ expect(clampPaneSize(1_000, 50).cols).toBe(1_000);});- test("MAX_PANE_COLS is 250", () => {- expect(MAX_PANE_COLS).toBe(250);+ test("exports magmux limits and the 80 × 24 minimum", () => {+ expect(MAX_PANE_COLS).toBe(9_999);+ expect(MAX_PANE_ROWS).toBe(9_999);+ expect(MAX_PANE_CELLS).toBe(4_000_000);+ expect(MIN_PANE_COLS).toBe(80);+ expect(MIN_PANE_ROWS).toBe(24);});});diff --git a/packages/cli/src/pane/pane-size.ts b/packages/cli/src/pane/pane-size.tsindex 7ac0c0bb..f83f2d44 100644--- a/packages/cli/src/pane/pane-size.ts+++ b/packages/cli/src/pane/pane-size.ts@@ -7,20 +7,31 @@* may change it at any time. magmux refuses a size outside its own limits (< 20 × 3, a side* over 10 000, over 4 M cells); claudish CLAMPS instead and reports the size it set.*- * The bounds are tighter than magmux's on purpose (plan review H1, L4): at 80 columns every- * closed-list dialog marker the classifier matches still fits one row, and 24 rows hold a- * whole permission or trust dialog. A smaller screen would turn a dialog into "no input box,- * no dialog" — an honest unknown that never settles. The column cap is 250 because the- * real classifier fixtures stop there: above it, `isBoxRule`'s cols − 1 rule is unverified.+ * The upper bounds are magmux's, nothing tighter. No claudish decision depends on the width+ * any more: readiness, prompt acceptance and dialogs come from magmux's input gate, and the+ * input box is located by the cursor row, not by a rule `cols − 1` long. Two magmux limits+ * meet here (mux/size.go at v0.17.0):+ * - a side: the `resize` op refuses a side over 10 000, but the launch size parsed from+ * `COLUMNS`/`LINES` is EXCLUSIVE of 10 000. A size requested while the pane is starting is+ * applied through those variables, so 9 999 is the largest side valid on both paths.+ * - the product: `maxScreenCells` = 4 000 000. When `cols × rows` exceeds it, `rows` drops to+ * `floor(4 000 000 / cols)`, so a clamped size never earns magmux's `too_large`.+ *+ * The floor is claudish's (plan review H1, L4): at 80 columns every closed-list dialog marker+ * the classifier matches still fits one row, and 24 rows hold a whole permission or trust+ * dialog. A smaller screen would turn a dialog into "no input box, no dialog" — an honest+ * unknown that never settles.*/export const DEFAULT_PANE_COLS = 160;export const DEFAULT_PANE_ROWS = 50;export const MIN_PANE_COLS = 80;-export const MAX_PANE_COLS = 250;+export const MAX_PANE_COLS = 9_999;export const MIN_PANE_ROWS = 24;-export const MAX_PANE_ROWS = 200;+export const MAX_PANE_ROWS = 9_999;+/** magmux's `maxScreenCells`: the most cells one pane screen may hold. */+export const MAX_PANE_CELLS = 4_000_000;/*** After a resize the child redraws everything it shows (SIGWINCH reflow). From the send@@ -38,12 +49,15 @@ function clamp(n: number, lo: number, hi: number): number {return Math.min(hi, Math.max(lo, Math.trunc(n)));}-/** The size claudish sets for a requested one: each side clamped into its bounds. */+/**+ * The size claudish sets for a requested one: each side clamped into its bounds, then `rows`+ * lowered until the screen fits `MAX_PANE_CELLS`. At the widest side (9 999) that still leaves+ * 400 rows, far above the 24-row floor.+ */export function clampPaneSize(cols: number, rows: number): PaneSize {- return {- cols: clamp(cols, MIN_PANE_COLS, MAX_PANE_COLS),- rows: clamp(rows, MIN_PANE_ROWS, MAX_PANE_ROWS),- };+ const c = clamp(cols, MIN_PANE_COLS, MAX_PANE_COLS);+ const r = clamp(rows, MIN_PANE_ROWS, MAX_PANE_ROWS);+ return { cols: c, rows: Math.min(r, Math.floor(MAX_PANE_CELLS / c)) };}export function samePaneSize(a: PaneSize | null, b: PaneSize | null): boolean {