@awebai/oats 0.67.1 → 0.68.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/bin/oats.mjs +112 -16
- package/docs/capabilities.md +54 -5
- package/docs/capability-manifest.schema.json +4 -0
- package/docs/design/2026-10-22-module-upgrade.md +192 -0
- package/docs/design/README.md +4 -0
- package/docs/desktop-cli-api.md +248 -9
- package/docs/desktop.md +316 -63
- package/docs/first-team.md +5 -3
- package/docs/implementation.md +42 -3
- package/docs/integrations.md +16 -4
- package/docs/knowledge.md +44 -27
- package/docs/layers.md +2 -2
- package/docs/official-catalog.md +5 -5
- package/docs/packages.md +14 -14
- package/docs/release-notes/v0.68.0.md +504 -0
- package/docs/release-notes/v0.68.1.md +102 -0
- package/docs/servers.md +6 -1
- package/docs/souls-and-instances.md +38 -3
- package/docs/tui.md +663 -243
- package/docs/upgrading.md +66 -6
- package/docs/workspaces.md +2 -2
- package/lib/capability-contract.mjs +6 -5
- package/lib/core.mjs +222 -38
- package/lib/instance-events.mjs +1 -1
- package/lib/instance-resolution.mjs +5 -5
- package/lib/instance-upgrade.mjs +1445 -0
- package/lib/materialize.mjs +225 -78
- package/lib/servers.mjs +11 -7
- package/lib/upgrade-state.mjs +101 -0
- package/lib/workspace.mjs +4 -1
- package/lib/worktree.mjs +103 -12
- package/package-catalog.json +5 -4
- package/package.json +1 -1
- package/packages/client/cli-adapter.mjs +15 -1
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/deployment-panel.mjs +6 -2
- package/packages/client/instance-display-name.mjs +18 -0
- package/packages/client/keymap.mjs +89 -45
- package/packages/client/keys-file.mjs +9 -5
- package/packages/client/panel-views.mjs +16 -3
- package/packages/client/spawn-naming.mjs +7 -6
- package/packages/client/spawn-preview-cli.mjs +37 -1
- package/packages/client/spawn-preview-contract.mjs +35 -0
- package/packages/client/spawn-preview.mjs +35 -2
- package/packages/client/team-members.mjs +4 -1
- package/packages/client/workspace-step.mjs +25 -0
- package/packages/tui/README.md +5 -5
- package/packages/tui/lib/actions.mjs +51 -27
- package/packages/tui/lib/client.mjs +4 -2
- package/packages/tui/lib/config.mjs +4 -4
- package/packages/tui/lib/main.mjs +27 -13
- package/packages/tui/lib/model.mjs +143 -21
- package/packages/tui/lib/store.mjs +343 -68
- package/packages/tui/lib/term/keys.mjs +5 -3
- package/packages/tui/lib/term/kitty.mjs +28 -10
- package/packages/tui/lib/term/screen.mjs +15 -6
- package/packages/tui/lib/term/through.mjs +33 -28
- package/packages/tui/lib/views/capabilities.mjs +6 -6
- package/packages/tui/lib/views/frame.mjs +88 -109
- package/packages/tui/lib/views/help.mjs +57 -35
- package/packages/tui/lib/views/instances.mjs +48 -30
- package/packages/tui/lib/views/souls.mjs +9 -8
- package/packages/tui/lib/views/workspaces.mjs +55 -0
- package/skills/oats-getting-started/SKILL.md +92 -43
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
// Selection is an identity (the shared `instanceId`), never an index, so it survives every read;
|
|
11
11
|
// the rows it moves among are the model's, in drawn order.
|
|
12
12
|
import { ACTIONS, LEADER_KEYS, backKeyLabel, bindings, chordKeys, chordsRead, paletteKeys } from "./actions.mjs";
|
|
13
|
-
import { CHORDS, chordFamilyFrom, collapseKey, displayLine, instanceActs, instanceId, outcomeWords, pendingEntry, spawnProblem } from "./client.mjs";
|
|
13
|
+
import { CHORDS, chordFamilyFrom, collapseKey, workspaceStep, displayLine, instanceActs, instanceId, outcomeWords, pendingEntry, spawnProblem } from "./client.mjs";
|
|
14
14
|
import { defaultDetachKey } from "./config.mjs";
|
|
15
|
-
import { BUTTON_ORDER, SPAWN_WORDS, SPLIT_WORDS, TAB_WORDS, actDecision, capabilitiesHeight, capabilitiesOf, capabilityUsersOf, disclosure, openDecision, paletteItems, paletteStep, preflightLine, returnedLine, roster, soulNames, soulOfAgent, soulsOf, spawnChoices, spawnChoicesKey, spawnLine, spawnPickerItems, spawnReady, spawnRing, spawnSelector, spawnedRow, switcher, switcherHeight, switcherWindow,
|
|
15
|
+
import { BUTTON_ORDER, SPAWN_WORDS, LEADER_WORDS, SPLIT_WORDS, TAB_WORDS, actDecision, capabilitiesHeight, capabilitiesOf, capabilityUsersOf, disclosure, openDecision, paletteItems, paletteStep, preflightLine, returnedLine, roster, soulNames, soulOfAgent, soulsOf, spawnChoices, spawnChoicesKey, spawnLine, spawnPickerItems, spawnReady, spawnRing, spawnSelector, spawnedRow, switcher, switcherHeight, switcherWindow, memoryKey, memoryKeys, LIST_WORDS, WORKSPACE_WORDS, listChoice, listChoices, workspaceList } from "./model.mjs";
|
|
16
16
|
import { backKeyId, backKeySequences, isBackKey } from "./term/through.mjs";
|
|
17
17
|
import { windowOf } from "./views/scroll.mjs";
|
|
18
18
|
import { SPLIT_MIN, splitFits } from "./views/split.mjs";
|
|
@@ -49,10 +49,11 @@ const NO_CAPABILITIES = Object.freeze({ wanted: false, held: new Map(), selected
|
|
|
49
49
|
* `rosterAt`, `memory`, `notes`, `collecting`: the roster of other machines as the shared rule
|
|
50
50
|
* left it, the time of the last outcome taken, what the machines reported, and whether a roster
|
|
51
51
|
* read is in flight. `unread`: per served deployment whose read failed with nothing kept, the
|
|
52
|
-
* instances it last held (see `took`). `loose`: the list was scrolled away from the selection
|
|
52
|
+
* instances it last held, and `unreadKeys` the memoryKey it was under then (see `took`). `loose`: the list was scrolled away from the selection
|
|
53
53
|
* on purpose (see `scrolledList`); the switcher has its own.
|
|
54
|
-
* `selected`, `top`, `detailTop` are the open view's; `places` keeps them for
|
|
55
|
-
* the
|
|
54
|
+
* `selected`, `top`, `detailTop` are the open view's; `places` keeps them, with the filter, for
|
|
55
|
+
* the workspaces left behind (per lib/model.mjs memoryKey; see `opened`), and `collapsed` holds
|
|
56
|
+
* every view's keys (each carries its `open`).
|
|
56
57
|
* `back`: the view under the help. `listed`: this computer's deployments list as it was last read
|
|
57
58
|
* (awebai/oats#1390): `rows`, the shared reader's `{ path, name, state }` in the kernel's order, of
|
|
58
59
|
* the last read that answered, and `failure`, the reason (`{ code, message }`) the last read failed
|
|
@@ -77,7 +78,9 @@ const NO_CAPABILITIES = Object.freeze({ wanted: false, held: new Map(), selected
|
|
|
77
78
|
* "terminal" while what is typed goes to the agent and "list" while the TUI reads keys, and `zoom`
|
|
78
79
|
* true while it has the whole body (only with the terminal's focus).
|
|
79
80
|
* `outcome`: the line after an open (the model's `{ said, under }`), shown above the panes until
|
|
80
|
-
* the next key bound to an action, or null
|
|
81
|
+
* the next key bound to an action, or null; with `once: true` (the list of workspaces' end, said
|
|
82
|
+
* by the leader's Up or Down, and the leader cancelled by its own read) until the next key of any kind (the leader's: the key after it), one
|
|
83
|
+
* typed to the agent included, or a resize (the loop's `{ passed }`). `notice`: such a line that came while no view that
|
|
81
84
|
* draws one at every width was shown (the switcher, the help, a detail or a terminal with the
|
|
82
85
|
* focus: see `drawsOutcome`), held until one is; or null.
|
|
83
86
|
* It is the add of the deployment the run started in, refused.
|
|
@@ -87,15 +90,20 @@ const NO_CAPABILITIES = Object.freeze({ wanted: false, held: new Map(), selected
|
|
|
87
90
|
* `leader`: `{ read, waiting }` from the leader's read on, or null (see `leading`).
|
|
88
91
|
* `keyboard`: the flags the terminal confirmed for the kitty keyboard protocol (lib/main.mjs, the
|
|
89
92
|
* event `{ keyboard }`), or null while it has not; `chords`: the chords of `platform`, key id ->
|
|
90
|
-
* `does` (actions.mjs chordKeys), in the family keys.json chose,
|
|
91
|
-
* is not null, and
|
|
92
|
-
* `leading`). `keysRead`: what keys.json said at the start (lib/config.mjs loadKeys, the shared
|
|
93
|
+
* `does` (actions.mjs chordKeys: on macOS the arrow chords alone, `mac` true), in the family keys.json chose, but the one the leader's key
|
|
94
|
+
* takes, every one read while `keyboard` is not null, and those with bytes of their own while it
|
|
95
|
+
* is null: the whole Alt family, the arrows of the others (actions.mjs chordsRead; see `leading`). `keysRead`: what keys.json said at the start (lib/config.mjs loadKeys, the shared
|
|
93
96
|
* reader's frozen `{ family, why }`; no file when none is given): the family `chords` are bound
|
|
94
97
|
* in, and why it is the default when the file did not choose it. The help names both.
|
|
95
98
|
* `palette`: the palette while it is open (see `paletteOpened`), or null; `paletteKeys` its own
|
|
96
99
|
* keys on `platform`, key id -> `does` (actions.mjs paletteKeys: none on macOS), which win over
|
|
97
|
-
* every other key while it is open. `recent`: the ids of
|
|
98
|
-
* latest first.
|
|
100
|
+
* every other key while it is open. `recent`: per workspace (memoryKey), the ids of its instances
|
|
101
|
+
* opened or shown in this run, the latest first (recentWith).
|
|
102
|
+
* `layouts`: per workspace left behind, its tabs as they were (layoutOf); `restoring`: the restore
|
|
103
|
+
* of the open workspace's while it opens them again (`{ key, tabs, split, group, shown, focus,
|
|
104
|
+
* zoom, queue, grant }`: the layout, the tabs not opened yet, and whether the focus is still given
|
|
105
|
+
* back), or null (restoreNext); `leftFocus`: `{ id, zoom }` while another view stands over the list
|
|
106
|
+
* and the terminal had the focus before it, or null (reduceStep).
|
|
99
107
|
* `act`: the confirmation open in the act view (see `actOpened`), or null; `acted` counts the
|
|
100
108
|
* confirmations opened in this run, so an answer for one that was closed is told apart.
|
|
101
109
|
* `starting`: id -> `{ verb, since }` of this run's starts and restarts whose child is still
|
|
@@ -113,18 +121,18 @@ const NO_CAPABILITIES = Object.freeze({ wanted: false, held: new Map(), selected
|
|
|
113
121
|
* agentsRoot, agent, reads, words }`, until its row is opened or two reads did not show it;
|
|
114
122
|
* `previews` the number of the last preview read asked in the run, so that an answer to a prompt
|
|
115
123
|
* already closed is never taken by the next one. */
|
|
116
|
-
export function initialState({ deployment = null, cli, home, entry = null, actions = ACTIONS, ascii = false, platform = process.platform, detachKey = defaultDetachKey(platform), keysRead = NO_KEYS_FILE }) {
|
|
124
|
+
export function initialState({ deployment = null, cli, home, entry = null, actions = ACTIONS, ascii = false, colour = true, platform = process.platform, detachKey = defaultDetachKey(platform), keysRead = NO_KEYS_FILE }) {
|
|
117
125
|
return Object.freeze({
|
|
118
126
|
view: deployment === null ? "switcher" : "instances", back: deployment === null ? "switcher" : "instances",
|
|
119
127
|
ctxs: Object.freeze(deployment === null ? [] : [deployment]), open: deployment,
|
|
120
128
|
entries: new Map(deployment === null ? [] : [[deployment, entry]]), numbers: new Map(),
|
|
121
129
|
remote: Object.freeze({ remoteGroups: Object.freeze([]), rosterAnswered: false, rosterFailure: null }), rosterAt: null,
|
|
122
130
|
memory: new Map(), notes: new Map(), collecting: false, cli, home,
|
|
123
|
-
selected: null, collapsed: new Set(), filter: NO_FILTER, focus: "list", top: 0, loose: false, detailTop: 0, places: new Map(), unread: new Map(),
|
|
131
|
+
selected: null, collapsed: new Set(), filter: NO_FILTER, focus: "list", top: 0, loose: false, detailTop: 0, places: new Map(), unread: new Map(), unreadKeys: new Map(), workspaceCursor: null, colour,
|
|
124
132
|
switcher: NO_SWITCHER,
|
|
125
133
|
listed: NO_LIST, identities: new Map(),
|
|
126
134
|
helpTop: 0, actions, ascii, detachKey, opening: null, terminal: null, outcome: null, act: null, acted: 0, starting: new Map(), retiring: new Set(),
|
|
127
|
-
leaderKey: backKeyId(detachKey), leader: null, keyboard: null, keysRead, chords: chordKeys(platform === "darwin", actions, CHORDS, keysRead.family), palette: null, paletteKeys: paletteKeys(platform === "darwin"), recent:
|
|
135
|
+
leaderKey: backKeyId(detachKey), leader: null, keyboard: null, keysRead, mac: platform === "darwin", chords: chordKeys(platform === "darwin", actions, CHORDS, keysRead.family, backKeyId(detachKey)), palette: null, paletteKeys: paletteKeys(platform === "darwin"), recent: new Map(), layouts: new Map(), restoring: null, leftFocus: null, souls: NO_SOULS, capabilities: NO_CAPABILITIES,
|
|
128
136
|
spawn: null, spawning: null, spawnCheck: null, arriving: null, previews: 0, tabs: Object.freeze([]), split: null, group: 0, aside: null,
|
|
129
137
|
notice: null,
|
|
130
138
|
});
|
|
@@ -193,8 +201,9 @@ function rehomed(before, state) {
|
|
|
193
201
|
/** The switcher, shown: over whatever view was there. `said`: a line of its own to show. */
|
|
194
202
|
const toSwitcher = (state, said = null) => next(state, { view: "switcher", switcher: Object.freeze({ ...state.switcher, editing: false, loose: false, line: said, refused: null, removing: null }) });
|
|
195
203
|
|
|
196
|
-
/** After what the reader gave changed:
|
|
197
|
-
*
|
|
204
|
+
/** After what the reader gave changed: the memory of a workspace no view holds any more is
|
|
205
|
+
* forgotten (remembered). When no view holds what was open any more (a machine that is no longer
|
|
206
|
+
* listed), the switcher is shown and says so, and nothing is open. Else the
|
|
198
207
|
* collapse keys of this view whose instance is gone are forgotten, and the selection finds its
|
|
199
208
|
* place.
|
|
200
209
|
* THAT AN INSTANCE IS GONE IS KNOWN ONLY OF A DEPLOYMENT THAT WAS READ. One whose read failed
|
|
@@ -204,13 +213,14 @@ const toSwitcher = (state, said = null) => next(state, { view: "switcher", switc
|
|
|
204
213
|
* meanwhile (another deployment, the roster of other machines), so the next good read finds
|
|
205
214
|
* the user where they were. A machine's rows are kept by the shared rule while it does not
|
|
206
215
|
* answer, so they need no such care. */
|
|
207
|
-
function settled(state,
|
|
208
|
-
const now = roster(taken);
|
|
216
|
+
function settled(state, was) {
|
|
217
|
+
const taken = remembered(was), now = roster(taken);
|
|
209
218
|
if (taken.open !== null && now.gone) {
|
|
210
|
-
|
|
219
|
+
// The workspace's memory goes with it (reduceStep closes its tabs).
|
|
220
|
+
const forgot = forgotten(taken, memoryKey(state, state.open));
|
|
211
221
|
// A confirmation open over that view is closed with it: what it sent goes on.
|
|
212
222
|
const dismiss = taken.act !== null ? { dismiss: taken.act.n } : {};
|
|
213
|
-
return { state: toSwitcher(next(taken, { open: null,
|
|
223
|
+
return { state: toSwitcher(next(taken, { open: null, ...forgot, selected: null, top: 0, loose: false, detailTop: 0, focus: "list", filter: NO_FILTER, back: "switcher", act: null }), "gone"), effect: { list: true, identify: true, ...dismiss } };
|
|
214
224
|
}
|
|
215
225
|
const before = roster(state);
|
|
216
226
|
const unknown = new Set([...taken.unread.values()].flatMap((ids) => [...ids]));
|
|
@@ -220,20 +230,33 @@ function settled(state, taken) {
|
|
|
220
230
|
const pruned = stillThere.length === taken.collapsed.size ? taken : next(taken, { collapsed: new Set(stillThere) });
|
|
221
231
|
return { state: unknown.has(pruned.selected) ? pruned : rehomed(before, pruned), effect: null };
|
|
222
232
|
}
|
|
233
|
+
/** The memory of every workspace no view holds any more (memoryKeys) forgotten, a hidden one's
|
|
234
|
+
* too, so one that comes back starts afresh. */
|
|
235
|
+
function remembered(state) {
|
|
236
|
+
if (!state.places.size && !state.recent.size && !state.layouts.size) return state;
|
|
237
|
+
const keys = memoryKeys(state);
|
|
238
|
+
const kept = (map) => { const left = new Map([...map].filter(([key]) => keys.has(key))); return left.size === map.size ? map : left; };
|
|
239
|
+
const places = kept(state.places), recent = kept(state.recent), layouts = kept(state.layouts);
|
|
240
|
+
return places === state.places && recent === state.recent && layouts === state.layouts ? state : next(state, { places, recent, layouts });
|
|
241
|
+
}
|
|
223
242
|
|
|
224
243
|
/** A served deployment's entry from the reader, with the number of the cycle that gave it. An
|
|
225
244
|
* answer for a deployment that is not served, or one that is not newer than the last taken for
|
|
226
245
|
* it, is dropped. Only an observed entry moves the selection or forgets a collapse: a failed
|
|
227
246
|
* read has no rows to move to, and the next good one finds the user where they were.
|
|
228
247
|
* `unread`: for a deployment whose read failed with nothing kept, the instances it held when it
|
|
229
|
-
* was last read, until it is read again
|
|
248
|
+
* was last read, until it is read again, and (`unreadKeys`) the workspace it was in: they are what
|
|
249
|
+
* `settled` must not take for gone, nor `remembered` forget. */
|
|
230
250
|
function took(state, { id, entry, number }) {
|
|
231
251
|
if (!state.ctxs.includes(id) || !(number > (state.numbers.get(id) ?? 0))) return { state, effect: null };
|
|
232
252
|
const observed = entry?.deployment?.status === "observed", held = state.entries.get(id);
|
|
233
|
-
let unread = state.unread;
|
|
234
|
-
if (observed && unread.has(id)) { unread = new Map(unread); unread.delete(id); }
|
|
235
|
-
else if (!observed && held?.deployment?.status === "observed")
|
|
236
|
-
|
|
253
|
+
let unread = state.unread, unreadKeys = state.unreadKeys;
|
|
254
|
+
if (observed && unread.has(id)) { unread = new Map(unread); unread.delete(id); unreadKeys = new Map(unreadKeys); unreadKeys.delete(id); }
|
|
255
|
+
else if (!observed && held?.deployment?.status === "observed") {
|
|
256
|
+
unread = new Map(unread).set(id, new Set((Array.isArray(held.instances) ? held.instances : []).map(instanceId)));
|
|
257
|
+
unreadKeys = new Map(unreadKeys).set(id, memoryKey(state, id));
|
|
258
|
+
}
|
|
259
|
+
const taken = next(state, { entries: new Map(state.entries).set(id, entry), numbers: new Map(state.numbers).set(id, number), unread, unreadKeys });
|
|
237
260
|
if (!observed) return { state: taken, effect: null };
|
|
238
261
|
const step = settled(state, taken);
|
|
239
262
|
if (step.state.arriving?.workspace !== id) return step;
|
|
@@ -247,15 +270,17 @@ function heard(state, { remote, memory, notes, at }) {
|
|
|
247
270
|
return settled(state, next(state, { remote, memory, notes, rosterAt: at, collecting: false }));
|
|
248
271
|
}
|
|
249
272
|
|
|
250
|
-
/** Open the view of deployment `id`: the place the
|
|
251
|
-
* on the way back
|
|
273
|
+
/** Open the view of deployment `id`: the place the workspace left behind is kept (`places`, per
|
|
274
|
+
* memoryKey), and found again on the way back: the row, where the list and the detail were
|
|
275
|
+
* scrolled, and the filter (docs/tui.md, "Tabs"), a field still being typed in kept as Enter keeps
|
|
276
|
+
* it. Another deployment of the same workspace finds the same place. */
|
|
252
277
|
function opened(state, id) {
|
|
253
278
|
const shown = next(state, { view: "instances", back: "instances", switcher: Object.freeze({ ...state.switcher, editing: false, query: "", line: null, refused: null, removing: null }) });
|
|
254
279
|
if (id === state.open) return shown;
|
|
255
280
|
const places = new Map(state.places);
|
|
256
|
-
if (state.open !== null) places.set(state.open, Object.freeze({ selected: state.selected, top: state.top, detailTop: state.detailTop }));
|
|
257
|
-
const place = places.get(id) ?? { selected: null, top: 0, detailTop: 0 };
|
|
258
|
-
return rehomed({ rows: [] }, next(shown, { open: id, places, focus: "list",
|
|
281
|
+
if (state.open !== null) places.set(memoryKey(state, state.open), Object.freeze({ selected: state.selected, top: state.top, detailTop: state.detailTop, filter: Object.freeze({ ...state.filter, editing: false }) }));
|
|
282
|
+
const place = places.get(memoryKey(state, id)) ?? { selected: null, top: 0, detailTop: 0, filter: NO_FILTER };
|
|
283
|
+
return rehomed({ rows: [] }, next(shown, { open: id, places, focus: "list", loose: false, ...place }));
|
|
259
284
|
}
|
|
260
285
|
|
|
261
286
|
/** A picked row of this computer's deployments list that is a deployment (lib/read.mjs made it
|
|
@@ -281,7 +306,7 @@ function joinedHeard(state, { admitted: ids, opens, at }) {
|
|
|
281
306
|
const target = opens.find((id) => joined.ctxs.includes(id) || !id.startsWith("/")) ?? null;
|
|
282
307
|
if (target === null) return { state: joined, effect: { list: true } };
|
|
283
308
|
// The workspace already open (from another machine's deployment) stays where its list was, and keeps its tabs (reduceStep).
|
|
284
|
-
const same = state.open !== null &&
|
|
309
|
+
const same = state.open !== null && memoryKey(joined, target) === memoryKey(state, state.open);
|
|
285
310
|
const shown = opened(joined, target);
|
|
286
311
|
return { state: same ? next(shown, { selected: state.selected, top: state.top, detailTop: state.detailTop }) : shown, effect: { refresh: { live: true } } };
|
|
287
312
|
}
|
|
@@ -304,6 +329,24 @@ function reselected(before, after) {
|
|
|
304
329
|
return found ? next(after, { switcher: Object.freeze({ ...after.switcher, selected: found.key, loose: false }) }) : after;
|
|
305
330
|
}
|
|
306
331
|
|
|
332
|
+
/** The list of workspaces' cursor after a step changed its rows (`before`, then `step`): kept while its
|
|
333
|
+
* row is listed; else on the row that now holds a deployment the cursor's stood for, as the switcher's
|
|
334
|
+
* selection follows it (`reselected`): a listed row whose workspace an identity read learned is in that
|
|
335
|
+
* workspace's row from then on, and back on a row of its own when a later answer takes that away, so
|
|
336
|
+
* Enter opens what was under the cursor. With no such row, the list's own rule: the open row. */
|
|
337
|
+
function cursorKept(before, step) {
|
|
338
|
+
const s = step.state, key = s.workspaceCursor;
|
|
339
|
+
if (key === null || key !== before.workspaceCursor || s.open === null || before.open === null) return step;
|
|
340
|
+
const list = workspaceList(s);
|
|
341
|
+
if (list.rows.some((row) => row.key === key)) return step;
|
|
342
|
+
const was = listChoice(before, key);
|
|
343
|
+
if (was === null) return step;
|
|
344
|
+
const ids = choiceDeployments(was);
|
|
345
|
+
const keys = new Set(list.rows.map((row) => row.key));
|
|
346
|
+
const found = listChoices(s).find((item) => keys.has(item.key) && choiceDeployments(item).some((id) => ids.includes(id)));
|
|
347
|
+
return found ? { ...step, state: next(s, { workspaceCursor: found.key }) } : step;
|
|
348
|
+
}
|
|
349
|
+
|
|
307
350
|
/** What an identity read learned of a deployment of this computer's list (lib/main.mjs): kept for the run,
|
|
308
351
|
* the last answer for each path; an answer replaces the one before it. The switcher's selection
|
|
309
352
|
* follows the deployment it stood on (`reselected`). */
|
|
@@ -578,12 +621,7 @@ function switched(state, action, page, event) {
|
|
|
578
621
|
}
|
|
579
622
|
case "open": {
|
|
580
623
|
const item = s.items.find((each) => each.key !== undefined && each.key === s.selected);
|
|
581
|
-
|
|
582
|
-
if (item.path !== undefined) return item.state === "ok" ? { state: put({ refused: null }), effect: { admit: item.path } } : stay;
|
|
583
|
-
// A workspace with deployments of this computer's list that this run does not serve: each is asked
|
|
584
|
-
// whether it is a deployment now, and served from then on (`joinedHeard`), before the workspace opens.
|
|
585
|
-
if (item.join?.length) return { state: put({ refused: null }), effect: { join: Object.freeze({ paths: item.join, opens: item.opens }) } };
|
|
586
|
-
return item.primary === null ? stay : { state: opened(state, item.primary), effect: { refresh: { live: true } } };
|
|
624
|
+
return (item && picked(state, item)) ?? stay;
|
|
587
625
|
}
|
|
588
626
|
case "remove": {
|
|
589
627
|
const item = s.items.find((each) => each.key !== undefined && each.key === s.selected);
|
|
@@ -595,6 +633,68 @@ function switched(state, action, page, event) {
|
|
|
595
633
|
}
|
|
596
634
|
}
|
|
597
635
|
|
|
636
|
+
/** A choice of the switcher's (or the list of workspaces', the same choices) picked: a row of the
|
|
637
|
+
* list that is a deployment is asked about (`admit`; a stale one does not open: its row says why);
|
|
638
|
+
* a workspace with deployments of this computer's list that this run does not serve has each
|
|
639
|
+
* asked whether it is a deployment now, and served from then on (`joinedHeard`), before it opens;
|
|
640
|
+
* else its view opens here. Null when nothing opens. */
|
|
641
|
+
function picked(state, item) {
|
|
642
|
+
const put = (s) => next(s, { switcher: Object.freeze({ ...s.switcher, refused: null }) });
|
|
643
|
+
if (item.path !== undefined) return item.state === "ok" ? { state: put(state), effect: { admit: item.path } } : null;
|
|
644
|
+
if (item.join?.length) return { state: put(state), effect: { join: Object.freeze({ paths: item.join, opens: item.opens }) } };
|
|
645
|
+
return item.primary === null ? null : { state: opened(state, item.primary), effect: { refresh: { live: true } } };
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/** THE LIST OF WORKSPACES' FOCUS (docs/tui.md, "The list of workspaces"): `w` (or the leader's `o`)
|
|
649
|
+
* gives it to the open workspace's row; the cursor (`workspaceCursor`) moves among the rows that
|
|
650
|
+
* open, passing over the others; Enter opens its row as the switcher's Enter does, and gives the
|
|
651
|
+
* list of instances the focus; Esc gives it back with nothing opened; `w` again shows the
|
|
652
|
+
* switcher, with what the list does not hold. Any other key first gives the focus back, then does
|
|
653
|
+
* what it does there. -> { state, effect }, or null for such a key. */
|
|
654
|
+
function inWorkspaces(state, action) {
|
|
655
|
+
const list = workspaceList(state), cursor = list.rows.some((row) => row.key === state.workspaceCursor) ? state.workspaceCursor : list.current;
|
|
656
|
+
const back = next(state, { focus: "list", workspaceCursor: null });
|
|
657
|
+
switch (action) {
|
|
658
|
+
case "up": case "down": case "top": case "bottom": {
|
|
659
|
+
const openable = list.rows.filter((row) => row.openable);
|
|
660
|
+
const key = action === "top" ? openable[0]?.key : action === "bottom" ? openable.at(-1)?.key : workspaceStep(list.rows, cursor, action === "up" ? -1 : 1);
|
|
661
|
+
return key == null || key === cursor ? { state, effect: null } : { state: next(state, { workspaceCursor: key }), effect: null };
|
|
662
|
+
}
|
|
663
|
+
case "open": {
|
|
664
|
+
const item = cursor === null ? null : listChoice(state, cursor);
|
|
665
|
+
return (item && picked(back, item)) ?? { state, effect: null };
|
|
666
|
+
}
|
|
667
|
+
case "close": case "instances": return { state: back, effect: null };
|
|
668
|
+
case "workspaces": return { state: toSwitcher(next(back, { back: "switcher" })), effect: { list: true, identify: true } };
|
|
669
|
+
default: return null;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
/** `w`: the list of workspaces' focus, on the Instances view (whatever was shown settled first), the
|
|
673
|
+
* open workspace's row under the cursor. With no workspace open there is no list: the switcher. */
|
|
674
|
+
function toWorkspaces(state) {
|
|
675
|
+
if (state.open === null) return { state: toSwitcher(next(state, { back: "switcher" })), effect: { list: true, identify: true } };
|
|
676
|
+
const settled = toInstances(state);
|
|
677
|
+
if (settled.state.view !== "instances") return settled;
|
|
678
|
+
return { state: next(settled.state, { focus: "workspaces", workspaceCursor: workspaceList(settled.state).current }), effect: settled.effect };
|
|
679
|
+
}
|
|
680
|
+
/** The leader's Up and Down (`workspace-previous`, `workspace-next`): the workspace of the row before
|
|
681
|
+
* or after the open one's, as the list draws them (the shared workspaceStep: rows that do not open
|
|
682
|
+
* are passed over, and it does not wrap), opened as a pick of it opens it. From the terminal's
|
|
683
|
+
* focus it is kept for the workspace left (layoutOf); from anywhere else what is open is settled
|
|
684
|
+
* first, as for the leader's other keys (toList). At an end, the line says so and nothing moves:
|
|
685
|
+
* with the list of workspaces' focus, the focus stays there, its cursor where it was. */
|
|
686
|
+
function workspaceMoved(state, step, inTerminal) {
|
|
687
|
+
const settled = inTerminal ? { state, effect: null } : toList(state), s = settled.state;
|
|
688
|
+
const list = workspaceList(s), key = workspaceStep(list.rows, list.current, step);
|
|
689
|
+
const item = key === null ? null : listChoice(s, key);
|
|
690
|
+
if (item === null) {
|
|
691
|
+
const kept = state.view === "instances" && state.focus === "workspaces" ? { focus: "workspaces", workspaceCursor: state.workspaceCursor } : {};
|
|
692
|
+
return { state: next(s, { ...kept, outcome: Object.freeze({ said: step < 0 ? WORKSPACE_WORDS.above() : WORKSPACE_WORDS.below(), under: Object.freeze([]), once: true }) }), effect: settled.effect };
|
|
693
|
+
}
|
|
694
|
+
const moved = picked(s, item) ?? { state: s, effect: null };
|
|
695
|
+
return { state: moved.state, effect: both(settled.effect, moved.effect) };
|
|
696
|
+
}
|
|
697
|
+
|
|
598
698
|
/** A key while the switcher asks whether to remove a row of this computer's deployments list
|
|
599
699
|
* (docs/tui.md, "The switcher"). Enter removes it: the loop runs `oats deployments remove`, and
|
|
600
700
|
* nothing on disk is touched. Esc keeps it, and so does every other key, which then does what it
|
|
@@ -638,7 +738,9 @@ function removedHeard(state, { name, ok, reason = null }) {
|
|
|
638
738
|
* workspace picked in the switcher are deployments now, and the ones it may open, in order),
|
|
639
739
|
* `{ identity: { path, read } }` (what an identity read answered of a row of the list),
|
|
640
740
|
* `{ removed: { path, name, ok, reason } }` (a Remove's answer) and
|
|
641
|
-
* `{ notListed: <reason> }` (the deployment the run started in was not added to the list)
|
|
741
|
+
* `{ notListed: <reason> }` (the deployment the run started in was not added to the list), and
|
|
742
|
+
* `{ passed: true }` (bytes typed to the agent, or a resize: what the loop saw that the store does
|
|
743
|
+
* not, which ends a line of one key).
|
|
642
744
|
* Opening an agent gives five more: `{ prepared: { id, error? } }` (the preflight of another
|
|
643
745
|
* machine's agent ended: `error` is what the shared prepareRemoteTerm threw), `{ given: true }`
|
|
644
746
|
* (the loop gave the preflight up itself: a suspend), `{ shown: { id } }` (the panel has the
|
|
@@ -659,7 +761,11 @@ function removedHeard(state, { name, ok, reason = null }) {
|
|
|
659
761
|
* The line after an open stands until the next key that is bound to an action: a key bound to
|
|
660
762
|
* nothing (a stray back key is no key at all) leaves it. */
|
|
661
763
|
export function reduce(state, event, keymap = bindings(state.actions)) {
|
|
662
|
-
|
|
764
|
+
const step = cursorKept(state, askedStill(noticed(reduceStep(state, event, keymap))));
|
|
765
|
+
// The list of workspaces made once for what the store took (lib/model.mjs workspaceList keeps
|
|
766
|
+
// it while nothing it is made from changes): no paint, resize or key asks the shared home again.
|
|
767
|
+
if (step.state.open !== null) workspaceList(step.state);
|
|
768
|
+
return step;
|
|
663
769
|
}
|
|
664
770
|
|
|
665
771
|
/** Whether the line under the sidebar's title stands now at every width (views/frame.mjs): in the
|
|
@@ -690,18 +796,156 @@ function askedStill(step) {
|
|
|
690
796
|
return { ...step, state: next(step.state, { switcher: Object.freeze({ ...step.state.switcher, removing: null }) }) };
|
|
691
797
|
}
|
|
692
798
|
|
|
799
|
+
/** Whether `event` is the person's: a key, text, a paste, or the leader or a chord typed in a
|
|
800
|
+
* terminal. What the loop reports (a read, a viewer shown or ended, a preflight's answer) is not. */
|
|
801
|
+
const personal = (event) => typeof event.key === "string" || event.text !== undefined || event.paste !== undefined || event.back !== undefined || event.chord !== undefined;
|
|
802
|
+
/** The events whose effect the loop does not take (lib/main.mjs keeps their state alone): the
|
|
803
|
+
* preflight given up and the reads dropped as the process stops, the keyboard protocol confirmed,
|
|
804
|
+
* and what a frame drew. A restore takes no step on one of them, which would lose its open: the
|
|
805
|
+
* next event it hears goes on. */
|
|
806
|
+
const UNTAKEN = Object.freeze(["given", "collecting", "passed", "keyboard", "spawnDrawn", "spawnTop", "capabilitiesTop"]);
|
|
807
|
+
const untaken = (event) => UNTAKEN.some((name) => event[name] !== undefined);
|
|
808
|
+
|
|
809
|
+
/** THE MEMORY OF A WORKSPACE (docs/tui.md, "Tabs"), for the run only, per memoryKey: `places` its
|
|
810
|
+
* place in the list (opened), `recent` the palette's recency (recentWith), and `layouts` its tabs
|
|
811
|
+
* as it was left (layoutOf), which a restore opens again (restoreNext). The workspace `key` gone
|
|
812
|
+
* from the views: all of it forgotten (settled, and remembered for the ones not open). */
|
|
813
|
+
function forgotten(state, key) {
|
|
814
|
+
const without = (map) => { const kept = new Map(map); kept.delete(key); return kept; };
|
|
815
|
+
return { places: without(state.places), recent: without(state.recent), layouts: without(state.layouts) };
|
|
816
|
+
}
|
|
817
|
+
/** The tabs of the open workspace as they stand, for its memory, or null with none:
|
|
818
|
+
* `{ tabs: [{ id, name, machine, routed, group }], split, group, shown: [group 0's, group 1's],
|
|
819
|
+
* focus, zoom }`. The focus is the terminal's, or the one it had when another view was shown over
|
|
820
|
+
* the list (`leftFocus`, the switcher a workspace is left from), or the terminal's while the
|
|
821
|
+
* palette opened from it stands (the leader's Up and Down leave from there; the palette took the
|
|
822
|
+
* zoom, as its Esc gives the focus back unzoomed: paletteClosed). During a restore it is the
|
|
823
|
+
* remembered layout, less the tabs that went since (closed, or dropped as gone), and the focus
|
|
824
|
+
* only while the person has not taken it. */
|
|
825
|
+
function layoutOf(state) {
|
|
826
|
+
const r = state.restoring;
|
|
827
|
+
if (r !== null) {
|
|
828
|
+
const still = new Set([...state.tabs, ...r.queue].map((tab) => tab.id)), tabs = r.tabs.filter((tab) => still.has(tab.id));
|
|
829
|
+
return tabs.length ? Object.freeze({ tabs: Object.freeze(tabs), split: r.split, group: r.group, shown: r.shown, focus: r.grant ? r.focus : "list", zoom: r.grant && r.zoom }) : null;
|
|
830
|
+
}
|
|
831
|
+
if (!state.tabs.length) return null;
|
|
832
|
+
const t = state.terminal, left = t === null || t.focus === "terminal" ? null
|
|
833
|
+
: state.leftFocus?.id === t.id ? state.leftFocus : state.palette?.from === "terminal" ? Object.freeze({ id: t.id, zoom: false }) : null;
|
|
834
|
+
return Object.freeze({
|
|
835
|
+
tabs: Object.freeze(state.tabs.map(({ id, name, machine, routed, group }) => Object.freeze({ id, name, machine, routed, group }))),
|
|
836
|
+
split: state.split, group: state.group, shown: Object.freeze([shownOf(state, 0), shownOf(state, 1)]),
|
|
837
|
+
focus: left !== null ? "terminal" : t?.focus ?? "list", zoom: left !== null ? left.zoom : t?.zoom ?? false,
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
/** Another workspace opened (or none, the one open gone): the tabs of the one left are kept in its
|
|
841
|
+
* memory, unless it went, then closed, their viewers ended (the agents keep running), the split
|
|
842
|
+
* with them, and an open under way given up. The workspace opened, when its memory holds tabs,
|
|
843
|
+
* starts its restore: they open again one at a time (restoreNext), the focus given back at the
|
|
844
|
+
* end unless the person moved it meanwhile (`grant`). */
|
|
845
|
+
function workspaceLeft(before, step) {
|
|
846
|
+
const s = step.state, layouts = new Map(s.layouts);
|
|
847
|
+
const was = memoryKey(before, before.open), now = memoryKey(s, s.open);
|
|
848
|
+
if (was !== null && s.open !== null) { const kept = layoutOf(before); if (kept !== null) layouts.set(was, kept); else layouts.delete(was); }
|
|
849
|
+
const ids = s.tabs.map((tab) => tab.id), record = now === null ? undefined : layouts.get(now);
|
|
850
|
+
if (record !== undefined) layouts.delete(now);
|
|
851
|
+
const restoring = record === undefined ? null : Object.freeze({ key: now, ...record, queue: record.tabs, grant: true });
|
|
852
|
+
const closed = next(s, { tabs: Object.freeze([]), terminal: null, ...NO_SPLIT, opening: null, layouts, restoring, leftFocus: null });
|
|
853
|
+
const ends = { ...(ids.length ? { close: ids } : {}), ...(s.opening !== null ? { abandon: true } : {}) };
|
|
854
|
+
return { state: closed, effect: Object.keys(ends).length ? both(step.effect, ends) : step.effect };
|
|
855
|
+
}
|
|
856
|
+
/** The next step of a restore (docs/tui.md, "Tabs"): nothing while a tab is starting or another
|
|
857
|
+
* machine is asked (one open at a time), nor before the view's rows are read (an instance not
|
|
858
|
+
* read is not gone), nor, for a tab missing from them, before what holds it is known: the roster
|
|
859
|
+
* of other machines first answered, for another machine's, and for this machine's, its
|
|
860
|
+
* deployment read again when its read failed with nothing kept (unreadHolds). Then the next
|
|
861
|
+
* remembered tab whose instance can be opened now opens, after the ones before it, with the list
|
|
862
|
+
* keeping the focus; one that is gone or cannot be opened (retired, stopped) is dropped, the line
|
|
863
|
+
* saying nothing. Another machine's is asked first again, as an
|
|
864
|
+
* open is, and dropped with the line that says why when that fails (prepared). The last one
|
|
865
|
+
* opened: restoreDone. */
|
|
866
|
+
function restoreNext(state) {
|
|
867
|
+
const r = state.restoring;
|
|
868
|
+
if (state.opening !== null || state.tabs.some((tab) => tab.status === "starting")) return { state, effect: null };
|
|
869
|
+
const rows = roster(state);
|
|
870
|
+
if (!rows.observed) return { state, effect: null };
|
|
871
|
+
let queue = r.queue;
|
|
872
|
+
while (queue.length) {
|
|
873
|
+
const tab = queue[0], row = rows.instances.find((each) => instanceId(each) === tab.id) ?? null;
|
|
874
|
+
if (row === null && (tab.routed ? !state.remote.rosterAnswered : unreadHolds(state, tab.id))) break;
|
|
875
|
+
queue = queue.slice(1);
|
|
876
|
+
const decision = row === null ? null : openDecision(state, row, instanceActs(row));
|
|
877
|
+
if (!decision?.open || state.tabs.length >= TAB_LIMIT) continue;
|
|
878
|
+
const s = next(state, { restoring: Object.freeze({ ...r, queue }) });
|
|
879
|
+
if (!decision.routed) return { state: restoredTab(s, decision), effect: { open: decision } };
|
|
880
|
+
return { state: next(s, { opening: Object.freeze({ id: decision.id, phase: "preflight", name: decision.name, machine: decision.machine, routed: true, restore: true }) }), effect: { open: decision } };
|
|
881
|
+
}
|
|
882
|
+
const left = next(state, { restoring: Object.freeze({ ...r, queue }) });
|
|
883
|
+
return queue.length ? { state: left, effect: null } : restoreDone(left);
|
|
884
|
+
}
|
|
885
|
+
/** Whether instance `id` is one a deployment held when its read failed with nothing kept (`unread`,
|
|
886
|
+
* see `took`): not gone, not known, until that deployment is read again. */
|
|
887
|
+
const unreadHolds = (state, id) => [...state.unread.values()].some((ids) => ids.has(id));
|
|
888
|
+
/** A remembered tab opened again: starting, after the others, shown in the one group a restore
|
|
889
|
+
* opens into, the list keeping the focus. */
|
|
890
|
+
function restoredTab(state, { id, name, machine, routed }) {
|
|
891
|
+
const tab = Object.freeze({ id, name, machine, routed, status: "starting", activity: false, group: 0 });
|
|
892
|
+
return next(state, { tabs: Object.freeze([...state.tabs, tab]), terminal: Object.freeze({ id, name, machine, routed, group: 0, focus: "list", zoom: false, status: "starting" }) });
|
|
893
|
+
}
|
|
894
|
+
/** A restore's end: the tabs opened again take their groups, the split as remembered (when the
|
|
895
|
+
* drops leave a group with none, the other takes the panel, as when a group's last tab closes:
|
|
896
|
+
* ungrouped; a group left empty is empty again);
|
|
897
|
+
* each group shows its remembered tab, or the one a close would show in its place (the next, else
|
|
898
|
+
* the one before); the focused group's, with the remembered focus and zoom while the person has
|
|
899
|
+
* not taken the focus meanwhile, and the list's otherwise. It is the most recent for the palette
|
|
900
|
+
* (showTab). The list's place, filter and collapse stay as they are: the workspace's own, or what
|
|
901
|
+
* the person made of them meanwhile. */
|
|
902
|
+
function restoreDone(state) {
|
|
903
|
+
const r = state.restoring, s = next(state, { restoring: null });
|
|
904
|
+
if (!s.tabs.length) return { state: next(s, { terminal: null, ...NO_SPLIT }), effect: null };
|
|
905
|
+
const open = new Set(s.tabs.map((tab) => tab.id));
|
|
906
|
+
const shownIn = (g) => {
|
|
907
|
+
const mine = r.tabs.filter((tab) => tab.group === g), at = Math.max(0, mine.findIndex((tab) => tab.id === r.shown[g]));
|
|
908
|
+
return [...mine.slice(at), ...mine.slice(0, at).reverse()].find((tab) => open.has(tab.id))?.id ?? null;
|
|
909
|
+
};
|
|
910
|
+
// A group that had no tab when the workspace was left is empty again; one emptied by the drops
|
|
911
|
+
// is no group.
|
|
912
|
+
const had = (g) => r.tabs.some((tab) => tab.group === g);
|
|
913
|
+
const split = r.split !== null && [0, 1].every((g) => shownIn(g) !== null || !had(g));
|
|
914
|
+
const groupOf = new Map(r.tabs.map((tab) => [tab.id, tab.group]));
|
|
915
|
+
const tabs = Object.freeze(s.tabs.map((tab) => { const group = split ? groupOf.get(tab.id) ?? 0 : 0; return tab.group === group ? tab : Object.freeze({ ...tab, group }); }));
|
|
916
|
+
const group = split ? r.group : 0, focused = split ? shownIn(r.group) : shownIn(r.group) ?? shownIn(1 - r.group);
|
|
917
|
+
const laid = next(s, { tabs, split: split ? r.split : null, group, aside: split ? shownIn(1 - r.group) : null, terminal: null });
|
|
918
|
+
// The focused group empty, as it was left: nothing has the focus but the list, and the other
|
|
919
|
+
// group's shown tab is the most recent.
|
|
920
|
+
const step = focused === null ? { state: next(laid, { recent: recentWith(laid, laid.aside) }), effect: null } : showTab(laid, focused, { focus: r.grant ? r.focus : "list", zoom: r.grant && r.zoom });
|
|
921
|
+
return { state: next(step.state, { selected: s.selected, top: s.top, loose: s.loose, detailTop: s.detailTop, filter: s.filter, collapsed: s.collapsed }), effect: step.effect };
|
|
922
|
+
}
|
|
923
|
+
|
|
693
924
|
function reduceStep(state, event, keymap) {
|
|
694
|
-
|
|
925
|
+
// (Not the rest of a read the leader came in: that is dropped, and the line says so.)
|
|
926
|
+
if (state.outcome !== null && typeof event.key === "string" && keymap.has(event.key) && !(state.leader !== null && sameRead(state.leader, event))) state = next(state, { outcome: null });
|
|
927
|
+
// A key of the person's while a restore runs: the focus is theirs from then on (restoreDone).
|
|
928
|
+
if (state.restoring?.grant && personal(event)) state = next(state, { restoring: Object.freeze({ ...state.restoring, grant: false }) });
|
|
695
929
|
let step = reduced(state, event, keymap);
|
|
930
|
+
// A line of one key (`once`) goes at the next key of any kind, bound or not, unless that key said
|
|
931
|
+
// a line of its own. Not at the leader alone: while it waits nothing on the screen changes.
|
|
932
|
+
if (state.outcome?.once === true && personal(event) && step.state.outcome === state.outcome && step.state.leader === null) step = { ...step, state: next(step.state, { outcome: null }) };
|
|
696
933
|
// The tabs are the open workspace's: whatever opened another (or left it, gone), they all close,
|
|
697
|
-
// and the split with them. Another deployment of the same
|
|
698
|
-
// machine, once served, in place of another machine's)
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
934
|
+
// and the split with them, kept in its memory (workspaceLeft). Another deployment of the same
|
|
935
|
+
// workspace opened (its deployment of this machine, once served, in place of another machine's)
|
|
936
|
+
// keeps them.
|
|
937
|
+
if (step.state.open !== state.open && memoryKey(step.state, step.state.open) !== memoryKey(state, state.open)) step = workspaceLeft(state, step);
|
|
938
|
+
// Nor on a step that quits, suspends or redraws (an effect of its own, which an open would
|
|
939
|
+
// take the place of): the next event goes on.
|
|
940
|
+
if (step.state.restoring !== null && !untaken(event) && typeof step.effect !== "string") { const more = restoreNext(step.state); step = { state: more.state, effect: both(step.effect, more.effect) }; }
|
|
941
|
+
// Where the focus was when another view (the switcher, the help) was shown over the list, or the
|
|
942
|
+
// list of workspaces took the focus: in the terminal, or in the palette opened from it, which give
|
|
943
|
+
// it to the list as they go. A workspace left from there keeps it (layoutOf); back in the list of
|
|
944
|
+
// instances it is forgotten.
|
|
945
|
+
const t0 = state.terminal, listing = (s) => s.view === "instances" && s.focus === "workspaces";
|
|
946
|
+
const away = state.view === "instances" && !listing(state) && (step.state.view !== "instances" || listing(step.state));
|
|
947
|
+
if (away && t0 !== null && step.state.terminal?.id === t0.id && (t0.focus === "terminal" || state.palette?.from === "terminal")) step = { ...step, state: next(step.state, { leftFocus: Object.freeze({ id: t0.id, zoom: t0.focus === "terminal" && t0.zoom }) }) };
|
|
948
|
+
else if (step.state.view === "instances" && !listing(step.state) && step.state.leftFocus !== null) step = { ...step, state: next(step.state, { leftFocus: null }) };
|
|
705
949
|
// The terminal has the focus only while the list of instances is shown: anything that shows
|
|
706
950
|
// another view (a workspace gone, which shows the switcher) gives the focus back to the list.
|
|
707
951
|
const t = step.state.terminal;
|
|
@@ -837,7 +1081,7 @@ function prepared(state, { id, error }) {
|
|
|
837
1081
|
if (opening === null || opening.id !== id || opening.phase !== "preflight") return { state, effect: null };
|
|
838
1082
|
if (error !== undefined) return { state: next(state, { opening: null, outcome: preflightLine(opening, error) }), effect: null };
|
|
839
1083
|
if (!roster(state).instances.some((row) => instanceId(row) === id)) return { state: next(state, { opening: null }), effect: null };
|
|
840
|
-
return { state: tabOpened(next(state, { opening: null }), opening), effect: { panel: id } };
|
|
1084
|
+
return { state: (opening.restore ? restoredTab : tabOpened)(next(state, { opening: null }), opening), effect: { panel: id } };
|
|
841
1085
|
}
|
|
842
1086
|
|
|
843
1087
|
/** The viewer of a tab ended by itself: its tab closes, the line says what happened, naming its
|
|
@@ -882,6 +1126,8 @@ function returned(state, { id, status, stderr, asked = false, refused = null })
|
|
|
882
1126
|
* holds its tab's place in the cap. Every open counts for the palette's recency (`recent`), as
|
|
883
1127
|
* every tab shown does (showTab). */
|
|
884
1128
|
function openAgent(state, row) {
|
|
1129
|
+
// The person's own open: a restore under way yields, and what it has not opened yet is dropped.
|
|
1130
|
+
if (state.restoring !== null) state = next(state, { restoring: null });
|
|
885
1131
|
if (state.opening !== null) return { state, effect: null };
|
|
886
1132
|
const id = instanceId(row);
|
|
887
1133
|
// A tab still starting is the one shown until the panel has its window (one open at a time).
|
|
@@ -927,7 +1173,7 @@ export function splitRefused(state, does, room, inTerminal = false) {
|
|
|
927
1173
|
return splitFits(dir, room) ? null : Object.freeze({ said: SPLIT_WORDS.small(dir, SPLIT_MIN), under: Object.freeze([]) });
|
|
928
1174
|
}
|
|
929
1175
|
// One group: only from the list, to its terminal.
|
|
930
|
-
case "group-next": return state.split === null && (inTerminal || state.terminal === null) ? true : null;
|
|
1176
|
+
case "group-next": case "group-previous": return state.split === null && (inTerminal || state.terminal === null) ? true : null;
|
|
931
1177
|
case "tab-move": return state.split === null || state.terminal === null ? true : null;
|
|
932
1178
|
case "group-close": return state.split === null || state.terminal !== null ? true : null;
|
|
933
1179
|
default: return true;
|
|
@@ -937,9 +1183,9 @@ export function splitRefused(state, does, room, inTerminal = false) {
|
|
|
937
1183
|
* when it came from the terminal's focus:
|
|
938
1184
|
* split-right, split-down: the tabs stay in the first group (left or top), and the second, empty,
|
|
939
1185
|
* is the focused one; the keys are the list's (Settled 2 of T3), so Enter on a row opens there;
|
|
940
|
-
* group-next: to the other group's shown terminal, with the focus (to the empty
|
|
941
|
-
* the keys the list's); from the list, to the focused group's terminal, or with
|
|
942
|
-
* empty to the other's;
|
|
1186
|
+
* group-next, group-previous: to the other group's shown terminal, with the focus (to the empty
|
|
1187
|
+
* group: focused, the keys the list's); from the list, to the focused group's terminal, or with
|
|
1188
|
+
* that group empty to the other's (with two groups the previous is the next);
|
|
943
1189
|
* tab-move: the focused group's shown tab to the other group, after its shown tab, shown there
|
|
944
1190
|
* with the focus; the group it leaves shows its neighbour, or stays, empty;
|
|
945
1191
|
* group-close: the empty focused group goes; the other takes the panel and is focused, and the
|
|
@@ -949,7 +1195,7 @@ function splitKey(state, does, inTerminal) {
|
|
|
949
1195
|
switch (does) {
|
|
950
1196
|
case "split-right": case "split-down":
|
|
951
1197
|
return { state: next(state, { split: does === "split-right" ? "right" : "down", group: 1, aside: t?.id ?? null, terminal: null, focus: "list" }), effect: null };
|
|
952
|
-
case "group-next": {
|
|
1198
|
+
case "group-next": case "group-previous": {
|
|
953
1199
|
if (state.split === null || (!inTerminal && t !== null)) return { state: terminalWith(state, { focus: "terminal" }), effect: null };
|
|
954
1200
|
const there = shownOf(state, other);
|
|
955
1201
|
if (there !== null) return showTab(state, there, { focus: "terminal", zoom: false });
|
|
@@ -1073,18 +1319,34 @@ function acted(state, event) {
|
|
|
1073
1319
|
return { state, effect: null };
|
|
1074
1320
|
}
|
|
1075
1321
|
|
|
1076
|
-
/** The
|
|
1322
|
+
/** The preflight under way given up (the process stops: lib/main.mjs stopPreflight). A restore's
|
|
1323
|
+
* tab is put back first in its queue, asked again on the next event the restore hears (one whose
|
|
1324
|
+
* effect the loop takes: reduceStep). */
|
|
1325
|
+
function preflightGiven(state) {
|
|
1326
|
+
const o = state.opening, r = state.restoring, tab = o.restore && r !== null ? r.tabs.find((each) => each.id === o.id) : undefined;
|
|
1327
|
+
const back = tab !== undefined ? { restoring: Object.freeze({ ...r, queue: Object.freeze([tab, ...r.queue]) }) } : {};
|
|
1328
|
+
return { state: next(state, { opening: null, ...back }), effect: null };
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
/** The instances the palette's recency keeps, per workspace. */
|
|
1077
1332
|
const RECENT_KEPT = 50;
|
|
1078
1333
|
/** The actions of the split (docs/tui.md, "Splits"). */
|
|
1079
|
-
const SPLIT_KEYS = Object.freeze(["split-right", "split-down", "group-next", "tab-move", "group-close"]);
|
|
1080
|
-
/** The palette's recency with `id` the most recent: an open, and
|
|
1081
|
-
|
|
1334
|
+
const SPLIT_KEYS = Object.freeze(["split-right", "split-down", "group-next", "group-previous", "tab-move", "group-close"]);
|
|
1335
|
+
/** The palette's recency with `id` the most recent in the open workspace's (memoryKey): an open, and
|
|
1336
|
+
* a tab shown. */
|
|
1337
|
+
function recentWith(state, id) {
|
|
1338
|
+
const key = memoryKey(state, state.open), was = state.recent.get(key) ?? [];
|
|
1339
|
+
return new Map(state.recent).set(key, Object.freeze([id, ...was.filter((each) => each !== id)].slice(0, RECENT_KEPT)));
|
|
1340
|
+
}
|
|
1082
1341
|
/** How many terminals the panel holds open at once (lib/panel.mjs MAX_TERMINALS, which a test
|
|
1083
1342
|
* holds this to). */
|
|
1084
1343
|
export const TAB_LIMIT = 4;
|
|
1085
1344
|
const leaderAt = (read, waiting) => Object.freeze({ read: Number.isInteger(read) ? read : null, waiting });
|
|
1086
1345
|
/** Whether an event came in the same read of input as the leader. */
|
|
1087
1346
|
const sameRead = (leader, event) => leader.read !== null && event.read === leader.read;
|
|
1347
|
+
/** The line of a leader cancelled by what came in its own read: nothing ran, and why. A line of one
|
|
1348
|
+
* key (`once`): from a terminal's focus it goes as the person types on, not at a key bound in the list. */
|
|
1349
|
+
const mergedLine = (state) => Object.freeze({ said: LEADER_WORDS.merged(backKeyLabel(state.detachKey)), under: Object.freeze([]), once: true });
|
|
1088
1350
|
/** Two effects as one: the dismissal of a confirmation the leader closed, and what it then ran. */
|
|
1089
1351
|
const both = (a, b) => (a === null ? b : b === null ? a : typeof b === "string" ? b : { ...a, ...b });
|
|
1090
1352
|
|
|
@@ -1105,7 +1367,7 @@ function leading(state, event, keymap) {
|
|
|
1105
1367
|
if (event.back !== undefined) {
|
|
1106
1368
|
if (state.terminal?.focus !== "terminal") return { state, effect: null };
|
|
1107
1369
|
if (l !== null && l.waiting && !sameRead(l, event)) return twice(next(state, { leader: leaderAt(event.read, false) }));
|
|
1108
|
-
return { state: next(state, { leader: leaderAt(event.read, event.rest !== true) }), effect: null };
|
|
1370
|
+
return { state: next(state, { leader: leaderAt(event.read, event.rest !== true), ...(event.rest === true ? { outcome: mergedLine(state) } : {}) }), effect: null };
|
|
1109
1371
|
}
|
|
1110
1372
|
// A chord typed in a terminal (term/through.mjs): the leader then its key, at once. Only one
|
|
1111
1373
|
// that is read now (chordsRead): the scanner takes no other.
|
|
@@ -1114,7 +1376,7 @@ function leading(state, event, keymap) {
|
|
|
1114
1376
|
return led(l === null ? state : next(state, { leader: null }), event.chord, event, keymap);
|
|
1115
1377
|
}
|
|
1116
1378
|
if (typeof event.key !== "string" && !("paste" in event)) return { pass: state };
|
|
1117
|
-
if (l !== null && sameRead(l, event)) return { state: l.waiting ? next(state, { leader: leaderAt(l.read, false) }) : state, effect: null };
|
|
1379
|
+
if (l !== null && sameRead(l, event)) return { state: l.waiting ? next(state, { leader: leaderAt(l.read, false), outcome: mergedLine(state) }) : state, effect: null };
|
|
1118
1380
|
if (l !== null && l.waiting) {
|
|
1119
1381
|
const after = next(state, { leader: leaderAt(event.read, false) });
|
|
1120
1382
|
if (event.key === state.leaderKey) return twice(after);
|
|
@@ -1128,15 +1390,15 @@ function leading(state, event, keymap) {
|
|
|
1128
1390
|
// A chord typed in a terminal (`{ chord }`, above) never comes then: the terminal has no focus.
|
|
1129
1391
|
if (state.palette !== null && typeof event.key === "string" && state.paletteKeys.has(event.key)) return { pass: plain };
|
|
1130
1392
|
// THE CHORDS (docs/tui.md, "Chords"): a chord does what the leader then its key does, from
|
|
1131
|
-
// whatever was open: every one while the terminal confirms the kitty keyboard protocol,
|
|
1132
|
-
//
|
|
1393
|
+
// whatever was open: every one while the terminal confirms the kitty keyboard protocol, those with
|
|
1394
|
+
// bytes of their own without it too (chordsRead: the Alt family, the arrows). While the leader waits it is a key not in the
|
|
1133
1395
|
// leader's table (above): it cancels the leader and is dropped.
|
|
1134
1396
|
const chord = typeof event.key !== "string" ? undefined : chordsRead(state.chords, state.keyboard !== null).get(event.key);
|
|
1135
1397
|
if (chord !== undefined) return led(plain, chord, event, keymap);
|
|
1136
1398
|
return { pass: plain };
|
|
1137
1399
|
}
|
|
1138
1400
|
|
|
1139
|
-
/** The leader twice (`state` is after it,
|
|
1401
|
+
/** The leader twice (`state` is after it, the leader cancelled). While the open terminal has the focus,
|
|
1140
1402
|
* which it keeps, the leader's own key goes to the agent: the effect `{ input: <bytes> }`, the
|
|
1141
1403
|
* bytes a terminal sends for the back key (term/through.mjs backKeySequences, its first form:
|
|
1142
1404
|
* 0x18 for C-x, the default; ESC o for M-o), which the loop types into the focused tab as it types what
|
|
@@ -1162,7 +1424,7 @@ function toList(state) {
|
|
|
1162
1424
|
if (field) s = field.close(s, field.query(s).trim());
|
|
1163
1425
|
if (s.view === "souls" || s.view === "capabilities") s = s.open === null ? toSwitcher(next(s, { back: "switcher" })) : next(s, { view: "instances", back: "instances" });
|
|
1164
1426
|
if (s.terminal?.focus === "terminal") s = terminalWith(s, { focus: "list", zoom: false });
|
|
1165
|
-
if (s.view === "instances" && s.focus === "detail") s = next(s, { focus: "list" });
|
|
1427
|
+
if (s.view === "instances" && (s.focus === "detail" || s.focus === "workspaces")) s = next(s, { focus: "list", workspaceCursor: null });
|
|
1166
1428
|
return { state: s, effect };
|
|
1167
1429
|
}
|
|
1168
1430
|
|
|
@@ -1220,6 +1482,7 @@ function led(state, does, event, keymap) {
|
|
|
1220
1482
|
return { state: step.state, effect: both(settledState.effect, step.effect) };
|
|
1221
1483
|
}
|
|
1222
1484
|
if (does === "previous" || does === "next") return stepped(state, does === "previous" ? -1 : 1, event);
|
|
1485
|
+
if (does === "workspace-previous" || does === "workspace-next") return workspaceMoved(state, does === "workspace-previous" ? -1 : 1, inTerminal);
|
|
1223
1486
|
// Another of the open terminal's soul, from its focus; from anywhere else, of the selection's.
|
|
1224
1487
|
// The Souls view's selected soul is named before the list is shown, which leaves that view.
|
|
1225
1488
|
if (does === "spawn" || does === "spawn-another") {
|
|
@@ -1356,7 +1619,7 @@ function reduced(state, event, keymap) {
|
|
|
1356
1619
|
if (event.keyboard !== undefined) return { state: next(state, { keyboard: event.keyboard }), effect: null };
|
|
1357
1620
|
if (event.acted !== undefined) return acted(state, event.acted);
|
|
1358
1621
|
if (event.prepared !== undefined) return prepared(state, event.prepared);
|
|
1359
|
-
if (event.given !== undefined) return state.opening?.phase === "preflight" ?
|
|
1622
|
+
if (event.given !== undefined) return state.opening?.phase === "preflight" ? preflightGiven(state) : stay;
|
|
1360
1623
|
if (event.returned !== undefined) return returned(state, event.returned);
|
|
1361
1624
|
if (event.shown !== undefined) return state.tabs.some((tab) => tab.id === event.shown.id) ? { state: tabWith(state, event.shown.id, { status: "open" }), effect: null } : stay;
|
|
1362
1625
|
// A hidden tab's agent wrote (the panel says so once per hidden spell): its mark.
|
|
@@ -1364,6 +1627,8 @@ function reduced(state, event, keymap) {
|
|
|
1364
1627
|
if (event.entry !== undefined) return took(state, event);
|
|
1365
1628
|
if (event.roster !== undefined) return heard(state, event.roster);
|
|
1366
1629
|
if (event.collecting !== undefined) return { state: event.collecting === state.collecting ? state : next(state, { collecting: event.collecting === true }), effect: null };
|
|
1630
|
+
// What the loop saw that the store does not: bytes typed to the agent, a resize. A line of one key goes.
|
|
1631
|
+
if (event.passed !== undefined) return { state: state.outcome?.once === true ? next(state, { outcome: null }) : state, effect: null };
|
|
1367
1632
|
// The rows stay where they are: only what they read changes.
|
|
1368
1633
|
if (event.retiring !== undefined) return { state: next(state, { retiring: new Set(event.retiring) }), effect: null };
|
|
1369
1634
|
if (event.listed !== undefined) return listedHeard(state, event.listed);
|
|
@@ -1374,7 +1639,12 @@ function reduced(state, event, keymap) {
|
|
|
1374
1639
|
if (event.admitted !== undefined) return { state: admitted(state, event), effect: { refresh: { live: true } } };
|
|
1375
1640
|
if (event.joined !== undefined) return joinedHeard(state, { ...event.joined, at: event.at });
|
|
1376
1641
|
if (event.identity !== undefined) return identityHeard(state, event.identity);
|
|
1377
|
-
if (event.refused !== undefined)
|
|
1642
|
+
if (event.refused !== undefined) {
|
|
1643
|
+
// Picked from the list of workspaces, the switcher not shown: the line says so.
|
|
1644
|
+
const name = state.listed.rows.find((row) => row.path === event.refused)?.name ?? event.refused;
|
|
1645
|
+
const said = state.view === "switcher" ? {} : { outcome: Object.freeze({ said: WORKSPACE_WORDS.refused(name), under: Object.freeze([]) }) };
|
|
1646
|
+
return { state: next(state, { switcher: Object.freeze({ ...state.switcher, refused: event.refused }), ...said }), effect: null };
|
|
1647
|
+
}
|
|
1378
1648
|
if (event.souls !== undefined) return soulsHeard(state, event.souls);
|
|
1379
1649
|
if (event.capabilities !== undefined) return capabilitiesHeard(state, event.capabilities);
|
|
1380
1650
|
if (event.capabilitiesTop !== undefined) return capabilitiesTop(state, event.capabilitiesTop);
|
|
@@ -1409,13 +1679,18 @@ function reduced(state, event, keymap) {
|
|
|
1409
1679
|
return windowOf({ top: moved(action, from, count, height), count, height }).top;
|
|
1410
1680
|
};
|
|
1411
1681
|
|
|
1682
|
+
if (state.view === "instances" && state.focus === "workspaces") {
|
|
1683
|
+
const step = inWorkspaces(state, action);
|
|
1684
|
+
if (step !== null) return step;
|
|
1685
|
+
state = next(state, { focus: "list", workspaceCursor: null });
|
|
1686
|
+
}
|
|
1412
1687
|
switch (action) {
|
|
1413
1688
|
case "quit": case "suspend": case "redraw": return { state, effect: action };
|
|
1414
1689
|
// In the switcher this computer's deployments list is read again too.
|
|
1415
1690
|
// In the Souls view it reads the souls again, and nothing else; in the Capabilities view, the capabilities.
|
|
1416
1691
|
case "refresh": return state.view === "souls" ? inSouls(state, action, event, page, scrolled) : state.view === "capabilities" ? inCapabilities(state, action, event, page, scrolled) : { state, effect: { refresh: { live: true }, ...((state.view === "help" ? state.back : state.view) === "switcher" ? { list: true, identify: true } : {}) } };
|
|
1417
1692
|
case "help": return { state: next(state, state.view === "help" ? { view: state.back } : { view: "help", back: state.view, helpTop: 0 }), effect: null };
|
|
1418
|
-
case "workspaces": return state.view === "switcher" ? stay :
|
|
1693
|
+
case "workspaces": return state.view === "switcher" ? stay : toWorkspaces(state);
|
|
1419
1694
|
case "palette": return { state: paletteOpened(state, event, "list"), effect: null };
|
|
1420
1695
|
// Souls and Capabilities are views of this machine, whatever workspace is open, or none.
|
|
1421
1696
|
case "souls": return soulsShown(state);
|
|
@@ -1448,7 +1723,7 @@ function reduced(state, event, keymap) {
|
|
|
1448
1723
|
case "open": return at < 0 ? stay : openAgent(state, r.items[at].row);
|
|
1449
1724
|
case "zoom": case "close-terminal": return terminalKey(state, action);
|
|
1450
1725
|
case "tab-previous": case "tab-next": return tabPicked(state, TAB_PICKS[action]);
|
|
1451
|
-
case "split-right": case "split-down": case "group-next": case "tab-move": case "group-close": {
|
|
1726
|
+
case "split-right": case "split-down": case "group-next": case "group-previous": case "tab-move": case "group-close": {
|
|
1452
1727
|
const refused = splitRefused(state, action, event.panel);
|
|
1453
1728
|
return refused === true ? { state, effect: null } : refused !== null ? { state: next(state, { outcome: refused }), effect: null } : splitKey(state, action, false);
|
|
1454
1729
|
}
|