@awebai/oats 0.55.1 → 0.57.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 +96 -72
- package/docs/capabilities.md +67 -3
- package/docs/design/2026-09-23-workspace-module-contracts.md +27 -3
- package/docs/desktop-cli-api.md +375 -37
- package/docs/desktop-instance-start.md +105 -12
- package/docs/desktop.md +65 -11
- package/docs/execution-targets.md +184 -9
- package/docs/harness-trust.md +128 -11
- package/docs/implementation.md +153 -11
- package/docs/integrations.md +5 -3
- package/docs/knowledge.md +117 -43
- package/docs/official-catalog.md +3 -3
- package/docs/packages.md +12 -12
- package/docs/release-lane.md +26 -1
- package/docs/release-notes/v0.56.0.md +699 -0
- package/docs/release-notes/v0.57.0.md +283 -0
- package/docs/schedules.md +8 -3
- package/docs/servers.md +21 -5
- package/docs/souls-and-instances.md +134 -19
- package/docs/tui.md +215 -31
- package/docs/upgrading.md +4 -1
- package/docs/workspaces.md +26 -6
- package/lib/automations.mjs +3 -4
- package/lib/bounded-read.mjs +18 -0
- package/lib/capability-show.mjs +13 -2
- package/lib/claim.mjs +3 -4
- package/lib/core.mjs +919 -278
- package/lib/errors.mjs +39 -0
- package/lib/harness-trust-write.mjs +119 -40
- package/lib/harness-trust.mjs +31 -18
- package/lib/instance-inspect.mjs +160 -11
- package/lib/instance-lifecycle.mjs +90 -37
- package/lib/packages.mjs +8 -5
- package/lib/pi-bridge.mjs +18 -19
- package/lib/remote.mjs +88 -51
- package/lib/retire-output.mjs +9 -4
- package/lib/schedule.mjs +3 -4
- package/lib/servers.mjs +39 -6
- package/lib/session-viewer.mjs +25 -1
- package/lib/triggers.mjs +3 -4
- package/lib/workspace.mjs +6 -6
- package/lib/worktree.mjs +33 -8
- package/lib/write-through-private-file.mjs +26 -0
- package/package-catalog.json +2 -2
- package/package.json +1 -1
- package/packages/client/cli-adapter.mjs +108 -13
- package/packages/client/cli-locator.mjs +16 -14
- package/packages/client/deployment-panel.mjs +4 -3
- package/packages/client/display-text.mjs +2 -1
- package/packages/client/instance-events-contract.mjs +4 -3
- package/packages/client/instance-lifecycle.mjs +235 -0
- package/packages/client/instance-presentation.mjs +9 -0
- package/packages/client/instance-tree.mjs +10 -8
- package/packages/client/kernel-lines.mjs +3 -3
- package/packages/client/launch-contract.mjs +11 -0
- package/packages/client/launch-prompt-outcome.mjs +1 -1
- package/packages/client/lifecycle-cli.mjs +12 -6
- package/packages/client/lifecycle-confirmation.mjs +407 -0
- package/packages/client/lifecycle-contract.mjs +6 -2
- package/packages/client/own-codes.mjs +1 -0
- package/packages/client/panel-views.mjs +39 -2
- package/packages/client/readiness-contract.mjs +2 -2
- package/packages/client/remote-roster.mjs +50 -5
- package/packages/client/roster-sections.mjs +3 -3
- package/packages/client/session-start.mjs +98 -0
- package/packages/client/start-gate.mjs +46 -0
- package/packages/client/start-messages.mjs +17 -0
- package/packages/client/workspace-views.mjs +2 -2
- package/packages/tui/README.md +21 -8
- package/packages/tui/lib/actions.mjs +11 -2
- package/packages/tui/lib/client.mjs +9 -2
- package/packages/tui/lib/config.mjs +39 -9
- package/packages/tui/lib/main.mjs +168 -20
- package/packages/tui/lib/model.mjs +315 -13
- package/packages/tui/lib/open.mjs +45 -0
- package/packages/tui/lib/read.mjs +171 -16
- package/packages/tui/lib/store.mjs +171 -10
- package/packages/tui/lib/term/tty.mjs +71 -12
- package/packages/tui/lib/views/act.mjs +85 -0
- package/packages/tui/lib/views/frame.mjs +145 -33
- package/packages/tui/lib/views/help.mjs +46 -11
- package/skills/oats-getting-started/SKILL.md +6 -3
|
@@ -1,14 +1,17 @@
|
|
|
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,
|
|
4
|
+
// machines registered here, follows them, opens an agent's terminal with the kernel's own
|
|
5
|
+
// viewer, and stops, starts, restarts and retires an instance after a confirmation, through the
|
|
6
|
+
// shared lifecycle boundary and start rule (docs/tui.md).
|
|
5
7
|
import { homedir } from "node:os";
|
|
6
8
|
import { resolve } from "node:path";
|
|
7
9
|
import { bindings } from "./actions.mjs";
|
|
8
|
-
import { displayLine, pendingEntry } from "./client.mjs";
|
|
10
|
+
import { TERMS, createLifecycleBoundary, createLifecycleConfirmation, displayLine, heldHome, pendingEntry, prepareRemoteTerm, sessionAttachArgv, startInstance } from "./client.mjs";
|
|
9
11
|
import { loadConfig } from "./config.mjs";
|
|
10
|
-
import { model, roster } from "./model.mjs";
|
|
11
|
-
import {
|
|
12
|
+
import { ACT_WORDS, actContext, actCwd, localDeployments, model, roster } from "./model.mjs";
|
|
13
|
+
import { startViewer } from "./open.mjs";
|
|
14
|
+
import { admitDeployment, createReader, findDeployment, leaveInstance, offeredDeployments, probeKernel, realpath, tellable } from "./read.mjs";
|
|
12
15
|
import { initialState, reduce } from "./store.mjs";
|
|
13
16
|
import { createKeyParser, keyId } from "./term/keys.mjs";
|
|
14
17
|
import { createScreen, glyphs } from "./term/screen.mjs";
|
|
@@ -21,8 +24,10 @@ const HELP = `Usage:
|
|
|
21
24
|
${USAGE}
|
|
22
25
|
|
|
23
26
|
The OATS terminal client (preview): a full-screen view of a workspace's instances,
|
|
24
|
-
on this machine and on the machines registered here. It follows them
|
|
25
|
-
|
|
27
|
+
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 restarts an instance
|
|
29
|
+
(X, D, S, R) after a confirmation.
|
|
30
|
+
Keys: ? help, Enter open, w workspaces, q quit.
|
|
26
31
|
docs/tui.md has the rest.
|
|
27
32
|
|
|
28
33
|
--dir <path> the deployment, or a directory inside one (default: where you are)
|
|
@@ -58,15 +63,19 @@ function errorLines(error) {
|
|
|
58
63
|
return String(text).split("\n", 12).map((line) => displayLine(line)).filter(Boolean);
|
|
59
64
|
}
|
|
60
65
|
|
|
61
|
-
/** What the loop does outside the terminal, each replaceable by a test.
|
|
62
|
-
|
|
66
|
+
/** What the loop does outside the terminal, each replaceable by a test. `realpath` is the one the
|
|
67
|
+
* 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
|
+
const EFFECTS = Object.freeze({ loadConfig, findDeployment, probeKernel, createReader, offeredDeployments, admitDeployment, prepareRemoteTerm, startViewer,
|
|
70
|
+
realpath, tellable, startInstance, createLifecycleConfirmation, createLifecycleBoundary });
|
|
63
71
|
|
|
64
72
|
/** Run. Resolves with the exit status; never calls process.exit, so what was written drains.
|
|
65
73
|
* Before the alternate screen, in this order, each failure one line on stderr and status 1:
|
|
66
74
|
* the arguments; the instance variables removed from the environment (a TUI started in an
|
|
67
75
|
* agent's pane must read the deployment it was asked about, and so must every child it starts);
|
|
68
76
|
* the terminal; the user's tui.json; the deployment; the kernel it shipped with. */
|
|
69
|
-
export async function main({ argv, stdin, stdout, stderr, env, proc = process, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout, cwd = () => process.cwd(), home = homedir(), effects = EFFECTS }) {
|
|
77
|
+
export async function main({ argv, stdin, stdout, stderr, env, proc = process, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout, cwd = () => process.cwd(), home = homedir(), effects: given = EFFECTS }) {
|
|
78
|
+
const effects = given === EFFECTS ? EFFECTS : { ...EFFECTS, ...given };
|
|
70
79
|
const { options, error } = parseArgs(argv);
|
|
71
80
|
if (error) { stderr.write(`${error}\n`); return 1; }
|
|
72
81
|
if (options.help) { stdout.write(HELP); return 0; }
|
|
@@ -86,14 +95,17 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
86
95
|
const clock = () => new Date(now()).toISOString();
|
|
87
96
|
const look = glyphs(env, { ascii: options.ascii || config.ascii });
|
|
88
97
|
const screen = createScreen({ ...look, color: colorEnabled(env) });
|
|
89
|
-
|
|
90
|
-
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 });
|
|
98
|
+
let parser = createKeyParser({ now });
|
|
99
|
+
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 });
|
|
91
100
|
const keymap = bindings(state.actions);
|
|
92
101
|
if (offered) state = reduce(state, { offered }, keymap).state;
|
|
93
102
|
// What the last frame drew, for the store: how tall the list pane is and how far the other
|
|
94
103
|
// pane scrolls. The store holds no size of its own.
|
|
95
104
|
let drawn = { page: 1, extent: 0, room: 1, cols: 1 };
|
|
96
|
-
let full = true, escTimer = null, ended = false;
|
|
105
|
+
let full = true, escTimer = null, ended = false, reads = 0;
|
|
106
|
+
/** The preflight of another machine's agent under way: `{ id, controller, prepared }`, where
|
|
107
|
+
* `prepared` is what it answered (`{ binary, args }`) once it has; or null. */
|
|
108
|
+
let preflight = null;
|
|
97
109
|
|
|
98
110
|
// What the reader reads for, it asks of the state at that moment: the served deployments, the
|
|
99
111
|
// entry a failed read keeps, and the roster and the memory the next outcome is made from.
|
|
@@ -104,6 +116,19 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
104
116
|
getRoster: () => ({ remote: state.remote, memory: state.memory, notes: state.notes }),
|
|
105
117
|
onEntry: heard, onRoster: heard,
|
|
106
118
|
});
|
|
119
|
+
// THE ACTS (docs/tui.md, "Stopping, starting, restarting and retiring"). One lifecycle boundary
|
|
120
|
+
// per run: its plans, its kept answers and its one apply at a time are this run's. Its exec runs
|
|
121
|
+
// a plan read as a read the loop asked for (kind "read", ended on every way out) and an apply
|
|
122
|
+
// (`detached: true`, cliLifecycle's own mark of a change) as a change, which the TUI never ends.
|
|
123
|
+
// `applying` is the label of the apply this run's confirmation just sent: only one confirmation
|
|
124
|
+
// is open at a time, and the boundary calls its exec in the same turn as the request.
|
|
125
|
+
let applying = null;
|
|
126
|
+
const boundary = effects.createLifecycleBoundary({ terms: TERMS, exec: (bin, argv, { detached, ...options }, callback) => (detached
|
|
127
|
+
? reader.changeExec(bin, argv, { ...options, label: applying }, callback)
|
|
128
|
+
: reader.exec(bin, argv, options, callback)) });
|
|
129
|
+
/** The confirmation open now: `{ n, made }`, `made` the shared confirmation; or null. */
|
|
130
|
+
let confirmation = null;
|
|
131
|
+
|
|
107
132
|
/** What the reader gave, into the state, and the screen after it. */
|
|
108
133
|
function heard(event) { if (!ended) guard.attempt(() => { if (!took(reduce(state, event, keymap))) guard.draw(); }); }
|
|
109
134
|
/** One step of the reducer taken: the state, then what only the loop can do. True once the
|
|
@@ -121,40 +146,158 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
121
146
|
const admitted = effects.admitDeployment(effect.admit);
|
|
122
147
|
took(reduce(state, admitted.ok ? { admitted: admitted.deployment, at: clock() } : { refused: effect.admit }, keymap));
|
|
123
148
|
}
|
|
149
|
+
if (effect.abandon) giveUpPreflight();
|
|
150
|
+
if (effect.open) open(effect.open);
|
|
151
|
+
if (effect.lend !== undefined) {
|
|
152
|
+
const ready = preflight;
|
|
153
|
+
preflight = null;
|
|
154
|
+
if (ready?.id === effect.lend && ready.prepared) lendTo(effect.lend, ready.prepared.binary, ready.prepared.args);
|
|
155
|
+
}
|
|
156
|
+
if (effect.dismiss !== undefined) dismiss(effect.dismiss);
|
|
157
|
+
if (effect.act) openConfirmation(effect.act);
|
|
158
|
+
if (effect.call) callConfirmation(effect.call);
|
|
159
|
+
if (effect.start) startAct(effect.start);
|
|
124
160
|
if (effect.refresh) refresh(effect.refresh);
|
|
125
161
|
return false;
|
|
126
162
|
}
|
|
163
|
+
|
|
164
|
+
/** What the boundary admits a request of deployment `id` against, read at every admission. */
|
|
165
|
+
const contextOf = (id) => actContext(state, id, clock());
|
|
166
|
+
/** Open the shared confirmation of a stop or a retire the store decided on (`{ n, verb, row,
|
|
167
|
+
* label }`). Every step it tells goes to the store as `{ acted }`; an answer that settles asks
|
|
168
|
+
* for a live read of the rows (onSettled), and nothing else after an apply does. */
|
|
169
|
+
function openConfirmation({ n, verb, row, label }) {
|
|
170
|
+
dismiss(confirmation?.n);
|
|
171
|
+
const id = row.deployment?.id, name = row.instance;
|
|
172
|
+
const target = { workspace: id, instance: name, agent: row.agent, agentsRoot: row.agentsRoot, home: row.home, server: row.server ?? null };
|
|
173
|
+
const mine = { n, made: null };
|
|
174
|
+
const tell = () => { if (mine.made && confirmation === mine) heard({ acted: { n, confirmation: { ...mine.made.state(), view: mine.made.view() } } }); };
|
|
175
|
+
confirmation = mine;
|
|
176
|
+
mine.made = effects.createLifecycleConfirmation({
|
|
177
|
+
request: (body) => { if (body?.action === "apply") applying = { verb, name }; return boundary(body, () => contextOf(id)); },
|
|
178
|
+
target, operation: verb, terms: TERMS, label, leftover: heldHome(row)?.kind === "spawn-incomplete",
|
|
179
|
+
onChange: tell, onSettled: () => refresh({ live: true }),
|
|
180
|
+
});
|
|
181
|
+
tell();
|
|
182
|
+
}
|
|
183
|
+
/** A button pressed in the confirmation: its call, when it is still the open one. */
|
|
184
|
+
function callConfirmation({ n, method, args = [] }) {
|
|
185
|
+
if (confirmation?.n === n) confirmation.made[method](...args);
|
|
186
|
+
}
|
|
187
|
+
/** The confirmation closed: what it sent goes on, and what it answers is no longer told. */
|
|
188
|
+
function dismiss(n) {
|
|
189
|
+
if (confirmation === null || confirmation.n !== n) return;
|
|
190
|
+
const { made } = confirmation;
|
|
191
|
+
confirmation = null;
|
|
192
|
+
made?.close();
|
|
193
|
+
}
|
|
194
|
+
/** Start or restart the row (`{ n, verb, id, row }`) through the shared start rule, once, with no
|
|
195
|
+
* launch choice. Its child is a change of this run: the store hears when it is spawned and when
|
|
196
|
+
* it closes (`starting`), and the answer, whatever it is, asks for a live read. */
|
|
197
|
+
function startAct({ n, verb, id, row }) {
|
|
198
|
+
const label = { verb, name: row?.instance ?? "" };
|
|
199
|
+
const exec = (bin, argv, options, callback) => {
|
|
200
|
+
const child = reader.changeExec(bin, argv, { ...options, label }, (...answer) => { heard({ acted: { closed: id } }); callback(...answer); });
|
|
201
|
+
heard({ acted: { spawned: { id, verb }, at: now() } });
|
|
202
|
+
return child;
|
|
203
|
+
};
|
|
204
|
+
Promise.resolve()
|
|
205
|
+
.then(() => effects.startInstance(probe.cli, row, {}, { restart: verb === "restart", deployments: localDeployments(state, clock()), realpath: effects.realpath, localCwd: actCwd(state), exec, terms: TERMS }))
|
|
206
|
+
.then((answer) => heard({ acted: { n, answer } }), () => heard({ acted: { n, answer: null } }));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Open the agent the store decided on (lib/model.mjs openDecision). On this machine the
|
|
210
|
+
* terminal is lent at once. On another, the shared preflight runs first over the reader's exec
|
|
211
|
+
* (a read like any other, ended on every way out), and what it prepared waits for the store's
|
|
212
|
+
* `lend`, which comes only if the open was not given up and the row is still there. */
|
|
213
|
+
function open(decision) {
|
|
214
|
+
if (!decision.routed) {
|
|
215
|
+
let args;
|
|
216
|
+
// A target the shared home refuses (no absolute home) starts nothing; the line after says
|
|
217
|
+
// the viewer ended without saying why.
|
|
218
|
+
try { args = sessionAttachArgv(probe.cli, decision.target, { detachKey: state.detachKey }); } catch { return void heard({ returned: { id: decision.id, status: null, stderr: "" } }); }
|
|
219
|
+
return lendTo(decision.id, probe.cli.bin, args);
|
|
220
|
+
}
|
|
221
|
+
giveUpPreflight();
|
|
222
|
+
const mine = preflight = { id: decision.id, controller: new AbortController(), prepared: null };
|
|
223
|
+
Promise.resolve()
|
|
224
|
+
.then(() => effects.prepareRemoteTerm(probe.cli, decision.target, { exec: reader.exec, signal: mine.controller.signal, detachKey: state.detachKey }))
|
|
225
|
+
.then((prepared) => { if (preflight === mine) { mine.prepared = prepared; heard({ prepared: { id: mine.id } }); } },
|
|
226
|
+
(error) => { if (preflight === mine) { preflight = null; heard({ prepared: { id: mine.id, error } }); } });
|
|
227
|
+
}
|
|
228
|
+
/** The preflight under way, given up: its child is ended through the signal, and whatever it
|
|
229
|
+
* answers is dropped. */
|
|
230
|
+
function giveUpPreflight() {
|
|
231
|
+
if (preflight === null) return;
|
|
232
|
+
preflight.controller.abort();
|
|
233
|
+
preflight = null;
|
|
234
|
+
}
|
|
235
|
+
/** Lend the terminal to the kernel's viewer (lib/open.mjs) and take it back when it closes.
|
|
236
|
+
* Before: every read in flight is void and none starts while it has the terminal, as at a
|
|
237
|
+
* stop. After: reads begin again, and the store says what happened and asks for a live read. */
|
|
238
|
+
function lendTo(id, bin, args) {
|
|
239
|
+
dropReads();
|
|
240
|
+
reader.hold();
|
|
241
|
+
let viewer = null;
|
|
242
|
+
guard.lend(() => { viewer = effects.startViewer(bin, args, { env }); return viewer.closed; }, { end: () => viewer?.end(), release: () => viewer?.release() }).then((outcome) => {
|
|
243
|
+
// The keys are read anew: what was typed before the viewer started (behind the Enter, in the
|
|
244
|
+
// same chunk) and a sequence begun then are gone, so none of it acts or joins a later key.
|
|
245
|
+
if (escTimer !== null) { clearTimer(escTimer); escTimer = null; }
|
|
246
|
+
parser = createKeyParser({ now });
|
|
247
|
+
reader.release();
|
|
248
|
+
const { status = null, stderr = "" } = outcome.value ?? {};
|
|
249
|
+
heard({ returned: { id, status, stderr } });
|
|
250
|
+
});
|
|
251
|
+
}
|
|
127
252
|
const guard = createGuard({
|
|
128
253
|
stdin, stdout, proc, setTimer, clearTimer,
|
|
129
254
|
frame() {
|
|
130
255
|
const size = guard.size(), at = clock();
|
|
131
256
|
// The layout first: the model's window is as tall, and its sentences as wide, as the list
|
|
132
257
|
// pane it gives. The switcher takes the whole body and has no notice of a deployment.
|
|
133
|
-
const
|
|
134
|
-
const
|
|
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 });
|
|
135
261
|
const made = frame(model(state, { page: g.page, now: now(), at, cols: g.listCols }), size);
|
|
136
262
|
drawn = { page: made.page, extent: made.extent, room: made.room, cols: g.listCols };
|
|
137
263
|
const bytes = screen.render(made.rows, size, { full });
|
|
138
264
|
full = false;
|
|
139
265
|
return bytes;
|
|
140
266
|
},
|
|
141
|
-
onInput(bytes) { reader.touch(); act(parser.feed(bytes)); watchEscape(); },
|
|
267
|
+
onInput(bytes) { if (guard.lent) return; reader.touch(); act(parser.feed(bytes)); watchEscape(); },
|
|
142
268
|
onResize() { full = true; guard.draw(); },
|
|
143
269
|
onRedraw() { full = true; guard.draw(); },
|
|
144
270
|
// A cycle in flight when the process stops is no evidence about the deployment (lib/read.mjs):
|
|
145
271
|
// it is dropped before the stop, and again after a stop nobody here asked for; the return
|
|
146
272
|
// reads at once.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
273
|
+
// A preflight is given up first, by the TUI itself: ended as a read it would answer as a
|
|
274
|
+
// timeout. The person opens the agent again.
|
|
275
|
+
onStop() { stopPreflight(); dropReads(); },
|
|
276
|
+
onResume(asked) { if (!asked) { stopPreflight(); dropReads(); } refresh({ live: true }); },
|
|
277
|
+
// On the way out the confirmation is closed and the reads end; a change in flight is let go,
|
|
278
|
+
// never signalled (lib/read.mjs changeExec), and named after the screen is left.
|
|
279
|
+
onEnd() { ended = true; dismiss(confirmation?.n); reader.stop(); },
|
|
150
280
|
});
|
|
151
281
|
function refresh(how) { Promise.resolve(reader.request(how)).catch(() => {}); }
|
|
282
|
+
/** A preflight under way when the process stops: given up, and the store told. */
|
|
283
|
+
function stopPreflight() {
|
|
284
|
+
if (preflight === null) return;
|
|
285
|
+
giveUpPreflight();
|
|
286
|
+
state = reduce(state, { given: true }, keymap).state;
|
|
287
|
+
}
|
|
152
288
|
/** Every read in flight is void (lib/read.mjs), the roster's with them: the reader says nothing
|
|
153
289
|
* for a void read, so the state is told here that none is in flight. */
|
|
154
290
|
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 lent the terminal, the rest are
|
|
292
|
+
* dropped: they were typed before the viewer started, and none may act while it has the
|
|
293
|
+
* terminal (a `q` behind the Enter would end the run under a live viewer). Each batch is one
|
|
294
|
+
* read of input, numbered (`read`): a confirmation ignores the press of its act in the read
|
|
295
|
+
* that moved the focus onto it, so a paste cannot both move and press. */
|
|
155
296
|
function act(events) {
|
|
297
|
+
const read = ++reads;
|
|
156
298
|
for (const event of events) {
|
|
157
|
-
if (
|
|
299
|
+
if (guard.lent) return;
|
|
300
|
+
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;
|
|
158
301
|
}
|
|
159
302
|
guard.draw();
|
|
160
303
|
}
|
|
@@ -162,7 +305,7 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
162
305
|
function watchEscape() {
|
|
163
306
|
if (escTimer !== null) { clearTimer(escTimer); escTimer = null; }
|
|
164
307
|
const due = parser.timeoutAt();
|
|
165
|
-
if (due !== null) escTimer = setTimer(() => { escTimer = null; guard.attempt(() => { act(parser.expire()); watchEscape(); }); }, Math.max(0, due - now()));
|
|
308
|
+
if (due !== null) escTimer = setTimer(() => { escTimer = null; if (!guard.lent) guard.attempt(() => { act(parser.expire()); watchEscape(); }); }, Math.max(0, due - now()));
|
|
166
309
|
}
|
|
167
310
|
|
|
168
311
|
guard.start();
|
|
@@ -171,6 +314,11 @@ export async function main({ argv, stdin, stdout, stderr, env, proc = process, n
|
|
|
171
314
|
const end = await guard.done;
|
|
172
315
|
if (escTimer !== null) clearTimer(escTimer);
|
|
173
316
|
// After the alternate screen is left, so the message stays on the screen the user returns to.
|
|
317
|
+
// One line per change still running, to a terminal or a file only; the status never depends on it.
|
|
318
|
+
const running = reader.changes?.() ?? [];
|
|
319
|
+
if (running.length && effects.tellable(stderr)) {
|
|
320
|
+
try { stderr.write(running.map(({ label }) => `${ACT_WORDS.leaving(label?.verb ?? "change", displayLine(label?.name) ?? "an instance")}\n`).join("")); } catch { /* nothing to tell it to */ }
|
|
321
|
+
}
|
|
174
322
|
if (end.error !== undefined) stderr.write(`oats: \`oats tui\` stopped on an internal error; the terminal was restored\n${errorLines(end.error).map((line) => ` ${line}\n`).join("")}`);
|
|
175
323
|
return end.status;
|
|
176
324
|
}
|