@awebai/oats 0.57.0 → 0.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/oats.mjs +24 -11
- package/docs/configuration.md +19 -28
- package/docs/desktop-cli-api.md +38 -15
- package/docs/desktop.md +14 -0
- package/docs/execution-targets.md +10 -1
- package/docs/implementation.md +7 -1
- package/docs/integrations.md +3 -1
- package/docs/official-catalog.md +1 -1
- package/docs/packages.md +5 -5
- package/docs/release-notes/v0.57.1.md +275 -0
- package/docs/release-notes/v0.58.0.md +107 -0
- package/docs/servers.md +18 -0
- package/docs/souls-and-instances.md +9 -0
- package/docs/tui.md +224 -87
- package/docs/workspaces.md +1 -1
- package/lib/core.mjs +11 -4
- package/lib/session-viewer.mjs +29 -4
- package/package-catalog.json +1 -1
- package/package.json +1 -1
- package/packages/client/cli-adapter.mjs +9 -7
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/composed-gate.mjs +34 -0
- package/packages/client/inspect-boundary.mjs +157 -0
- package/packages/client/inspect-cache.mjs +86 -0
- package/packages/client/keyed-catalog.mjs +132 -0
- package/packages/client/launch-view.mjs +46 -0
- package/packages/client/panel-views.mjs +1 -1
- package/packages/client/session-attach.mjs +7 -5
- package/packages/client/soul-catalog.mjs +77 -0
- package/packages/client/soul-colors.mjs +31 -0
- package/packages/client/soul-facts.mjs +85 -0
- package/packages/client/soul-rows.mjs +48 -0
- package/packages/client/spawn-apply-cli.mjs +19 -8
- package/packages/client/spawn-apply.mjs +216 -0
- package/packages/client/spawn-messages.mjs +131 -85
- package/packages/client/spawn-preview-cli.mjs +2 -1
- package/packages/client/spawn-preview-contract.mjs +3 -0
- package/packages/client/spawn-preview-facts.mjs +119 -0
- package/packages/client/spawn-preview.mjs +164 -0
- package/packages/client/spawn-transaction.mjs +136 -0
- package/packages/record/lib/directory-identity.mjs +14 -0
- package/packages/record/lib/native-history.mjs +6 -5
- package/packages/tui/README.md +32 -11
- package/packages/tui/lib/actions.mjs +10 -1
- package/packages/tui/lib/config.mjs +9 -14
- package/packages/tui/lib/main.mjs +165 -57
- package/packages/tui/lib/model.mjs +28 -24
- package/packages/tui/lib/panel.mjs +1019 -0
- package/packages/tui/lib/read.mjs +5 -14
- package/packages/tui/lib/store.mjs +77 -30
- package/packages/tui/lib/term/capture.mjs +260 -0
- package/packages/tui/lib/term/screen.mjs +44 -8
- package/packages/tui/lib/term/style.mjs +78 -6
- package/packages/tui/lib/term/text.mjs +24 -4
- package/packages/tui/lib/term/through.mjs +213 -0
- package/packages/tui/lib/term/tty.mjs +7 -60
- package/packages/tui/lib/views/frame.mjs +126 -40
- package/packages/tui/lib/views/help.mjs +12 -10
- package/skills/oats-getting-started/SKILL.md +3 -2
- package/packages/tui/lib/open.mjs +0 -45
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
// `oats tui` (preview): the loop. Events from the keyboard and from the reader go through one
|
|
2
2
|
// pure reduce(state, event); what only the loop can do comes back as an effect; the frame is
|
|
3
3
|
// drawn from the state. This version shows a workspace's instances, on this machine and on the
|
|
4
|
-
// machines registered here, follows them, opens an agent's terminal
|
|
5
|
-
// viewer,
|
|
6
|
-
//
|
|
4
|
+
// machines registered here, follows them, opens an agent's terminal in a panel beside the list
|
|
5
|
+
// (the kernel's own viewer, in a pane of the run's private tmux server: lib/panel.mjs), and
|
|
6
|
+
// stops, starts, restarts and retires an instance after a confirmation, through the shared
|
|
7
|
+
// lifecycle boundary and start rule (docs/tui.md).
|
|
7
8
|
import { homedir } from "node:os";
|
|
8
9
|
import { resolve } from "node:path";
|
|
9
10
|
import { bindings } from "./actions.mjs";
|
|
10
11
|
import { TERMS, createLifecycleBoundary, createLifecycleConfirmation, displayLine, heldHome, pendingEntry, prepareRemoteTerm, sessionAttachArgv, startInstance } from "./client.mjs";
|
|
11
12
|
import { loadConfig } from "./config.mjs";
|
|
12
13
|
import { ACT_WORDS, actContext, actCwd, localDeployments, model, roster } from "./model.mjs";
|
|
13
|
-
import {
|
|
14
|
-
import { admitDeployment, createReader, findDeployment, leaveInstance, offeredDeployments, probeKernel, realpath, tellable } from "./read.mjs";
|
|
14
|
+
import { createPanel, sweep } from "./panel.mjs";
|
|
15
|
+
import { CHANGE_FILES, admitDeployment, createReader, findDeployment, leaveInstance, offeredDeployments, probeKernel, realpath, tellable } from "./read.mjs";
|
|
15
16
|
import { initialState, reduce } from "./store.mjs";
|
|
17
|
+
import { captureRows } from "./term/capture.mjs";
|
|
16
18
|
import { createKeyParser, keyId } from "./term/keys.mjs";
|
|
17
19
|
import { createScreen, glyphs } from "./term/screen.mjs";
|
|
18
20
|
import { colorEnabled } from "./term/style.mjs";
|
|
21
|
+
import { backKeySequences, createThrough } from "./term/through.mjs";
|
|
19
22
|
import { createGuard, isTerminal } from "./term/tty.mjs";
|
|
20
23
|
import { frame, layout } from "./views/frame.mjs";
|
|
21
24
|
|
|
@@ -25,8 +28,8 @@ const HELP = `Usage:
|
|
|
25
28
|
|
|
26
29
|
The OATS terminal client (preview): a full-screen view of a workspace's instances,
|
|
27
30
|
on this machine and on the machines registered here. It follows them, opens an
|
|
28
|
-
agent's terminal with Enter, and stops, retires, starts or
|
|
29
|
-
(X, D, S, R) after a confirmation.
|
|
31
|
+
agent's terminal beside the list with Enter, and stops, retires, starts or
|
|
32
|
+
restarts an instance (X, D, S, R) after a confirmation.
|
|
30
33
|
Keys: ? help, Enter open, w workspaces, q quit.
|
|
31
34
|
docs/tui.md has the rest.
|
|
32
35
|
|
|
@@ -65,9 +68,12 @@ function errorLines(error) {
|
|
|
65
68
|
|
|
66
69
|
/** What the loop does outside the terminal, each replaceable by a test. `realpath` is the one the
|
|
67
70
|
* shared start rule checks a local home with; `startInstance` and `createLifecycleConfirmation`
|
|
68
|
-
* are the shared home's, replaceable so a test can drive the loop's wiring.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
* are the shared home's, replaceable so a test can drive the loop's wiring. `runDir` makes the
|
|
72
|
+
* run's private directory (the reader's change output and the panel's tmux server share it), and
|
|
73
|
+
* `removeDir` removes it on the way out once both have removed their files; `sweep` removes what
|
|
74
|
+
* runs that are gone left of theirs (lib/panel.mjs). */
|
|
75
|
+
const EFFECTS = Object.freeze({ loadConfig, findDeployment, probeKernel, createReader, offeredDeployments, admitDeployment, prepareRemoteTerm, createPanel, sweep,
|
|
76
|
+
runDir: CHANGE_FILES.dir, removeDir: CHANGE_FILES.remove, realpath, tellable, startInstance, createLifecycleConfirmation, createLifecycleBoundary });
|
|
71
77
|
|
|
72
78
|
/** Run. Resolves with the exit status; never calls process.exit, so what was written drains.
|
|
73
79
|
* Before the alternate screen, in this order, each failure one line on stderr and status 1:
|
|
@@ -98,6 +104,11 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
98
104
|
let parser = createKeyParser({ now });
|
|
99
105
|
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 });
|
|
100
106
|
const keymap = bindings(state.actions);
|
|
107
|
+
// While a terminal has the focus the bytes typed go to the agent: this scanner takes from them
|
|
108
|
+
// only the back key and a bracketed paste (term/through.mjs). A new one each time the terminal
|
|
109
|
+
// takes the focus, so nothing held from before is typed into it.
|
|
110
|
+
const backKey = backKeySequences(state.detachKey);
|
|
111
|
+
let through = createThrough({ sequences: backKey, now }), throughTimer = null;
|
|
101
112
|
if (offered) state = reduce(state, { offered }, keymap).state;
|
|
102
113
|
// What the last frame drew, for the store: how tall the list pane is and how far the other
|
|
103
114
|
// pane scrolls. The store holds no size of its own.
|
|
@@ -106,6 +117,11 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
106
117
|
/** The preflight of another machine's agent under way: `{ id, controller, prepared }`, where
|
|
107
118
|
* `prepared` is what it answered (`{ binary, args }`) once it has; or null. */
|
|
108
119
|
let preflight = null;
|
|
120
|
+
/** The run's private directory, made at the first change or the first open (lib/read.mjs
|
|
121
|
+
* CHANGE_FILES): the reader writes a change's output there, and the panel keeps its tmux
|
|
122
|
+
* server's socket there. */
|
|
123
|
+
let dir = null;
|
|
124
|
+
const runDir = () => (dir ??= effects.runDir());
|
|
109
125
|
|
|
110
126
|
// What the reader reads for, it asks of the state at that moment: the served deployments, the
|
|
111
127
|
// entry a failed read keeps, and the roster and the memory the next outcome is made from.
|
|
@@ -115,6 +131,24 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
115
131
|
getEntry: (id) => state.entries.get(id) ?? null,
|
|
116
132
|
getRoster: () => ({ remote: state.remote, memory: state.memory, notes: state.notes }),
|
|
117
133
|
onEntry: heard, onRoster: heard,
|
|
134
|
+
files: { ...CHANGE_FILES, dir: runDir },
|
|
135
|
+
});
|
|
136
|
+
// THE OPEN TERMINAL (docs/tui.md, "Open an agent's terminal"): one at a time, in the panel.
|
|
137
|
+
// `viewing` is its viewer, `{ id, panel }` (the row's instanceId, and the panel's own id once
|
|
138
|
+
// the window exists, null before); `screenNow` the last capture (`{ lines, cursor }`), drawn
|
|
139
|
+
// until the next; `panelSize` and `panelShown` what the panel was last told.
|
|
140
|
+
let viewing = null, screenNow = null, panelSize = null, panelShown = true;
|
|
141
|
+
const panel = effects.createPanel({
|
|
142
|
+
dir: runDir, env, capture: captureRows,
|
|
143
|
+
onScreen: ({ id, screen: lines, cursor }) => { if (!ended && viewing !== null && viewing.panel === id) { screenNow = { lines, cursor }; guard.attempt(() => guard.draw()); } },
|
|
144
|
+
// The viewer ended. The store is told, whatever ended it; a terminal the person closed is no
|
|
145
|
+
// longer `viewing`, and the store says nothing of it.
|
|
146
|
+
onClosed: ({ id, status = null, stderr = "", asked = false }) => {
|
|
147
|
+
if (viewing === null || viewing.panel !== id) return;
|
|
148
|
+
const row = viewing.id;
|
|
149
|
+
viewing = null; screenNow = null;
|
|
150
|
+
heard({ returned: { id: row, status, stderr, asked } });
|
|
151
|
+
},
|
|
118
152
|
});
|
|
119
153
|
// THE ACTS (docs/tui.md, "Stopping, starting, restarting and retiring"). One lifecycle boundary
|
|
120
154
|
// per run: its plans, its kept answers and its one apply at a time are this run's. Its exec runs
|
|
@@ -147,11 +181,12 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
147
181
|
took(reduce(state, admitted.ok ? { admitted: admitted.deployment, at: clock() } : { refused: effect.admit }, keymap));
|
|
148
182
|
}
|
|
149
183
|
if (effect.abandon) giveUpPreflight();
|
|
184
|
+
if (effect.close !== undefined) closeTerminal();
|
|
150
185
|
if (effect.open) open(effect.open);
|
|
151
|
-
if (effect.
|
|
186
|
+
if (effect.panel !== undefined) {
|
|
152
187
|
const ready = preflight;
|
|
153
188
|
preflight = null;
|
|
154
|
-
if (ready?.id === effect.
|
|
189
|
+
if (ready?.id === effect.panel && ready.prepared) view(effect.panel, ready.prepared.binary, ready.prepared.args);
|
|
155
190
|
}
|
|
156
191
|
if (effect.dismiss !== undefined) dismiss(effect.dismiss);
|
|
157
192
|
if (effect.act) openConfirmation(effect.act);
|
|
@@ -206,22 +241,23 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
206
241
|
.then((answer) => heard({ acted: { n, answer } }), () => heard({ acted: { n, answer: null } }));
|
|
207
242
|
}
|
|
208
243
|
|
|
209
|
-
/** Open the agent the store decided on (lib/model.mjs openDecision). On this machine the
|
|
210
|
-
*
|
|
211
|
-
* (a read like any other, ended on every way out), and what it prepared waits for the
|
|
212
|
-
* `
|
|
244
|
+
/** Open the agent the store decided on (lib/model.mjs openDecision). On this machine the viewer
|
|
245
|
+
* starts in the panel at once. On another, the shared preflight runs first over the reader's
|
|
246
|
+
* exec (a read like any other, ended on every way out), and what it prepared waits for the
|
|
247
|
+
* store's `panel`, which comes only if the open was not given up and the row is still there.
|
|
248
|
+
* The viewer is given no key of its own: the TUI takes the back key before the pane sees it. */
|
|
213
249
|
function open(decision) {
|
|
214
250
|
if (!decision.routed) {
|
|
215
251
|
let args;
|
|
216
252
|
// A target the shared home refuses (no absolute home) starts nothing; the line after says
|
|
217
253
|
// the viewer ended without saying why.
|
|
218
|
-
try { args = sessionAttachArgv(probe.cli, decision.target
|
|
219
|
-
return
|
|
254
|
+
try { args = sessionAttachArgv(probe.cli, decision.target); } catch { return void heard({ returned: { id: decision.id, status: null, stderr: "" } }); }
|
|
255
|
+
return view(decision.id, probe.cli.bin, args);
|
|
220
256
|
}
|
|
221
257
|
giveUpPreflight();
|
|
222
258
|
const mine = preflight = { id: decision.id, controller: new AbortController(), prepared: null };
|
|
223
259
|
Promise.resolve()
|
|
224
|
-
.then(() => effects.prepareRemoteTerm(probe.cli, decision.target, { exec: reader.exec, signal: mine.controller.signal
|
|
260
|
+
.then(() => effects.prepareRemoteTerm(probe.cli, decision.target, { exec: reader.exec, signal: mine.controller.signal }))
|
|
225
261
|
.then((prepared) => { if (preflight === mine) { mine.prepared = prepared; heard({ prepared: { id: mine.id } }); } },
|
|
226
262
|
(error) => { if (preflight === mine) { preflight = null; heard({ prepared: { id: mine.id, error } }); } });
|
|
227
263
|
}
|
|
@@ -232,51 +268,115 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
232
268
|
preflight.controller.abort();
|
|
233
269
|
preflight = null;
|
|
234
270
|
}
|
|
235
|
-
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
271
|
+
/** Start the viewer of row `id` (`node <bin> <args…>`) in the panel, at the size the frame gives
|
|
272
|
+
* the terminal, and tell the store when its window exists. One the panel could not start is a
|
|
273
|
+
* viewer that ended, with the panel's refusal: no tmux (or one too old), or tmux's own words.
|
|
274
|
+
* Nothing is lent: the reads and the screen go on. */
|
|
275
|
+
function view(id, bin, args) {
|
|
276
|
+
const mine = viewing = { id, panel: null };
|
|
277
|
+
const size = guard.size(), area = composed().made.terminal ?? { cols: size.cols, rows: Math.max(1, size.rows - 6) };
|
|
278
|
+
panelSize = { cols: area.cols, rows: area.rows };
|
|
279
|
+
// Shown: the panel keeps hidden or shown across its viewers, and the last one may have been
|
|
280
|
+
// closed hidden (behind the detail, or the list alone under 80 columns).
|
|
281
|
+
if (!panelShown) panel.setVisible(true);
|
|
282
|
+
panelShown = true;
|
|
283
|
+
Promise.resolve()
|
|
284
|
+
.then(() => panel.open({ argv: [process.execPath, bin, ...args], cols: area.cols, rows: area.rows }))
|
|
285
|
+
.then(({ id: made }) => {
|
|
286
|
+
if (viewing !== mine) return;
|
|
287
|
+
mine.panel = made;
|
|
288
|
+
// A frame of another size while the window was being made told a panel with no window yet.
|
|
289
|
+
if (panelSize.cols !== area.cols || panelSize.rows !== area.rows) panel.resize(panelSize.cols, panelSize.rows);
|
|
290
|
+
heard({ shown: { id } });
|
|
291
|
+
},
|
|
292
|
+
(error) => { if (viewing === mine) { viewing = null; heard({ returned: { id, status: null, stderr: typeof error?.detail === "string" ? error.detail : "", refused: error?.code === "E_PANEL_TMUX" ? "tmux" : "start" } }); } });
|
|
293
|
+
}
|
|
294
|
+
/** Close the open terminal's viewer (also one whose window is still being made): the agent keeps
|
|
295
|
+
* running, and the panel reports the end as asked for, which nobody waits for. */
|
|
296
|
+
function closeTerminal() {
|
|
297
|
+
if (viewing === null) return;
|
|
298
|
+
viewing = null; screenNow = null;
|
|
299
|
+
panel.close();
|
|
300
|
+
}
|
|
301
|
+
/** The panel told what the frame gives the terminal: shown or not (no capture runs while it is
|
|
302
|
+
* hidden, and one runs when it shows again), and its size (the viewer's window follows it). */
|
|
303
|
+
function fitPanel(given) {
|
|
304
|
+
// A view that draws no terminal (the help, the switcher, a confirmation) gives none.
|
|
305
|
+
const area = given ?? null;
|
|
306
|
+
if (viewing === null) return;
|
|
307
|
+
if ((area !== null) !== panelShown) { panelShown = area !== null; panel.setVisible(panelShown); }
|
|
308
|
+
if (area !== null && (area.cols !== panelSize.cols || area.rows !== panelSize.rows)) { panelSize = { cols: area.cols, rows: area.rows }; panel.resize(area.cols, area.rows); }
|
|
309
|
+
}
|
|
310
|
+
/** The frame for the state now, with what the loop needs of it: the layout first, because the
|
|
311
|
+
* model's window is as tall, and its sentences as wide, as the list pane it gives. The switcher
|
|
312
|
+
* takes the whole body and has no notice of a deployment. The last capture of the open
|
|
313
|
+
* terminal goes with the model: it is the panel's, not the store's. */
|
|
314
|
+
function composed() {
|
|
315
|
+
const size = guard.size(), at = clock();
|
|
316
|
+
const listing = (state.view === "help" ? state.back : state.view) === "switcher";
|
|
317
|
+
const r = listing ? { notice: null, note: null, observed: true } : roster(state, at);
|
|
318
|
+
const g = layout(r.notice, size, { observed: r.observed, note: r.note, ascii: state.ascii, outcome: listing ? null : state.outcome });
|
|
319
|
+
const m = { ...model(state, { page: g.page, now: now(), at, cols: g.listCols }), screen: screenNow };
|
|
320
|
+
return { size, g, made: frame(m, size) };
|
|
321
|
+
}
|
|
322
|
+
/** Whether what is typed goes to the agent: the open terminal has the focus. */
|
|
323
|
+
const typing = () => state.terminal?.focus === "terminal" && state.view === "instances";
|
|
324
|
+
/** Bytes typed while the terminal has the focus: to the agent as they came, a paste as a paste,
|
|
325
|
+
* and the back key to the store, which gives the focus to the list; what came after the back key
|
|
326
|
+
* in the same read is read as keys, by a parser that starts afresh. */
|
|
327
|
+
function typed(events) {
|
|
328
|
+
for (const event of events) {
|
|
329
|
+
if (event.input) panel.input(event.input);
|
|
330
|
+
else if (event.paste !== undefined) panel.paste(event.paste);
|
|
331
|
+
else if (event.back) {
|
|
332
|
+
parser = createKeyParser({ now });
|
|
333
|
+
if (took(reduce(state, { back: true }, keymap))) return;
|
|
334
|
+
if (event.rest.length) act(parser.feed(event.rest)); else guard.draw();
|
|
335
|
+
watchEscape();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
watchThrough();
|
|
339
|
+
}
|
|
340
|
+
/** A beginning of the back key that nothing has followed for the parser's timeout is the agent's. */
|
|
341
|
+
function watchThrough() {
|
|
342
|
+
if (throughTimer !== null) { clearTimer(throughTimer); throughTimer = null; }
|
|
343
|
+
const due = through.timeoutAt();
|
|
344
|
+
if (due !== null) throughTimer = setTimer(() => { throughTimer = null; guard.attempt(() => { if (typing()) typed(through.expire()); }); }, Math.max(0, due - now()));
|
|
251
345
|
}
|
|
252
346
|
const guard = createGuard({
|
|
253
347
|
stdin, stdout, proc, setTimer, clearTimer,
|
|
254
348
|
frame() {
|
|
255
|
-
const
|
|
256
|
-
// The layout first: the model's window is as tall, and its sentences as wide, as the list
|
|
257
|
-
// pane it gives. The switcher takes the whole body and has no notice of a deployment.
|
|
258
|
-
const listing = (state.view === "help" ? state.back : state.view) === "switcher";
|
|
259
|
-
const r = listing ? { notice: null, note: null, observed: true } : roster(state, at);
|
|
260
|
-
const g = layout(r.notice, size, { observed: r.observed, note: r.note, ascii: state.ascii, outcome: listing ? null : state.outcome });
|
|
261
|
-
const made = frame(model(state, { page: g.page, now: now(), at, cols: g.listCols }), size);
|
|
349
|
+
const { size, g, made } = composed();
|
|
262
350
|
drawn = { page: made.page, extent: made.extent, room: made.room, cols: g.listCols };
|
|
263
|
-
|
|
351
|
+
fitPanel(made.terminal);
|
|
352
|
+
const bytes = screen.render(made.rows, size, { full, cursor: made.cursor });
|
|
264
353
|
full = false;
|
|
265
354
|
return bytes;
|
|
266
355
|
},
|
|
267
|
-
onInput(bytes) {
|
|
356
|
+
onInput(bytes) {
|
|
357
|
+
reader.touch();
|
|
358
|
+
if (typing()) return typed(through.feed(bytes));
|
|
359
|
+
act(parser.feed(bytes)); watchEscape();
|
|
360
|
+
},
|
|
268
361
|
onResize() { full = true; guard.draw(); },
|
|
269
|
-
|
|
362
|
+
// Ctrl+L and the return from a stop: the whole screen, and the open terminal captured afresh.
|
|
363
|
+
onRedraw() { full = true; if (viewing !== null) panel.refresh(); guard.draw(); },
|
|
270
364
|
// A cycle in flight when the process stops is no evidence about the deployment (lib/read.mjs):
|
|
271
365
|
// it is dropped before the stop, and again after a stop nobody here asked for; the return
|
|
272
366
|
// reads at once.
|
|
273
367
|
// A preflight is given up first, by the TUI itself: ended as a read it would answer as a
|
|
274
368
|
// timeout. The person opens the agent again.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
369
|
+
// The open terminal's server and viewer live on through a stop; the panel stops sending output
|
|
370
|
+
// while nothing reads it, and captures afresh on the way back.
|
|
371
|
+
onStop() { stopPreflight(); dropReads(); if (viewing !== null) panel.pause(); },
|
|
372
|
+
onResume(asked) { if (!asked) { stopPreflight(); dropReads(); } if (viewing !== null) panel.resume(); refresh({ live: true }); },
|
|
373
|
+
// On the way out the confirmation is closed, the private tmux server is ended (its viewer with
|
|
374
|
+
// it) and the reads end; a change in flight is let go, never signalled (lib/read.mjs
|
|
375
|
+
// changeExec), and named after the screen is left.
|
|
376
|
+
// The run's directory goes last, made for whichever of the two needed it first: the reader
|
|
377
|
+
// removes it only when it wrote a change there, and one it cannot remove (a change still
|
|
378
|
+
// writing) stays.
|
|
379
|
+
onEnd() { ended = true; dismiss(confirmation?.n); panel.end(); reader.stop(); if (dir !== null) { try { effects.removeDir(dir); } catch { /* not empty, or gone */ } } },
|
|
280
380
|
});
|
|
281
381
|
function refresh(how) { Promise.resolve(reader.request(how)).catch(() => {}); }
|
|
282
382
|
/** A preflight under way when the process stops: given up, and the store told. */
|
|
@@ -288,16 +388,20 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
288
388
|
/** Every read in flight is void (lib/read.mjs), the roster's with them: the reader says nothing
|
|
289
389
|
* for a void read, so the state is told here that none is in flight. */
|
|
290
390
|
function dropReads() { reader.voidInFlight(); state = reduce(state, { collecting: false }, keymap).state; }
|
|
291
|
-
/** The events of one batch of input, in order. Once one of them
|
|
292
|
-
* dropped: they were typed before
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
391
|
+
/** The events of one batch of input, in order. Once one of them gave the terminal the focus,
|
|
392
|
+
* the rest are dropped: they were typed before it had it, and neither the list nor the agent
|
|
393
|
+
* is to have them (a `q` behind the Enter would end the run). Each batch is one read of input,
|
|
394
|
+
* numbered (`read`): a confirmation ignores the press of its act in the read that moved the
|
|
395
|
+
* focus onto it, so a paste cannot both move and press. */
|
|
296
396
|
function act(events) {
|
|
297
397
|
const read = ++reads;
|
|
298
398
|
for (const event of events) {
|
|
299
|
-
if (guard.lent) return;
|
|
300
399
|
if (took(reduce(state, "paste" in event ? { paste: event.paste } : { key: keyId(event), ...(typeof event.text === "string" && !event.alt ? { text: event.text } : {}), read, ...drawn }, keymap))) return;
|
|
400
|
+
if (typing()) {
|
|
401
|
+
if (escTimer !== null) { clearTimer(escTimer); escTimer = null; }
|
|
402
|
+
through = createThrough({ sequences: backKey, now });
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
301
405
|
}
|
|
302
406
|
guard.draw();
|
|
303
407
|
}
|
|
@@ -305,14 +409,18 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
305
409
|
function watchEscape() {
|
|
306
410
|
if (escTimer !== null) { clearTimer(escTimer); escTimer = null; }
|
|
307
411
|
const due = parser.timeoutAt();
|
|
308
|
-
if (due !== null) escTimer = setTimer(() => { escTimer = null; if (!
|
|
412
|
+
if (due !== null) escTimer = setTimer(() => { escTimer = null; if (!typing()) guard.attempt(() => { act(parser.expire()); watchEscape(); }); }, Math.max(0, due - now()));
|
|
309
413
|
}
|
|
310
414
|
|
|
311
415
|
guard.start();
|
|
312
416
|
guard.attempt(() => { if (!ended) Promise.resolve(reader.start()).catch(() => {}); });
|
|
313
417
|
guard.attempt(() => guard.draw());
|
|
418
|
+
// Once a run, after the first frame: what runs that are gone left of their private servers
|
|
419
|
+
// (lib/panel.mjs sweep, which signals nothing and removes only what it can prove is dead).
|
|
420
|
+
guard.attempt(() => { if (!ended) { try { effects.sweep({ env }); } catch { /* nothing swept */ } } });
|
|
314
421
|
const end = await guard.done;
|
|
315
422
|
if (escTimer !== null) clearTimer(escTimer);
|
|
423
|
+
if (throughTimer !== null) clearTimer(throughTimer);
|
|
316
424
|
// After the alternate screen is left, so the message stays on the screen the user returns to.
|
|
317
425
|
// One line per change still running, to a terminal or a file only; the status never depends on it.
|
|
318
426
|
const running = reader.changes?.() ?? [];
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
hasInstanceChildren, heldHome, rosterSections, deploymentState, rowStale, primaryDeployment, isMultiDeployment, runtimeState, runtimeCounts,
|
|
11
11
|
waitingClaim, waitingLabel, waitedText, waitingClock, waitingBelowText, instanceActs,
|
|
12
12
|
identityMemory, viewModel, workspaceChoices, workspaceChoiceRows, choiceMatches, UNMATCHED_SECTION, shortPath,
|
|
13
|
-
openAct, deployments as heldDeployments,
|
|
13
|
+
openAct, deployments as heldDeployments, attachExit, preflightFailure, kernelLines,
|
|
14
14
|
startGate, launchFlagIgnored, flagIgnoredNotice, retainedStartMessage,
|
|
15
15
|
} from "./client.mjs";
|
|
16
16
|
import { shownLines } from "./term/text.mjs";
|
|
@@ -157,13 +157,7 @@ function build(state, at) {
|
|
|
157
157
|
// Whether a list stands under the header: not for a deployment of this machine that was never
|
|
158
158
|
// observed, nor for a machine that is not live and has no row kept. Each has only its reason.
|
|
159
159
|
const observed = panel !== null && !gone && (local ? status === "observed" : live || instances.length > 0);
|
|
160
|
-
// Whether each other machine's OATS has the key that leaves a viewer, by the deployment its rows
|
|
161
|
-
// are tagged with (the shared panel's `row.deployment.id`; the TUI builds no deployment id).
|
|
162
|
-
// Worked out here, once for what the roster is made from, so a paint reads no machine again.
|
|
163
|
-
const opens = new Map();
|
|
164
|
-
if (panel !== null) for (const d of heldDeployments(heldOf(state, at))) if (d.remote) opens.set(d.id, hostDetachKeySupported(state.cli, d.group));
|
|
165
160
|
return {
|
|
166
|
-
opens,
|
|
167
161
|
panel, gone, instances, deployments, multi, parts, rows, filtering, stale, section, live, observed,
|
|
168
162
|
below: waitingRollup(instances, state.collapsed, state.open, { filtering, stale, section }),
|
|
169
163
|
status,
|
|
@@ -287,13 +281,18 @@ const reasonSpoken = (reason) => spoken(reason.sentence, reason.origin, reason.o
|
|
|
287
281
|
* machine's name), drawn through the display filter on its own. `<id>` and `<home>` in the
|
|
288
282
|
* command are the TUI's placeholders: nothing of the row is in them. */
|
|
289
283
|
export const OPEN_WORDS = Object.freeze({
|
|
290
|
-
left: (name) => [{ own: "You left " }, { shown: name }, { own: ". It keeps running." }],
|
|
291
284
|
failed: (name) => [{ shown: name }, { own: " could not be opened." }],
|
|
292
285
|
link: (machine) => [{ own: "The connection to " }, { shown: machine }, { own: " ended." }],
|
|
293
286
|
unknown: (name) => [{ own: "The viewer of " }, { shown: name }, { own: " ended without saying why." }],
|
|
287
|
+
noTmux: (name) => [{ shown: name }, { own: " could not be opened: the terminal panel needs tmux 3.2 or later on this machine." }],
|
|
294
288
|
notRunning: (name) => [{ shown: name }, { own: " is not running, so it has no terminal to open." }],
|
|
295
289
|
stateUnknown: (name) => [{ own: "Whether " }, { shown: name }, { own: " runs is not known, so it is not opened." }],
|
|
296
|
-
|
|
290
|
+
});
|
|
291
|
+
/** The line of a view that is not in this version (its key: 2, 3), with what to run instead: the
|
|
292
|
+
* help's commands (views/help.mjs VIEWS), in the TUI's own words. */
|
|
293
|
+
export const NOT_BUILT = Object.freeze({
|
|
294
|
+
souls: Object.freeze({ said: Object.freeze([{ own: "Souls are not in this version: `oats souls` lists them, and `oats spawn <soul>` makes an instance of one." }]), under: Object.freeze([]) }),
|
|
295
|
+
capabilities: Object.freeze({ said: Object.freeze([{ own: "Capabilities are not in this version: `oats capabilities` lists them." }]), under: Object.freeze([]) }),
|
|
297
296
|
});
|
|
298
297
|
/** A sentence from outside (a reason of the shared home's, the preflight table's), as a text
|
|
299
298
|
* under the line: drawn as the detail draws a reason, wrapped on the reason's rows, never as one
|
|
@@ -310,7 +309,8 @@ const elsewhere = (row) => typeof row.server === "string" && row.server !== "";
|
|
|
310
309
|
* for a row of another machine (its preflight runs first)
|
|
311
310
|
* { open: false, said: { said, under } } opens nothing, and this says why
|
|
312
311
|
* Whether a row can be opened is the shared openAct's, switched on its reason's code, never on a
|
|
313
|
-
* sentence
|
|
312
|
+
* sentence. The viewer is started with no key of its own (the TUI takes the back key before the
|
|
313
|
+
* pane sees it), so a kernel or a host of any version is opened alike. */
|
|
314
314
|
export function openDecision(state, row, acts) {
|
|
315
315
|
const name = row.instance, id = instanceId(row);
|
|
316
316
|
const machine = elsewhere(row) ? row.deployment?.machine ?? row.server : null;
|
|
@@ -325,23 +325,25 @@ export function openDecision(state, row, acts) {
|
|
|
325
325
|
if (act.reason.code === "state-unknown") return no(OPEN_WORDS.stateUnknown(name));
|
|
326
326
|
return no([], outside(reasonSpoken(act.reason)));
|
|
327
327
|
}
|
|
328
|
-
if (!elsewhere(row)) {
|
|
329
|
-
return detachKeySupported(state.cli) ? { open: true, id, name, machine, target: { home: row.home }, routed: false } : no(OPEN_WORDS.noKey(null));
|
|
330
|
-
}
|
|
331
|
-
if (roster(state).opens.get(row.deployment?.id) !== true) return no(OPEN_WORDS.noKey(machine));
|
|
328
|
+
if (!elsewhere(row)) return { open: true, id, name, machine, target: { home: row.home }, routed: false };
|
|
332
329
|
return { open: true, id, name, machine, target: { serverId: row.server, instance: row.instance, home: row.home }, routed: true };
|
|
333
330
|
}
|
|
334
331
|
|
|
335
|
-
/** The line after
|
|
336
|
-
* ended
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
|
|
342
|
-
|
|
332
|
+
/** The line after a terminal closed by itself, or null when the TUI says nothing of its own: the
|
|
333
|
+
* viewer ended with status 0 (the list shows the agent as the kernel now reports it), or the
|
|
334
|
+
* person closed it (`asked`: c, or Enter on another row). `status` is what the pane's shell
|
|
335
|
+
* wrote of the viewer's exit (lib/panel.mjs), null when it wrote none; the shared attachExit reads
|
|
336
|
+
* it, as for a viewer started with no key, and the TUI compares no number. What the viewer printed
|
|
337
|
+
* on stderr stands under a failure, once, as one text in quotation marks naming nobody: OATS, tmux
|
|
338
|
+
* and ssh all print there, and nothing is compared with it. `refused` is the panel's own refusal
|
|
339
|
+
* when no viewer was started at all: "tmux" (no tmux here, or one too old), or "start" (the
|
|
340
|
+
* panel's server or window was not made; `stderr` is then what tmux said). */
|
|
341
|
+
export function returnedLine({ name, machine, routed }, status, stderr, { asked = false, refused = null } = {}) {
|
|
342
|
+
if (asked) return null;
|
|
343
|
+
if (refused === "tmux") return { said: OPEN_WORDS.noTmux(name), under: [] };
|
|
344
|
+
if (refused !== null) status = 1;
|
|
345
|
+
const word = attachExit(status, { keyed: false, routed });
|
|
343
346
|
if (word === "ended") return null;
|
|
344
|
-
if (word === "left") return { said: OPEN_WORDS.left(name), under: [] };
|
|
345
347
|
if (word === "unknown") return { said: OPEN_WORDS.unknown(name), under: [] };
|
|
346
348
|
const line = displayLine(stderr);
|
|
347
349
|
const under = line === null ? [] : [line === DETAIL_WITHHELD ? DETAIL_WITHHELD : `"${line}"`];
|
|
@@ -467,6 +469,7 @@ export function model(state, { page, now, at, cols }) {
|
|
|
467
469
|
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,
|
|
468
470
|
detailTop: state.detailTop, helpTop: state.helpTop, open: state.open !== null,
|
|
469
471
|
detachKey: state.detachKey, opening: state.opening, outcome: state.outcome, openable: false, actable: [],
|
|
472
|
+
terminal: state.terminal, onTerminal: false,
|
|
470
473
|
act: state.view === "act" && state.act ? actView(state) : null,
|
|
471
474
|
};
|
|
472
475
|
// The view under the help, or under a confirmation, decides what the header says.
|
|
@@ -499,8 +502,9 @@ export function model(state, { page, now, at, cols }) {
|
|
|
499
502
|
list: r.items.slice(win.top, win.top + win.size).map((item) => (item?.id !== undefined ? { kind: "row", ...listRow(state, r, item) } : item)),
|
|
500
503
|
above: win.above, below: win.below, wordWidth: r.wordWidth,
|
|
501
504
|
detail: selected >= 0 ? detailOf(state, r, r.items[selected], now, acts) : null,
|
|
502
|
-
// Enter opens the selected agent's terminal now
|
|
505
|
+
// Enter opens the selected agent's terminal now, or (`onTerminal`) goes to the one open on it.
|
|
503
506
|
openable: decision?.open === true && state.opening === null,
|
|
507
|
+
onTerminal: row !== null && state.terminal !== null && state.terminal.id === instanceId(row),
|
|
504
508
|
// The acts whose key opens a confirmation now, read from the same instanceActs answer: the
|
|
505
509
|
// footer names them. A key not named still answers, with the line that says why.
|
|
506
510
|
actable: row && state.opening === null ? ACT_VERBS.filter((verb) => actDecision(state, row, acts, verb).open) : [],
|