ltms-reader 0.1.0 → 0.1.1

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/src/screen.mjs CHANGED
@@ -10,12 +10,20 @@
10
10
  // row early, and nothing of the frame before may stay after it (R.F6). Each row's segments are put in the order the
11
11
  // right-to-left mode writes them (text.mjs displayOrder, R1): laid out by the reader, or as stored for a terminal that
12
12
  // lays bidirectional text out itself. A row laid out by the reader that holds right-to-left text is written inside a
13
- // left-to-right override, LRO after its first grapheme cluster that takes a column and PDF at its end (Y1, round 6; Z3,
14
- // round 7: after a first cluster that takes none, it was at the row's first column), so that a terminal that
15
- // lays text out itself keeps the reader's order: measured on four terminals (S378, CONTROLS.md), the two take no column
16
- // in Alacritty 0.17.0, Konsole 26.08.3, tmux 3.6 and VS Code 1.146.0's terminal (xterm.js) there, and Konsole applies an
17
- // override from a row's second column on; at its first column an LRO is not applied by Konsole, dropped by tmux and
18
- // given a column by xterm.js, which gives an isolate (LRI, RLI, PDI) a column anywhere; so nothing else is written.
13
+ // left-to-right override, LRO after its first grapheme cluster that takes a column and PDF at its end (after a first
14
+ // cluster that takes none, the LRO was once at the row's first column), so that a terminal that lays text
15
+ // out itself with a left-to-right base for each line (Konsole, at its default settings) keeps the reader's order:
16
+ // measured on four terminals on 2026-11-16, the two take no column after a character in Alacritty 0.17.0, Konsole
17
+ // 26.08.3, tmux 3.6 and VS Code 1.146.0's xterm.js (run in a headless browser; xterm.js gives a zero-width character a
18
+ // column after an escape sequence, as it does the PDF after a row's last styled segment, which moves nothing), and
19
+ // Konsole applies an override from a row's second column on; at its first column an LRO is not applied by Konsole,
20
+ // dropped by tmux and given a column by xterm.js, which with its own Unicode 6 widths gives an isolate (LRI, RLI, PDI) a
21
+ // column anywhere. Between that first cluster and the LRO, a left-to-right mark (LRM, 0.1.1): a terminal that lays a row
22
+ // out with a left-to-right base (Konsole) moved a first cluster that is right to left, standing outside the override, to
23
+ // the row's other end (0.1.0's first Known limit, measured on Konsole 26.08.3 on 2026-11-20), and with the mark it keeps
24
+ // it first (measured there too); an LRM past the first column took no column in all four on 2026-11-16. Nothing else is
25
+ // written in "reader"; in "terminal" the text goes as stored, an RLM at the end of each line of a right-to-left
26
+ // paragraph (text.mjs displayOrder).
19
27
  import readline from 'node:readline';
20
28
  import { AL, AN, R, classOf } from './bidi.mjs';
21
29
  import { clusterWidth, clusters, displayOrder, visible } from './text.mjs';
@@ -36,8 +44,14 @@ export const colourFrom = (env) => !(typeof env.NO_COLOR === 'string' && env.NO_
36
44
  /** One segment's text as it is written: visible, on one line. */
37
45
  const safe = (s) => visible(s).replace(/\n/g, '\\n').replace(/\t/g, '\\t');
38
46
 
47
+ /** The left-to-right mark (U+200E) written between such a row's first cluster that takes a column and its override
48
+ * (0.1.1). A transcript's own marks are written as they are, so a test finds the reader's by its place, never by its
49
+ * character. */
50
+ export const LRM = String.fromCharCode(0x200e);
39
51
  /** The left-to-right override (U+202D) and the pop that ends it (U+202C), written around a row laid out by the reader
40
- * that holds right-to-left text (Y1): the only bidirectional controls the reader writes (a transcript's are escapes). */
52
+ * that holds right-to-left text (Y1): with the mark, the only bidirectional controls the reader writes in "reader"; in
53
+ * "terminal" it writes none of these, and an RLM at the end of each line of a right-to-left paragraph (text.mjs
54
+ * displayOrder). A transcript's overrides are escapes. */
41
55
  export const LRO = '\u202d', PDF = '\u202c';
42
56
  /** A text with no character that could be right to left (every R, AL and AN code point is at U+0590 or above). */
43
57
  const NO_RTL = /^[\u0000-\u058f]*$/;
@@ -49,8 +63,8 @@ export function holdsRtl(text) {
49
63
  return false;
50
64
  }
51
65
 
52
- /** Where the first grapheme cluster of `text` that takes a column ends (Z3, round 7: after a first cluster that takes
53
- * none, ZWSP or a lone mark, the LRO was in the row's first column), or -1 when none takes a column. */
66
+ /** Where the first grapheme cluster of `text` that takes a column ends (after a first cluster that takes none, ZWSP
67
+ * or a lone mark, the LRO was once in the row's first column), or -1 when none takes a column. */
54
68
  function firstColumnEnd(text) {
55
69
  let at = 0;
56
70
  for (const c of clusters(text)) { at += c.length; if (clusterWidth(c) > 0) return at; }
@@ -59,7 +73,8 @@ function firstColumnEnd(text) {
59
73
 
60
74
  /** The bytes of one whole frame: each line at its row, the row erased whole first, then the line, styled; its segments in
61
75
  * the order the right-to-left mode `rtl` writes them ("reader" or "terminal"); in "reader", a row that holds
62
- * right-to-left text inside LRO (after its first grapheme cluster that takes a column) and PDF (last). */
76
+ * right-to-left text inside LRO (after its first grapheme cluster that takes a column, and an LRM before it) and PDF
77
+ * (last). */
63
78
  export function frameBytes(lines, { cols, rows, colour = true, rtl = 'reader' }) {
64
79
  let out = '';
65
80
  for (let i = 0; i < rows; i++) {
@@ -69,17 +84,18 @@ export function frameBytes(lines, { cols, rows, colour = true, rtl = 'reader' })
69
84
  const merged = [];
70
85
  for (const s of row) { const last = merged[merged.length - 1]; if (last && (last.style ?? null) === (s.style ?? null)) last.text += s.text; else merged.push({ text: s.text, style: s.style ?? null }); }
71
86
  const texts = merged.map((s) => safe(s.text));
72
- // laid out by the reader and holding right-to-left text: LRO right after the row's first grapheme cluster that takes
73
- // a column (where it ends, in whichever segment that is, a mark on its character kept with it; never in the row's
74
- // first column, where the terminals measured drop it, give it a column or do not apply it: Z3, round 7), PDF last; a
75
- // row with no cluster that takes a column has nothing a terminal could reorder, and neither
87
+ // laid out by the reader and holding right-to-left text: LRM and LRO right after the row's first grapheme cluster that
88
+ // takes a column (where it ends, in whichever segment that is, a mark on its character kept with it; never in the row's
89
+ // first column, where the terminals measured drop it, give it a column or do not apply it; the LRM keeps a
90
+ // right-to-left first cluster first on a terminal with a left-to-right base: 0.1.1), PDF last; a row with no cluster
91
+ // that takes a column has nothing a terminal could reorder, and none of the three
76
92
  let end = '';
77
93
  if (rtl === 'reader') {
78
94
  const whole = texts.join('');
79
95
  const first = holdsRtl(whole) ? firstColumnEnd(whole) : -1;
80
96
  if (first > 0) {
81
97
  for (let k = 0, at = 0; k < texts.length; at += texts[k++].length) {
82
- if (at < first && first <= at + texts[k].length) { texts[k] = texts[k].slice(0, first - at) + LRO + texts[k].slice(first - at); break; }
98
+ if (at < first && first <= at + texts[k].length) { texts[k] = texts[k].slice(0, first - at) + LRM + LRO + texts[k].slice(first - at); break; }
83
99
  }
84
100
  end = PDF;
85
101
  }
package/src/start.mjs CHANGED
@@ -21,11 +21,14 @@ again (Projects, a project's Sessions); ? the keys; q quits.
21
21
  For lines to read or to pipe, ltms is the command (npx long-term-memory-structure).
22
22
 
23
23
  Right to left (Hebrew, Arabic): in every terminal the reader lays out each line itself, by the Unicode Bidirectional
24
- Algorithm, and writes a line that holds right-to-left text inside a left-to-right override (U+202D after its first
25
- character that takes a column, U+202C at its end), so that a terminal that lays text out itself keeps that order.
26
- Measured on four terminals: Alacritty, Konsole, tmux and VS Code's terminal; no other was. To choose:
24
+ Algorithm, and writes a line that holds right-to-left text inside a left-to-right override (U+200E and U+202D after
25
+ its first grapheme cluster that takes a column, U+202C at its end), so that a terminal that lays text out itself
26
+ with a left-to-right base for each line (Konsole at its default settings) keeps that order (for a line that begins
27
+ with a right-to-left letter, this was measured only with Hebrew letters without points). Measured on Alacritty,
28
+ Konsole, tmux and the xterm.js of VS Code's terminal (run in a headless browser); no other was. To choose:
27
29
  LTMS_READER_BIDI=reader the reader lays it out (the default)
28
- LTMS_READER_BIDI=terminal as stored, with no override (for a terminal that lays text out itself)
30
+ LTMS_READER_BIDI=terminal as stored, with no override, and an RLM at the end of each line of a right-to-left
31
+ paragraph (for a terminal that lays text out itself)
29
32
  `;
30
33
 
31
34
  /** The arguments: { help } | { version } | { path } (null for none) | { usage: what is wrong }. */
@@ -61,7 +64,7 @@ export function notTerminal(stdin, stdout) {
61
64
  // the commands are written as npx runs them, so that they run as they are written: installing ltms-reader does not put
62
65
  // ltms on the PATH (R.F13)
63
66
  return `ltms-reader: ${which}, so nothing was read.
64
- ltms-reader shows transcripts on a terminal's screen only: none of their text goes to a pipe, a file or a log.
67
+ ltms-reader shows transcripts on a terminal's screen only: it writes none of their text to a pipe, a file or a log.
65
68
  For lines to read or to pipe, ltms is the command, from the package ltms-reader is built on.
66
69
  npm install -g long-term-memory-structure puts ltms on the PATH; npx runs it without that:
67
70
  npx long-term-memory-structure index <projects folder>/<project> the sessions, newest first
package/src/text.mjs CHANGED
@@ -4,8 +4,8 @@
4
4
  // the clipboard). None reaches the terminal as such: every C0 and C1 control character and DEL, but the new line and the
5
5
  // tab, is shown as a visible escape (ESC as ␛, the rest as \xNN), so a transcript cannot move the cursor, set the title,
6
6
  // write the clipboard or leave the terminal in another mode. The new line ends a line and the tab becomes spaces (by
7
- // the callers below); neither is written to the terminal as itself. What reorders or hides text is shown the same way
8
- // (R.F5, decided S376), as \uXXXX or \u{XXXXX}: the bidirectional embeddings, overrides and isolates (U+202A to U+202E,
7
+ // the callers below); neither is written to the terminal as itself. What reorders or hides text is shown the same way,
8
+ // as \uXXXX or \u{XXXXX}: the bidirectional embeddings, overrides and isolates (U+202A to U+202E,
9
9
  // U+2066 to U+2069), which on a terminal that lays bidirectional text out itself reorder the rest of their row, the
10
10
  // reader's own words after them too; the byte order mark (U+FEFF); the line and paragraph separators (U+2028, U+2029);
11
11
  // and the tag characters (U+E0000 to U+E007F). The light marks Hebrew and Arabic text use, LRM (U+200E), RLM (U+200F)
@@ -15,20 +15,22 @@
15
15
  // (East_Asian_Width W or F: src/width-table.mjs, generated from Unicode's EastAsianWidth.txt), when it is an emoji
16
16
  // presentation sequence (an emoji and U+FE0F) or a flag (regional indicators); none when every character in it takes
17
17
  // none (combining marks, niqqud and cantillation among them, and format characters); one otherwise. A line is cut by
18
- // columns, between clusters, never inside one; a space where it is cut stays at the end of the line before (lineSpans:
19
- // V7, round 5, as UAX #14 has it).
18
+ // columns, between clusters, never inside one; a space where it is cut stays at the end of the line before (lineSpans,
19
+ // as UAX #14 has it).
20
20
  //
21
- // Right to left (R1, decided by the measurement of S377 on three terminals; Y1, round 6, by that of S378 on four): there
21
+ // Right to left (one layout for every terminal, chosen on four terminals measured on 2026-11-16: rtlModeOf): there
22
22
  // are two modes (displayOrder, below): "reader", the default in every terminal, in which the reader lays the text out
23
23
  // itself, by the Unicode Bidirectional Algorithm (src/bidi.mjs), and writes it in visual order (src/screen.mjs writes a
24
- // row of it that holds right-to-left text inside a left-to-right override, so that a terminal that lays text out itself,
25
- // as Konsole does, keeps that order); and "terminal", LTMS_READER_BIDI's choice, in which the text is written as stored,
26
- // with a right-to-left mark (RLM) at the end of each right-to-left paragraph, which on Konsole puts the paragraph's end
27
- // punctuation where it belongs. rtlModeOf reads the choice; no terminal is detected. A paragraph here is a
24
+ // row of it that holds right-to-left text inside a left-to-right override, so that a terminal that lays text out itself
25
+ // with a left-to-right base for each line, as Konsole does at its default settings, keeps that order); and "terminal",
26
+ // LTMS_READER_BIDI's choice, in which the text is written as stored, with a right-to-left mark (RLM) at the end of each
27
+ // line of a right-to-left paragraph, which on Konsole puts the paragraph's end punctuation where it belongs after
28
+ // right-to-left text or a number (after a left-to-right word or a path it does not: a model of Konsole, not measured).
29
+ // rtlModeOf reads the choice; no terminal is detected. A paragraph here is a
28
30
  // segment of a row (a list's cell, the reader's own words before it, a line cut to the row's width), or a text a view
29
31
  // wraps into lines (a record's text line, a message, an error, the reader's own words), each line of which names it: its
30
- // levels are resolved once, and each line is reordered from them, whole (W1, round 4; V7, round 5; UAX #9 section 3.4:
31
- // paragraphLine). A path or a URL in a paragraph is laid out as one left-to-right unit (UAX #9 HL4).
32
+ // levels are resolved once, and each line is reordered from them, whole (UAX #9 section 3.4: paragraphLine). A path or
33
+ // a URL in a paragraph is laid out as one left-to-right unit (UAX #9 HL4).
32
34
  import { AL, AN, BN, ISO, L as LTR_CLASS, NSM, R, classOf, classesOf, lineLevels, mirrorOf, paragraphLevel, resolveLevels, visualOrder } from './bidi.mjs';
33
35
  import { WIDE } from './width-table.mjs';
34
36
 
@@ -160,17 +162,17 @@ export function pad(s, cols) {
160
162
  return r.text + ' '.repeat(Math.max(0, cols - r.width));
161
163
  }
162
164
 
163
- /** Whitespace that hangs at the end of a line (V7, round 5): a cluster made only of the spaces of UAX #9's class WS that
165
+ /** Whitespace that hangs at the end of a line: a cluster made only of the spaces of UAX #9's class WS that
164
166
  * take a column (U+0020, U+1680, U+2000 to U+200A, U+205F, U+3000: DerivedBidiClass.txt 17.0.0; the form feed and
165
- * U+2028, of the class too, are shown as escapes), but U+2007 FIGURE SPACE, a no-break space (isGlue: Z2, round 7).
167
+ * U+2028, of the class too, are shown as escapes), but U+2007 FIGURE SPACE, a no-break space (isGlue).
166
168
  * UAX #14 keeps a space on the line it follows (LB7, LB18) and does not break before the others but after a space
167
169
  * (LB12a, LB21); L1 gives those that end a line the paragraph's level. */
168
170
  const HANGS = /^[\u0020\u1680\u2000-\u2006\u2008-\u200a\u205f\u3000]+$/;
169
171
 
170
172
  /** Whether the code unit g begins a cluster that UAX #14 gives no break before but after a space, a character of class
171
173
  * BA or a hyphen (LB12a, class GL: LineBreak.txt; ICU 78.3, Unicode 17.0, measured): a no-break space (U+00A0, U+2007
172
- * FIGURE SPACE, U+202F) or the non-breaking hyphen (U+2011). Z2, round 7: U+2007, UAX #9 whitespace, hung at a break
173
- * as a space does, so that a line began with the GL character after it, or with U+2007 itself. */
174
+ * FIGURE SPACE, U+202F) or the non-breaking hyphen (U+2011). U+2007, UAX #9 whitespace, once hung at a break as a
175
+ * space does, so that a line began with the GL character after it, or with U+2007 itself. */
174
176
  const isGlue = (g) => g === 0xa0 || g === 0x2007 || g === 0x202f || g === 0x2011;
175
177
  /** Whether UAX #14 breaks before a GL character after the code unit g (LB12a): a space (SP), a hyphen-minus (HY), a
176
178
  * space of class BA (U+1680, U+2000 to U+2006, U+2008 to U+200A, U+205F, U+3000); a hyphen-minus but after a Hebrew
@@ -184,7 +186,7 @@ export const isHebrewLetter = (cp) => (cp >= 0x5d0 && cp <= 0x5ea) || (cp >= 0x5
184
186
  const MARK = /^\p{M}$/u;
185
187
  /** The marks (General_Category M) that are not of UAX #14's class CM, which LB9 does not fold into the character before
186
188
  * them: 21 of class GL (combining double marks), U+0F7F of class BA, 2 of VF and 7 of VI (viramas). LineBreak.txt 17.0.0;
187
- * ICU 78.3 gives the same (round 8's probe cmsets.py). */
189
+ * ICU 78.3 gives the same (measured on 2026-11-17). */
188
190
  const MARK_NOT_CM = new Set([0x35c, 0x35d, 0x35e, 0x35f, 0x360, 0x361, 0x362, 0xf7f, 0x1aeb, 0x1b44, 0x1bf2, 0x1bf3, 0x1dcd, 0x1dfc, 0xa9c0, 0xfe20, 0xfe22, 0xfe24, 0xfe26, 0xfe27, 0xfe29, 0xfe2b, 0xfe2d, 0xfe2e, 0x11046, 0x1107f, 0x1134d, 0x113d0, 0x1193e, 0x11f42, 0x16fe4]);
189
191
  /** The code points of class CM that are not marks, ZWJ aside (the same sources): the C0 and C1 controls, ALM, ZWNJ, LRM,
190
192
  * RLM, the bidirectional embeddings, overrides and isolates, U+206A to U+206F, U+3035, U+FFF9 to U+FFFB, U+1BCA0 to
@@ -210,10 +212,10 @@ function baseBefore(s, j) {
210
212
  * LB9 folds into a character (a mark, ZWJ, and the characters of class CM that are not marks: ALM, ZWNJ, LRM, RLM...)
211
213
  * takes its class: between the letter and the hyphen, and after the hyphen or the space; but no break after ZWJ
212
214
  * (LB8a), and none after such a run where it follows a space (SP) or nothing, as LB9 folds nothing into a space and LB10
213
- * then takes the run as a letter (AL). Z2, round 7: the reader broke after a Hebrew letter's hyphen as after a Latin
214
- * letter's (ICU 78.3 breaks before U+00A0 after 'abcd-', and gives no break in a Hebrew word, '-', U+00A0 and a Hebrew
215
- * word); R8e, round 8: and did where ALM, ZWNJ, LRM or RLM stood between the letter and the hyphen (round 7's check). What
216
- * is before i is read from s, so that a line laid out from its start is the same as from the text's. */
215
+ * then takes the run as a letter (AL). The reader once broke after a Hebrew letter's hyphen as after a Latin letter's
216
+ * (ICU 78.3 breaks before U+00A0 after 'abcd-', and gives no break in a Hebrew word, '-', U+00A0 and a Hebrew word),
217
+ * and then still did where ALM, ZWNJ, LRM or RLM stood between the letter and the hyphen. What is before i is read
218
+ * from s, so that a line laid out from its start is the same as from the text's. */
217
219
  function breaksBeforeGlueAt(s, i) {
218
220
  let [g, at] = codePointBefore(s, i + 1);
219
221
  if (g === 0x200d) return false;
@@ -232,7 +234,7 @@ function foldsWhole(c) {
232
234
  return c !== '';
233
235
  }
234
236
 
235
- /** Where to end a line that a cluster of class GL (isGlue) does not fit at the end of (Y3 (e), round 6): the index, in
237
+ /** Where to end a line that a cluster of class GL (isGlue) does not fit at the end of: the index, in
236
238
  * the line's clusters (`starts`: where each begins in s; `widths`: its columns), of the first cluster of the next line,
237
239
  * which takes the rest of them and the GL cluster (of `cw` columns), at most `n` columns: after the clusters of class GL
238
240
  * the line ends in and the character before them, where that is a space, BA or a hyphen (LB12a; a hyphen-minus not
@@ -245,7 +247,7 @@ function glueBreak(s, starts, widths, at, cw, n) {
245
247
  while (k > 0 && isGlue(s.charCodeAt(starts[k - 1]))) k--;
246
248
  const run = k < starts.length ? starts[k] : at;
247
249
  let cut = run > 0 && breaksBeforeGlueAt(s, run - 1) ? k : k - 1;
248
- // LB9 (R8e, round 8): a cluster made only of what it folds goes with the cluster it follows, but a space (SP)
250
+ // LB9: a cluster made only of what it folds goes with the cluster it follows, but a space (SP)
249
251
  if (cut < k) while (cut > 0 && foldsWhole(s.slice(starts[cut], cut + 1 < starts.length ? starts[cut + 1] : at)) && s.charCodeAt(starts[cut - 1]) !== 0x20) cut--;
250
252
  if (cut < 1 || cut === starts.length) return -1;
251
253
  let w = cw;
@@ -257,11 +259,11 @@ function glueBreak(s, starts, widths, at, cw, n) {
257
259
  * at most `cols` columns between clusters, a cluster wider than the columns on a line of its own; from offset `from`,
258
260
  * where a line begins. Whitespace (HANGS) that does not fit at the end of a line stays at the end of that line, with
259
261
  * the whitespace after it, as UAX #14 has a space: it hangs there, past the line's columns, and is in no line (nothing
260
- * past the screen is drawn); the next line begins after it, so that no line but the first begins with whitespace (V7,
261
- * round 5: the space that did not fit began the next line). Whitespace that fits ends its line. A no-break space or
262
+ * past the screen is drawn); the next line begins after it, so that no line but the first begins with whitespace (the
263
+ * space that did not fit once began the next line). Whitespace that fits ends its line. A no-break space or
262
264
  * a non-breaking hyphen (class GL) that does not fit begins the next line with the character before it (glueBreak:
263
- * UAX #14 gives no break before it but after a space, BA or a hyphen, a hyphen-minus not after a Hebrew letter; Y3 (e),
264
- * round 6: it began the line by itself; Z2, round 7: after a Hebrew letter's hyphen, and U+2007, it still did).
265
+ * UAX #14 gives no break before it but after a space, BA or a hyphen, a hyphen-minus not after a Hebrew letter; it
266
+ * once began the line by itself, and then still did after a Hebrew letter's hyphen, and so did U+2007).
265
267
  * One pair at a time, so that a long text can be laid out without its lines being made; from a line's start, the lines
266
268
  * are those from the text's start (what a line holds depends only on the text from its start). An empty s is one empty
267
269
  * line. */
@@ -317,9 +319,9 @@ export function wrap(s, cols) {
317
319
  /** Where the lines of wrapWords(s, cols) begin and end in s, [start, end) each: a paragraph in lines of at most `cols`
318
320
  * columns, broken at spaces where a line can be, else by columns (lineSpans). A space a line is broken at is in no line
319
321
  * (it hangs at the end of the line before, as UAX #14 has the whitespace at a break, and is not drawn, though the line
320
- * has room for it: Y3 (c), round 6), and so is the whitespace (HANGS) after it, at the start of the word that begins
322
+ * has room for it), and so is the whitespace (HANGS) after it, at the start of the word that begins
321
323
  * the next line, and whitespace that hangs inside a word cut by columns, which ends its line: no line but the first
322
- * begins with whitespace (V7, round 5). Each line is s.slice(start, end), so that its place in its paragraph is known
324
+ * begins with whitespace. Each line is s.slice(start, end), so that its place in its paragraph is known
323
325
  * (W1: a line is laid out from its paragraph's levels). */
324
326
  export function wordSpans(s, cols) {
325
327
  const out = [];
@@ -339,7 +341,7 @@ export function wordSpans(s, cols) {
339
341
  line = word.slice(x, y); from = at + x; open = y === word.length;
340
342
  }
341
343
  // a paragraph that ends in whitespace at a break ends with its last word: what is left after the break hangs, and
342
- // makes no empty line (Y3 (d), round 6: it made one, drawn as a blank row); an empty s, or one of spaces only, is one
344
+ // makes no empty line (it once made one, drawn as a blank row); an empty s, or one of spaces only, is one
343
345
  // empty line
344
346
  if (line !== '' || !out.length) out.push([from, from + line.length]);
345
347
  return out;
@@ -386,9 +388,11 @@ export const RTL_MODES = Object.freeze(['reader', 'terminal']);
386
388
 
387
389
  /**
388
390
  * The right-to-left mode: LTMS_READER_BIDI when it is set ("terminal" or "reader"); else "reader", in every terminal
389
- * (Y1, round 6: one layout for every terminal, decided S378 on a measurement of Alacritty 0.17.0, Konsole 26.08.3, tmux
390
- * 3.6 and VS Code 1.146.0's terminal; round 3 gave Konsole, detected by KONSOLE_VERSION, "terminal", which a reader run
391
- * over ssh from Konsole did not see). Returns { mode, by } or { refused: why }.
391
+ * (one layout for every terminal, chosen on a measurement on 2026-11-16 of Alacritty 0.17.0, Konsole 26.08.3, tmux
392
+ * 3.6 and the xterm.js of VS Code 1.146.0's terminal, run in a headless browser, which 1.147.0's has matched since;
393
+ * before it, Konsole, detected by KONSOLE_VERSION, was given "terminal", which a reader run over ssh from Konsole did
394
+ * not see).
395
+ * Returns { mode, by } or { refused: why }.
392
396
  */
393
397
  export function rtlModeOf(env) {
394
398
  const v = env.LTMS_READER_BIDI;
@@ -440,7 +444,7 @@ const drawn = (c, level) => {
440
444
  const marksAlone = (c) => { for (const ch of c) if (classOf(ch.codePointAt(0)) !== NSM) return false; return true; };
441
445
 
442
446
  /**
443
- * The items of a stretch of text s, in order, each laid out whole (Z5, round 7), added to the end of the caller's
447
+ * The items of a stretch of text s, in order, each laid out whole, added to the end of the caller's
444
448
  * `items`, and each one's level to `at`: the level of its first character X9 kept (`levelOf(c)`, asked of each cluster
445
449
  * c of s in order, -1 where X9 removed them all). Each item is a grapheme cluster, but where a cluster of nonspacing
446
450
  * marks alone follows clusters X9 removed whole (a soft hyphen, ZWSP, WJ: the segmenter breaks after each, a control,
@@ -448,7 +452,7 @@ const marksAlone = (c) => { for (const ch of c) if (classOf(ch.codePointAt(0)) !
448
452
  * cluster, and so do the removed characters between, in their order. UAX #9 gives the mark the class of the character
449
453
  * before it, the removed ones passed over (W1), and the reader keeps a letter's marks after it, as a terminal draws
450
454
  * them; as an item of its own, at an odd level, the mark was reversed with its run, before its letter, on the cell
451
- * before it (round 6's check: final nun, WJ, WJ, patah was written patah, WJ, WJ, nun). Only after a cluster with a
455
+ * before it (found on 2026-11-17: final nun, WJ, WJ, patah was written patah, WJ, WJ, nun). Only after a cluster with a
452
456
  * character X9 keeps: a mark after removed characters that begin the stretch, or follow only removed ones, has no
453
457
  * letter there, and is an item of its own, at its own level. A cluster X9 removed whole is at the level of the item
454
458
  * before it, or at `fallback` when it is the first.
@@ -492,7 +496,7 @@ function unitLevels(s) {
492
496
  }
493
497
 
494
498
  /**
495
- * A paragraph's levels, resolved once (W1, round 4; UAX #9 section 3.4: X9, W1 to W7, N0 to N2, I1 and I2 over the whole
499
+ * A paragraph's levels, resolved once (UAX #9 section 3.4: X9, W1 to W7, N0 to N2, I1 and I2 over the whole
496
500
  * paragraph; then each line it is wrapped into is reordered from them, by lineOf, never resolved by itself). `level` is
497
501
  * the paragraph's (0 or 1; null: by P2 and P3). With `units`, each path or URL in it stands as one isolate (ISO, HL4),
498
502
  * and its content is resolved once too, on its own. Returns { text, level, levels, units }: `levels` per code unit
@@ -521,8 +525,8 @@ function layOut(text, level, units) {
521
525
  function lineOf(P, a, b) {
522
526
  const { text, level: p, levels, units } = P;
523
527
  // the first unit that ends after a, by a binary search (the units are in order and apart, so their ends are in order
524
- // too): a line late in a paragraph of many paths is laid out without passing over the units before it (V1, round 5:
525
- // passed over one by one, a page at the end of 200,000 paths cost seven to fifteen times a page at the start)
528
+ // too): a line late in a paragraph of many paths is laid out without passing over the units before it (passed over
529
+ // one by one, a page at the end of 200,000 paths cost seven to fifteen times a page at the start)
526
530
  let u = 0;
527
531
  for (let hi = units.length; u < hi;) { const mid = (u + hi) >> 1; if (units[mid].b <= a) u = mid + 1; else hi = mid; }
528
532
  const piece = (U, s, e) => (U.inner ? ordered(text.slice(s, e), U.inner, s - U.a, 0) : text.slice(s, e));
@@ -640,8 +644,8 @@ function boundaryAt(s, i) {
640
644
 
641
645
  /**
642
646
  * The whitespace at either end of a segment's text, ECMAScript's as trimStart and trimEnd take it, in whole grapheme
643
- * clusters made of whitespace only: [a, b), the core between them (V3, round 5: by trimStart, a space carrying a mark at
644
- * a segment's start was cut from its mark, which was laid out with the rest, on the letter beside it). A character that
647
+ * clusters made of whitespace only: [a, b), the core between them (taken by trimStart, a space carrying a mark at a
648
+ * segment's start was cut from its mark, which was laid out with the rest, on the letter beside it). A character that
645
649
  * joins the cluster of a space before it is at U+0300 or above (a mark, ZWJ, a spacing mark); one that joins a space
646
650
  * after it, at U+0600 or above (a Prepend character): below those the boundary is not looked up (test/text.test.mjs
647
651
  * checks both, by Intl.Segmenter).
@@ -660,8 +664,8 @@ function blankEdges(text) {
660
664
  * segment's text is the slice at `at`: a line of a record, of a message, of the reader's own words wrapped into lines,
661
665
  * W1). Its direction is `dir` when given (0 or 1: a line's, its paragraph's), else its own (P2, P3).
662
666
  * "reader": a line of a paragraph laid out whole from the paragraph's levels (paragraphLine), its whitespace at either
663
- * end with the rest, as UAX #9's L1 and L2 lay out a line (V7, round 5: they stayed where they were, and the line's
664
- * text differed from UAX #9's); a paragraph of its own (a cell, a line cut to its columns: R1 (c)) laid out by
667
+ * end with the rest, as UAX #9's L1 and L2 lay out a line (left where they were, they made the line's text differ
668
+ * from UAX #9's); a paragraph of its own (a cell, a line cut to its columns: R1 (c)) laid out by
665
669
  * visualLine but its spaces at either end, in whole clusters (blankEdges), which stay where they are: a cell's are the
666
670
  * cell's padding. Either way the columns stay, and the text is aligned left. "terminal": as stored, with an RLM after a
667
671
  * right-to-left paragraph's text (before the spaces at its end), so that a terminal that lays the line out with a
package/src/view.mjs CHANGED
@@ -153,7 +153,7 @@ export function sessionView(input, { name, caps = true }) {
153
153
  out.push({ ta, a: at(p), line: lineOf(p), ch: inputChannel(pr) || 'none', time: str(pr?.timestamp) ?? null, n: text.length, prompt: clip(text, LIMITS.prompt), command: commandOf(text), records: 1 + turn.records.length,
154
154
  calls: calls.length, failed: calls.filter((x) => x.ok === false).length, from: least(lines), to: most(lines), items });
155
155
  }
156
- // A compaction made by /compact (S365, A.F5): Claude Code writes the boundary and its summary first, then the
156
+ // A compaction made by /compact: Claude Code writes the boundary and its summary first, then the
157
157
  // command's own records with the command's earlier time, so the /compact opens the turn after the one that holds its
158
158
  // compaction (measured: the demo's dc532898, L128 at 00:57:02, its /compact at L131, 00:56:23). Where ltms's turns put
159
159
  // the compaction inside the /compact's own turn (its fixtures library-detached*.jsonl), no note is made. Nothing is
package/src/views.mjs CHANGED
@@ -6,7 +6,7 @@
6
6
  // transcript's text is a segment of its own, apart from the reader's words before it (a cell given as parts: R1); or,
7
7
  // where a paragraph is wrapped into lines (a record's text line, a message, an error, the reader's own words), a line of
8
8
  // one: `par` its paragraph, `at` where the line begins in it, `dir` its direction, so that each line is laid out from
9
- // the paragraph's levels (W1, round 4). plain() gives their text, in logical order.
9
+ // the paragraph's levels. plain() gives their text, in logical order.
10
10
  //
11
11
  // Every list row begins with its address as ltms prints it (a session's prefix, a turn's id, a record's <prefix>:L<line>),
12
12
  // so the address of what is on screen can be given to an agent as it is; the selected row's is also on the last line.
@@ -339,7 +339,7 @@ const STEP = 256;
339
339
  * a window passed through, ran Node's heap out). The record is a list of pieces: a line of its own (a blank line
340
340
  * between parts, a "more characters" line, the empty record's note), or a text laid out by its new lines, each line's
341
341
  * tabs as spaces, then by columns between clusters, a space at a break hanging at the end of the line before
342
- * (src/text.mjs lineSpans, as wrap cuts: V7, round 5). One pass counts the lines and keeps where every STEP-th begins
342
+ * (src/text.mjs lineSpans, as wrap cuts). One pass counts the lines and keeps where every STEP-th begins
343
343
  * (its piece, the start of its text line, the offset in that line once its tabs are spaces); slice(a, b) lays out lines
344
344
  * a to b from the nearest. What it keeps is the pieces (the record's own strings) and those marks, whatever the lines
345
345
  * are.
@@ -485,12 +485,12 @@ export const KEYS = [
485
485
  ];
486
486
  export function help(state, cols, rows) {
487
487
  // the key column: 16 wide, and one column narrower at MIN_COLS (20), where 16 left a key's words no column within the
488
- // screen (V2, round 5: its lines took 21); its longest key ('Enter or Right') takes 14
488
+ // screen (its lines took 21 columns); its longest key ('Enter or Right') takes 14
489
489
  const kw = Math.min(16, cols - 5);
490
490
  const body = [
491
491
  ...KEYS.flatMap(([k, what]) => paragraph(what, Math.max(1, cols - kw - 4)).map((l, i) => [seg(` ${cell(i ? '' : k, kw)}`, i ? null : 'addr'), seg(' '), l])),
492
492
  [],
493
- ...textBody('It shows your transcripts\' text, to you, on this terminal\'s alternate screen: nothing it shows is written to stdout, a pipe or a log. It writes no file and uses no network. Its lists are the lines ltms index and ltms search print; a session\'s turns and calls are those ltms skeleton prints.', cols),
493
+ ...textBody('It shows your transcripts\' text, to you, on the alternate screen of this terminal, its stdout, and writes it nowhere else: no file, no pipe, no log; a program that records this terminal records what it draws. It uses no network. Its lists are the lines ltms index and ltms search print; a session\'s turns and calls are those ltms skeleton prints.', cols),
494
494
  ];
495
495
  return frame({ ...state, input: null, note: null }, cols, rows, { title: 'ltms-reader Keys', sub: 'q quits; any other key goes back', body, detail: '', hint: 'q or Ctrl-C quits any other key goes back' });
496
496
  }