@awebai/oats 0.51.0 → 0.53.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.
Files changed (166) hide show
  1. package/README.md +3 -1
  2. package/bin/oats.mjs +407 -123
  3. package/docs/capabilities.md +75 -6
  4. package/docs/configuration.md +200 -91
  5. package/docs/desktop-cli-api.md +1563 -113
  6. package/docs/desktop-instance-start.md +69 -0
  7. package/docs/desktop.md +10 -7
  8. package/docs/execution-targets.md +145 -58
  9. package/docs/first-team.md +3 -1
  10. package/docs/harness-trust.md +50 -2
  11. package/docs/implementation.md +238 -17
  12. package/docs/integrations.md +13 -9
  13. package/docs/knowledge-reference/acceptance.md +1 -0
  14. package/docs/knowledge-reference/harvester.md +5 -3
  15. package/docs/knowledge-reference/model.md +5 -3
  16. package/docs/knowledge-theory.md +1 -1
  17. package/docs/knowledge.md +25 -2
  18. package/docs/launch-prompt-completion.md +50 -48
  19. package/docs/macos-test-runs.md +246 -0
  20. package/docs/oats-local.schema.json +4 -3
  21. package/docs/official-catalog.md +5 -5
  22. package/docs/packages.md +14 -14
  23. package/docs/release-lane.md +225 -11
  24. package/docs/release-notes/v0.44.0.md +1 -1
  25. package/docs/release-notes/v0.52.0.md +933 -0
  26. package/docs/release-notes/v0.53.0.md +1274 -0
  27. package/docs/schedules.md +97 -4
  28. package/docs/souls-and-instances.md +332 -40
  29. package/docs/tui.md +584 -0
  30. package/docs/upgrading.md +298 -0
  31. package/docs/workspaces.md +3 -3
  32. package/lib/automations.mjs +22 -22
  33. package/lib/claim.mjs +278 -49
  34. package/lib/config-data.mjs +4 -1
  35. package/lib/core.mjs +1282 -289
  36. package/lib/errors.mjs +170 -0
  37. package/lib/harness-trust-write.mjs +68 -27
  38. package/lib/harness-trust.mjs +34 -16
  39. package/lib/instance-events.mjs +19 -1
  40. package/lib/instance-git.mjs +39 -3
  41. package/lib/instance-inspect.mjs +45 -17
  42. package/lib/instance-lifecycle.mjs +306 -57
  43. package/lib/instance-resolution.mjs +59 -6
  44. package/lib/launch-preference.mjs +236 -9
  45. package/lib/launch-prompt-completion.mjs +7 -43
  46. package/lib/launch-prompt-evidence.mjs +14 -7
  47. package/lib/launch-prompt-fixtures/README.md +86 -152
  48. package/lib/launch-prompt-fixtures/dev-channel-confirmation.json +50 -0
  49. package/lib/launch-prompt-fixtures.mjs +122 -109
  50. package/lib/launch-prompt-transport.mjs +2 -56
  51. package/lib/launch-prompts.mjs +102 -100
  52. package/lib/local-edit.mjs +118 -0
  53. package/lib/packages.mjs +13 -4
  54. package/lib/pi-bridge.mjs +308 -0
  55. package/lib/refused-text.mjs +11 -0
  56. package/lib/remote.mjs +190 -25
  57. package/lib/resolve.mjs +2 -1
  58. package/lib/retained-after-retire.mjs +2 -2
  59. package/lib/retire-output.mjs +12 -1
  60. package/lib/schedule-host.mjs +125 -22
  61. package/lib/schedule.mjs +73 -24
  62. package/lib/shell-word.mjs +13 -0
  63. package/lib/soul-launch-verbs.mjs +153 -0
  64. package/lib/stable-node.mjs +62 -0
  65. package/lib/system-tools.mjs +39 -0
  66. package/lib/teams-verbs.mjs +18 -46
  67. package/lib/tmux-server-scope.mjs +62 -0
  68. package/lib/triggers.mjs +4 -4
  69. package/lib/workspace.mjs +54 -30
  70. package/lib/worktree-hooks.mjs +98 -20
  71. package/lib/worktree.mjs +83 -24
  72. package/package-catalog.json +4 -4
  73. package/package.json +8 -2
  74. package/packages/client/attach-exit.mjs +25 -0
  75. package/packages/client/capability-show-contract.mjs +230 -0
  76. package/packages/client/capability-warnings-contract.mjs +57 -0
  77. package/packages/client/cli-adapter.mjs +561 -0
  78. package/packages/client/cli-environment.mjs +53 -0
  79. package/packages/client/cli-locator.mjs +253 -0
  80. package/packages/client/cli-probe-contract.mjs +47 -0
  81. package/packages/client/client-terms.mjs +60 -0
  82. package/packages/client/deployment-contract.mjs +72 -0
  83. package/packages/client/deployment-data.mjs +483 -0
  84. package/packages/client/deployment-facts.mjs +95 -0
  85. package/packages/client/deployment-label.mjs +76 -0
  86. package/packages/client/deployment-observer.mjs +89 -0
  87. package/packages/client/deployment-panel.mjs +180 -0
  88. package/packages/client/deployment-read-cli.mjs +57 -0
  89. package/packages/client/display-text.mjs +50 -0
  90. package/packages/client/harness-names.mjs +30 -0
  91. package/packages/client/inspect-contract.mjs +62 -0
  92. package/packages/client/instance-acts.mjs +90 -0
  93. package/packages/client/instance-admission.mjs +45 -0
  94. package/packages/client/instance-events-contract.mjs +76 -0
  95. package/packages/client/instance-git-contract.mjs +80 -0
  96. package/packages/client/instance-presentation.mjs +86 -0
  97. package/packages/client/instance-tree.mjs +462 -0
  98. package/packages/client/kernel-environment.mjs +11 -0
  99. package/packages/client/kernel-lines.mjs +31 -0
  100. package/packages/client/kernel-made.mjs +23 -0
  101. package/packages/client/launch-contract.mjs +51 -0
  102. package/packages/client/launch-prompt-outcome.mjs +200 -0
  103. package/packages/client/lifecycle-cli.mjs +61 -0
  104. package/packages/client/lifecycle-contract.mjs +413 -0
  105. package/packages/client/liveness-main.mjs +10 -0
  106. package/packages/client/liveness.mjs +48 -0
  107. package/packages/client/machine-contract.mjs +123 -0
  108. package/packages/client/own-codes.mjs +31 -0
  109. package/packages/client/own-environment.mjs +22 -0
  110. package/packages/client/panel-views.mjs +293 -0
  111. package/packages/client/readiness-contract.mjs +174 -0
  112. package/packages/client/refresh-loop.mjs +52 -0
  113. package/packages/client/remote-address.mjs +151 -0
  114. package/packages/client/remote-identity-memory.mjs +94 -0
  115. package/packages/client/remote-roster.mjs +153 -0
  116. package/packages/client/roster-sections.mjs +80 -0
  117. package/packages/client/session-attach.mjs +175 -0
  118. package/packages/client/spawn-apply-cli.mjs +104 -0
  119. package/packages/client/spawn-apply-contract.mjs +195 -0
  120. package/packages/client/spawn-decision.mjs +46 -0
  121. package/packages/client/spawn-messages.mjs +142 -0
  122. package/packages/client/spawn-preview-cli.mjs +38 -0
  123. package/packages/client/spawn-preview-contract.mjs +318 -0
  124. package/packages/client/team-members.mjs +41 -0
  125. package/packages/client/team-rows.mjs +45 -0
  126. package/packages/client/terminal-contract.mjs +57 -0
  127. package/packages/client/terminal-exec.mjs +21 -0
  128. package/packages/client/tmux-status.mjs +66 -0
  129. package/packages/client/waiting-on-you.mjs +88 -0
  130. package/packages/client/workspace-admission.mjs +45 -0
  131. package/packages/client/workspace-choices.mjs +95 -0
  132. package/packages/client/workspace-cli.mjs +142 -0
  133. package/packages/client/workspace-views.mjs +183 -0
  134. package/packages/record/README.md +21 -0
  135. package/packages/record/bin/setup.mjs +108 -15
  136. package/packages/tui/README.md +64 -0
  137. package/packages/tui/bin/tui.mjs +7 -0
  138. package/packages/tui/lib/actions.mjs +44 -0
  139. package/packages/tui/lib/client.mjs +35 -0
  140. package/packages/tui/lib/config.mjs +151 -0
  141. package/packages/tui/lib/main.mjs +176 -0
  142. package/packages/tui/lib/model.mjs +392 -0
  143. package/packages/tui/lib/read.mjs +473 -0
  144. package/packages/tui/lib/store.mjs +364 -0
  145. package/packages/tui/lib/term/keys.mjs +367 -0
  146. package/packages/tui/lib/term/screen.mjs +134 -0
  147. package/packages/tui/lib/term/style.mjs +43 -0
  148. package/packages/tui/lib/term/text.mjs +109 -0
  149. package/packages/tui/lib/term/tty.mjs +178 -0
  150. package/packages/tui/lib/term/width.mjs +124 -0
  151. package/packages/tui/lib/views/detail.mjs +46 -0
  152. package/packages/tui/lib/views/frame.mjs +256 -0
  153. package/packages/tui/lib/views/help.mjs +140 -0
  154. package/packages/tui/lib/views/instances.mjs +137 -0
  155. package/packages/tui/lib/views/scroll.mjs +19 -0
  156. package/packages/tui/lib/views/switcher.mjs +97 -0
  157. package/packages/tui/package.json +8 -0
  158. package/skills/oats-getting-started/SKILL.md +30 -23
  159. package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-05-channel-seeded.txt +0 -35
  160. package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-06-first-after-channel.txt +0 -35
  161. package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-07-after-channel-200ms.txt +0 -35
  162. package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/frame-08-installed-after-channel-200ms.txt +0 -35
  163. package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/manifest.json +0 -77
  164. package/lib/launch-prompt-fixtures/claude-2.1.289-darwin-arm64/max-bypass-source.json +0 -88
  165. package/lib/launch-prompt-fixtures/structural-completion.json +0 -205
  166. package/lib/launch-prompt-policy.mjs +0 -87
@@ -0,0 +1,178 @@
1
+ // The guard: everything the TUI changes in the terminal, and the promise that it is put back.
2
+ // With term/screen.mjs it is the only module that produces an ESC byte. docs/tui.md lists the
3
+ // changes for operators; ENTER and LEAVE below are that list, and nothing else is ever switched on:
4
+ // no mouse or focus reporting, no keyboard protocol, no keypad or cursor-key mode, no title, no
5
+ // clipboard, no bell, no query that expects a reply.
6
+ //
7
+ // Handing the terminal to someone else (the shell at a suspend; a viewer in later versions) is
8
+ // leave() and enter(), and only that pair.
9
+
10
+ const mode = (number, on) => `\x1b[?${number}${on ? "h" : "l"}`;
11
+ /** After raw mode: the alternate screen, the cursor hidden, autowrap off, bracketed paste on.
12
+ * Autowrap is off so no row wraps where the terminal and width.mjs disagree about a character (a
13
+ * wrap on the last row would scroll the screen). Bracketed paste is on so pasted text arrives
14
+ * marked as a paste, not as keys. */
15
+ export const ENTER = mode(1049, true) + mode(25, false) + mode(7, false) + mode(2004, true);
16
+ /** The reverse, with the style reset; then raw mode off. */
17
+ export const LEAVE = mode(2004, false) + mode(7, true) + "\x1b[0m" + mode(25, true) + mode(1049, false);
18
+
19
+ /** 128 + the signal's number, as a shell reports a process the signal ended. */
20
+ export const SIGNAL_STATUS = Object.freeze({ SIGINT: 130, SIGTERM: 143, SIGHUP: 129, SIGQUIT: 131 });
21
+ /** The terminal went away with no signal (stdin ended, a write failed): as SIGHUP. */
22
+ export const TERMINAL_GONE_STATUS = SIGNAL_STATUS.SIGHUP;
23
+ /** How long a suspend waits for the stop before it concludes there was none. */
24
+ const STOP_GRACE_MS = 100;
25
+
26
+ /** A terminal on both ends that can be addressed: no escape byte is ever written to anything else. */
27
+ export function isTerminal({ stdin, stdout, env }) {
28
+ return stdin.isTTY === true && stdout.isTTY === true && typeof env.TERM === "string" && env.TERM !== "" && env.TERM !== "dumb";
29
+ }
30
+
31
+ /** The guard of one run. `frame()` answers the bytes of the newest frame when it is time to write
32
+ * one; `onInput(bytes)`, `onResize()` and `onRedraw()` (the screen must be drawn in full: after a
33
+ * suspend, after SIGCONT) are the events. `done` resolves once, with `{ status, error }`, after the
34
+ * terminal is restored and every listener is removed.
35
+ * Three more, for whoever started work that outlives a frame (the reads of lib/read.mjs), each
36
+ * optional: `onStop()` is called when the process is about to be stopped by its own suspend, after
37
+ * the terminal is handed back and before the signal; `onResume(asked)` when it runs again, `asked`
38
+ * true after its own suspend and false when it was stopped and continued from outside; `onEnd()`
39
+ * once on every way out, after the terminal is restored and before `done` resolves. */
40
+ export function createGuard({ stdin, stdout, proc, frame, onInput, onResize, onRedraw, onStop = null, onResume = null, onEnd = null, setTimer = setTimeout, clearTimer = clearTimeout }) {
41
+ let entered = false, raw = false, modes = false;
42
+ let suspended = false, stopTimer = null;
43
+ let over = false, blocked = false, stale = false;
44
+ let settle;
45
+ const done = new Promise((resolve) => { settle = resolve; });
46
+ const listeners = [];
47
+ const on = (emitter, name, listener) => { emitter.on(name, listener); listeners.push([emitter, name, listener]); };
48
+ /** A terminal that is gone cannot be restored, and saying so helps nobody. */
49
+ const quietly = (act) => { try { act(); } catch { /* gone */ } };
50
+
51
+ /** Raw mode, then the modes. Each step is recorded before it is taken, so leave() undoes exactly
52
+ * what was done, whenever it is called. */
53
+ function enter() {
54
+ if (over || entered) return;
55
+ entered = true;
56
+ raw = true;
57
+ stdin.setRawMode(true);
58
+ if (!entered) return; // left while entering: nothing more is switched on
59
+ modes = true;
60
+ stdout.write(ENTER);
61
+ }
62
+ /** Put the terminal back. Idempotent; never throws. */
63
+ function leave() {
64
+ if (!entered) return;
65
+ entered = false;
66
+ if (modes) { modes = false; quietly(() => stdout.write(LEAVE)); }
67
+ if (raw) { raw = false; quietly(() => stdin.setRawMode(false)); }
68
+ }
69
+
70
+ /** The end of the run, by any way out: restore, stop listening, report once. */
71
+ function finish(status, error) {
72
+ if (over) return;
73
+ over = true;
74
+ leave();
75
+ // What it throws must not keep the run from ending, nor replace the status it ends with.
76
+ if (onEnd) quietly(onEnd);
77
+ if (stopTimer !== null) { clearTimer(stopTimer); stopTimer = null; }
78
+ for (const [emitter, name, listener] of listeners) emitter.removeListener(name, listener);
79
+ proc.removeListener("SIGTSTP", suspend);
80
+ quietly(() => stdin.pause());
81
+ settle({ status, error });
82
+ }
83
+
84
+ /** Run one of the loop's own steps. What it throws ends the run as an uncaught error would,
85
+ * without waiting for the process to say so. */
86
+ function attempt(step) {
87
+ try { step(); } catch (error) { finish(1, error); }
88
+ }
89
+
90
+ /** One write per frame. While the last write has not drained nothing is queued: the newest frame
91
+ * is made when it has. */
92
+ function draw() {
93
+ if (!entered || over) return;
94
+ if (blocked) { stale = true; return; }
95
+ const bytes = frame();
96
+ if (bytes && stdout.write(bytes) === false) blocked = true;
97
+ }
98
+ function drained() {
99
+ blocked = false;
100
+ if (stale) { stale = false; attempt(draw); }
101
+ }
102
+
103
+ /** Ctrl+Z, or SIGTSTP from outside: hand the terminal back, then stop as a cooked-mode program is
104
+ * stopped. In raw mode the terminal sends the byte, not the signal, so the TUI sends what the
105
+ * terminal would have: SIGTSTP to the whole foreground process group. A wrapper that did not
106
+ * exec (`sh -c`, `npx`) stops with it, and the shell sees a stopped job. */
107
+ function suspend() {
108
+ if (!entered || over) return;
109
+ leave();
110
+ if (onStop) { attempt(onStop); if (over) return; }
111
+ suspended = true;
112
+ proc.removeListener("SIGTSTP", suspend); // the default action stops the process
113
+ quietly(() => proc.kill(0, "SIGTSTP"));
114
+ // Stopped, this timer fires only once the process is continued. Not stopped (SIGTSTP ignored,
115
+ // an orphaned process group), nothing would ever send SIGCONT: it brings the screen back.
116
+ stopTimer = setTimer(resume, STOP_GRACE_MS);
117
+ }
118
+ function resume() {
119
+ if (!suspended || over) return;
120
+ suspended = false;
121
+ if (stopTimer !== null) { clearTimer(stopTimer); stopTimer = null; }
122
+ proc.on("SIGTSTP", suspend);
123
+ try { enter(); } catch { return finish(TERMINAL_GONE_STATUS); }
124
+ if (onResume) attempt(() => onResume(true));
125
+ attempt(onRedraw);
126
+ }
127
+ /** Take the terminal again where it may no longer be as enter() left it: something outside the
128
+ * program reset it (a shell while the process was stopped, a `reset` typed elsewhere, the
129
+ * multiplexer). Node does nothing when asked for the raw mode it believes it is in, so raw goes
130
+ * off and on; then the modes, then a full redraw. This is what Ctrl+L asks for: a redraw that
131
+ * left bracketed paste off would let a paste act as keys.
132
+ * The modes are written as LEAVE and then ENTER, in one write: the pair a suspend and a resume
133
+ * write. Entering the alternate screen also saves the cursor, and a terminal that is still on
134
+ * it may take a second entry as a new save, over the shell's position: the prompt would then
135
+ * land on the wrong row at the end. Leaving first puts back the cursor the first entry saved,
136
+ * so the second saves the same one. On a terminal that was reset, the leave changes nothing. */
137
+ function reassert() {
138
+ if (!entered || over) return;
139
+ quietly(() => { stdin.setRawMode(false); stdin.setRawMode(true); });
140
+ quietly(() => stdout.write(LEAVE + ENTER));
141
+ attempt(onRedraw);
142
+ }
143
+ /** SIGCONT. After our own suspend: come back. Otherwise the process was stopped and continued
144
+ * from outside while it held the terminal. */
145
+ function continued() {
146
+ if (over) return;
147
+ if (suspended) return resume();
148
+ if (onResume && entered) { attempt(() => onResume(false)); if (over) return; }
149
+ reassert();
150
+ }
151
+
152
+ /** Every way out is registered before the terminal is touched; then enter. A signal cannot land
153
+ * inside enter(), which is synchronous, and one that lands after it finds its listener. */
154
+ function start() {
155
+ for (const [signal, status] of Object.entries(SIGNAL_STATUS)) on(proc, signal, () => finish(status));
156
+ on(proc, "SIGCONT", continued);
157
+ proc.on("SIGTSTP", suspend);
158
+ on(proc, "uncaughtException", (error) => finish(1, error));
159
+ on(proc, "unhandledRejection", (reason) => finish(1, reason));
160
+ on(proc, "exit", () => { leave(); if (onEnd) quietly(onEnd); }); // the last resort: a process.exit() nobody expected
161
+ // A dead terminal answers a write or a read with an error event. These two listeners are never
162
+ // removed: the write that restores the terminal can fail after the run is over, and an error
163
+ // event nobody hears is an uncaught exception, which would turn the status into 1.
164
+ for (const stream of [stdin, stdout]) stream.on("error", () => finish(TERMINAL_GONE_STATUS));
165
+ on(stdin, "end", () => finish(TERMINAL_GONE_STATUS));
166
+ on(stdin, "close", () => finish(TERMINAL_GONE_STATUS));
167
+ on(stdin, "data", (bytes) => { if (entered) attempt(() => onInput(bytes)); });
168
+ on(stdout, "resize", () => { if (entered) attempt(onResize); });
169
+ on(stdout, "drain", drained);
170
+ try { enter(); } catch (error) { return finish(1, error); }
171
+ if (!over) stdin.resume();
172
+ }
173
+
174
+ /** The terminal's size now; 80x24 when the terminal does not say. */
175
+ const size = () => ({ cols: Number.isInteger(stdout.columns) && stdout.columns > 0 ? stdout.columns : 80, rows: Number.isInteger(stdout.rows) && stdout.rows > 0 ? stdout.rows : 24 });
176
+
177
+ return { start, enter, leave, finish, suspend, reassert, attempt, draw, size, done, get entered() { return entered; } };
178
+ }
@@ -0,0 +1,124 @@
1
+ /** Terminal cell widths: how many cells a grapheme takes when `oats tui` writes it.
2
+ * Pure: no IO and no imports, only `Intl.Segmenter`, Unicode property escapes and
3
+ * one range table. A grapheme is the unit of layout: the terminal is given whole
4
+ * graphemes, each in the one or two cells this module says it takes. */
5
+
6
+ /** Longest grapheme written as itself, in UTF-16 units. The longest emoji sequences
7
+ * stay well under it; anything longer is a stack of marks on one base, and is replaced. */
8
+ export const MAX_GRAPHEME_UNITS = 32;
9
+ /** What stands in for a grapheme that must not reach the terminal. One cell. */
10
+ export const REPLACEMENT = "\uFFFD";
11
+
12
+ /** East Asian Wide (W) and Fullwidth (F) code points, as sorted, non-touching
13
+ * `[first, last]` pairs. Taken from Unicode 16.0 EastAsianWidth.txt and deliberately
14
+ * coarse: each pair is a whole block or run of blocks, so an unassigned code point
15
+ * inside one counts wide, as the standard says of the CJK blocks. No assigned
16
+ * narrow code point of 16.0 is inside a pair.
17
+ * Emoji are not decided by this table but by the Emoji_Presentation property of
18
+ * the running Node's ICU, which follows new emoji without a table change. */
19
+ export const WIDE_RANGES = Object.freeze([
20
+ [0x1100, 0x115f], // Hangul Jamo leading consonants
21
+ [0x2329, 0x232a], // angle brackets
22
+ [0x2630, 0x2637], // Yijing trigrams
23
+ [0x268a, 0x268f], // Yijing monograms and digrams
24
+ [0x2e80, 0x303e], // CJK radicals, Kangxi, description characters, CJK symbols (not U+303F)
25
+ [0x3041, 0x3247], // kana, Bopomofo, Hangul compatibility Jamo, Kanbun, strokes, enclosed CJK
26
+ [0x3250, 0xa4cf], // enclosed CJK, CJK compatibility, Extension A, hexagrams, ideographs, Yi
27
+ [0xa960, 0xa97f], // Hangul Jamo Extended-A
28
+ [0xac00, 0xd7a3], // Hangul syllables
29
+ [0xf900, 0xfaff], // CJK compatibility ideographs
30
+ [0xfe10, 0xfe19], // vertical forms
31
+ [0xfe30, 0xfe6f], // CJK compatibility forms, small form variants
32
+ [0xff01, 0xff60], // fullwidth forms
33
+ [0xffe0, 0xffe6], // fullwidth signs
34
+ [0x16fe0, 0x18d7f], // ideographic symbols and punctuation, Tangut, Khitan small script
35
+ [0x1aff0, 0x1b2ff], // kana extended and supplement, small kana, Nushu
36
+ [0x1d300, 0x1d376], // Tai Xuan Jing symbols, counting rod numerals
37
+ [0x1f200, 0x1f2ff], // enclosed ideographic supplement
38
+ [0x20000, 0x2fffd], // supplementary ideographic plane
39
+ [0x30000, 0x3fffd], // tertiary ideographic plane
40
+ ].map(Object.freeze));
41
+
42
+ const SEGMENTER = new Intl.Segmenter(undefined, { granularity: "grapheme" });
43
+
44
+ const PRINTABLE_ASCII = /^[\x20-\x7e]*$/;
45
+ /** Never written: C0, DEL and C1 controls (Cc) drive the terminal, a lone surrogate
46
+ * (Cs) is ill-formed, and terminals disagree on what the line and paragraph
47
+ * separators (Zl, Zp) do. With the `u` flag a paired surrogate is not Cs. */
48
+ const UNWRITABLE = /[\p{Cc}\p{Cs}\p{Zl}\p{Zp}]/u;
49
+ /** Only non-spacing and enclosing marks and format characters: nothing to draw on
50
+ * its own. Cf covers ZWJ, the direction marks, the soft hyphen and U+200B, U+2060,
51
+ * U+FEFF; the variation selectors are Mn. Spacing marks (Mc) take a cell. */
52
+ const ZERO_WIDTH = /^[\p{Mn}\p{Me}\p{Cf}]+$/u;
53
+ /** Drawn as emoji by default. A regional indicator is one, so a flag needs no rule. */
54
+ const EMOJI_PRESENTATION = /^\p{Emoji_Presentation}/u;
55
+ /** A text-presentation emoji turned into an emoji: by U+FE0F, by a skin tone on a
56
+ * base that takes one, or by a ZWJ join. A digit, `#` or `*` is an Emoji code point
57
+ * too, and U+FE0F alone does not widen it. */
58
+ const EMOJI_SEQUENCE = /(?![#*0-9])\p{Emoji}\uFE0F|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}|\p{Extended_Pictographic}\u200D\p{Extended_Pictographic}/u;
59
+ /** A digit, `#` or `*` is an emoji only as a whole keycap: base, U+FE0F, U+20E3. */
60
+ const KEYCAP = /^[#*0-9]\uFE0F\u20E3/;
61
+
62
+ function isWide(codePoint) {
63
+ if (codePoint < WIDE_RANGES[0][0]) return false;
64
+ let low = 0;
65
+ let high = WIDE_RANGES.length - 1;
66
+ while (low <= high) {
67
+ const middle = (low + high) >> 1;
68
+ const [first, last] = WIDE_RANGES[middle];
69
+ if (codePoint < first) high = middle - 1;
70
+ else if (codePoint > last) low = middle + 1;
71
+ else return true;
72
+ }
73
+ return false;
74
+ }
75
+
76
+ /** 0, 1 or 2 cells, or -1 for a grapheme that is replaced. The order is the rule:
77
+ * replaced before zero-width, so an endless run of marks is not measured, and
78
+ * zero-width before wide, so a lone wide combining mark (U+3099) takes no cell. */
79
+ function measure(grapheme) {
80
+ if (grapheme.length === 1) {
81
+ const unit = grapheme.charCodeAt(0);
82
+ if (unit >= 0x20 && unit <= 0x7e) return 1;
83
+ }
84
+ if (grapheme.length > MAX_GRAPHEME_UNITS || UNWRITABLE.test(grapheme)) return -1;
85
+ if (grapheme === "") return 0;
86
+ if (ZERO_WIDTH.test(grapheme)) return 0;
87
+ if (isWide(grapheme.codePointAt(0))) return 2;
88
+ if (EMOJI_PRESENTATION.test(grapheme) || EMOJI_SEQUENCE.test(grapheme) || KEYCAP.test(grapheme)) return 2;
89
+ return 1;
90
+ }
91
+
92
+ /** Cells one grapheme takes: 0, 1 or 2. Decided by its first code point, or by its
93
+ * emoji presentation; East Asian Ambiguous counts 1. A grapheme `cells()` replaces
94
+ * (a control, a lone surrogate, an over-long one) measures 1, the cell of its
95
+ * REPLACEMENT. */
96
+ export function graphemeWidth(grapheme) {
97
+ const width = measure(grapheme);
98
+ return width < 0 ? 1 : width;
99
+ }
100
+
101
+ /** The cells of a text: its graphemes in order, each `{ text, width }` with width 1
102
+ * or 2. A zero-width grapheme standing alone is dropped: it takes no cell and is not
103
+ * written. A grapheme that must not be written becomes one REPLACEMENT cell. */
104
+ export function cells(text) {
105
+ const out = [];
106
+ if (PRINTABLE_ASCII.test(text)) {
107
+ for (let index = 0; index < text.length; index++) out.push({ text: text[index], width: 1 });
108
+ return out;
109
+ }
110
+ for (const { segment } of SEGMENTER.segment(text)) {
111
+ const width = measure(segment);
112
+ if (width < 0) out.push({ text: REPLACEMENT, width: 1 });
113
+ else if (width > 0) out.push({ text: segment, width });
114
+ }
115
+ return out;
116
+ }
117
+
118
+ /** Total cells of a text: the sum over `cells(text)`. */
119
+ export function textWidth(text) {
120
+ if (PRINTABLE_ASCII.test(text)) return text.length;
121
+ let total = 0;
122
+ for (const cell of cells(text)) total += cell.width;
123
+ return total;
124
+ }
@@ -0,0 +1,46 @@
1
+ // The detail of the selected instance: (model, pane) -> rows of spans. Pure: no IO, no clock, no
2
+ // escape byte. A label of the TUI's own and a value per line; every value is text the TUI did not
3
+ // write (a kernel's field, a shared sentence) and goes through shown(), cut or wrapped by cells.
4
+ import { lit, shown, shownEnd, shownLines } from "../term/text.mjs";
5
+ import { style } from "../term/style.mjs";
6
+ import { cutNote } from "./instances.mjs";
7
+ import { windowOf } from "./scroll.mjs";
8
+
9
+ const BOLD = style({ bold: true });
10
+ const DIM = style({ dim: true });
11
+ /** The title and the labels start here: the first cell holds the mark of the pane with the focus. */
12
+ const LEFT = 2;
13
+ /** The values start here: the longest label, `harness`, and a gap. */
14
+ const VALUE = LEFT + 9;
15
+ /** The most rows one wrapped value takes. */
16
+ const WRAP_ROWS = 6;
17
+
18
+ /** Every row of the detail for a pane `cols` wide, before it is scrolled: the title, then the
19
+ * facts. A sentence is wrapped onto rows of its own under its label; a path is read from its
20
+ * end. */
21
+ export function detailRows(m, cols) {
22
+ if (!m.detail) return [];
23
+ const room = Math.max(0, cols - VALUE);
24
+ const rows = [[{ col: LEFT, text: shown(m.detail.title), style: BOLD, width: Math.max(0, cols - LEFT) }]];
25
+ for (const fact of m.detail.facts) {
26
+ const label = fact.label ? [{ col: LEFT, text: lit(fact.label), style: DIM, width: VALUE - LEFT - 1 }] : [];
27
+ if (room < 1) { rows.push(label); continue; }
28
+ if (fact.form === "wrap") shownLines(fact.value, room, WRAP_ROWS, { ascii: m.ascii }).forEach((line, i) => rows.push([...(i === 0 ? label : []), { col: VALUE, text: line, width: room }]));
29
+ else rows.push([...label, { col: VALUE, text: fact.form === "end" ? shownEnd(fact.value, room, { ascii: m.ascii }) : shown(fact.value), width: room }]);
30
+ }
31
+ return rows;
32
+ }
33
+
34
+ /** `{ rows, extent }`: `size.rows` rows for a pane `size.cols` wide, scrolled to the model's
35
+ * `detailTop`, and how many rows the whole detail has. The pane that has the focus says so with
36
+ * `>` beside the title, never by an attribute alone. */
37
+ export function detail(m, size) {
38
+ const all = detailRows(m, size.cols);
39
+ const rows = Array.from({ length: size.rows }, () => []);
40
+ const win = windowOf({ top: m.detailTop, count: all.length, height: size.rows });
41
+ all.slice(win.top, win.top + win.size).forEach((spans, i) => { rows[i] = spans; });
42
+ const note = cutNote(win.above, win.below);
43
+ if (note && size.rows > 0) rows[size.rows - 1] = [{ col: LEFT, text: lit(note), style: DIM, width: Math.max(0, size.cols - LEFT) }];
44
+ if (m.focus === "detail" && size.rows > 0 && all.length) rows[0] = [{ col: 0, text: lit(">"), style: BOLD, width: 1 }, ...rows[0]];
45
+ return { rows, extent: all.length };
46
+ }
@@ -0,0 +1,256 @@
1
+ // The frame: (model, size) -> the rows of the whole screen. Pure: no IO, no clock, no escape
2
+ // byte. It places the views: the header, the list of instances and the detail beside it (or as a
3
+ // page of its own on a narrow terminal), the switcher of workspaces over the whole body, the
4
+ // help, and the footer. The TUI's own words are lit(); everything else is shown(). Meaning never
5
+ // rests on colour alone: what is dim or bold also says what it is in words or by a mark.
6
+ import { keyLabel } from "../actions.mjs";
7
+ import { lit, shown, shownLines } from "../term/text.mjs";
8
+ import { style } from "../term/style.mjs";
9
+ import { detail } from "./detail.mjs";
10
+ import { help, keyText } from "./help.mjs";
11
+ import { instances, measured } from "./instances.mjs";
12
+ import { switcher } from "./switcher.mjs";
13
+
14
+ /** The frame is drawn from this size up (docs/tui.md); the design size is 80x24. */
15
+ export const MIN_SIZE = Object.freeze({ cols: 60, rows: 15 });
16
+ /** From this width up the detail stands beside the list; under it, it is a page of its own. */
17
+ export const WIDE = 80;
18
+ /** The views, named so the frame has its shape. Two are dim: they cannot be opened yet, and the
19
+ * help says what to run instead. */
20
+ const VIEWS = Object.freeze([Object.freeze({ name: "1 Instances", open: true }), Object.freeze({ name: "2 Souls", open: false }), Object.freeze({ name: "3 Capabilities", open: false })]);
21
+ const GAP = 3;
22
+ /** One cell of margin on each side of the header and the footer. */
23
+ const MARGIN = 1;
24
+ /** The longest run one lit() holds with room to spare: the display filter bounds a line, and a
25
+ * terminal can be wider than that bound. */
26
+ const RUN = 500;
27
+ /** The rows a reason may take above the list: a quarter of the body, at least one, at most this. */
28
+ const REASON_ROWS = 4;
29
+ /** The rows a deployment's note may take above the list. */
30
+ const NOTE_ROWS = 2;
31
+ /** The cells a kept filter takes in the footer. */
32
+ const FILTER_COLS = 24;
33
+ /** What the header holds in the workspace's place while the switcher is shown. */
34
+ const WORKSPACES = "workspaces";
35
+ /** The TUI's word before the one machine of a view that holds no deployment of this machine. */
36
+ const ON = "on";
37
+ /** The cells the workspace's name keeps (all of them, when it is shorter) before the header says
38
+ * how many other machines it is on: under that the name comes first. */
39
+ const NAME_MIN = 8;
40
+
41
+ const BOLD = style({ bold: true });
42
+ const DIM = style({ dim: true });
43
+
44
+ const clamp = (n, low, high) => Math.min(Math.max(n, low), high);
45
+ const tooSmall = (size) => size.cols < MIN_SIZE.cols || size.rows < MIN_SIZE.rows;
46
+
47
+ /** One row saying so, with the size found and the size needed. Short, and the sizes early: on a
48
+ * terminal this small the screen clips the end of the row. */
49
+ function tooSmallRows(size) {
50
+ const rows = Array.from({ length: size.rows }, () => []);
51
+ if (size.rows > 0) rows[0] = [{ col: 0, text: lit(`Terminal too small: ${size.cols}x${size.rows}, oats tui needs ${MIN_SIZE.cols}x${MIN_SIZE.rows}.`) }];
52
+ return rows;
53
+ }
54
+
55
+ /** A horizontal rule over the whole width, with a joint where the panes' rule meets it. */
56
+ function rule(cols, ascii, joint = null) {
57
+ const spans = [], dash = ascii ? "-" : "─";
58
+ for (let col = 0; col < cols; col += RUN) spans.push({ col, text: lit(dash.repeat(Math.min(RUN, cols - col))), style: DIM });
59
+ if (joint) spans.push({ col: joint.col, text: lit(ascii ? "+" : joint.up ? "┴" : "┬"), style: DIM, width: 1 });
60
+ return spans;
61
+ }
62
+
63
+ /** Where everything stands for a size: the body under the header, the reason of a deployment
64
+ * that is not live and the note of the one deployment of a view without headings (both wrapped
65
+ * here, since their rows take room from the panes), and the panes. `notice` and `note` are the
66
+ * model's (lib/model.mjs): the main loop asks for the layout first, because the model's window
67
+ * is as tall, and the sentences in its list as wide, as the list pane this gives. The answer's
68
+ * `note` is the note's rows. */
69
+ export function layout(notice, size, { observed = true, note = null, ascii = false } = {}) {
70
+ const body = { top: 3, rows: Math.max(0, size.rows - 5) };
71
+ const wide = size.cols >= WIDE;
72
+ const listCols = wide ? clamp(Math.floor(size.cols * 0.48), 36, 60) : size.cols;
73
+ const across = Math.max(1, size.cols - 2 * MARGIN);
74
+ const reason = notice ? shownLines(notice.reason, across, clamp(Math.floor(body.rows / 4), 1, REASON_ROWS), { ascii }) : [];
75
+ const noted = note ? shownLines(note, across, NOTE_ROWS, { ascii }) : [];
76
+ // The state and its reason, then the note, stand above the panes, over the whole width; a rule
77
+ // closes them when instances follow.
78
+ const said = (notice ? 1 + reason.length : 0) + noted.length;
79
+ const above = said ? Math.min(body.rows, said + (observed ? 1 : 0)) : 0;
80
+ return { body, wide, listCols, reason, note: noted, above, panes: { top: body.top + above, rows: Math.max(0, body.rows - above) }, page: Math.max(0, body.rows - above) };
81
+ }
82
+
83
+ /** The header's middle, from `col` on in `room` cells: the workspace's name and, when the view
84
+ * holds other machines, what says so, in the TUI's words and dim:
85
+ * `+N machine(s)` beside a deployment of this machine;
86
+ * `on <machine>` the one machine of a view that holds no deployment of this machine (no
87
+ * heading names it there);
88
+ * `N machines` two or more of them and no deployment of this machine.
89
+ * Whether a deployment is this machine's is the shared entries' word (the model's `here`), and
90
+ * the machine's name is theirs. What stands after the name gives way before the name is cut
91
+ * short of NAME_MIN cells, and a machine's name is cut before the workspace's. While the
92
+ * switcher is shown no workspace is named: the header says what is listed instead. */
93
+ function nameSpans(m, col, room) {
94
+ if (room <= 0) return [];
95
+ if (m.under === "switcher") return [{ col, text: lit(WORKSPACES), width: room }];
96
+ const name = measured(m.workspace), alone = [{ col, text: name.text, width: room }];
97
+ if (!(m.machines > 0)) return alone;
98
+ const least = Math.min(name.width, NAME_MIN);
99
+ // Two cells between the name and what follows it, as everywhere in the header.
100
+ const after = (width) => col + width + (width ? 2 : 0);
101
+ if (!m.here && m.machine !== null) {
102
+ const where = measured(m.machine), left = room - 2 - ON.length - 1;
103
+ // The machine's name is cut first, down to the cells that still say something: the
104
+ // workspace's name has what that leaves.
105
+ const kept = Math.min(where.width, NAME_MIN);
106
+ if (left - least < kept) return alone;
107
+ const width = Math.min(name.width, left - kept), at = after(width);
108
+ return [...(width ? [{ col, text: name.text, width }] : []), { col: at, text: lit(ON), style: DIM, width: ON.length }, { col: at + ON.length + 1, text: where.text, style: DIM, width: Math.min(where.width, left - width) }];
109
+ }
110
+ const more = `${m.here ? "+" : ""}${m.machines} ${m.machines === 1 ? "machine" : "machines"}`;
111
+ const left = room - 2 - more.length;
112
+ if (left < least) return alone;
113
+ const width = Math.min(name.width, left);
114
+ return [...(width ? [{ col, text: name.text, width }] : []), { col: after(width), text: lit(more), style: DIM, width: more.length }];
115
+ }
116
+
117
+ /** The header's counts, right aligned, each a number and a word. When they do not all fit, the
118
+ * ones from the shared count are given up from the end, never the two the TUI adds. */
119
+ function countSpans(counts, cols) {
120
+ const texts = counts.map((count) => ({ ...count, text: `${count.n} ${count.word}` }));
121
+ const width = (list) => list.reduce((sum, c) => sum + c.text.length, 0) + Math.max(0, list.length - 1) * 2;
122
+ const room = cols - 2 * MARGIN - "oats".length - 2;
123
+ let kept = texts;
124
+ while (width(kept) > room && kept.some((c) => c.shared)) kept = kept.filter((c, i) => i !== kept.findLastIndex((k) => k.shared));
125
+ const spans = [];
126
+ let col = cols - MARGIN - width(kept);
127
+ for (const count of kept) { if (col >= 0) spans.push({ col, text: count.shared ? shown(count.text) : lit(count.text), width: count.text.length }); col += count.text.length + 2; }
128
+ return { spans, start: cols - MARGIN - width(kept) };
129
+ }
130
+
131
+ /** The footer: the filter field while it is open; else the actions that apply now, read from the
132
+ * effective table, as many as fit, `help` and `quit` last and always: their room is set aside
133
+ * first, and a kept filter and the other hints take what is left. A hint that does not fit ends
134
+ * the row's hints, so the order they are tried in is the order they are given up from the end:
135
+ * `workspaces` stands after `refresh`, and a row too narrow for both keeps `refresh`. The
136
+ * switcher has a filter of its own, drawn as the list's. A key's label is the user's
137
+ * (views/help.mjs keyText); everything is placed by cells. */
138
+ function footer(m, cols) {
139
+ const action = (id) => m.actions.find((a) => a.id === id && a.keys.length);
140
+ /** A hint: a key and what it does. */
141
+ const made = (key, word) => ({ key, word, width: key.width + 1 + word.length });
142
+ const hint = (id, label) => { const a = action(id); return a ? made(keyText(keyLabel(a.keys[0])), label ?? a.label) : null; };
143
+ const edge = cols - MARGIN; // nothing stands at or past it
144
+ /** A hint's spans at `col`, never past the edge. */
145
+ const put = (h, col, look) => [
146
+ { col, text: h.key.text, width: Math.max(0, Math.min(h.key.width, edge - col)), ...look },
147
+ { col: col + h.key.width + 1, text: lit(h.word), width: Math.max(0, Math.min(h.word.length, edge - col - h.key.width - 1)), ...look },
148
+ ].filter((span) => span.width > 0);
149
+ const span = (hints) => hints.reduce((sum, h) => sum + h.width, 0) + Math.max(0, hints.length - 1) * GAP;
150
+
151
+ if (m.view !== "help" && m.filter.editing) {
152
+ const hints = [made({ text: lit("Enter"), width: "Enter".length }, "keep"), hint("close", "clear")].filter(Boolean);
153
+ const spans = [{ col: MARGIN, text: lit("/"), style: BOLD, width: 1 }, { col: MARGIN + 1, text: shown(m.filter.query), width: Math.max(0, edge - span(hints) - GAP - MARGIN - 1) }];
154
+ let col = Math.max(MARGIN + 2, edge - span(hints));
155
+ for (const h of hints) { spans.push(...put(h, col, { style: DIM })); col += h.width + GAP; }
156
+ return spans;
157
+ }
158
+ const ids = m.view === "help" ? ["close"]
159
+ // Esc closes the switcher only onto a view, and there is none before a workspace is opened.
160
+ // A kept filter puts `close` before `refresh`, as in the list: the key that clears it is the hint to keep.
161
+ : m.view === "switcher" ? ["open-workspace", "filter", ...(m.filter.query ? ["close", "refresh"] : ["refresh", ...(m.open ? ["close"] : [])])]
162
+ : m.focus === "detail" ? ["detail", "close", "refresh"]
163
+ : ["filter", "detail", ...(m.filter.query ? ["close"] : []), "refresh", "workspaces"];
164
+ const last = ["help", "quit"].map((id) => hint(id)).filter(Boolean);
165
+ const spans = [];
166
+ let col = MARGIN;
167
+ if (m.view !== "help" && m.filter.query) {
168
+ // The kept filter has a place of its own width, so the hints stand where they always do;
169
+ // it gives way, down to nothing, before `help` and `quit` do.
170
+ const slot = Math.min(FILTER_COLS - GAP, edge - MARGIN - span(last) - (last.length ? GAP : 0));
171
+ if (slot >= 2) {
172
+ spans.push({ col, text: lit("/"), style: BOLD, width: 1 }, { col: col + 1, text: shown(m.filter.query), style: BOLD, width: slot - 1 });
173
+ col += slot + GAP;
174
+ }
175
+ }
176
+ for (const h of ids.map((id) => hint(id)).filter(Boolean)) {
177
+ if (col + h.width + GAP + span(last) > edge) break;
178
+ spans.push(...put(h, col));
179
+ col += h.width + GAP;
180
+ }
181
+ for (const h of last) { spans.push(...put(h, col)); col += h.width + GAP; }
182
+ return spans;
183
+ }
184
+
185
+ /** Shift a pane's rows to its place on the screen. */
186
+ const placed = (spans, col) => spans.map((span) => ({ ...span, col: span.col + col }));
187
+
188
+ /** The whole screen for a model: `{ rows, page, extent, room }`. `page` is the rows of the list
189
+ * pane (of the whole body, for the switcher); `extent` and `room` are how many rows the other
190
+ * scrolling pane (the help, else the detail) holds and shows. The main loop hands the three back
191
+ * with the next key, so the store scrolls by what is on the screen without holding a size. */
192
+ export function frame(m, size) {
193
+ if (tooSmall(size)) return { rows: tooSmallRows(size), page: 1, extent: 0, room: 1 };
194
+ const rows = Array.from({ length: size.rows }, () => []);
195
+ const g = layout(m.notice, size, { observed: m.observed, note: m.note, ascii: m.ascii });
196
+ const { cols } = size;
197
+ // The switcher is no view of the three: while it is shown, or is under the help, none is current.
198
+ const listing = m.under === "switcher";
199
+
200
+ const counts = countSpans(m.counts, cols);
201
+ const nameCol = MARGIN + "oats".length + 2;
202
+ rows[0] = [{ col: MARGIN, text: lit("oats"), style: BOLD }, ...nameSpans(m, nameCol, counts.start - 2 - nameCol), ...counts.spans];
203
+ let col = MARGIN;
204
+ for (const view of VIEWS) { rows[1].push({ col, text: lit(view.name), ...(view.open && !listing ? {} : { style: DIM }), width: view.name.length }); col += view.name.length + GAP; }
205
+ if (m.readAt) { const read = `read ${m.readAt}`; rows[1].push({ col: cols - MARGIN - read.length, text: lit(read), style: DIM, width: read.length }); }
206
+ rows[size.rows - 1] = footer(m, cols);
207
+
208
+ if (m.view === "help") {
209
+ rows[2] = rule(cols, m.ascii);
210
+ rows[size.rows - 2] = rule(cols, m.ascii);
211
+ const drawn = help(m.actions, { cols, rows: g.body.rows }, { top: m.helpTop, ascii: m.ascii });
212
+ drawn.rows.forEach((spans, i) => { rows[g.body.top + i] = spans; });
213
+ return { rows, page: Math.max(1, g.page), extent: drawn.extent, room: g.body.rows };
214
+ }
215
+
216
+ // The switcher takes the whole body, over the whole width: one pane, so no joint in the rules.
217
+ // Nothing beside it scrolls on its own.
218
+ if (listing) {
219
+ rows[2] = rule(cols, m.ascii);
220
+ rows[size.rows - 2] = rule(cols, m.ascii);
221
+ switcher(m, { cols, rows: g.body.rows }).forEach((spans, i) => { rows[g.body.top + i] = spans; });
222
+ return { rows, page: Math.max(1, g.body.rows), extent: 0, room: 1 };
223
+ }
224
+
225
+ // The state of a deployment that is not live, and on rows of its own the reason, which is the
226
+ // shared home's sentence or the kernel's: nothing of the TUI's stands on a reason's row. Then
227
+ // the note of the one deployment of a view without headings, the shared home's sentence too.
228
+ const said = [];
229
+ if (m.notice) {
230
+ const since = m.notice.since ? `since ${m.notice.since}` : null;
231
+ said.push([{ col: MARGIN, text: shown(m.notice.text), style: BOLD, width: Math.max(0, cols - 2 * MARGIN - (since ? since.length + 2 : 0)) }, ...(since ? [{ col: cols - MARGIN - since.length, text: lit(since), style: DIM, width: since.length }] : [])]);
232
+ for (const line of g.reason) said.push([{ col: MARGIN, text: line, width: cols - 2 * MARGIN }]);
233
+ }
234
+ for (const line of g.note) said.push([{ col: MARGIN, text: line, width: cols - 2 * MARGIN }]);
235
+ said.slice(0, g.above).forEach((spans, i) => { rows[g.body.top + i] = spans; });
236
+ const paged = !g.wide && m.focus === "detail" && m.detail;
237
+ // Two panes only over an observed deployment: with no instance there is nothing to put beside the list.
238
+ const split = g.wide && g.panes.rows > 0 && m.observed;
239
+ const joint = split ? { col: g.listCols } : null;
240
+ // The rule that opens the panes: the one under the header, or the one under the reason and the note.
241
+ const opening = m.observed && g.above > 0 ? g.panes.top - 1 : 2;
242
+ rows[2] = rule(cols, m.ascii, opening === 2 ? joint : null);
243
+ if (opening !== 2 && opening < size.rows - 2) rows[opening] = rule(cols, m.ascii, joint);
244
+ rows[size.rows - 2] = rule(cols, m.ascii, joint && { ...joint, up: true });
245
+
246
+ const pane = { cols: g.wide ? g.listCols : cols, rows: g.panes.rows };
247
+ let extent = 0;
248
+ if (!paged) instances(m, pane).forEach((spans, i) => { rows[g.panes.top + i] = spans; });
249
+ if (split || paged) {
250
+ const at = paged ? MARGIN : g.listCols + 2;
251
+ const drawn = detail(m, { cols: Math.max(0, cols - at - MARGIN), rows: g.panes.rows });
252
+ extent = drawn.extent;
253
+ drawn.rows.forEach((spans, i) => { rows[g.panes.top + i] = [...rows[g.panes.top + i], ...(split ? [{ col: g.listCols, text: lit(m.ascii ? "|" : "│"), style: DIM, width: 1 }] : []), ...placed(spans, at)]; });
254
+ }
255
+ return { rows, page: Math.max(1, g.page), extent, room: Math.max(1, g.panes.rows) };
256
+ }