@awebai/oats 0.58.0 → 0.60.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/bin/oats.mjs +1 -1
- package/docs/desktop-cli-api.md +80 -8
- package/docs/desktop.md +30 -3
- package/docs/execution-targets.md +18 -2
- package/docs/implementation.md +3 -0
- package/docs/integrations.md +2 -2
- package/docs/knowledge.md +4 -4
- package/docs/official-catalog.md +4 -4
- package/docs/packages.md +14 -14
- package/docs/release-notes/v0.59.0.md +288 -0
- package/docs/release-notes/v0.60.0.md +104 -0
- package/docs/servers.md +4 -1
- package/docs/souls-and-instances.md +21 -0
- package/docs/tui.md +753 -119
- package/docs/workspaces.md +2 -2
- package/lib/core.mjs +258 -57
- package/lib/read-ahead-worker.mjs +119 -0
- package/lib/read-ahead.mjs +115 -0
- package/lib/retire-state.mjs +33 -0
- package/lib/servers.mjs +9 -1
- package/lib/session-input.mjs +53 -26
- package/package-catalog.json +3 -3
- package/package.json +1 -1
- package/packages/client/capability-catalog.mjs +93 -0
- package/packages/client/capability-facts.mjs +59 -0
- package/packages/client/capability-rows.mjs +121 -0
- package/packages/client/catalog-messages.mjs +12 -0
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/deployment-data.mjs +4 -0
- package/packages/client/deployment-panel.mjs +3 -0
- package/packages/client/instance-acts.mjs +23 -8
- package/packages/client/instance-presentation.mjs +3 -2
- package/packages/client/instance-tree.mjs +84 -39
- package/packages/client/lifecycle-confirmation.mjs +9 -3
- package/packages/client/remote-roster.mjs +4 -1
- package/packages/client/retire-in-flight.mjs +65 -0
- package/packages/client/retire-state.mjs +30 -0
- package/packages/client/soul-catalog.mjs +8 -0
- package/packages/client/soul-facts.mjs +7 -0
- package/packages/client/spawn-apply.mjs +13 -4
- package/packages/client/spawn-messages.mjs +8 -0
- package/packages/client/subsequence-score.mjs +15 -0
- package/packages/tui/README.md +23 -10
- package/packages/tui/lib/actions.mjs +63 -5
- package/packages/tui/lib/client.mjs +17 -1
- package/packages/tui/lib/config.mjs +7 -2
- package/packages/tui/lib/main.mjs +364 -82
- package/packages/tui/lib/model.mjs +614 -57
- package/packages/tui/lib/panel.mjs +436 -125
- package/packages/tui/lib/read.mjs +52 -26
- package/packages/tui/lib/store.mjs +1025 -65
- package/packages/tui/lib/term/keys.mjs +9 -2
- package/packages/tui/lib/term/text.mjs +4 -0
- package/packages/tui/lib/term/through.mjs +12 -1
- package/packages/tui/lib/views/capabilities.mjs +239 -0
- package/packages/tui/lib/views/frame.mjs +433 -99
- package/packages/tui/lib/views/help.mjs +61 -15
- package/packages/tui/lib/views/instances.mjs +43 -25
- package/packages/tui/lib/views/palette.mjs +66 -0
- package/packages/tui/lib/views/souls.mjs +270 -0
- package/packages/tui/lib/views/spawn.mjs +301 -0
- package/packages/tui/lib/views/split.mjs +29 -0
- package/skills/oats-getting-started/SKILL.md +2 -2
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
// The spawn prompt (docs/tui.md, "Spawning an agent"): (model, area) -> rows of spans, over the
|
|
2
|
+
// whole body as the palette is. Pure: no IO, no clock, no escape byte. Two steps, the model's
|
|
3
|
+
// `m.spawn` (lib/model.mjs):
|
|
4
|
+
// the picker a title, one input, then the window of the souls the model lists, the selected one
|
|
5
|
+
// in reverse with `>`, a soul a spawn here would refuse dim with `!` and its refusal;
|
|
6
|
+
// the preview the shared preview's facts (packages/client/spawn-preview-facts.mjs previewFacts),
|
|
7
|
+
// the folds, scrolled by the model's `top` when they are taller than their room
|
|
8
|
+
// (to the fold with the focus, whatever `top` says); under them, pinned to the
|
|
9
|
+
// body's bottom, the two fields, the Spawn button and a problem.
|
|
10
|
+
// A soul's name, the query, every fact, the label of the instance a child would be of, the typed
|
|
11
|
+
// name and a problem's lines are text the TUI did not write and go through shown(); the titles,
|
|
12
|
+
// the field labels, the folds' labels and summaries and the button are the TUI's own. Nothing is
|
|
13
|
+
// told by colour alone: what has the focus carries `>` as well as reverse video, the focused
|
|
14
|
+
// button stands between `>` and `<`, a refused soul carries `!` and its refusal in words, and a
|
|
15
|
+
// preview being read again says so in words above its dim facts.
|
|
16
|
+
import { lit, ownEllipsis, shown, shownEnd, shownLines, textOf } from "../term/text.mjs";
|
|
17
|
+
import { style } from "../term/style.mjs";
|
|
18
|
+
import { textWidth } from "../term/width.mjs";
|
|
19
|
+
import { partRows } from "./frame.mjs";
|
|
20
|
+
import { cutNote, measured } from "./instances.mjs";
|
|
21
|
+
import { windowOf } from "./scroll.mjs";
|
|
22
|
+
|
|
23
|
+
/** The TUI's own lines in the prompt. Those that end in an ellipsis are drawn `...` in ASCII. */
|
|
24
|
+
export const SPAWN_TEXT = Object.freeze({
|
|
25
|
+
pick: "Spawn: pick a soul",
|
|
26
|
+
title: "Spawn",
|
|
27
|
+
readingSouls: "Reading souls…",
|
|
28
|
+
readingPreview: "Reading the preview…",
|
|
29
|
+
none: "No souls in this workspace.",
|
|
30
|
+
nomatch: "No soul matches.",
|
|
31
|
+
name: "name",
|
|
32
|
+
child: "child of",
|
|
33
|
+
noParent: "none",
|
|
34
|
+
button: "Spawn",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
/** The query's prompt, and the cells it takes with the gap after it (the palette's). */
|
|
38
|
+
const PROMPT = ">", PROMPT_CELLS = 2;
|
|
39
|
+
/** A picker row's columns, as the palette's: the selection mark, a gap, the refused mark, a gap. */
|
|
40
|
+
const MARK = 2, LEAD = 4;
|
|
41
|
+
/** The mark of a soul a spawn here would refuse (the Souls view's). */
|
|
42
|
+
const REFUSED = "!";
|
|
43
|
+
/** The cells between a refused soul's name and its refusal. */
|
|
44
|
+
const REFUSAL_GAP = 2;
|
|
45
|
+
/** The picker's title and query rows: the window of souls starts under them. */
|
|
46
|
+
const PICKER_HEAD = 2;
|
|
47
|
+
/** The preview's labels start here: the first cell holds the focus mark. */
|
|
48
|
+
const LEFT = 2;
|
|
49
|
+
/** The values start here: the longest label the shared facts give ("Relationship") and a gap. */
|
|
50
|
+
const VALUE = LEFT + 14;
|
|
51
|
+
/** An open fold's content is set in this far. */
|
|
52
|
+
const INNER = LEFT + 2;
|
|
53
|
+
/** The most rows one value, sentence or line of a fold takes. */
|
|
54
|
+
const WRAP_ROWS = 8;
|
|
55
|
+
/** One cell is kept at the right edge. */
|
|
56
|
+
const EDGE = 1;
|
|
57
|
+
|
|
58
|
+
const PLAIN = style();
|
|
59
|
+
const BOLD = style({ bold: true });
|
|
60
|
+
const DIM = style({ dim: true });
|
|
61
|
+
const SELECTED = style({ reverse: true });
|
|
62
|
+
const FOCUSED = style({ bold: true, reverse: true });
|
|
63
|
+
const FOCUSED_DIM = style({ dim: true, reverse: true });
|
|
64
|
+
|
|
65
|
+
/** The TUI's own one-line words as drawn: the ellipsis is `...` in ASCII. */
|
|
66
|
+
const own = (text, ascii) => lit(ownEllipsis(text, ascii));
|
|
67
|
+
/** One span of the TUI's own words at `col`, kept inside `width` cells from column 0. */
|
|
68
|
+
function ownSpan(text, col, width, ascii, look = PLAIN) {
|
|
69
|
+
const said = ownEllipsis(text, ascii), cells = Math.min(said.length, Math.max(0, width - col));
|
|
70
|
+
return cells > 0 ? [{ col, text: lit(said), width: cells, style: look }] : [];
|
|
71
|
+
}
|
|
72
|
+
/** Text from outside on as many rows as it needs (at most `max`), each a span at `col`. */
|
|
73
|
+
function outsideRows(value, col, width, max, ascii, look = PLAIN) {
|
|
74
|
+
const room = width - col;
|
|
75
|
+
if (room < 1) return [];
|
|
76
|
+
return shownLines(value, room, max, { ascii }).map((text) => [{ col, text, width: room, style: look }]);
|
|
77
|
+
}
|
|
78
|
+
/** Spans restyled: every span takes `look`. */
|
|
79
|
+
const restyled = (spans, look) => spans.map((span) => ({ ...span, style: look }));
|
|
80
|
+
|
|
81
|
+
// ── The picker ──────────────────────────────────────────────────────────────────────────────────
|
|
82
|
+
|
|
83
|
+
/** One soul's row in `cols` cells: `>` and reverse video when selected, `!` and dim when a spawn of
|
|
84
|
+
* it here would be refused, its name, and after a refused one's name its refusal, dim. */
|
|
85
|
+
function soulRow(row, cols) {
|
|
86
|
+
const look = (base) => (row.selected ? SELECTED : base);
|
|
87
|
+
const quiet = row.refused ? DIM : PLAIN;
|
|
88
|
+
const end = cols - EDGE;
|
|
89
|
+
const spans = [];
|
|
90
|
+
if (row.selected) spans.push({ col: 0, width: cols, style: SELECTED }, { col: 0, text: lit(PROMPT), style: SELECTED, width: 1 });
|
|
91
|
+
if (row.refused) spans.push({ col: MARK, text: lit(REFUSED), style: look(DIM), width: 1 });
|
|
92
|
+
const name = measured(row.name), nameWidth = Math.max(0, Math.min(name.width, end - LEAD));
|
|
93
|
+
if (nameWidth > 0) spans.push({ col: LEAD, text: name.text, style: look(quiet), width: nameWidth });
|
|
94
|
+
const at = LEAD + nameWidth + REFUSAL_GAP;
|
|
95
|
+
if (row.refused && row.refusal && at < end) {
|
|
96
|
+
const refusal = measured(row.refusal);
|
|
97
|
+
spans.push({ col: at, text: refusal.text, style: look(DIM), width: Math.min(refusal.width, end - at) });
|
|
98
|
+
}
|
|
99
|
+
return spans;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The picker's rows: the title, the query with its prompt, then the window of souls or the one
|
|
103
|
+
* sentence of a state with none; the last row says what the window cuts off. The cursor stands
|
|
104
|
+
* after the query. */
|
|
105
|
+
function picker(s, size, ascii) {
|
|
106
|
+
const rows = Array.from({ length: size.rows }, () => []);
|
|
107
|
+
const width = size.cols - EDGE;
|
|
108
|
+
if (size.rows > 0) rows[0] = ownSpan(SPAWN_TEXT.pick, 0, width, ascii, BOLD);
|
|
109
|
+
const query = measured(s.query ?? ""), room = Math.max(0, width - PROMPT_CELLS);
|
|
110
|
+
if (size.rows > 1) rows[1] = [{ col: 0, text: lit(PROMPT), style: BOLD, width: PROMPT.length }, ...(query.width && room ? [{ col: PROMPT_CELLS, text: query.text, width: Math.min(query.width, room) }] : [])];
|
|
111
|
+
const list = s.rows ?? [];
|
|
112
|
+
list.forEach((row, i) => { if (PICKER_HEAD + i < size.rows) rows[PICKER_HEAD + i] = soulRow(row, size.cols); });
|
|
113
|
+
if (!list.length && size.rows > PICKER_HEAD) {
|
|
114
|
+
const said = s.state === "failed" ? outsideRows(s.failure, LEAD, width, Math.max(1, size.rows - PICKER_HEAD), ascii)
|
|
115
|
+
: { reading: [ownSpan(SPAWN_TEXT.readingSouls, LEAD, width, ascii, DIM)], none: [ownSpan(SPAWN_TEXT.none, LEAD, width, ascii, DIM)], nomatch: [ownSpan(SPAWN_TEXT.nomatch, LEAD, width, ascii, DIM)] }[s.state] ?? [];
|
|
116
|
+
said.forEach((spans, i) => { if (PICKER_HEAD + i < size.rows) rows[PICKER_HEAD + i] = spans; });
|
|
117
|
+
}
|
|
118
|
+
const note = cutNote(s.above ?? 0, s.below ?? 0);
|
|
119
|
+
if (note && size.rows > PICKER_HEAD + 1) rows[size.rows - 1] = ownSpan(note, LEAD, width, ascii, DIM);
|
|
120
|
+
return { rows, cursor: size.rows > 1 ? { row: 1, col: PROMPT_CELLS + Math.min(query.width, room) } : null, extent: 0, room: 1 };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ── The preview ─────────────────────────────────────────────────────────────────────────────────
|
|
124
|
+
|
|
125
|
+
/** A value's parts from `col` in `width` cells (from column 0): each part is text from outside,
|
|
126
|
+
* written `gap` cells after the one before it, and never broken but where it is wider than a row;
|
|
127
|
+
* a `muted` part is dim. A `sub` part (where a value came from, what else) is dim on a row of its
|
|
128
|
+
* own under the value. */
|
|
129
|
+
function partsRows(parts, col, width, ascii, gap = 1) {
|
|
130
|
+
const room = width - col;
|
|
131
|
+
if (room < 1) return [];
|
|
132
|
+
const rows = [];
|
|
133
|
+
let row = [], used = 0;
|
|
134
|
+
const flush = () => { if (row.length) rows.push(row); row = []; used = 0; };
|
|
135
|
+
for (const part of (parts ?? []).filter((each) => !each?.sub)) {
|
|
136
|
+
const m = measured(part?.text), look = part?.muted ? DIM : PLAIN;
|
|
137
|
+
if (m.width === 0) continue;
|
|
138
|
+
const at = row.length ? used + gap : 0;
|
|
139
|
+
if (at + m.width <= room) { row.push({ col: col + at, text: m.text, width: m.width, style: look }); used = at + m.width; continue; }
|
|
140
|
+
flush();
|
|
141
|
+
if (m.width <= room) { row.push({ col, text: m.text, width: m.width, style: look }); used = m.width; continue; }
|
|
142
|
+
// Wider than a row: broken over rows of its own.
|
|
143
|
+
for (const text of shownLines(part.text, room, WRAP_ROWS, { ascii })) rows.push([{ col, text, width: room, style: look }]);
|
|
144
|
+
}
|
|
145
|
+
flush();
|
|
146
|
+
for (const part of (parts ?? []).filter((each) => each?.sub)) rows.push(...outsideRows(part.text, col, width, WRAP_ROWS, ascii, DIM));
|
|
147
|
+
return rows;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A label (text from outside, dim, cut to the label column) with its value's rows beside it. */
|
|
151
|
+
function labelled(label, valueRows, width) {
|
|
152
|
+
const name = measured(label), cells = Math.max(0, Math.min(name.width, VALUE - LEFT - 1, width - LEFT));
|
|
153
|
+
const head = cells > 0 ? [{ col: LEFT, text: name.text, width: cells, style: DIM }] : [];
|
|
154
|
+
if (!valueRows.length) return [head];
|
|
155
|
+
return valueRows.map((spans, i) => (i === 0 ? [...head, ...spans] : spans));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** An open fold's content, set in at INNER. */
|
|
159
|
+
function foldContent(key, facts, width, ascii) {
|
|
160
|
+
const out = [];
|
|
161
|
+
if (key === "prompts") {
|
|
162
|
+
for (const prompt of facts?.prompts ?? []) {
|
|
163
|
+
out.push(...outsideRows(prompt.label, INNER, width, 2, ascii, DIM));
|
|
164
|
+
out.push(...outsideRows(prompt.text, INNER + 2, width, WRAP_ROWS, ascii));
|
|
165
|
+
}
|
|
166
|
+
} else if (key === "warnings") {
|
|
167
|
+
(facts?.warnings ?? []).forEach((lines, i) => {
|
|
168
|
+
if (i > 0) out.push([]);
|
|
169
|
+
for (const line of Array.isArray(lines) ? lines : [lines]) out.push(...outsideRows(line, INNER, width, WRAP_ROWS, ascii));
|
|
170
|
+
});
|
|
171
|
+
} else if (key === "modules") {
|
|
172
|
+
const described = (module) => [{ text: module.name }, ...(module.why ? [{ text: module.why, muted: true }] : []), ...(module.source ? [{ text: module.source, muted: true }] : [])];
|
|
173
|
+
for (const slot of facts?.modules?.core ?? []) {
|
|
174
|
+
const value = slot.module ? partsRows(described(slot.module), VALUE, width, ascii, 2) : [ownSpan(SPAWN_TEXT.noParent, VALUE, width, ascii, DIM)];
|
|
175
|
+
const name = measured(slot.label), cells = Math.max(0, Math.min(name.width, VALUE - INNER - 1, width - INNER));
|
|
176
|
+
const head = cells > 0 ? [{ col: INNER, text: name.text, width: cells, style: DIM }] : [];
|
|
177
|
+
out.push(...value.map((spans, i) => (i === 0 ? [...head, ...spans] : spans)));
|
|
178
|
+
}
|
|
179
|
+
for (const module of facts?.modules?.caps ?? []) out.push(...partsRows(described(module), INNER, width, ascii, 2));
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** A row's text in focus: `>` in the first cell, and from it to the end of its spans in reverse video. */
|
|
185
|
+
function focusedRow(spans) {
|
|
186
|
+
const end = spans.reduce((most, span) => Math.max(most, span.col + span.width), 1);
|
|
187
|
+
return [{ col: 0, width: end, style: FOCUSED }, { col: 0, text: lit(PROMPT), style: FOCUSED, width: 1 }, ...restyled(spans, FOCUSED)];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The preview's two parts for an area `cols` wide (one cell kept at the edge):
|
|
191
|
+
* scroll the rows that scroll by the model's `top`: the title, the status, the identity, the
|
|
192
|
+
* facts and the folds, each open one with its content;
|
|
193
|
+
* keep the row of the fold with the focus in `scroll`, or -1: the window always holds it;
|
|
194
|
+
* pinned the rows that keep the area's bottom, as a confirmation's buttons do: the two fields,
|
|
195
|
+
* the Spawn button and a problem (cut to `problemRows` rows, the last one the cut mark);
|
|
196
|
+
* cursor where the name field's cursor stands in `pinned` (`{ row, col }`), or null while the
|
|
197
|
+
* field has no focus;
|
|
198
|
+
* button the Spawn button's row in `pinned`. */
|
|
199
|
+
export function previewRows(s, cols, ascii, { problemRows = Infinity } = {}) {
|
|
200
|
+
const width = Math.max(1, cols - EDGE);
|
|
201
|
+
const rows = [];
|
|
202
|
+
let keep = -1;
|
|
203
|
+
// The title: the TUI's word and the soul's name, bold.
|
|
204
|
+
// A space ends the TUI's word: the soul's name is not written against it (frame.mjs partRows).
|
|
205
|
+
const title = partRows([{ own: `${SPAWN_TEXT.title} ` }, ...(s.soul ? [{ shown: s.soul }] : [])], width - LEFT, 2, { ascii });
|
|
206
|
+
rows.push(...title.map((spans) => restyled(spans, BOLD).map((span) => ({ ...span, col: span.col + LEFT }))), []);
|
|
207
|
+
if (s.status === "souls") rows.push(ownSpan(SPAWN_TEXT.readingSouls, LEFT, width, ascii, DIM), []);
|
|
208
|
+
if (s.status === "reading") rows.push(ownSpan(SPAWN_TEXT.readingPreview, LEFT, width, ascii, DIM), []);
|
|
209
|
+
// The facts: shown while read and while a new read runs (dim then: they are the last read's).
|
|
210
|
+
const facts = s.status === "shown" || s.status === "reading" ? s.facts : null;
|
|
211
|
+
if (facts) {
|
|
212
|
+
const stale = s.status === "reading";
|
|
213
|
+
const block = [];
|
|
214
|
+
for (const item of facts.identity ?? []) block.push(...labelled(item.label, partsRows([{ text: item.text, muted: item.muted }], VALUE, width, ascii), width));
|
|
215
|
+
for (const fact of facts.facts ?? []) block.push(...labelled(fact.label, partsRows(fact.parts, VALUE, width, ascii), width));
|
|
216
|
+
rows.push(...(stale ? block.map((spans) => restyled(spans, DIM)) : block));
|
|
217
|
+
const folds = s.folds ?? [];
|
|
218
|
+
if (folds.length) rows.push([]);
|
|
219
|
+
for (const fold of folds) {
|
|
220
|
+
const line = partRows([{ own: `${fold.label}: ${fold.summary}` }], width - LEFT, 1, { ascii }).flat().map((span) => ({ ...span, col: span.col + LEFT, style: stale ? DIM : PLAIN }));
|
|
221
|
+
if (fold.focused) keep = rows.length;
|
|
222
|
+
rows.push(fold.focused ? focusedRow(line) : line);
|
|
223
|
+
if (fold.open) {
|
|
224
|
+
const content = foldContent(fold.key, facts, width, ascii);
|
|
225
|
+
rows.push(...(stale ? content.map((spans) => restyled(spans, DIM)) : content));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// The two fields, after an empty row: the name the person typed (empty: the identity's Name row
|
|
230
|
+
// says the kernel numbers it), and, when offered, the instance the new one would be a child of.
|
|
231
|
+
const pinned = [[]];
|
|
232
|
+
const fields = s.fields ?? {};
|
|
233
|
+
let cursor = null;
|
|
234
|
+
if (fields.name) {
|
|
235
|
+
const label = ownSpan(SPAWN_TEXT.name, LEFT, width, ascii);
|
|
236
|
+
const room = Math.max(0, width - VALUE);
|
|
237
|
+
const text = room > 0 ? shownEnd(fields.name.text ?? "", room, { ascii }) : null;
|
|
238
|
+
const used = text ? Math.min(textWidth(textOf(text)), room) : 0;
|
|
239
|
+
const value = used > 0 ? [{ col: VALUE, text, width: used }] : [];
|
|
240
|
+
pinned.push(fields.name.focused ? [...focusedRow(label), ...value] : [...label, ...value]);
|
|
241
|
+
if (fields.name.focused) cursor = { row: pinned.length - 1, col: Math.min(VALUE + used, width) };
|
|
242
|
+
}
|
|
243
|
+
if (fields.child?.offered) {
|
|
244
|
+
const label = ownSpan(SPAWN_TEXT.child, LEFT, width, ascii);
|
|
245
|
+
const value = fields.child.on && fields.child.label != null
|
|
246
|
+
? (() => { const m = measured(fields.child.label); return [{ col: VALUE, text: m.text, width: Math.max(0, Math.min(m.width, width - VALUE)) }].filter((span) => span.width > 0); })()
|
|
247
|
+
: ownSpan(SPAWN_TEXT.noParent, VALUE, width, ascii, DIM);
|
|
248
|
+
pinned.push(fields.child.focused ? [...focusedRow(label), ...value] : [...label, ...value]);
|
|
249
|
+
}
|
|
250
|
+
// The button: between `>` and `<` while it has the focus; dim while Enter on it would not spawn
|
|
251
|
+
// the preview on screen (still read, failed, or not drawn for these choices yet).
|
|
252
|
+
const focused = s.focus === "spawn";
|
|
253
|
+
const label = focused ? `> ${SPAWN_TEXT.button} <` : `[ ${SPAWN_TEXT.button} ]`;
|
|
254
|
+
pinned.push([], ownSpan(label, LEFT, width, ascii, s.ready ? (focused ? FOCUSED : PLAIN) : (focused ? FOCUSED_DIM : DIM)));
|
|
255
|
+
const button = pinned.length - 1;
|
|
256
|
+
// A failed read, or a spawn's outcome that brought the prompt back, after an empty row: its
|
|
257
|
+
// sentence bold, then the lines under it as they came. Cut to the rows it is given, the last of
|
|
258
|
+
// them the cut mark then.
|
|
259
|
+
if (s.problem && problemRows > 0) {
|
|
260
|
+
const problem = [[]];
|
|
261
|
+
problem.push(...partRows(s.problem.said ?? [], width - LEFT, WRAP_ROWS, { ascii }).map((spans) => restyled(spans, BOLD).map((span) => ({ ...span, col: span.col + LEFT }))));
|
|
262
|
+
for (const line of s.problem.under ?? []) problem.push(...outsideRows(line, LEFT, width, WRAP_ROWS, ascii));
|
|
263
|
+
pinned.push(...(problem.length <= problemRows ? problem : [...problem.slice(0, problemRows - 1), ownSpan("\u2026", LEFT, width, ascii, DIM)]));
|
|
264
|
+
}
|
|
265
|
+
return { scroll: rows, keep, pinned, cursor, button };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** The rows the scrolling part keeps at least, above what is pinned under it. */
|
|
269
|
+
const SCROLL_MIN = 3;
|
|
270
|
+
|
|
271
|
+
/** The preview in `size.rows` rows: the fields, the button and a problem pinned at the bottom, and
|
|
272
|
+
* above them the rest scrolled to the model's `top`, or to the window that holds the fold with
|
|
273
|
+
* the focus (the store scrolls only with the movement keys; Tab can land on a fold out of sight).
|
|
274
|
+
* The scrolling part's last row says what is cut off. `extent` and `room` are the scrolling
|
|
275
|
+
* part's, for the store's scroll, and `top` the row the window drawn starts at (which keeps the
|
|
276
|
+
* focused fold in sight, and so may stand where the model's `top` does not), which the loop
|
|
277
|
+
* gives the store once it is painted; `armed` is whether the ready Spawn button is on the screen. */
|
|
278
|
+
function preview(s, size, ascii) {
|
|
279
|
+
const rows = Array.from({ length: size.rows }, () => []);
|
|
280
|
+
const fixed = previewRows(s, size.cols, ascii, { problemRows: 0 }).pinned.length;
|
|
281
|
+
const all = previewRows(s, size.cols, ascii, { problemRows: Math.max(0, size.rows - SCROLL_MIN - fixed) });
|
|
282
|
+
const pinned = all.pinned.slice(-size.rows);
|
|
283
|
+
const room = Math.max(0, size.rows - pinned.length);
|
|
284
|
+
const win = windowOf({ top: s.top ?? 0, count: all.scroll.length, height: room, keep: all.keep });
|
|
285
|
+
all.scroll.slice(win.top, win.top + win.size).forEach((spans, i) => { rows[i] = spans; });
|
|
286
|
+
const note = cutNote(win.above, win.below);
|
|
287
|
+
if (note && room > 0) rows[room - 1] = ownSpan(note, LEFT, size.cols - EDGE, ascii, DIM);
|
|
288
|
+
pinned.forEach((spans, i) => { rows[room + i] = spans; });
|
|
289
|
+
const cut = all.pinned.length - pinned.length;
|
|
290
|
+
const cursor = all.cursor && all.cursor.row >= cut ? { row: room + all.cursor.row - cut, col: all.cursor.col } : null;
|
|
291
|
+
return { rows, cursor, extent: all.scroll.length, room: Math.max(1, room), top: win.top, armed: s.ready === true && all.button >= cut };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** `{ rows, cursor, extent, room, top?, armed? }`: `size.rows` rows for an area `size.cols` wide, the step of the
|
|
295
|
+
* prompt the model is at. `cursor` is `{ row, col }` in the area (the query's end, or the name
|
|
296
|
+
* field's while it has the focus), or null; `extent` and `room` are the preview's scrolling
|
|
297
|
+
* part's, for the store's scroll (0 and 1 for the picker, which the model windows itself). */
|
|
298
|
+
export function spawn(m, size) {
|
|
299
|
+
const s = m.spawn;
|
|
300
|
+
return s.step === "picker" ? picker(s, size, m.ascii) : preview(s, size, m.ascii);
|
|
301
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The split of the panel (docs/tui.md, "Splits"): two groups side by side ("right") or one above
|
|
2
|
+
// the other ("down"), always even, with a rule between them. Pure geometry, shared by the store
|
|
3
|
+
// (which refuses a split the panel cannot hold) and the frame (which draws one group alone while
|
|
4
|
+
// the panel is too small for both).
|
|
5
|
+
|
|
6
|
+
/** The least a group takes: 40 columns side by side, 8 rows (its strip counted) one above the other. */
|
|
7
|
+
export const SPLIT_MIN = Object.freeze({ cols: 40, rows: 8 });
|
|
8
|
+
|
|
9
|
+
/** Whether a panel of `room` (`{ cols, rows }`, its strip row counted in `rows`) holds two groups
|
|
10
|
+
* split `dir`. A room not known holds none: no split is admitted on a size nobody measured. */
|
|
11
|
+
export function splitFits(dir, room) {
|
|
12
|
+
if (!room || !Number.isInteger(room.cols) || !Number.isInteger(room.rows)) return false;
|
|
13
|
+
return dir === "right" ? Math.floor((room.cols - 1) / 2) >= SPLIT_MIN.cols : Math.floor((room.rows - 1) / 2) >= SPLIT_MIN.rows;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The two groups' places in a panel `area` (`{ title, col, cols, rows }`: its strip row, its first
|
|
17
|
+
* column, its width and the rows under the strip), split `dir`: `[first, second, rule]`. The first
|
|
18
|
+
* (left or top) takes the extra cell or row; each group is `{ title, top, col, cols, rows }` as
|
|
19
|
+
* the area is, and `rule` the column (`{ col }`) or the row (`{ row }`) between them. */
|
|
20
|
+
export function splitRegions(area, dir) {
|
|
21
|
+
if (dir === "right") {
|
|
22
|
+
const left = Math.ceil((area.cols - 1) / 2), right = area.cols - 1 - left;
|
|
23
|
+
const at = (col, cols) => ({ title: area.title, top: area.title + 1, col, cols, rows: area.rows });
|
|
24
|
+
return [at(area.col, left), at(area.col + left + 1, right), { col: area.col + left }];
|
|
25
|
+
}
|
|
26
|
+
const total = area.rows + 1, upper = Math.ceil((total - 1) / 2), lower = total - 1 - upper;
|
|
27
|
+
const at = (title, height) => ({ title, top: title + 1, col: area.col, cols: area.cols, rows: height - 1 });
|
|
28
|
+
return [at(area.title, upper), at(area.title + upper + 1, lower), { row: area.title + upper }];
|
|
29
|
+
}
|
|
@@ -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.12.
|
|
64
|
-
oats.okf: v5.2.
|
|
63
|
+
oats.framework: v1.12.3 # bare versions resolve through the official catalog
|
|
64
|
+
oats.okf: v5.2.1
|
|
65
65
|
defaults:
|
|
66
66
|
capabilities: { oats.core: { from: package } }
|
|
67
67
|
knowledge: { oats.okf: { from: package } }
|