@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
|
@@ -12,19 +12,20 @@
|
|
|
12
12
|
import { homedir } from "node:os";
|
|
13
13
|
import { resolve } from "node:path";
|
|
14
14
|
import { bindings } from "./actions.mjs";
|
|
15
|
-
import { TERMS, capabilityCatalogKey, createCapabilityCatalog, createLifecycleBoundary, createLifecycleConfirmation, createRetiresInFlight, createSoulCatalog, createSpawnApplyBoundary, createSpawnPreview, createSpawnTransaction, displayLine, heldHome, pendingEntry, prepareRemoteTerm, sessionAttachArgv, soulCatalogKey, startInstance } from "./client.mjs";
|
|
15
|
+
import { TERMS, capabilityCatalogKey, cliDeploymentList, deploymentsListSupported, createCapabilityCatalog, createLifecycleBoundary, createLifecycleConfirmation, createRetiresInFlight, createSoulCatalog, createSpawnApplyBoundary, createSpawnPreview, createSpawnTransaction, displayLine, heldHome, pendingEntry, prepareRemoteTerm, sessionAttachArgv, soulCatalogKey, startInstance } from "./client.mjs";
|
|
16
16
|
import { loadConfig } from "./config.mjs";
|
|
17
|
-
import { ACT_WORDS, actContext, actCwd, localDeployments, model, outcomeOf, reachedMachines, roster, spawnContext } from "./model.mjs";
|
|
17
|
+
import { ACT_WORDS, LIST_WORDS, actContext, actCwd, localDeployments, model, outcomeOf, reachedMachines, roster, spawnContext } from "./model.mjs";
|
|
18
18
|
import { createPanel, sweep } from "./panel.mjs";
|
|
19
|
-
import { CHANGE_FILES, admitDeployment, createReader, findDeployment, leaveInstance,
|
|
19
|
+
import { CHANGE_FILES, admitDeployment, createReader, findDeployment, leaveInstance, probeKernel, realpath, startExec, tellable } from "./read.mjs";
|
|
20
20
|
import { initialState, reduce } from "./store.mjs";
|
|
21
21
|
import { captureRows } from "./term/capture.mjs";
|
|
22
22
|
import { createKeyParser, keyId } from "./term/keys.mjs";
|
|
23
|
+
import { confirmed } from "./term/kitty.mjs";
|
|
23
24
|
import { createScreen, glyphs } from "./term/screen.mjs";
|
|
24
25
|
import { colorEnabled } from "./term/style.mjs";
|
|
25
26
|
import { backKeySequences, createThrough } from "./term/through.mjs";
|
|
26
27
|
import { createGuard, isTerminal } from "./term/tty.mjs";
|
|
27
|
-
import { frame, layout, panelPlace } from "./views/frame.mjs";
|
|
28
|
+
import { frame, layout, mainArea, panelPlace } from "./views/frame.mjs";
|
|
28
29
|
|
|
29
30
|
export const USAGE = "oats tui [--dir <path>] [--ascii]";
|
|
30
31
|
const HELP = `Usage:
|
|
@@ -45,6 +46,10 @@ export const NO_TERMINAL = "oats: `oats tui` needs a terminal on stdin and stdou
|
|
|
45
46
|
/** A path is echoed only when it is plain: these lines go to a terminal. */
|
|
46
47
|
const plainPath = (path) => (typeof path === "string" && /^[\x20-\x7e]{1,200}$/.test(path) ? path : "that directory");
|
|
47
48
|
export const noDeployment = (dir) => `oats: no OATS deployment at or above ${plainPath(dir)} (E_NO_DEPLOYMENT); name one with \`oats tui --dir <path>\``;
|
|
49
|
+
/** A start outside every deployment, with no `--dir`, when this computer's deployments list holds none (awebai/oats#1390). */
|
|
50
|
+
export const noDeploymentListed = (dir) => `oats: no deployment at or above ${plainPath(dir)}, and this computer's list of deployments holds none (E_NO_DEPLOYMENT): \`oats tui --dir <path>\` opens one (and lists it), \`oats onboard <dir> --workspace <ref>\` creates one`;
|
|
51
|
+
/** The same start, when the list could not be read: the kernel's code and its message, which says what to do. */
|
|
52
|
+
export const noList = (reason) => `oats: \`oats tui\` could not read this computer's list of deployments (${/^E_[A-Z0-9_]{1,62}$/.test(reason?.code ?? "") ? reason.code : NOT_ASKED.code}): ${displayLine(reason?.message) ?? "it gave no reason"}`;
|
|
48
53
|
export const noKernel = (reason) => `oats: \`oats tui\` could not use its own kernel (E_TUI_KERNEL): ${displayLine(reason) ?? "it gave no reason"}`;
|
|
49
54
|
|
|
50
55
|
/** The arguments: `--ascii`, `--help`/`-h`, `--dir <path>` and `--dir=<path>`. Everything else is
|
|
@@ -65,6 +70,12 @@ export function parseArgs(argv) {
|
|
|
65
70
|
return { options };
|
|
66
71
|
}
|
|
67
72
|
|
|
73
|
+
/** The label of a change to this computer's deployments list (an add or a remove), for the line after leaving. */
|
|
74
|
+
const LIST_CHANGE = Object.freeze({ verb: "list" });
|
|
75
|
+
/** Why a call to this computer's deployments list has no answer at all: it threw before the kernel
|
|
76
|
+
* could answer. The shared adapter's own code for a kernel call that failed (deployment-list-cli.mjs). */
|
|
77
|
+
const NOT_ASKED = Object.freeze({ code: "E_CLI_FAILED", message: "the kernel could not be asked" });
|
|
78
|
+
|
|
68
79
|
/** An error as lines fit for a terminal: its stack, each line through the display filter. */
|
|
69
80
|
function errorLines(error) {
|
|
70
81
|
const text = error instanceof Error ? error.stack || error.message : String(error);
|
|
@@ -80,8 +91,10 @@ function errorLines(error) {
|
|
|
80
91
|
* catalog of a workspace's souls, and `createCapabilityCatalog` its table of capabilities, each
|
|
81
92
|
* replaceable so a test can count its reads; the three spawn
|
|
82
93
|
* factories are the shared home's preview, apply boundary and transaction, replaceable so a test
|
|
83
|
-
* can answer them.
|
|
84
|
-
|
|
94
|
+
* can answer them. `deploymentList` is the shared cliDeploymentList (this computer's deployments
|
|
95
|
+
* list, through the kernel: awebai/oats#1390), and `startExec` the exec it is handed before the
|
|
96
|
+
* terminal is taken; replaceable so a test can answer the list. */
|
|
97
|
+
const EFFECTS = Object.freeze({ loadConfig, findDeployment, probeKernel, createReader, deploymentList: cliDeploymentList, startExec, admitDeployment, prepareRemoteTerm, createPanel, sweep,
|
|
85
98
|
runDir: CHANGE_FILES.dir, removeDir: CHANGE_FILES.remove, realpath, tellable, startInstance, createLifecycleConfirmation, createLifecycleBoundary, createSoulCatalog,
|
|
86
99
|
createCapabilityCatalog, createSpawnPreview, createSpawnApplyBoundary, createSpawnTransaction });
|
|
87
100
|
|
|
@@ -111,46 +124,74 @@ export function createRunTimers({ setTimer, clearTimer }) {
|
|
|
111
124
|
* Before the alternate screen, in this order, each failure one line on stderr and status 1:
|
|
112
125
|
* the arguments; the instance variables removed from the environment (a TUI started in an
|
|
113
126
|
* agent's pane must read the deployment it was asked about, and so must every child it starts);
|
|
114
|
-
* the terminal; the user's tui.json; the deployment; the kernel it shipped with
|
|
115
|
-
|
|
127
|
+
* the terminal; the user's tui.json; the deployment; the kernel it shipped with; and, for a start
|
|
128
|
+
* outside every deployment with no `--dir`, this computer's deployments list, read through that
|
|
129
|
+
* kernel. */
|
|
130
|
+
/** How long a run waits for the terminal's answer to the kitty keyboard protocol's query, in
|
|
131
|
+
* milliseconds, before it pops the protocol and reads keys as before for the rest of the run
|
|
132
|
+
* (docs/tui.md, "Chords"). A terminal answers as it reads the query, before any key typed after
|
|
133
|
+
* it, so the wait only bounds a terminal that never answers; it is long enough for a slow link. */
|
|
134
|
+
export const KEYBOARD_WAIT_MS = 2000;
|
|
135
|
+
|
|
136
|
+
/** `keyboard`: whether the run asks the terminal for the kitty keyboard protocol (term/tty.mjs PUSH,
|
|
137
|
+
* QUERY). Every run does; a test of a terminal that is never asked passes false. */
|
|
138
|
+
export async function main({ argv, stdin, stdout, stderr, env, proc = process, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout, cwd = () => process.cwd(), home = homedir(), keyboard = true, effects: given = EFFECTS }) {
|
|
116
139
|
const effects = given === EFFECTS ? EFFECTS : { ...EFFECTS, ...given };
|
|
117
140
|
const { options, error } = parseArgs(argv);
|
|
118
141
|
if (error) { stderr.write(`${error}\n`); return 1; }
|
|
119
142
|
if (options.help) { stdout.write(HELP); return 0; }
|
|
120
143
|
leaveInstance(env);
|
|
121
144
|
if (!isTerminal({ stdin, stdout, env })) { stderr.write(`${NO_TERMINAL}\n`); return 1; }
|
|
122
|
-
const config = effects.loadConfig({ env, home });
|
|
145
|
+
const config = effects.loadConfig({ env, home, platform: proc.platform });
|
|
123
146
|
if (!config.ok) { stderr.write(config.lines.map((line) => `${line}\n`).join("")); return 1; }
|
|
124
147
|
const found = effects.findDeployment(resolve(cwd(), options.dir ?? "."));
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
const offered = found.ok || options.dir !== null ? null : effects.offeredDeployments(home, []);
|
|
128
|
-
if (!found.ok && !offered?.offered.length) { stderr.write(`${noDeployment(found.dir)}\n`); return 1; }
|
|
148
|
+
// A `--dir` that is in no deployment is refused as it is: what was asked for is not there.
|
|
149
|
+
if (!found.ok && options.dir !== null) { stderr.write(`${noDeployment(found.dir)}\n`); return 1; }
|
|
129
150
|
// The kernel is asked once: an upgrade under a running TUI is met by starting it again.
|
|
130
151
|
const probe = await effects.probeKernel({ env });
|
|
131
152
|
if (!probe.ok) { stderr.write(`${noKernel(probe.reason)}\n`); return 1; }
|
|
153
|
+
// Outside every deployment, and with none named: the switcher, when this computer's deployments
|
|
154
|
+
// list holds a row, read through the kernel just asked. A list that cannot be read is no empty one.
|
|
155
|
+
let listedAtStart = null;
|
|
156
|
+
if (!found.ok) {
|
|
157
|
+
const listed = await effects.deploymentList(probe.cli, { action: "list" }, { exec: effects.startExec, env });
|
|
158
|
+
if (!listed.ok) { stderr.write(`${noList(listed.reason)}\n`); return 1; }
|
|
159
|
+
if (!listed.value.rows.length) { stderr.write(`${noDeploymentListed(found.dir)}\n`); return 1; }
|
|
160
|
+
listedAtStart = listed.value.rows;
|
|
161
|
+
}
|
|
132
162
|
|
|
133
163
|
const clock = () => new Date(now()).toISOString();
|
|
134
164
|
const look = glyphs(env, { ascii: options.ascii || config.ascii });
|
|
135
165
|
const screen = createScreen({ ...look, color: colorEnabled(env) });
|
|
136
|
-
let
|
|
137
|
-
let state = initialState({ deployment: found.ok ? found.deployment : null, cli: probe.cli, home, entry: found.ok ? pendingEntry(null, clock()) : null, actions: config.actions, ascii: look.ascii, detachKey: config.detachKey });
|
|
166
|
+
let state = initialState({ deployment: found.ok ? found.deployment : null, cli: probe.cli, home, entry: found.ok ? pendingEntry(null, clock()) : null, actions: config.actions, ascii: look.ascii, platform: proc.platform, detachKey: config.detachKey });
|
|
138
167
|
const keymap = bindings(state.actions);
|
|
168
|
+
// THE KITTY KEYBOARD PROTOCOL (docs/tui.md, "Chords"): asked for as the terminal is taken (the
|
|
169
|
+
// guard's PUSH and QUERY), "asking" until it answers or KEYBOARD_WAIT_MS passes, then the flags
|
|
170
|
+
// it confirmed (flag 1 held), or null for the rest of the run. The key parser and the scanner
|
|
171
|
+
// below are made with it, and each reads the answer itself when it comes through it.
|
|
172
|
+
let kb = keyboard ? "asking" : null, kbTimer = null;
|
|
173
|
+
/** The clock time the wait for the answer ends: what may begin it is held up to then. */
|
|
174
|
+
const answerBy = keyboard ? now() + KEYBOARD_WAIT_MS : null;
|
|
175
|
+
const newParser = () => createKeyParser({ now, keyboard: kb, chords: state.chords, answerBy });
|
|
176
|
+
let parser = newParser();
|
|
139
177
|
// While a terminal has the focus the bytes typed go to the agent: this scanner takes from them
|
|
140
|
-
// only the back key and a bracketed paste (term/through.mjs). A new one each time the
|
|
141
|
-
// takes the focus, so nothing held from before is typed into it.
|
|
178
|
+
// only the back key, the chords and a bracketed paste (term/through.mjs). A new one each time the
|
|
179
|
+
// terminal takes the focus, so nothing held from before is typed into it.
|
|
142
180
|
const backKey = backKeySequences(state.detachKey);
|
|
143
|
-
|
|
144
|
-
|
|
181
|
+
const newThrough = () => createThrough({ sequences: backKey, now, keyboard: kb, leader: state.leaderKey, chords: state.chords, answerBy });
|
|
182
|
+
let through = newThrough(), throughTimer = null;
|
|
183
|
+
if (listedAtStart) state = reduce(state, { listed: { rows: listedAtStart } }, keymap).state;
|
|
145
184
|
// What the last frame drew, for the store: how tall the list pane is and how far the other
|
|
146
185
|
// pane scrolls. The store holds no size of its own; the panel's room goes with each key as it
|
|
147
186
|
// is when the key is read (placed), whatever the last frame drew.
|
|
148
|
-
let drawn = { page: 1, extent: 0, room: 1, cols: 1 };
|
|
187
|
+
let drawn = { page: 1, extent: 0, room: 1, cols: 1, area: 1 };
|
|
149
188
|
let full = true, escTimer = null, ended = false, reads = 0;
|
|
150
189
|
/** The preflight of another machine's agent under way: `{ id, controller, prepared }`, where
|
|
151
190
|
* `prepared` is what it answered (`{ binary, args }`) once it has; or null. */
|
|
152
191
|
let preflight = null;
|
|
153
|
-
/** The run's private directory, made at the first change
|
|
192
|
+
/** The run's private directory, made at the first change (with a kernel that lists this
|
|
193
|
+
* computer's deployments, the add of the deployment the run started in, at the start) or the
|
|
194
|
+
* first open (lib/read.mjs
|
|
154
195
|
* CHANGE_FILES): the reader writes a change's output there, and the panel keeps its tmux
|
|
155
196
|
* server's socket there. */
|
|
156
197
|
let dir = null;
|
|
@@ -379,8 +420,9 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
379
420
|
});
|
|
380
421
|
}
|
|
381
422
|
/** One step of the reducer taken: the state, then what only the loop can do. True once the
|
|
382
|
-
* TUI is leaving.
|
|
383
|
-
*
|
|
423
|
+
* TUI is leaving. Asking whether a picked row is a deployment reads the file system
|
|
424
|
+
* (lib/read.mjs), and reading or changing this computer's deployments list asks the kernel; what
|
|
425
|
+
* each finds is an event of its own. */
|
|
384
426
|
function took(step) {
|
|
385
427
|
state = step.state;
|
|
386
428
|
const effect = step.effect;
|
|
@@ -388,7 +430,8 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
388
430
|
if (effect === "suspend") guard.suspend();
|
|
389
431
|
if (effect === "redraw") guard.reassert(); // the modes again, then the whole screen
|
|
390
432
|
if (effect === null || typeof effect !== "object") return false;
|
|
391
|
-
if (effect.
|
|
433
|
+
if (effect.list) readList();
|
|
434
|
+
if (effect.remove) removeListed(effect.remove);
|
|
392
435
|
if (effect.admit !== undefined) {
|
|
393
436
|
const admitted = effects.admitDeployment(effect.admit);
|
|
394
437
|
took(reduce(state, admitted.ok ? { admitted: admitted.deployment, at: clock() } : { refused: effect.admit }, keymap));
|
|
@@ -402,6 +445,8 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
402
445
|
preflight = null;
|
|
403
446
|
if (ready?.id === effect.panel && ready.prepared) view(effect.panel, ready.prepared.binary, ready.prepared.args);
|
|
404
447
|
}
|
|
448
|
+
// The leader twice from the terminal's focus: its own bytes to the agent, as what is typed goes.
|
|
449
|
+
if (effect.input) { if (keysReady()) panel.input(effect.input); }
|
|
405
450
|
if (effect.dismiss !== undefined) dismiss(effect.dismiss);
|
|
406
451
|
if (effect.act) openConfirmation(effect.act);
|
|
407
452
|
if (effect.call) callConfirmation(effect.call);
|
|
@@ -417,6 +462,49 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
417
462
|
return false;
|
|
418
463
|
}
|
|
419
464
|
|
|
465
|
+
// THIS COMPUTER'S DEPLOYMENTS LIST (docs/tui.md, "The switcher"; awebai/oats#1390), the kernel's,
|
|
466
|
+
// through the shared cliDeploymentList. A read of it is a read (the reader's exec, ended on every
|
|
467
|
+
// way out), and one runs at a time: a read asked for while one is on its way is one more, after
|
|
468
|
+
// it, however many times it was asked, and the answer of the one on its way is not taken, since
|
|
469
|
+
// it may be of the list as it was before what asked again (a Remove). An add or a remove is a
|
|
470
|
+
// change (the reader's changeExec: never ended by the TUI, only at the adapter's own deadline),
|
|
471
|
+
// labelled so the line after leaving names the list. The kernel this TUI shipped with lists
|
|
472
|
+
// this computer's deployments in every release; one that does not (a checkout between the
|
|
473
|
+
// kernel's change and this one) is asked nothing in the run, and its "Update oats" is not said
|
|
474
|
+
// of the TUI's own kernel.
|
|
475
|
+
const listing = deploymentsListSupported(probe.cli);
|
|
476
|
+
/** The read on its way: `{ again }`, `again` once another was asked for meanwhile; or null. */
|
|
477
|
+
let listRead = null;
|
|
478
|
+
const listChange = (bin, argv, options, callback) => reader.changeExec(bin, argv, { ...options, label: LIST_CHANGE }, callback);
|
|
479
|
+
function readList() {
|
|
480
|
+
if (ended || !listing) return;
|
|
481
|
+
if (listRead !== null) { listRead.again = true; return; }
|
|
482
|
+
const mine = listRead = { again: false };
|
|
483
|
+
Promise.resolve()
|
|
484
|
+
.then(() => effects.deploymentList(probe.cli, { action: "list" }, { exec: reader.exec, env }))
|
|
485
|
+
.then((answer) => (answer.ok ? { rows: answer.value.rows } : { failure: answer.reason }), () => ({ failure: NOT_ASKED }))
|
|
486
|
+
.then((listed) => {
|
|
487
|
+
listRead = null;
|
|
488
|
+
if (mine.again) readList(); else heard({ listed });
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
/** Remove the row the store asked about (`{ path, name }`) from the list: nothing on disk is
|
|
492
|
+
* touched. Its answer goes to the store, which asks for the list again. */
|
|
493
|
+
function removeListed({ path, name }) {
|
|
494
|
+
Promise.resolve()
|
|
495
|
+
.then(() => effects.deploymentList(probe.cli, { action: "remove", path }, { exec: listChange, env }))
|
|
496
|
+
.then((answer) => heard({ removed: { path, name, ok: answer.ok, reason: answer.ok ? null : answer.reason } }), () => heard({ removed: { path, name, ok: false, reason: NOT_ASKED } }));
|
|
497
|
+
}
|
|
498
|
+
/** The deployment the run started in (from where it was started, or `--dir`), added to the list
|
|
499
|
+
* once, as the TUI's: best effort. A failure opens nothing less, and is said once, in the line
|
|
500
|
+
* under the sidebar's title. A row opened from the switcher is on the list already. */
|
|
501
|
+
function listStart(path) {
|
|
502
|
+
if (!listing) return;
|
|
503
|
+
Promise.resolve()
|
|
504
|
+
.then(() => effects.deploymentList(probe.cli, { action: "add", path, via: "tui" }, { exec: listChange, env }))
|
|
505
|
+
.then((answer) => { if (!answer.ok) heard({ notListed: answer.reason }); }, () => heard({ notListed: NOT_ASKED }));
|
|
506
|
+
}
|
|
507
|
+
|
|
420
508
|
/** What the boundary admits a request of deployment `id` against, read at every admission. */
|
|
421
509
|
const contextOf = (id) => actContext(state, id, clock());
|
|
422
510
|
/** Open the shared confirmation of a stop or a retire the store decided on (`{ n, verb, row,
|
|
@@ -558,20 +646,26 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
558
646
|
if (keys !== null && keys !== keysTo) { panel.focus(keys); keysTo = keys; }
|
|
559
647
|
}
|
|
560
648
|
/** The frame for the state now, with what the loop needs of it: the layout first, because the
|
|
561
|
-
* model's window is as tall, and its sentences as wide, as the list
|
|
562
|
-
*
|
|
563
|
-
*
|
|
649
|
+
* model's window is as tall, and its sentences as wide, as the sidebar's list it gives, and an
|
|
650
|
+
* overlay's window as tall as the area it gives (`body`). The open view of the sidebar is the
|
|
651
|
+
* one under the help or a confirmation; the switcher opens none and has no notice of a
|
|
652
|
+
* deployment. The last captures of the displayed tabs go with the model: they are the panel's,
|
|
653
|
+
* not the store's. */
|
|
564
654
|
function composed() {
|
|
565
|
-
const { size, g, m } = modelled();
|
|
566
|
-
return { size, g, made: frame(m, size) };
|
|
655
|
+
const { size, g, m, area } = modelled();
|
|
656
|
+
return { size, g, area, made: frame(m, size) };
|
|
567
657
|
}
|
|
658
|
+
/** The model for the state and the size now, and the width of the main area (`area`,
|
|
659
|
+
* views/frame.mjs mainArea), which the switcher stands in: the lines above its choices wrap to it. */
|
|
568
660
|
function modelled() {
|
|
569
661
|
const size = guard.size(), at = clock();
|
|
570
|
-
const
|
|
571
|
-
const
|
|
572
|
-
const
|
|
573
|
-
const
|
|
574
|
-
|
|
662
|
+
const under = state.view === "help" || state.view === "act" ? state.back : state.view;
|
|
663
|
+
const listing = under === "switcher";
|
|
664
|
+
const r = listing ? { notice: null, note: null } : roster(state, at);
|
|
665
|
+
const g = layout(r.notice, size, { note: r.note, ascii: state.ascii, outcome: listing ? null : outcomeOf(state), terminal: state.tabs.length > 0, open: listing ? null : under });
|
|
666
|
+
const area = mainArea(g, size.cols).cols;
|
|
667
|
+
const m = { ...model(state, { page: g.page, body: g.body, now: now(), at, cols: g.listCols, area }), screen: screens.get(state.terminal?.id) ?? null, screens };
|
|
668
|
+
return { size, g, m, area };
|
|
575
669
|
}
|
|
576
670
|
/** Where the panel stands for the state and the size now, as the Instances view gives it with
|
|
577
671
|
* the terminal's focus (views/frame.mjs panelPlace): measured whatever is drawn over it, and
|
|
@@ -591,14 +685,36 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
591
685
|
for (const event of events) {
|
|
592
686
|
if (event.input) { if (keysReady()) panel.input(event.input); }
|
|
593
687
|
else if (event.paste !== undefined) { if (keysReady()) panel.paste(event.paste); }
|
|
688
|
+
else if (event.keyboard !== undefined) answered(event.keyboard);
|
|
594
689
|
else if (event.back) {
|
|
595
|
-
parser =
|
|
690
|
+
parser = newParser();
|
|
596
691
|
if (took(reduce(state, { back: true, read: ++reads, rest: event.rest.length > 0 }, keymap))) return;
|
|
597
692
|
guard.draw();
|
|
693
|
+
} else if (event.chord !== undefined) {
|
|
694
|
+
// A chord from the terminal's focus is the leader then its key (the store's `led`): it never
|
|
695
|
+
// reaches the agent, and the rest of its read is dropped, as after the leader's key.
|
|
696
|
+
parser = newParser();
|
|
697
|
+
if (took(reduce(state, { chord: event.chord, read: ++reads, ...drawn, panel: placed()?.panel ?? null }, keymap))) return;
|
|
698
|
+
guard.draw();
|
|
598
699
|
}
|
|
599
700
|
}
|
|
600
701
|
watchThrough();
|
|
601
702
|
}
|
|
703
|
+
/** The terminal's answer to the protocol's query (`flags`), or none in time (null): the protocol is
|
|
704
|
+
* read from now on when the answer holds flag 1, and popped otherwise; an answer after that is
|
|
705
|
+
* not taken. The parser or the scanner that read the answer reads the rest of its read as it
|
|
706
|
+
* says; the other is made again. */
|
|
707
|
+
function answered(flags) {
|
|
708
|
+
if (kb !== "asking") return;
|
|
709
|
+
if (kbTimer !== null) { clearTimer(kbTimer); kbTimer = null; }
|
|
710
|
+
kb = confirmed(flags) ? flags : null;
|
|
711
|
+
guard.keyboardAnswered(kb !== null);
|
|
712
|
+
if (parser.keyboard === "asking") parser = newParser();
|
|
713
|
+
// What the scanner held as a possible beginning of the answer is the agent's after all.
|
|
714
|
+
const released = through.giveUp();
|
|
715
|
+
if (released.length && typing()) typed(released);
|
|
716
|
+
if (kb !== null) { state = reduce(state, { keyboard: kb }, keymap).state; guard.draw(); }
|
|
717
|
+
}
|
|
602
718
|
/** Whether the keys typed now reach the agent the state gives them to, the focused group's shown
|
|
603
719
|
* tab: the panel is fitted to the state first when it was not, also while no frame is written
|
|
604
720
|
* (the output blocked), so a tab or a group switched to takes what is typed after the switch,
|
|
@@ -618,10 +734,10 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
618
734
|
if (due !== null) throughTimer = setTimer(() => { throughTimer = null; guard.attempt(() => { if (typing()) typed(through.expire()); }); }, Math.max(0, due - now()));
|
|
619
735
|
}
|
|
620
736
|
const guard = createGuard({
|
|
621
|
-
stdin, stdout, proc, setTimer, clearTimer,
|
|
737
|
+
stdin, stdout, proc, setTimer, clearTimer, keyboard: kb === "asking",
|
|
622
738
|
frame() {
|
|
623
|
-
const { size, g, made } = composed();
|
|
624
|
-
drawn = { page: made.page, extent: made.extent, room: made.room, cols: g.listCols };
|
|
739
|
+
const { size, g, area, made } = composed();
|
|
740
|
+
drawn = { page: made.page, extent: made.extent, room: made.room, cols: g.listCols, area };
|
|
625
741
|
fitPanel(made);
|
|
626
742
|
const bytes = screen.render(made.rows, size, { full, cursor: made.cursor });
|
|
627
743
|
full = false;
|
|
@@ -678,10 +794,11 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
678
794
|
function act(events) {
|
|
679
795
|
const read = ++reads;
|
|
680
796
|
for (const event of events) {
|
|
797
|
+
if (event.keyboard !== undefined) { answered(event.keyboard); continue; }
|
|
681
798
|
if (took(reduce(state, "paste" in event ? { paste: event.paste, read } : { key: keyId(event), ...(typeof event.text === "string" && !event.alt ? { text: event.text } : {}), read, ...drawn, panel: placed()?.panel ?? null }, keymap))) return;
|
|
682
799
|
if (typing()) {
|
|
683
800
|
if (escTimer !== null) { clearTimer(escTimer); escTimer = null; }
|
|
684
|
-
through =
|
|
801
|
+
through = newThrough();
|
|
685
802
|
break;
|
|
686
803
|
}
|
|
687
804
|
}
|
|
@@ -695,7 +812,10 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
695
812
|
}
|
|
696
813
|
|
|
697
814
|
guard.start();
|
|
815
|
+
// At the wait's end what the key parser kept as a possible beginning of the answer is read as typed.
|
|
816
|
+
if (kb === "asking" && !ended) kbTimer = setTimer(() => { kbTimer = null; guard.attempt(() => { const released = parser.giveUp(); answered(null); if (released.length && !typing()) act(released); watchEscape(); }); }, Math.max(0, answerBy - now()));
|
|
698
817
|
guard.attempt(() => { if (!ended) Promise.resolve(reader.start()).catch(() => {}); });
|
|
818
|
+
if (found.ok) guard.attempt(() => { if (!ended) listStart(found.deployment); });
|
|
699
819
|
guard.attempt(() => guard.draw());
|
|
700
820
|
// Once a run, after the first frame: what runs that are gone left of their private servers
|
|
701
821
|
// (lib/panel.mjs sweep, which signals nothing and removes only what it can prove is dead).
|
|
@@ -703,11 +823,12 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
703
823
|
const end = await guard.done;
|
|
704
824
|
if (escTimer !== null) clearTimer(escTimer);
|
|
705
825
|
if (throughTimer !== null) clearTimer(throughTimer);
|
|
826
|
+
if (kbTimer !== null) clearTimer(kbTimer);
|
|
706
827
|
// After the alternate screen is left, so the message stays on the screen the user returns to.
|
|
707
828
|
// One line per change still running, to a terminal or a file only; the status never depends on it.
|
|
708
829
|
const running = reader.changes?.() ?? [];
|
|
709
830
|
if (running.length && effects.tellable(stderr)) {
|
|
710
|
-
try { stderr.write(running.map(({ label }) => `${ACT_WORDS.leaving(label?.verb ?? "change", displayLine(label?.name) ?? "an instance")}\n`).join("")); } catch { /* nothing to tell it to */ }
|
|
831
|
+
try { stderr.write(running.map(({ label }) => `${label === LIST_CHANGE ? LIST_WORDS.leaving : ACT_WORDS.leaving(label?.verb ?? "change", displayLine(label?.name) ?? "an instance")}\n`).join("")); } catch { /* nothing to tell it to */ }
|
|
711
832
|
}
|
|
712
833
|
if (end.error !== undefined) stderr.write(`oats: \`oats tui\` stopped on an internal error; the terminal was restored\n${errorLines(end.error).map((line) => ` ${line}\n`).join("")}`);
|
|
713
834
|
return end.status;
|
|
@@ -21,6 +21,7 @@ import { ownEllipsis, shownLines } from "./term/text.mjs";
|
|
|
21
21
|
import { textWidth } from "./term/width.mjs";
|
|
22
22
|
import { windowOf } from "./views/scroll.mjs";
|
|
23
23
|
import { SOUL_COLOURS } from "./views/souls.mjs";
|
|
24
|
+
import { leadRows } from "./views/switcher.mjs";
|
|
24
25
|
|
|
25
26
|
/** The widest the word column of the list may be, in cells. */
|
|
26
27
|
export const WORD_MAX = 20;
|
|
@@ -165,7 +166,7 @@ function build(state, at) {
|
|
|
165
166
|
const heading = (deployment, label, path = null) => {
|
|
166
167
|
const its = deploymentState(deployment), up = its.key === "live";
|
|
167
168
|
// A machine's rows are what it reported at the last roster read: that time stands on its
|
|
168
|
-
// heading only when the
|
|
169
|
+
// heading only when the time of this read (the help's top row) is another, so the heading of a machine read with
|
|
169
170
|
// this one is its name alone. A deployment that is not live has its state and short reason
|
|
170
171
|
// in the shared words instead, and no time.
|
|
171
172
|
const read = up && deployment.local === false ? clockTime(state.rosterAt) : null;
|
|
@@ -215,7 +216,7 @@ function build(state, at) {
|
|
|
215
216
|
// machine is in it: both read from the shared entries (`local`), never decided here.
|
|
216
217
|
const away = [...new Set(deployments.filter((d) => d.local === false && text(d.machine)).map((d) => d.machine))];
|
|
217
218
|
const machines = away.length, here = deployments.some((d) => d.local === true);
|
|
218
|
-
// Whether a list stands
|
|
219
|
+
// Whether a list stands in the sidebar: not for a deployment of this machine that was never
|
|
219
220
|
// observed, nor for a machine that is not live and has no row kept. Each has only its reason.
|
|
220
221
|
const observed = panel !== null && !gone && (local ? status === "observed" : live || instances.length > 0);
|
|
221
222
|
return {
|
|
@@ -283,7 +284,7 @@ function flatten(base, cols, ascii) {
|
|
|
283
284
|
* they changed. The flattening for the last width asked is kept beside it. */
|
|
284
285
|
const MADE_FROM = ["entries", "remote", "memory", "notes", "rosterAt", "collecting", "ctxs", "open", "collapsed", "cli", "home", "retiring", "ascii"];
|
|
285
286
|
let kept = null;
|
|
286
|
-
/** The roster of a state: the rows in drawn order and what the
|
|
287
|
+
/** The roster of a state: the rows in drawn order and what the sidebar's title says, for a list pane
|
|
287
288
|
* `cols` wide. Only `items` and `index` depend on the width; `rows`, the instances in drawn
|
|
288
289
|
* order, do not. `at` stamps a machine's panel before any roster outcome was taken, which
|
|
289
290
|
* never shows; it is passed on. */
|
|
@@ -502,17 +503,39 @@ function detailOf(state, r, item, now, acts) {
|
|
|
502
503
|
return { title: row.instance, facts };
|
|
503
504
|
}
|
|
504
505
|
|
|
505
|
-
/** The heading of the deployments
|
|
506
|
+
/** The heading of the rows of this computer's deployments list that this run does not serve: the TUI's own. */
|
|
506
507
|
export const OFFERED_SECTION = "On this machine, not opened";
|
|
507
|
-
|
|
508
|
+
|
|
509
|
+
/** The words of this computer's deployments list (awebai/oats#1390) where they are a line of their
|
|
510
|
+
* own: the add of the deployment the run started in, when it failed (the line under the sidebar's title,
|
|
511
|
+
* once; the kernel's message says what to do, and is shown as it came), and a change to the list
|
|
512
|
+
* still running as the TUI leaves. */
|
|
513
|
+
export const LIST_WORDS = Object.freeze({
|
|
514
|
+
notAdded: (message) => Object.freeze([{ own: "This deployment was not added to this computer's list: " }, { shown: message }]),
|
|
515
|
+
/** An add or a remove still running as the TUI leaves: one line, after the screen is left. */
|
|
516
|
+
leaving: "oats: a change to this computer's list of deployments is still running; `oats deployments` shows the list.",
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
/** What the switcher says above its rows, as views/switcher.mjs leadRows reads it. */
|
|
520
|
+
const leadOf = (state) => ({ said: state.switcher.line, failure: state.listed.failure?.message ?? null, removing: state.switcher.removing !== null });
|
|
521
|
+
/** How many rows stand above the switcher's choices in an area `cols` wide (the switcher's is the
|
|
522
|
+
* whole width): what happened (`line`), that the last read of the list failed, and a Remove
|
|
523
|
+
* asked, as views/switcher.mjs leadRows draws them. The window of the choices is that much
|
|
524
|
+
* shorter, so none is hidden for them. */
|
|
525
|
+
export function switcherLead(state, cols) {
|
|
526
|
+
return leadRows(leadOf(state), Number.isInteger(cols) && cols > 0 ? cols : 80, { ascii: state.ascii }).length;
|
|
527
|
+
}
|
|
508
528
|
|
|
509
529
|
/** The switcher's rows for a state, top to bottom: the workspaces this run can show, as the
|
|
510
530
|
* shared home lists and words them; then the ones matched to no workspace under the shared
|
|
511
|
-
* heading; then the
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
*
|
|
515
|
-
*
|
|
531
|
+
* heading; then the rows of this computer's deployments list that this run does not serve, in
|
|
532
|
+
* the kernel's order, under the TUI's own. A served deployment's id and a row's path are both
|
|
533
|
+
* canonical, so a deployment opened in this run is never offered again.
|
|
534
|
+
* An item is `{ heading, shared }`, or a choice: `{ key, label, place, notLiveText, open,
|
|
535
|
+
* primary }` for a view (`primary` is the deployment Enter opens) and `{ key, label, place,
|
|
536
|
+
* path, state, refused }` for a row of the list (`state` the kernel's: views/switcher.mjs says a
|
|
537
|
+
* stale one in words). `keys` are the choices in order; `selected` is the key the selection
|
|
538
|
+
* stands on (the first choice when the state's own is not listed). */
|
|
516
539
|
export function switcher(state, at = new Date(0).toISOString()) {
|
|
517
540
|
const held = heldOf(state, at), views = viewModel(held, TERMS);
|
|
518
541
|
const rows = workspaceChoiceRows(workspaceChoices(held, TERMS, views));
|
|
@@ -524,17 +547,17 @@ export function switcher(state, at = new Date(0).toISOString()) {
|
|
|
524
547
|
});
|
|
525
548
|
const shown = rows.filter((row) => choiceMatches(row, query));
|
|
526
549
|
const matched = shown.filter((row) => !row.unattached).map(choice), unmatched = shown.filter((row) => row.unattached).map(choice);
|
|
527
|
-
const
|
|
528
|
-
|
|
550
|
+
const unserved = state.listed.rows.filter((row) => !state.ctxs.includes(row.path));
|
|
551
|
+
const offered = unserved
|
|
552
|
+
.map(({ path, name, state: listedState }) => ({ key: `path\u0000${path}`, label: name, place: shortPath(path, { home: state.home }), path, state: listedState, refused: state.switcher.refused === path }))
|
|
529
553
|
.filter((item) => choiceMatches(item, query));
|
|
530
554
|
const items = [
|
|
531
555
|
...matched,
|
|
532
556
|
...(unmatched.length ? [{ heading: UNMATCHED_SECTION, shared: true }, ...unmatched] : []),
|
|
533
557
|
...(offered.length ? [{ heading: OFFERED_SECTION, shared: false }, ...offered] : []),
|
|
534
|
-
...(state.offered.limited ? [{ own: MORE_FOLDERS }] : []),
|
|
535
558
|
];
|
|
536
559
|
const keys = items.filter((item) => item.key !== undefined).map((item) => item.key);
|
|
537
|
-
const total = rows.length +
|
|
560
|
+
const total = rows.length + unserved.length;
|
|
538
561
|
return {
|
|
539
562
|
items, keys, selected: keys.includes(state.switcher.selected) ? state.switcher.selected : keys[0] ?? null,
|
|
540
563
|
empty: keys.length ? null : total ? "nomatch" : "none",
|
|
@@ -632,19 +655,31 @@ function paletteView(state, page, at) {
|
|
|
632
655
|
};
|
|
633
656
|
}
|
|
634
657
|
|
|
658
|
+
/** The rows the switcher's window has in an area `body` rows tall and `cols` wide: the lines above
|
|
659
|
+
* the choices take theirs (switcherLead), and the filter field one while it is typed or kept
|
|
660
|
+
* (views/frame.mjs). */
|
|
661
|
+
export const switcherHeight = (state, body, cols) => Math.max(1, body - switcherLead(state, cols) - (state.switcher.editing || state.switcher.query ? 1 : 0));
|
|
662
|
+
|
|
635
663
|
/** What the views draw for a state. For the Instances view, in a list pane `page` rows tall and
|
|
636
|
-
* `cols` wide: the
|
|
637
|
-
* instance's detail
|
|
638
|
-
*
|
|
639
|
-
|
|
664
|
+
* `cols` wide: the title's facts, the rows of the window with their marks, and the selected
|
|
665
|
+
* instance's detail; the Souls and the Capabilities views' lists in the same pane, also under the
|
|
666
|
+
* help, which leaves the sidebar beside it (views/frame.mjs). For the switcher, the palette and
|
|
667
|
+
* the spawn prompt, in an area `body` rows tall (`page` when none is given): the window of their
|
|
668
|
+
* rows; `area` is the main area's width (`cols` when none is given), which the lines above the
|
|
669
|
+
* switcher's choices wrap to (views/frame.mjs mainArea). Only the rows in the pane are worked out. */
|
|
670
|
+
export function model(state, { page, body = page, now, at, cols, area = cols }) {
|
|
640
671
|
const r = roster(state, at, cols);
|
|
672
|
+
// The view under the help, or under a confirmation, decides what the sidebar says.
|
|
673
|
+
const under = state.view === "help" || state.view === "act" ? state.back : state.view;
|
|
641
674
|
const common = {
|
|
642
675
|
view: state.view, focus: state.focus, ascii: state.ascii, actions: state.actions,
|
|
643
676
|
// The filter of the view shown: the Souls view has one of its own.
|
|
644
677
|
filter: state.view === "souls" ? state.souls.filter : state.view === "capabilities" ? state.capabilities.filter : state.filter,
|
|
645
678
|
workspace: r.workspace, machines: r.machines, here: r.here, machine: r.machine, counts: r.counts, readAt: r.readAt, notice: r.notice, note: r.note, empty: r.empty, observed: r.observed,
|
|
646
679
|
detailTop: state.detailTop, helpTop: state.helpTop, open: state.open !== null,
|
|
647
|
-
detachKey: state.detachKey, opening: state.opening, openable: false,
|
|
680
|
+
detachKey: state.detachKey, opening: state.opening, openable: false,
|
|
681
|
+
// The chords, `[key id, does]`, while the terminal confirms the kitty keyboard protocol; else null.
|
|
682
|
+
chords: state.keyboard === null ? null : [...state.chords],
|
|
648
683
|
terminal: state.terminal, onTerminal: false,
|
|
649
684
|
// The panel's groups (views/frame.mjs), the split and the focused group; the panel stands while
|
|
650
685
|
// any tab is open. `tabs` is the focused group's strip: each tab in order, the shown one marked,
|
|
@@ -652,35 +687,35 @@ export function model(state, { page, now, at, cols }) {
|
|
|
652
687
|
split: state.split, group: state.group, panelOpen: state.tabs.length > 0, groups: groupsOf(state),
|
|
653
688
|
tabs: groupsOf(state)[state.group].tabs,
|
|
654
689
|
act: state.view === "act" && state.act ? actView(state) : null,
|
|
655
|
-
// The leader waits for its key (the
|
|
656
|
-
leader: state.leader?.waiting === true, palette: state.palette === null ? null : paletteView(state,
|
|
657
|
-
souls:
|
|
658
|
-
capabilities:
|
|
659
|
-
spawn: state.spawn === null ? null : spawnView(state,
|
|
660
|
-
// The line
|
|
690
|
+
// The leader waits for its key (the cheat sheet is its hint), and the palette, while it is open.
|
|
691
|
+
leader: state.leader?.waiting === true, palette: state.palette === null ? null : paletteView(state, body, at),
|
|
692
|
+
souls: under === "souls" ? soulsView(state, page, at) : null,
|
|
693
|
+
capabilities: under === "capabilities" ? capabilitiesView(state, page, at) : null,
|
|
694
|
+
spawn: state.spawn === null ? null : spawnView(state, body, at),
|
|
695
|
+
// The line under the sidebar's title: the last outcome, else a spawn under way (outcomeOf).
|
|
661
696
|
outcome: outcomeOf(state),
|
|
662
697
|
};
|
|
663
|
-
// The view under the help, or under a confirmation, decides what the header says.
|
|
664
|
-
const under = state.view === "help" || state.view === "act" ? state.back : state.view;
|
|
665
698
|
if (under === "switcher") {
|
|
666
699
|
const s = switcher(state, at);
|
|
667
700
|
const at_ = s.selected === null ? -1 : s.items.findIndex((item) => item.key === s.selected);
|
|
668
|
-
// The
|
|
669
|
-
//
|
|
670
|
-
const win = windowOf({ top: state.switcher.top, count: s.items.length, height:
|
|
701
|
+
// The lines above the rows take the pane's rows, and so does the filter field while it is
|
|
702
|
+
// typed or kept: the window is that much shorter, so no choice is hidden for them (switcherHeight).
|
|
703
|
+
const win = windowOf({ top: state.switcher.top, count: s.items.length, height: switcherHeight(state, body, area), keep: state.switcher.loose ? -1 : at_ });
|
|
671
704
|
return {
|
|
672
705
|
...common, under, list: [], above: 0, below: 0, wordWidth: 0, detail: null,
|
|
673
|
-
// Nothing of a workspace stands in the
|
|
706
|
+
// Nothing of a workspace stands in the sidebar while the switcher is shown.
|
|
674
707
|
workspace: "", machines: 0, here: false, machine: null, counts: [], readAt: null, notice: null, note: null, empty: null, observed: true, outcome: null,
|
|
675
708
|
filter: Object.freeze({ editing: state.switcher.editing, query: state.switcher.query }),
|
|
676
709
|
switcher: {
|
|
677
710
|
rows: s.items.slice(win.top, win.top + win.size).map((item) => (item.key === undefined ? item : { ...item, selected: item.key === s.selected })),
|
|
678
|
-
above: win.above, below: win.below, empty: s.empty,
|
|
711
|
+
above: win.above, below: win.below, empty: s.empty, ...leadOf(state),
|
|
712
|
+
// Whether the remove key acts on the selected row: a row of the list (the cheat sheet names it then).
|
|
713
|
+
removable: s.items.some((item) => item.key === s.selected && item.path !== undefined),
|
|
679
714
|
},
|
|
680
715
|
};
|
|
681
716
|
}
|
|
682
717
|
const selected = state.selected === null ? -1 : r.index.get(state.selected) ?? -1;
|
|
683
|
-
// What the detail
|
|
718
|
+
// What the detail and Enter read of the selected row is worked out once per paint.
|
|
684
719
|
const row = selected >= 0 ? r.items[selected].row : null, acts = row ? instanceActs(row) : null;
|
|
685
720
|
const decision = row ? openDecision(state, row, acts) : null;
|
|
686
721
|
// The window holds the selection, unless the list was scrolled away from it on purpose.
|
|
@@ -693,10 +728,6 @@ export function model(state, { page, now, at, cols }) {
|
|
|
693
728
|
// Enter opens the selected agent's terminal now, or (`onTerminal`) goes to the one open on it.
|
|
694
729
|
openable: decision?.open === true && state.opening === null,
|
|
695
730
|
onTerminal: row !== null && state.terminal !== null && state.terminal.id === instanceId(row),
|
|
696
|
-
// The acts whose key opens a confirmation now, read from the same instanceActs answer: the
|
|
697
|
-
// footer names them. A key not named still answers, with the line that says why. A secondary
|
|
698
|
-
// act (Retire while a retire runs) opens on its key and is not named.
|
|
699
|
-
actable: row && state.opening === null ? ACT_VERBS.filter((verb) => !acts.acts.some((each) => each.verb === verb && each.secondary) && actDecision(state, row, acts, verb).open) : [],
|
|
700
731
|
switcher: null,
|
|
701
732
|
};
|
|
702
733
|
}
|
|
@@ -722,7 +753,7 @@ export function localDeployments(state, at) {
|
|
|
722
753
|
return heldDeployments(held).filter((w) => !w.remote).map((w) => ({ id: w.id, remote: false, instances: rowsOf(held, w.id) }));
|
|
723
754
|
}
|
|
724
755
|
|
|
725
|
-
/** The four acts on an instance, in the order the help, the
|
|
756
|
+
/** The four acts on an instance, in the order the help, the palette and the keys know them. */
|
|
726
757
|
export const ACT_VERBS = Object.freeze(["stop", "retire", "start", "restart"]);
|
|
727
758
|
const DONE = Object.freeze({ stop: "stopped", retire: "retired", start: "started", restart: "restarted" });
|
|
728
759
|
/** The TUI's own words around the acts (docs/tui.md, "Stopping, starting, restarting and
|
|
@@ -763,7 +794,7 @@ export function buttonLabel(offer, verb, phase) {
|
|
|
763
794
|
export const BUTTON_ORDER = Object.freeze(["close", "refresh", "check-again", "apply"]);
|
|
764
795
|
|
|
765
796
|
/** Whether an act key on `row` opens a confirmation, and what the line says when it does not.
|
|
766
|
-
* `acts` is the row's instanceActs answer, read once per paint (the
|
|
797
|
+
* `acts` is the row's instanceActs answer, read once per paint (the palette) or per key, as
|
|
767
798
|
* openDecision reads it; nothing here decides which acts a row has.
|
|
768
799
|
* { open: true, verb, id, name, kind, machine, label, home } a confirmation opens: `kind`
|
|
769
800
|
* "lifecycle" for stop and retire (the shared confirmation), "start" for the TUI's own
|
|
@@ -968,7 +999,8 @@ function soulsView(state, page, at) {
|
|
|
968
999
|
// Nothing held: the first read is in flight (or the deployment not read yet), or it failed.
|
|
969
1000
|
return reason && !s.held.reading ? { ...base, state: "failed", failure: soulCatalogFailure(reason) } : { ...base, state: "reading" };
|
|
970
1001
|
}
|
|
971
|
-
|
|
1002
|
+
// A failed re-read's heading: the accordion's row above it names the view, so it has no word of its own.
|
|
1003
|
+
const heading = reason ? { label: "", path: null, state: null, short: soulCatalogFailure(reason), readAt: clockTime(entry.observedAt) } : null;
|
|
972
1004
|
const state_ = !s.all.length ? "none" : !s.rows.length ? "nomatch" : "rows";
|
|
973
1005
|
const height = Math.max(1, page - (heading ? 1 : 0));
|
|
974
1006
|
const at_ = s.selected ? s.rows.indexOf(s.selected) : -1;
|
|
@@ -1080,7 +1112,7 @@ function capabilitiesView(state, page, at) {
|
|
|
1080
1112
|
if (!c.local) return { ...base, state: "none" };
|
|
1081
1113
|
const entry = c.held?.entry ?? null, reason = entry?.reason ?? null;
|
|
1082
1114
|
if (!c.listed) return reason && !c.held.reading ? { ...base, state: "failed", failure: catalogFailure("capabilities", reason) } : { ...base, state: "reading" };
|
|
1083
|
-
const heading = c.heading ? { label: "
|
|
1115
|
+
const heading = c.heading ? { label: "", path: null, state: null, short: catalogFailure("capabilities", reason), readAt: clockTime(entry.observedAt) } : null;
|
|
1084
1116
|
const state_ = !c.all.length ? "none" : !c.keys.length ? "nomatch" : "rows";
|
|
1085
1117
|
const at_ = c.items.findIndex((item) => item.key !== undefined && item.key === c.selected);
|
|
1086
1118
|
const win = windowOf({ top: v.top, count: c.items.length, height: capabilitiesHeight(c, page), keep: v.loose ? -1 : at_ });
|