src/vs/platform/agentHost/node/agentHostHeadlessTerminal.ts
145 LOC · 144 covered · 1 uncovered · 36 ranges · 2246 concepts · 14 introducers · 1048 tests
File neighbourhood
The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.
Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file
In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.
Graph controls are ready.
Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.
/*---------------------------------------------------------------------------------------------
agentHostHeadlessTerminal.ts ×11
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Emitter, Event } from '../../../base/common/event.js';
import { DeferredPromise } from '../../../base/common/async.js';
import { Disposable, DisposableStore } from '../../../base/common/lifecycle.js';
import type { ILogService } from '../../log/common/log.js';
import pkg from '@xterm/headless';
type XtermTerminal = pkg.Terminal;
const { Terminal: XtermTerminal } = pkg;
export interface IAgentHostHeadlessTerminalOptions {
cols: number;
rows: number;
scrollback: number;
logService: ILogService;
terminalFactory?: (options: IXtermTerminalOptions) => XtermTerminal;
}
/**
* Mirrors an agent-host PTY into xterm's interpreted terminal model.
*
* The mirror is intentionally internal to the agent host. Protocol-visible
* terminal data still flows through the existing OSC 633 parser and content
* model; this class provides terminal responses for programs that query
* terminal state.
*/
export class AgentHostHeadlessTerminal extends Disposable {
private readonly _terminal: XtermTerminal;
private readonly _logService: ILogService;
private readonly _onResponseData = this._register(new Emitter<string>());
readonly onResponseData: Event<string> = this._onResponseData.event;
private _writeBarrier: Promise<void> = Promise.resolve();
private _isDisposed = false;
constructor(options: IAgentHostHeadlessTerminalOptions) {
this._logService = options.logService;
const terminalOptions: IXtermTerminalOptions = {
cols: options.cols,
rows: options.rows,
scrollback: options.scrollback,
allowProposedApi: true,
};
this._terminal = options.terminalFactory?.(terminalOptions) ?? new XtermTerminal(terminalOptions);
this._register(this._terminal.onData(data => {
this._logService.debug(`[AgentHostHeadlessTerminal] Forwarding terminal response ${JSON.stringify(data)}`);
agentHostHeadlessTerminal.ts ×1
this._onResponseData.fire(data);
this._logService.debug(`[AgentHostHeadlessTerminal] Dropping terminal response ${JSON.stringify(data)}`);
agentHostHeadlessTerminal.ts ×1
}
this._register({
dispose: () => {
this._isDisposed = true;
this._terminal.dispose();
}
});
}
writePtyData(data: string): Promise<void> {
this._writeBarrier = this._writeBarrier.catch(() => undefined).then(() => {
agentHostHeadlessTerminal.ts ×5
if (this._isDisposed) {
}
try {
this._terminal.write(data, resolve);
} catch {
}
return this._writeBarrier;
}
whenPtyDataFlushed(): Promise<void> {
}
resize(cols: number, rows: number): void {
}
isBracketedPasteMode(): boolean {
}
isInAltBuffer(): boolean {
return this._terminal.buffer.active === this._terminal.buffer.alternate;
agentHostHeadlessTerminal.ts ×5
}
createAltBufferPromise(store: DisposableStore): Promise<void> {
const complete = () => {
this._logService.debug('[AgentHostHeadlessTerminal] Detected alternate buffer entry');
deferred.complete();
}
};
if (this.isInAltBuffer()) {
complete();
store.add(this._terminal.buffer.onBufferChange(() => {
complete();
}
}
return deferred.p;
}
clear(): void {
// xterm.clear() preserves the visible line content; emulate a terminal
agentHostHeadlessTerminal.ts ×1
// clear sequence so future terminal-state reads match a user-visible clear.
void this.writePtyData('\x1b[2J\x1b[3J\x1b[H');
}
override dispose(): void {
super.dispose();
}
private _isCursorPositionReportResponse(data: string): boolean {
// Only forward cursor position reports for now. xterm can also answer
agentHostHeadlessTerminal.ts ×3
// device attribute queries, but workbench only forwards those in narrow
// ConPTY-specific cases; keep Agent Host conservative until needed.
return /^(?:\x1b\[\??\d+;\d+R)+$/.test(data);
}
interface IXtermTerminalOptions {
cols: number;
rows: number;
scrollback: number;
allowProposedApi: boolean;
}