@fnndsc/calypso 0.29.14 → 0.30.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/dist/calypso.js +19 -8
- package/dist/calypso.js.map +1 -1
- package/dist/daemon/attachFile.d.ts +26 -19
- package/dist/daemon/attachFile.js +42 -51
- package/dist/daemon/attachFile.js.map +1 -1
- package/dist/daemon/attachOrigin.d.ts +69 -0
- package/dist/daemon/attachOrigin.js +125 -0
- package/dist/daemon/attachOrigin.js.map +1 -0
- package/dist/daemon/berth.d.ts +265 -26
- package/dist/daemon/berth.js +521 -158
- package/dist/daemon/berth.js.map +1 -1
- package/dist/daemon/claims.js +19 -9
- package/dist/daemon/claims.js.map +1 -1
- package/dist/daemon/commandLane.d.ts +317 -0
- package/dist/daemon/commandLane.js +409 -0
- package/dist/daemon/commandLane.js.map +1 -0
- package/dist/daemon/console.d.ts +0 -2
- package/dist/daemon/console.js +7 -10
- package/dist/daemon/console.js.map +1 -1
- package/dist/daemon/consoleSession.js +4 -1
- package/dist/daemon/consoleSession.js.map +1 -1
- package/dist/daemon/elevation.d.ts +0 -3
- package/dist/daemon/elevation.js +1 -3
- package/dist/daemon/elevation.js.map +1 -1
- package/dist/daemon/face.d.ts +18 -4
- package/dist/daemon/face.js +77 -32
- package/dist/daemon/face.js.map +1 -1
- package/dist/daemon/hostControl.d.ts +114 -1
- package/dist/daemon/hostControl.js +104 -4
- package/dist/daemon/hostControl.js.map +1 -1
- package/dist/daemon/hostPty.d.ts +14 -0
- package/dist/daemon/hostPty.js +19 -1
- package/dist/daemon/hostPty.js.map +1 -1
- package/dist/daemon/hostPtyRelay.d.ts +118 -0
- package/dist/daemon/hostPtyRelay.js +186 -0
- package/dist/daemon/hostPtyRelay.js.map +1 -0
- package/dist/daemon/httpRoutes.d.ts +257 -0
- package/dist/daemon/httpRoutes.js +537 -0
- package/dist/daemon/httpRoutes.js.map +1 -0
- package/dist/daemon/instance.d.ts +37 -0
- package/dist/daemon/instance.js +59 -0
- package/dist/daemon/instance.js.map +1 -0
- package/dist/daemon/launch.d.ts +17 -0
- package/dist/daemon/launch.js +198 -194
- package/dist/daemon/launch.js.map +1 -1
- package/dist/daemon/launchBanner.d.ts +76 -0
- package/dist/daemon/launchBanner.js +80 -0
- package/dist/daemon/launchBanner.js.map +1 -0
- package/dist/daemon/rival.d.ts +65 -0
- package/dist/daemon/rival.js +67 -0
- package/dist/daemon/rival.js.map +1 -0
- package/dist/daemon/server.d.ts +104 -190
- package/dist/daemon/server.js +358 -866
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/settings.d.ts +42 -0
- package/dist/daemon/settings.js +43 -0
- package/dist/daemon/settings.js.map +1 -0
- package/dist/daemon/surface.d.ts +103 -0
- package/dist/daemon/surface.js +71 -0
- package/dist/daemon/surface.js.map +1 -0
- package/dist/daemon/surfaceReplies.d.ts +109 -0
- package/dist/daemon/surfaceReplies.js +108 -0
- package/dist/daemon/surfaceReplies.js.map +1 -0
- package/dist/daemon/terminals.js +5 -2
- package/dist/daemon/terminals.js.map +1 -1
- package/dist/daemon/token.d.ts +41 -5
- package/dist/daemon/token.js +43 -12
- package/dist/daemon/token.js.map +1 -1
- package/dist/daemon/uploadHold.d.ts +85 -0
- package/dist/daemon/uploadHold.js +205 -0
- package/dist/daemon/uploadHold.js.map +1 -0
- package/dist/daemon/vfsHeaders.d.ts +11 -0
- package/dist/daemon/vfsHeaders.js +60 -0
- package/dist/daemon/vfsHeaders.js.map +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/notes.json +1 -1
- package/package.json +9 -4
- package/dist/daemon/discovery.d.ts +0 -23
- package/dist/daemon/discovery.js +0 -57
- package/dist/daemon/discovery.js.map +0 -1
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The daemon's running lines: their turns on the session, their slots, the waits on a person, and STOP.
|
|
3
|
+
*
|
|
4
|
+
* Execution takes turns across the whole session (lane.ts): a line waits until nothing running holds what it
|
|
5
|
+
* changes, then runs in a slot of its own, and whatever the engine raises under it (output, a question, a pipe
|
|
6
|
+
* segment) goes to its own surface. A line waiting on a person gives up what it holds until the answer comes
|
|
7
|
+
* (`person_await`), so other lines run meanwhile. STOP and Ctrl-C end a line: its signal is aborted, and one still
|
|
8
|
+
* running after a grace is abandoned. What a finished line answers is the daemon's to send: `line_end` notes it and
|
|
9
|
+
* refreshes the prompt, which the line awaits in its own turn, and `line_answer` sends the answer.
|
|
10
|
+
*
|
|
11
|
+
* Key components:
|
|
12
|
+
* - CommandLane: the running lines, their lane and the slot the code runs inside.
|
|
13
|
+
* - CommandSlot: one running line.
|
|
14
|
+
* - lineExit_derive: a line's exit status, as `$?` holds it.
|
|
15
|
+
* - STOP_GRACE_MS, STOP_PENDING_MS: how long a stop waits, and how long a stop of a waiting line holds.
|
|
16
|
+
*
|
|
17
|
+
* Typical usage:
|
|
18
|
+
* ```ts
|
|
19
|
+
* const commands: CommandLane = new CommandLane(engine, { stopper_resolve, surface_isAttached, line_end, line_answer });
|
|
20
|
+
* void commands.line_run(surface, message);
|
|
21
|
+
* const answer: string = await commands.person_await((): Promise<string> => ask());
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Dependencies: lane.ts (the turns), the engine's line seam (engine.ts), surface.ts; Node's AsyncLocalStorage
|
|
25
|
+
* carries the slot through whatever the line awaits.
|
|
26
|
+
*
|
|
27
|
+
* @module
|
|
28
|
+
*/
|
|
29
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
30
|
+
import { Lane, LOCKS_ALL } from './lane.js';
|
|
31
|
+
/** How long a stopped command has to end before the session abandons it. */
|
|
32
|
+
export const STOP_GRACE_MS = 3000;
|
|
33
|
+
/** How long a STOP pressed while its command waits still applies when the command starts. */
|
|
34
|
+
export const STOP_PENDING_MS = 10000;
|
|
35
|
+
/**
|
|
36
|
+
* A line's exit status, as `$?` holds it and a remote `chell -c` exits with.
|
|
37
|
+
* The status the engine left when the line ended is the line's: `false ||
|
|
38
|
+
* pwd` answered an error and ended 0. A line that threw fails with its own
|
|
39
|
+
* status when it set one and 1 otherwise. Only a line the engine never
|
|
40
|
+
* ended (stopped before it ran, abandoned) is judged by its answers.
|
|
41
|
+
*
|
|
42
|
+
* @param envelopes - What the line answered; undefined when it threw.
|
|
43
|
+
* @param failureReason - Why it threw, when it did.
|
|
44
|
+
* @param lineExit - The status the engine left when the line ended.
|
|
45
|
+
* @returns The status.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* lineExit_derive([{ status: 'ok', rendered: 'nothing closed\n' }], undefined, 1); // 1
|
|
50
|
+
* lineExit_derive([{ status: 'error', rendered: '' }, { status: 'ok', rendered: '' }], undefined, 0); // 0
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function lineExit_derive(envelopes, failureReason, lineExit) {
|
|
54
|
+
if (failureReason !== undefined)
|
|
55
|
+
return lineExit !== undefined && lineExit !== 0 ? lineExit : 1;
|
|
56
|
+
if (lineExit !== undefined)
|
|
57
|
+
return lineExit;
|
|
58
|
+
return envelopes?.some((envelope) => envelope.status === 'error') === true ? 1 : 0;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The session's running lines. Execution takes turns across the whole session (lane.ts): one command works at a
|
|
62
|
+
* time on what it changes, so a prompt raised mid-command has one unambiguous surface to ask, the one holding the
|
|
63
|
+
* lane. A command waiting on a person gives the lane up until the answer comes (`person_await`).
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const commands: CommandLane = new CommandLane(engine, hooks);
|
|
68
|
+
* void commands.line_run(surface, { type: 'execute', id: '1', line: 'pwd' });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export class CommandLane {
|
|
72
|
+
engine;
|
|
73
|
+
hooks;
|
|
74
|
+
/** The turns every line and joblet takes. */
|
|
75
|
+
lane = new Lane();
|
|
76
|
+
/**
|
|
77
|
+
* The line the code runs inside: several may run at once, so each keeps
|
|
78
|
+
* its own slot, and whatever it raises (output, a question, a pipe
|
|
79
|
+
* segment) goes to its own surface.
|
|
80
|
+
*/
|
|
81
|
+
slotScope = new AsyncLocalStorage();
|
|
82
|
+
/** The lines running now, waiting aside or not, in the order they started. */
|
|
83
|
+
running = new Set();
|
|
84
|
+
/** Names each line for the engine. */
|
|
85
|
+
lineCount = 0;
|
|
86
|
+
/** Surfaces whose STOP found their command still waiting its turn, and when. */
|
|
87
|
+
stopPending = new Map();
|
|
88
|
+
/**
|
|
89
|
+
* @param engine - The engine the lines run in.
|
|
90
|
+
* @param hooks - What the lane asks of the daemon.
|
|
91
|
+
*/
|
|
92
|
+
constructor(engine, hooks) {
|
|
93
|
+
this.engine = engine;
|
|
94
|
+
this.hooks = hooks;
|
|
95
|
+
}
|
|
96
|
+
/** The surface of the line the code runs inside, or null outside any. */
|
|
97
|
+
get currentOrigin() {
|
|
98
|
+
return this.slotScope.getStore()?.origin ?? null;
|
|
99
|
+
}
|
|
100
|
+
/** The surface's id for the line the code runs inside, or null outside any. */
|
|
101
|
+
get currentId() {
|
|
102
|
+
return this.slotScope.getStore()?.id ?? null;
|
|
103
|
+
}
|
|
104
|
+
/** Whether the line the code runs inside is surface-internal. */
|
|
105
|
+
get currentInstrument() {
|
|
106
|
+
return this.slotScope.getStore()?.instrument === true;
|
|
107
|
+
}
|
|
108
|
+
/** How many wait their turn. */
|
|
109
|
+
get waiting() {
|
|
110
|
+
return this.lane.waiting;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Whether a foreground command is executing right now.
|
|
114
|
+
*
|
|
115
|
+
* @returns True while a line holds its turn.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* if (commands.busy_get()) void promptline_push();
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
busy_get() {
|
|
123
|
+
return [...this.running].some((slot) => slot.hold !== null);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The operator's line working now: the first holding its turn that is not a surface's own housekeeping.
|
|
127
|
+
*
|
|
128
|
+
* @returns The slot, or undefined when none works.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* const working: CommandSlot | undefined = commands.foreground_find();
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
foreground_find() {
|
|
136
|
+
return [...this.running].find((slot) => slot.hold !== null && !slot.instrument);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* What a line holds while it runs, as the engine reads it off the line: a
|
|
140
|
+
* read runs beside anything, and lines changing the same piece of the
|
|
141
|
+
* session take turns (#1273).
|
|
142
|
+
*
|
|
143
|
+
* @param line - The line.
|
|
144
|
+
* @returns What it holds.
|
|
145
|
+
*/
|
|
146
|
+
lineWant_get(line) {
|
|
147
|
+
let held = 'all';
|
|
148
|
+
try {
|
|
149
|
+
held = this.engine.line_holds?.(line) ?? 'all';
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// A line the engine cannot read runs alone, as every line once did.
|
|
153
|
+
}
|
|
154
|
+
return held === 'all' ? LOCKS_ALL : new Set(held);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Runs one line in its turn: it waits until nothing running holds what it
|
|
158
|
+
* changes, then runs in a slot of its own.
|
|
159
|
+
*
|
|
160
|
+
* @param origin - The surface that submitted the request.
|
|
161
|
+
* @param message - The execute request.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* void commands.line_run(surface, { type: 'execute', id: '1', line: 'pwd' });
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
async line_run(origin, message) {
|
|
169
|
+
this.lineCount += 1;
|
|
170
|
+
const slot = {
|
|
171
|
+
key: `line-${this.lineCount}`,
|
|
172
|
+
origin,
|
|
173
|
+
id: message.id,
|
|
174
|
+
instrument: message.instrument === true,
|
|
175
|
+
line: message.line,
|
|
176
|
+
startedAt: performance.now(),
|
|
177
|
+
want: this.lineWant_get(message.line),
|
|
178
|
+
hold: null,
|
|
179
|
+
asideStoppable: false,
|
|
180
|
+
abandon: null,
|
|
181
|
+
};
|
|
182
|
+
slot.hold = await this.lane.acquire(slot.want);
|
|
183
|
+
slot.startedAt = performance.now();
|
|
184
|
+
this.running.add(slot);
|
|
185
|
+
try {
|
|
186
|
+
// The command runs inside its own slot, so whatever the engine raises
|
|
187
|
+
// (a prompt, output, a pipe segment) reaches the surface that
|
|
188
|
+
// submitted it, whatever else runs meanwhile.
|
|
189
|
+
await this.slotScope.run(slot, () => this.execute_run(slot, message));
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
this.running.delete(slot);
|
|
193
|
+
if (slot.hold !== null)
|
|
194
|
+
this.lane.release(slot.hold);
|
|
195
|
+
slot.hold = null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Runs one execute request in the engine, then hands what it came to to the daemon to answer.
|
|
200
|
+
*
|
|
201
|
+
* @param slot - The line's slot, holding its turn.
|
|
202
|
+
* @param message - The execute request.
|
|
203
|
+
*/
|
|
204
|
+
async execute_run(slot, message) {
|
|
205
|
+
const origin = slot.origin;
|
|
206
|
+
let envelopes;
|
|
207
|
+
let failureReason;
|
|
208
|
+
// The line's own exit status, as the engine leaves it when the line ends.
|
|
209
|
+
let lineExit;
|
|
210
|
+
// A STOP pressed while this command waited its turn ends it unrun.
|
|
211
|
+
const stopper = this.hooks.stopper_resolve(origin);
|
|
212
|
+
const pendingAt = message.instrument === true ? undefined : this.stopPending.get(stopper);
|
|
213
|
+
if (pendingAt !== undefined)
|
|
214
|
+
this.stopPending.delete(stopper);
|
|
215
|
+
if (pendingAt !== undefined && Date.now() - pendingAt < STOP_PENDING_MS) {
|
|
216
|
+
envelopes = [{ status: 'error', rendered: '', renderedErr: `stopped: \`${message.line}\` was stopped before it ran\n` }];
|
|
217
|
+
}
|
|
218
|
+
else
|
|
219
|
+
try {
|
|
220
|
+
// A stopped command that does not end is abandoned: the session
|
|
221
|
+
// stops waiting, and whatever it does later is no one's.
|
|
222
|
+
const abandoned = new Promise((resolve) => {
|
|
223
|
+
slot.abandon = () => resolve([{ status: 'error', rendered: '', renderedErr: `stopped: \`${message.line}\` did not end when asked and was abandoned\n` }]);
|
|
224
|
+
});
|
|
225
|
+
// The line counts against its surface's own last answer: a terminal
|
|
226
|
+
// a surface shows is that surface (#1273).
|
|
227
|
+
envelopes = await Promise.race([this.engine.line_execute(message.line, { origin: stopper.id, id: slot.key, ended: (code) => { lineExit = code; } }), abandoned]);
|
|
228
|
+
}
|
|
229
|
+
catch (err) {
|
|
230
|
+
failureReason = err instanceof Error ? err.message : String(err);
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
slot.abandon = null;
|
|
234
|
+
}
|
|
235
|
+
const exitCode = lineExit_derive(envelopes, failureReason, lineExit);
|
|
236
|
+
await this.hooks.line_end(slot, exitCode);
|
|
237
|
+
this.hooks.line_answer(slot, message, { envelopes, failureReason, exitCode });
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Takes a hold for work no line of a surface runs (a joblet): it waits in
|
|
241
|
+
* the same lane as every line, and runs beside the lines it shares
|
|
242
|
+
* nothing with (#1273).
|
|
243
|
+
*
|
|
244
|
+
* @param holds - What the work changes, or 'all'.
|
|
245
|
+
* @returns Gives the hold back; a second call does nothing.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* const release: () => void = await commands.hold_take(['cwd']);
|
|
250
|
+
* release();
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
async hold_take(holds) {
|
|
254
|
+
const hold = await this.lane.acquire(holds === 'all' ? LOCKS_ALL : new Set(holds));
|
|
255
|
+
let given = false;
|
|
256
|
+
return () => {
|
|
257
|
+
if (given)
|
|
258
|
+
return;
|
|
259
|
+
given = true;
|
|
260
|
+
this.lane.release(hold);
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Waits on a person without holding the session: the request is sent and
|
|
265
|
+
* what the line holds given up, so other lines run; when the person
|
|
266
|
+
* answers, the line queues for its turn again.
|
|
267
|
+
*
|
|
268
|
+
* @param ask - Sends the request (under the asking command's slot) and
|
|
269
|
+
* resolves with the person's answer.
|
|
270
|
+
* @param stoppable - Whether the line waits aside on a task, where its surface's STOP still reaches it.
|
|
271
|
+
* @returns The answer.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* const answer: string = await commands.person_await((): Promise<string> => prompts.open(socket, send));
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
async person_await(ask, stoppable = false) {
|
|
279
|
+
const answered = ask();
|
|
280
|
+
const mine = this.slotScope.getStore();
|
|
281
|
+
if (mine === undefined || mine.hold === null)
|
|
282
|
+
return await answered;
|
|
283
|
+
// What the line holds is given up while it waits, and its slot stays
|
|
284
|
+
// its own: the engine keeps its per-line state (its exit code, a pipe's
|
|
285
|
+
// untaken input, its cancellation) per line, so nothing is handed over.
|
|
286
|
+
// A line waiting aside on a task stays the operator's to stop, and
|
|
287
|
+
// stays so while it waits for its turn again behind another's line: a
|
|
288
|
+
// STOP in that moment would otherwise find nothing of theirs running.
|
|
289
|
+
mine.asideStoppable = stoppable && !mine.instrument;
|
|
290
|
+
this.lane.release(mine.hold);
|
|
291
|
+
mine.hold = null;
|
|
292
|
+
try {
|
|
293
|
+
return await answered;
|
|
294
|
+
}
|
|
295
|
+
finally {
|
|
296
|
+
mine.hold = await this.lane.acquire(mine.want);
|
|
297
|
+
mine.asideStoppable = false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Waits aside: the running command steps out of the lane while it waits
|
|
302
|
+
* on something that is not the session's work (a task's next line), so
|
|
303
|
+
* other lines run meanwhile, and takes its turn again before going on.
|
|
304
|
+
* Its surface's STOP still reaches it.
|
|
305
|
+
*
|
|
306
|
+
* @param waiting - What it waits on.
|
|
307
|
+
* @returns What that resolved with.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* const next: string = await commands.aside_await(task.next());
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
aside_await(waiting) {
|
|
315
|
+
if (this.currentOrigin === null)
|
|
316
|
+
return waiting;
|
|
317
|
+
return this.person_await(() => waiting, true);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Ctrl-C: stops the surface's own foreground command with this id.
|
|
321
|
+
*
|
|
322
|
+
* @param origin - The surface asking.
|
|
323
|
+
* @param id - The surface's id for the command.
|
|
324
|
+
* @returns False when no such command works for it.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* if (!commands.foreground_cancel(surface, message.id)) send(surface.socket, refusal);
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
foreground_cancel(origin, id) {
|
|
332
|
+
const slot = [...this.running].find((each) => each.origin === origin && each.id === id && each.hold !== null);
|
|
333
|
+
if (slot === undefined)
|
|
334
|
+
return false;
|
|
335
|
+
// Ctrl-C is a stop: the command is asked to end, and abandoned if it does not.
|
|
336
|
+
this.command_stop(slot);
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* The operator's STOP: ends the command running for this surface, its own
|
|
341
|
+
* or one typed in a terminal it owns, whatever the command is.
|
|
342
|
+
*
|
|
343
|
+
* @param origin - The surface pressing STOP.
|
|
344
|
+
* @returns False when nothing of its is running or waiting.
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* if (!commands.stop_press(surface)) send(surface.socket, { type: 'error', reason: 'stop: nothing of yours is running' });
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
stop_press(origin) {
|
|
352
|
+
// A surface's silent housekeeping is not what the operator stops. A line
|
|
353
|
+
// whose surface has gone is anyone's to stop: nobody else can.
|
|
354
|
+
const slot_isStoppable = (slot) => !slot.instrument && (this.hooks.stopper_resolve(slot.origin) === origin || !this.hooks.surface_isAttached(slot.origin));
|
|
355
|
+
const working = [...this.running].filter((slot) => slot.hold !== null && slot_isStoppable(slot));
|
|
356
|
+
if (working.length > 0) {
|
|
357
|
+
for (const slot of working)
|
|
358
|
+
this.command_stop(slot);
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
// Its command may be waiting aside on a task: stopped where it waits,
|
|
362
|
+
// its own surface's first, else one whose surface has gone.
|
|
363
|
+
const asides = [...this.running].filter((slot) => slot.hold === null && slot.asideStoppable && slot_isStoppable(slot));
|
|
364
|
+
const aside = asides.find((slot) => this.hooks.stopper_resolve(slot.origin) === origin) ?? asides[0];
|
|
365
|
+
if (aside !== undefined) {
|
|
366
|
+
this.engine.line_abort?.(aside.key);
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
// Its command may be waiting its turn behind someone else's: it is
|
|
370
|
+
// stopped the moment it starts, without running.
|
|
371
|
+
if (this.lane.waiting > 0) {
|
|
372
|
+
this.stopPending.set(origin, Date.now());
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* A shell that goes away hangs up on its commands: each still working is stopped.
|
|
379
|
+
*
|
|
380
|
+
* @param surface - The surface that went away.
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* commands.surface_hangup(surface);
|
|
385
|
+
* ```
|
|
386
|
+
*/
|
|
387
|
+
surface_hangup(surface) {
|
|
388
|
+
for (const slot of this.running)
|
|
389
|
+
if (slot.origin === surface && slot.hold !== null)
|
|
390
|
+
this.command_stop(slot);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Stops the running command: its signal is aborted (a command that checks
|
|
394
|
+
* it ends, a host process it started is killed), and one still running
|
|
395
|
+
* after {@link STOP_GRACE_MS} is abandoned, so the session is free again
|
|
396
|
+
* whatever the command was waiting on.
|
|
397
|
+
*
|
|
398
|
+
* @param slot - The line to stop.
|
|
399
|
+
*/
|
|
400
|
+
command_stop(slot) {
|
|
401
|
+
this.engine.line_abort?.(slot.key) ?? this.engine.line_cancel?.(slot.key);
|
|
402
|
+
const timer = setTimeout(() => {
|
|
403
|
+
if (this.running.has(slot))
|
|
404
|
+
slot.abandon?.();
|
|
405
|
+
}, STOP_GRACE_MS);
|
|
406
|
+
timer.unref?.();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
//# sourceMappingURL=commandLane.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandLane.js","sourceRoot":"","sources":["../../src/daemon/commandLane.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAOrD,OAAO,EAAE,IAAI,EAAE,SAAS,EAA2B,MAAM,WAAW,CAAC;AAMrE,4EAA4E;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAW,IAAI,CAAC;AAE1C,6FAA6F;AAC7F,MAAM,CAAC,MAAM,eAAe,GAAW,KAAK,CAAC;AA8E7C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,SAAwC,EAAE,aAAiC,EAAE,QAA4B;IACvI,IAAI,aAAa,KAAK,SAAS;QAAE,OAAO,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAChG,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC5C,OAAO,SAAS,EAAE,IAAI,CAAC,CAAC,QAAyB,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AI,CAAC,IAAI,KAAK,IAAI;gBAAE,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC9G,CAAC;IAED;;;;;;;OAOG;IACK,YAAY,CAAC,IAAiB;QACpC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1E,MAAM,KAAK,GAAkC,UAAU,CAAC,GAAS,EAAE;YACjE,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/C,CAAC,EAAE,aAAa,CAAC,CAAC;QAClB,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;IAClB,CAAC;CACF"}
|
package/dist/daemon/console.d.ts
CHANGED
|
@@ -11,5 +11,3 @@ export declare function consoleCage_start(): void;
|
|
|
11
11
|
* was written, or when no cage was in place.
|
|
12
12
|
*/
|
|
13
13
|
export declare function consoleCage_stop(): string[];
|
|
14
|
-
/** Whether the daemon's console output is currently being held. */
|
|
15
|
-
export declare function consoleCage_isActive(): boolean;
|
package/dist/daemon/console.js
CHANGED
|
@@ -21,13 +21,14 @@ export function consoleCage_start() {
|
|
|
21
21
|
if (cage !== null)
|
|
22
22
|
return;
|
|
23
23
|
const ring = new FaceLogRing();
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// Each stream read as its own text (a sequence or a character cut across its writes is read whole), into one ring.
|
|
25
|
+
const capture = (channel) => (chunk) => {
|
|
26
|
+
ring.push(chunk, channel);
|
|
26
27
|
return true;
|
|
27
|
-
}
|
|
28
|
+
};
|
|
28
29
|
cage = { ring, stdoutWrite: process.stdout.write, stderrWrite: process.stderr.write };
|
|
29
|
-
process.stdout.write = capture;
|
|
30
|
-
process.stderr.write = capture;
|
|
30
|
+
process.stdout.write = capture('out');
|
|
31
|
+
process.stderr.write = capture('err');
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Restores the terminal's own writes and returns what was held.
|
|
@@ -40,12 +41,8 @@ export function consoleCage_stop() {
|
|
|
40
41
|
return [];
|
|
41
42
|
process.stdout.write = cage.stdoutWrite;
|
|
42
43
|
process.stderr.write = cage.stderrWrite;
|
|
43
|
-
const held = cage.ring.drain();
|
|
44
|
+
const held = cage.ring.drain(true);
|
|
44
45
|
cage = null;
|
|
45
46
|
return held;
|
|
46
47
|
}
|
|
47
|
-
/** Whether the daemon's console output is currently being held. */
|
|
48
|
-
export function consoleCage_isActive() {
|
|
49
|
-
return cage !== null;
|
|
50
|
-
}
|
|
51
48
|
//# sourceMappingURL=console.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/daemon/console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/daemon/console.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,WAAW,EAAoB,MAAM,WAAW,CAAC;AAS1D,IAAI,IAAI,GAAqB,IAAI,CAAC;AAElC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAC/B,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO;IAC1B,MAAM,IAAI,GAAgB,IAAI,WAAW,EAAE,CAAC;IAC5C,mHAAmH;IACnH,MAAM,OAAO,GAAG,CAAC,OAAoB,EAA+B,EAAE,CAAC,CAAC,KAA0B,EAAW,EAAE;QAC7G,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IACF,IAAI,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtF,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAC9B,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IAC7B,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC;IACxC,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC;IACxC,MAAM,IAAI,GAAa,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7C,IAAI,GAAG,IAAI,CAAC;IACZ,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -33,6 +33,7 @@ import { spawn as childSpawn } from 'node:child_process';
|
|
|
33
33
|
import { existsSync } from 'node:fs';
|
|
34
34
|
import { createRequire } from 'node:module';
|
|
35
35
|
import { dirname, join } from 'node:path';
|
|
36
|
+
import { ATTACH_TOKEN_ENV, CONSOLE_ENV } from '@fnndsc/menu';
|
|
36
37
|
import chalk from 'chalk';
|
|
37
38
|
import { consoleCage_start, consoleCage_stop } from './console.js';
|
|
38
39
|
/** The default: the `chell` a user would run, found on the path. */
|
|
@@ -68,7 +69,9 @@ export function surface_spawn(target, launch = CHELL_ON_PATH, spawn = childSpawn
|
|
|
68
69
|
// The identity rides along so the surface greets with it, not with the
|
|
69
70
|
// address twice; the environment mark tells it whose terminal it is on,
|
|
70
71
|
// so it skips the greeting the daemon's banner already gave.
|
|
71
|
-
|
|
72
|
+
// The token goes to the surface in its environment, never on its command line: an argument list is shown
|
|
73
|
+
// to every user of this host by `ps`, an environment only to the process's own user.
|
|
74
|
+
const child = spawn(launch.exec, [...launch.prefixArgs, '--remote', target.identity, '--attach', target.url], { stdio: 'inherit', env: { ...process.env, [CONSOLE_ENV]: '1', [ATTACH_TOKEN_ENV]: target.token } });
|
|
72
75
|
const exited = new Promise((resolve) => {
|
|
73
76
|
child.once('exit', (code) => { resolve(code ?? 0); });
|
|
74
77
|
child.once('error', (error) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consoleSession.js","sourceRoot":"","sources":["../../src/daemon/consoleSession.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAE,KAAK,IAAI,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"consoleSession.js","sourceRoot":"","sources":["../../src/daemon/consoleSession.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAE,KAAK,IAAI,UAAU,EAAqB,MAAM,oBAAoB,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAiBnE,oEAAoE;AACpE,MAAM,CAAC,MAAM,aAAa,GAAkB,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;AAE9E;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe,MAAM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IAAI,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC,CAAC;YAC5D,KAAK,MAAM,IAAI,IAAI,IAAI;gBAAE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,mGAAmG,CAAC,CAAC,CAAC;QAC3H,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;YAAE,OAAO;IACzC,CAAC;AACH,CAAC"}
|
|
@@ -15,9 +15,6 @@ export interface ElevationDoor {
|
|
|
15
15
|
/** Checks a password at the door; true when it is theirs. */
|
|
16
16
|
readonly verify: (password: string) => Promise<boolean>;
|
|
17
17
|
}
|
|
18
|
-
/** The environment names the door a porter gives a daemon it starts. */
|
|
19
|
-
export declare const ELEVATION_URL_ENV: string;
|
|
20
|
-
export declare const ELEVATION_USER_ENV: string;
|
|
21
18
|
/**
|
|
22
19
|
* Checks a password at a CUBE: `auth-token/` answers 200 with a token for
|
|
23
20
|
* the right one, which is dropped unread; anything else is a refusal.
|
package/dist/daemon/elevation.js
CHANGED
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
export const ELEVATION_URL_ENV = 'CALYPSO_ELEVATION_URL';
|
|
13
|
-
export const ELEVATION_USER_ENV = 'CALYPSO_ELEVATION_USER';
|
|
11
|
+
import { ELEVATION_URL_ENV, ELEVATION_USER_ENV } from './settings.js';
|
|
14
12
|
/**
|
|
15
13
|
* Checks a password at a CUBE: `auth-token/` answers 200 with a token for
|
|
16
14
|
* the right one, which is dropped unread; anything else is a refusal.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elevation.js","sourceRoot":"","sources":["../../src/daemon/elevation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"elevation.js","sourceRoot":"","sources":["../../src/daemon/elevation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAWtE;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAAe,EAAE,QAAgB,EAAE,QAAgB,EAAE,UAAwB,KAAK;IACzH,MAAM,GAAG,GAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,aAAa,CAAC;IACpF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAa,MAAM,OAAO,CAAC,GAAG,EAAE;YAC5C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,EAAE;YAC3E,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;SAC7C,CAAC,CAAC;QACH,OAAO,QAAQ,CAAC,EAAE,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAAC,GAAsB,EAAE,UAAwB,KAAK;IAClF,MAAM,GAAG,GAAuB,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACvD,MAAM,IAAI,GAAuB,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACzD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,EAAE,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IACtF,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,QAAgB,EAAoB,EAAE,CAAC,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;AACpH,CAAC"}
|
package/dist/daemon/face.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface FaceOptions {
|
|
|
26
26
|
/** Live readings; omitted readings render as an idle daemon. */
|
|
27
27
|
telemetry_get?: () => FaceTelemetry;
|
|
28
28
|
}
|
|
29
|
+
/** The stream a hijacked write came from. */
|
|
30
|
+
export type FaceChannel = 'out' | 'err';
|
|
29
31
|
/**
|
|
30
32
|
* A bounded line buffer for output arriving while the face owns the screen.
|
|
31
33
|
*
|
|
@@ -36,8 +38,11 @@ export interface FaceOptions {
|
|
|
36
38
|
*/
|
|
37
39
|
export declare class FaceLogRing {
|
|
38
40
|
private lines;
|
|
39
|
-
private pending;
|
|
40
41
|
private unflushed;
|
|
42
|
+
/** Each hijacked stream read as its own text: a sequence or a character cut across its writes is read whole. */
|
|
43
|
+
private readonly streams;
|
|
44
|
+
/** The line on the screen not yet ended: both streams write onto it, as both write onto one terminal. */
|
|
45
|
+
private pending;
|
|
41
46
|
/**
|
|
42
47
|
* Absorbs one raw write, splitting it into stripped, stored lines.
|
|
43
48
|
*
|
|
@@ -45,9 +50,16 @@ export declare class FaceLogRing {
|
|
|
45
50
|
* discards what preceded it on the line rather than appending, so a
|
|
46
51
|
* thousand frames stay one line, not one enormous one.
|
|
47
52
|
*
|
|
48
|
-
* @param chunk - The text a hijacked
|
|
53
|
+
* @param chunk - The text (or UTF-8 bytes) a hijacked write carried.
|
|
54
|
+
* @param channel - Which stream wrote it.
|
|
55
|
+
*/
|
|
56
|
+
push(chunk: string | Uint8Array, channel?: FaceChannel): void;
|
|
57
|
+
/**
|
|
58
|
+
* Puts words on the screen's lines: ended lines into the ring, the rest pending.
|
|
59
|
+
*
|
|
60
|
+
* @param words - The words, escapes already read out.
|
|
49
61
|
*/
|
|
50
|
-
|
|
62
|
+
private words_take;
|
|
51
63
|
/**
|
|
52
64
|
* The newest lines, for the face's log strip.
|
|
53
65
|
*
|
|
@@ -58,9 +70,11 @@ export declare class FaceLogRing {
|
|
|
58
70
|
/**
|
|
59
71
|
* Returns and forgets the lines not yet replayed into the normal buffer.
|
|
60
72
|
*
|
|
73
|
+
* @param final - True when the screen is handed back for good: the streams
|
|
74
|
+
* end, and the line not yet ended is replayed too, so nothing visible is lost.
|
|
61
75
|
* @returns The unflushed lines, oldest first.
|
|
62
76
|
*/
|
|
63
|
-
drain(): string[];
|
|
77
|
+
drain(final?: boolean): string[];
|
|
64
78
|
}
|
|
65
79
|
/** Everything the pure composer needs to draw one frame. */
|
|
66
80
|
export interface FaceFrame {
|