@awebai/oats 0.65.0 → 0.67.1
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 +74 -20
- package/docs/capabilities.md +4 -4
- package/docs/capability-manifest.schema.json +1 -1
- package/docs/desktop-cli-api.md +222 -10
- package/docs/desktop.md +101 -22
- package/docs/implementation.md +16 -6
- package/docs/integrations.md +1 -1
- package/docs/official-catalog.md +2 -2
- package/docs/packages.md +7 -7
- package/docs/release-lane.md +16 -0
- package/docs/release-notes/v0.66.0.md +183 -0
- package/docs/release-notes/v0.67.0.md +366 -0
- package/docs/release-notes/v0.67.1.md +64 -0
- package/docs/servers.md +5 -4
- package/docs/souls-and-instances.md +20 -3
- package/docs/tui.md +658 -143
- package/docs/upgrading.md +107 -25
- package/docs/workspaces.md +9 -2
- package/lib/capability-contract.mjs +2 -2
- package/lib/core.mjs +126 -54
- package/lib/deployments.mjs +21 -5
- package/lib/instance-color.mjs +58 -0
- package/lib/instance-inspect.mjs +107 -23
- package/lib/instance-lifecycle.mjs +21 -1
- package/lib/instance-naming.mjs +187 -0
- package/lib/instance-resolution.mjs +5 -1
- package/lib/materialize.mjs +62 -11
- package/lib/servers.mjs +15 -6
- package/lib/soul-composition.mjs +7 -3
- package/package-catalog.json +2 -2
- package/package.json +1 -1
- package/packages/client/cli-adapter.mjs +37 -5
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/composed-gate.mjs +10 -2
- package/packages/client/deployment-data.mjs +5 -0
- package/packages/client/deployment-identity.mjs +40 -0
- package/packages/client/deployment-panel.mjs +3 -1
- package/packages/client/inspect-boundary.mjs +11 -7
- package/packages/client/inspect-cache.mjs +2 -2
- package/packages/client/instance-name.mjs +28 -0
- package/packages/client/instance-presentation.mjs +11 -0
- package/packages/client/keymap.mjs +99 -11
- package/packages/client/keys-file.mjs +122 -0
- package/packages/client/machine-contract.mjs +1 -5
- package/packages/client/own-codes.mjs +4 -2
- package/packages/client/panel-views.mjs +62 -9
- package/packages/client/spawn-naming.mjs +31 -0
- package/packages/client/spawn-preview-cli.mjs +22 -7
- package/packages/client/spawn-preview-contract.mjs +24 -0
- package/packages/client/spawn-preview-facts.mjs +8 -4
- package/packages/client/spawn-preview.mjs +47 -2
- 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 +9 -8
- package/packages/tui/lib/actions.mjs +108 -64
- package/packages/tui/lib/client.mjs +8 -3
- package/packages/tui/lib/config.mjs +208 -26
- package/packages/tui/lib/main.mjs +91 -20
- package/packages/tui/lib/model.mjs +167 -61
- package/packages/tui/lib/read.mjs +53 -1
- package/packages/tui/lib/store.mjs +156 -47
- package/packages/tui/lib/term/keys.mjs +150 -34
- package/packages/tui/lib/term/kitty.mjs +223 -0
- package/packages/tui/lib/term/through.mjs +174 -27
- package/packages/tui/lib/term/tty.mjs +43 -12
- package/packages/tui/lib/views/frame.mjs +158 -79
- package/packages/tui/lib/views/help.mjs +143 -21
- package/packages/tui/lib/views/instances.mjs +59 -20
- package/packages/tui/lib/views/palette.mjs +14 -4
- package/packages/tui/lib/views/souls.mjs +2 -2
- package/packages/tui/lib/views/switcher.mjs +6 -1
- package/skills/oats-getting-started/SKILL.md +107 -34
|
@@ -13,13 +13,14 @@ import { homedir } from "node:os";
|
|
|
13
13
|
import { resolve } from "node:path";
|
|
14
14
|
import { bindings } from "./actions.mjs";
|
|
15
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
|
-
import { loadConfig } from "./config.mjs";
|
|
16
|
+
import { loadConfig, loadKeys } from "./config.mjs";
|
|
17
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, probeKernel, realpath, startExec, tellable } from "./read.mjs";
|
|
19
|
+
import { CHANGE_FILES, admitDeployment, createIdentityReads, 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";
|
|
@@ -92,8 +93,9 @@ function errorLines(error) {
|
|
|
92
93
|
* factories are the shared home's preview, apply boundary and transaction, replaceable so a test
|
|
93
94
|
* can answer them. `deploymentList` is the shared cliDeploymentList (this computer's deployments
|
|
94
95
|
* list, through the kernel: awebai/oats#1390), and `startExec` the exec it is handed before the
|
|
95
|
-
* terminal is taken; replaceable so a test can answer the list.
|
|
96
|
-
|
|
96
|
+
* terminal is taken; replaceable so a test can answer the list. `loadKeys` reads keys.json, the
|
|
97
|
+
* chord family (lib/config.mjs), replaceable so no test reads a user's file. */
|
|
98
|
+
const EFFECTS = Object.freeze({ loadConfig, loadKeys, findDeployment, probeKernel, createReader, createIdentityReads, deploymentList: cliDeploymentList, startExec, admitDeployment, prepareRemoteTerm, createPanel, sweep,
|
|
97
99
|
runDir: CHANGE_FILES.dir, removeDir: CHANGE_FILES.remove, realpath, tellable, startInstance, createLifecycleConfirmation, createLifecycleBoundary, createSoulCatalog,
|
|
98
100
|
createCapabilityCatalog, createSpawnPreview, createSpawnApplyBoundary, createSpawnTransaction });
|
|
99
101
|
|
|
@@ -126,7 +128,15 @@ export function createRunTimers({ setTimer, clearTimer }) {
|
|
|
126
128
|
* the terminal; the user's tui.json; the deployment; the kernel it shipped with; and, for a start
|
|
127
129
|
* outside every deployment with no `--dir`, this computer's deployments list, read through that
|
|
128
130
|
* kernel. */
|
|
129
|
-
|
|
131
|
+
/** How long a run waits for the terminal's answer to the kitty keyboard protocol's query, in
|
|
132
|
+
* milliseconds, before it pops the protocol and reads keys as before for the rest of the run
|
|
133
|
+
* (docs/tui.md, "Chords"). A terminal answers as it reads the query, before any key typed after
|
|
134
|
+
* it, so the wait only bounds a terminal that never answers; it is long enough for a slow link. */
|
|
135
|
+
export const KEYBOARD_WAIT_MS = 2000;
|
|
136
|
+
|
|
137
|
+
/** `keyboard`: whether the run asks the terminal for the kitty keyboard protocol (term/tty.mjs PUSH,
|
|
138
|
+
* QUERY). Every run does; a test of a terminal that is never asked passes false. */
|
|
139
|
+
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 }) {
|
|
130
140
|
const effects = given === EFFECTS ? EFFECTS : { ...EFFECTS, ...given };
|
|
131
141
|
const { options, error } = parseArgs(argv);
|
|
132
142
|
if (error) { stderr.write(`${error}\n`); return 1; }
|
|
@@ -135,6 +145,9 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
135
145
|
if (!isTerminal({ stdin, stdout, env })) { stderr.write(`${NO_TERMINAL}\n`); return 1; }
|
|
136
146
|
const config = effects.loadConfig({ env, home, platform: proc.platform });
|
|
137
147
|
if (!config.ok) { stderr.write(config.lines.map((line) => `${line}\n`).join("")); return 1; }
|
|
148
|
+
// keys.json, the chord family (docs/tui.md, "Switch to Ctrl+Shift"): read once, here, and never
|
|
149
|
+
// a reason not to start: what is wrong with it is the default, and the help says why.
|
|
150
|
+
const keysRead = effects.loadKeys({ env, home });
|
|
138
151
|
const found = effects.findDeployment(resolve(cwd(), options.dir ?? "."));
|
|
139
152
|
// A `--dir` that is in no deployment is refused as it is: what was asked for is not there.
|
|
140
153
|
if (!found.ok && options.dir !== null) { stderr.write(`${noDeployment(found.dir)}\n`); return 1; }
|
|
@@ -154,14 +167,23 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
154
167
|
const clock = () => new Date(now()).toISOString();
|
|
155
168
|
const look = glyphs(env, { ascii: options.ascii || config.ascii });
|
|
156
169
|
const screen = createScreen({ ...look, color: colorEnabled(env) });
|
|
157
|
-
let
|
|
158
|
-
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 });
|
|
170
|
+
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, keysRead });
|
|
159
171
|
const keymap = bindings(state.actions);
|
|
172
|
+
// THE KITTY KEYBOARD PROTOCOL (docs/tui.md, "Chords"): asked for as the terminal is taken (the
|
|
173
|
+
// guard's PUSH and QUERY), "asking" until it answers or KEYBOARD_WAIT_MS passes, then the flags
|
|
174
|
+
// it confirmed (flag 1 held), or null for the rest of the run. The key parser and the scanner
|
|
175
|
+
// below are made with it, and each reads the answer itself when it comes through it.
|
|
176
|
+
let kb = keyboard ? "asking" : null, kbTimer = null;
|
|
177
|
+
/** The clock time the wait for the answer ends: what may begin it is held up to then. */
|
|
178
|
+
const answerBy = keyboard ? now() + KEYBOARD_WAIT_MS : null;
|
|
179
|
+
const newParser = () => createKeyParser({ now, keyboard: kb, chords: state.chords, leader: state.leaderKey, answerBy });
|
|
180
|
+
let parser = newParser();
|
|
160
181
|
// While a terminal has the focus the bytes typed go to the agent: this scanner takes from them
|
|
161
|
-
// only the back key and a bracketed paste (term/through.mjs). A new one each time the
|
|
162
|
-
// takes the focus, so nothing held from before is typed into it.
|
|
182
|
+
// only the back key, the chords and a bracketed paste (term/through.mjs). A new one each time the
|
|
183
|
+
// terminal takes the focus, so nothing held from before is typed into it.
|
|
163
184
|
const backKey = backKeySequences(state.detachKey);
|
|
164
|
-
|
|
185
|
+
const newThrough = () => createThrough({ sequences: backKey, now, keyboard: kb, leader: state.leaderKey, chords: state.chords, answerBy });
|
|
186
|
+
let through = newThrough(), throughTimer = null;
|
|
165
187
|
if (listedAtStart) state = reduce(state, { listed: { rows: listedAtStart } }, keymap).state;
|
|
166
188
|
// What the last frame drew, for the store: how tall the list pane is and how far the other
|
|
167
189
|
// pane scrolls. The store holds no size of its own; the panel's room goes with each key as it
|
|
@@ -412,12 +434,18 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
412
434
|
if (effect === "suspend") guard.suspend();
|
|
413
435
|
if (effect === "redraw") guard.reassert(); // the modes again, then the whole screen
|
|
414
436
|
if (effect === null || typeof effect !== "object") return false;
|
|
415
|
-
if (effect.list) readList();
|
|
437
|
+
if (effect.list) readList({ identify: effect.identify === true });
|
|
416
438
|
if (effect.remove) removeListed(effect.remove);
|
|
417
439
|
if (effect.admit !== undefined) {
|
|
418
440
|
const admitted = effects.admitDeployment(effect.admit);
|
|
419
441
|
took(reduce(state, admitted.ok ? { admitted: admitted.deployment, at: clock() } : { refused: effect.admit }, keymap));
|
|
420
442
|
}
|
|
443
|
+
if (effect.join) {
|
|
444
|
+
// Each listed deployment of the workspace picked, asked whether it is a deployment now, as a picked row is.
|
|
445
|
+
const answers = effect.join.paths.map((path) => [path, effects.admitDeployment(path)]);
|
|
446
|
+
const canonical = new Map(answers.filter(([, a]) => a.ok).map(([path, a]) => [path, a.deployment]));
|
|
447
|
+
took(reduce(state, { joined: { admitted: [...canonical.values()], opens: effect.join.opens.map((id) => canonical.get(id) ?? id) }, at: clock() }, keymap));
|
|
448
|
+
}
|
|
421
449
|
if (effect.abandon) giveUpPreflight();
|
|
422
450
|
// A tab shown (`show`) needs nothing here: the frame after it brings the panel to it (fitPanel).
|
|
423
451
|
if (effect.close !== undefined) for (const id of effect.close) closeTerminal(id);
|
|
@@ -458,18 +486,32 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
458
486
|
/** The read on its way: `{ again }`, `again` once another was asked for meanwhile; or null. */
|
|
459
487
|
let listRead = null;
|
|
460
488
|
const listChange = (bin, argv, options, callback) => reader.changeExec(bin, argv, { ...options, label: LIST_CHANGE }, callback);
|
|
461
|
-
|
|
489
|
+
/** `identify`: once the list has answered, read the identities of its rows (`identify` below). A read asked
|
|
490
|
+
* for while one is on its way keeps the wish of either. */
|
|
491
|
+
function readList({ identify: wanted = false } = {}) {
|
|
462
492
|
if (ended || !listing) return;
|
|
463
|
-
if (listRead !== null) { listRead.again = true; return; }
|
|
464
|
-
const mine = listRead = { again: false };
|
|
493
|
+
if (listRead !== null) { listRead.again = true; listRead.identify ||= wanted; return; }
|
|
494
|
+
const mine = listRead = { again: false, identify: wanted };
|
|
465
495
|
Promise.resolve()
|
|
466
496
|
.then(() => effects.deploymentList(probe.cli, { action: "list" }, { exec: reader.exec, env }))
|
|
467
497
|
.then((answer) => (answer.ok ? { rows: answer.value.rows } : { failure: answer.reason }), () => ({ failure: NOT_ASKED }))
|
|
468
498
|
.then((listed) => {
|
|
469
499
|
listRead = null;
|
|
470
|
-
if (mine.again) readList(
|
|
500
|
+
if (mine.again) return readList({ identify: mine.identify });
|
|
501
|
+
heard({ listed });
|
|
502
|
+
if (mine.identify) identify();
|
|
471
503
|
});
|
|
472
504
|
}
|
|
505
|
+
// THE IDENTITY READS (lib/read.mjs createIdentityReads; docs/tui.md, "The switcher"): the rows of this
|
|
506
|
+
// computer's list that this run does not serve and that the kernel says are deployments, each read for
|
|
507
|
+
// its workspace's identity, one at a time, so the switcher puts it in its workspace's row. At the start
|
|
508
|
+
// and when the switcher is opened or refreshed, never on a timer; their answers come in as the screen
|
|
509
|
+
// is used. A suspend gives the run up (what a stopped TUI reads is no evidence), as it does the cycles.
|
|
510
|
+
const identities = effects.createIdentityReads({ cli: probe.cli, exec: reader.exec, env, onRead: (identity) => heard({ identity }) });
|
|
511
|
+
function identify() {
|
|
512
|
+
if (ended) return;
|
|
513
|
+
identities.start(state.listed.rows.filter((row) => row.state === "ok" && !state.ctxs.includes(row.path)).map((row) => row.path));
|
|
514
|
+
}
|
|
473
515
|
/** Remove the row the store asked about (`{ path, name }`) from the list: nothing on disk is
|
|
474
516
|
* touched. Its answer goes to the store, which asks for the list again. */
|
|
475
517
|
function removeListed({ path, name }) {
|
|
@@ -667,14 +709,36 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
667
709
|
for (const event of events) {
|
|
668
710
|
if (event.input) { if (keysReady()) panel.input(event.input); }
|
|
669
711
|
else if (event.paste !== undefined) { if (keysReady()) panel.paste(event.paste); }
|
|
712
|
+
else if (event.keyboard !== undefined) answered(event.keyboard);
|
|
670
713
|
else if (event.back) {
|
|
671
|
-
parser =
|
|
714
|
+
parser = newParser();
|
|
672
715
|
if (took(reduce(state, { back: true, read: ++reads, rest: event.rest.length > 0 }, keymap))) return;
|
|
673
716
|
guard.draw();
|
|
717
|
+
} else if (event.chord !== undefined) {
|
|
718
|
+
// A chord from the terminal's focus is the leader then its key (the store's `led`): it never
|
|
719
|
+
// reaches the agent, and the rest of its read is dropped, as after the leader's key.
|
|
720
|
+
parser = newParser();
|
|
721
|
+
if (took(reduce(state, { chord: event.chord, read: ++reads, ...drawn, panel: placed()?.panel ?? null }, keymap))) return;
|
|
722
|
+
guard.draw();
|
|
674
723
|
}
|
|
675
724
|
}
|
|
676
725
|
watchThrough();
|
|
677
726
|
}
|
|
727
|
+
/** The terminal's answer to the protocol's query (`flags`), or none in time (null): the protocol is
|
|
728
|
+
* read from now on when the answer holds flag 1, and popped otherwise; an answer after that is
|
|
729
|
+
* not taken. The parser or the scanner that read the answer reads the rest of its read as it
|
|
730
|
+
* says; the other is made again. */
|
|
731
|
+
function answered(flags) {
|
|
732
|
+
if (kb !== "asking") return;
|
|
733
|
+
if (kbTimer !== null) { clearTimer(kbTimer); kbTimer = null; }
|
|
734
|
+
kb = confirmed(flags) ? flags : null;
|
|
735
|
+
guard.keyboardAnswered(kb !== null);
|
|
736
|
+
if (parser.keyboard === "asking") parser = newParser();
|
|
737
|
+
// What the scanner held as a possible beginning of the answer is the agent's after all.
|
|
738
|
+
const released = through.giveUp();
|
|
739
|
+
if (released.length && typing()) typed(released);
|
|
740
|
+
if (kb !== null) { state = reduce(state, { keyboard: kb }, keymap).state; guard.draw(); }
|
|
741
|
+
}
|
|
678
742
|
/** Whether the keys typed now reach the agent the state gives them to, the focused group's shown
|
|
679
743
|
* tab: the panel is fitted to the state first when it was not, also while no frame is written
|
|
680
744
|
* (the output blocked), so a tab or a group switched to takes what is typed after the switch,
|
|
@@ -694,7 +758,7 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
694
758
|
if (due !== null) throughTimer = setTimer(() => { throughTimer = null; guard.attempt(() => { if (typing()) typed(through.expire()); }); }, Math.max(0, due - now()));
|
|
695
759
|
}
|
|
696
760
|
const guard = createGuard({
|
|
697
|
-
stdin, stdout, proc, setTimer, clearTimer,
|
|
761
|
+
stdin, stdout, proc, setTimer, clearTimer, keyboard: kb === "asking",
|
|
698
762
|
frame() {
|
|
699
763
|
const { size, g, area, made } = composed();
|
|
700
764
|
drawn = { page: made.page, extent: made.extent, room: made.room, cols: g.listCols, area };
|
|
@@ -734,7 +798,7 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
734
798
|
// The run's directory goes last, made for whichever of the two needed it first: the reader
|
|
735
799
|
// removes it only when it wrote a change there, and one it cannot remove (a change still
|
|
736
800
|
// writing) stays.
|
|
737
|
-
onEnd() { ended = true; spawnTimers.end(); dismiss(confirmation?.n); panel.end(); reader.stop(); if (dir !== null) { try { effects.removeDir(dir); } catch { /* not empty, or gone */ } } },
|
|
801
|
+
onEnd() { ended = true; spawnTimers.end(); dismiss(confirmation?.n); panel.end(); identities.stop(); reader.stop(); if (dir !== null) { try { effects.removeDir(dir); } catch { /* not empty, or gone */ } } },
|
|
738
802
|
});
|
|
739
803
|
function refresh(how) { Promise.resolve(reader.request(how)).catch(() => {}); }
|
|
740
804
|
/** A preflight under way when the process stops: given up, and the store told. */
|
|
@@ -745,7 +809,7 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
745
809
|
}
|
|
746
810
|
/** Every read in flight is void (lib/read.mjs), the roster's with them: the reader says nothing
|
|
747
811
|
* for a void read, so the state is told here that none is in flight. */
|
|
748
|
-
function dropReads() { reader.voidInFlight(); state = reduce(state, { collecting: false }, keymap).state; }
|
|
812
|
+
function dropReads() { reader.voidInFlight(); identities.stop(); state = reduce(state, { collecting: false }, keymap).state; }
|
|
749
813
|
/** The events of one batch of input, in order. Once one of them gave the terminal the focus,
|
|
750
814
|
* the rest are dropped: they were typed before it had it, and neither the list nor the agent
|
|
751
815
|
* is to have them (a `q` behind the Enter would end the run). Each batch is one read of input,
|
|
@@ -754,10 +818,11 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
754
818
|
function act(events) {
|
|
755
819
|
const read = ++reads;
|
|
756
820
|
for (const event of events) {
|
|
821
|
+
if (event.keyboard !== undefined) { answered(event.keyboard); continue; }
|
|
757
822
|
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;
|
|
758
823
|
if (typing()) {
|
|
759
824
|
if (escTimer !== null) { clearTimer(escTimer); escTimer = null; }
|
|
760
|
-
through =
|
|
825
|
+
through = newThrough();
|
|
761
826
|
break;
|
|
762
827
|
}
|
|
763
828
|
}
|
|
@@ -771,8 +836,13 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
771
836
|
}
|
|
772
837
|
|
|
773
838
|
guard.start();
|
|
839
|
+
// At the wait's end what the key parser kept as a possible beginning of the answer is read as typed.
|
|
840
|
+
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()));
|
|
774
841
|
guard.attempt(() => { if (!ended) Promise.resolve(reader.start()).catch(() => {}); });
|
|
775
842
|
if (found.ok) guard.attempt(() => { if (!ended) listStart(found.deployment); });
|
|
843
|
+
// Once a run, at the start: the identities of this computer's listed deployments, the list read first
|
|
844
|
+
// when the run did not read it before the terminal was taken.
|
|
845
|
+
guard.attempt(() => { if (!ended) { if (listedAtStart) identify(); else readList({ identify: true }); } });
|
|
776
846
|
guard.attempt(() => guard.draw());
|
|
777
847
|
// Once a run, after the first frame: what runs that are gone left of their private servers
|
|
778
848
|
// (lib/panel.mjs sweep, which signals nothing and removes only what it can prove is dead).
|
|
@@ -780,6 +850,7 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
780
850
|
const end = await guard.done;
|
|
781
851
|
if (escTimer !== null) clearTimer(escTimer);
|
|
782
852
|
if (throughTimer !== null) clearTimer(throughTimer);
|
|
853
|
+
if (kbTimer !== null) clearTimer(kbTimer);
|
|
783
854
|
// After the alternate screen is left, so the message stays on the screen the user returns to.
|
|
784
855
|
// One line per change still running, to a terminal or a file only; the status never depends on it.
|
|
785
856
|
const running = reader.changes?.() ?? [];
|
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
// in. What it adds is the TUI's: the window, the clock times, and which fact stands on which line.
|
|
8
8
|
import {
|
|
9
9
|
TERMS, panelData, displayLine, DETAIL_WITHHELD, originLead, instanceId, instanceVisibleInTree, waitingRollup, collapseKey, filterInstanceTree,
|
|
10
|
-
hasInstanceChildren, heldHome, instanceSiblings, siblingText, rosterSections, deploymentState, rowStale, primaryDeployment, isMultiDeployment, runtimeState, runtimeCounts,
|
|
10
|
+
hasInstanceChildren, heldHome, instanceSiblings, siblingText, rosterSections, deploymentState, rowStale, primaryDeployment, isMultiDeployment, runtimeState, runtimeCounts, instanceColor,
|
|
11
11
|
waitingClaim, waitingLabel, waitedText, waitingClock, waitingBelowText, instanceActs, rowReason,
|
|
12
|
-
identityMemory, viewModel, workspaceChoices, workspaceChoiceRows, choiceMatches, UNMATCHED_SECTION, shortPath,
|
|
12
|
+
identityMemory, viewModel, listedViews, workspaceChoices, workspaceChoiceRows, choiceMatches, UNMATCHED_SECTION, shortPath, machineLabels,
|
|
13
13
|
openAct, deployments as heldDeployments, attachExit, preflightFailure, kernelLines,
|
|
14
14
|
startGate, launchFlagIgnored, flagIgnoredNotice, retainedStartMessage, retiringRows, soulRows, soulFacts, spawnRefusal,
|
|
15
15
|
defaultSpawnChoices, spawnProblem, outcomeWords, previewFacts, deploymentLabel, subsequenceScore, soulMatches, soulCatalogFailure, catalogFailure,
|
|
16
16
|
memberNames, capabilitySource, groupCapabilities, hostKeyOf, capabilitySections, matchCapabilities, soulsComposition, rosterAgentName, layerLabel, capabilityUsers,
|
|
17
|
-
capabilityFacts, CAPABILITY_COPY,
|
|
17
|
+
capabilityFacts, CAPABILITY_COPY, CHORD_FAMILY_LABELS, DEFAULT_CHORD_FAMILY, chordFamilyNote,
|
|
18
18
|
} from "./client.mjs";
|
|
19
|
-
import { LEADER, keyLabel } from "./actions.mjs";
|
|
19
|
+
import { LEADER, chordsRead, keyLabel } from "./actions.mjs";
|
|
20
20
|
import { ownEllipsis, shownLines } from "./term/text.mjs";
|
|
21
21
|
import { textWidth } from "./term/width.mjs";
|
|
22
22
|
import { windowOf } from "./views/scroll.mjs";
|
|
@@ -44,6 +44,9 @@ export function heldOf(state, at) {
|
|
|
44
44
|
remembered: identityMemory({ memory: state.memory, notes: state.notes }),
|
|
45
45
|
rosterAnswered: state.remote.rosterAnswered, rosterFailure: state.remote.rosterFailure, cli: state.cli,
|
|
46
46
|
observing: new Set(), remoteCollecting: state.collecting, home: state.home, at: state.rosterAt ?? at,
|
|
47
|
+
// What the identity reads learned of this computer's listed deployments (lib/main.mjs): a listed one is
|
|
48
|
+
// matched to its workspace in the switcher, and one opened from there is in its view before its first read.
|
|
49
|
+
learned: state.identities,
|
|
47
50
|
};
|
|
48
51
|
}
|
|
49
52
|
|
|
@@ -55,6 +58,14 @@ export function panelOf(state, at) {
|
|
|
55
58
|
return state.open === null ? null : panelData(heldOf(state, at), state.open, TERMS);
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
/** The workspace (the shared view's id: panel-views.mjs viewModel) that holds deployment `id` in `state`,
|
|
62
|
+
* or null: what the tabs belong to, so a change of `state.open` within one workspace (its deployment of
|
|
63
|
+
* this machine opened beside another machine's) is not taken for opening another. */
|
|
64
|
+
export function workspaceOf(state, id, at) {
|
|
65
|
+
if (id === null) return null;
|
|
66
|
+
return viewModel(heldOf(state, at), TERMS).views.find((v) => v.id === id || v.deployments.includes(id))?.id ?? null;
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
const text = (value) => typeof value === "string" && value !== "";
|
|
59
70
|
const pad = (n) => String(n).padStart(2, "0");
|
|
60
71
|
/** An ISO time as a local clock time, `14:03:27`, or null. */
|
|
@@ -104,6 +115,10 @@ function markOf(row) {
|
|
|
104
115
|
return word === "stopped" && row.runtimeState === "shell" ? "shell" : word;
|
|
105
116
|
}
|
|
106
117
|
|
|
118
|
+
/** An instance row's colour (feature instance-color) as one of the terminal's sixteen, through the souls'
|
|
119
|
+
* map (views/souls.mjs SOUL_COLOURS), or null: which colour a row shows is the shared rule (instanceColor). */
|
|
120
|
+
const rowColour = (row) => SOUL_COLOURS[instanceColor(row)] ?? null;
|
|
121
|
+
|
|
107
122
|
/** The key prefix of each run of instances related to no other, as the shared grouping names it
|
|
108
123
|
* (`independent:<id>`). Read by key, not by label: a cluster whose root is named `independent` has that
|
|
109
124
|
* label too, and its key is `cluster:<n>:independent`. */
|
|
@@ -310,7 +325,7 @@ function listRow(state, r, item) {
|
|
|
310
325
|
const closed = disclosure(state, r, item) === "closed";
|
|
311
326
|
return {
|
|
312
327
|
id: item.id, name: item.row.instance, depth: item.depth, selected: item.id === state.selected,
|
|
313
|
-
mark: markOf(item.row), word: wordOf(item.row, state.ascii),
|
|
328
|
+
mark: markOf(item.row), color: rowColour(item.row), word: wordOf(item.row, state.ascii),
|
|
314
329
|
waiting: waitingClaim(item.row, { stale: r.stale(item.row) }) !== null,
|
|
315
330
|
folded: closed ? r.folded.get(item.id) ?? 0 : 0,
|
|
316
331
|
below: closed ? r.below.get(item.id)?.length ?? 0 : 0,
|
|
@@ -526,43 +541,90 @@ export function switcherLead(state, cols) {
|
|
|
526
541
|
return leadRows(leadOf(state), Number.isInteger(cols) && cols > 0 ? cols : 80, { ascii: state.ascii }).length;
|
|
527
542
|
}
|
|
528
543
|
|
|
529
|
-
/** The
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
544
|
+
/** The word an indicator line says of a deployment of a workspace in the switcher, or null for a live
|
|
545
|
+
* one: "not opened" for a deployment of this computer's list that this run does not serve (the TUI's
|
|
546
|
+
* own), else the shared word for its state (roster-sections.mjs deploymentState: not observed, not
|
|
547
|
+
* reached, stale, remembered). */
|
|
548
|
+
export const NOT_OPENED = "not opened";
|
|
549
|
+
function indicatorState(info) {
|
|
550
|
+
if (info.listed) return NOT_OPENED;
|
|
551
|
+
const said = deploymentState(info);
|
|
552
|
+
return said.key === "live" ? null : said.text;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/** The switcher's rows for a state, top to bottom: the workspaces, each a choice followed by one
|
|
556
|
+
* indicator line per deployment of it; then the views matched to no workspace under the shared
|
|
557
|
+
* heading; then the rows of this computer's deployments list that this run does not serve and that
|
|
558
|
+
* no workspace took, in the kernel's order, under the TUI's own.
|
|
559
|
+
* A workspace is what the shared rule (panel-views.mjs listedViews, buildViews underneath) makes of
|
|
560
|
+
* the deployments this run serves, the machines' groups and the listed deployments whose identity a
|
|
561
|
+
* read learned (`state.identities`, lib/main.mjs): a listed deployment that reports the same
|
|
562
|
+
* workspace as another is in its row. A served deployment's id and a row's path are both canonical,
|
|
563
|
+
* so a deployment opened in this run is never offered again.
|
|
564
|
+
* An item is `{ heading, shared }`; `{ indicator }`, a line under a workspace (its deployment's
|
|
565
|
+
* machine label, with a path tail where the shared label adds one, then its state word when it is
|
|
566
|
+
* not live: indicatorState), never a choice; or a choice: `{ key, label, open, primary, join, opens }`
|
|
567
|
+
* for a workspace (`primary` the deployment Enter opens when every local one is served; `join` the
|
|
568
|
+
* listed deployments Enter opens first, and `opens` the deployments it may then open, in order),
|
|
569
|
+
* `{ key, label, place, notLiveText, open, primary }` for a view matched to no workspace, and
|
|
570
|
+
* `{ key, label, place, path, state, refused }` for a row of the list (`state` the kernel's:
|
|
571
|
+
* views/switcher.mjs says a stale one in words; `place` why no workspace took it, when a read said, then its path: the reason first, so a narrow row
|
|
572
|
+
* cuts the path and keeps it).
|
|
573
|
+
* `keys` are the choices in order; `selected` is the key the selection stands on (the first choice
|
|
574
|
+
* when the state's own is not listed). */
|
|
539
575
|
export function switcher(state, at = new Date(0).toISOString()) {
|
|
540
|
-
const held = heldOf(state, at)
|
|
576
|
+
const held = heldOf(state, at);
|
|
577
|
+
const unserved = state.listed.rows.filter((row) => !state.ctxs.includes(row.path));
|
|
578
|
+
// Only a row the kernel says is a deployment is matched: a stale one (missing, not one any more) says so instead.
|
|
579
|
+
const views = listedViews(held, unserved.filter((row) => row.state === "ok"), TERMS);
|
|
541
580
|
const rows = workspaceChoiceRows(workspaceChoices(held, TERMS, views));
|
|
542
581
|
const query = state.switcher.query;
|
|
582
|
+
const viewOf = (id) => views.views.find((v) => v.id === id);
|
|
543
583
|
const openView = state.open === null ? null : views.views.find((v) => v.id === state.open || v.deployments.includes(state.open))?.id ?? null;
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
.
|
|
584
|
+
const items = [];
|
|
585
|
+
for (const row of rows.filter((each) => !each.unattached)) {
|
|
586
|
+
// This machine's deployments first (the served, then the listed), then the other machines', each in the shared order.
|
|
587
|
+
const all = viewOf(row.id).deployments.map((id) => views.infos.get(id)).filter(Boolean);
|
|
588
|
+
const infos = [...all.filter((info) => info.local), ...all.filter((info) => !info.local)], view = viewOf(row.id);
|
|
589
|
+
const labels = machineLabels(infos, TERMS);
|
|
590
|
+
const lines = infos.map((info) => [labels.get(info.id), indicatorState(info)].filter(Boolean).join(" · "));
|
|
591
|
+
if (!choiceMatches({ label: row.label, place: lines.join(" ") }, query)) continue;
|
|
592
|
+
const join = infos.filter((info) => info.listed).map((info) => info.id);
|
|
593
|
+
items.push({ key: `view\u0000${row.id}`, label: row.label, open: row.id === openView, primary: view.primary, join,
|
|
594
|
+
opens: infos.map((info) => info.id) });
|
|
595
|
+
for (const line of lines) items.push({ indicator: line });
|
|
596
|
+
}
|
|
597
|
+
const unmatched = rows.filter((row) => row.unattached && choiceMatches(row, query)).map((row) => ({
|
|
598
|
+
key: `view\u0000${row.id}`, label: row.label, place: row.place, notLiveText: row.notLiveText, open: row.id === openView, primary: viewOf(row.id)?.primary ?? null,
|
|
599
|
+
}));
|
|
600
|
+
const why = new Map(views.unmatched.map((info) => [info.id, info.short]));
|
|
601
|
+
const taken = new Set([...views.infos.keys()]);
|
|
602
|
+
const offered = unserved.filter((row) => !taken.has(row.path))
|
|
603
|
+
.map(({ path, name, state: listedState }) => ({
|
|
604
|
+
key: `path\u0000${path}`, label: name, place: [why.get(path), shortPath(path, { home: state.home })].filter(Boolean).join(" · "), path, state: listedState, refused: state.switcher.refused === path,
|
|
605
|
+
}))
|
|
553
606
|
.filter((item) => choiceMatches(item, query));
|
|
554
|
-
|
|
555
|
-
...matched,
|
|
607
|
+
items.push(
|
|
556
608
|
...(unmatched.length ? [{ heading: UNMATCHED_SECTION, shared: true }, ...unmatched] : []),
|
|
557
609
|
...(offered.length ? [{ heading: OFFERED_SECTION, shared: false }, ...offered] : []),
|
|
558
|
-
|
|
610
|
+
);
|
|
559
611
|
const keys = items.filter((item) => item.key !== undefined).map((item) => item.key);
|
|
560
|
-
const total = rows.length + unserved.length;
|
|
612
|
+
const total = rows.length + unserved.filter((row) => !taken.has(row.path)).length;
|
|
561
613
|
return {
|
|
562
614
|
items, keys, selected: keys.includes(state.switcher.selected) ? state.switcher.selected : keys[0] ?? null,
|
|
563
615
|
empty: keys.length ? null : total ? "nomatch" : "none",
|
|
564
616
|
};
|
|
565
617
|
}
|
|
618
|
+
/** The window of the switcher's `items` in a pane `height` rows tall, from `top`, that holds the choice
|
|
619
|
+
* `key` and, while they fit, the indicator lines under it (scroll.mjs windowOf, asked to keep the last
|
|
620
|
+
* of them and then the choice). No key (-1 kept): the window as `top` gives it. */
|
|
621
|
+
export function switcherWindow(items, key, { top, height }) {
|
|
622
|
+
const at = key === null ? -1 : items.findIndex((item) => item.key === key);
|
|
623
|
+
let last = at;
|
|
624
|
+
while (last >= 0 && items[last + 1]?.indicator !== undefined) last++;
|
|
625
|
+
const after = windowOf({ top, count: items.length, height, keep: last });
|
|
626
|
+
return windowOf({ top: after.top, count: items.length, height, keep: at });
|
|
627
|
+
}
|
|
566
628
|
|
|
567
629
|
/** The palette's views and commands, each a row's label and the action it runs. */
|
|
568
630
|
const PALETTE_VIEWS = Object.freeze([["instances", "Instances"], ["souls", "Souls"], ["capabilities", "Capabilities"]]);
|
|
@@ -574,51 +636,75 @@ const PALETTE_SPLIT = Object.freeze({
|
|
|
574
636
|
});
|
|
575
637
|
const PALETTE_ACTS = Object.freeze({ stop: "Stop", restart: "Restart", retire: "Retire", start: "Start" });
|
|
576
638
|
|
|
639
|
+
/** Which way each of the palette's own keys (its `does`, lib/actions.mjs paletteKeys) moves the
|
|
640
|
+
* selection among the palette's runs: to the next, or to the one before. */
|
|
641
|
+
const PALETTE_STEPS = Object.freeze({ "palette-next-group": 1, "palette-previous-group": -1 });
|
|
642
|
+
|
|
577
643
|
/** THE PALETTE'S ROWS (docs/tui.md, "The palette"), in this order: the instances that can be
|
|
578
|
-
* opened
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
644
|
+
* opened, grouped and ordered as the sidebar's tree but by recency (the shared rosterSections
|
|
645
|
+
* with `lastFocus`, the Desktop's palette's: the group, the cluster, the root and the child opened
|
|
646
|
+
* most recently in this run first, then the shared order; one section per deployment where the
|
|
647
|
+
* view has several, as the sidebar's), each group led by a row of its label (`kind: "group"`: its
|
|
648
|
+
* name, the deployment's before it where there are several, never selected), then the souls of
|
|
649
|
+
* the open workspace once its catalog was read, its capabilities once theirs was, the views, the
|
|
650
|
+
* acts the palette's instance offers (the open terminal's, when the palette came from its focus;
|
|
651
|
+
* else the selected one) and, once the catalog lists its soul, another of that soul, then
|
|
652
|
+
* spawning an agent, workspaces, refresh and help, and the split's that apply. With a query, an
|
|
653
|
+
* instance group keeps the rows the Desktop's subsequence score matches, in its own order, and a
|
|
654
|
+
* group with none has no label row; each kind after them keeps its matches the best first (a
|
|
655
|
+
* prefix first), a tie in that order. A row: `{ key, kind, label, does?, id?, name?, machine?, mark?, sibling?, capability?, source? }`.
|
|
656
|
+
* `runs`: the keys of the rows that can be selected, run by run (each instance group, then each
|
|
657
|
+
* kind), which the palette's own keys move between (paletteStep). `selected` is the key the
|
|
658
|
+
* selection stands on (the first row that can be selected when the palette's own is not listed). */
|
|
586
659
|
export function paletteItems(state, at = new Date(0).toISOString()) {
|
|
587
660
|
const p = state.palette;
|
|
588
|
-
if (p === null) return { items: [], selected: null };
|
|
589
|
-
const
|
|
661
|
+
if (p === null) return { items: [], runs: [], selected: null };
|
|
662
|
+
const query = p.query.trim();
|
|
663
|
+
// An instance group keeps its order under a query; a kind is ranked by the score.
|
|
664
|
+
const matched = (item) => query === "" || subsequenceScore(item.text, query) !== null;
|
|
665
|
+
const ranked = (group) => (query === "" ? group
|
|
666
|
+
: group.map((item, i) => ({ item, i, score: subsequenceScore(item.text, query) })).filter((each) => each.score !== null).sort((a, b) => a.score - b.score || a.i - b.i).map(({ item }) => item));
|
|
667
|
+
const runs = [];
|
|
590
668
|
if (state.open !== null) {
|
|
591
669
|
const r = roster(state, at);
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
const
|
|
595
|
-
|
|
670
|
+
const openable = r.instances.filter((row) => openDecision(state, row, instanceActs(row)).open);
|
|
671
|
+
// The record of focus the shared order reads: larger is more recent, `recent` is the latest first.
|
|
672
|
+
const lastFocus = new Map(state.recent.map((id, i) => [id, state.recent.length - i]));
|
|
673
|
+
const item = (row) => {
|
|
596
674
|
const machine = elsewhere(row) ? row.deployment?.machine ?? row.server : null;
|
|
597
675
|
// `sibling`: the shared words for its siblings, or null; never part of what a query matches.
|
|
598
676
|
return {
|
|
599
677
|
key: `instance\u0000${instanceId(row)}`, kind: "instance", label: row.instance, id: instanceId(row), name: row.instance, machine, mark: markOf(row),
|
|
600
678
|
sibling: siblingText(r.siblings.get(instanceId(row))), text: `${row.instance} ${machine ?? ""}`,
|
|
601
679
|
};
|
|
602
|
-
}
|
|
680
|
+
};
|
|
681
|
+
for (const section of rosterSections(r.instances, openable, r.deployments, TERMS, { lastFocus })) for (const group of section.groups) {
|
|
682
|
+
const rows = group.clusters.flatMap((cluster) => cluster.instances).map(item).filter(matched);
|
|
683
|
+
if (!rows.length) continue;
|
|
684
|
+
// A group is named, and kept apart, by its deployment where there are several (the Desktop's palette.mjs).
|
|
685
|
+
const key = section.deployment ? `${section.deployment.id}|${group.key}` : group.key;
|
|
686
|
+
runs.push([{ key: `group\u0000${key}`, kind: "group", label: section.deployment ? `${section.label} · ${group.label}` : group.label }, ...rows]);
|
|
687
|
+
}
|
|
603
688
|
}
|
|
689
|
+
const kinds = [];
|
|
604
690
|
// The souls of the open workspace, once its catalog was read (the Souls view opened): choosing
|
|
605
691
|
// one shows the Souls view with it selected. A palette never reads the catalog.
|
|
606
|
-
|
|
692
|
+
kinds.push(soulsOf(state).all.map((row) => ({ key: `soul\u0000${row.name}`, kind: "soul", label: row.name, name: row.name, text: row.name })));
|
|
607
693
|
// The capabilities of the open workspace, once its catalog was read (the Capabilities view opened):
|
|
608
694
|
// choosing one shows that view with it selected. Each says where it comes from (a package's and a
|
|
609
695
|
// member's may share a name).
|
|
610
696
|
const c = capabilitiesOf(state), names = memberNames(c.status);
|
|
611
|
-
|
|
697
|
+
kinds.push(c.all.map((row) => {
|
|
612
698
|
const capability = capabilityKey(row, names);
|
|
613
699
|
return { key: `capability\u0000${capability}`, kind: "capability", label: row.name, name: row.name, capability, source: capabilitySource(row, names).label, text: row.name };
|
|
614
700
|
}));
|
|
615
|
-
|
|
701
|
+
kinds.push(PALETTE_VIEWS.map(([does, label]) => ({ key: `view\u0000${does}`, kind: "view", label, does, text: label })));
|
|
616
702
|
const id = p.from === "terminal" && state.terminal !== null ? state.terminal.id : state.selected;
|
|
617
703
|
const row = id === null || state.open === null ? null : roster(state, at).instances.find((each) => instanceId(each) === id) ?? null;
|
|
618
704
|
if (row !== null && state.opening === null) {
|
|
619
705
|
const acts = instanceActs(row);
|
|
620
706
|
const another = !elsewhere(row) && state.ctxs.includes(state.open) ? soulOfAgent(state, state.open, row.agent) : null;
|
|
621
|
-
|
|
707
|
+
kinds.push([
|
|
622
708
|
...ACT_VERBS.filter((verb) => actDecision(state, row, acts, verb).open)
|
|
623
709
|
.map((verb) => ({ key: `act\u0000${verb}`, kind: "act", label: PALETTE_ACTS[verb], does: verb, id: instanceId(row), name: row.instance, text: `${PALETTE_ACTS[verb]} ${row.instance}` })),
|
|
624
710
|
// Another of its soul (N), once the catalog lists that soul: the row names the soul.
|
|
@@ -630,16 +716,28 @@ export function paletteItems(state, at = new Date(0).toISOString()) {
|
|
|
630
716
|
// empty. A split there is no room for says so when it is run.
|
|
631
717
|
const splitting = state.tabs.length > 0 && state.opening === null && !state.tabs.some((tab) => tab.status === "starting");
|
|
632
718
|
const SPLIT = splitting ? (state.split === null ? PALETTE_SPLIT.one : state.terminal !== null ? PALETTE_SPLIT.shown : PALETTE_SPLIT.empty) : [];
|
|
633
|
-
|
|
634
|
-
const
|
|
635
|
-
const items =
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
//
|
|
639
|
-
//
|
|
640
|
-
|
|
641
|
-
const first = p.query === "" &&
|
|
642
|
-
return {
|
|
719
|
+
kinds.push([...PALETTE_COMMANDS, ...SPLIT].map(([does, label]) => ({ key: `command\u0000${does}`, kind: "command", label, does, text: label })));
|
|
720
|
+
for (const kind of kinds) { const rows = ranked(kind); if (rows.length) runs.push(rows); }
|
|
721
|
+
const items = runs.flat(), selectable = items.filter((each) => each.kind !== "group"), instances = selectable.filter((each) => each.kind === "instance");
|
|
722
|
+
// With nothing chosen yet, the first row that can be selected; but in the palette as it opens (no
|
|
723
|
+
// query), when that is the shown tab's instance (the most recent), the instance shown before it
|
|
724
|
+
// (`recent`'s second, wherever its group puts it), else the second instance: the palette and Enter
|
|
725
|
+
// go back to the terminal before it, as the Desktop's recent group did.
|
|
726
|
+
const before = instances.find((each) => each.id === state.recent[1]) ?? instances[1];
|
|
727
|
+
const first = p.query === "" && instances.length > 1 && selectable[0] === instances[0] && instances[0].id === state.terminal?.id ? before : selectable[0];
|
|
728
|
+
return {
|
|
729
|
+
items, runs: runs.map((run) => run.filter((each) => each.kind !== "group").map((each) => each.key)),
|
|
730
|
+
selected: selectable.some((each) => each.key === p.selected) ? p.selected : first?.key ?? null,
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
/** Where the palette's own key `does` (lib/actions.mjs paletteKeys) takes the selection of `list`
|
|
734
|
+
* (paletteItems): the first row of the next run, or of the one before, wrapping past either end;
|
|
735
|
+
* with one run, its first row. Null with no row, or for a `does` that is not the palette's. */
|
|
736
|
+
export function paletteStep(list, does) {
|
|
737
|
+
const step = PALETTE_STEPS[does], n = list.runs.length;
|
|
738
|
+
if (step === undefined || n === 0) return null;
|
|
739
|
+
const at = list.runs.findIndex((run) => run.includes(list.selected));
|
|
740
|
+
return list.runs[(((at < 0 ? 0 : at + step) % n) + n) % n][0];
|
|
643
741
|
}
|
|
644
742
|
/** The palette as the view draws it, in a body `page` rows tall: its query on the first row, and
|
|
645
743
|
* under it the window of its rows that holds the selection (whose last row says what is cut off,
|
|
@@ -678,6 +776,15 @@ export function model(state, { page, body = page, now, at, cols, area = cols })
|
|
|
678
776
|
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,
|
|
679
777
|
detailTop: state.detailTop, helpTop: state.helpTop, open: state.open !== null,
|
|
680
778
|
detachKey: state.detachKey, opening: state.opening, openable: false,
|
|
779
|
+
// The chords read now, `[key id, does]` (actions.mjs chordsRead), and whether the terminal
|
|
780
|
+
// confirms the kitty keyboard protocol: then the help and a terminal's cheat sheet lead with them.
|
|
781
|
+
chords: [...chordsRead(state.chords, state.keyboard !== null)], kitty: state.keyboard !== null,
|
|
782
|
+
// The family the chords are bound in (keys.json, lib/config.mjs loadKeys), its name, and the line that says
|
|
783
|
+
// why the file was not taken, or null (the shared chordFamilyNote): the help's chords section names both.
|
|
784
|
+
keys: state.keysRead ? Object.freeze({ family: state.keysRead.family, label: CHORD_FAMILY_LABELS[state.keysRead.family] ?? CHORD_FAMILY_LABELS[DEFAULT_CHORD_FAMILY], note: chordFamilyNote(state.keysRead) }) : null,
|
|
785
|
+
// The palette's own keys, `[key id, does]` (actions.mjs paletteKeys; none on macOS): its cheat
|
|
786
|
+
// sheet and the help name them.
|
|
787
|
+
paletteKeys: [...state.paletteKeys],
|
|
681
788
|
terminal: state.terminal, onTerminal: false,
|
|
682
789
|
// The panel's groups (views/frame.mjs), the split and the focused group; the panel stands while
|
|
683
790
|
// any tab is open. `tabs` is the focused group's strip: each tab in order, the shown one marked,
|
|
@@ -695,10 +802,9 @@ export function model(state, { page, body = page, now, at, cols, area = cols })
|
|
|
695
802
|
};
|
|
696
803
|
if (under === "switcher") {
|
|
697
804
|
const s = switcher(state, at);
|
|
698
|
-
const at_ = s.selected === null ? -1 : s.items.findIndex((item) => item.key === s.selected);
|
|
699
805
|
// The lines above the rows take the pane's rows, and so does the filter field while it is
|
|
700
806
|
// typed or kept: the window is that much shorter, so no choice is hidden for them (switcherHeight).
|
|
701
|
-
const win =
|
|
807
|
+
const win = switcherWindow(s.items, state.switcher.loose ? null : s.selected, { top: state.switcher.top, height: switcherHeight(state, body, area) });
|
|
702
808
|
return {
|
|
703
809
|
...common, under, list: [], above: 0, below: 0, wordWidth: 0, detail: null,
|
|
704
810
|
// Nothing of a workspace stands in the sidebar while the switcher is shown.
|
|
@@ -981,7 +1087,7 @@ function soulDetail(state, at, row) {
|
|
|
981
1087
|
name: row.name, description: row.description ?? "", from: soulFrom(row), works: facts.work, refusal: facts.refusalLine,
|
|
982
1088
|
harness: { rows: facts.rows, notes: facts.notes, problem: facts.problem },
|
|
983
1089
|
teams, capabilities,
|
|
984
|
-
instances: { shown: here.slice(0, INSTANCES_NAMED).map((each) => ({ name: each.instance, mark: markOf(each) })), more: Math.max(0, here.length - INSTANCES_NAMED) },
|
|
1090
|
+
instances: { shown: here.slice(0, INSTANCES_NAMED).map((each) => ({ name: each.instance, mark: markOf(each), color: rowColour(each) })), more: Math.max(0, here.length - INSTANCES_NAMED) },
|
|
985
1091
|
};
|
|
986
1092
|
}
|
|
987
1093
|
|