ds-harness-remote 0.5.7 → 0.5.8

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.
Files changed (49) hide show
  1. package/dist/acp/adapters/antigravity/transcript-loader.d.ts.map +1 -1
  2. package/dist/acp/adapters/antigravity/transcript-loader.js +4 -1
  3. package/dist/acp/adapters/antigravity/transcript-loader.js.map +1 -1
  4. package/dist/acp/gateway.d.ts +2 -0
  5. package/dist/acp/gateway.d.ts.map +1 -1
  6. package/dist/acp/gateway.js +46 -37
  7. package/dist/acp/gateway.js.map +1 -1
  8. package/dist/acp/workspace-tools.js +1 -1
  9. package/dist/acp/workspace-tools.js.map +1 -1
  10. package/dist/client.github.js +1 -1
  11. package/dist/client.js +1 -1
  12. package/dist/client.js.map +1 -1
  13. package/dist/harness-remote-bridge.js +2 -2
  14. package/dist/harness-remote-bridge.js.map +1 -1
  15. package/dist/index.js +6205 -399
  16. package/dist/index.js.map +4 -4
  17. package/dist/remote-terminal-controller.d.ts +90 -0
  18. package/dist/remote-terminal-controller.d.ts.map +1 -0
  19. package/dist/remote-terminal-controller.js +494 -0
  20. package/dist/remote-terminal-controller.js.map +1 -0
  21. package/dist/remote-terminal-provider.d.ts +46 -0
  22. package/dist/remote-terminal-provider.d.ts.map +1 -0
  23. package/dist/remote-terminal-provider.js +147 -0
  24. package/dist/remote-terminal-provider.js.map +1 -0
  25. package/dist/server-api.d.ts +3 -0
  26. package/dist/server-api.d.ts.map +1 -1
  27. package/dist/server-api.js +24 -9
  28. package/dist/server-api.js.map +1 -1
  29. package/dist/server-connection.d.ts.map +1 -1
  30. package/dist/server-connection.js +2 -0
  31. package/dist/server-connection.js.map +1 -1
  32. package/dist/service.d.ts.map +1 -1
  33. package/dist/service.js +9 -3
  34. package/dist/service.js.map +1 -1
  35. package/dist/terminal-policy.d.ts +6 -0
  36. package/dist/terminal-policy.d.ts.map +1 -1
  37. package/dist/terminal-policy.js +24 -6
  38. package/dist/terminal-policy.js.map +1 -1
  39. package/dist/typert-gateway-switch.d.ts.map +1 -1
  40. package/dist/typert-gateway-switch.js +8 -3
  41. package/dist/typert-gateway-switch.js.map +1 -1
  42. package/dist/version.d.ts +1 -1
  43. package/dist/version.js +1 -1
  44. package/dist/workspace-bridge.d.ts +6 -89
  45. package/dist/workspace-bridge.d.ts.map +1 -1
  46. package/dist/workspace-bridge.js +37 -294
  47. package/dist/workspace-bridge.js.map +1 -1
  48. package/dsh-plugin.json +1 -1
  49. package/package.json +4 -2
@@ -0,0 +1,90 @@
1
+ import type { Terminal } from '@xterm/headless';
2
+ import { RpcError } from './safe-error.js';
3
+ import type { TypertRpcResult } from './typert-gateway-contract.js';
4
+ import { type RemoteTerminalProcess, type RemoteTerminalSpawner, type TerminalShell } from './remote-terminal-provider.js';
5
+ type Frame = Record<string, unknown>;
6
+ type ScopeError = (code: string, message: string) => RpcError;
7
+ /** Slow followers fail; detaching never keeps an unbounded output journal. */
8
+ declare class TerminalFollower implements AsyncIterable<Frame> {
9
+ private readonly detach;
10
+ private values;
11
+ private bytes;
12
+ private wake?;
13
+ private finished;
14
+ private closed;
15
+ private failure?;
16
+ constructor(detach: () => void);
17
+ push(value: Frame): void;
18
+ finish(): void;
19
+ close(): void;
20
+ [Symbol.asyncIterator](): AsyncIterator<Frame>;
21
+ }
22
+ /** One Host-owned terminal. All screen/output/input transitions are serialized. */
23
+ declare class OwnedTerminal {
24
+ readonly sessionId: string;
25
+ readonly id: string;
26
+ readonly cwd: string;
27
+ cols: number;
28
+ rows: number;
29
+ private readonly removed;
30
+ readonly allocation: AbortController;
31
+ readonly screen: Terminal;
32
+ private readonly serializer;
33
+ readonly followers: Set<TerminalFollower>;
34
+ readonly holders: Set<TerminalFollower>;
35
+ pending?: Promise<void>;
36
+ process?: RemoteTerminalProcess;
37
+ shell?: TerminalShell;
38
+ title: string;
39
+ controller?: TerminalFollower;
40
+ controllerId?: string;
41
+ sequence: number;
42
+ state: 'running' | 'exited' | 'failed';
43
+ exitCode: number | null;
44
+ error?: string;
45
+ closing: boolean;
46
+ private disposed;
47
+ private operations;
48
+ private cleanup?;
49
+ private timer?;
50
+ private idle?;
51
+ private activityEpoch;
52
+ constructor(sessionId: string, id: string, cwd: string, cols: number, rows: number, removed: () => void);
53
+ info(): Frame;
54
+ enqueue<T>(operation: () => T | Promise<T>): Promise<T>;
55
+ emit(value: Frame): void;
56
+ invalidate(): void;
57
+ pump(): Promise<void>;
58
+ snapshot(): string;
59
+ monitor(): void;
60
+ private observe;
61
+ /** Failed cleanup remains owned and closed to input, allowing a later retry. */
62
+ close(): Promise<void>;
63
+ }
64
+ /** Shared across encrypted connections; backend disposal also fences pending creations. */
65
+ export declare class RemoteTerminalState {
66
+ readonly onRemoved: (key: string) => void;
67
+ readonly terminals: Map<string, OwnedTerminal>;
68
+ revision: number;
69
+ constructor(onRemoved?: (key: string) => void);
70
+ dispose(matches?: (sessionId: string) => boolean): Promise<void>;
71
+ }
72
+ /** Official terminal shapes over backend-owned IDs, without creating Harness Agents. */
73
+ export declare class RemoteTerminalController {
74
+ private readonly shared;
75
+ private readonly spawn;
76
+ private readonly enabled;
77
+ private readonly scopeError;
78
+ private readonly subscriptions;
79
+ constructor(shared: RemoteTerminalState, spawn: RemoteTerminalSpawner, enabled: () => boolean, scopeError: ScopeError);
80
+ call(endpoint: string, sessionId: string, cwd: string, args: Record<string, unknown>, signal: AbortSignal): Promise<TypertRpcResult>;
81
+ open(endpoint: string, sessionId: string, args: Record<string, unknown>, signal: AbortSignal): Promise<AsyncIterable<Frame>>;
82
+ /** A connection only disposes its subscriptions; the Host still owns the shells. */
83
+ closeAll(): void;
84
+ private shells;
85
+ private create;
86
+ private check;
87
+ private requireTerminal;
88
+ }
89
+ export {};
90
+ //# sourceMappingURL=remote-terminal-controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-terminal-controller.d.ts","sourceRoot":"","sources":["../src/remote-terminal-controller.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK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m/headless';
2
+ import serialize from '@xterm/addon-serialize';
3
+ import { RpcError } from './safe-error.js';
4
+ import { discoverTerminalShells } from './remote-terminal-provider.js';
5
+ const MAX_INPUT_BYTES = 64 * 1024;
6
+ const MAX_COLS = 240;
7
+ const MAX_ROWS = 100;
8
+ const MAX_TERMINALS = 256;
9
+ const MAX_SESSION_TERMINALS = 8;
10
+ const SCROLLBACK = 1000;
11
+ const MAX_SNAPSHOT_BYTES = 256 * 1024;
12
+ const MAX_FOLLOWER_BYTES = 1024 * 1024;
13
+ const IDLE_TIMEOUT_MS = 2 * 60 * 60 * 1000;
14
+ const POLL_MS = 30_000;
15
+ /** Slow followers fail; detaching never keeps an unbounded output journal. */
16
+ class TerminalFollower {
17
+ detach;
18
+ values = [];
19
+ bytes = 0;
20
+ wake;
21
+ finished = false;
22
+ closed = false;
23
+ failure;
24
+ constructor(detach) {
25
+ this.detach = detach;
26
+ }
27
+ push(value) {
28
+ if (this.closed || this.finished)
29
+ return;
30
+ const bytes = Buffer.byteLength(JSON.stringify(value));
31
+ if (this.bytes + bytes > MAX_FOLLOWER_BYTES) {
32
+ this.failure = new RpcError('TERMINAL_BUFFER_EXCEEDED', 'Terminal output fell behind. Reconnect to recover the screen.');
33
+ this.close();
34
+ return;
35
+ }
36
+ this.bytes += bytes;
37
+ this.values.push({ value, bytes });
38
+ this.wake?.();
39
+ }
40
+ finish() { this.finished = true; this.wake?.(); }
41
+ close() {
42
+ if (this.closed)
43
+ return;
44
+ this.closed = true;
45
+ this.values = [];
46
+ this.bytes = 0;
47
+ this.detach();
48
+ this.wake?.();
49
+ }
50
+ async *[Symbol.asyncIterator]() {
51
+ try {
52
+ while (!this.closed) {
53
+ const next = this.values.shift();
54
+ if (next) {
55
+ this.bytes -= next.bytes;
56
+ yield next.value;
57
+ }
58
+ else if (this.finished)
59
+ break;
60
+ else
61
+ await new Promise(resolve => { this.wake = resolve; });
62
+ }
63
+ if (this.failure)
64
+ throw this.failure;
65
+ }
66
+ finally {
67
+ this.close();
68
+ }
69
+ }
70
+ }
71
+ /** One Host-owned terminal. All screen/output/input transitions are serialized. */
72
+ class OwnedTerminal {
73
+ sessionId;
74
+ id;
75
+ cwd;
76
+ cols;
77
+ rows;
78
+ removed;
79
+ allocation = new AbortController();
80
+ screen;
81
+ serializer = new serialize.SerializeAddon();
82
+ followers = new Set();
83
+ holders = new Set();
84
+ pending;
85
+ process;
86
+ shell;
87
+ title = '';
88
+ controller;
89
+ controllerId;
90
+ sequence = 0;
91
+ state = 'running';
92
+ exitCode = null;
93
+ error;
94
+ closing = false;
95
+ disposed = false;
96
+ operations = Promise.resolve();
97
+ cleanup;
98
+ timer;
99
+ idle;
100
+ activityEpoch = 0;
101
+ constructor(sessionId, id, cwd, cols, rows, removed) {
102
+ this.sessionId = sessionId;
103
+ this.id = id;
104
+ this.cwd = cwd;
105
+ this.cols = cols;
106
+ this.rows = rows;
107
+ this.removed = removed;
108
+ this.screen = new headless.Terminal({ cols, rows, scrollback: SCROLLBACK, allowProposedApi: true });
109
+ this.screen.loadAddon(this.serializer);
110
+ }
111
+ info() {
112
+ return { id: this.id, title: this.title, shell: this.shell && { ...this.shell, args: [...this.shell.args] },
113
+ cwd: this.cwd, cols: this.cols, rows: this.rows, state: this.state, exitCode: this.exitCode,
114
+ ...(this.error === undefined ? {} : { error: this.error }),
115
+ ...(this.controllerId === undefined ? {} : { controllerId: this.controllerId }) };
116
+ }
117
+ enqueue(operation) {
118
+ const result = this.operations.then(operation);
119
+ this.operations = result.then(() => undefined, () => undefined);
120
+ return result;
121
+ }
122
+ emit(value) { for (const follower of this.followers)
123
+ follower.push(value); }
124
+ invalidate() { this.activityEpoch++; this.idle = undefined; }
125
+ async pump() {
126
+ const process = this.process;
127
+ // Register the rejection handler immediately, even while output is still open.
128
+ const outcome = process.completed.then(value => ({ value }), () => ({ value: undefined }));
129
+ let failed = false;
130
+ try {
131
+ for await (const chunk of process.output) {
132
+ // Bound each wire frame and preserve UTF-16 surrogate pairs across splits.
133
+ for (let start = 0; start < chunk.length;) {
134
+ let end = Math.min(start + 16_384, chunk.length);
135
+ if (end < chunk.length && /[\uD800-\uDBFF]/u.test(chunk[end - 1]))
136
+ end--;
137
+ const data = chunk.slice(start, end);
138
+ start = end;
139
+ await this.enqueue(async () => {
140
+ if (this.disposed)
141
+ return;
142
+ await new Promise(resolve => this.screen.write(data, resolve));
143
+ this.sequence++;
144
+ this.emit({ type: 'output', sequence: this.sequence, data });
145
+ });
146
+ }
147
+ }
148
+ }
149
+ catch {
150
+ failed = true;
151
+ }
152
+ if (failed) {
153
+ await this.enqueue(() => {
154
+ if (this.disposed)
155
+ return;
156
+ this.state = 'failed';
157
+ this.error = 'The terminal output stream failed.';
158
+ this.emit({ type: 'state', info: this.info() });
159
+ });
160
+ await this.close().catch(() => undefined);
161
+ return;
162
+ }
163
+ const ended = await outcome;
164
+ await this.enqueue(() => {
165
+ if (this.disposed)
166
+ return;
167
+ this.exitCode = ended.value?.exitCode ?? null;
168
+ if (failed || ended.value === undefined) {
169
+ this.state = 'failed';
170
+ this.error = 'The terminal process or output stream failed.';
171
+ }
172
+ else
173
+ this.state = 'exited';
174
+ this.emit({ type: 'state', info: this.info() });
175
+ for (const follower of this.followers)
176
+ follower.finish();
177
+ });
178
+ }
179
+ snapshot() {
180
+ let lines = SCROLLBACK;
181
+ let screen = this.serializer.serialize({ scrollback: lines });
182
+ while (Buffer.byteLength(screen) > MAX_SNAPSHOT_BYTES && lines > 0) {
183
+ lines = Math.floor(lines / 2);
184
+ screen = this.serializer.serialize({ scrollback: lines });
185
+ }
186
+ if (Buffer.byteLength(screen) > MAX_SNAPSHOT_BYTES)
187
+ throw new RpcError('TERMINAL_BUFFER_EXCEEDED', 'The terminal screen exceeds the recovery limit.');
188
+ return screen;
189
+ }
190
+ monitor() {
191
+ if (this.timer || this.disposed || (!this.closing && !this.process?.inspectActivity))
192
+ return;
193
+ this.timer = setTimeout(() => {
194
+ this.timer = undefined;
195
+ void this.observe().finally(() => this.monitor());
196
+ }, POLL_MS);
197
+ this.timer.unref();
198
+ }
199
+ async observe() {
200
+ if (this.closing) {
201
+ await this.close().catch(() => undefined);
202
+ return;
203
+ }
204
+ if (this.holders.size || this.followers.size) {
205
+ this.invalidate();
206
+ return;
207
+ }
208
+ const epoch = this.activityEpoch;
209
+ try {
210
+ const activity = await this.process.inspectActivity();
211
+ if (this.disposed || epoch !== this.activityEpoch)
212
+ return;
213
+ if (activity.state !== 'idle') {
214
+ this.idle = undefined;
215
+ return;
216
+ }
217
+ const now = performance.now();
218
+ if (this.idle?.revision !== activity.revision || now - this.idle.observedAt > POLL_MS * 2)
219
+ this.idle = { since: now, revision: activity.revision, observedAt: now };
220
+ else {
221
+ this.idle.observedAt = now;
222
+ if (now - this.idle.since >= IDLE_TIMEOUT_MS)
223
+ await this.close();
224
+ }
225
+ }
226
+ catch {
227
+ this.idle = undefined;
228
+ }
229
+ }
230
+ /** Failed cleanup remains owned and closed to input, allowing a later retry. */
231
+ close() {
232
+ if (this.cleanup)
233
+ return this.cleanup;
234
+ this.closing = true;
235
+ this.invalidate();
236
+ this.allocation.abort();
237
+ this.cleanup = (async () => {
238
+ await this.pending?.catch(() => undefined);
239
+ await this.process?.terminate();
240
+ await this.enqueue(() => {
241
+ if (this.disposed)
242
+ return;
243
+ this.disposed = true;
244
+ if (this.timer)
245
+ clearTimeout(this.timer);
246
+ this.state = 'exited';
247
+ this.emit({ type: 'state', info: this.info() });
248
+ for (const follower of [...this.followers, ...this.holders])
249
+ follower.finish();
250
+ this.screen.dispose();
251
+ this.removed();
252
+ });
253
+ })().catch(() => {
254
+ this.cleanup = undefined;
255
+ this.state = 'failed';
256
+ this.error = 'Terminal cleanup failed. Close the terminal again to retry.';
257
+ this.emit({ type: 'state', info: this.info() });
258
+ this.monitor();
259
+ throw new RpcError('TERMINAL_CLEANUP_FAILED', 'The terminal process could not be fully stopped. Retry closing it.');
260
+ });
261
+ return this.cleanup;
262
+ }
263
+ }
264
+ /** Shared across encrypted connections; backend disposal also fences pending creations. */
265
+ export class RemoteTerminalState {
266
+ onRemoved;
267
+ terminals = new Map();
268
+ revision = 0;
269
+ constructor(onRemoved = () => { }) {
270
+ this.onRemoved = onRemoved;
271
+ }
272
+ async dispose(matches = () => true) {
273
+ this.revision++;
274
+ const results = await Promise.allSettled([...this.terminals.values()].filter(terminal => matches(terminal.sessionId)).map(terminal => terminal.close()));
275
+ if (results.some(result => result.status === 'rejected'))
276
+ throw new RpcError('TERMINAL_CLEANUP_FAILED', 'Some terminal processes could not be stopped. Retry cleanup.');
277
+ }
278
+ }
279
+ /** Official terminal shapes over backend-owned IDs, without creating Harness Agents. */
280
+ export class RemoteTerminalController {
281
+ shared;
282
+ spawn;
283
+ enabled;
284
+ scopeError;
285
+ subscriptions = new Set();
286
+ constructor(shared, spawn, enabled, scopeError) {
287
+ this.shared = shared;
288
+ this.spawn = spawn;
289
+ this.enabled = enabled;
290
+ this.scopeError = scopeError;
291
+ }
292
+ async call(endpoint, sessionId, cwd, args, signal) {
293
+ this.check(signal);
294
+ if (endpoint === 'terminal/environment')
295
+ return { ok: true, value: { cwd, maxInputBytes: MAX_INPUT_BYTES, maxCols: MAX_COLS, maxRows: MAX_ROWS, scrollback: SCROLLBACK } };
296
+ if (endpoint === 'terminal/shells')
297
+ return { ok: true, value: await this.shells(signal) };
298
+ if (endpoint === 'terminal/list')
299
+ return { ok: true, value: [...this.shared.terminals.values()].filter(item => item.sessionId === sessionId && item.shell && item.process).map(item => item.info()) };
300
+ if (endpoint === 'terminal/create')
301
+ return { ok: true, value: await this.create(sessionId, cwd, args, signal) };
302
+ const id = identifier(args.id);
303
+ if (endpoint === 'terminal/close') {
304
+ await this.shared.terminals.get(`${sessionId}/${id}`)?.close();
305
+ return { ok: true };
306
+ }
307
+ const terminal = this.requireTerminal(sessionId, id);
308
+ await terminal.enqueue(async () => {
309
+ this.check(signal);
310
+ if (terminal.closing)
311
+ throw this.scopeError('TERMINAL_NOT_FOUND', 'The terminal is closing.');
312
+ if (endpoint === 'terminal/rename') {
313
+ if (typeof args.title !== 'string' || !args.title.trim() || args.title.length > 120)
314
+ throw new RpcError('INVALID_MESSAGE', 'The terminal title is invalid.');
315
+ terminal.title = args.title.trim();
316
+ terminal.emit({ type: 'state', info: terminal.info() });
317
+ return;
318
+ }
319
+ if (endpoint !== 'terminal/write' && endpoint !== 'terminal/resize')
320
+ throw new RpcError('METHOD_NOT_FOUND', 'The terminal method does not exist.');
321
+ if (identifier(args.attachmentId) !== terminal.controllerId || !terminal.controller
322
+ || !this.subscriptions.has(terminal.controller) || terminal.state !== 'running')
323
+ throw new RpcError('PERMISSION_DENIED', 'This attachment does not own terminal input.');
324
+ terminal.invalidate();
325
+ if (endpoint === 'terminal/write') {
326
+ if (typeof args.data !== 'string' || Buffer.byteLength(args.data) > MAX_INPUT_BYTES)
327
+ throw new RpcError('INVALID_MESSAGE', 'Terminal input is invalid or too large.');
328
+ await terminal.process.write(args.data);
329
+ }
330
+ else {
331
+ const cols = dimension(args.cols, MAX_COLS), rows = dimension(args.rows, MAX_ROWS);
332
+ await terminal.process.resize(cols, rows);
333
+ terminal.screen.resize(cols, rows);
334
+ terminal.cols = cols;
335
+ terminal.rows = rows;
336
+ terminal.emit({ type: 'state', info: terminal.info() });
337
+ }
338
+ });
339
+ return { ok: true };
340
+ }
341
+ async open(endpoint, sessionId, args, signal) {
342
+ this.check(signal);
343
+ const terminal = this.requireTerminal(sessionId, identifier(args.id));
344
+ let follower;
345
+ const abort = () => follower.close();
346
+ follower = new TerminalFollower(() => {
347
+ signal.removeEventListener('abort', abort);
348
+ this.subscriptions.delete(follower);
349
+ terminal.followers.delete(follower);
350
+ terminal.holders.delete(follower);
351
+ terminal.invalidate();
352
+ if (terminal.controller === follower) {
353
+ terminal.controller = undefined;
354
+ terminal.controllerId = undefined;
355
+ terminal.emit({ type: 'state', info: terminal.info() });
356
+ }
357
+ });
358
+ // Register before awaiting the serialized snapshot, so disconnect can also
359
+ // revoke a follower whose open request has not returned yet.
360
+ this.subscriptions.add(follower);
361
+ signal.addEventListener('abort', abort, { once: true });
362
+ if (signal.aborted)
363
+ abort();
364
+ try {
365
+ if (endpoint === 'terminal/retain') {
366
+ terminal.invalidate();
367
+ terminal.holders.add(follower);
368
+ follower.push({ type: 'retained' });
369
+ }
370
+ else if (endpoint === 'terminal/follow') {
371
+ const attachmentId = identifier(args.attachmentId);
372
+ await terminal.enqueue(() => {
373
+ this.check(signal);
374
+ if (!this.subscriptions.has(follower))
375
+ throw new RpcError('TRANSPORT_CLOSED', 'The terminal attachment was disconnected.');
376
+ if (terminal.closing)
377
+ throw this.scopeError('TERMINAL_NOT_FOUND', 'The terminal is closing.');
378
+ const screen = terminal.snapshot();
379
+ terminal.invalidate();
380
+ terminal.controller = follower;
381
+ terminal.controllerId = attachmentId;
382
+ terminal.emit({ type: 'state', info: terminal.info() });
383
+ follower.push({ type: 'snapshot', sequence: terminal.sequence, screen, info: terminal.info() });
384
+ terminal.followers.add(follower);
385
+ if (terminal.state !== 'running')
386
+ follower.finish();
387
+ });
388
+ }
389
+ else
390
+ throw new RpcError('METHOD_NOT_FOUND', 'The terminal stream does not exist.');
391
+ this.check(signal);
392
+ if (!this.subscriptions.has(follower))
393
+ throw new RpcError('TRANSPORT_CLOSED', 'The terminal attachment was disconnected.');
394
+ return follower;
395
+ }
396
+ catch (error) {
397
+ follower.close();
398
+ throw error;
399
+ }
400
+ }
401
+ /** A connection only disposes its subscriptions; the Host still owns the shells. */
402
+ closeAll() { for (const subscription of [...this.subscriptions])
403
+ subscription.close(); }
404
+ async shells(signal) {
405
+ try {
406
+ const result = await (this.spawn.shells?.(signal) ?? discoverTerminalShells(undefined, signal));
407
+ this.check(signal);
408
+ if (!result.length)
409
+ throw new Error();
410
+ return result;
411
+ }
412
+ catch (error) {
413
+ if (signal.aborted)
414
+ throw error;
415
+ if (error instanceof RpcError && error.code === 'TERMINAL_DISABLED')
416
+ throw error;
417
+ throw this.scopeError('TERMINAL_UNAVAILABLE', 'The Host terminal shells could not be discovered.');
418
+ }
419
+ }
420
+ async create(sessionId, cwd, args, signal) {
421
+ const request = typeof args.request === 'object' && args.request !== null ? args.request : {};
422
+ const id = identifier(request.id), key = `${sessionId}/${id}`;
423
+ const existing = this.shared.terminals.get(key);
424
+ if (existing) {
425
+ if (existing.closing)
426
+ throw this.scopeError('TERMINAL_NOT_FOUND', 'The terminal is closing.');
427
+ await existing.pending;
428
+ this.check(signal);
429
+ if (existing.closing)
430
+ throw this.scopeError('TERMINAL_NOT_FOUND', 'The terminal is closing.');
431
+ return existing.info();
432
+ }
433
+ if (this.shared.terminals.size >= MAX_TERMINALS || [...this.shared.terminals.values()].filter(item => item.sessionId === sessionId).length >= MAX_SESSION_TERMINALS)
434
+ throw new RpcError('RATE_LIMITED', 'Too many remote terminals are active.');
435
+ const terminal = new OwnedTerminal(sessionId, id, cwd, dimension(request.cols ?? 80, MAX_COLS), dimension(request.rows ?? 24, MAX_ROWS), () => {
436
+ if (this.shared.terminals.get(key) === terminal) {
437
+ this.shared.terminals.delete(key);
438
+ this.shared.onRemoved(key);
439
+ }
440
+ });
441
+ this.shared.terminals.set(key, terminal);
442
+ const allocationSignal = AbortSignal.any([signal, terminal.allocation.signal]);
443
+ terminal.pending = (async () => {
444
+ const shells = await this.shells(allocationSignal);
445
+ const shell = request.shellPath === undefined ? shells[0] : shells.find(shell => shell.path === request.shellPath);
446
+ if (!shell)
447
+ throw new RpcError('INVALID_MESSAGE', 'The requested shell is not available for this workspace.');
448
+ terminal.shell = shell;
449
+ terminal.title = shell.name;
450
+ terminal.process = await this.spawn({ argv: [shell.path, ...shell.args], cwd,
451
+ cols: terminal.cols, rows: terminal.rows, terminalType: 'xterm-256color', env: { DSH_SESSION_ID: sessionId }, signal: allocationSignal });
452
+ this.check(allocationSignal);
453
+ void terminal.pump();
454
+ terminal.monitor();
455
+ })();
456
+ try {
457
+ await terminal.pending;
458
+ // pending resolves only after allocation has been checked and committed.
459
+ // Returning failure for later request cancellation would also release
460
+ // its device claim while the committed shell is still alive.
461
+ if (terminal.closing)
462
+ throw this.scopeError('TERMINAL_NOT_FOUND', 'The terminal is closing.');
463
+ return terminal.info();
464
+ }
465
+ catch (error) {
466
+ await terminal.close();
467
+ if (error instanceof RpcError || signal.aborted)
468
+ throw error;
469
+ throw this.scopeError('TERMINAL_UNAVAILABLE', 'The Host terminal could not be started.');
470
+ }
471
+ }
472
+ check(signal) {
473
+ signal.throwIfAborted();
474
+ if (!this.enabled())
475
+ throw new RpcError('TERMINAL_DISABLED', 'Remote terminal is disabled on this Host.');
476
+ }
477
+ requireTerminal(sessionId, id) {
478
+ const terminal = this.shared.terminals.get(`${sessionId}/${id}`);
479
+ if (!terminal?.process || terminal.closing)
480
+ throw this.scopeError('TERMINAL_NOT_FOUND', 'The terminal is no longer available.');
481
+ return terminal;
482
+ }
483
+ }
484
+ function identifier(value) {
485
+ if (typeof value !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/u.test(value))
486
+ throw new RpcError('INVALID_MESSAGE', 'The terminal identifier is invalid.');
487
+ return value;
488
+ }
489
+ function dimension(value, max) {
490
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 1 || value > max)
491
+ throw new RpcError('INVALID_MESSAGE', 'Terminal dimensions exceed the allowed limits.');
492
+ return value;
493
+ }
494
+ //# sourceMappingURL=remote-terminal-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-terminal-controller.js","sourceRoot":"","sources":["../src/remote-terminal-controller.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,iBAAiB,CAAA;AACtC,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE1C,OAAO,EAAE,sBAAsB,EAA8E,MAAM,+BAA+B,CAAA;AAElJ,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAA;AACjC,MAAM,QAAQ,GAAG,GAAG,CAAA;AACpB,MAAM,QAAQ,GAAG,GAAG,CA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