@hncode/hncode 0.8.1 → 0.8.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 +18 -0
- package/README_CN.md +14 -0
- package/bin/hncode +54 -8
- package/package.json +1 -1
- package/src/agent-task.js +356 -337
- package/src/agent.js +1465 -1405
- package/src/animate.js +56 -0
- package/src/colors.js +615 -593
- package/src/config.js +50 -7
- package/src/context-bar.js +280 -278
- package/src/doctor.js +4 -3
- package/src/file-tree.js +4 -3
- package/src/highlight.js +20 -6
- package/src/i18n.js +1432 -389
- package/src/image-row.js +11 -2
- package/src/index.js +218 -6
- package/src/keybindings.js +2 -1
- package/src/llm.js +146 -21
- package/src/log-file.js +112 -0
- package/src/markdown.js +646 -567
- package/src/mcp-server.js +409 -0
- package/src/mcp.js +279 -29
- package/src/memory-profile.js +19 -16
- package/src/migrate-index.js +175 -0
- package/src/migrate.js +392 -0
- package/src/panels.js +9 -7
- package/src/plan.js +7 -5
- package/src/plugin.js +37 -21
- package/src/registry-browser.js +17 -15
- package/src/rows-plan-bg.js +3 -2
- package/src/rows-status.js +20 -6
- package/src/rows-tool-result.js +242 -208
- package/src/screen-paint.js +153 -128
- package/src/session-recover.js +317 -0
- package/src/session.js +203 -13
- package/src/settings-schema.js +9 -0
- package/src/swarm-progress.js +6 -2
- package/src/tasks-browser.js +37 -36
- package/src/team-panel.js +12 -11
- package/src/term.js +57 -21
- package/src/text.js +254 -149
- package/src/tool-line.js +7 -2
- package/src/tool-result.js +400 -327
- package/src/tools/agent.js +7 -2
- package/src/tools/ask-user-question.js +1 -2
- package/src/tools/bash.js +446 -434
- package/src/tools/edit.js +653 -665
- package/src/tools/goal.js +130 -93
- package/src/tools/read.js +141 -133
- package/src/tools/tasks.js +214 -214
- package/src/tools/utils.js +143 -104
- package/src/tui.js +20887 -19942
package/src/session.js
CHANGED
|
@@ -6,6 +6,8 @@ import os from 'node:os';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import crypto from 'node:crypto';
|
|
9
|
+
import { recoverSessionFile } from './session-recover.js';
|
|
10
|
+
import { appendLog } from './log-file.js';
|
|
9
11
|
|
|
10
12
|
const DEFAULT_DIR = () => path.join(os.homedir(), '.hncode', 'sessions');
|
|
11
13
|
function dir(custom) { return custom || process.env.HNCODE_SESSIONS_DIR || DEFAULT_DIR(); }
|
|
@@ -36,18 +38,15 @@ export function invalidateSessionCache(storeDir) {
|
|
|
36
38
|
// if external state is suspected. Our own save/delete already invalidate.
|
|
37
39
|
|
|
38
40
|
// FIX: single place for the error log so save/load failures are never silent.
|
|
41
|
+
//
|
|
42
|
+
// Rotation-bounded: this file is written by every failed save, so an unattended session
|
|
43
|
+
// that keeps failing one would otherwise grow without limit — and the failure it records
|
|
44
|
+
// is the one thing the user needs to read, so it must not bury itself.
|
|
39
45
|
function errorLogFile() {
|
|
40
46
|
return path.join(os.homedir(), '.hncode', 'session-errors.log');
|
|
41
47
|
}
|
|
42
48
|
function logSessionError(op, detail) {
|
|
43
|
-
|
|
44
|
-
fs.mkdirSync(path.dirname(errorLogFile()), { recursive: true });
|
|
45
|
-
fs.appendFileSync(
|
|
46
|
-
errorLogFile(),
|
|
47
|
-
`[${new Date().toISOString()}] ${op}: ${detail}\n`,
|
|
48
|
-
'utf8',
|
|
49
|
-
);
|
|
50
|
-
} catch { /* logging must never throw */ }
|
|
49
|
+
appendLog(errorLogFile(), `[${new Date().toISOString()}] ${op}: ${detail}\n`);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
export function newId() {
|
|
@@ -113,6 +112,10 @@ function serializableSession(session) {
|
|
|
113
112
|
for (const k of Object.keys(session)) {
|
|
114
113
|
if (k in out) continue;
|
|
115
114
|
if (k === 'messages' || k === 'transcript') continue;
|
|
115
|
+
// `_`-prefixed keys are runtime markers, never session data. `_unrecoverable` says the
|
|
116
|
+
// file could not be read back; persisting it would make the NEXT load treat a healthy
|
|
117
|
+
// session as damaged.
|
|
118
|
+
if (k.startsWith('_')) continue;
|
|
116
119
|
out[k] = session[k];
|
|
117
120
|
}
|
|
118
121
|
out.messages = Array.isArray(session.messages) ? session.messages : [];
|
|
@@ -120,7 +123,104 @@ function serializableSession(session) {
|
|
|
120
123
|
return out;
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
// ---- saving -----------------------------------------------------------------
|
|
127
|
+
//
|
|
128
|
+
// SAVING IS ON THE PER-TURN PATH, SO IT MUST NOT BLOCK THE FRAME.
|
|
129
|
+
//
|
|
130
|
+
// `saveSession` used to do the whole thing synchronously: `JSON.stringify` of the entire history, then `writeFileSync`,
|
|
131
|
+
// then `renameSync`. On a 2.5 MB session that is a visible stall between the user pressing Enter and anything appearing
|
|
132
|
+
// on screen — and it is paid TWICE per turn, once for the user message and once at each step boundary
|
|
133
|
+
// (`persistTurnProgress`). A slow disk multiplies all of it.
|
|
134
|
+
//
|
|
135
|
+
// The write is now scheduled, and calls that land in the same tick coalesce into ONE write: the session object is the
|
|
136
|
+
// same reference every time, so the last call is the one worth writing.
|
|
137
|
+
//
|
|
138
|
+
// ORDERING IS KEPT. `serialize` runs INSIDE the scheduled callback, not at call time, so the bytes written always
|
|
139
|
+
// describe the session as it is when the write happens — never an older snapshot queued behind a newer one.
|
|
140
|
+
//
|
|
141
|
+
// A CALLER THAT MUST HAVE THE BYTES ON DISK uses `saveSessionNow` (used on exit).
|
|
142
|
+
let pendingSave = null; // { session, storeDir }
|
|
143
|
+
let pendingScheduled = false;
|
|
144
|
+
let saveTimer = null;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* How long a queued save may wait.
|
|
148
|
+
*
|
|
149
|
+
* A turn saves once per step boundary plus once at the end, a few seconds apart — long enough that `setImmediate` never
|
|
150
|
+
* coalesced any of them. Three seconds is short enough that a crash loses at most the last step, and long enough that a
|
|
151
|
+
* burst of steps becomes one write.
|
|
152
|
+
*/
|
|
153
|
+
const SAVE_DELAY_MS = 3000;
|
|
154
|
+
|
|
155
|
+
// Declared before its first use: `writeSessionSync` records a failure, and a `let` further down the file would
|
|
156
|
+
// put it in the temporal dead zone.
|
|
157
|
+
let saveFailure = null;
|
|
158
|
+
|
|
159
|
+
// ---- incremental serialisation ------------------------------------------------
|
|
160
|
+
//
|
|
161
|
+
// A SAVE USED TO RE-SERIALISE EVERY MESSAGE, WHICH IS THE WHOLE HISTORY EVERY TIME.
|
|
162
|
+
//
|
|
163
|
+
// Measured on the real session: 19.8ms of JSON.stringify per save, 43ms including the write, and a turn saves several
|
|
164
|
+
// times. Deferring it only moved the stall to a later frame — during streaming, which is the worst moment for one.
|
|
165
|
+
//
|
|
166
|
+
// A turn appends a few messages and leaves the rest untouched, so each message's JSON is worth keeping. `WeakMap` on
|
|
167
|
+
// the message object is the right home for it: the entry dies with the message, and a message that is REPLACED (a
|
|
168
|
+
// compaction rebuilds the array, /undo swaps objects) simply misses. A message that is MUTATED IN PLACE is the one case
|
|
169
|
+
// a WeakMap cannot see — that is what `bumpMessage` is for, and the call sites that edit an existing message use it.
|
|
170
|
+
//
|
|
171
|
+
// Measured: 15.97ms cold for the whole array, 0.14ms once the cache is warm. That is the difference between a stall the
|
|
172
|
+
// user can see and one they cannot.
|
|
173
|
+
const messageJson = new WeakMap();
|
|
174
|
+
|
|
175
|
+
/** JSON for one message, cached on the object. */
|
|
176
|
+
function jsonOf(m) {
|
|
177
|
+
let j = messageJson.get(m);
|
|
178
|
+
if (j === undefined) { j = JSON.stringify(m); messageJson.set(m, j); }
|
|
179
|
+
return j;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Forget a message's cached JSON. Call after editing one IN PLACE.
|
|
184
|
+
*
|
|
185
|
+
* A rename of the field itself would be a compile error; this cannot be, so the discipline is: anything that writes to
|
|
186
|
+
* a message that may already have been saved calls this. Missing one means that edit is not persisted until the message
|
|
187
|
+
* object is replaced — not corruption, but a stale field on the next resume.
|
|
188
|
+
*/
|
|
189
|
+
export function bumpMessage(m) {
|
|
190
|
+
if (m && typeof m === 'object') messageJson.delete(m);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* `JSON.stringify(session)` without re-serialising messages that have not changed.
|
|
195
|
+
*
|
|
196
|
+
* The outer object is small (a dozen scalars), so it is rebuilt every time; only `messages` — and a `transcript` array,
|
|
197
|
+
* when there is one — come from the per-message cache. The result is byte-identical to one `JSON.stringify` call, which
|
|
198
|
+
* is what the reader on the other side expects.
|
|
199
|
+
*/
|
|
200
|
+
function stringifySession(session) {
|
|
201
|
+
const obj = serializableSession(session);
|
|
202
|
+
const messages = obj.messages;
|
|
203
|
+
// The rest of the object is tiny, so it is serialised normally with a placeholder standing in for the arrays.
|
|
204
|
+
const PLACE = '\u0000HNCODE_PLACEHOLDER\u0000';
|
|
205
|
+
const shallow = { ...obj, messages: PLACE };
|
|
206
|
+
if (Array.isArray(obj.transcript)) shallow.transcript = PLACE;
|
|
207
|
+
const text = JSON.stringify(shallow);
|
|
208
|
+
// A REPLACEMENT STRING IS NOT LITERAL. `String.replace` expands `$&`, `` $` ``, `$'` and
|
|
209
|
+
// `$$` inside it, so a message that merely MENTIONED `sed s/x/$&/g` spliced a copy of the
|
|
210
|
+
// session's own metadata head into its own JSON — every save corrupted the file, the file
|
|
211
|
+
// would not parse, and the next save wrote an empty history over it. Returning the value
|
|
212
|
+
// from a function is the only form that is not expanded.
|
|
213
|
+
const messagesJson = '[' + messages.map((m) => (m && typeof m === 'object' ? jsonOf(m) : JSON.stringify(m))).join(',') + ']';
|
|
214
|
+
let out = text.replace(JSON.stringify(PLACE), () => messagesJson);
|
|
215
|
+
if (Array.isArray(obj.transcript)) {
|
|
216
|
+
const tr = obj.transcript;
|
|
217
|
+
const trJson = '[' + tr.map((m) => (m && typeof m === 'object' ? jsonOf(m) : JSON.stringify(m))).join(',') + ']';
|
|
218
|
+
out = out.replace(JSON.stringify(PLACE), () => trJson);
|
|
219
|
+
}
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function writeSessionSync(session, storeDir) {
|
|
124
224
|
if (!session || !session.id) return session;
|
|
125
225
|
// Keep the live object's updatedAt in sync for callers that read it back.
|
|
126
226
|
session.updatedAt = Date.now();
|
|
@@ -133,8 +233,8 @@ export function saveSession(session, storeDir) {
|
|
|
133
233
|
// Compact JSON, no indentation. `null, 2` made the file ~30% larger for a
|
|
134
234
|
// human who never reads it (the reader is JSON.parse), and the pretty-printer
|
|
135
235
|
// itself costs real time on a large transcript — measured ~22ms for 5.7MB, all
|
|
136
|
-
// of it spent inserting whitespace.
|
|
137
|
-
const json =
|
|
236
|
+
// of it spent inserting whitespace.
|
|
237
|
+
const json = stringifySession(session);
|
|
138
238
|
fs.writeFileSync(tmp, json, 'utf8');
|
|
139
239
|
// Atomic replace. If this throws (EXDEV etc.) the temp is cleaned up below.
|
|
140
240
|
fs.renameSync(tmp, target);
|
|
@@ -158,9 +258,79 @@ export function saveSession(session, storeDir) {
|
|
|
158
258
|
return session;
|
|
159
259
|
}
|
|
160
260
|
|
|
261
|
+
/**
|
|
262
|
+
* Queue a save for the next event-loop tick, coalescing with any other call that lands before then.
|
|
263
|
+
*
|
|
264
|
+
* THIS IS THE ONE THE TUI USES. `saveSession` stays synchronous because its contract is "the file is on disk when
|
|
265
|
+
* this returns", and several callers depend on that — the store-integrity tests among them. On the per-turn path that
|
|
266
|
+
* contract is what costs a visible stall: a 1.3 MB session measured 38 ms of `JSON.stringify` + `writeFileSync`
|
|
267
|
+
* between Enter and the first frame, paid twice a turn, on a slow disk much worse.
|
|
268
|
+
*
|
|
269
|
+
* The session object is the same reference every time, so the last call is the one worth writing. `serialize` runs
|
|
270
|
+
* inside the scheduled callback, never at call time, so the bytes written always describe the session as it is when
|
|
271
|
+
* the write happens.
|
|
272
|
+
*/
|
|
273
|
+
export function saveSessionSoon(session, storeDir) {
|
|
274
|
+
if (!session || !session.id) return session;
|
|
275
|
+
// Update the timestamp NOW so the object a caller reads back is already stamped — the same
|
|
276
|
+
// guarantee the synchronous version gave.
|
|
277
|
+
session.updatedAt = Date.now();
|
|
278
|
+
pendingSave = { session, storeDir };
|
|
279
|
+
// A SHORT DELAY, NOT THE NEXT TICK.
|
|
280
|
+
//
|
|
281
|
+
// `setImmediate` coalesced calls made in one tick, which is not what a turn looks like: a turn's saves are spread
|
|
282
|
+
// across seconds (one per step boundary, then the turn end), so every one of them ran a full `JSON.stringify` plus
|
|
283
|
+
// write on the main thread — 17-38 ms each on a real session, and each one is a frame the user sees stop.
|
|
284
|
+
//
|
|
285
|
+
// Nothing reads a session file while the program is running: `loadSession` is called at startup and from `/sessions`,
|
|
286
|
+
// both by the same process that already holds the live object. So the file only has to be CURRENT ENOUGH for a crash,
|
|
287
|
+
// and a few seconds of coalescing costs at most the last couple of steps of a session that died — against a stall the
|
|
288
|
+
// user pays on every single turn.
|
|
289
|
+
//
|
|
290
|
+
// `flushSaves` (exit) and `saveSession` (callers that need the bytes now) still write immediately.
|
|
291
|
+
if (!pendingScheduled) {
|
|
292
|
+
pendingScheduled = true;
|
|
293
|
+
saveTimer = setTimeout(() => {
|
|
294
|
+
saveTimer = null;
|
|
295
|
+
pendingScheduled = false;
|
|
296
|
+
const job = pendingSave;
|
|
297
|
+
pendingSave = null;
|
|
298
|
+
if (job) writeSessionSync(job.session, job.storeDir);
|
|
299
|
+
}, SAVE_DELAY_MS);
|
|
300
|
+
// The timer must not hold the process open by itself.
|
|
301
|
+
if (saveTimer.unref) saveTimer.unref();
|
|
302
|
+
}
|
|
303
|
+
return session;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Write any queued save NOW and wait for it. For exit paths, where there is no next tick. */
|
|
307
|
+
export function flushSaves() {
|
|
308
|
+
const job = pendingSave;
|
|
309
|
+
pendingSave = null;
|
|
310
|
+
pendingScheduled = false;
|
|
311
|
+
// The timer would fire into an empty queue anyway; clearing it keeps the process from lingering for its sake.
|
|
312
|
+
if (saveTimer) { clearTimeout(saveTimer); saveTimer = null; }
|
|
313
|
+
if (job) writeSessionSync(job.session, job.storeDir);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Save the session, synchronously. The file is on disk when this returns.
|
|
318
|
+
*
|
|
319
|
+
* Kept as the default because that is its documented contract and callers rely on it — reading the file straight
|
|
320
|
+
* back, listing sessions right after a rename, and asserting on a write failure all need the bytes to be there. The
|
|
321
|
+
* per-turn path uses `saveSessionSoon` instead; see it for why that matters on a large session.
|
|
322
|
+
*/
|
|
323
|
+
export function saveSession(session, storeDir) {
|
|
324
|
+
return writeSessionSync(session, storeDir);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** Save synchronously. Only for callers that cannot wait for the next tick (exit). */
|
|
328
|
+
export function saveSessionNow(session, storeDir) {
|
|
329
|
+
return writeSessionSync(session, storeDir);
|
|
330
|
+
}
|
|
331
|
+
|
|
161
332
|
// The most recent save failure, or null. Set once per failure so a caller can report it
|
|
162
333
|
// (the TUI shows a warning) without this module reaching into the UI.
|
|
163
|
-
let saveFailure = null;
|
|
164
334
|
|
|
165
335
|
/** The last save failure `{ at, id, detail }`, or null when saving has been clean. */
|
|
166
336
|
export function lastSaveFailure() { return saveFailure; }
|
|
@@ -180,6 +350,19 @@ export function loadSession(id, storeDir) {
|
|
|
180
350
|
try {
|
|
181
351
|
return JSON.parse(text);
|
|
182
352
|
} catch (e) {
|
|
353
|
+
// A file that no longer parses is RECOVERED, not written off. An older hncode wrote
|
|
354
|
+
// session files through a `String.replace`, and a message that happened to contain
|
|
355
|
+
// `$&` or `` $` `` spliced a copy of the file's own metadata into it — which then
|
|
356
|
+
// failed to parse here, fell back to the metadata head in `latestSession`, and was
|
|
357
|
+
// overwritten with an empty history by the next save. See session-recover.js.
|
|
358
|
+
const fixed = recoverSessionFile(file, text);
|
|
359
|
+
if (fixed && fixed.session) {
|
|
360
|
+
logSessionError('recover', `${id}: ${e.message} -> ${fixed.report.route}, `
|
|
361
|
+
+ `${fixed.report.kept} kept, ${fixed.report.dropped} dropped`
|
|
362
|
+
+ (fixed.wrote ? `, original kept as ${fixed.backup}` : ', file NOT rewritten'));
|
|
363
|
+
cacheFor(storeDir, false)?.delete(file);
|
|
364
|
+
return fixed.session;
|
|
365
|
+
}
|
|
183
366
|
// FIX: a corrupt file is NOT the same as a missing session. Log it so the
|
|
184
367
|
// user can find the damaged file instead of silently "losing" the session.
|
|
185
368
|
logSessionError('parse', `${id}: ${e.message} (file: ${file})`);
|
|
@@ -216,7 +399,14 @@ export function latestSession(cwd, storeDir, opts = {}) {
|
|
|
216
399
|
if (loaded) return loaded;
|
|
217
400
|
// If the full load failed (corrupt), fall back to the metadata we already have
|
|
218
401
|
// so the caller still gets an id/title/workspace instead of null.
|
|
219
|
-
|
|
402
|
+
//
|
|
403
|
+
// It is a LAST RESORT, not a session: it carries no `messages`, and the TUI's next save
|
|
404
|
+
// would write that emptiness to disk. Marked so the caller can refuse the resume instead
|
|
405
|
+
// — three real conversations were lost this way, each one an apparently healthy session
|
|
406
|
+
// with 700 rounds and no history.
|
|
407
|
+
return pick.meta && typeof pick.meta === 'object'
|
|
408
|
+
? { ...pick.meta, messages: [], _unrecoverable: true }
|
|
409
|
+
: pick.meta;
|
|
220
410
|
}
|
|
221
411
|
|
|
222
412
|
// Enumerate the session directory, reading each file's metadata head ONCE per
|
package/src/settings-schema.js
CHANGED
|
@@ -75,6 +75,10 @@ export const SETTINGS_SCHEMA = [
|
|
|
75
75
|
// forgetting it left /settings offering fewer themes than /theme did.
|
|
76
76
|
{ key: 'theme', ...en('dark', THEME_NAMES),
|
|
77
77
|
ui: { tab: 'appearance', group: 'Display', label: 'Theme', hint: 'Colour scheme. `auto` follows the terminal background' } },
|
|
78
|
+
// The language of the TERMINAL UI. Only what a person reads is translated; the system
|
|
79
|
+
// prompt and everything the model reads stay English.
|
|
80
|
+
{ key: 'lang', ...en('en', ['en', 'zh']),
|
|
81
|
+
ui: { tab: 'appearance', group: 'Display', label: 'Interface language', hint: 'The language the terminal UI speaks. The model still reads English' } },
|
|
78
82
|
{ key: 'calm_mode', ...bool(false),
|
|
79
83
|
ui: { tab: 'appearance', group: 'Display', label: 'Calm mode', hint: 'Fewer decorative flourishes; keeps the information, drops the animation' } },
|
|
80
84
|
{ key: 'reduced_motion', ...bool(false),
|
|
@@ -219,6 +223,11 @@ export const SETTINGS_SCHEMA = [
|
|
|
219
223
|
ui: { tab: 'model', group: 'Thinking', label: 'Max output size', hint: 'Startup default for the reply length; 0 means fall back' } },
|
|
220
224
|
{ key: 'reasoning', ...bool(false),
|
|
221
225
|
ui: { tab: 'model', group: 'Thinking', label: 'Reasoning by default', hint: 'Whether new sessions start with thinking on' } },
|
|
226
|
+
// Whether the model is told to wrap its reasoning in <|thinking|> tags. THREE states,
|
|
227
|
+
// not two: `auto` follows the model (a model with a reasoning channel does not need
|
|
228
|
+
// the tag, one without it does), and the other two decide by hand.
|
|
229
|
+
{ key: 'thinking_tags', ...en('auto', ['auto', 'on', 'off']),
|
|
230
|
+
ui: { tab: 'model', group: 'Thinking', label: 'Inline reasoning tags', hint: 'Ask the model to wrap its reasoning in <|thinking|> tags. Auto: only for a model with no reasoning channel of its own' } },
|
|
222
231
|
{ key: 'plugins_dir', ...str(''),
|
|
223
232
|
ui: { tab: 'advanced', group: 'MCP', label: 'Plugins directory', hint: 'Where plugins load from; defaults to ~/.hncode/plugins' } },
|
|
224
233
|
{ key: 'web_host', ...str('127.0.0.1'),
|
package/src/swarm-progress.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
import { C } from './colors.js';
|
|
25
25
|
import { visualWidth } from './term.js';
|
|
26
|
+
import { uiText } from './i18n.js';
|
|
26
27
|
|
|
27
28
|
const ESC = '\x1b';
|
|
28
29
|
function visWidth(s) { return visualWidth(String(s).replace(/\x1b\[[0-9;?]*[a-zA-Z]/g, '')); }
|
|
@@ -43,7 +44,10 @@ const PHASE = {
|
|
|
43
44
|
failed: { label: 'Failed.', color: C.red },
|
|
44
45
|
cancelled: { label: 'Cancelled.', color: C.gray },
|
|
45
46
|
};
|
|
46
|
-
export function phaseInfo(phase) {
|
|
47
|
+
export function phaseInfo(phase) {
|
|
48
|
+
const p = PHASE[phase] || PHASE.working;
|
|
49
|
+
return { ...p, label: uiText(p.label) };
|
|
50
|
+
}
|
|
47
51
|
|
|
48
52
|
const BAR_EMPTY = '-';
|
|
49
53
|
const BAR_FULL = '#';
|
|
@@ -237,7 +241,7 @@ export function renderSwarmProgress(snapshot, width, opts = {}) {
|
|
|
237
241
|
const lines = [];
|
|
238
242
|
|
|
239
243
|
// ---- header: `─ Agent Swarm ─ desc ─ model ─────` ----
|
|
240
|
-
const title = col('Agent Swarm', C.spring + C.bold);
|
|
244
|
+
const title = col(uiText('Agent Swarm'), C.spring + C.bold);
|
|
241
245
|
const suffix = [];
|
|
242
246
|
if (desc) suffix.push(col(' \u2500 ', C.spring) + col(desc, C.white));
|
|
243
247
|
if (model) suffix.push(col(' \u2500 ', C.spring) + col(model, C.gray));
|
package/src/tasks-browser.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { C } from './colors.js';
|
|
16
16
|
import { visualWidth } from './term.js';
|
|
17
17
|
import { STATUS_LABEL } from './agent-task.js';
|
|
18
|
+
import { uiText } from './i18n.js';
|
|
18
19
|
|
|
19
20
|
const ELLIPSIS = '\u2026';
|
|
20
21
|
const ESC = '\x1b';
|
|
@@ -77,12 +78,12 @@ function singleLine(t) { return String(t == null ? '' : t).replace(/\s+/g, ' ').
|
|
|
77
78
|
function relativeTime(ts) {
|
|
78
79
|
if (!ts || !Number.isFinite(ts) || ts <= 0) return '';
|
|
79
80
|
const d = Math.floor(Math.max(0, Date.now() - ts) / 1000);
|
|
80
|
-
if (d < 60) return 'just now';
|
|
81
|
+
if (d < 60) return uiText('just now');
|
|
81
82
|
const m = Math.floor(d / 60);
|
|
82
|
-
if (m < 60) return m + 'm ago';
|
|
83
|
+
if (m < 60) return m + uiText('m ago');
|
|
83
84
|
const h = Math.floor(m / 60);
|
|
84
|
-
if (h < 24) return h + 'h ago';
|
|
85
|
-
return Math.floor(h / 24) + 'd ago';
|
|
85
|
+
if (h < 24) return h + uiText('h ago');
|
|
86
|
+
return Math.floor(h / 24) + uiText('d ago');
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
export function visibleTasks(tasks, filter) {
|
|
@@ -127,11 +128,11 @@ export function renderTasksBrowser(state, cols, rows) {
|
|
|
127
128
|
const visible = visibleTasks(state.tasks, state.filter);
|
|
128
129
|
const counts = countByStatus(visible);
|
|
129
130
|
|
|
130
|
-
const segs = [C.cyan + C.bold + ' TASK BROWSER ' + C.reset, C.gray + ' filter=' + (state.filter === 'all' ? 'ALL' : 'ACTIVE') + ' ' + C.reset];
|
|
131
|
-
if (counts.running) segs.push(C.green + ' ' + counts.running + ' running ' + C.reset);
|
|
132
|
-
if (counts.completed) segs.push(C.gray + ' ' + counts.completed + ' completed ' + C.reset);
|
|
133
|
-
if (counts.failed) segs.push(C.red + ' ' + counts.failed + ' interrupted ' + C.reset);
|
|
134
|
-
segs.push(C.gray + ' ' + visible.length + ' total ' + C.reset);
|
|
131
|
+
const segs = [C.cyan + C.bold + uiText(' TASK BROWSER ') + C.reset, C.gray + ' filter=' + uiText(state.filter === 'all' ? 'ALL' : 'ACTIVE') + ' ' + C.reset];
|
|
132
|
+
if (counts.running) segs.push(C.green + ' ' + counts.running + uiText(' running ') + C.reset);
|
|
133
|
+
if (counts.completed) segs.push(C.gray + ' ' + counts.completed + uiText(' completed ') + C.reset);
|
|
134
|
+
if (counts.failed) segs.push(C.red + ' ' + counts.failed + uiText(' interrupted ') + C.reset);
|
|
135
|
+
segs.push(C.gray + ' ' + visible.length + uiText(' total ') + C.reset);
|
|
135
136
|
const header = fitExactly(segs.join(''), cols);
|
|
136
137
|
|
|
137
138
|
const key = (s) => C.cyan + C.bold + s + C.reset;
|
|
@@ -146,22 +147,22 @@ export function renderTasksBrowser(state, cols, rows) {
|
|
|
146
147
|
// gets a clickable span. `c` tracks the column so the spans land exactly on the
|
|
147
148
|
// rendered words — the original drew `N/esc cancel` as one run, so the two keys
|
|
148
149
|
// share the single "cancel" label and are measured as one span.
|
|
149
|
-
const prefix = ' ' + C.orange + C.bold + 'Stop' + C.reset + ' ' + C.white + state.pendingStop + C.reset + '? ';
|
|
150
|
+
const prefix = ' ' + C.orange + C.bold + uiText('Stop') + C.reset + ' ' + C.white + state.pendingStop + C.reset + '? ';
|
|
150
151
|
let c = visWidth(prefix);
|
|
151
|
-
const yPart = key('Y') + ' ' + dim('confirm');
|
|
152
|
+
const yPart = key('Y') + ' ' + dim(uiText('confirm'));
|
|
152
153
|
footerHits.push({ keyWord: 'Y', label: 'confirm', action: 'confirmStop', col0: c, col1: c + visWidth(yPart) - 1 });
|
|
153
154
|
c += visWidth(yPart) + 2;
|
|
154
|
-
const nPart = key('N') + dim('/') + key('esc') + ' ' + dim('cancel');
|
|
155
|
+
const nPart = key('N') + dim('/') + key('esc') + ' ' + dim(uiText('cancel'));
|
|
155
156
|
footerHits.push({ keyWord: 'N/esc', label: 'cancel', action: 'cancelStop', col0: c, col1: c + visWidth(nPart) - 1 });
|
|
156
157
|
footer = fitExactly(prefix + yPart + ' ' + nPart + ' ', cols);
|
|
157
158
|
} else {
|
|
158
159
|
const specs = [
|
|
159
|
-
['
|
|
160
|
-
['Enter/O', 'output', 'openOutput'],
|
|
161
|
-
['S', 'stop', 'requestStop'],
|
|
162
|
-
['R', 'refresh', 'refresh'],
|
|
163
|
-
['Tab', 'filter', 'toggleFilter'],
|
|
164
|
-
['Q/Esc', 'close', 'close'],
|
|
160
|
+
['↑↓', uiText('select'), 'select'],
|
|
161
|
+
['Enter/O', uiText('output'), 'openOutput'],
|
|
162
|
+
['S', uiText('stop'), 'requestStop'],
|
|
163
|
+
['R', uiText('refresh'), 'refresh'],
|
|
164
|
+
['Tab', uiText('filter'), 'toggleFilter'],
|
|
165
|
+
['Q/Esc', uiText('close'), 'close'],
|
|
165
166
|
];
|
|
166
167
|
const parts = [];
|
|
167
168
|
let cursor = 1;
|
|
@@ -191,7 +192,7 @@ export function renderTasksBrowser(state, cols, rows) {
|
|
|
191
192
|
const listInnerW = listW - 2;
|
|
192
193
|
let listLines;
|
|
193
194
|
if (!visible.length) {
|
|
194
|
-
listLines = [C.gray + (state.filter === 'active' ? 'No active tasks. Tab = show all.' : 'No background tasks in this session.') + C.reset];
|
|
195
|
+
listLines = [C.gray + uiText(state.filter === 'active' ? 'No active tasks. Tab = show all.' : 'No background tasks in this session.') + C.reset];
|
|
195
196
|
} else {
|
|
196
197
|
listLines = visible.map((t, i) => {
|
|
197
198
|
const selected = i === state.selectedIndex;
|
|
@@ -206,7 +207,7 @@ export function renderTasksBrowser(state, cols, rows) {
|
|
|
206
207
|
const idCol = t.kind === 'agent' ? C.green : t.kind === 'question' ? C.orange : C.blue;
|
|
207
208
|
const idText = selected ? idCol + C.bold + t.taskId + C.reset : idCol + t.taskId + C.reset;
|
|
208
209
|
const pad = ' '.repeat(Math.max(0, 20 - visWidth(t.taskId)));
|
|
209
|
-
const badge = statusColorToken(t.status) + (STATUS_LABEL[t.status] || t.status) + C.reset;
|
|
210
|
+
const badge = statusColorToken(t.status) + uiText(STATUS_LABEL[t.status] || t.status) + C.reset;
|
|
210
211
|
const prefix = lead + ptr + idText + pad + ' ' + badge;
|
|
211
212
|
const budget = Math.max(0, listInnerW - visWidth(prefix) - 1);
|
|
212
213
|
if (budget < 4) return fitExactly(prefix, listInnerW);
|
|
@@ -237,34 +238,34 @@ export function renderTasksBrowser(state, cols, rows) {
|
|
|
237
238
|
|
|
238
239
|
const detailLines = [];
|
|
239
240
|
if (!task) {
|
|
240
|
-
detailLines.push(C.gray + 'Select a task from the list.' + C.reset);
|
|
241
|
+
detailLines.push(C.gray + uiText('Select a task from the list.') + C.reset);
|
|
241
242
|
} else {
|
|
242
243
|
const label = (s) => C.gray + s.padEnd(14) + C.reset;
|
|
243
244
|
const val = (s) => C.white + String(s) + C.reset;
|
|
244
|
-
detailLines.push(label('Task ID:') + val(task.taskId));
|
|
245
|
-
detailLines.push(label('Kind:') + val(task.kind));
|
|
246
|
-
detailLines.push(label('Status:') + statusColorToken(task.status) + (STATUS_LABEL[task.status] || task.status) + C.reset);
|
|
247
|
-
detailLines.push(label('Description:') + val(singleLine(task.description) || '-'));
|
|
245
|
+
detailLines.push(label(uiText('Task ID:')) + val(task.taskId));
|
|
246
|
+
detailLines.push(label(uiText('Kind:')) + val(task.kind));
|
|
247
|
+
detailLines.push(label(uiText('Status:')) + statusColorToken(task.status) + uiText(STATUS_LABEL[task.status] || task.status) + C.reset);
|
|
248
|
+
detailLines.push(label(uiText('Description:')) + val(singleLine(task.description) || '-'));
|
|
248
249
|
if (task.kind === 'process') {
|
|
249
|
-
if (task.command && task.command !== task.description) detailLines.push(label('Command:') + val(singleLine(task.command)));
|
|
250
|
-
if (task.pid) detailLines.push(label('Pid:') + C.gray + task.pid + C.reset);
|
|
251
|
-
if (task.exitCode != null) detailLines.push(label('Exit code:') + C.gray + task.exitCode + C.reset);
|
|
250
|
+
if (task.command && task.command !== task.description) detailLines.push(label(uiText('Command:')) + val(singleLine(task.command)));
|
|
251
|
+
if (task.pid) detailLines.push(label(uiText('Pid:')) + C.gray + task.pid + C.reset);
|
|
252
|
+
if (task.exitCode != null) detailLines.push(label(uiText('Exit code:')) + C.gray + task.exitCode + C.reset);
|
|
252
253
|
}
|
|
253
254
|
if (task.kind === 'agent') {
|
|
254
|
-
if (task.agentId) detailLines.push(label('Agent ID:') + val(task.agentId));
|
|
255
|
-
if (task.subagentType) detailLines.push(label('Agent type:') + val(task.subagentType));
|
|
256
|
-
if (task.model) detailLines.push(label('Model:') + val(task.model));
|
|
257
|
-
if (task.thinkingEffort) detailLines.push(label('Effort:') + val(task.thinkingEffort));
|
|
255
|
+
if (task.agentId) detailLines.push(label(uiText('Agent ID:')) + val(task.agentId));
|
|
256
|
+
if (task.subagentType) detailLines.push(label(uiText('Agent type:')) + val(task.subagentType));
|
|
257
|
+
if (task.model) detailLines.push(label(uiText('Model:')) + val(task.model));
|
|
258
|
+
if (task.thinkingEffort) detailLines.push(label(uiText('Effort:')) + val(task.thinkingEffort));
|
|
258
259
|
}
|
|
259
260
|
if (task.kind === 'question') {
|
|
260
|
-
detailLines.push(label('Questions:') + C.gray + task.questionCount + C.reset);
|
|
261
|
-
if (task.toolCallId) detailLines.push(label('Tool call:') + C.gray + task.toolCallId + C.reset);
|
|
261
|
+
detailLines.push(label(uiText('Questions:')) + C.gray + task.questionCount + C.reset);
|
|
262
|
+
if (task.toolCallId) detailLines.push(label(uiText('Tool call:')) + C.gray + task.toolCallId + C.reset);
|
|
262
263
|
}
|
|
263
264
|
const timing = task.status === 'running'
|
|
264
265
|
? 'running ' + relativeTime(task.startedAt)
|
|
265
266
|
: (task.endedAt ? 'finished ' + relativeTime(task.endedAt) : '');
|
|
266
|
-
if (timing) detailLines.push(label('Time:') + C.gray + timing + C.reset);
|
|
267
|
-
if (task.stopReason) detailLines.push(label('Reason:') + C.gray + singleLine(task.stopReason) + C.reset);
|
|
267
|
+
if (timing) detailLines.push(label(uiText('Time:')) + C.gray + timing + C.reset);
|
|
268
|
+
if (task.stopReason) detailLines.push(label(uiText('Reason:')) + C.gray + singleLine(task.stopReason) + C.reset);
|
|
268
269
|
}
|
|
269
270
|
while (detailLines.length < Math.max(0, detailH - 2)) detailLines.push('');
|
|
270
271
|
const detailFrame = renderFrame('Detail', detailLines, rightW, detailH);
|
package/src/team-panel.js
CHANGED
|
@@ -21,6 +21,7 @@ import { readTeamFile } from './team/store.js';
|
|
|
21
21
|
import { readMailbox, writeToMailbox } from './team/mailbox.js';
|
|
22
22
|
import { readTasks, formatTasks } from './team/tasks.js';
|
|
23
23
|
import { TEAM_LEAD_NAME } from './team/constants.js';
|
|
24
|
+
import { uiText } from './i18n.js';
|
|
24
25
|
|
|
25
26
|
|
|
26
27
|
/** The state a panel needs, created once when it opens. */
|
|
@@ -303,26 +304,26 @@ export function renderTeamPanel(panel, cols, rows) {
|
|
|
303
304
|
const m = roster[Math.min(panel.selectedIndex, roster.length - 1)];
|
|
304
305
|
push('');
|
|
305
306
|
push(` ${C.cyan}${C.bold}@${m.name}${C.reset} ${C.gray}${m.state || ''}${C.reset}`);
|
|
306
|
-
push(` ${C.gray}${m.model || '(no model set)'}${m.model ? '' : ''}${C.reset}`);
|
|
307
|
+
push(` ${C.gray}${m.model || uiText('(no model set)')}${m.model ? '' : ''}${C.reset}`);
|
|
307
308
|
push(` ${C.gray}mode: ${m.permissionMode || 'ask'}${C.reset}`);
|
|
308
309
|
if (m.taskId) push(` ${C.gray}task: ${m.taskId}${C.reset}`);
|
|
309
310
|
if (m.cwd) push(` ${C.gray}cwd: ${m.cwd}${C.reset}`);
|
|
310
311
|
push('');
|
|
311
|
-
push(` ${C.gray}── what it is doing ──${C.reset}`);
|
|
312
|
+
push(` ${C.gray}── ${uiText('what it is doing')} ──${C.reset}`);
|
|
312
313
|
const live = (panel.chat && panel.chat[m.name]) || [];
|
|
313
314
|
const preview = previewLines(panel, m.name, Math.max(3, rows - 14), cols);
|
|
314
|
-
if (!preview.length) push(` ${C.gray}(nothing yet)${C.reset}`);
|
|
315
|
+
if (!preview.length) push(` ${C.gray}${uiText('(nothing yet)')}${C.reset}`);
|
|
315
316
|
for (const line of preview) push(` ${C.gray}${line}${C.reset}`);
|
|
316
317
|
void live;
|
|
317
318
|
while (out.length < rows - 3) push('');
|
|
318
319
|
push(C.border + '─'.repeat(cols) + C.reset);
|
|
319
|
-
push(` ${C.gray}← back · Enter message · k kill · s stop · m mode${C.reset}`);
|
|
320
|
+
push(` ${C.gray}${uiText('← back · Enter message · k kill · s stop · m mode')}${C.reset}`);
|
|
320
321
|
push('');
|
|
321
322
|
return out.slice(0, rows);
|
|
322
323
|
}
|
|
323
324
|
|
|
324
325
|
if (!roster.length) {
|
|
325
|
-
push(' ' + C.gray + 'No members. Add one with /team add <name>.' + C.reset);
|
|
326
|
+
push(' ' + C.gray + uiText('No members. Add one with /team add <name>.') + C.reset);
|
|
326
327
|
}
|
|
327
328
|
|
|
328
329
|
// The roster, then the selected member's traffic, then the composer.
|
|
@@ -479,9 +480,9 @@ export function renderTeamPanel(panel, cols, rows) {
|
|
|
479
480
|
const req = panel.pendingPermission;
|
|
480
481
|
if (req && out.length < rows - composerRows - 3) {
|
|
481
482
|
const cut2 = (s) => String(s || '').replace(/\s+/g, ' ').trim().slice(0, Math.max(8, cols - 4));
|
|
482
|
-
const who = String(req.agentId || 'a member');
|
|
483
|
-
const what = String(req.description || req.toolName || 'a tool call');
|
|
484
|
-
push(` ${C.yellow}${cut2(`${who} wants ${req.toolName}: ${what}`)}${C.reset}`);
|
|
483
|
+
const who = uiText(String(req.agentId || 'a member'));
|
|
484
|
+
const what = uiText(String(req.description || req.toolName || 'a tool call'));
|
|
485
|
+
push(` ${C.yellow}${cut2(uiText(`${who} wants ${req.toolName}: ${what}`))}${C.reset}`);
|
|
485
486
|
const inputLine = req.input && typeof req.input === 'object'
|
|
486
487
|
? Object.entries(req.input).slice(0, 2).map(([k, v]) => `${k}=${String(v).slice(0, 40)}`).join(' ')
|
|
487
488
|
: '';
|
|
@@ -503,12 +504,12 @@ export function renderTeamPanel(panel, cols, rows) {
|
|
|
503
504
|
push(C.border + '─'.repeat(cols) + C.reset);
|
|
504
505
|
if (panel.mode === 'compose') {
|
|
505
506
|
push(` ${C.cyan}→ ${sel ? sel.name : '?'}${C.reset} ${panel.composing}${C.cyan}█${C.reset}`);
|
|
506
|
-
push(' ' + C.gray + 'Enter send · Esc cancel' + C.reset);
|
|
507
|
+
push(' ' + C.gray + uiText('Enter send · Esc cancel') + C.reset);
|
|
507
508
|
} else {
|
|
508
|
-
push(' ' + C.gray + 'Enter write · Tab next · ↑↓ select · Esc close' + C.reset);
|
|
509
|
+
push(' ' + C.gray + uiText('Enter write · Tab next · ↑↓ select · Esc close') + C.reset);
|
|
509
510
|
// The roster actions, named so they are discoverable rather than folklore. A second line because
|
|
510
511
|
// squeezing six shortcuts onto one makes all of them unreadable.
|
|
511
|
-
push(' ' + C.gray + 'k kill · s stop · p prune idle · m mode · r read' + C.reset);
|
|
512
|
+
push(' ' + C.gray + uiText('k kill · s stop · p prune idle · m mode · r read') + C.reset);
|
|
512
513
|
}
|
|
513
514
|
|
|
514
515
|
return out.slice(0, rows);
|
package/src/term.js
CHANGED
|
@@ -218,30 +218,53 @@ const AMBIGUOUS = [
|
|
|
218
218
|
[0x2103, 0x2103], [0x2105, 0x2105], [0x2109, 0x2109], [0x2113, 0x2113],
|
|
219
219
|
[0x2116, 0x2116], [0x2121, 0x2122], [0x2126, 0x2126], [0x212B, 0x212B],
|
|
220
220
|
[0x2153, 0x2154], [0x215B, 0x215E], [0x2160, 0x216B], [0x2170, 0x2179],
|
|
221
|
-
[0x2189, 0x2189], [0x2190, 0x2199], [
|
|
222
|
-
[
|
|
223
|
-
[
|
|
224
|
-
[
|
|
225
|
-
[
|
|
226
|
-
[
|
|
227
|
-
[
|
|
228
|
-
[
|
|
229
|
-
[
|
|
230
|
-
[
|
|
231
|
-
[
|
|
232
|
-
[
|
|
233
|
-
[
|
|
234
|
-
[
|
|
235
|
-
[
|
|
236
|
-
[
|
|
237
|
-
[
|
|
238
|
-
[
|
|
239
|
-
[
|
|
240
|
-
[
|
|
241
|
-
[
|
|
221
|
+
[0x2189, 0x2189], [0x2190, 0x2199], [0x219A, 0x219B], [0x219E, 0x21A0],
|
|
222
|
+
[0x21A3, 0x21A3], [0x21A6, 0x21A6], [0x21A9, 0x21AA], [0x21AE, 0x21AE],
|
|
223
|
+
[0x21B0, 0x21B1], [0x21B3, 0x21B4], [0x21B6, 0x21B9], [0x21B8, 0x21B9],
|
|
224
|
+
[0x21BC, 0x21BD], [0x21C0, 0x21C1], [0x21C4, 0x21C5], [0x21C7, 0x21C9],
|
|
225
|
+
[0x21CB, 0x21CC], [0x21CE, 0x21CF], [0x21D2, 0x21D2], [0x21D4, 0x21D4],
|
|
226
|
+
[0x21DA, 0x21DB], [0x21DD, 0x21DD], [0x21E0, 0x21E1], [0x21E4, 0x21E5],
|
|
227
|
+
[0x21E7, 0x21E7], [0x21EA, 0x21ED], [0x21F4, 0x21F4], [0x2200, 0x2200],
|
|
228
|
+
[0x2202, 0x2203], [0x2207, 0x2208], [0x220B, 0x220B], [0x220F, 0x220F],
|
|
229
|
+
[0x2211, 0x2211], [0x2215, 0x2215], [0x221A, 0x221A], [0x221D, 0x2220],
|
|
230
|
+
[0x2223, 0x2223], [0x2225, 0x2225], [0x2227, 0x222C], [0x222E, 0x222E],
|
|
231
|
+
[0x2234, 0x2237], [0x223C, 0x223D], [0x2248, 0x2248], [0x224C, 0x224C],
|
|
232
|
+
[0x2252, 0x2252], [0x2260, 0x2261], [0x2264, 0x2267], [0x226A, 0x226B],
|
|
233
|
+
[0x226E, 0x226F], [0x2282, 0x2283], [0x2286, 0x2287], [0x2295, 0x2295],
|
|
234
|
+
[0x2299, 0x2299], [0x22A5, 0x22A5], [0x22BF, 0x22BF], [0x2312, 0x2312],
|
|
235
|
+
[0x2460, 0x24E9], [0x24EB, 0x254B], [0x2550, 0x2573], [0x2580, 0x258F],
|
|
236
|
+
[0x2592, 0x2595], [0x25A0, 0x25A1], [0x25A3, 0x25A9], [0x25B2, 0x25B3],
|
|
237
|
+
[0x25B6, 0x25B7], [0x25BC, 0x25BD], [0x25C0, 0x25C1], [0x25C6, 0x25C8],
|
|
238
|
+
[0x25CB, 0x25CB], [0x25CE, 0x25D1], [0x25E2, 0x25E5], [0x25EF, 0x25EF],
|
|
239
|
+
[0x2605, 0x2606], [0x2609, 0x2609], [0x260E, 0x260F], [0x261C, 0x261C],
|
|
240
|
+
[0x261E, 0x261E], [0x2640, 0x2640], [0x2642, 0x2642], [0x2660, 0x2661],
|
|
241
|
+
[0x2663, 0x2665], [0x2667, 0x266A], [0x266C, 0x266D], [0x266F, 0x266F],
|
|
242
|
+
[0x269E, 0x269F], [0x26C6, 0x26CD], [0x26CF, 0x26D3], [0x26D5, 0x26E1],
|
|
243
|
+
[0x26E3, 0x26E3], [0x26E8, 0x26E9], [0x26EB, 0x26F1], [0x26F4, 0x26F4],
|
|
244
|
+
[0x26F6, 0x26F9], [0x26FB, 0x26FC], [0x26FE, 0x26FF], [0x273D, 0x273D],
|
|
245
|
+
[0x2761, 0x2761], [0x2776, 0x277F], [0x2B56, 0x2B59], [0x3248, 0x324F],
|
|
246
|
+
[0xE000, 0xF8FF], [0xFE00, 0xFE0F], [0xFFFD, 0xFFFD], [0x1F100, 0x1F10A],
|
|
242
247
|
[0x1F110, 0x1F12D], [0x1F130, 0x1F169], [0x1F170, 0x1F19A],
|
|
243
248
|
];
|
|
244
249
|
|
|
250
|
+
// EAW=Ambiguous code points that every terminal still draws ONE column wide.
|
|
251
|
+
//
|
|
252
|
+
// Box drawing and block elements exist to tile: a `─` that was two columns wide could not
|
|
253
|
+
// meet its neighbour, so terminals draw them at one regardless of locale. Unicode classes
|
|
254
|
+
// them Ambiguous anyway, and honouring that measured every box and panel twice as wide as
|
|
255
|
+
// the space it was given — the frames they compose came apart.
|
|
256
|
+
//
|
|
257
|
+
// The three typographic marks are the same story for a different reason: `…`, `·`, `•` are
|
|
258
|
+
// used here for truncation and as separators, INSIDE single-column layouts. A truncated
|
|
259
|
+
// title measured two columns wide overflowed the panel it was cut to fit, and the panel's
|
|
260
|
+
// own border was then one column short on that row.
|
|
261
|
+
const AMBIGUOUS_ALWAYS_NARROW = [
|
|
262
|
+
[0x00B7, 0x00B7], // ·
|
|
263
|
+
[0x2022, 0x2022], // •
|
|
264
|
+
[0x2026, 0x2026], // …
|
|
265
|
+
[0x2500, 0x259F], // box drawing and block elements
|
|
266
|
+
];
|
|
267
|
+
|
|
245
268
|
/**
|
|
246
269
|
* Should EAW=Ambiguous characters measure 2 columns?
|
|
247
270
|
*
|
|
@@ -302,6 +325,19 @@ export function charWidth(ch) {
|
|
|
302
325
|
if (isZeroWidth(c)) return 0;
|
|
303
326
|
if (isWideByDefault(c)) return 2;
|
|
304
327
|
if (inRanges(c, WIDE)) return 2;
|
|
328
|
+
// EAST ASIAN AMBIGUOUS: 1 column normally, 2 on a CJK terminal.
|
|
329
|
+
//
|
|
330
|
+
// `detectAmbiguousWide` and the AMBIGUOUS table both existed and NEITHER was consulted
|
|
331
|
+
// here, so every ambiguous character measured 1 while a Chinese terminal drew it as 2.
|
|
332
|
+
// The visible damage was the `↳` gutter: the arrow is ambiguous, so the marker measured
|
|
333
|
+
// a column narrower than the terminal drew it and the rows under it started a column
|
|
334
|
+
// early — a ragged block, and only on a CJK machine.
|
|
335
|
+
//
|
|
336
|
+
// BOX DRAWING AND BLOCK ELEMENTS ARE EXCLUDED, although Unicode classes them Ambiguous.
|
|
337
|
+
// Every terminal draws `─ │ ╭ █` one column wide regardless of locale — they exist to
|
|
338
|
+
// tile — and measuring them as two made every box and panel twice as wide as the space
|
|
339
|
+
// it was given, which broke the frames they compose.
|
|
340
|
+
if (isAmbiguousWide() && !inRanges(c, AMBIGUOUS_ALWAYS_NARROW) && inRanges(c, AMBIGUOUS)) return 2;
|
|
305
341
|
return 1;
|
|
306
342
|
}
|
|
307
343
|
|