ltms-reader 0.0.0-stage → 0.1.0
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/CHANGELOG.md +136 -0
- package/LICENSE +21 -0
- package/LICENSE-UNICODE +49 -0
- package/README.md +284 -2
- package/bin/ltms-reader.mjs +16 -0
- package/package.json +32 -4
- package/src/app.mjs +415 -0
- package/src/bidi-table.mjs +354 -0
- package/src/bidi.mjs +251 -0
- package/src/engine.mjs +505 -0
- package/src/guard.mjs +116 -0
- package/src/helper.mjs +127 -0
- package/src/layout.mjs +181 -0
- package/src/lines.mjs +18 -0
- package/src/main.mjs +133 -0
- package/src/reading.mjs +165 -0
- package/src/screen-process.mjs +6 -0
- package/src/screen.mjs +127 -0
- package/src/sources.mjs +134 -0
- package/src/start.mjs +123 -0
- package/src/text.mjs +712 -0
- package/src/view.mjs +337 -0
- package/src/views.mjs +518 -0
- package/src/width-table.mjs +101 -0
package/src/views.mjs
ADDED
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
// src/views.mjs — what the screen shows: one render function per view, (state, columns, rows) → the screen's lines,
|
|
2
|
+
// exactly `rows` of them. A line is a list of segments { text, style, dir, par, at }: the text already made visible
|
|
3
|
+
// (src/text.mjs), one line, cut to its columns (the last line one column short, so nothing is ever written to the
|
|
4
|
+
// screen's last cell); the style one of null, 'head', 'dim', 'sel', 'bad', 'addr'. src/screen.mjs writes them, each
|
|
5
|
+
// segment a paragraph for the right-to-left layout (text.mjs displayOrder: its direction its own, or `dir`), so that a
|
|
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
|
+
// 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
|
+
// 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.
|
|
10
|
+
//
|
|
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
|
+
// 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.
|
|
13
|
+
import { clusters, directionOf, expandTabs, fit, fitParts, lineSpans, visible, width, wordSpans } from './text.mjs';
|
|
14
|
+
import { prefixOf } from './view.mjs';
|
|
15
|
+
|
|
16
|
+
export const MIN_COLS = 20, MIN_ROWS = 5;
|
|
17
|
+
export const top = (state) => state.stack[state.stack.length - 1];
|
|
18
|
+
export const plain = (lines) => lines.map((l) => l.map((s) => s.text).join(''));
|
|
19
|
+
|
|
20
|
+
// ---- text into cells ------------------------------------------------------------------------------------------------
|
|
21
|
+
/** A label on one line: every control character, the new line and the tab included, visible. */
|
|
22
|
+
export const label = (s) => visible(s ?? '').replace(/\n/g, '\\n').replace(/\t/g, '\\t');
|
|
23
|
+
/** The first line of a text that holds anything but blanks, made visible, its tabs as spaces; with … at its end when
|
|
24
|
+
* the view layer's clip cut the text inside that line (`more` units left out: R.F4), so that the row shows it goes on. */
|
|
25
|
+
export function preview(s, more = 0) {
|
|
26
|
+
const pieces = visible(typeof s === 'string' ? s : '').split('\n');
|
|
27
|
+
const i = pieces.findIndex((l) => l.trim() !== '');
|
|
28
|
+
if (i < 0) return more > 0 ? '\u2026' : '';
|
|
29
|
+
const first = expandTabs(pieces[i]).trimEnd();
|
|
30
|
+
return more > 0 && i === pieces.length - 1 ? `${first}\u2026` : first;
|
|
31
|
+
}
|
|
32
|
+
const num = (n) => (Number.isFinite(n) ? n.toLocaleString('en-US') : '-');
|
|
33
|
+
const plural = (n, one, many) => `${num(n)} ${n === 1 ? one : many}`;
|
|
34
|
+
/** text in exactly w columns: cut with … when longer, padded with spaces (at the left when align is 'right'). */
|
|
35
|
+
export function cell(text, w, align = 'left') {
|
|
36
|
+
if (w <= 0) return '';
|
|
37
|
+
const t = fit(text, w), gap = ' '.repeat(Math.max(0, w - width(t)));
|
|
38
|
+
return align === 'right' ? gap + t : t + gap;
|
|
39
|
+
}
|
|
40
|
+
const seg = (text, style = null, dir = undefined) => (dir === undefined ? { text, style } : { text, style, dir });
|
|
41
|
+
/** A line of a paragraph: its text, the slice of `par` at `at`; `dir`, the paragraph's direction (W1). */
|
|
42
|
+
const lineSeg = (text, style, dir, par, at) => ({ text, style, dir, par, at });
|
|
43
|
+
/** One line of plain text in `cols` columns, in one style; given as parts (each a paragraph of its own), a segment each. */
|
|
44
|
+
const line = (text, cols, style = null) => (Array.isArray(text) ? fitParts(text, cols).map((t) => seg(t, style)) : [seg(fit(text, cols), style)]);
|
|
45
|
+
/** A paragraph (one line of text: no new line in it) wrapped at spaces into lines of at most `cols` columns (wordSpans),
|
|
46
|
+
* each a segment of the paragraph's own, laid out from its levels (W1). */
|
|
47
|
+
const paragraph = (text, cols, style = null) => { const dir = directionOf(text); return wordSpans(text, cols).map(([a, b]) => lineSeg(text.slice(a, b), style, dir, text, a)); };
|
|
48
|
+
|
|
49
|
+
const formats = new Map();
|
|
50
|
+
/** An ISO time as YYYY-MM-DD HH:MM in the time zone of the state (this machine's when none is set). */
|
|
51
|
+
export function when(iso, timeZone) {
|
|
52
|
+
if (typeof iso !== 'string' || iso === '') return '';
|
|
53
|
+
const d = new Date(iso);
|
|
54
|
+
if (Number.isNaN(d.getTime())) return label(iso).slice(0, 16);
|
|
55
|
+
const key = timeZone ?? '';
|
|
56
|
+
if (!formats.has(key)) formats.set(key, new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }));
|
|
57
|
+
const p = Object.fromEntries(formats.get(key).formatToParts(d).map((x) => [x.type, x.value]));
|
|
58
|
+
return `${p.year}-${p.month}-${p.day} ${p.hour}:${p.minute}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ---- the frame --------------------------------------------------------------------------------------------------------
|
|
62
|
+
/** Each view's keys on its last line, the first to keep first; "? keys" and "q quits" are always kept (R.F10). */
|
|
63
|
+
const HINTS = {
|
|
64
|
+
projects: ['Enter opens', '/ search', ': address', '? keys', 'q quits'],
|
|
65
|
+
sessions: ['Enter opens', 'Esc back', '/ search', ': address', '? keys', 'q quits'],
|
|
66
|
+
session: ['Enter opens', 'Esc back', '/ search', ': address', '? keys', 'q quits'],
|
|
67
|
+
turn: ['Enter opens the record', 'Esc back', '/ search', ': address', '? keys', 'q quits'],
|
|
68
|
+
record: ['j JSON', 'Esc back', 'PgUp PgDn pages', '/ search', ': address', '? keys', 'q quits'],
|
|
69
|
+
search: ['Enter opens', 'Esc back', '/ search', ': address', '? keys', 'q quits'],
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** The keys of a hint that fit in `cols` columns: its last two always (cut only when they alone do not fit), and before
|
|
73
|
+
* them as many of the others as fit, from the first (R.F10: at 80 columns, after a long address, the hint was cut and
|
|
74
|
+
* "q quits" with it). A hint that is a string is fit as it is. */
|
|
75
|
+
export function hintIn(hint, cols) {
|
|
76
|
+
if (typeof hint === 'string') return fit(hint, cols);
|
|
77
|
+
const kept = hint.slice(-2), rest = hint.slice(0, -2), out = [];
|
|
78
|
+
for (const h of rest) { if (width([...out, h, ...kept].join(' ')) > cols) break; out.push(h); }
|
|
79
|
+
return fit([...out, ...kept].join(' '), cols);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The end of s that fits in `cols` columns, in whole clusters (what is typed last stays in sight). */
|
|
83
|
+
export function tail(s, cols) {
|
|
84
|
+
const cs = [...clusters(s)];
|
|
85
|
+
let w = 0, i = cs.length;
|
|
86
|
+
while (i > 0 && w + width(cs[i - 1]) <= cols) { w += width(cs[i - 1]); i--; }
|
|
87
|
+
return cs.slice(i).join('');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The last line: what is being typed, else a message, else the selected row's address and the keys. Never in the
|
|
91
|
+
* screen's last column. */
|
|
92
|
+
function statusLine(state, cols, address, hint = HINTS[top(state).kind] ?? '') {
|
|
93
|
+
const w = cols - 1;
|
|
94
|
+
if (state.input) {
|
|
95
|
+
const prompt = state.input.kind === 'search' ? `/ search ${state.input.scopeShown ?? ''}: ` : ': address: ';
|
|
96
|
+
const room = Math.max(1, w - width(prompt) - 1);
|
|
97
|
+
return [seg(fit(prompt, w)), seg(tail(label(state.input.text), room)), seg(' ', 'sel')];
|
|
98
|
+
}
|
|
99
|
+
if (!address) return [seg(hintIn(hint, w), 'dim')];
|
|
100
|
+
const a = fit(label(address), w);
|
|
101
|
+
const room = w - width(a) - 2;
|
|
102
|
+
return room > 0 ? [seg(a, 'addr'), seg(` ${hintIn(hint, room)}`, 'dim')] : [seg(a, 'addr')];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The body's height for a frame with (or without) a line of column headings, and `head` lines between the title and
|
|
106
|
+
* them (one, the view's second line, but in a Sessions view: sessionsHead). */
|
|
107
|
+
export const bodyHeight = (rows, headings, head = 1) => Math.max(1, rows - 3 - head - (headings ? 1 : 0));
|
|
108
|
+
|
|
109
|
+
/** `head`: the lines under the title, when they are more than the one line `sub`. The frame's lines: the title, `head`,
|
|
110
|
+
* the column headings, the body (at least one row of it), the detail line, the status line. On a screen too low for
|
|
111
|
+
* them all (W3: 80 x 5, a list with column headings; 6 rows and fewer, a kept Sessions list), the detail line gives way
|
|
112
|
+
* first, then the column headings, then the head's lines from its last, so that the status line, with "? keys" and
|
|
113
|
+
* "q quits", is the last line drawn at every height the reader draws (MIN_ROWS and more; under it, render() draws
|
|
114
|
+
* `small`). */
|
|
115
|
+
function frame(state, cols, rows, { title, sub = '', head = null, headings = null, body, detail = '', address = null, hint }) {
|
|
116
|
+
let heads = head ?? [line(sub, cols, 'dim')];
|
|
117
|
+
const h = bodyHeight(rows, !!headings, heads.length);
|
|
118
|
+
let over = 1 + heads.length + (headings ? 1 : 0) + h + 2 - rows;
|
|
119
|
+
const withDetail = over <= 0;
|
|
120
|
+
if (!withDetail) over--;
|
|
121
|
+
const withHeadings = !!headings && over <= 0;
|
|
122
|
+
if (headings && !withHeadings) over--;
|
|
123
|
+
if (over > 0) heads = heads.slice(0, Math.max(0, heads.length - over));
|
|
124
|
+
const out = [line(title, cols, 'head'), ...heads];
|
|
125
|
+
if (withHeadings) out.push([seg(fit(headings, cols), 'dim')]);
|
|
126
|
+
for (let i = 0; i < h; i++) out.push(body[i] ?? []);
|
|
127
|
+
if (withDetail) out.push(line(detail, cols, 'dim'));
|
|
128
|
+
out.push(statusLine(state, cols, address, hint));
|
|
129
|
+
if (state.note && !state.input) {
|
|
130
|
+
// a message: on the last line, and on up to two lines above it when it is longer
|
|
131
|
+
const style = state.note.bad ? 'bad' : null, lines = paragraph(label(state.note.text), cols - 1, style).map((l) => [l]);
|
|
132
|
+
// a third line that would not hold the rest is the rest cut, a line laid out by itself (R1 (c))
|
|
133
|
+
const shown = lines.length > 3 ? [...lines.slice(0, 2), line(lines.slice(2).map(([l]) => l.text).join(' '), cols - 1, style)] : lines;
|
|
134
|
+
shown.forEach((l, i) => { out[out.length - shown.length + i] = l; });
|
|
135
|
+
}
|
|
136
|
+
// more lines than rows only when the title itself would not fit beside a row of the body: the last line stays
|
|
137
|
+
return out.length > rows ? [...out.slice(0, Math.max(0, rows - 1)), out[out.length - 1]].slice(-rows) : out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const widths = new WeakMap();
|
|
141
|
+
/** The widest of f(row) over a list's rows, at least `min` and at most `max`, by a loop (a list can hold more rows than a
|
|
142
|
+
* call can take arguments), counted once per list and kind of column. */
|
|
143
|
+
function widest(rows, tag, f, min, max) {
|
|
144
|
+
let byTag = widths.get(rows);
|
|
145
|
+
if (!byTag) { byTag = new Map(); widths.set(rows, byTag); }
|
|
146
|
+
if (!byTag.has(tag)) { let w = min; for (const r of rows) { const x = f(r); if (x !== null) w = Math.max(w, x); if (w >= max) break; } byTag.set(tag, Math.min(max, w)); }
|
|
147
|
+
return byTag.get(tag);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A count column's width: its widest count as shown (f(row), or null for a row without one), its heading's at least. */
|
|
151
|
+
const countWidth = (rows, tag, f, heading) => widest(rows, `count:${tag}`, (r) => { const t = f(r); return t === null ? null : width(t); }, width(heading), 15);
|
|
152
|
+
|
|
153
|
+
/** The first list row in sight: the view's own, moved so that its selected row is in sight. */
|
|
154
|
+
export function topOf(view, n, h) {
|
|
155
|
+
let t = Math.max(0, Math.min(view.top ?? 0, n - h));
|
|
156
|
+
const sel = view.sel ?? 0;
|
|
157
|
+
if (sel < t) t = sel;
|
|
158
|
+
if (sel >= t + h) t = sel - h + 1;
|
|
159
|
+
return Math.max(0, t);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** A list row from its cells ([text, columns, align, style]), the last cell taking what is left (its text may be parts,
|
|
163
|
+
* each a segment: the reader's words, then a transcript's text); the selected row marked with > and drawn in reverse
|
|
164
|
+
* across the whole width. */
|
|
165
|
+
function listRow(cells, cols, selected) {
|
|
166
|
+
const out = [seg(selected ? '> ' : ' ')];
|
|
167
|
+
let used = 2;
|
|
168
|
+
cells.forEach(([text, w, align = 'left', style = null], i) => {
|
|
169
|
+
const last = i === cells.length - 1, room = cols - used;
|
|
170
|
+
if (room <= 0) return;
|
|
171
|
+
const sep = i === 0 ? '' : ' ';
|
|
172
|
+
if (sep) { out.push(seg(fit(sep, room))); used += width(sep); }
|
|
173
|
+
const flex = last && w === 0; // a last cell of no width takes what is left
|
|
174
|
+
const cw = flex ? Math.max(0, cols - used) : Math.min(w, cols - used);
|
|
175
|
+
if (flex && Array.isArray(text)) { for (const t of fitParts(text, cw)) { out.push(seg(t, style)); used += width(t); } return; }
|
|
176
|
+
const t = flex ? fit(text, cw) : cell(text, cw, align);
|
|
177
|
+
out.push(seg(t, style));
|
|
178
|
+
used += width(t);
|
|
179
|
+
});
|
|
180
|
+
if (selected) {
|
|
181
|
+
const rest = cols - used;
|
|
182
|
+
if (rest > 0) out.push(seg(' '.repeat(rest)));
|
|
183
|
+
return out.map((s) => ({ text: s.text, style: 'sel' }));
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const loadingBody = (view, state, what) => {
|
|
189
|
+
const secs = view.since ? Math.floor(((state.now ?? Date.now()) - view.since) / 1000) : 0;
|
|
190
|
+
return [[seg(` ${what}${secs >= 1 ? ` (${secs} s)` : ''}`, 'dim')]];
|
|
191
|
+
};
|
|
192
|
+
const errorBody = (text, cols) => paragraph(label(text), Math.max(1, cols - 2), 'bad').map((l) => [seg(' '), l]);
|
|
193
|
+
const textBody = (text, cols, style = 'dim') => text.split('\n').flatMap((p) => paragraph(expandTabs(visible(p)), Math.max(1, cols - 2), style)).map((l) => [seg(' '), l]);
|
|
194
|
+
|
|
195
|
+
function listBody(view, rows, h, toCells, cols) {
|
|
196
|
+
const t = topOf(view, rows.length, h);
|
|
197
|
+
return rows.slice(t, t + h).map((r, i) => listRow(toCells(r), cols, t + i === view.sel && r.kind !== 'info'));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ---- Projects ---------------------------------------------------------------------------------------------------------
|
|
201
|
+
export function projects(state, cols, rows) {
|
|
202
|
+
const v = top(state), d = v.data;
|
|
203
|
+
const title = `ltms-reader Projects ${label(d?.rootShown ?? v.rootShown ?? '')}`;
|
|
204
|
+
if (v.error) return frame(state, cols, rows, { title, sub: 'the projects folder could not be listed', body: errorBody(v.error, cols) });
|
|
205
|
+
if (!d) return frame(state, cols, rows, { title, body: loadingBody(v, state, 'reading the projects folder') });
|
|
206
|
+
const h = bodyHeight(rows, true);
|
|
207
|
+
const sub = d.state !== 'dir' ? `no folder at ${label(d.rootShown)}` : `${plural(d.projects.length, 'project folder', 'project folders')}${d.links ? `; ${plural(d.links, 'symbolic link', 'symbolic links')} not entered` : ''}`;
|
|
208
|
+
const nameW = Math.max(8, cols - 2 - 2 - 11 - 2 - 16);
|
|
209
|
+
const body = d.projects.length ? listBody(v, v.rows, h, (r) => [[label(r.name), nameW], [r.unreadable ? 'unreadable' : r.transcripts === null ? '?' : `${num(r.transcripts)}${r.cut ? '+' : ''}`, 11, 'right', r.unreadable ? 'bad' : null], [when(r.newest ? new Date(r.newest).toISOString() : '', state.timeZone), 16]], cols)
|
|
210
|
+
: textBody(d.state !== 'dir' ? 'Give ltms-reader a folder of project folders, or one transcript (a .jsonl file).' : 'No project folders here: a project folder holds the transcripts (.jsonl) of the sessions run in one directory.', cols);
|
|
211
|
+
const r = v.rows[v.sel];
|
|
212
|
+
const detail = r ? `${label(d.rootShown)}/${label(r.name)}${r.unreadable ? `: cannot be listed (${label(r.unreadable)})` : ''}` : '';
|
|
213
|
+
return frame(state, cols, rows, { title, sub, headings: ` ${cell('project folder', nameW)} ${cell('transcripts', 11, 'right')} newest`, body, detail, address: r ? label(r.name) : null });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ---- Sessions ---------------------------------------------------------------------------------------------------------
|
|
217
|
+
/** From this width on, a Sessions view's counts and its notice are shown whole (N2). */
|
|
218
|
+
export const WHOLE_FROM = 80;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The lines between a Sessions view's title and its column headings: the counts and the coverage of `ltms index`'s
|
|
222
|
+
* reading, then, for a list kept from an earlier reading (src/engine.mjs: one that took AUTO_MS or more is not read
|
|
223
|
+
* again by itself when a file changes), when it was read and how many files changed since (R.F2). At WHOLE_FROM columns
|
|
224
|
+
* and wider each is whole, on as many lines as it takes (N2: the notice, put first on the counts' line, hid them at 80
|
|
225
|
+
* and 100 columns and was cut itself); narrower, or on a screen too low to keep a row of the list (under 8 rows at 80
|
|
226
|
+
* columns), each takes one line, cut with …. The App reads its length for its pages (headOf).
|
|
227
|
+
*/
|
|
228
|
+
export function sessionsHead(state, v, cols, rows) {
|
|
229
|
+
const d = v.data, c = d.coverage?.files ?? {};
|
|
230
|
+
const counts = `${plural(d.sessions.length, 'session', 'sessions')} ${num(c.found)} files found, ${num(c.read)} read, ${num(c.failed)} failed${c.notConversation ? `, ${num(c.notConversation)} with no conversation` : ''}${d.copies?.files ? `; ${plural(d.copies.files, 'identical copy', 'identical copies')} folded` : ''} ${((d.ms ?? 0) / 1000).toFixed(1)} s`;
|
|
231
|
+
const notice = d.changed ? `this list was read at ${when(new Date(d.changed.since).toISOString(), state.timeZone)}, and ${plural(d.changed.count, 'file', 'files')} changed since: r reads it again` : null;
|
|
232
|
+
const lines = (text, style, whole) => (whole ? paragraph(text, cols, style).map((l) => [l]) : [line(text, cols, style)]);
|
|
233
|
+
const of = (whole) => [...lines(counts, 'dim', whole), ...(notice ? lines(notice, null, whole) : [])];
|
|
234
|
+
const whole = cols >= WHOLE_FROM ? of(true) : null;
|
|
235
|
+
return whole && rows - 4 - whole.length >= 1 ? whole : of(false);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** How many lines a view has between its title and its column headings (frame's head): one, but in a Sessions view. */
|
|
239
|
+
export const headOf = (state, v) => (v.kind === 'sessions' && v.data && !v.error ? sessionsHead(state, v, state.cols, state.rows).length : 1);
|
|
240
|
+
|
|
241
|
+
export function sessions(state, cols, rows) {
|
|
242
|
+
const v = top(state), d = v.data;
|
|
243
|
+
const title = `ltms-reader Sessions ${label(v.project)}`;
|
|
244
|
+
if (v.error) return frame(state, cols, rows, { title, sub: 'ltms index could not list them', body: errorBody(v.error, cols) });
|
|
245
|
+
if (!d) return frame(state, cols, rows, { title, sub: 'ltms index reads every transcript of the project', body: loadingBody(v, state, 'reading the sessions with ltms index') });
|
|
246
|
+
const head = sessionsHead(state, v, cols, rows);
|
|
247
|
+
const pw = widest(v.rows, 'p', (r) => width(label(r.p)), 8, 26);
|
|
248
|
+
const wide = cols >= 120;
|
|
249
|
+
// each count as wide as its widest, its heading's width at least (R.F9: 12,000 turns read "12,0…" in 5 columns)
|
|
250
|
+
const agents = (r) => (r.agents === null || r.agents === undefined ? '?' : num(r.agents));
|
|
251
|
+
const tw = countWidth(v.rows, 'turns', (r) => num(r.turns), 'turns'), cw = countWidth(v.rows, 'calls', (r) => num(r.calls), 'calls');
|
|
252
|
+
const fw = countWidth(v.rows, 'failures', (r) => num(r.failures), 'failed'), kw = countWidth(v.rows, 'compactions', (r) => num(r.compactions), 'compact');
|
|
253
|
+
const gw = countWidth(v.rows, 'agents', agents, 'agents');
|
|
254
|
+
const cellsOf = (r) => [
|
|
255
|
+
[label(r.p), pw, 'left', 'addr'], [when(r.first, state.timeZone), 16], [num(r.turns), tw, 'right'], [num(r.calls), cw, 'right'],
|
|
256
|
+
[num(r.failures), fw, 'right', r.failures ? 'bad' : null], [num(r.compactions), kw, 'right'], [agents(r), gw, 'right'],
|
|
257
|
+
...(wide ? [[when(r.last, state.timeZone), 16], [`${label(r.file)}${r.copies ? ` +${plural(r.copies, 'identical copy', 'identical copies')}` : ''}`, 0]] : []),
|
|
258
|
+
];
|
|
259
|
+
const headings = ` ${cell('session', pw)} ${cell('started', 16)} ${cell('turns', tw, 'right')} ${cell('calls', cw, 'right')} ${cell('failed', fw, 'right')} ${cell('compact', kw, 'right')} ${cell('agents', gw, 'right')}${wide ? ` ${cell('last', 16)} file` : ''}`;
|
|
260
|
+
const h = bodyHeight(rows, true, head.length);
|
|
261
|
+
const body = v.rows.length ? listBody(v, v.rows, h, cellsOf, cols) : textBody('ltms index lists no session here: no transcript in this folder holds a turn.', cols);
|
|
262
|
+
const r = v.rows[v.sel];
|
|
263
|
+
const detail = r ? `${label(r.file)} first prompt ${label(r.firstPrompt ?? '-')} last reply ${label(r.lastReply ?? '-')}${r.copies ? ` +${plural(r.copies, 'identical copy', 'identical copies')}` : ''}` : '';
|
|
264
|
+
return frame(state, cols, rows, { title, head, headings, body, detail, address: r ? label(r.p) : null });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// ---- A session --------------------------------------------------------------------------------------------------------
|
|
268
|
+
const tokens = (n) => (Number.isFinite(n) ? num(n) : '?');
|
|
269
|
+
export function compactionText(r, word = true) {
|
|
270
|
+
return `${word ? 'compaction' : ''}${r.trigger ? ` (${label(r.trigger)})` : ''}${r.summary ? ` summary ${label(r.summary)}` : ' no summary'}${r.pre !== null || r.post !== null ? ` ${tokens(r.pre)} -> ${tokens(r.post)} tokens` : ''}${r.by ? ` made by /compact at ${label(r.by)}` : ''}`;
|
|
271
|
+
}
|
|
272
|
+
export function session(state, cols, rows) {
|
|
273
|
+
const v = top(state), doc = v.doc;
|
|
274
|
+
const where = v.project === null ? label(v.file) : `${label(v.project)}/${label(v.file)}`;
|
|
275
|
+
const title = `ltms-reader Session ${label(prefixOf(String(v.file).slice(String(v.file).lastIndexOf('/') + 1)))} ${where}`;
|
|
276
|
+
if (v.error) return frame(state, cols, rows, { title, sub: 'this transcript could not be read', body: errorBody(v.error, cols) });
|
|
277
|
+
if (!doc) return frame(state, cols, rows, { title, body: loadingBody(v, state, `reading ${label(v.file)}`) });
|
|
278
|
+
const sv = doc.view, failed = sv.index.failures, calls = sv.index.calls;
|
|
279
|
+
const sub = `${plural(sv.turns.length, 'turn', 'turns')} ${plural(calls, 'call', 'calls')} ${num(failed)} failed ${plural(sv.index.compactions.length, 'compaction', 'compactions')} ${plural(sv.stats.lines, 'line', 'lines')}${sv.stats.first ? ` ${when(sv.stats.first, state.timeZone)} to ${when(sv.stats.last, state.timeZone)}` : ''}`;
|
|
280
|
+
const aw = widest(v.rows, 'ta', (r) => width(label(r.ta ?? r.a)), 8, 26);
|
|
281
|
+
const h = bodyHeight(rows, true);
|
|
282
|
+
const turnsOnly = (f) => (r) => (r.kind === 'turn' ? f(r) : null);
|
|
283
|
+
const cw = countWidth(v.rows, 'calls', turnsOnly((r) => num(r.calls)), 'calls'), fw = countWidth(v.rows, 'failed', turnsOnly((r) => num(r.failed)), 'failed');
|
|
284
|
+
const cellsOf = (r) => (r.kind === 'turn'
|
|
285
|
+
? [[label(r.ta), aw, 'left', 'addr'], [label(r.ch), 8], [num(r.calls), cw, 'right'], [num(r.failed), fw, 'right', r.failed ? 'bad' : null], [r.command ? `${label(r.command.name)} ${label(r.command.args)}` : preview(r.prompt, r.promptMore), 0]]
|
|
286
|
+
: r.kind === 'compaction' ? [[label(r.a), aw, 'left', 'addr'], [compactionText(r), 0, 'left', 'dim']]
|
|
287
|
+
: [[label(r.a), aw, 'left', 'addr'], [[`${r.kind} `, preview(r.text, r.more)], 0, 'left', 'dim']]);
|
|
288
|
+
const empty = `No turns: ltms reads this file as ${label(sv.fileKind)}, ${plural(sv.stats.lines, 'line', 'lines')}, ${plural(sv.stats.parsed, 'record', 'records')} parsed${sv.problems.count ? `, ${plural(sv.problems.count, 'line', 'lines')} not read` : ''}. A session's turns start at its prompts.`;
|
|
289
|
+
const body = v.rows.length ? listBody(v, v.rows, h, cellsOf, cols) : textBody(empty, cols);
|
|
290
|
+
const r = v.rows[v.sel];
|
|
291
|
+
let detail = '';
|
|
292
|
+
if (r?.kind === 'turn') detail = `${label(r.ta)} prompt ${label(r.a)} lines ${r.from} to ${r.to} ${plural(r.records, 'record', 'records')}${r.time ? ` ${when(r.time, state.timeZone)}` : ''}`;
|
|
293
|
+
else if (r?.kind === 'compaction') detail = `boundary ${label(r.a)}${r.summary ? ` summary ${label(r.summary)}` : ''}${r.time ? ` ${when(r.time, state.timeZone)}` : ''}${r.lead ? ' before the first prompt' : ''}`;
|
|
294
|
+
else if (r) detail = `${label(r.a)} ${r.kind}`;
|
|
295
|
+
return frame(state, cols, rows, { title, sub, headings: ` ${cell('turn', aw)} ${cell('channel', 8)} ${cell('calls', cw, 'right')} ${cell('failed', fw, 'right')} prompt`, body, detail, address: r ? (r.ta ?? r.a) : null });
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ---- A turn -----------------------------------------------------------------------------------------------------------
|
|
299
|
+
/** What a turn's row says after its address and kind, as parts: the reader's words, then the transcript's text, each a
|
|
300
|
+
* paragraph of its own (R1). */
|
|
301
|
+
export function itemParts(r, ek) {
|
|
302
|
+
const text = (t, more) => [preview(t, more)];
|
|
303
|
+
switch (r.kind) {
|
|
304
|
+
case 'prompt': return [`${label(r.ch)} ${plural(r.n, 'character', 'characters')} `, ...(r.command ? [`${label(r.command.name)} ${label(r.command.args)}`] : text(r.text, r.more))];
|
|
305
|
+
case 'call': {
|
|
306
|
+
const status = r.ok === true ? 'ok' : r.ok === false ? `failed${ek ? ` ${label(ek)}` : ''}` : 'no result recorded';
|
|
307
|
+
return [`${status} ${label(r.tool)} ${r.inputKey ? `${label(r.inputKey)}: ` : ''}`, ...text(r.inputText, r.inputMore)];
|
|
308
|
+
}
|
|
309
|
+
case 'result': return [`${plural(r.n, 'character', 'characters')} `, ...text(r.text, r.more)];
|
|
310
|
+
case 'compaction': return [compactionText(r, false).trim()];
|
|
311
|
+
case 'note': return [`${label(r.sub)} `, ...(r.command ? [`${label(r.command.name)} ${label(r.command.args)}`] : text(r.text, r.more))];
|
|
312
|
+
default: return text(r.text, r.more);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/** What a turn's row says after its address and kind, as one string. */
|
|
316
|
+
export const itemText = (r, ek) => itemParts(r, ek).join('');
|
|
317
|
+
export function turn(state, cols, rows) {
|
|
318
|
+
const v = top(state), doc = v.doc, t = v.turn;
|
|
319
|
+
const title = `ltms-reader Turn ${label(t.ta)} ${v.project === null ? label(v.file) : `${label(v.project)}/${label(v.file)}`}`;
|
|
320
|
+
const sub = `${label(t.ch)} ${plural(t.calls, 'call', 'calls')} ${num(t.failed)} failed${t.time ? ` ${when(t.time, state.timeZone)}` : ''}${doc.ekError ? ' (error classes: ltms skeleton failed)' : doc.ek ? '' : ' (error classes: reading)'}`;
|
|
321
|
+
const aw = widest(v.rows, 'a', (r) => width(label(r.a)), 8, 26);
|
|
322
|
+
const h = bodyHeight(rows, true);
|
|
323
|
+
const cellsOf = (r) => [[label(r.a), aw, 'left', 'addr'], [r.kind, 10], [itemParts(r, doc.ek?.get(r.call ?? r.item)), 0, 'left', r.kind === 'call' && r.ok === false ? 'bad' : r.kind === 'result' || r.kind === 'note' ? 'dim' : null]];
|
|
324
|
+
const body = listBody(v, v.rows, h, cellsOf, cols);
|
|
325
|
+
const r = v.rows[v.sel];
|
|
326
|
+
let detail = '';
|
|
327
|
+
if (r?.kind === 'call') detail = `${label(r.a)} call ${label(r.tool)} ${itemText(r, doc.ek?.get(r.item)).split(' ')[0]}${r.r ? ` result ${label(r.r)}` : ''}${r.time ? ` ${when(r.time, state.timeZone)}` : ''}`;
|
|
328
|
+
else if (r?.kind === 'result') detail = `${label(r.a)} the result of the call at ${label(r.of)}`;
|
|
329
|
+
else if (r) detail = `${label(r.a)} ${r.kind}${r.time ? ` ${when(r.time, state.timeZone)}` : ''}`;
|
|
330
|
+
return frame(state, cols, rows, { title, sub, headings: ` ${cell('address', aw)} ${cell('kind', 10)} what`, body, detail, address: r?.a ?? null });
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ---- A record ---------------------------------------------------------------------------------------------------------
|
|
334
|
+
/** Every STEP-th line's start is kept when a record's lines are counted; a page is laid out from the nearest before it. */
|
|
335
|
+
const STEP = 256;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* A record's lines at one width, laid out a page at a time (R.F1: a record's lines, made whole and kept at every width
|
|
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
|
+
* between parts, a "more characters" line, the empty record's note), or a text laid out by its new lines, each line's
|
|
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
|
|
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
|
+
* a to b from the nearest. What it keeps is the pieces (the record's own strings) and those marks, whatever the lines
|
|
345
|
+
* are.
|
|
346
|
+
*/
|
|
347
|
+
export class RecordLines {
|
|
348
|
+
constructor(pieces, cols) {
|
|
349
|
+
this.pieces = pieces;
|
|
350
|
+
this.cols = cols;
|
|
351
|
+
this.marks = [];
|
|
352
|
+
this.last = null; // the text line laid out last, its tabs as spaces: { p, at, text, dir }
|
|
353
|
+
let n = 0;
|
|
354
|
+
for (const l of this.walk(0, 0, 0)) { if (n % STEP === 0) this.marks.push([l.p, l.at, l.k]); n++; }
|
|
355
|
+
this.length = n;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** A text line of piece p, from `at` to the next new line, with its tabs as spaces (the one laid out last is kept). */
|
|
359
|
+
textLine(p, at, end) {
|
|
360
|
+
if (this.last?.p !== p || this.last.at !== at) this.last = { p, at, text: expandTabs(this.pieces[p].text.slice(at, end)) };
|
|
361
|
+
return this.last.text;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** The direction of the text line a line of it is in (the one laid out last, as walk() lays them out). */
|
|
365
|
+
directionOf(l) {
|
|
366
|
+
if (this.last?.text === l.text) return (this.last.dir ??= directionOf(l.text));
|
|
367
|
+
return directionOf(l.text);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** The lines from a mark (piece p, its text line at `at`, offset k in it): { p, at, k, text, a, b, style } each, where
|
|
371
|
+
* text.slice(a, b) is the line; a piece's own line has no text line ({ line }). */
|
|
372
|
+
*walk(p, at, k) {
|
|
373
|
+
for (; p < this.pieces.length; p++, at = 0, k = 0) {
|
|
374
|
+
const piece = this.pieces[p];
|
|
375
|
+
if (piece.line !== undefined) { yield { p, at: 0, k: 0, line: piece.line, style: piece.style }; continue; }
|
|
376
|
+
const t = piece.text;
|
|
377
|
+
for (;;) {
|
|
378
|
+
let end = t.indexOf('\n', at);
|
|
379
|
+
if (end < 0) end = t.length;
|
|
380
|
+
const text = this.textLine(p, at, end);
|
|
381
|
+
for (const [a, b] of lineSpans(text, this.cols, k)) yield { p, at, k: a, text, a, b, style: piece.style };
|
|
382
|
+
if (end === t.length) break;
|
|
383
|
+
at = end + 1; k = 0;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** Lines a to b (all, when not given), as the views' lines: [{ text, style, dir, par, at }] each, [] for a blank line; a
|
|
389
|
+
* line of a text is a line of its text line (`par`, from `at`: the paragraph it is laid out from, W1), with its text
|
|
390
|
+
* line's direction (directionOf), found once. */
|
|
391
|
+
slice(a = 0, b = this.length) {
|
|
392
|
+
a = Math.max(0, a); b = Math.min(b, this.length);
|
|
393
|
+
if (a >= b) return [];
|
|
394
|
+
const m = Math.min(this.marks.length - 1, Math.floor(a / STEP));
|
|
395
|
+
const out = [];
|
|
396
|
+
let i = m * STEP;
|
|
397
|
+
for (const l of this.walk(...this.marks[m])) {
|
|
398
|
+
if (i >= a) out.push(l.line !== undefined ? (l.line === '' ? [] : [seg(l.line, l.style)]) : [lineSeg(l.text.slice(l.a, l.b), l.style, this.directionOf(l), l.text, l.a)]);
|
|
399
|
+
if (++i >= b) break;
|
|
400
|
+
}
|
|
401
|
+
return out;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** A record's pieces at `cols` columns: each part's label (wrapped: a tool's name can be long), its text, and how much
|
|
406
|
+
* of it is not shown; or its JSON. */
|
|
407
|
+
function recordPieces(rec, json, cols) {
|
|
408
|
+
const more = (n) => ({ line: fit(`... ${plural(n, 'more character', 'more characters')} not shown`, cols), style: 'dim' });
|
|
409
|
+
if (json) return [{ text: visible(rec.raw.text), style: null }, ...(rec.raw.more ? [more(rec.raw.more)] : [])];
|
|
410
|
+
if (!rec.reading.length) return [{ line: fit('(nothing to read in this record)', cols), style: 'dim' }];
|
|
411
|
+
return rec.reading.flatMap((p, i) => [
|
|
412
|
+
...(i ? [{ line: '', style: null }] : []),
|
|
413
|
+
{ text: `-- ${label(p.label)} --`, style: 'head' },
|
|
414
|
+
...(p.text !== '' ? [{ text: visible(p.text), style: null }] : []),
|
|
415
|
+
...(p.more ? [more(p.more)] : []),
|
|
416
|
+
]);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const pages = new WeakMap();
|
|
420
|
+
/** The record's lines at `cols` columns (a RecordLines: its length, and slice(a, b)), its text's or its JSON's. Kept for
|
|
421
|
+
* the width drawn last only: the lines at every width a window was resized through, kept, ran Node's heap out (R.F1). */
|
|
422
|
+
export function recordLines(rec, json, cols) {
|
|
423
|
+
let kept = pages.get(rec);
|
|
424
|
+
if (!kept) { kept = { t: null, j: null }; pages.set(rec, kept); }
|
|
425
|
+
const kind = json ? 'j' : 't';
|
|
426
|
+
if (kept[kind]?.cols !== cols) { kept[kind] = null; kept[kind] = new RecordLines(recordPieces(rec, json, cols), cols); }
|
|
427
|
+
return kept[kind];
|
|
428
|
+
}
|
|
429
|
+
export function record(state, cols, rows) {
|
|
430
|
+
const v = top(state), rec = v.rec;
|
|
431
|
+
const title = `ltms-reader Record ${label(v.a ?? rec.a)} ${v.project === null ? label(v.file) : `${label(v.project)}/${label(v.file)}`}`;
|
|
432
|
+
if (v.error) return frame(state, cols, rows, { title, sub: 'this record is not shown', body: errorBody(v.error, cols), detail: `${label(v.a)} line ${v.line} of ${label(v.file)}`, address: v.a });
|
|
433
|
+
const lines = recordLines(rec, v.json, cols);
|
|
434
|
+
const h = bodyHeight(rows, false);
|
|
435
|
+
const t = Math.max(0, Math.min(v.top ?? 0, lines.length - h));
|
|
436
|
+
const kind = [rec.type, rec.subtype].filter(Boolean).map(label).join('/') || '(no type)';
|
|
437
|
+
// the place first, then whether it is the JSON: at 80 columns the end of the line can be cut, these never (R.F10)
|
|
438
|
+
const sub = `lines ${num(Math.min(lines.length, t + 1))} to ${num(Math.min(lines.length, t + h))} of ${num(lines.length)} ${v.json ? 'as JSON' : plural(rec.reading.length, 'part', 'parts')} ${kind}${rec.channel ? ` ${label(rec.channel)}` : ''}${rec.time ? ` ${when(rec.time, state.timeZone)}` : ''} ${plural(rec.bytes, 'byte', 'bytes')} at offset ${num(rec.offset)}`;
|
|
439
|
+
return frame(state, cols, rows, { title, sub, body: lines.slice(t, t + h), detail: `${label(rec.a)} line ${rec.line} of ${label(v.file)}${rec.uuid ? ` uuid ${label(rec.uuid)}` : ''}`, address: rec.a });
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// ---- Search -----------------------------------------------------------------------------------------------------------
|
|
443
|
+
export function coverageText(c) {
|
|
444
|
+
if (!c) return 'ltms search printed no coverage line';
|
|
445
|
+
const f = c.files ?? {}, ns = c.notSearched ?? {};
|
|
446
|
+
const skipped = Object.entries(ns).filter(([, n]) => n).map(([k, n]) => `${num(n)} ${k}`);
|
|
447
|
+
return `${plural(c.hits?.turns ?? 0, 'matching turn', 'matching turns')} in ${num(c.hits?.files ?? 0)} of ${plural(f.found ?? 0, 'file', 'files')} (${num(f.read)} read, ${num(f.failed)} failed) searched: ${(c.kinds ?? []).join(', ')}${c.kindsOff?.length ? ` not searched: ${c.kindsOff.join(', ')}` : ''}${skipped.length ? `; ${skipped.join(', ')}` : ''}${c.mode === 'substring' ? ' inside words' : ''}`;
|
|
448
|
+
}
|
|
449
|
+
export function search(state, cols, rows) {
|
|
450
|
+
const v = top(state), d = v.result;
|
|
451
|
+
const title = `ltms-reader Search "${label(v.q)}" ${v.scopeShown}`;
|
|
452
|
+
if (v.error) return frame(state, cols, rows, { title, sub: 'ltms search could not run', body: errorBody(v.error, cols) });
|
|
453
|
+
if (!d) return frame(state, cols, rows, { title, sub: 'ltms search reads every transcript in scope', body: loadingBody(v, state, 'searching with ltms search') });
|
|
454
|
+
const c = d.coverage, shown = c?.shown?.turns ?? d.hits.length;
|
|
455
|
+
const sub = `turns ${num(shown ? d.skip + 1 : 0)} to ${num(d.skip + shown)} of ${num(c?.hits?.turns ?? 0)} ${((d.ms ?? 0) / 1000).toFixed(1)} s`;
|
|
456
|
+
const tw = widest(v.rows, 'tap', (r) => (r.kind === 'hit' || r.kind === 'file' ? width(label(r.ta ?? r.p)) : null), 8, 26);
|
|
457
|
+
const h = bodyHeight(rows, false);
|
|
458
|
+
const cellsOf = (r) => {
|
|
459
|
+
if (r.kind === 'info') return [[r.text, 0, 'left', 'dim']];
|
|
460
|
+
if (r.kind === 'file') return [[label(r.p), tw, 'left', 'addr'], [when(r.last, state.timeZone), 16], [`${r.project === null ? '' : `${label(r.project)}/`}${label(r.file)}${r.copies ? ` +${plural(r.copies, 'identical copy', 'identical copies')}` : ''}`, 0]];
|
|
461
|
+
if (r.kind === 'more') return [[`the next ${num(r.next)} of ${plural(r.left, 'more matching turn', 'more matching turns')}`, 0]];
|
|
462
|
+
return [[label(r.ta), tw, 'left', 'addr'], [label(r.ch), 8], [r.at.map((e) => `${label(String(e.a).slice(String(e.a).lastIndexOf(':') + 1))} ${label(e.kind)}`).join(' '), 0]];
|
|
463
|
+
};
|
|
464
|
+
const body = listBody(v, v.rows, h, cellsOf, cols);
|
|
465
|
+
const r = v.rows[v.sel];
|
|
466
|
+
let detail = '';
|
|
467
|
+
if (r?.kind === 'hit') detail = `${label(r.ta)} ${plural(r.at.length, 'record', 'records')} with a match first ${label(r.at[0]?.a ?? '')} ${label(r.at[0]?.kind ?? '')}`;
|
|
468
|
+
else if (r?.kind === 'file') detail = `${r.project === null ? '' : `${label(r.project)}/`}${label(r.file)} its latest record ${when(r.last, state.timeZone)}`;
|
|
469
|
+
return frame(state, cols, rows, { title, sub, body, detail, address: r?.kind === 'hit' ? label(r.ta) : r?.kind === 'file' ? label(r.p) : null });
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// ---- the keys ---------------------------------------------------------------------------------------------------------
|
|
473
|
+
export const KEYS = [
|
|
474
|
+
['Up Down', 'move one row (in a record, one line)'],
|
|
475
|
+
['PgUp PgDn', 'move one page'],
|
|
476
|
+
['Home End', 'the first row, the last'],
|
|
477
|
+
['Enter or Right', 'open the row: a project, a session, a turn, a record'],
|
|
478
|
+
['Esc or Left', 'go back'],
|
|
479
|
+
['/', 'search: the turns that hold every word, by ltms search, in this project (in every project from Projects)'],
|
|
480
|
+
[':', 'open an address as ltms prints it: <prefix>:L<line> (a record) or <prefix>:T<turn> (a turn)'],
|
|
481
|
+
['r', 'in Projects and in a project\'s Sessions: read the list again, the selection kept on its row'],
|
|
482
|
+
['j', 'in a record: its JSON, and back'],
|
|
483
|
+
['?', 'these keys'],
|
|
484
|
+
['q or Ctrl-C', 'quit'],
|
|
485
|
+
];
|
|
486
|
+
export function help(state, cols, rows) {
|
|
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
|
|
489
|
+
const kw = Math.min(16, cols - 5);
|
|
490
|
+
const body = [
|
|
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
|
+
[],
|
|
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),
|
|
494
|
+
];
|
|
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
|
+
}
|
|
497
|
+
|
|
498
|
+
/** A screen too small to use: the size the reader needs, wrapped over the lines there are, each line one column short of
|
|
499
|
+
* the screen (W3: one line cut to the screen's width lost the size under 26 columns), at its spaces but those inside a
|
|
500
|
+
* size ("20 x 5", and the screen's own), which stays on one line where it fits; on a screen too small for all of it,
|
|
501
|
+
* its first lines. Each line is a line of the message (W1: par, at). */
|
|
502
|
+
export function small(state, cols, rows) {
|
|
503
|
+
const w = cols - 1, text = `ltms-reader needs ${MIN_COLS} x ${MIN_ROWS} at least; this is ${cols} x ${rows}`;
|
|
504
|
+
// where its lines begin and end: the spaces of a size taken as no-break ones (the same length, so the same places)
|
|
505
|
+
const spans = w >= 1 ? wordSpans(text.replace(/(\d) x (\d)/g, '$1\u00a0x\u00a0$2'), w) : [];
|
|
506
|
+
const out = spans.map(([a, b]) => [lineSeg(text.slice(a, b), 'bad', 0, text, a)]);
|
|
507
|
+
while (out.length < rows) out.push([]);
|
|
508
|
+
return out.slice(0, Math.max(0, rows));
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export const RENDER = Object.freeze({ projects, sessions, session, turn, record, search });
|
|
512
|
+
|
|
513
|
+
/** The screen's lines for the state: the keys when asked for, else the view on top. */
|
|
514
|
+
export function render(state, cols, rows) {
|
|
515
|
+
if (cols < MIN_COLS || rows < MIN_ROWS) return small(state, cols, rows);
|
|
516
|
+
if (state.help) return help(state, cols, rows);
|
|
517
|
+
return RENDER[top(state).kind](state, cols, rows);
|
|
518
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// src/width-table.mjs — WRITTEN BY scripts/width-table.mjs; do not edit it by hand: change the script, and run it again.
|
|
2
|
+
//
|
|
3
|
+
// The code points a terminal draws two columns wide: East_Asian_Width W (wide) or F (fullwidth), with the defaults the
|
|
4
|
+
// file's header states (W for the unassigned code points of the CJK ideograph blocks and of planes 2 and 3), as merged,
|
|
5
|
+
// sorted, inclusive ranges [first, last, first, last, ...]. "A" (ambiguous) is not here: one column.
|
|
6
|
+
//
|
|
7
|
+
// From Unicode's EastAsianWidth.txt, version 17.0.0:
|
|
8
|
+
// https://www.unicode.org/Public/17.0.0/ucd/EastAsianWidth.txt
|
|
9
|
+
// sha256 ea7ce50f3444a050333448dffef1cadd9325af55cbb764b4a2280faf52170a33
|
|
10
|
+
// whose first lines are
|
|
11
|
+
// # EastAsianWidth-17.0.0.txt
|
|
12
|
+
// # Date: 2025-07-24, 00:12:54 GMT
|
|
13
|
+
// # © 2025 Unicode®, Inc.
|
|
14
|
+
//
|
|
15
|
+
// Its licence (LICENSE-UNICODE, which the package ships beside this table):
|
|
16
|
+
//
|
|
17
|
+
// Two files of this package are derived from the Unicode Character Database, version 17.0.0, whose files' headers say
|
|
18
|
+
// "© 2025 Unicode®, Inc.":
|
|
19
|
+
// - src/width-table.mjs from EastAsianWidth.txt (https://www.unicode.org/Public/17.0.0/ucd/EastAsianWidth.txt, sha256
|
|
20
|
+
// ea7ce50f3444a050333448dffef1cadd9325af55cbb764b4a2280faf52170a33);
|
|
21
|
+
// - src/bidi-table.mjs from DerivedBidiClass.txt, UnicodeData.txt, BidiBrackets.txt and BidiMirroring.txt
|
|
22
|
+
// (https://www.unicode.org/Public/17.0.0/ucd/, each named with its sha256 at the head of the table).
|
|
23
|
+
// They are used under this licence, the Unicode License v3 (https://www.unicode.org/license.txt):
|
|
24
|
+
//
|
|
25
|
+
// UNICODE LICENSE V3
|
|
26
|
+
//
|
|
27
|
+
// COPYRIGHT AND PERMISSION NOTICE
|
|
28
|
+
//
|
|
29
|
+
// Copyright © 2025 Unicode, Inc.
|
|
30
|
+
//
|
|
31
|
+
// NOTICE TO USER: Carefully read the following legal agreement. BY
|
|
32
|
+
// DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
|
|
33
|
+
// SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
|
|
34
|
+
// TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT
|
|
35
|
+
// DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE.
|
|
36
|
+
//
|
|
37
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
38
|
+
// copy of data files and any associated documentation (the "Data Files") or
|
|
39
|
+
// software and any associated documentation (the "Software") to deal in the
|
|
40
|
+
// Data Files or Software without restriction, including without limitation
|
|
41
|
+
// the rights to use, copy, modify, merge, publish, distribute, and/or sell
|
|
42
|
+
// copies of the Data Files or Software, and to permit persons to whom the
|
|
43
|
+
// Data Files or Software are furnished to do so, provided that either (a)
|
|
44
|
+
// this copyright and permission notice appear with all copies of the Data
|
|
45
|
+
// Files or Software, or (b) this copyright and permission notice appear in
|
|
46
|
+
// associated Documentation.
|
|
47
|
+
//
|
|
48
|
+
// THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
|
|
49
|
+
// KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
50
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
51
|
+
// THIRD PARTY RIGHTS.
|
|
52
|
+
//
|
|
53
|
+
// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE
|
|
54
|
+
// BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES,
|
|
55
|
+
// OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
56
|
+
// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
57
|
+
// ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA
|
|
58
|
+
// FILES OR SOFTWARE.
|
|
59
|
+
//
|
|
60
|
+
// Except as contained in this notice, the name of a copyright holder shall
|
|
61
|
+
// not be used in advertising or otherwise to promote the sale, use or other
|
|
62
|
+
// dealings in these Data Files or Software without prior written
|
|
63
|
+
// authorization of the copyright holder.
|
|
64
|
+
//
|
|
65
|
+
// SPDX-License-Identifier: Unicode-3.0
|
|
66
|
+
export const UNICODE_VERSION = '17.0.0';
|
|
67
|
+
export const SOURCE_URL = 'https://www.unicode.org/Public/17.0.0/ucd/EastAsianWidth.txt';
|
|
68
|
+
export const SOURCE_SHA256 = 'ea7ce50f3444a050333448dffef1cadd9325af55cbb764b4a2280faf52170a33';
|
|
69
|
+
export const WIDE = Object.freeze([
|
|
70
|
+
0x1100, 0x115f, 0x231a, 0x231b, 0x2329, 0x232a, 0x23e9, 0x23ec,
|
|
71
|
+
0x23f0, 0x23f0, 0x23f3, 0x23f3, 0x25fd, 0x25fe, 0x2614, 0x2615,
|
|
72
|
+
0x2630, 0x2637, 0x2648, 0x2653, 0x267f, 0x267f, 0x268a, 0x268f,
|
|
73
|
+
0x2693, 0x2693, 0x26a1, 0x26a1, 0x26aa, 0x26ab, 0x26bd, 0x26be,
|
|
74
|
+
0x26c4, 0x26c5, 0x26ce, 0x26ce, 0x26d4, 0x26d4, 0x26ea, 0x26ea,
|
|
75
|
+
0x26f2, 0x26f3, 0x26f5, 0x26f5, 0x26fa, 0x26fa, 0x26fd, 0x26fd,
|
|
76
|
+
0x2705, 0x2705, 0x270a, 0x270b, 0x2728, 0x2728, 0x274c, 0x274c,
|
|
77
|
+
0x274e, 0x274e, 0x2753, 0x2755, 0x2757, 0x2757, 0x2795, 0x2797,
|
|
78
|
+
0x27b0, 0x27b0, 0x27bf, 0x27bf, 0x2b1b, 0x2b1c, 0x2b50, 0x2b50,
|
|
79
|
+
0x2b55, 0x2b55, 0x2e80, 0x2e99, 0x2e9b, 0x2ef3, 0x2f00, 0x2fd5,
|
|
80
|
+
0x2ff0, 0x303e, 0x3041, 0x3096, 0x3099, 0x30ff, 0x3105, 0x312f,
|
|
81
|
+
0x3131, 0x318e, 0x3190, 0x31e5, 0x31ef, 0x321e, 0x3220, 0x3247,
|
|
82
|
+
0x3250, 0xa48c, 0xa490, 0xa4c6, 0xa960, 0xa97c, 0xac00, 0xd7a3,
|
|
83
|
+
0xf900, 0xfaff, 0xfe10, 0xfe19, 0xfe30, 0xfe52, 0xfe54, 0xfe66,
|
|
84
|
+
0xfe68, 0xfe6b, 0xff01, 0xff60, 0xffe0, 0xffe6, 0x16fe0, 0x16fe4,
|
|
85
|
+
0x16ff0, 0x16ff6, 0x17000, 0x18cd5, 0x18cff, 0x18d1e, 0x18d80, 0x18df2,
|
|
86
|
+
0x1aff0, 0x1aff3, 0x1aff5, 0x1affb, 0x1affd, 0x1affe, 0x1b000, 0x1b122,
|
|
87
|
+
0x1b132, 0x1b132, 0x1b150, 0x1b152, 0x1b155, 0x1b155, 0x1b164, 0x1b167,
|
|
88
|
+
0x1b170, 0x1b2fb, 0x1d300, 0x1d356, 0x1d360, 0x1d376, 0x1f004, 0x1f004,
|
|
89
|
+
0x1f0cf, 0x1f0cf, 0x1f18e, 0x1f18e, 0x1f191, 0x1f19a, 0x1f200, 0x1f202,
|
|
90
|
+
0x1f210, 0x1f23b, 0x1f240, 0x1f248, 0x1f250, 0x1f251, 0x1f260, 0x1f265,
|
|
91
|
+
0x1f300, 0x1f320, 0x1f32d, 0x1f335, 0x1f337, 0x1f37c, 0x1f37e, 0x1f393,
|
|
92
|
+
0x1f3a0, 0x1f3ca, 0x1f3cf, 0x1f3d3, 0x1f3e0, 0x1f3f0, 0x1f3f4, 0x1f3f4,
|
|
93
|
+
0x1f3f8, 0x1f43e, 0x1f440, 0x1f440, 0x1f442, 0x1f4fc, 0x1f4ff, 0x1f53d,
|
|
94
|
+
0x1f54b, 0x1f54e, 0x1f550, 0x1f567, 0x1f57a, 0x1f57a, 0x1f595, 0x1f596,
|
|
95
|
+
0x1f5a4, 0x1f5a4, 0x1f5fb, 0x1f64f, 0x1f680, 0x1f6c5, 0x1f6cc, 0x1f6cc,
|
|
96
|
+
0x1f6d0, 0x1f6d2, 0x1f6d5, 0x1f6d8, 0x1f6dc, 0x1f6df, 0x1f6eb, 0x1f6ec,
|
|
97
|
+
0x1f6f4, 0x1f6fc, 0x1f7e0, 0x1f7eb, 0x1f7f0, 0x1f7f0, 0x1f90c, 0x1f93a,
|
|
98
|
+
0x1f93c, 0x1f945, 0x1f947, 0x1f9ff, 0x1fa70, 0x1fa7c, 0x1fa80, 0x1fa8a,
|
|
99
|
+
0x1fa8e, 0x1fac6, 0x1fac8, 0x1fac8, 0x1facd, 0x1fadc, 0x1fadf, 0x1faea,
|
|
100
|
+
0x1faef, 0x1faf8, 0x20000, 0x2fffd, 0x30000, 0x3fffd,
|
|
101
|
+
]);
|