@anhlp/alp-daemon 0.0.0-stage → 0.0.1-beta.4
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/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +14 -2
- package/dist/THIRD-PARTY-NOTICES.txt +431 -0
- package/dist/alp-templates.d.ts +5 -0
- package/dist/alpd.js +49562 -0
- package/dist/attachments.d.ts +211 -0
- package/dist/attachments.js +819 -0
- package/dist/build-manifest.json +131 -0
- package/dist/conversation.d.ts +119 -0
- package/dist/conversation.js +672 -0
- package/dist/files.d.ts +123 -0
- package/dist/files.js +365 -0
- package/dist/git.d.ts +87 -0
- package/dist/git.js +1093 -0
- package/dist/gitignore.d.ts +62 -0
- package/dist/gitignore.js +254 -0
- package/dist/history.d.ts +24 -0
- package/dist/history.js +149 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +25 -0
- package/dist/lifecycle.d.ts +101 -0
- package/dist/lifecycle.js +239 -0
- package/dist/lock.d.ts +21 -0
- package/dist/lock.js +42 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +277 -0
- package/dist/operations.d.ts +23 -0
- package/dist/operations.js +275 -0
- package/dist/registry.d.ts +89 -0
- package/dist/registry.js +343 -0
- package/dist/rpc-error.d.ts +6 -0
- package/dist/rpc-error.js +11 -0
- package/dist/scheduler.d.ts +96 -0
- package/dist/scheduler.js +290 -0
- package/dist/schedules.d.ts +69 -0
- package/dist/schedules.js +244 -0
- package/dist/server.d.ts +58 -0
- package/dist/server.js +1780 -0
- package/dist/store.d.ts +176 -0
- package/dist/store.js +385 -0
- package/dist/terminals.d.ts +157 -0
- package/dist/terminals.js +487 -0
- package/dist/worktrees.d.ts +41 -0
- package/dist/worktrees.js +246 -0
- package/package.json +159 -4
- package/src/alp-templates.d.ts +5 -0
- package/src/attachments.ts +870 -0
- package/src/conversation.ts +837 -0
- package/src/files.ts +459 -0
- package/src/git.ts +1045 -0
- package/src/gitignore.ts +277 -0
- package/src/history.ts +118 -0
- package/src/index.ts +11 -0
- package/src/lifecycle.ts +283 -0
- package/src/lock.ts +53 -0
- package/src/main.ts +292 -0
- package/src/operations.ts +300 -0
- package/src/registry.ts +238 -0
- package/src/rpc-error.ts +4 -0
- package/src/scheduler.ts +422 -0
- package/src/schedules.ts +294 -0
- package/src/server.ts +2056 -0
- package/src/store.ts +448 -0
- package/src/terminals.ts +591 -0
- package/src/worktrees.ts +287 -0
package/src/terminals.ts
ADDED
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { access, lstat, readFile } from 'node:fs/promises';
|
|
6
|
+
import { createRequire } from 'node:module';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { ERROR, RPC_ERROR, TERMINAL, TERMINAL_LIMIT_KEYS, isTerminalId } from '@anhlp/alp-protocol';
|
|
9
|
+
import type { TerminalEndReason, TerminalEvent, TerminalInfo, TerminalLimits } from '@anhlp/alp-protocol/rpc';
|
|
10
|
+
import { RpcError } from './rpc-error.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Terminals (capability `terminal`, docs/protocol/alp-json-rpc-v1.md §12.10, issue #121 H): a real
|
|
14
|
+
* PTY running a shell on this host **as the daemon's account**. A workspace chooses only where the
|
|
15
|
+
* shell starts and who sees the terminal; it is not a sandbox. alpd serves terminals only while the
|
|
16
|
+
* host owner opted in (`<ALP_HOME>/terminal.json` `allowRemoteTerminal`, an owner-private file no RPC
|
|
17
|
+
* writes), on macOS and Linux, when the optional `node-pty` module loads. Lifecycle is audited;
|
|
18
|
+
* input, output and the environment never are.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Who a call acts for, as for attachments: a gateway's credential and grant epoch, or the owner. */
|
|
22
|
+
export type TerminalPrincipal = { id: string; epoch: string; roots?: readonly string[] };
|
|
23
|
+
/** The connection a terminal streams to: alpd's own IPC connection object. */
|
|
24
|
+
export type TerminalSink = { send(message: unknown): void; socket?: { writableLength: number; destroyed?: boolean } };
|
|
25
|
+
type Disposable = { dispose(): void };
|
|
26
|
+
/** What alpd uses of a node-pty process. */
|
|
27
|
+
export type PtyProcess = {
|
|
28
|
+
pid: number;
|
|
29
|
+
/** The PTY's device (node-pty's UnixTerminal), such as /dev/ttys004 or /dev/pts/3. */
|
|
30
|
+
readonly ptsName?: string;
|
|
31
|
+
write(data: string): void;
|
|
32
|
+
resize(cols: number, rows: number): void;
|
|
33
|
+
kill(signal?: string): void;
|
|
34
|
+
onData(listener: (data: string) => void): Disposable;
|
|
35
|
+
onExit(listener: (event: { exitCode: number; signal?: number }) => void): Disposable;
|
|
36
|
+
};
|
|
37
|
+
export type PtySpawn = (file: string, args: string[], options: { name: string; cols: number; rows: number; cwd: string; env: Record<string, string> }) => PtyProcess;
|
|
38
|
+
/** One process: ids, (Linux) session, controlling tty, age, and the terminal markers in its environment. */
|
|
39
|
+
export type ProcessRow = { pid: number; ppid: number; pgid: number; sid?: number; tty?: string; elapsedMs: number; markers?: string[] };
|
|
40
|
+
type Log = { info(message: string, fields?: Record<string, unknown>): void; warn(message: string, fields?: Record<string, unknown>): void };
|
|
41
|
+
|
|
42
|
+
export type TerminalServiceOptions = {
|
|
43
|
+
home: string;
|
|
44
|
+
/** The canonical directory of a registry workspace, or a RegistryError-like refusal. */
|
|
45
|
+
resolveWorkspace(workspaceId: string): Promise<string>;
|
|
46
|
+
log: Log;
|
|
47
|
+
/** Lower limits (tests, an embedding host); never higher than TERMINAL. */
|
|
48
|
+
limits?: Partial<TerminalLimits>;
|
|
49
|
+
now?: () => number;
|
|
50
|
+
platform?: NodeJS.Platform;
|
|
51
|
+
/** Test hook: the PTY spawner; default node-pty, loaded on first use. */
|
|
52
|
+
spawn?: PtySpawn;
|
|
53
|
+
/** Test hook: the process table; default `ps`. */
|
|
54
|
+
processes?: () => Promise<ProcessRow[]>;
|
|
55
|
+
sweepMs?: number;
|
|
56
|
+
killGraceMs?: number;
|
|
57
|
+
/** Bytes of terminal events waiting on a connection's socket before it counts as a slow consumer. */
|
|
58
|
+
maxBufferedBytes?: number;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type Frame = { seq: number; data: string; bytes: number };
|
|
62
|
+
type Terminal = {
|
|
63
|
+
id: string;
|
|
64
|
+
principal: { id: string; epoch: string };
|
|
65
|
+
workspaceId: string;
|
|
66
|
+
root: string;
|
|
67
|
+
title: string;
|
|
68
|
+
cols: number;
|
|
69
|
+
rows: number;
|
|
70
|
+
pty: PtyProcess;
|
|
71
|
+
pid: number;
|
|
72
|
+
/** The PTY's device as ps names it (ttys004, pts/3): a controlling terminal outlives double forks. */
|
|
73
|
+
tty?: string;
|
|
74
|
+
createdAt: number;
|
|
75
|
+
lastActivityAt: number;
|
|
76
|
+
expiresAt: number;
|
|
77
|
+
requestKey: string;
|
|
78
|
+
ring: Frame[];
|
|
79
|
+
ringBytes: number;
|
|
80
|
+
nextSeq: number;
|
|
81
|
+
sink?: TerminalSink;
|
|
82
|
+
detachedAt?: number;
|
|
83
|
+
/**
|
|
84
|
+
* A random value in the environment of every process the terminal starts (ALP_TERMINAL_ID): it
|
|
85
|
+
* finds a job that left the shell's tree (double fork, re-parented, shell already gone) without
|
|
86
|
+
* remembering any process or group id that could be reused.
|
|
87
|
+
*/
|
|
88
|
+
marker: string;
|
|
89
|
+
ending?: TerminalEndReason;
|
|
90
|
+
exit?: { seq: number; exitCode: number | null; signal: number | null; reason: TerminalEndReason; at: number };
|
|
91
|
+
disposables: Disposable[];
|
|
92
|
+
reaped?: Promise<void>;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const SWEEP_MS = 5_000;
|
|
96
|
+
const KILL_GRACE_MS = 1_000;
|
|
97
|
+
const MAX_BUFFERED_BYTES = 2 * 1024 * 1024;
|
|
98
|
+
const CONFIG_FILE = 'terminal.json';
|
|
99
|
+
/** Variables of alpd's own environment a terminal does not inherit. */
|
|
100
|
+
const PRIVATE_ENV = /^(ALP_|npm_)/i;
|
|
101
|
+
|
|
102
|
+
const notFound = () => new RpcError(ERROR.notFound, 'No such terminal', { reason: 'not_found' });
|
|
103
|
+
const iso = (ms: number) => new Date(ms).toISOString();
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The host switch and the operator's lower limits. Anything but a regular, owner-private file of
|
|
107
|
+
* this user saying `"allowRemoteTerminal": true` is off.
|
|
108
|
+
*/
|
|
109
|
+
export async function readTerminalConfig(home: string, log?: Log): Promise<{ enabled: boolean; reason?: string; limits: TerminalLimits; paseo: boolean }> {
|
|
110
|
+
const defaults = Object.fromEntries(TERMINAL_LIMIT_KEYS.map(key => [key, TERMINAL[key as keyof typeof TERMINAL]])) as TerminalLimits;
|
|
111
|
+
const file = path.join(home, CONFIG_FILE);
|
|
112
|
+
const info = await lstat(file).catch(() => undefined);
|
|
113
|
+
if (!info) return { enabled: false, reason: 'missing', limits: defaults, paseo: false };
|
|
114
|
+
if (!info.isFile() || (process.getuid && info.uid !== process.getuid()) || (info.mode & 0o077)) {
|
|
115
|
+
log?.warn('terminal.json is not a private file of the daemon user; terminals stay off', { code: 'ALPD_TERMINAL_CONFIG' });
|
|
116
|
+
return { enabled: false, reason: 'not_private', limits: defaults, paseo: false };
|
|
117
|
+
}
|
|
118
|
+
let value: any;
|
|
119
|
+
try { value = JSON.parse(await readFile(file, 'utf8')); } catch {
|
|
120
|
+
log?.warn('terminal.json is not valid JSON; terminals stay off', { code: 'ALPD_TERMINAL_CONFIG' });
|
|
121
|
+
return { enabled: false, reason: 'invalid', limits: defaults, paseo: false };
|
|
122
|
+
}
|
|
123
|
+
if (!value || typeof value !== 'object' || value.version !== 1) return { enabled: false, reason: 'invalid', limits: defaults, paseo: false };
|
|
124
|
+
const limits = { ...defaults };
|
|
125
|
+
if (value.limits && typeof value.limits === 'object') {
|
|
126
|
+
for (const [key, raw] of Object.entries(value.limits)) {
|
|
127
|
+
if (!(TERMINAL_LIMIT_KEYS as readonly string[]).includes(key) || !Number.isSafeInteger(raw) || (raw as number) < 1) { log?.warn(`terminal.json limit ${key} ignored`, { code: 'ALPD_TERMINAL_CONFIG' }); continue; }
|
|
128
|
+
const k = key as keyof TerminalLimits;
|
|
129
|
+
if ((raw as number) > defaults[k]) { log?.warn(`terminal.json limit ${key} is above the maximum; ignored`, { code: 'ALPD_TERMINAL_CONFIG' }); continue; }
|
|
130
|
+
limits[k] = raw as number;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// allowPaseoTerminal: Paseo app devices paired through the relay act as the owner and hold no
|
|
134
|
+
// terminal.exec; the Paseo bridge offers terminals only with this second, separate opt-in.
|
|
135
|
+
return value.allowRemoteTerminal === true ? { enabled: true, limits, paseo: value.allowPaseoTerminal === true } : { enabled: false, reason: 'off', limits, paseo: false };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** `[[dd-]hh:]mm:ss` of ps etime, in milliseconds. */
|
|
139
|
+
function elapsed(text: string) {
|
|
140
|
+
const [days, rest] = text.includes('-') ? text.split('-') : ['0', text];
|
|
141
|
+
const parts = rest!.split(':').map(Number);
|
|
142
|
+
while (parts.length < 3) parts.unshift(0);
|
|
143
|
+
const [h, m, s] = parts as [number, number, number];
|
|
144
|
+
return (((Number(days) * 24 + h) * 60 + m) * 60 + s) * 1000;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const MARKER = /(?:^|\s)ALP_TERMINAL_ID=(atm_[0-9a-f]{32})(?=\s|$)/g;
|
|
148
|
+
const markersOf = (text: string) => [...text.matchAll(MARKER)].map(match => match[1]!);
|
|
149
|
+
const ENTRY = /^ALP_TERMINAL_ID=(atm_[0-9a-f]{32})$/;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* The process table: pid, parent, group, (Linux) session, controlling tty, age, and the terminal
|
|
153
|
+
* markers in each process's environment (macOS: `ps -E`, this user's processes only; Linux:
|
|
154
|
+
* /proc/<pid>/environ, readable for this user's processes).
|
|
155
|
+
*/
|
|
156
|
+
export function psProcesses(platform: NodeJS.Platform = process.platform): () => Promise<ProcessRow[]> {
|
|
157
|
+
const linux = platform === 'linux';
|
|
158
|
+
// At most 10 s for each ps, even one that does not die at once.
|
|
159
|
+
const run = (args: string[]) => new Promise<string | undefined>(resolve => {
|
|
160
|
+
const child = execFile('ps', args, { encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, killSignal: 'SIGKILL', env: { ...process.env, LC_ALL: 'C' } }, (error, stdout) => { clearTimeout(timer); resolve(error ? undefined : stdout); });
|
|
161
|
+
const timer = setTimeout(() => { child.kill('SIGKILL'); resolve(undefined); }, 10_000);
|
|
162
|
+
});
|
|
163
|
+
return async () => {
|
|
164
|
+
const columns = linux ? 'pid=,ppid=,pgid=,sid=,tty=,etime=' : 'pid=,ppid=,pgid=,tty=,etime=,command=';
|
|
165
|
+
// macOS: `ps -E` appends the environment to the command line (escaping newlines as \012); the
|
|
166
|
+
// command line alone, from a second pass, is cut off first so a marker in arguments never counts.
|
|
167
|
+
const [stdout, plain] = await Promise.all([run(linux ? ['-A', '-o', columns] : ['-A', '-E', '-ww', '-o', columns]), linux ? undefined : run(['-A', '-ww', '-o', 'pid=,command='])]);
|
|
168
|
+
if (stdout === undefined) return [];
|
|
169
|
+
const commands = new Map<number, string>();
|
|
170
|
+
for (const line of plain?.split('\n') ?? []) {
|
|
171
|
+
const match = /^\s*(\d+) (.*)$/.exec(line);
|
|
172
|
+
if (match) commands.set(Number(match[1]), match[2]!);
|
|
173
|
+
}
|
|
174
|
+
const rows: ProcessRow[] = [];
|
|
175
|
+
for (const line of stdout.split('\n')) {
|
|
176
|
+
const cells = line.trim().split(/\s+/);
|
|
177
|
+
if (cells.length < 5) continue;
|
|
178
|
+
const [pid, ppid, pgid] = cells.slice(0, 3).map(Number) as [number, number, number];
|
|
179
|
+
if (!Number.isSafeInteger(pid) || !Number.isSafeInteger(ppid) || !Number.isSafeInteger(pgid)) continue;
|
|
180
|
+
const sid = linux ? Number(cells[3]) : undefined;
|
|
181
|
+
const tty = cells[linux ? 4 : 3]!;
|
|
182
|
+
let markers: string[] = [];
|
|
183
|
+
// Linux: one entry of the environment, never a marker inside another variable's value.
|
|
184
|
+
if (linux) { try { markers = readFileSync(`/proc/${pid}/environ`, 'utf8').split('\0').flatMap(entry => ENTRY.exec(entry)?.[1] ?? []); } catch {} }
|
|
185
|
+
else {
|
|
186
|
+
// Exactly one space after etime: a command line may itself start with spaces.
|
|
187
|
+
const full = /^\s*(?:\S+\s+){4}\S+ (.*)$/.exec(line)?.[1] ?? '';
|
|
188
|
+
const command = commands.get(pid);
|
|
189
|
+
// The environment is what follows the command line; when the two passes disagree, none.
|
|
190
|
+
if (command !== undefined && full.startsWith(command)) markers = markersOf(full.slice(command.length));
|
|
191
|
+
}
|
|
192
|
+
rows.push({ pid, ppid, pgid, ...(sid !== undefined && Number.isSafeInteger(sid) ? { sid } : {}), ...(/^[?-]+$/.test(tty) ? {} : { tty }), elapsedMs: elapsed(cells[linux ? 5 : 4]!), ...(markers.length ? { markers } : {}) });
|
|
193
|
+
}
|
|
194
|
+
return rows;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Splits output into frames of at most `max` UTF-8 bytes, never inside a character. */
|
|
199
|
+
export function frames(data: string, max: number): string[] {
|
|
200
|
+
if (Buffer.byteLength(data) <= max) return [data];
|
|
201
|
+
const out: string[] = [];
|
|
202
|
+
let current = '';
|
|
203
|
+
let bytes = 0;
|
|
204
|
+
for (const char of data) {
|
|
205
|
+
const size = Buffer.byteLength(char);
|
|
206
|
+
if (bytes + size > max && current) { out.push(current); current = ''; bytes = 0; }
|
|
207
|
+
current += char;
|
|
208
|
+
bytes += size;
|
|
209
|
+
}
|
|
210
|
+
if (current) out.push(current);
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function createTerminalService(options: TerminalServiceOptions) {
|
|
215
|
+
const { home, resolveWorkspace, log } = options;
|
|
216
|
+
const now = options.now ?? Date.now;
|
|
217
|
+
const platform = options.platform ?? process.platform;
|
|
218
|
+
const supported = platform === 'darwin' || platform === 'linux';
|
|
219
|
+
const listProcesses = options.processes ?? psProcesses(platform);
|
|
220
|
+
const killGraceMs = options.killGraceMs ?? KILL_GRACE_MS;
|
|
221
|
+
const maxBuffered = options.maxBufferedBytes ?? MAX_BUFFERED_BYTES;
|
|
222
|
+
const terminals = new Map<string, Terminal>();
|
|
223
|
+
const requests = new Map<string, string>();
|
|
224
|
+
let spawner: PtySpawn | undefined = options.spawn;
|
|
225
|
+
let loadError: unknown;
|
|
226
|
+
let closed = false;
|
|
227
|
+
let enabled = false;
|
|
228
|
+
|
|
229
|
+
/** node-pty, loaded once on first need; its absence only turns terminals off. */
|
|
230
|
+
function pty(): PtySpawn | undefined {
|
|
231
|
+
if (spawner || loadError) return spawner;
|
|
232
|
+
try {
|
|
233
|
+
const name = 'node-pty';
|
|
234
|
+
const module = createRequire(import.meta.url)(name);
|
|
235
|
+
spawner = module.spawn as PtySpawn;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
loadError = error;
|
|
238
|
+
log.warn('the optional node-pty module did not load; terminals are unavailable', { code: 'ALPD_TERMINAL_UNAVAILABLE', error });
|
|
239
|
+
}
|
|
240
|
+
return spawner;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** Effective limits: the operator's, then the caller's lower ones. */
|
|
244
|
+
function effective(config: TerminalLimits): TerminalLimits {
|
|
245
|
+
const limits = { ...config };
|
|
246
|
+
for (const key of TERMINAL_LIMIT_KEYS as readonly (keyof TerminalLimits)[]) {
|
|
247
|
+
const lower = options.limits?.[key];
|
|
248
|
+
if (Number.isSafeInteger(lower) && lower! > 0 && lower! < limits[key]) limits[key] = lower!;
|
|
249
|
+
}
|
|
250
|
+
return limits;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** The switch now: off kills every terminal (reason `disabled`). */
|
|
254
|
+
async function state() {
|
|
255
|
+
const config = await readTerminalConfig(home, log);
|
|
256
|
+
const limits = effective(config.limits);
|
|
257
|
+
if (enabled && !config.enabled) {
|
|
258
|
+
log.info('terminals turned off on this host; ending every terminal', { code: 'ALPD_TERMINAL_DISABLED' });
|
|
259
|
+
for (const terminal of terminals.values()) if (!terminal.exit) void end(terminal, 'disabled');
|
|
260
|
+
}
|
|
261
|
+
enabled = config.enabled;
|
|
262
|
+
return { enabled: config.enabled, limits };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The switch, the platform and the module, or the refusal. */
|
|
266
|
+
async function ready() {
|
|
267
|
+
if (closed) throw new RpcError(ERROR.unavailable, 'alpd is shutting down', { reason: 'terminal_unsupported' });
|
|
268
|
+
if (!supported) throw new RpcError(ERROR.unavailable, 'Terminals are not supported on this host\'s platform', { reason: 'terminal_unsupported' });
|
|
269
|
+
const current = await state();
|
|
270
|
+
if (!current.enabled) throw new RpcError(ERROR.unavailable, 'The host has not allowed remote terminals (alp terminal allow)', { reason: 'terminal_disabled' });
|
|
271
|
+
if (!pty()) throw new RpcError(ERROR.unavailable, 'The terminal module is not installed on this host', { reason: 'terminal_unsupported' });
|
|
272
|
+
return current.limits;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function info(terminal: Terminal): TerminalInfo {
|
|
276
|
+
return {
|
|
277
|
+
terminalId: terminal.id, workspaceId: terminal.workspaceId, title: terminal.title, cols: terminal.cols, rows: terminal.rows,
|
|
278
|
+
state: terminal.exit ? 'exited' : 'running', attached: !!terminal.sink, createdAt: iso(terminal.createdAt),
|
|
279
|
+
lastActivityAt: iso(terminal.lastActivityAt), expiresAt: iso(terminal.expiresAt),
|
|
280
|
+
...(terminal.exit ? { exitCode: terminal.exit.exitCode, signal: terminal.exit.signal, endReason: terminal.exit.reason } : {}),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const audit = (message: string, terminal: Terminal, fields: Record<string, unknown> = {}) =>
|
|
285
|
+
log.info(message, { terminalId: terminal.id, workspaceId: terminal.workspaceId, principal: terminal.principal.id, ...fields });
|
|
286
|
+
|
|
287
|
+
/** The caller's own terminal, in its roots; anything else is the same not_found. */
|
|
288
|
+
function own(principal: TerminalPrincipal, terminalId: unknown): Terminal {
|
|
289
|
+
const terminal = isTerminalId(terminalId) ? terminals.get(terminalId as string) : undefined;
|
|
290
|
+
if (!terminal || terminal.principal.id !== principal.id || terminal.principal.epoch !== principal.epoch || !within(principal, terminal.root)) throw notFound();
|
|
291
|
+
return terminal;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function within(principal: TerminalPrincipal, root: string) {
|
|
295
|
+
if (principal.roots === undefined) return true;
|
|
296
|
+
return principal.roots.some(granted => root === granted || root.startsWith(granted.endsWith(path.sep) ? granted : granted + path.sep));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function send(terminal: Terminal, event: TerminalEvent) {
|
|
300
|
+
const sink = terminal.sink;
|
|
301
|
+
if (!sink) return;
|
|
302
|
+
sink.send({ jsonrpc: '2.0', method: 'terminal.event', params: event });
|
|
303
|
+
if (event.type === 'output' && (sink.socket?.writableLength ?? 0) > maxBuffered) detach(terminal, 'slow_consumer');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Ends the stream of a terminal (it keeps running for reconnectMs). */
|
|
307
|
+
function detach(terminal: Terminal, reason: 'replaced' | 'slow_consumer' | 'disconnected') {
|
|
308
|
+
const sink = terminal.sink;
|
|
309
|
+
if (!sink) return;
|
|
310
|
+
terminal.sink = undefined;
|
|
311
|
+
terminal.detachedAt = now();
|
|
312
|
+
if (reason !== 'disconnected') sink.send({ jsonrpc: '2.0', method: 'terminal.event', params: { terminalId: terminal.id, type: 'detached', reason } satisfies TerminalEvent });
|
|
313
|
+
audit('terminal detached', terminal, { code: 'ALPD_TERMINAL_DETACHED', reason });
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function output(terminal: Terminal, data: string, limits: TerminalLimits) {
|
|
317
|
+
terminal.lastActivityAt = now();
|
|
318
|
+
for (const piece of frames(data, limits.maxOutputFrameBytes)) {
|
|
319
|
+
const frame: Frame = { seq: terminal.nextSeq++, data: piece, bytes: Buffer.byteLength(piece) };
|
|
320
|
+
terminal.ring.push(frame);
|
|
321
|
+
terminal.ringBytes += frame.bytes;
|
|
322
|
+
while (terminal.ringBytes > limits.replayBytes && terminal.ring.length > 1) terminal.ringBytes -= terminal.ring.shift()!.bytes;
|
|
323
|
+
send(terminal, { terminalId: terminal.id, type: 'output', seq: frame.seq, data: frame.data });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Every process of a terminal still running, identified afresh from the process table, never from
|
|
329
|
+
* a remembered pid or group id (one that may have been reused):
|
|
330
|
+
* - its marker in the environment (any process the terminal started, wherever it went);
|
|
331
|
+
* - while the shell runs: the shell itself and every process whose controlling terminal is its PTY;
|
|
332
|
+
* - on Linux, its session (a session id is not reused while the session has members);
|
|
333
|
+
* then their descendants, and every member of their process groups (a live group's id is not
|
|
334
|
+
* reused either). Never alpd itself or its group, never a process older than the terminal.
|
|
335
|
+
*/
|
|
336
|
+
async function tree(terminal: Terminal): Promise<ProcessRow[]> {
|
|
337
|
+
// Whether the shell runs is decided before the snapshot, never after it.
|
|
338
|
+
const running = !terminal.exit;
|
|
339
|
+
// The terminal's age when the snapshot began: ps (and its /proc reads) may take a while.
|
|
340
|
+
const lifetime = now() - terminal.createdAt;
|
|
341
|
+
const rows = await listProcesses();
|
|
342
|
+
const age = now() - terminal.createdAt + 2_000;
|
|
343
|
+
const own = rows.find(row => row.pid === process.pid);
|
|
344
|
+
const children = new Map<number, ProcessRow[]>();
|
|
345
|
+
for (const row of rows) children.set(row.ppid, [...(children.get(row.ppid) ?? []), row]);
|
|
346
|
+
const found = new Map<number, ProcessRow>();
|
|
347
|
+
for (const row of rows) if (row.markers?.includes(terminal.marker)) found.set(row.pid, row);
|
|
348
|
+
// The process with the shell's pid is our shell only when it is as old as the terminal (etime
|
|
349
|
+
// counts whole seconds): a younger one got the pid again after our shell had gone.
|
|
350
|
+
const holder = rows.find(row => row.pid === terminal.pid);
|
|
351
|
+
const ours = !holder || holder.elapsedMs >= lifetime - 2_000;
|
|
352
|
+
const shell = running && ours ? holder : undefined;
|
|
353
|
+
if (shell) found.set(shell.pid, shell);
|
|
354
|
+
// The PTY's device name counts only while the shell, in this very snapshot, still has it as its
|
|
355
|
+
// terminal: once node-pty closed it the name may already be another PTY's.
|
|
356
|
+
const tty = shell && terminal.tty && shell.tty === terminal.tty ? terminal.tty : undefined;
|
|
357
|
+
// Linux: the session, also once the shell has gone. A pid is not given out again while it is a
|
|
358
|
+
// live process's session id, so while our session has members its id stays ours; a younger
|
|
359
|
+
// process holding the shell's pid means it was given out again. (Left open: our session emptied,
|
|
360
|
+
// and within the reap's second or so a new session leader got the very same pid and exited.)
|
|
361
|
+
for (const row of rows) {
|
|
362
|
+
if ((tty && row.tty === tty) || (row.sid !== undefined && row.sid === terminal.pid && ours)) found.set(row.pid, row);
|
|
363
|
+
}
|
|
364
|
+
const queue = [...found.values()];
|
|
365
|
+
while (queue.length) {
|
|
366
|
+
const row = queue.pop()!;
|
|
367
|
+
for (const child of children.get(row.pid) ?? []) if (!found.has(child.pid)) { found.set(child.pid, child); queue.push(child); }
|
|
368
|
+
}
|
|
369
|
+
const groups = new Set([...found.values()].map(row => row.pgid));
|
|
370
|
+
for (const row of rows) if (groups.has(row.pgid)) found.set(row.pid, row);
|
|
371
|
+
return [...found.values()].filter(row => row.pid > 1 && row.pid !== process.pid && (!own || row.pgid !== own.pgid) && row.elapsedMs <= age);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function signal(rows: ProcessRow[], name: NodeJS.Signals) {
|
|
375
|
+
for (const row of rows) { try { process.kill(row.pid, name); } catch {} }
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Kills what is left of a terminal's tree: SIGHUP, then SIGKILL after the grace. Only processes
|
|
380
|
+
* the process table shows in the tree now (never a bare group id that may have been reused).
|
|
381
|
+
*/
|
|
382
|
+
function reap(terminal: Terminal) {
|
|
383
|
+
terminal.reaped ??= (async () => {
|
|
384
|
+
signal(await tree(terminal), 'SIGHUP');
|
|
385
|
+
await new Promise(resolve => setTimeout(resolve, killGraceMs));
|
|
386
|
+
const left = await tree(terminal);
|
|
387
|
+
signal(left, 'SIGKILL');
|
|
388
|
+
if (left.length) {
|
|
389
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
390
|
+
signal(await tree(terminal), 'SIGKILL');
|
|
391
|
+
}
|
|
392
|
+
})().catch(error => log.warn('could not end every process of a terminal', { code: 'ALPD_TERMINAL_REAP_FAILED', terminalId: terminal.id, error }));
|
|
393
|
+
return terminal.reaped;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** The shell ended: the exit event, the rest of its tree killed, the record kept for reconnectMs. */
|
|
397
|
+
function exited(terminal: Terminal, exitCode: number | null, signalNumber: number | null) {
|
|
398
|
+
if (terminal.exit) return;
|
|
399
|
+
const reason = terminal.ending ?? 'exited';
|
|
400
|
+
terminal.exit = { seq: terminal.nextSeq++, exitCode, signal: signalNumber, reason, at: now() };
|
|
401
|
+
for (const disposable of terminal.disposables) { try { disposable.dispose(); } catch {} }
|
|
402
|
+
requests.delete(terminal.requestKey);
|
|
403
|
+
send(terminal, { terminalId: terminal.id, type: 'exit', seq: terminal.exit.seq, exitCode, signal: signalNumber, reason });
|
|
404
|
+
audit('terminal ended', terminal, { code: 'ALPD_TERMINAL_ENDED', reason, exitCode, signal: signalNumber });
|
|
405
|
+
void reap(terminal);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Ends a running terminal for `reason`; resolves once its tree was killed. */
|
|
409
|
+
async function end(terminal: Terminal, reason: TerminalEndReason) {
|
|
410
|
+
if (terminal.exit) return terminal.reaped;
|
|
411
|
+
terminal.ending ??= reason;
|
|
412
|
+
const reaping = reap(terminal);
|
|
413
|
+
try { terminal.pty.kill('SIGHUP'); } catch {}
|
|
414
|
+
await reaping;
|
|
415
|
+
// node-pty reports the exit when the PTY closes; do not wait on it for ever.
|
|
416
|
+
if (!terminal.exit) exited(terminal, null, null);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
let sweeping = false;
|
|
420
|
+
async function sweep() {
|
|
421
|
+
if (closed || sweeping) return;
|
|
422
|
+
sweeping = true;
|
|
423
|
+
try { await sweepOnce(); } finally { sweeping = false; }
|
|
424
|
+
}
|
|
425
|
+
async function sweepOnce() {
|
|
426
|
+
const current = await state().catch(() => undefined);
|
|
427
|
+
if (!current) return;
|
|
428
|
+
const { limits } = current;
|
|
429
|
+
const at = now();
|
|
430
|
+
for (const terminal of [...terminals.values()]) {
|
|
431
|
+
if (terminal.exit) {
|
|
432
|
+
if (at - terminal.exit.at >= limits.reconnectMs) terminals.delete(terminal.id);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if (at >= terminal.expiresAt) void end(terminal, 'lifetime');
|
|
436
|
+
else if (at - terminal.lastActivityAt >= limits.idleMs) void end(terminal, 'idle');
|
|
437
|
+
else if (!terminal.sink && terminal.detachedAt !== undefined && at - terminal.detachedAt >= limits.reconnectMs) void end(terminal, 'detached');
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
const timer = setInterval(() => void sweep().catch(() => {}), options.sweepMs ?? SWEEP_MS);
|
|
441
|
+
timer.unref?.();
|
|
442
|
+
|
|
443
|
+
/** The approved shell: the daemon user's login shell when /etc/shells lists it, else /bin/sh. */
|
|
444
|
+
async function shell() {
|
|
445
|
+
const candidate = process.env.SHELL;
|
|
446
|
+
if (candidate && path.isAbsolute(candidate)) {
|
|
447
|
+
const listed = await readFile('/etc/shells', 'utf8').then(text => text.split('\n').map(line => line.trim()).includes(candidate), () => false);
|
|
448
|
+
if (listed && await access(candidate, constants.X_OK).then(() => true, () => false)) return candidate;
|
|
449
|
+
}
|
|
450
|
+
return '/bin/sh';
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function environment(marker: string) {
|
|
454
|
+
const env: Record<string, string> = {};
|
|
455
|
+
for (const [key, value] of Object.entries(process.env)) if (value !== undefined && !PRIVATE_ENV.test(key)) env[key] = value;
|
|
456
|
+
return { ...env, TERM: 'xterm-256color', COLORTERM: 'truecolor', ALP_TERMINAL: '1', ALP_TERMINAL_ID: marker };
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const running = (filter: (terminal: Terminal) => boolean) => [...terminals.values()].filter(terminal => !terminal.exit && filter(terminal)).length;
|
|
460
|
+
|
|
461
|
+
return {
|
|
462
|
+
/** `terminalLimits` for daemon.hello while terminals are served, else undefined. */
|
|
463
|
+
async advertised(): Promise<TerminalLimits | undefined> {
|
|
464
|
+
if (closed || !supported) return undefined;
|
|
465
|
+
const current = await state().catch(() => undefined);
|
|
466
|
+
return current?.enabled && pty() ? current.limits : undefined;
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
async create(principal: TerminalPrincipal, params: { workspaceId: string; cols: number; rows: number; requestId: string }): Promise<{ terminal: TerminalInfo }> {
|
|
470
|
+
const limits = await ready();
|
|
471
|
+
const requestKey = JSON.stringify([principal.id, principal.epoch, params.requestId]);
|
|
472
|
+
let root: string;
|
|
473
|
+
try { root = await resolveWorkspace(params.workspaceId); } catch (error: any) {
|
|
474
|
+
if (typeof error?.code === 'number' && error.code !== ERROR.failed) throw new RpcError(error.code === ERROR.forbidden ? ERROR.forbidden : ERROR.notFound, error.code === ERROR.forbidden ? 'The workspace directory changed' : 'No workspace with this workspaceId', { reason: error.data?.reason ?? 'not_found' });
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
if (!within(principal, root)) throw new RpcError(ERROR.forbidden, 'The workspace is outside this grant', { reason: 'outside_workspace' });
|
|
478
|
+
const file = await shell();
|
|
479
|
+
// From here to the spawn nothing awaits: the requestId, both limits and the new terminal are
|
|
480
|
+
// checked and recorded in one step, so concurrent creates cannot pass the same check.
|
|
481
|
+
if (closed) throw new RpcError(ERROR.unavailable, 'alpd is shutting down', { reason: 'terminal_unsupported' });
|
|
482
|
+
const repeated = terminals.get(requests.get(requestKey) ?? '');
|
|
483
|
+
if (repeated && !repeated.exit) {
|
|
484
|
+
if (repeated.workspaceId !== params.workspaceId) throw new RpcError(ERROR.conflict, 'This requestId created another terminal', { reason: 'request_conflict' });
|
|
485
|
+
return { terminal: info(repeated) };
|
|
486
|
+
}
|
|
487
|
+
if (running(terminal => terminal.principal.id === principal.id) >= limits.maxPerPrincipal) throw new RpcError(ERROR.unavailable, `At most ${limits.maxPerPrincipal} terminals run per principal`, { reason: 'terminal_limit', limit: 'principal' });
|
|
488
|
+
if (running(() => true) >= limits.maxPerDaemon) throw new RpcError(ERROR.unavailable, `At most ${limits.maxPerDaemon} terminals run on this host`, { reason: 'terminal_limit', limit: 'daemon' });
|
|
489
|
+
const at = now();
|
|
490
|
+
const marker = `atm_${randomBytes(16).toString('hex')}`;
|
|
491
|
+
const process_ = pty()!(file, [], { name: 'xterm-256color', cols: params.cols, rows: params.rows, cwd: root, env: environment(marker) });
|
|
492
|
+
const terminal: Terminal = {
|
|
493
|
+
id: `term_${randomBytes(16).toString('hex')}`, principal: { id: principal.id, epoch: principal.epoch }, workspaceId: params.workspaceId,
|
|
494
|
+
root, title: path.basename(file).slice(0, 64), cols: params.cols, rows: params.rows, pty: process_, pid: process_.pid,
|
|
495
|
+
...(typeof process_.ptsName === 'string' && process_.ptsName.startsWith('/dev/') ? { tty: process_.ptsName.slice('/dev/'.length) } : {}),
|
|
496
|
+
createdAt: at, lastActivityAt: at, expiresAt: at + limits.maxLifetimeMs, requestKey, ring: [], ringBytes: 0, nextSeq: 1,
|
|
497
|
+
detachedAt: at, marker, disposables: [],
|
|
498
|
+
};
|
|
499
|
+
terminals.set(terminal.id, terminal);
|
|
500
|
+
requests.set(requestKey, terminal.id);
|
|
501
|
+
terminal.disposables.push(process_.onData(data => output(terminal, data, limits)));
|
|
502
|
+
terminal.disposables.push(process_.onExit(({ exitCode, signal: number }) => exited(terminal, terminal.ending ? null : exitCode, number || null)));
|
|
503
|
+
audit('terminal created', terminal, { code: 'ALPD_TERMINAL_CREATED' });
|
|
504
|
+
return { terminal: info(terminal) };
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
async list(principal: TerminalPrincipal, params: { workspaceId?: string }) {
|
|
508
|
+
if (supported) await state().catch(() => undefined);
|
|
509
|
+
const terminals_ = [...terminals.values()]
|
|
510
|
+
.filter(terminal => terminal.principal.id === principal.id && terminal.principal.epoch === principal.epoch && within(principal, terminal.root) && (params.workspaceId === undefined || terminal.workspaceId === params.workspaceId))
|
|
511
|
+
.sort((a, b) => b.createdAt - a.createdAt || (a.id < b.id ? -1 : 1));
|
|
512
|
+
return { terminals: terminals_.map(info) };
|
|
513
|
+
},
|
|
514
|
+
|
|
515
|
+
async attach(principal: TerminalPrincipal, sink: TerminalSink, params: { terminalId: string; after?: number }) {
|
|
516
|
+
await ready();
|
|
517
|
+
const terminal = own(principal, params.terminalId);
|
|
518
|
+
if (terminal.sink && terminal.sink !== sink) detach(terminal, 'replaced');
|
|
519
|
+
terminal.sink = sink;
|
|
520
|
+
terminal.detachedAt = undefined;
|
|
521
|
+
const after = Math.min(params.after ?? 0, terminal.nextSeq - 1);
|
|
522
|
+
const first = terminal.ring[0]?.seq ?? terminal.nextSeq;
|
|
523
|
+
const lastOutput = terminal.exit ? terminal.exit.seq - 1 : terminal.nextSeq - 1;
|
|
524
|
+
const gap = after + 1 < first && after < lastOutput ? { fromSeq: after + 1, toSeq: Math.min(first, lastOutput + 1) - 1 } : undefined;
|
|
525
|
+
for (const frame of terminal.ring) if (frame.seq > after) sink.send({ jsonrpc: '2.0', method: 'terminal.event', params: { terminalId: terminal.id, type: 'output', seq: frame.seq, data: frame.data } satisfies TerminalEvent });
|
|
526
|
+
if (terminal.exit && terminal.exit.seq > after) sink.send({ jsonrpc: '2.0', method: 'terminal.event', params: { terminalId: terminal.id, type: 'exit', seq: terminal.exit.seq, exitCode: terminal.exit.exitCode, signal: terminal.exit.signal, reason: terminal.exit.reason } satisfies TerminalEvent });
|
|
527
|
+
audit('terminal attached', terminal, { code: 'ALPD_TERMINAL_ATTACHED', after, ...(gap ? { gap: gap.toSeq - gap.fromSeq + 1 } : {}) });
|
|
528
|
+
return { terminal: info(terminal), nextSeq: terminal.nextSeq, ...(gap ? { gap } : {}) };
|
|
529
|
+
},
|
|
530
|
+
|
|
531
|
+
async input(principal: TerminalPrincipal, sink: TerminalSink, params: { terminalId: string; data: string }) {
|
|
532
|
+
const limits = await ready();
|
|
533
|
+
const terminal = own(principal, params.terminalId);
|
|
534
|
+
if (terminal.sink !== sink) throw new RpcError(ERROR.conflict, 'Attach the terminal on this connection first', { reason: 'not_attached' });
|
|
535
|
+
if (terminal.exit || terminal.ending) throw new RpcError(ERROR.conflict, 'The terminal has ended', { reason: 'terminal_exited' });
|
|
536
|
+
const bytes = Buffer.byteLength(params.data);
|
|
537
|
+
if (bytes > limits.maxInputBytes) throw new RpcError(RPC_ERROR.invalidParams, `At most ${limits.maxInputBytes} bytes of input at once`, { reason: 'input_too_large' });
|
|
538
|
+
terminal.pty.write(params.data);
|
|
539
|
+
terminal.lastActivityAt = now();
|
|
540
|
+
return { bytes };
|
|
541
|
+
},
|
|
542
|
+
|
|
543
|
+
async resize(principal: TerminalPrincipal, sink: TerminalSink, params: { terminalId: string; cols: number; rows: number }) {
|
|
544
|
+
await ready();
|
|
545
|
+
const terminal = own(principal, params.terminalId);
|
|
546
|
+
if (terminal.sink !== sink) throw new RpcError(ERROR.conflict, 'Attach the terminal on this connection first', { reason: 'not_attached' });
|
|
547
|
+
if (terminal.exit || terminal.ending) throw new RpcError(ERROR.conflict, 'The terminal has ended', { reason: 'terminal_exited' });
|
|
548
|
+
terminal.pty.resize(params.cols, params.rows);
|
|
549
|
+
terminal.cols = params.cols;
|
|
550
|
+
terminal.rows = params.rows;
|
|
551
|
+
return { cols: terminal.cols, rows: terminal.rows };
|
|
552
|
+
},
|
|
553
|
+
|
|
554
|
+
async close(principal: TerminalPrincipal, params: { terminalId: string }) {
|
|
555
|
+
const terminal = own(principal, params.terminalId);
|
|
556
|
+
if (terminal.exit) { terminals.delete(terminal.id); return { closed: true as const }; }
|
|
557
|
+
await end(terminal, 'closed');
|
|
558
|
+
terminals.delete(terminal.id);
|
|
559
|
+
return { closed: true as const };
|
|
560
|
+
},
|
|
561
|
+
|
|
562
|
+
/** Every terminal of a principal, any epoch: a gateway's revocation. */
|
|
563
|
+
async revoke(principalId: string) {
|
|
564
|
+
const mine = [...terminals.values()].filter(terminal => terminal.principal.id === principalId);
|
|
565
|
+
const live = mine.filter(terminal => !terminal.exit);
|
|
566
|
+
await Promise.all(live.map(terminal => end(terminal, 'revoked')));
|
|
567
|
+
for (const terminal of mine) terminals.delete(terminal.id);
|
|
568
|
+
if (mine.length) log.info('revoked the terminals of a principal', { code: 'ALPD_TERMINAL_REVOKED', principal: principalId, closed: live.length });
|
|
569
|
+
return { closed: live.length };
|
|
570
|
+
},
|
|
571
|
+
|
|
572
|
+
/** A connection closed: its terminals keep running for reconnectMs. */
|
|
573
|
+
disconnect(sink: TerminalSink) {
|
|
574
|
+
for (const terminal of terminals.values()) if (terminal.sink === sink) detach(terminal, 'disconnected');
|
|
575
|
+
},
|
|
576
|
+
|
|
577
|
+
sweep,
|
|
578
|
+
|
|
579
|
+
/** alpd stops: every terminal ends (reason `shutdown`) and its tree is killed. */
|
|
580
|
+
async shutdown() {
|
|
581
|
+
closed = true;
|
|
582
|
+
clearInterval(timer);
|
|
583
|
+
await Promise.all([...terminals.values()].map(terminal => terminal.exit ? terminal.reaped : end(terminal, 'shutdown')));
|
|
584
|
+
terminals.clear();
|
|
585
|
+
},
|
|
586
|
+
|
|
587
|
+
/** Test hook: pids of every running terminal's shell. */
|
|
588
|
+
pids() { return [...terminals.values()].filter(terminal => !terminal.exit).map(terminal => terminal.pid); },
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
export type TerminalService = ReturnType<typeof createTerminalService>;
|