@awebai/oats 0.56.0 → 0.57.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.
@@ -0,0 +1,85 @@
1
+ // The act view: one confirmation of a stop, a retire, a start or a restart, over the list of
2
+ // instances (as the help is). Pure: no IO, no clock, no escape byte. (model, area) -> rows.
3
+ // The content (lib/model.mjs actView) scrolls when it is taller than the area; the buttons keep
4
+ // the area's last row. The TUI's own words are lit(); every shared sentence, the kernel's lines,
5
+ // a name and a path go through shown(). Meaning never rests on colour alone: the button with the
6
+ // focus is drawn between `>` and `<` as well as in reverse.
7
+ import { EMPTY, lit, shown, shownLines, textOf } from "../term/text.mjs";
8
+ import { textWidth } from "../term/width.mjs";
9
+ import { style } from "../term/style.mjs";
10
+ import { partRows } from "./frame.mjs";
11
+ import { cutNote } from "./instances.mjs";
12
+ import { windowOf } from "./scroll.mjs";
13
+
14
+ const LEFT = 2;
15
+ const GAP = 3;
16
+ /** The most rows one line of the content takes. */
17
+ const LINE_ROWS = 12;
18
+ const BOLD = style({ bold: true });
19
+ const DIM = style({ dim: true });
20
+ const FOCUSED = style({ bold: true, reverse: true });
21
+ const LOOKS = Object.freeze({ bold: BOLD, dim: DIM });
22
+
23
+ /** A line's own rows of spans from column 0, in `width` cells. */
24
+ function lineRows(line, width, ascii) {
25
+ const look = LOOKS[line.look];
26
+ const styled = (spans) => (look ? spans.map((span) => ({ ...span, style: look })) : spans);
27
+ if (line.gap) return [[]];
28
+ if (line.said) return partRows(line.said, width, LINE_ROWS, { ascii }).map(styled);
29
+ if (line.own !== undefined) return partRows([{ own: line.own }], width, LINE_ROWS, { ascii }).map(styled);
30
+ if (line.pair) {
31
+ // A state row's label is the shared plan's (a target's name among them), so it is text from
32
+ // outside like its value: filtered, cut to half the width, and measured as it is drawn.
33
+ const [label, value] = line.pair;
34
+ const name = shownLines(label, Math.max(1, Math.floor(width / 2)), 1, { ascii })[0] ?? EMPTY;
35
+ const used = textWidth(textOf(name)), at = used + 2;
36
+ return [[{ col: 0, text: name, style: DIM, width: used }, { col: at, text: shown(value), width: Math.max(0, width - at) }]];
37
+ }
38
+ if (line.choice) {
39
+ const box = line.choice.value ? "[x]" : "[ ]";
40
+ return shownLines(line.choice.sentence, Math.max(1, width - 4), LINE_ROWS, { ascii })
41
+ .map((text, i) => [...(i === 0 ? [{ col: 0, text: lit(box), width: 3 }] : []), { col: 4, text, width: Math.max(0, width - 4) }]);
42
+ }
43
+ // A shared sentence or the kernel's line, with a path after it: one text from outside.
44
+ const text = line.path ? `${line.text ?? ""} ${line.path}` : line.text;
45
+ return shownLines(text, width, LINE_ROWS, { ascii }).map((value) => styled([{ col: 0, text: value, width }]));
46
+ }
47
+
48
+ /** Every row of the content for an area `cols` wide, before it is scrolled: the title, then the lines. */
49
+ export function actRows(m, cols) {
50
+ const width = Math.max(1, cols - 2 * LEFT);
51
+ const t = m.act.title;
52
+ const title = t.said ? partRows(t.said, width, 2, { ascii: m.ascii }) : shownLines(t.text, width, 2, { ascii: m.ascii }).map((text) => [{ col: 0, text, width }]);
53
+ const rows = [...title.map((spans) => spans.map((span) => ({ ...span, style: BOLD }))), []];
54
+ for (const line of m.act.lines) rows.push(...lineRows(line, width, m.ascii));
55
+ return rows.map((spans) => spans.map((span) => ({ ...span, col: span.col + LEFT })));
56
+ }
57
+
58
+ /** The buttons, one per offer of the confirmation and in its order, on one row; the one with the
59
+ * focus between `>` and `<`. */
60
+ function buttonRow(buttons, cols) {
61
+ const spans = [];
62
+ let col = LEFT;
63
+ for (const button of buttons) {
64
+ const label = button.focused ? `> ${button.label} <` : `[ ${button.label} ]`;
65
+ if (col + label.length > cols) break;
66
+ spans.push({ col, text: lit(label), width: label.length, ...(button.focused ? { style: FOCUSED } : {}) });
67
+ col += label.length + GAP;
68
+ }
69
+ return spans;
70
+ }
71
+
72
+ /** `{ rows, extent, room }`: `size.rows` rows for an area `size.cols` wide: the content scrolled
73
+ * to the confirmation's `top`, then an empty row and the buttons on the last row. `extent` and
74
+ * `room` are the content's, for the store's scroll. */
75
+ export function act(m, size) {
76
+ const rows = Array.from({ length: size.rows }, () => []);
77
+ const room = Math.max(0, size.rows - 2);
78
+ const all = actRows(m, size.cols);
79
+ const win = windowOf({ top: m.act.top ?? 0, count: all.length, height: room });
80
+ all.slice(win.top, win.top + win.size).forEach((spans, i) => { rows[i] = spans; });
81
+ const note = cutNote(win.above, win.below);
82
+ if (note && room > 0) rows[room - 1] = [{ col: LEFT, text: lit(note), style: DIM, width: Math.max(0, size.cols - LEFT) }];
83
+ if (size.rows > 0) rows[size.rows - 1] = buttonRow(m.act.buttons, size.cols);
84
+ return { rows, extent: all.length, room: Math.max(1, room) };
85
+ }
@@ -6,6 +6,7 @@
6
6
  import { keyLabel } from "../actions.mjs";
7
7
  import { lit, shown, shownLines } from "../term/text.mjs";
8
8
  import { style } from "../term/style.mjs";
9
+ import { act } from "./act.mjs";
9
10
  import { detail } from "./detail.mjs";
10
11
  import { help, keyText } from "./help.mjs";
11
12
  import { instances, measured } from "./instances.mjs";
@@ -181,13 +182,17 @@ function countSpans(counts, cols) {
181
182
  * first, and a kept filter and the other hints take what is left. The hints stand in the order
182
183
  * given, and when they do not all fit they are given up in an order of their own (`keep`, the
183
184
  * first kept longest), so a hint can stand first and still be given up before another: in the
184
- * list of instances `workspaces` goes first, then `refresh`, the key that clears a kept filter,
185
- * `detail`, `open` and last `filter` (`filter` before `open` while a filter is kept: its own `/`
186
- * stands in the footer then). A row too narrow for the whole of a hint drops it.
185
+ * list of instances the acts go first (`restart`, `start`, `retire`, then `stop`), then
186
+ * `workspaces`, `refresh`, the key that clears a kept filter, `detail`, `open` and last `filter`
187
+ * (`filter` before `open` while a filter is kept: its own `/` stands in the footer then). A row
188
+ * too narrow for the whole of a hint drops it.
187
189
  * `open` stands first while Enter would open the selected agent's terminal, and names the key
188
190
  * that brings the TUI back (tui.json's `open.detachKey`, text from outside); while another
189
- * machine is asked first, the key that gives the open up stands in its place. The switcher has
190
- * a filter of its own, drawn as the list's. A key's label is the user's (views/help.mjs keyText);
191
+ * machine is asked first, the key that gives the open up stands in its place. After it stand
192
+ * the acts whose key opens a confirmation for the selected row now (the model's `actable`). In a
193
+ * confirmation the buttons are on the screen, and the footer says how to work them: the close
194
+ * key with the close button's label, the keys that move, Enter, and `quit`. The switcher has a
195
+ * filter of its own, drawn as the list's. A key's label is the user's (views/help.mjs keyText);
191
196
  * everything is placed by cells. */
192
197
  function footer(m, cols) {
193
198
  const action = (id) => m.actions.find((a) => a.id === id && a.keys.length);
@@ -222,20 +227,38 @@ function footer(m, cols) {
222
227
  const spans = [{ col: 0, text: lit(lead), width: lead.length }, { col: lead.length, text: key.text, width: key.width }, { col: lead.length + key.width + 1, text: lit(tail), width: tail.length }];
223
228
  return made(keyText(keyLabel(a.keys[0])), { spans, width: lead.length + key.width + 1 + tail.length });
224
229
  };
230
+ if (m.view === "act" && m.act) {
231
+ // The confirmation: its buttons are the offers, on the screen; the footer says how to work them.
232
+ const close = action("close"), shut = m.act.buttons.find((button) => button.id === "close");
233
+ const hints = [
234
+ ...(close && shut ? [made(keyText(keyLabel(close.keys[0])), shut.label)] : []),
235
+ ...(m.act.buttons.length > 1 ? [made({ text: lit("Left/Right"), width: "Left/Right".length }, "move")] : []),
236
+ made({ text: lit("Enter"), width: "Enter".length }, "press"),
237
+ ].map(spansOf);
238
+ const quit = hint("quit");
239
+ const all = [...hints, ...(quit ? [spansOf(quit)] : [])];
240
+ const spans = [];
241
+ let col = MARGIN;
242
+ for (const h of all) { if (col + h.width > edge) break; spans.push(...put(h, col)); col += h.width + GAP; }
243
+ return spans;
244
+ }
225
245
  const listing = m.view !== "help" && m.view !== "switcher";
226
246
  // While another machine is asked first, Esc gives the open up, and that is all it does: the
227
247
  // hint stands where `open` stood, is kept as long, and `close` is not listed beside it.
228
248
  const asking = listing && m.opening?.phase === "preflight";
229
249
  // An action with no key (tui.json may unbind one) has no hint: nothing stands first then.
230
250
  const first = (asking ? [["open", hint("close", "stop opening")]] : listing && m.openable ? [["open", opener()]] : []).filter(([, h]) => h);
251
+ // The acts the selected row offers now stand after `open`, and are the first given up.
252
+ const acts = listing && !asking ? (m.actable ?? []).map((verb) => [verb, hint(verb)]).filter(([, h]) => h) : [];
253
+ const ACTS = ["stop", "retire", "start", "restart"];
231
254
  const [ids, keep] = m.view === "help" ? [["close"], ["close"]]
232
255
  // Esc closes the switcher only onto a view, and there is none before a workspace is opened.
233
256
  // A kept filter puts `close` before `refresh`, as in the list: the key that clears it is the hint to keep.
234
257
  : m.view === "switcher" ? [["open", "filter", ...(m.filter.query ? ["close", "refresh"] : ["refresh", ...(m.open ? ["close"] : [])])], null]
235
- : m.focus === "detail" ? [["detail", "close", "refresh"], ["open", "detail", "close", "refresh"]]
258
+ : m.focus === "detail" ? [["detail", "close", "refresh"], ["open", "detail", "close", "refresh", ...ACTS]]
236
259
  // A kept filter shows its own `/` beside the hints: then `open` outlives the `/ filter` hint.
237
- : [["filter", "detail", ...(m.filter.query ? ["close"] : []), "refresh", "workspaces"], [...(m.filter.query ? ["open", "filter"] : ["filter", "open"]), "detail", "close", "refresh", "workspaces"]];
238
- const hints = [...first, ...ids.filter((id) => !(asking && id === "close")).map((id) => [id, hint(id)])].filter(([, h]) => h).map(([id, h]) => [id, spansOf(h)]);
260
+ : [["filter", "detail", ...(m.filter.query ? ["close"] : []), "refresh", "workspaces"], [...(m.filter.query ? ["open", "filter"] : ["filter", "open"]), "detail", "close", "refresh", "workspaces", ...ACTS]];
261
+ const hints = [...first, ...acts, ...ids.filter((id) => !(asking && id === "close")).map((id) => [id, hint(id)])].filter(([, h]) => h).map(([id, h]) => [id, spansOf(h)]);
239
262
  const last = ["help", "quit"].map((id) => hint(id)).filter(Boolean).map(spansOf);
240
263
  const spans = [];
241
264
  let col = MARGIN;
@@ -286,6 +309,13 @@ export function frame(m, size) {
286
309
  if (m.readAt) { const read = `read ${m.readAt}`; rows[1].push({ col: cols - MARGIN - read.length, text: lit(read), style: DIM, width: read.length }); }
287
310
  rows[size.rows - 1] = footer(m, cols);
288
311
 
312
+ if (m.view === "act" && m.act) {
313
+ rows[2] = rule(cols, m.ascii);
314
+ rows[size.rows - 2] = rule(cols, m.ascii);
315
+ const drawn = act(m, { cols, rows: g.body.rows });
316
+ drawn.rows.forEach((spans, i) => { rows[g.body.top + i] = spans; });
317
+ return { rows, page: Math.max(1, g.page), extent: drawn.extent, room: drawn.room };
318
+ }
289
319
  if (m.view === "help") {
290
320
  rows[2] = rule(cols, m.ascii);
291
321
  rows[size.rows - 2] = rule(cols, m.ascii);
@@ -30,9 +30,7 @@ export function keyText(label) {
30
30
  * removes a line when it adds the act. */
31
31
  export const NOT_YET = Object.freeze([
32
32
  Object.freeze({ what: "open an agent in its own tmux window", command: "oats session attach --home <home>" }),
33
- Object.freeze({ what: "stop an agent", command: "oats instance stop <instance>" }),
34
- Object.freeze({ what: "start or restart an agent", command: "oats session start --home <home>" }),
35
- Object.freeze({ what: "retire an agent", command: "oats retire <instance>" }),
33
+ Object.freeze({ what: "start with another harness or model", command: "oats session start --home <home>" }),
36
34
  Object.freeze({ what: "add a machine to this workspace", command: "oats server connect <id> --ssh <alias>" }),
37
35
  Object.freeze({ what: "check a machine", command: "oats server check <id>" }),
38
36
  Object.freeze({ what: "remove a machine", command: "oats server remove <id>" }),
@@ -101,6 +99,13 @@ function openRows(detachKey, room) {
101
99
  ...OPEN_RULES.flatMap((sentence) => flow(words(sentence), room).map((text) => [{ col: 0, text: lit(text) }])),
102
100
  ];
103
101
  }
102
+ /** The TUI's own sentences under the line of the last act: how a confirmation is worked, and that
103
+ * what it sent is never ended by the TUI. */
104
+ export const ACT_RULES = Object.freeze([
105
+ "Each act opens a confirmation with Cancel chosen: move to the act with Left/Right or Tab, then press Enter.",
106
+ "Esc closes a confirmation; an act it sent goes on, also after oats tui quits.",
107
+ ]);
108
+ const actRows = (room) => ACT_RULES.flatMap((sentence) => flow(words(sentence), room).map((text) => [{ col: 0, text: lit(text) }]));
104
109
  const heading = (text) => [{ col: INDENT, text: lit(text), style: TITLE }];
105
110
  /** Sentences, each from the left margin on as many rows as it needs, with that margin kept at
106
111
  * the right too: its later rows are set in, so the next sentence is seen to start. */
@@ -113,7 +118,7 @@ const sentences = (list, cols) => list.flatMap((sentence) => {
113
118
  * listed as such: the table can be changed by the user's tui.json, and the help says what is so
114
119
  * now. An action that does one thing in each view has a line per view, its key on each; under
115
120
  * the line of opening an agent stand the key that leaves its terminal (`detachKey`, tui.json's
116
- * `open.detachKey`) and the rules of OPEN_RULES. */
121
+ * `open.detachKey`) and the rules of OPEN_RULES; under the line of the last act, ACT_RULES. */
117
122
  export function helpRows(actions, ascii, cols = 100, detachKey = null) {
118
123
  const marks = marksOf(ascii);
119
124
  const closing = keyText(["close", "help"].map((id) => actions.find((action) => action.id === id)).filter((action) => action?.keys.length).map((action) => keyLabel(action.keys[0])).join(" or "));
@@ -123,7 +128,8 @@ export function helpRows(actions, ascii, cols = 100, detachKey = null) {
123
128
  ...table(actions.flatMap((action) => {
124
129
  const left = action.keys.length ? keyText(keysLabel(action)) : "(no key)";
125
130
  if (!action.views) return [[left, words(action.label)]];
126
- return action.views.map(([view, said]) => [left, words(said), action.id === "open" && view === "instances" && detachKey !== null ? (room) => openRows(detachKey, room) : undefined]);
131
+ return action.views.map(([view, said]) => [left, words(said), action.id === "open" && view === "instances" && detachKey !== null ? (room) => openRows(detachKey, room)
132
+ : action.id === "restart" ? actRows : undefined]);
127
133
  }), cols, KEYS),
128
134
  [],
129
135
  heading("Marks"),
@@ -60,8 +60,8 @@ members:
60
60
  - git:github.com/acme/agents # the host is a member too
61
61
  - git:github.com/acme/platform
62
62
  packages:
63
- oats.framework: v1.10.1 # bare versions resolve through the official catalog
64
- oats.okf: v5.1.0
63
+ oats.framework: v1.10.2 # bare versions resolve through the official catalog
64
+ oats.okf: v5.2.0
65
65
  defaults:
66
66
  capabilities: { oats.core: { from: package } }
67
67
  knowledge: { oats.okf: { from: package } }