@yanzc/claude-pro 0.9.2 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -71,7 +71,7 @@ claude-pro -p "用 Read 工具读取 package.json,告诉我项目版本"
71
71
 
72
72
  网关 key 只来自 `/login`:登录后保存在 `~/.claude-pro/gateway.json`,不用手动填写,也没有环境变量或 `.env` 文件可以设置它(没有浏览器的机器可以把另一台登录过的电脑的 `gateway.json` 拷过去)。
73
73
 
74
- 一般只需要 `/login`、`/model`、`/effort`、`/tui` 和 settings。五个普通设置直接写在 `settings.json` 顶层(下面也是默认值):
74
+ 一般只需要 `/login`、`/model`、`/effort`、`/tui` 和 settings。六个普通设置直接写在 `settings.json` 顶层(下面也是默认值):
75
75
 
76
76
  ```json
77
77
  {
@@ -79,10 +79,13 @@ claude-pro -p "用 Read 工具读取 package.json,告诉我项目版本"
79
79
  "effort": "auto",
80
80
  "tui": "fullscreen",
81
81
  "promptCacheTtl": "1h",
82
- "subagentPromptCacheTtl": "5m"
82
+ "subagentPromptCacheTtl": "5m",
83
+ "cleanupPeriodDays": 30
83
84
  }
84
85
  ```
85
86
 
87
+ `cleanupPeriodDays` 和 Claude Code 的同名设置一样:会话最后一次使用超过这么多天就删除(连同它的 trace,此后 `/resume` 里也看不到),每次启动后在后台清理所有项目,一台机器一小时最多一次;保存的大块工具输出最多留 7 天、`/rewind` 快照最多 14 天,项目记忆从不删。最小 1,想长期保留就设 `3650` 之类的大数。这一项只从 `~/.claude-pro/settings.json` 读,项目里的设置文件改不了它。
88
+
86
89
  也可以用命令修改:
87
90
 
88
91
  ```bash
@@ -93,7 +96,7 @@ claude-pro config list --advanced # 另外显示高级配置
93
96
  claude-pro config set CLAUDE_PRO_GATEWAY_URL https://gw.predix.icu
94
97
  ```
95
98
 
96
- 会话中 `/config` 默认只显示这五项,`/config advanced` 查看高级项;`/config set model sonnet` 等同于 CLI 的 `config set`。普通设置写顶层,高级设置写 `env`。`/config set/unset` 保留 `--project`、`--local`,分别修改项目共享设置或本地设置。`/model`、`/effort` 仍会记住选择,`/tui` 记到顶层 `tui`;`--model`、`--effort` 可覆盖本次启动。
99
+ 会话中 `/config` 默认只显示这六项,`/config advanced` 查看高级项;`/config set model sonnet` 等同于 CLI 的 `config set`。普通设置写顶层,高级设置写 `env`。`/config set/unset` 保留 `--project`、`--local`,分别修改项目共享设置或本地设置。`/model`、`/effort` 仍会记住选择,`/tui` 记到顶层 `tui`;`--model`、`--effort` 可覆盖本次启动。
97
100
 
98
101
  设置文件从低到高:`~/.claude-pro/settings.json`、项目 `.claude-pro/settings.json`、`.claude-pro/settings.local.json`。高级项仍兼容进程环境变量(高于设置文件),包括网关地址、远程会话、输出/thinking 预算、缓存总开关、保活、网络重试、工具路径、验证、自动记忆/话题标题和 Trace 开关;普通设置不从进程环境读取。旧 `settings.json.env` 中的 `CLAUDE_PRO_GATEWAY_MODEL`、`CLAUDE_CODE_EFFORT_LEVEL`、`CLAUDE_PRO_TUI`、`CLAUDE_CODE_PROMPT_CACHE_TTL`、`CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL` 只作为兼容别名读取,同文件顶层新字段优先;用 `config set` 或 `/config set` 设置旧别名,会改写顶层新字段并移除同文件旧别名。provider 固定为 `gateway`,已删除 `--provider` 和 `CLAUDE_PRO_PROVIDER` 配置入口。
99
102
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanzc/claude-pro",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "claude-pro: a command line coding agent for the codex-gateway. Full access with no permission prompts; file edits are checkpointed and can be rewound.",
5
5
  "type": "module",
6
6
  "repository": {
package/src/config.js CHANGED
@@ -33,6 +33,9 @@ export const BASIC_SETTINGS = {
33
33
  tui: { default: 'fullscreen', legacy: 'CLAUDE_PRO_TUI', description: 'fullscreen or default; /tui switches and remembers it' },
34
34
  promptCacheTtl: { default: '1h', legacy: 'CLAUDE_CODE_PROMPT_CACHE_TTL', description: 'Conversation prompt cache: 5m or 1h' },
35
35
  subagentPromptCacheTtl: { default: '5m', legacy: 'CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL', description: 'Sub-agent, compaction and side-query prompt cache: 5m or 1h' },
36
+ // `userOnly`: read from ~/.claude-pro/settings.json only. It deletes the data of every project, so a project's
37
+ // settings file (it comes with the repository) must not lower it.
38
+ cleanupPeriodDays: { default: 30, userOnly: true, description: 'Days a conversation is kept after it was last used (then deleted with its traces, as in Claude Code; at least 1)' },
36
39
  };
37
40
 
38
41
  // Advanced keys, shown only by /config advanced (or config list --advanced). Settings files may also carry
@@ -61,6 +64,11 @@ export const KNOWN_KEYS = {
61
64
  };
62
65
 
63
66
  function basicValue(key, value) {
67
+ if (key === 'cleanupPeriodDays') {
68
+ const days = typeof value === 'number' ? value : /^\s*\d+\s*$/.test(String(value)) ? Number(value) : NaN;
69
+ if (Number.isInteger(days) && days >= 1) return days;
70
+ throw new Error(`Invalid ${key}: ${value}. A whole number of days, at least 1 (e.g. 3650 to keep conversations for years).`);
71
+ }
64
72
  if (typeof value !== 'string') throw new Error(`${key} must be a string.`);
65
73
  const text = value.trim();
66
74
  if (key === 'model') {
@@ -92,6 +100,7 @@ export function writeConfigSetting(file, key, value) {
92
100
  key = configKey(key);
93
101
  const basic = BASIC_SETTINGS[key];
94
102
  const normalized = basic ? basicValue(key, value) : String(value);
103
+ if (basic?.userOnly && path.resolve(file) !== path.resolve(userSettingsFile())) throw new Error(`${key} is read from ${userSettingsFile()} only.`);
95
104
  updateSettingsFile(file, (json) => {
96
105
  if (basic) {
97
106
  json[key] = normalized;
@@ -153,8 +162,9 @@ export function loadConfig({ cwd = process.cwd(), flags = {} } = {}) {
153
162
  if (!json) continue;
154
163
  set(json.env, file);
155
164
  for (const [key, spec] of Object.entries(BASIC_SETTINGS)) {
165
+ if (spec.userOnly && scope !== 'user') continue;
156
166
  // A top-level field wins over its legacy spelling in the same file; later files win over earlier ones.
157
- const value = json[key] ?? json.env?.[spec.legacy];
167
+ const value = json[key] ?? (spec.legacy ? json.env?.[spec.legacy] : undefined);
158
168
  if (value == null) continue;
159
169
  try { settings[key] = basicValue(key, value); sources[key] = file; } catch { /* invalid: use the earlier value or default */ }
160
170
  }
package/src/runtime.js CHANGED
@@ -13,7 +13,7 @@ import { isAbort } from './api.js';
13
13
  import { McpManager } from './mcp.js';
14
14
  import { HookRunner } from './hooks.js';
15
15
  import { BackgroundTasks, taskNotification } from './tasks.js';
16
- import { autoMemoryDir, pruneToolResults, pruneCheckpoints, pruneTraces, projectDir } from './session.js';
16
+ import { autoMemoryDir, sweepOldData, projectDir } from './session.js';
17
17
  import { loadAutoMemoryIndex, takeEnvSnapshot, takeEnvSnapshotAsync, localDate } from './context.js';
18
18
  import { canRestart } from './restart.js';
19
19
  import { RuntimeTrace } from './trace.js';
@@ -24,9 +24,15 @@ export async function createRuntime({ cwd, flags = {}, io, sessionId = '' }) {
24
24
  const trace = new RuntimeTrace({ cwd, sessionId, enabled: config.traceEnabled });
25
25
  applyRememberedChoices(config, flags); // what /model and /effort chose last time
26
26
  if (flags.verify) config.verifyOverride = flags.verify;
27
- pruneToolResults(cwd);
28
- pruneCheckpoints(cwd);
29
- pruneTraces(cwd);
27
+ // Old conversations and what goes with them, in the background a while after the start (not in the self-check's
28
+ // throwaway process, nor a test's: CLAUDE_PRO_CONFIG_DIR points elsewhere then anyway)
29
+ if (process.env.CLAUDE_PRO_SELF_CHECK !== '1') {
30
+ setTimeout(() => {
31
+ sweepOldData({ days: config.setting('cleanupPeriodDays'), keep: [sessionId, config.sessionId] })
32
+ .then((done) => { if (done.files) trace.append('cleanup', { conversations: done.conversations, files: done.files, bytes: done.bytes }); })
33
+ .catch(() => {});
34
+ }, 15_000).unref();
35
+ }
30
36
  pruneStaleShellFiles();
31
37
  // Full access: nothing is ever asked.
32
38
  const checkpoints = new CheckpointStore(path.join(projectDir(cwd), 'checkpoints', `${Date.now()}-${crypto.randomBytes(3).toString('hex')}`));
package/src/session.js CHANGED
@@ -88,46 +88,59 @@ export function toolResultsDir(cwd) {
88
88
  return path.join(projectDir(cwd), 'tool-results');
89
89
  }
90
90
 
91
- // Delete saved tool output older than maxAgeMs (best effort, run at startup).
92
- export function pruneToolResults(cwd, maxAgeMs = 7 * 24 * 3600_000) {
93
- const dir = toolResultsDir(cwd);
94
- let entries = [];
95
- try { entries = fs.readdirSync(dir); } catch { return; }
96
- const cutoff = Date.now() - maxAgeMs;
97
- for (const name of entries) {
98
- const file = path.join(dir, name);
99
- try { if (fs.statSync(file).mtimeMs < cutoff) fs.rmSync(file, { force: true }); } catch { /* ignore */ }
100
- }
101
- }
102
-
103
- // Delete the traces (see trace.js) of conversations not traced for maxAgeMs: one file a conversation, up to 40 MB
104
- // with its rotation, kept for good before (best effort, run at startup).
105
- export function pruneTraces(cwd, maxAgeMs = 30 * 24 * 3600_000) {
106
- const dir = path.join(projectDir(cwd), 'traces');
107
- let entries = [];
108
- try { entries = fs.readdirSync(dir); } catch { return; }
109
- const cutoff = Date.now() - maxAgeMs;
110
- for (const name of entries) {
111
- const file = path.join(dir, name);
112
- try { if (fs.statSync(file).mtimeMs < cutoff) fs.rmSync(file, { force: true }); } catch { /* ignore */ }
113
- }
114
- }
115
-
116
91
  // Where /rewind keeps file snapshots: one sub-directory per run of the program.
117
92
  export function checkpointsDir(cwd) {
118
93
  return path.join(projectDir(cwd), 'checkpoints');
119
94
  }
120
95
 
121
- // Delete snapshot directories of old runs (best effort, run at startup).
122
- export function pruneCheckpoints(cwd, maxAgeMs = 14 * 24 * 3600_000) {
123
- const dir = checkpointsDir(cwd);
124
- let entries = [];
125
- try { entries = fs.readdirSync(dir); } catch { return; }
126
- const cutoff = Date.now() - maxAgeMs;
127
- for (const name of entries) {
128
- const sub = path.join(dir, name);
129
- try { if (fs.statSync(sub).mtimeMs < cutoff) fs.rmSync(sub, { recursive: true, force: true }); } catch { /* ignore */ }
96
+ // Delete what is older than `days` (the cleanupPeriodDays setting, as in Claude Code: 30 by default), in every
97
+ // project: conversations not written to since (they no longer appear in /resume), their traces, saved tool outputs
98
+ // (at most 7 days) and /rewind snapshots (at most 14 days). The memory is never touched. Conversations were kept
99
+ // for good before: 646 MB in 176 files in a month (2026-11-11), of which only the current project's tool outputs,
100
+ // snapshots and traces were deleted, and only when a session started there. Runs in the background, at most once
101
+ // an hour on the machine (`marker`); `keep`: conversation ids not to delete whatever their age. Returns what went.
102
+ export async function sweepOldData({ days, keep = [], root = path.join(CONFIG_DIR, 'projects'), now = Date.now() } = {}) {
103
+ const done = { conversations: 0, files: 0, bytes: 0 };
104
+ if (!(days >= 1)) return done;
105
+ const marker = path.join(root, '.last-sweep');
106
+ try { if (now - fs.statSync(marker).mtimeMs < 3600_000) return done; } catch { /* never swept */ }
107
+ try { fs.mkdirSync(root, { recursive: true }); fs.writeFileSync(marker, ''); } catch { return done; }
108
+ const day = 24 * 3600_000;
109
+ const keepIds = new Set(keep.filter(Boolean));
110
+ const fsp = fs.promises;
111
+ const list = async (dir) => { try { return await fsp.readdir(dir, { withFileTypes: true }); } catch { return []; } };
112
+ const old = async (file, maxAgeMs) => { try { return now - (await fsp.stat(file)).mtimeMs > maxAgeMs; } catch { return false; } };
113
+ const remove = async (file, isDir = false) => {
114
+ try {
115
+ const size = isDir ? 0 : (await fsp.stat(file)).size;
116
+ await fsp.rm(file, { recursive: isDir, force: true });
117
+ done.files++;
118
+ done.bytes += size;
119
+ return true;
120
+ } catch { return false; }
121
+ };
122
+ for (const project of await list(root)) {
123
+ if (!project.isDirectory()) continue;
124
+ const dir = path.join(root, project.name);
125
+ for (const e of await list(dir)) {
126
+ const id = e.name.replace(/\.jsonl$/, '');
127
+ if (!e.isFile() || id === e.name || keepIds.has(id)) continue;
128
+ if (await old(path.join(dir, e.name), days * day) && (await remove(path.join(dir, e.name)))) done.conversations++;
129
+ }
130
+ for (const e of await list(path.join(dir, 'traces'))) { // a conversation's trace is written with it
131
+ const f = path.join(dir, 'traces', e.name);
132
+ if (!keepIds.has(e.name.replace(/\.jsonl(\.\d+)?$/, '')) && (await old(f, days * day))) await remove(f);
133
+ }
134
+ for (const e of await list(path.join(dir, 'tool-results'))) {
135
+ const f = path.join(dir, 'tool-results', e.name);
136
+ if (await old(f, Math.min(days, 7) * day)) await remove(f);
137
+ }
138
+ for (const e of await list(path.join(dir, 'checkpoints'))) { // one directory per run of the program
139
+ const f = path.join(dir, 'checkpoints', e.name);
140
+ if (await old(f, Math.min(days, 14) * day)) await remove(f, true);
141
+ }
130
142
  }
143
+ return done;
131
144
  }
132
145
 
133
146
  // Persistent, model-maintained memory for this project (MEMORY.md + topic files).
package/src/ui/ansi.js CHANGED
@@ -96,11 +96,20 @@ function inRanges(cp, ranges) {
96
96
  return false;
97
97
  }
98
98
 
99
+ // Some Windows conhosts render symbols such as ·, … and ↓ in two cells even in UTF-8. Use the cursor
100
+ // advances measured at startup instead of guessing from the code page (or changing the user's console settings).
101
+ const terminalWidths = new Map();
102
+ export function setTerminalWidths(widths) {
103
+ terminalWidths.clear();
104
+ for (const [char, width] of widths) {
105
+ if (width === 1 || width === 2) terminalWidths.set(char.codePointAt(0), width);
106
+ }
107
+ }
108
+
99
109
  export function codePointWidth(cp) {
100
110
  if (cp < 32 || (cp >= 0x7f && cp < 0xa0)) return 0;
101
111
  if (inRanges(cp, ZERO)) return 0;
102
- if (inRanges(cp, WIDE)) return 2;
103
- return 1;
112
+ return terminalWidths.get(cp) ?? (inRanges(cp, WIDE) ? 2 : 1);
104
113
  }
105
114
 
106
115
  const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
package/src/ui/screen.js CHANGED
@@ -29,7 +29,7 @@
29
29
  // of a restart) goes on right below the output.
30
30
 
31
31
  import { PassThrough } from 'node:stream';
32
- import { ESC, wrapLine, termWidth, truncate, stringWidth, stripAnsi, graphemes, graphemeWidth } from './ansi.js';
32
+ import { ESC, wrapLine, termWidth, truncate, stringWidth, stripAnsi, graphemes, graphemeWidth, setTerminalWidths } from './ansi.js';
33
33
 
34
34
  const SYNC_START = '\x1b[?2026h';
35
35
  const SYNC_END = '\x1b[?2026l';
@@ -136,32 +136,54 @@ export function mouseFilter(stdin, onMouse) {
136
136
  });
137
137
  return out;
138
138
  }
139
- const CPR = /\x1b\[(\d+);(\d+)R/; // the terminal's answer to DSR 6: row;column
139
+ const CPR = /\x1b\[(\d+);(\d+)R/g; // the terminal's answer to DSR 6: row;column
140
+ const WIDTH_PROBES = process.platform === 'win32' ? Array.from('·…↑↓←→↻⇣⏎◷⇄•◦⏺⎿✻✢✳✶✽✉⚠') : [];
140
141
 
141
- // Ask the terminal where the cursor is (DSR 6): resolves with its row (1-based), or null when it does not answer
142
- // within `timeout`. Run before anything else reads `stdin`, with the terminal in raw mode; what else arrives
143
- // meanwhile (keys typed during start-up) is put back for the key reader.
142
+ // Ask the terminal where the cursor is (DSR 6): resolves with its row (1-based), or null when it does not answer.
143
+ // On Windows, also measure the UI symbols whose width varies between conhosts/fonts. All probes start at column
144
+ // one, fit on this row, and are erased before restoring the cursor. Run before anything else reads raw `stdin`;
145
+ // keys typed meanwhile are put back byte for byte, without the terminal's replies.
144
146
  export function queryCursorRow(stdin, out, timeout = 300) {
145
147
  return new Promise((resolve) => {
146
148
  let buf = Buffer.alloc(0);
147
- let timer = null;
148
- const done = (row) => {
149
+ let timer = null, probing = false, finished = false;
150
+ const replies = () => [...buf.toString('latin1').matchAll(CPR)];
151
+ const done = () => {
152
+ if (finished) return;
153
+ finished = true;
149
154
  clearTimeout(timer);
150
155
  stdin.off('data', onData);
151
156
  stdin.pause();
152
- const m = CPR.exec(buf.toString('latin1')); // latin1: one character a byte, so the index is a byte index
153
- const rest = m ? Buffer.concat([buf.subarray(0, m.index), buf.subarray(m.index + m[0].length)]) : buf;
157
+ const matches = replies();
158
+ const first = matches[0];
159
+ if (probing) {
160
+ const widths = matches.slice(1).map((m, i) => [WIDTH_PROBES[i], Number(m[2]) - 1]);
161
+ if (matches.length === WIDTH_PROBES.length + 1 && matches.every((m) => m[1] === first[1]) && widths.every(([, w]) => w === 1 || w === 2)) setTerminalWidths(widths);
162
+ try { out.write('\r' + ESC.right(Number(first[2]) - 1) + ESC.showCursor + SYNC_END); } catch { /* terminal closed */ }
163
+ }
164
+ // latin1 keeps a one-to-one mapping of bytes, including keys/pastes split in the middle of a UTF-8 character.
165
+ const rest = Buffer.from(buf.toString('latin1').replace(CPR, ''), 'latin1');
154
166
  if (rest.length) stdin.unshift(rest);
155
- resolve(row);
167
+ resolve(first ? Number(first[1]) : null);
156
168
  };
157
169
  const onData = (d) => {
158
170
  buf = Buffer.concat([buf, Buffer.isBuffer(d) ? d : Buffer.from(String(d), 'utf8')]);
159
- const m = CPR.exec(buf.toString('latin1'));
160
- if (m) done(Number(m[1]));
171
+ const matches = replies();
172
+ if (!matches.length) return;
173
+ if (!WIDTH_PROBES.length || (out.columns && out.columns < 3)) { done(); return; }
174
+ if (probing) {
175
+ if (matches.length >= WIDTH_PROBES.length + 1) done();
176
+ return;
177
+ }
178
+ probing = true;
179
+ clearTimeout(timer);
180
+ timer = setTimeout(done, timeout);
181
+ const probes = WIDTH_PROBES.map((char) => '\r' + char + '\x1b[6n').join('');
182
+ try { out.write(SYNC_START + ESC.hideCursor + probes + '\r\x1b[K'); } catch { done(); }
161
183
  };
162
- timer = setTimeout(() => done(null), timeout);
184
+ timer = setTimeout(done, timeout);
163
185
  stdin.on('data', onData);
164
- try { out.write('\x1b[6n'); } catch { done(null); }
186
+ try { out.write('\x1b[6n'); } catch { done(); }
165
187
  });
166
188
  }
167
189
 
@@ -186,6 +208,7 @@ export class Screen {
186
208
  // pin: keep the live region on the last rows of the screen (see the top of this file).
187
209
  constructor(out = process.stdout, { pin = true } = {}) {
188
210
  this.out = out;
211
+ this.dimensions = this.readSize();
189
212
  this.pin = pin;
190
213
  this.pinned = null; // rows from the top of the live region to the bottom of the screen; null: not known
191
214
  this.full = false; // fullscreen: see the top of this file
@@ -220,6 +243,12 @@ export class Screen {
220
243
  this.titleInherited = false; // the process before this one in the session already saved the shell's title
221
244
  this.exitTitle = '';
222
245
  out.on('resize', () => this.onResize());
246
+ // RDP display changes can leave Node's columns/rows cache behind. Check the native size even while idle;
247
+ // finding a change takes the same debounced full-repaint path as a normal resize event.
248
+ if (process.platform === 'win32' && out.isTTY && out._handle?.getWindowSize) {
249
+ this.sizeTimer = setInterval(() => this.checkSize(), 250);
250
+ this.sizeTimer.unref();
251
+ }
223
252
  }
224
253
 
225
254
  // Keep the terminal's title (the label of its tab or window) following `provider()`. `exitTitle` is what
@@ -242,8 +271,28 @@ export class Screen {
242
271
  return (first ? TITLE_PUSH : '') + `\x1b]0;${text}\x07`;
243
272
  }
244
273
 
245
- get width() { return Math.max(20, this.out.columns || termWidth()); }
246
- get height() { return Math.max(10, this.out.rows || 30); }
274
+ readSize() {
275
+ const fallback = [this.out.columns || this.dimensions?.[0] || termWidth(), this.out.rows || this.dimensions?.[1] || 30];
276
+ if (process.platform === 'win32' && this.out.isTTY && this.out._handle?.getWindowSize) {
277
+ try {
278
+ const size = [0, 0];
279
+ if (!this.out._handle.getWindowSize(size) && size.every((n) => Number.isInteger(n) && n > 0)) return size;
280
+ } catch { /* closed or unsupported handle: keep the last valid size */ }
281
+ return this.dimensions || fallback;
282
+ }
283
+ return fallback;
284
+ }
285
+
286
+ checkSize() {
287
+ if (this.closed) return false;
288
+ const size = this.readSize();
289
+ if (size[0] === this.dimensions[0] && size[1] === this.dimensions[1]) return false;
290
+ this.onResize(size);
291
+ return true;
292
+ }
293
+
294
+ get width() { return Math.max(20, this.dimensions[0]); }
295
+ get height() { return Math.max(10, this.dimensions[1]); }
247
296
  // True from a size change until the repaint that follows it.
248
297
  get resizing() { return this.resizeTimer !== null; }
249
298
 
@@ -707,9 +756,10 @@ export class Screen {
707
756
  // Draw the screen: the conversation above, the live region on the last rows, the cursor in the input box.
708
757
  draw({ full = false } = {}) {
709
758
  if (this.closed || !this.full) return;
759
+ if (this.checkSize() || this.resizing) return;
710
760
  if (this.scheduled) { clearTimeout(this.scheduled); this.scheduled = null; }
711
761
  const cols = this.width;
712
- const screenRows = Math.max(1, this.out.rows || this.height);
762
+ const screenRows = Math.max(1, this.dimensions[1]);
713
763
  if (!this.scroll) this.scrollLiveRows = null;
714
764
  else if (full) this.scrollLiveRows = null; // a resize changes wrapping; capture the new live layout below
715
765
  let layout = this.layoutLive(cols);
@@ -841,7 +891,7 @@ export class Screen {
841
891
  const end = input ? starts[input.row + input.rows] : undefined;
842
892
  const box = end !== undefined && end - starts[input.row] === input.rows ? { top: starts[input.row], rows: input.rows, col: input.col } : null;
843
893
  // Cap to the terminal height so there is always a way back to the top.
844
- const maxRows = Math.max(1, Math.min(this.height, this.out.rows || this.height) - 1);
894
+ const maxRows = Math.max(1, this.dimensions[1] - 1);
845
895
  if (rows.length > maxRows) {
846
896
  const dropped = rows.length - maxRows;
847
897
  rows.splice(0, dropped);
@@ -864,8 +914,9 @@ export class Screen {
864
914
  return buf;
865
915
  }
866
916
 
867
- onResize() {
917
+ onResize(size = this.readSize()) {
868
918
  if (this.closed) return;
919
+ this.dimensions = size;
869
920
  const now = Date.now();
870
921
  if (!this.resizeSince) this.resizeSince = now;
871
922
  clearTimeout(this.resizeTimer);
@@ -876,7 +927,7 @@ export class Screen {
876
927
  settleResize() {
877
928
  this.resizeTimer = null;
878
929
  this.resizeSince = 0;
879
- this.repaint();
930
+ if (!this.checkSize()) this.repaint();
880
931
  }
881
932
 
882
933
  // Write the whole viewport again after a resize: the newest static lines that fit, then the live region,
@@ -888,6 +939,7 @@ export class Screen {
888
939
  // What was on screen above our output (a short session: the shell that started us) is overwritten.
889
940
  repaint() {
890
941
  if (this.closed) return;
942
+ this.dimensions = this.readSize();
891
943
  if (this.full) {
892
944
  clearTimeout(this.resizeTimer);
893
945
  this.resizeTimer = null;
@@ -901,7 +953,7 @@ export class Screen {
901
953
  this.resizeTimer = null;
902
954
  this.resizeSince = 0;
903
955
  const cols = this.width;
904
- const screenRows = Math.max(1, this.out.rows || this.height);
956
+ const screenRows = Math.max(1, this.dimensions[1]);
905
957
  this.takeStatic();
906
958
  const layout = this.layoutLive(cols);
907
959
  const room = Math.max(0, screenRows - layout.rows.length);
@@ -933,7 +985,7 @@ export class Screen {
933
985
 
934
986
  flush() {
935
987
  if (this.closed) return;
936
- if (this.resizing) return; // the repaint after the resize writes everything that is waiting
988
+ if (this.checkSize() || this.resizing) return; // the repaint after the resize writes everything that is waiting
937
989
  if (this.full) { this.takeStatic(); this.draw(); return; }
938
990
  if (this.scheduled) { clearTimeout(this.scheduled); this.scheduled = null; }
939
991
  const cols = this.width;
@@ -1004,6 +1056,7 @@ export class Screen {
1004
1056
  this.flush();
1005
1057
  }
1006
1058
  this.closed = true;
1059
+ clearInterval(this.sizeTimer);
1007
1060
  clearTimeout(this.resizeTimer);
1008
1061
  // Give the tab back its old label: a terminal with a title stack restores it, and one without is
1009
1062
  // left with a neutral one rather than a title that still looks like a program that is running.