@awebai/oats 0.64.0 → 0.66.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/README.md +11 -5
- package/bin/oats.mjs +109 -11
- package/docs/desktop-cli-api.md +88 -5
- package/docs/desktop.md +14 -5
- package/docs/implementation.md +26 -3
- package/docs/integrations.md +1 -1
- package/docs/official-catalog.md +2 -2
- package/docs/packages.md +7 -7
- package/docs/release-notes/v0.65.0.md +187 -0
- package/docs/release-notes/v0.66.0.md +183 -0
- package/docs/servers.md +2 -2
- package/docs/tui.md +548 -249
- package/docs/upgrading.md +1 -1
- package/docs/workspaces.md +132 -1
- package/lib/core.mjs +14 -4
- package/lib/deployments.mjs +341 -0
- package/lib/resolved-deployment.mjs +37 -0
- package/lib/workspace.mjs +2 -0
- package/package-catalog.json +2 -2
- package/package.json +1 -1
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/deployment-label.mjs +2 -2
- package/packages/client/deployment-list-cli.mjs +98 -0
- package/packages/client/deployment-list.mjs +91 -0
- package/packages/client/keymap.mjs +133 -0
- package/packages/client/machine-contract.mjs +1 -5
- package/packages/client/own-codes.mjs +2 -0
- package/packages/client/panel-views.mjs +1 -1
- package/packages/client/workspace-admission.mjs +2 -1
- package/packages/record/bin/setup.mjs +10 -2
- package/packages/record/docs/capture-service.md +45 -6
- package/packages/record/lib/capture-service-install.mjs +6 -95
- package/packages/record/lib/capture-setup-write.mjs +233 -0
- package/packages/tui/README.md +10 -9
- package/packages/tui/lib/actions.mjs +89 -64
- package/packages/tui/lib/client.mjs +4 -1
- package/packages/tui/lib/config.mjs +184 -36
- package/packages/tui/lib/main.mjs +161 -40
- package/packages/tui/lib/model.mjs +73 -41
- package/packages/tui/lib/read.mjs +15 -45
- package/packages/tui/lib/store.mjs +174 -40
- package/packages/tui/lib/term/keys.mjs +135 -33
- package/packages/tui/lib/term/kitty.mjs +198 -0
- package/packages/tui/lib/term/through.mjs +160 -24
- package/packages/tui/lib/term/tty.mjs +43 -12
- package/packages/tui/lib/views/act.mjs +17 -13
- package/packages/tui/lib/views/frame.mjs +418 -421
- package/packages/tui/lib/views/help.mjs +90 -29
- package/packages/tui/lib/views/instances.mjs +38 -9
- package/packages/tui/lib/views/switcher.mjs +65 -21
- package/skills/oats-getting-started/SKILL.md +102 -32
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// text. Pure: no IO, no clock, no escape byte. The keys are generated from the table the reducer
|
|
3
3
|
// acts on, so the help names every key that does something and no key that does not; the marks
|
|
4
4
|
// are the ones the list and the switcher draw (views/instances.mjs, views/switcher.mjs).
|
|
5
|
-
import { LEADER, keyLabel } from "../actions.mjs";
|
|
5
|
+
import { LEADER, backKeyLabel, keyLabel } from "../actions.mjs";
|
|
6
6
|
import { lit, ownEllipsis } from "../term/text.mjs";
|
|
7
7
|
import { style } from "../term/style.mjs";
|
|
8
8
|
import { cutNote, marksOf, measured } from "./instances.mjs";
|
|
@@ -38,17 +38,17 @@ export const NOT_YET = Object.freeze([
|
|
|
38
38
|
Object.freeze({ what: "see a capability's skills and files", command: "oats capabilities show <name>" }),
|
|
39
39
|
Object.freeze({ what: "open an agent in its own tmux window", command: "oats session attach --home <home>" }),
|
|
40
40
|
Object.freeze({ what: "start with another harness or model", command: "oats session start --home <home>" }),
|
|
41
|
-
Object.freeze({ what: "add a machine to this workspace", command: "oats server connect <id> --ssh <alias>" }),
|
|
41
|
+
Object.freeze({ what: "add a machine to this workspace", command: "oats server connect <id> --ssh <alias> --dir <path on that machine>" }),
|
|
42
42
|
Object.freeze({ what: "check a machine", command: "oats server check <id>" }),
|
|
43
43
|
Object.freeze({ what: "remove a machine", command: "oats server remove <id>" }),
|
|
44
|
-
// The switcher lists the deployments opened in this run and those
|
|
45
|
-
Object.freeze({ what: "open a deployment
|
|
44
|
+
// The switcher lists the deployments opened in this run and those on this computer's list, and no other.
|
|
45
|
+
Object.freeze({ what: "open a deployment that is not listed", command: "oats tui --dir <path>" }),
|
|
46
46
|
]);
|
|
47
47
|
/** What a user should know of the machines the list shows, each a sentence of the TUI's own: a
|
|
48
48
|
* limit that no command lifts is stated too. */
|
|
49
49
|
export const MACHINES = Object.freeze([
|
|
50
|
-
"A machine's rows are what it reported at the time on its heading (in a view of one machine,
|
|
51
|
-
"Nothing is kept on disk: a machine not reached in this run is listed by its own name.",
|
|
50
|
+
"A machine's rows are what it reported at the time on its heading (in a view of one machine, at the top of this help).",
|
|
51
|
+
"Nothing of its own is kept on disk: a machine not reached in this run is listed by its own name.",
|
|
52
52
|
"Souls and Capabilities are this machine's.",
|
|
53
53
|
]);
|
|
54
54
|
/** The views the frame names, what each holds, and what to run for what a view does not do yet.
|
|
@@ -68,10 +68,11 @@ const flow = (pieces, room) => pieces.reduce((lines, piece) => {
|
|
|
68
68
|
return lines;
|
|
69
69
|
}, []);
|
|
70
70
|
/** A table: a left column as wide as its widest entry, then what each entry means, given as
|
|
71
|
-
* pieces that are never
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
71
|
+
* pieces that are never cut (a word, or a whole command: a command cut short cannot be typed).
|
|
72
|
+
* What does not fit `cols` goes on in the same column on the next row. A table with a piece
|
|
73
|
+
* wider than that column puts every meaning under its entry instead, so no row is cut at the
|
|
74
|
+
* smallest width the frame draws at; a piece wider than even that starts further left, and a
|
|
75
|
+
* command wider than the whole area is broken before its flags (commandRows). */
|
|
75
76
|
function table(pairs, cols, look) {
|
|
76
77
|
// An entry is the TUI's own word, or text made elsewhere with its width (a key's label). A
|
|
77
78
|
// third member makes rows of its own under the entry's meaning: given the meaning's column and
|
|
@@ -83,12 +84,29 @@ function table(pairs, cols, look) {
|
|
|
83
84
|
const stacked = pairs.some(([, pieces]) => pieces.some((piece) => column + piece.length > cols));
|
|
84
85
|
const at = stacked ? INDENT + 2 : column;
|
|
85
86
|
return pairs.flatMap(([left, pieces]) => {
|
|
86
|
-
|
|
87
|
+
// A row wider than its column (a whole command, in a narrow area) starts as far left as it
|
|
88
|
+
// must to stand whole, down to the area's first column: a command cut short cannot be typed.
|
|
89
|
+
const lines = flow(pieces, cols - at).flatMap((text) => (text.length <= cols ? [{ col: Math.max(0, Math.min(at, cols - text.length)), text: lit(text) }] : commandRows(text, at, cols)));
|
|
87
90
|
const more = (under.get(pieces)?.(cols - at) ?? []).map((spans) => spans.map((span) => ({ ...span, col: span.col + at })));
|
|
88
91
|
return [...(stacked ? [[entry(left)], ...lines.map((line) => [line])] : lines.map((line, i) => (i === 0 ? [entry(left), line] : [line]))), ...more];
|
|
89
92
|
});
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
/** A command wider than the whole area (`oats server connect`'s, at 80 columns and under), on as
|
|
96
|
+
* few rows as it needs: broken only before a flag (`--dir`), each flag with its value, the rows
|
|
97
|
+
* after the first 2 cells further in, so read in order they are the command, and every row
|
|
98
|
+
* stands whole inside the area, as far right as `at` when there is room. */
|
|
99
|
+
function commandRows(command, at, cols) {
|
|
100
|
+
const rows = command.split(/ (?=--)/).reduce((rows, part) => {
|
|
101
|
+
const last = rows.length - 1;
|
|
102
|
+
if (last >= 0 && rows[last].length + 1 + part.length <= (last === 0 ? cols : cols - 2)) rows[last] += ` ${part}`;
|
|
103
|
+
else rows.push(part);
|
|
104
|
+
return rows;
|
|
105
|
+
}, []);
|
|
106
|
+
const start = Math.max(0, Math.min(at, cols - Math.max(rows[0].length, ...rows.slice(1).map((row) => row.length + 2))));
|
|
107
|
+
return rows.map((row, i) => ({ col: start + (i === 0 ? 0 : 2), text: lit(row) }));
|
|
108
|
+
}
|
|
109
|
+
|
|
92
110
|
/** The TUI's own sentences under the line of `open` in the list of instances: what the terminal
|
|
93
111
|
* takes, what it does not do, and where the keys that can be the back key are listed (the help
|
|
94
112
|
* does not restate the grammar). */
|
|
@@ -97,18 +115,23 @@ export const OPEN_RULES = Object.freeze([
|
|
|
97
115
|
"Up to 4 terminals are open at a time, each a tab. They have no scrollback but the viewer's own, and no mouse.",
|
|
98
116
|
"docs/tui.md has the keys that can be the leader.",
|
|
99
117
|
]);
|
|
100
|
-
/** The rows under the line of `open`, in `room` cells: the leader
|
|
101
|
-
*
|
|
102
|
-
* each sentence on as many rows as it needs. */
|
|
103
|
-
function openRows(detachKey, room) {
|
|
104
|
-
const
|
|
105
|
-
const
|
|
118
|
+
/** The rows under the line of `open`, in `room` cells: the leader then Esc, which takes the focus
|
|
119
|
+
* from the open terminal, and the leader twice, which types it into the terminal (tui.json's
|
|
120
|
+
* open.detachKey, text from outside), then OPEN_RULES, each sentence on as many rows as it needs. */
|
|
121
|
+
function openRows(detachKey, room, chorded = false) {
|
|
122
|
+
const label = backKeyLabel(detachKey), esc = keyLabel(LEADER.find((entry) => entry.does === "list").keys[0]);
|
|
123
|
+
const pair = (keys, said) => {
|
|
124
|
+
const key = keyText(keys), lines = flow(words(said), Math.max(1, room - key.width - 1));
|
|
125
|
+
return [[{ col: 0, text: key.text, width: key.width }, { col: key.width + 1, text: lit(lines[0]) }], ...lines.slice(1).map((text) => [{ col: key.width + 1, text: lit(text) }])];
|
|
126
|
+
};
|
|
106
127
|
return [
|
|
107
|
-
|
|
108
|
-
...
|
|
109
|
-
...OPEN_RULES.flatMap((sentence) => flow(words(sentence), room).map((text) => [{ col: 0, text: lit(text) }])),
|
|
128
|
+
...pair(`${label} ${esc}`, "takes the focus from the terminal back to the list; the agent keeps running."),
|
|
129
|
+
...pair(`${label} ${label}`, "types the leader into the terminal."),
|
|
130
|
+
...[...OPEN_RULES, ...(chorded ? [CHORD_OPEN_RULE] : [])].flatMap((sentence) => flow(words(sentence), room).map((text) => [{ col: 0, text: lit(text) }])),
|
|
110
131
|
];
|
|
111
132
|
}
|
|
133
|
+
/** Under OPEN_RULES, while the chords are listed: they too are the TUI's in a terminal. */
|
|
134
|
+
export const CHORD_OPEN_RULE = "The chords (below) are taken there too: they never reach the agent.";
|
|
112
135
|
/** The TUI's own sentences under the line of the last act: how a confirmation is worked, and that
|
|
113
136
|
* what it sent is never ended by the TUI. */
|
|
114
137
|
export const ACT_RULES = Object.freeze([
|
|
@@ -124,10 +147,40 @@ const sentences = (list, cols) => list.flatMap((sentence) => {
|
|
|
124
147
|
return [first, ...flow(rest.flatMap(words), cols - 2 * INDENT - 2)].map((text, i) => [{ col: INDENT + (i ? 2 : 0), text: lit(text) }]);
|
|
125
148
|
});
|
|
126
149
|
|
|
150
|
+
/** What the leader pressed again does, the last line of the leader's table. */
|
|
151
|
+
export const LEADER_AGAIN = "the leader again: types it into the terminal that has the focus; with the list focused, closes the hint";
|
|
152
|
+
|
|
153
|
+
/** THE CHORDS (docs/tui.md, "Chords"): listed only while the terminal confirms the kitty keyboard
|
|
154
|
+
* protocol, which alone sends them, as extras: the leader is the key that always works. What a
|
|
155
|
+
* terminal may take first is said, with foot's list. */
|
|
156
|
+
export const CHORD_RULES = Object.freeze([
|
|
157
|
+
"Your terminal may take some of these first: foot takes Ctrl+Shift+C, V, R, N, O, U, Z, X and Q. The leader works in every terminal.",
|
|
158
|
+
]);
|
|
159
|
+
/** The chords' rows: `chords` are `[key id, does]`, each said as the leader's table says its `does`. */
|
|
160
|
+
function chordRows(chords, cols) {
|
|
161
|
+
const said = (does) => LEADER.find((entry) => entry.does === does)?.label ?? does;
|
|
162
|
+
return [
|
|
163
|
+
heading("Chords"),
|
|
164
|
+
[],
|
|
165
|
+
...sentences(["Your terminal sends these keys too: each does what the leader then its key does, from every focus, a terminal's too."], cols),
|
|
166
|
+
...table(chords.map(([key, does]) => [keyLabel(key), words(said(does))]), cols, KEYS),
|
|
167
|
+
...sentences(CHORD_RULES, cols),
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The palette's keys (docs/tui.md, "The palette"): it reads its keys itself, so they are fixed
|
|
172
|
+
* and the TUI's words. */
|
|
173
|
+
export const PALETTE_KEYS = Object.freeze([
|
|
174
|
+
Object.freeze(["Up, Down", "move; typing narrows the list"]),
|
|
175
|
+
Object.freeze(["Enter", "run the selected row"]),
|
|
176
|
+
Object.freeze(["Esc", "close the palette"]),
|
|
177
|
+
]);
|
|
178
|
+
const paletteRows = (cols) => [heading("The palette"), [], ...table(PALETTE_KEYS.map(([keys, said]) => [keys, words(said)]), cols, KEYS)];
|
|
179
|
+
|
|
127
180
|
/** The leader's rows (docs/tui.md, "The leader"): its key, then the table of what each key after
|
|
128
181
|
* it does (actions.mjs LEADER), from every focus. */
|
|
129
182
|
function leaderRows(detachKey, cols) {
|
|
130
|
-
const key = keyText(detachKey);
|
|
183
|
+
const key = keyText(backKeyLabel(detachKey));
|
|
131
184
|
// The sentence after the key on as many rows as it needs, its later rows under its first.
|
|
132
185
|
const at = INDENT + key.width + 1;
|
|
133
186
|
const lead = flow(words("then one of these keys, from every focus; a terminal too:"), Math.max(1, cols - INDENT - at));
|
|
@@ -136,8 +189,11 @@ function leaderRows(detachKey, cols) {
|
|
|
136
189
|
[],
|
|
137
190
|
[{ col: INDENT, text: key.text, width: key.width, style: KEYS }, { col: at, text: lit(lead[0]) }],
|
|
138
191
|
...lead.slice(1).map((text) => [{ col: at, text: lit(text) }]),
|
|
139
|
-
...table(LEADER.map((entry) => [entry.keys.map(keyLabel).join(", "),
|
|
140
|
-
words(entry.
|
|
192
|
+
...table([...LEADER.map((entry) => [entry.keys.map(keyLabel).join(", "),
|
|
193
|
+
words(entry.terminal ? `${entry.label}, while a terminal is open` : entry.label)]),
|
|
194
|
+
// The leader again is the user's key, so it is not in the table: it types the leader into the
|
|
195
|
+
// terminal that has the focus, and with the list focused only closes the hint.
|
|
196
|
+
[key, words(LEADER_AGAIN)]], cols, KEYS),
|
|
141
197
|
];
|
|
142
198
|
}
|
|
143
199
|
|
|
@@ -148,7 +204,7 @@ export const SPAWN_KEYS = Object.freeze([
|
|
|
148
204
|
Object.freeze(["Enter", "pick the selected soul; a soul marked ! would be refused here and cannot be picked"]),
|
|
149
205
|
Object.freeze(["Esc", "close the soul picker"]),
|
|
150
206
|
Object.freeze(["Tab, Shift+Tab", "move the focus in the preview: Spawn, name, child of, then each fold"]),
|
|
151
|
-
Object.freeze(["Enter", "do what the
|
|
207
|
+
Object.freeze(["Enter", "do what the cheat sheet names: on Spawn spawn, on name keep the name and read the preview again, on child of switch it, on a fold open or close it"]),
|
|
152
208
|
Object.freeze(["Esc", "from a field back to Spawn; from Spawn back to the picker, or to the list"]),
|
|
153
209
|
]);
|
|
154
210
|
export const SPAWN_RULES = Object.freeze([
|
|
@@ -161,8 +217,10 @@ const spawnRows = (cols) => [heading("The spawn prompt"), [], ...table(SPAWN_KEY
|
|
|
161
217
|
* now. An action that does one thing in each view has a line per view, its key on each; under
|
|
162
218
|
* the line of opening an agent stand the back key (`detachKey`, tui.json's `open.detachKey`) and
|
|
163
219
|
* the rules of OPEN_RULES; under the line of the last act, ACT_RULES. After the leader's table,
|
|
164
|
-
* the
|
|
165
|
-
|
|
220
|
+
* the chords (`chords`, `[key id, does]`, or null while the terminal has not confirmed the kitty
|
|
221
|
+
* keyboard protocol: then they are not listed), the palette's keys (PALETTE_KEYS) and the spawn
|
|
222
|
+
* prompt's (SPAWN_KEYS, SPAWN_RULES). */
|
|
223
|
+
export function helpRows(actions, ascii, cols = 100, detachKey = null, chords = null) {
|
|
166
224
|
const marks = marksOf(ascii);
|
|
167
225
|
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 "));
|
|
168
226
|
return [
|
|
@@ -171,10 +229,13 @@ export function helpRows(actions, ascii, cols = 100, detachKey = null) {
|
|
|
171
229
|
...table(actions.flatMap((action) => {
|
|
172
230
|
const left = action.keys.length ? keyText(keysLabel(action)) : "(no key)";
|
|
173
231
|
if (!action.views) return [[left, words(action.label)]];
|
|
174
|
-
return action.views.map(([view, said]) => [left, words(said), action.id === "open" && view === "instances" && detachKey !== null ? (room) => openRows(detachKey, room)
|
|
232
|
+
return action.views.map(([view, said]) => [left, words(said), action.id === "open" && view === "instances" && detachKey !== null ? (room) => openRows(detachKey, room, chords !== null && chords.length > 0)
|
|
175
233
|
: action.id === "restart" ? actRows : undefined]);
|
|
176
234
|
}), cols, KEYS),
|
|
177
235
|
...(detachKey !== null ? [[], ...leaderRows(detachKey, cols)] : []),
|
|
236
|
+
...(chords !== null && chords.length > 0 ? [[], ...chordRows(chords, cols)] : []),
|
|
237
|
+
[],
|
|
238
|
+
...paletteRows(cols),
|
|
178
239
|
[],
|
|
179
240
|
...spawnRows(cols),
|
|
180
241
|
[],
|
|
@@ -212,8 +273,8 @@ export function helpRows(actions, ascii, cols = 100, detachKey = null) {
|
|
|
212
273
|
|
|
213
274
|
/** `{ rows, extent }`: `size.rows` rows for an area `size.cols` wide, scrolled to `top`, and how
|
|
214
275
|
* many rows the whole help has. The movement keys scroll it. */
|
|
215
|
-
export function help(actions, size, { top = 0, ascii = false, detachKey = null } = {}) {
|
|
216
|
-
const all = helpRows(actions, ascii, size.cols, detachKey);
|
|
276
|
+
export function help(actions, size, { top = 0, ascii = false, detachKey = null, chords = null } = {}) {
|
|
277
|
+
const all = helpRows(actions, ascii, size.cols, detachKey, chords);
|
|
217
278
|
const rows = Array.from({ length: size.rows }, () => []);
|
|
218
279
|
const win = windowOf({ top, count: all.length, height: size.rows });
|
|
219
280
|
all.slice(win.top, win.top + win.size).forEach((spans, i) => { rows[i] = spans; });
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// many it folds away, `+n`. In a view of two or more deployments the list also holds a heading
|
|
8
8
|
// per deployment and the sentences the model sets under one: a heading says in words what it is
|
|
9
9
|
// of.
|
|
10
|
+
import { keyLabel } from "../actions.mjs";
|
|
10
11
|
import { lit, shown, shownEnd, textOf } from "../term/text.mjs";
|
|
11
12
|
import { style } from "../term/style.mjs";
|
|
12
13
|
import { textWidth } from "../term/width.mjs";
|
|
@@ -28,8 +29,11 @@ const WAITING = 4;
|
|
|
28
29
|
const LEAD = 4;
|
|
29
30
|
/** The column of the state mark, before a row's indent. */
|
|
30
31
|
const MARK = 2;
|
|
32
|
+
/** The cells a row's name keeps before its word, and the fewest a cut word is drawn in: under
|
|
33
|
+
* them the word is left out, since a few cells of it say nothing. */
|
|
34
|
+
const NAME_LEAST = 16, WORD_LEAST = 6;
|
|
31
35
|
|
|
32
|
-
/** A heading starts here: at the margin the
|
|
36
|
+
/** A heading starts here: at the margin the sidebar keeps, not at a row's indent. */
|
|
33
37
|
const HEAD = 1;
|
|
34
38
|
/** The cells between two parts of a heading. */
|
|
35
39
|
const GAP = 2;
|
|
@@ -52,10 +56,13 @@ const WAITS_SELECTED = style({ reverse: true, bold: true });
|
|
|
52
56
|
|
|
53
57
|
export const EMPTY_TEXT = Object.freeze({
|
|
54
58
|
reading: "Reading the deployment.",
|
|
55
|
-
none: "No
|
|
59
|
+
none: "No agents yet",
|
|
56
60
|
nomatch: "No instance matches the filter.",
|
|
57
61
|
});
|
|
58
62
|
|
|
63
|
+
/** The words after EMPTY_TEXT.none and the key that spawns (docs/tui.md, "What it shows"). */
|
|
64
|
+
export const SPAWNS_ONE = "spawns one";
|
|
65
|
+
|
|
59
66
|
/** Text the TUI did not write, with the cells its display takes: `{ text, width }`. What stands
|
|
60
67
|
* after it on a row is placed by that width. */
|
|
61
68
|
export function measured(value) {
|
|
@@ -68,27 +75,33 @@ const waitingText = (row) => (row.below > 99 ? "!99+" : row.below > 0 ? `!${row.
|
|
|
68
75
|
/** One instance's row in a pane `cols` wide: the state mark, the name cut to what is left, on a
|
|
69
76
|
* folded row `+n` after the name, the row's word (when it has one) in the word column, and the
|
|
70
77
|
* waiting mark at the edge. A row with no word gives its name the word column's cells too. The
|
|
71
|
-
* name
|
|
72
|
-
*
|
|
78
|
+
* name wins over the word: it keeps NAME_LEAST cells (all of it when it is shorter), and when the
|
|
79
|
+
* word column would leave it fewer, the word is cut to what the name leaves, after it, or given
|
|
80
|
+
* up under WORD_LEAST cells; the mark and the detail still say it. The name is cut before `+n`
|
|
81
|
+
* is: the count stays whole beside what is left of the name. Every span has its width, so no
|
|
82
|
+
* text can pass its column whatever the terminal thinks a character takes. */
|
|
73
83
|
function instanceRow(row, cols, wordWidth, marks) {
|
|
74
84
|
const look = (own) => (row.selected ? SELECTED : own);
|
|
75
85
|
const at = Math.min(row.depth, LEVELS - 1) * INDENT;
|
|
76
|
-
const worded = wordWidth > 0 && row.word !== null && row.word !== undefined;
|
|
77
|
-
const wordCol = Math.max(0, cols - WAITING - 1 - wordWidth);
|
|
78
|
-
const nameCol = LEAD + at, nameEnd = worded ? wordCol - 2 : cols - WAITING - 1;
|
|
79
86
|
const fold = row.folded > 0 ? `+${row.folded}` : null;
|
|
87
|
+
const nameCol = LEAD + at, room = cols - WAITING - 1 - nameCol;
|
|
88
|
+
const name = measured(row.name), claim = Math.min(name.width + (fold ? fold.length + 1 : 0), NAME_LEAST);
|
|
89
|
+
// The word's cells: its column's, or what the name's claim leaves of the row, or none.
|
|
90
|
+
const left = room - claim - 2;
|
|
91
|
+
const wordCells = wordWidth > 0 && row.word !== null && row.word !== undefined ? (left >= wordWidth ? wordWidth : left >= WORD_LEAST ? left : 0) : 0;
|
|
92
|
+
const wordCol = left >= wordWidth ? cols - WAITING - 1 - wordWidth : nameCol + claim + 2;
|
|
93
|
+
const nameEnd = wordCells ? wordCol - 2 : cols - WAITING - 1;
|
|
80
94
|
const spans = [];
|
|
81
95
|
if (row.selected) spans.push({ col: 0, width: cols, style: SELECTED }, { col: 0, text: lit(marks.selected), style: SELECTED, width: 1 });
|
|
82
96
|
spans.push({ col: MARK + at, text: lit(marks[row.mark] ?? marks.unknown), style: look(LOOK[row.mark] ?? LOOK.unknown), width: 1 });
|
|
83
97
|
if (nameEnd > nameCol) {
|
|
84
|
-
const name = measured(row.name);
|
|
85
98
|
// The count and the gap before it, when there is room for them and for a cell of the name.
|
|
86
99
|
const after = fold && nameEnd - nameCol > fold.length + 1 ? fold.length + 1 : 0;
|
|
87
100
|
const nameWidth = Math.min(name.width, nameEnd - nameCol - after);
|
|
88
101
|
spans.push({ col: nameCol, text: name.text, style: look(PLAIN), width: after ? nameWidth : nameEnd - nameCol });
|
|
89
102
|
if (after) spans.push({ col: nameCol + nameWidth + 1, text: lit(fold), style: look(DIM), width: fold.length });
|
|
90
103
|
}
|
|
91
|
-
if (
|
|
104
|
+
if (wordCells) spans.push({ col: wordCol, text: shown(row.word), style: look(DIM), width: wordCells });
|
|
92
105
|
const waits = waitingText(row);
|
|
93
106
|
if (waits) spans.push({ col: cols - waits.length, text: lit(waits), style: row.selected ? WAITS_SELECTED : WAITS, width: waits.length });
|
|
94
107
|
return spans;
|
|
@@ -132,6 +145,21 @@ export function cutNote(above, below) {
|
|
|
132
145
|
return [above > 0 ? `${above} more above` : null, below > 0 ? `${below} more below` : null].filter(Boolean).join(", ");
|
|
133
146
|
}
|
|
134
147
|
|
|
148
|
+
/** The one row of a view with no instances, in `aside` cells: `No agents yet: n spawns one`, with
|
|
149
|
+
* the key the user's table gives `spawn` (text from outside: tui.json may rebind it), or `No
|
|
150
|
+
* agents yet.` while it has none. Cut at the edge, the key before the words after it. */
|
|
151
|
+
function noneRow(m, aside) {
|
|
152
|
+
const action = (m.actions ?? []).find((a) => a.id === "spawn" && a.keys.length);
|
|
153
|
+
if (!action) return [{ col: SENTENCE_INDENT, text: lit(`${EMPTY_TEXT.none}.`), style: DIM, width: aside }];
|
|
154
|
+
const end = SENTENCE_INDENT + aside, lead = `${EMPTY_TEXT.none}:`, key = measured(keyLabel(action.keys[0]));
|
|
155
|
+
const at = SENTENCE_INDENT + lead.length + 1, after = at + key.width + 1;
|
|
156
|
+
return [
|
|
157
|
+
{ col: SENTENCE_INDENT, text: lit(lead), style: DIM, width: Math.min(lead.length, aside) },
|
|
158
|
+
{ col: at, text: key.text, style: DIM, width: Math.max(0, Math.min(key.width, end - at)) },
|
|
159
|
+
{ col: after, text: lit(SPAWNS_ONE), style: DIM, width: Math.max(0, Math.min(SPAWNS_ONE.length, end - after)) },
|
|
160
|
+
].filter((span) => span.width > 0);
|
|
161
|
+
}
|
|
162
|
+
|
|
135
163
|
/** `size.rows` rows for a pane `size.cols` wide: the model's window of the list, one item per row,
|
|
136
164
|
* and on the last row what is cut off above and below. An item is an instance, a deployment's
|
|
137
165
|
* heading, one row of a sentence the model wrapped (safe text already, placed as it is), a line
|
|
@@ -146,6 +174,7 @@ export function instances(m, size) {
|
|
|
146
174
|
if (item.heading) rows[i] = headingRow(item.heading, size.cols, m.ascii);
|
|
147
175
|
else if (item.line) rows[i] = [{ col: SENTENCE_INDENT, text: item.line, width: sentence }];
|
|
148
176
|
else if (item.own) rows[i] = [{ col: SENTENCE_INDENT, text: lit(item.own), style: DIM, width: sentence }];
|
|
177
|
+
else if (item.empty === "none") rows[i] = noneRow(m, aside);
|
|
149
178
|
else if (item.empty) rows[i] = [{ col: SENTENCE_INDENT, text: lit(EMPTY_TEXT[item.empty]), style: DIM, width: aside }];
|
|
150
179
|
else rows[i] = instanceRow(item, size.cols, m.wordWidth, marks);
|
|
151
180
|
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// The switcher of workspaces: (model, area) -> rows of spans. Pure: no IO, no clock, no escape
|
|
2
|
-
// byte. It
|
|
3
|
-
// its deployments are not live are the shared home's words and go through shown(), as
|
|
4
|
-
//
|
|
2
|
+
// byte. It is drawn in the area views/frame.mjs gives it: the main area. A workspace's name, its machines and how many of
|
|
3
|
+
// its deployments are not live are the shared home's words and go through shown(), as do a listed
|
|
4
|
+
// deployment's name and path and what the kernel said; the marks, the headings of its own and its
|
|
5
|
+
// few sentences are the TUI's.
|
|
5
6
|
// Nothing is told by colour alone: the selected row carries `>` as well as reverse video, and
|
|
6
7
|
// the workspace that is open carries `*`.
|
|
7
|
-
import { lit, shown } from "../term/text.mjs";
|
|
8
|
+
import { lit, shown, shownLines } from "../term/text.mjs";
|
|
8
9
|
import { style } from "../term/style.mjs";
|
|
9
10
|
import { cutNote, measured } from "./instances.mjs";
|
|
10
11
|
|
|
@@ -17,12 +18,22 @@ export const SWITCHER_TEXT = Object.freeze({
|
|
|
17
18
|
nomatch: "No workspace matches the filter.",
|
|
18
19
|
gone: "That workspace is no longer listed.",
|
|
19
20
|
refused: "Not an OATS deployment any more.",
|
|
21
|
+
/** A stale row of this computer's deployments list, in place of its path, by the kernel's state
|
|
22
|
+
* (packages/client/deployment-list.mjs DEPLOYMENT_STATES). Such a row does not open. */
|
|
23
|
+
states: Object.freeze({ missing: "Not found.", "not-a-deployment": "Not an OATS deployment any more.", unreadable: "Can't be read." }),
|
|
24
|
+
/** The two lines of a Remove asked, over the rows: the selected row stays marked under them. */
|
|
25
|
+
removing: Object.freeze(["Remove the selected row from this computer's list?", "Enter removes it; other keys keep it. Its folder stays."]),
|
|
26
|
+
/** What a Remove answered, and that the list could not be read: each with a name or the kernel's
|
|
27
|
+
* message, shown as it came. */
|
|
28
|
+
removed: (name) => `${name} was removed from this computer's list.`,
|
|
29
|
+
notRemoved: (name, message) => `${name} was not removed from this computer's list: ${message}`,
|
|
30
|
+
unread: (message) => `This computer's list of deployments could not be read: ${message}`,
|
|
20
31
|
});
|
|
21
32
|
|
|
22
33
|
/** The columns of a choice: the selection mark in the first cell, the open mark, then the label.
|
|
23
34
|
* A heading and every line that is not a choice start two cells before the labels. */
|
|
24
35
|
const OPEN = 2, LABEL = 4, ASIDE = LABEL - 2;
|
|
25
|
-
/** One cell of margin at the right edge, as the
|
|
36
|
+
/** One cell of margin at the right edge, as the sidebar keeps. */
|
|
26
37
|
const MARGIN = 1;
|
|
27
38
|
/** The cells between two columns. */
|
|
28
39
|
const GAP = 2;
|
|
@@ -35,7 +46,7 @@ const PLAIN = style();
|
|
|
35
46
|
const DIM = style({ dim: true });
|
|
36
47
|
const SELECTED = style({ reverse: true });
|
|
37
48
|
|
|
38
|
-
/** One choice in an area `cols` wide: a workspace, or a
|
|
49
|
+
/** One choice in an area `cols` wide: a workspace, or a listed deployment that is not opened yet. What a
|
|
39
50
|
* workspace says of its deployments that are not live stands whole at the right edge; when the
|
|
40
51
|
* row is too narrow the place is cut first, then the label. */
|
|
41
52
|
function choiceRow(item, cols) {
|
|
@@ -49,29 +60,63 @@ function choiceRow(item, cols) {
|
|
|
49
60
|
const liveCol = Math.max(LABEL, edge - live.width);
|
|
50
61
|
// Where the label and the place end: at the edge, or two cells before what stands there.
|
|
51
62
|
const limit = live.width ? liveCol - GAP : edge;
|
|
52
|
-
// A
|
|
53
|
-
const
|
|
63
|
+
// A row that turned out not to be a deployment, and a stale one, say so where its path stood.
|
|
64
|
+
const own = item.refused ? SWITCHER_TEXT.refused : SWITCHER_TEXT.states[item.state] ?? null;
|
|
65
|
+
const place = own !== null ? { text: lit(own), width: own.length } : measured(item.place);
|
|
54
66
|
// With no place to show, the label has the row.
|
|
55
67
|
const labelWidth = Math.max(0, Math.min(place.width ? labelCols : limit - LABEL, limit - LABEL));
|
|
56
68
|
if (labelWidth) spans.push({ col: LABEL, text: shown(item.label), style: look(PLAIN), width: labelWidth });
|
|
57
|
-
if (place.width && limit > placeCol) spans.push({ col: placeCol, text: place.text, style: look(
|
|
69
|
+
if (place.width && limit > placeCol) spans.push({ col: placeCol, text: place.text, style: look(own !== null ? PLAIN : DIM), width: limit - placeCol });
|
|
58
70
|
if (live.width) spans.push({ col: liveCol, text: live.text, style: look(PLAIN), width: Math.max(0, Math.min(live.width, edge - liveCol)) });
|
|
59
71
|
return spans.filter((span) => span.width > 0);
|
|
60
72
|
}
|
|
61
73
|
|
|
62
|
-
/** The
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
/** The most rows one sentence with a name or the kernel's words in it takes above the choices: the
|
|
75
|
+
* kernel's message says what to do, so it is wrapped, not cut, up to this. */
|
|
76
|
+
const LEAD_ROWS = 4;
|
|
77
|
+
|
|
78
|
+
/** The rows that stand above the choices, top to bottom, for an area `cols` wide, each
|
|
79
|
+
* `{ text, style }` with `text` made (term/text.mjs): what happened (that the workspace which was
|
|
80
|
+
* open is no longer listed, what a Remove answered), that this computer's deployments list could
|
|
81
|
+
* not be read, and a Remove asked: each something to read, so not dim, and each wrapped to the
|
|
82
|
+
* width: a sentence with a name or the kernel's words in it is shown as it came. lib/model.mjs counts these rows to make
|
|
83
|
+
* the window of the choices that much shorter (switcherLead), so it never hides a choice. */
|
|
84
|
+
export function leadRows(s, cols, { ascii = false } = {}) {
|
|
85
|
+
const width = Math.max(1, cols - ASIDE - MARGIN), rows = [];
|
|
86
|
+
// A sentence of the TUI's own is broken at its spaces (the main area beside the sidebar can be narrow).
|
|
87
|
+
const own = (text) => { for (const line of wrapped(text, width)) rows.push({ text: lit(line), style: PLAIN }); };
|
|
88
|
+
const shared = (text) => { for (const line of shownLines(text, width, LEAD_ROWS, { ascii })) rows.push({ text: line, style: PLAIN }); };
|
|
89
|
+
if (s.said === "gone") own(SWITCHER_TEXT.gone);
|
|
90
|
+
else if (s.said?.removed !== undefined) shared(SWITCHER_TEXT.removed(s.said.removed));
|
|
91
|
+
else if (s.said?.notRemoved !== undefined) shared(SWITCHER_TEXT.notRemoved(s.said.notRemoved, s.said.message));
|
|
92
|
+
if (s.failure) shared(SWITCHER_TEXT.unread(s.failure));
|
|
93
|
+
if (s.removing) for (const text of SWITCHER_TEXT.removing) own(text);
|
|
94
|
+
return rows;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The rows above the choices: leadRows, then why no workspace is listed (dim, as the list's own
|
|
98
|
+
* empty line is), which stands only when there is no choice to hide. */
|
|
99
|
+
function leadLines(s, cols, ascii) {
|
|
100
|
+
const lines = leadRows(s, cols, { ascii });
|
|
101
|
+
const dim = (text) => lines.push({ text: lit(text), style: DIM });
|
|
102
|
+
if (s.empty === "nomatch") dim(SWITCHER_TEXT.nomatch);
|
|
69
103
|
if (s.empty === "none") {
|
|
70
|
-
const [first, second, command] = SWITCHER_TEXT.none, whole = `${second} ${command}
|
|
71
|
-
|
|
104
|
+
const [first, second, command] = SWITCHER_TEXT.none, whole = `${second} ${command}`, room = cols - MARGIN - ASIDE;
|
|
105
|
+
// A sentence wider than the area (the main area beside the sidebar can be narrow) goes on on the
|
|
106
|
+
// next row, broken at its spaces; the command is a piece of its own, never broken.
|
|
107
|
+
for (const text of [...wrapped(first, room), ...(whole.length <= room ? [whole] : [...wrapped(second, room), command])]) dim(text);
|
|
72
108
|
}
|
|
73
109
|
return lines;
|
|
74
110
|
}
|
|
111
|
+
/** A sentence of the TUI's own on rows of at most `room` cells, broken at its spaces. */
|
|
112
|
+
function wrapped(text, room) {
|
|
113
|
+
return text.split(" ").reduce((rows, word) => {
|
|
114
|
+
const last = rows.at(-1);
|
|
115
|
+
if (last !== undefined && last.length + 1 + word.length <= room) rows[rows.length - 1] = `${last} ${word}`;
|
|
116
|
+
else rows.push(word);
|
|
117
|
+
return rows;
|
|
118
|
+
}, []);
|
|
119
|
+
}
|
|
75
120
|
|
|
76
121
|
/** `size.rows` rows for an area `size.cols` wide: the lines above, the model's window of the
|
|
77
122
|
* switcher's rows, one item per row, and on the last row what is cut off above and below.
|
|
@@ -83,13 +128,12 @@ export function switcher(m, size) {
|
|
|
83
128
|
if (!s || size.rows < 1) return rows;
|
|
84
129
|
const { cols } = size, aside = Math.max(0, cols - ASIDE - MARGIN);
|
|
85
130
|
const note = cutNote(s.above, s.below);
|
|
86
|
-
const lead = leadLines(s, cols).slice(0, Math.max(0, size.rows - s.rows.length - (note ? 1 : 0)));
|
|
87
|
-
lead.forEach((line, i) => { rows[i] = [{ col: ASIDE, text:
|
|
131
|
+
const lead = leadLines(s, cols, m.ascii === true).slice(0, Math.max(0, size.rows - s.rows.length - (note ? 1 : 0)));
|
|
132
|
+
lead.forEach((line, i) => { rows[i] = [{ col: ASIDE, text: line.text, style: line.style, width: aside }]; });
|
|
88
133
|
s.rows.forEach((item, i) => {
|
|
89
134
|
const at = lead.length + i;
|
|
90
135
|
if (at >= size.rows) return;
|
|
91
136
|
if (item.heading !== undefined) rows[at] = [{ col: ASIDE, text: item.shared ? shown(item.heading) : lit(item.heading), style: DIM, width: aside }];
|
|
92
|
-
else if (item.own !== undefined) rows[at] = [{ col: LABEL, text: lit(item.own), style: DIM, width: Math.max(0, cols - LABEL - MARGIN) }];
|
|
93
137
|
else rows[at] = choiceRow(item, cols);
|
|
94
138
|
});
|
|
95
139
|
if (note) rows[size.rows - 1] = [{ col: ASIDE, text: lit(note), style: DIM, width: aside }];
|