@yanzc/claude-pro 0.9.3 → 0.9.4
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/package.json +1 -1
- package/src/ui/ansi.js +51 -2
- package/src/ui/repl.js +2 -1
- package/src/ui/screen.js +60 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanzc/claude-pro",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4",
|
|
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/ui/ansi.js
CHANGED
|
@@ -96,8 +96,57 @@ function inRanges(cp, ranges) {
|
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
//
|
|
100
|
-
//
|
|
99
|
+
// East Asian Ambiguous characters (UAX #11: the Basic Multilingual Plane, without combining marks and the private
|
|
100
|
+
// use area). A terminal gives them one cell or two depending on its font and settings: the Windows console with a
|
|
101
|
+
// Chinese, Japanese or Korean font draws those its font has full-width glyphs for (“ ” — … · × ° ① → ■ α Я) in
|
|
102
|
+
// two cells and the others (é, box drawing) in one, whatever the code page. So their widths are measured where
|
|
103
|
+
// that matters (see queryCursorRow in screen.js), not looked up. (Ranges end where a block does: neighbours in a
|
|
104
|
+
// block mostly have the same width, which is what measuring them together relies on.)
|
|
105
|
+
const AMBIGUOUS = [
|
|
106
|
+
[0xa1, 0xa1], [0xa4, 0xa4], [0xa7, 0xa8], [0xaa, 0xaa], [0xae, 0xae], [0xb0, 0xb4], [0xb6, 0xba], [0xbc, 0xbf],
|
|
107
|
+
[0xc6, 0xc6], [0xd0, 0xd0], [0xd7, 0xd8], [0xde, 0xe1], [0xe6, 0xe6], [0xe8, 0xea], [0xec, 0xed], [0xf0, 0xf0],
|
|
108
|
+
[0xf2, 0xf3], [0xf7, 0xfa], [0xfc, 0xfc], [0xfe, 0xfe], [0x101, 0x101], [0x111, 0x111], [0x113, 0x113],
|
|
109
|
+
[0x11b, 0x11b], [0x126, 0x127], [0x12b, 0x12b], [0x131, 0x133], [0x138, 0x138], [0x13f, 0x142], [0x144, 0x144],
|
|
110
|
+
[0x148, 0x14b], [0x14d, 0x14d], [0x152, 0x153], [0x166, 0x167], [0x16b, 0x16b], [0x1ce, 0x1ce], [0x1d0, 0x1d0],
|
|
111
|
+
[0x1d2, 0x1d2], [0x1d4, 0x1d4], [0x1d6, 0x1d6], [0x1d8, 0x1d8], [0x1da, 0x1da], [0x1dc, 0x1dc], [0x251, 0x251],
|
|
112
|
+
[0x261, 0x261], [0x2c4, 0x2c4], [0x2c7, 0x2c7], [0x2c9, 0x2cb], [0x2cd, 0x2cd], [0x2d0, 0x2d0], [0x2d8, 0x2db],
|
|
113
|
+
[0x2dd, 0x2dd], [0x2df, 0x2df], [0x391, 0x3a1], [0x3a3, 0x3a9], [0x3b1, 0x3c1], [0x3c3, 0x3c9], [0x401, 0x401],
|
|
114
|
+
[0x410, 0x44f], [0x451, 0x451], [0x2010, 0x2010], [0x2013, 0x2016], [0x2018, 0x2019], [0x201c, 0x201d],
|
|
115
|
+
[0x2020, 0x2022], [0x2024, 0x2027], [0x2030, 0x2030], [0x2032, 0x2033], [0x2035, 0x2035], [0x203b, 0x203b],
|
|
116
|
+
[0x203e, 0x203e], [0x2074, 0x2074], [0x207f, 0x207f], [0x2081, 0x2084], [0x20ac, 0x20ac], [0x2103, 0x2103],
|
|
117
|
+
[0x2105, 0x2105], [0x2109, 0x2109], [0x2113, 0x2113], [0x2116, 0x2116], [0x2121, 0x2122], [0x2126, 0x2126],
|
|
118
|
+
[0x212b, 0x212b], [0x2153, 0x2154], [0x215b, 0x215e], [0x2160, 0x216b], [0x2170, 0x2179], [0x2189, 0x2189],
|
|
119
|
+
[0x2190, 0x2199], [0x21b8, 0x21b9], [0x21d2, 0x21d2], [0x21d4, 0x21d4], [0x21e7, 0x21e7], [0x2200, 0x2200], [0x2202, 0x2203],
|
|
120
|
+
[0x2207, 0x2208], [0x220b, 0x220b], [0x220f, 0x220f], [0x2211, 0x2211], [0x2215, 0x2215], [0x221a, 0x221a],
|
|
121
|
+
[0x221d, 0x2220], [0x2223, 0x2223], [0x2225, 0x2225], [0x2227, 0x222c], [0x222e, 0x222e], [0x2234, 0x2237],
|
|
122
|
+
[0x223c, 0x223d], [0x2248, 0x2248], [0x224c, 0x224c], [0x2252, 0x2252], [0x2260, 0x2261], [0x2264, 0x2267],
|
|
123
|
+
[0x226a, 0x226b], [0x226e, 0x226f], [0x2282, 0x2283], [0x2286, 0x2287], [0x2295, 0x2295], [0x2299, 0x2299],
|
|
124
|
+
[0x22a5, 0x22a5], [0x22bf, 0x22bf], [0x2312, 0x2312], [0x2460, 0x24e9], [0x24eb, 0x24ff], [0x2500, 0x254b],
|
|
125
|
+
[0x2550, 0x2573], [0x2580, 0x258f], [0x2592, 0x2595], [0x25a0, 0x25a1], [0x25a3, 0x25a9], [0x25b2, 0x25b3], [0x25b6, 0x25b7],
|
|
126
|
+
[0x25bc, 0x25bd], [0x25c0, 0x25c1], [0x25c6, 0x25c8], [0x25cb, 0x25cb], [0x25ce, 0x25d1], [0x25e2, 0x25e5],
|
|
127
|
+
[0x25ef, 0x25ef], [0x2605, 0x2606], [0x2609, 0x2609], [0x260e, 0x260f], [0x261c, 0x261c], [0x261e, 0x261e],
|
|
128
|
+
[0x2640, 0x2640], [0x2642, 0x2642], [0x2660, 0x2661], [0x2663, 0x2665], [0x2667, 0x266a], [0x266c, 0x266d],
|
|
129
|
+
[0x266f, 0x266f], [0x269e, 0x269f], [0x26bf, 0x26bf], [0x26c6, 0x26cd], [0x26cf, 0x26d3], [0x26d5, 0x26e1],
|
|
130
|
+
[0x26e3, 0x26e3], [0x26e8, 0x26e9], [0x26eb, 0x26f1], [0x26f4, 0x26f4], [0x26f6, 0x26f9], [0x26fb, 0x26fc],
|
|
131
|
+
[0x26fe, 0x26ff], [0x273d, 0x273d], [0x2776, 0x277f], [0x2b56, 0x2b59], [0x3248, 0x324f], [0xfffd, 0xfffd],
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
// Those characters as strings of neighbours: each range, in pieces of at most `max` characters.
|
|
135
|
+
export function ambiguousGroups(max) {
|
|
136
|
+
const groups = [];
|
|
137
|
+
for (const [from, to] of AMBIGUOUS) {
|
|
138
|
+
for (let cp = from; cp <= to; cp += max) {
|
|
139
|
+
let text = '';
|
|
140
|
+
for (let k = cp; k <= Math.min(to, cp + max - 1); k++) text += String.fromCodePoint(k);
|
|
141
|
+
groups.push(text);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return groups;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// The widths this terminal was measured to give characters (see queryCursorRow): [[character, cells], ...]. They
|
|
148
|
+
// come before the tables above, which is what makes the program's layout and the terminal's agree where the
|
|
149
|
+
// terminal draws a symbol such as ·, … or “ in two cells.
|
|
101
150
|
const terminalWidths = new Map();
|
|
102
151
|
export function setTerminalWidths(widths) {
|
|
103
152
|
terminalWidths.clear();
|
package/src/ui/repl.js
CHANGED
|
@@ -2418,7 +2418,8 @@ export class App {
|
|
|
2418
2418
|
// ---------------------------------------------------------------- live region
|
|
2419
2419
|
|
|
2420
2420
|
spinnerLine() {
|
|
2421
|
-
|
|
2421
|
+
// (as wide as the widest frame: where the terminal draws some of them in two cells, the text behind moved back and forth)
|
|
2422
|
+
const frame = padEnd(SPINNER[Math.floor(Date.now() / 120) % SPINNER.length], Math.max(...SPINNER.map(stringWidth)));
|
|
2422
2423
|
if (this.rateWait) {
|
|
2423
2424
|
const w = this.rateWait;
|
|
2424
2425
|
const left = humanDuration(w.resumeAt - Date.now()); // the same wording as the notice above it
|
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, setTerminalWidths } from './ansi.js';
|
|
32
|
+
import { ESC, wrapLine, termWidth, truncate, stringWidth, stripAnsi, graphemes, graphemeWidth, setTerminalWidths, ambiguousGroups } from './ansi.js';
|
|
33
33
|
|
|
34
34
|
const SYNC_START = '\x1b[?2026h';
|
|
35
35
|
const SYNC_END = '\x1b[?2026l';
|
|
@@ -137,17 +137,45 @@ export function mouseFilter(stdin, onMouse) {
|
|
|
137
137
|
return out;
|
|
138
138
|
}
|
|
139
139
|
const CPR = /\x1b\[(\d+);(\d+)R/g; // the terminal's answer to DSR 6: row;column
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
//
|
|
140
|
+
// Windows: the symbols the interface is drawn with are measured at start-up (see queryCursorRow), as its terminals
|
|
141
|
+
// do not agree on their widths. The first FONT_SIZED of them are East Asian Ambiguous characters: a terminal that
|
|
142
|
+
// draws one of those in two cells sizes all such characters by its font, and is asked about all of them.
|
|
143
|
+
const UI_PROBES = process.platform === 'win32' ? Array.from('·…↑↓←→↻⇣⏎◷⇄•◦⏺⎿✻✢✳✶✽✉⚠') : [];
|
|
144
|
+
const FONT_SIZED = 6;
|
|
145
|
+
const AMBIGUOUS_TIMEOUT_MS = 1500; // some 200 to 400 answers: 0.2 ms each in the Windows 11 console, 0.5 on a server
|
|
146
|
+
|
|
147
|
+
// Ask the terminal where the cursor is (DSR 6): resolves with its row (1-based), or null when it does not answer
|
|
148
|
+
// within `timeout`. Run before anything else reads `stdin`, with the terminal in raw mode; what else arrives
|
|
149
|
+
// meanwhile (keys typed during start-up) is put back for the key reader, byte for byte.
|
|
150
|
+
//
|
|
151
|
+
// On Windows the widths of characters are measured too (setTerminalWidths): each one is written at the start of the
|
|
152
|
+
// cursor's row and the cursor's column asked for, and the row is erased afterwards. The interface's own symbols
|
|
153
|
+
// first; then, only where the terminal sizes ambiguous characters by its font (the console with a Chinese font: ·
|
|
154
|
+
// … “ ” — × ① in two cells), all of those: text with them in it was wrapped and padded as if they took one cell,
|
|
155
|
+
// which broke rows in two and left the footer on screen twice. Those are some 800 characters, so neighbours are
|
|
156
|
+
// written together first: one answer does for all of them when they are all one cell wide or all two, which most
|
|
157
|
+
// are, and only the others are then asked about one by one. A batch that is not answered whole in time is not used.
|
|
146
158
|
export function queryCursorRow(stdin, out, timeout = 300) {
|
|
147
159
|
return new Promise((resolve) => {
|
|
148
160
|
let buf = Buffer.alloc(0);
|
|
149
|
-
let timer = null,
|
|
161
|
+
let timer = null, finished = false, batch = 0;
|
|
162
|
+
const sent = []; // what was written to be measured (a character, or neighbours), in the order of the answers
|
|
163
|
+
let answered = 0; // how many of them have an answer: counted when a whole batch is in
|
|
150
164
|
const replies = () => [...buf.toString('latin1').matchAll(CPR)];
|
|
165
|
+
const cells = (matches, i) => Number(matches[1 + i][2]) - 1;
|
|
166
|
+
// The width of each character of `text`, which took `n` cells: 0 when they are not all one or all two cells wide.
|
|
167
|
+
const uniform = (text, n) => (n === text.length ? 1 : n === 2 * text.length ? 2 : 0);
|
|
168
|
+
// What to measure next, decided by the answers so far.
|
|
169
|
+
const next = (matches) => {
|
|
170
|
+
batch++;
|
|
171
|
+
if (batch === 1) return UI_PROBES.length && !(out.columns && out.columns < 3) ? UI_PROBES : [];
|
|
172
|
+
if (batch === 2) {
|
|
173
|
+
if (!UI_PROBES.slice(0, FONT_SIZED).some((_, i) => cells(matches, i) === 2)) return [];
|
|
174
|
+
return ambiguousGroups(Math.max(1, Math.min(40, Math.floor(((out.columns || 80) - 2) / 2)))); // a piece fits the row at two cells each
|
|
175
|
+
}
|
|
176
|
+
if (batch === 3) return sent.flatMap((text, i) => (text.length > 1 && !uniform(text, cells(matches, i)) ? [...text] : []));
|
|
177
|
+
return [];
|
|
178
|
+
};
|
|
151
179
|
const done = () => {
|
|
152
180
|
if (finished) return;
|
|
153
181
|
finished = true;
|
|
@@ -156,30 +184,39 @@ export function queryCursorRow(stdin, out, timeout = 300) {
|
|
|
156
184
|
stdin.pause();
|
|
157
185
|
const matches = replies();
|
|
158
186
|
const first = matches[0];
|
|
159
|
-
if (
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
187
|
+
if (sent.length) {
|
|
188
|
+
const answers = matches.slice(1, 1 + answered);
|
|
189
|
+
// (an answer from another row: the screen moved meanwhile, and nothing that was measured is trusted)
|
|
190
|
+
if (answers.every((m) => m[1] === first[1])) {
|
|
191
|
+
const widths = [];
|
|
192
|
+
answers.forEach((m, i) => {
|
|
193
|
+
const width = uniform(sent[i], Number(m[2]) - 1);
|
|
194
|
+
if (width) for (const char of sent[i]) widths.push([char, width]);
|
|
195
|
+
});
|
|
196
|
+
setTerminalWidths(widths);
|
|
197
|
+
}
|
|
198
|
+
try { out.write('\r' + ESC.right(Number(first[2]) - 1) + ESC.showCursor + SYNC_END); } catch { /* the terminal is gone */ }
|
|
163
199
|
}
|
|
164
200
|
// latin1 keeps a one-to-one mapping of bytes, including keys/pastes split in the middle of a UTF-8 character.
|
|
165
201
|
const rest = Buffer.from(buf.toString('latin1').replace(CPR, ''), 'latin1');
|
|
166
202
|
if (rest.length) stdin.unshift(rest);
|
|
167
203
|
resolve(first ? Number(first[1]) : null);
|
|
168
204
|
};
|
|
205
|
+
const measure = (texts, ms) => {
|
|
206
|
+
const start = sent.length ? '' : SYNC_START + ESC.hideCursor;
|
|
207
|
+
sent.push(...texts);
|
|
208
|
+
clearTimeout(timer);
|
|
209
|
+
timer = setTimeout(done, ms);
|
|
210
|
+
try { out.write(start + texts.map((text) => '\r' + text + '\x1b[6n').join('') + '\r\x1b[K'); } catch { done(); }
|
|
211
|
+
};
|
|
169
212
|
const onData = (d) => {
|
|
170
213
|
buf = Buffer.concat([buf, Buffer.isBuffer(d) ? d : Buffer.from(String(d), 'utf8')]);
|
|
171
214
|
const matches = replies();
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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(); }
|
|
215
|
+
if (matches.length < 1 + sent.length) return; // the first answer is the cursor's position
|
|
216
|
+
answered = sent.length;
|
|
217
|
+
const more = next(matches);
|
|
218
|
+
if (more.length) measure(more, batch === 1 ? timeout : AMBIGUOUS_TIMEOUT_MS);
|
|
219
|
+
else done();
|
|
183
220
|
};
|
|
184
221
|
timer = setTimeout(done, timeout);
|
|
185
222
|
stdin.on('data', onData);
|