Skip to content

Interface: TerminalHarness

@termwright/driver


@termwright/driver / TerminalHarness

Defined in: driver/src/api.ts:172

@termwright/driver — PTY + VT sessions, locators, actions and waits.

The normative public API lives in api.ts; this module is the only entry point and re-exports the types from there together with their runtime implementations.

import { launchTerminal } from '@termwright/driver';
const terminal = await launchTerminal({ command: ['node', 'app.js'] });
await terminal.waitForText('Ready');
await terminal.getByRole('button', { name: 'Approve' }).activate();
await terminal.close();

readonly artifactSecurity: ResolvedArtifactSecurityPolicy

Defined in: driver/src/api.ts:175

Resolved policy inherited by traces, reports and other artifact sinks.


readonly events: SessionEvents

Defined in: driver/src/api.ts:259


readonly exit: Promise<ExitStatus>

Defined in: driver/src/api.ts:290


readonly keyboard: Keyboard

Defined in: driver/src/api.ts:181

One physical keyboard implementation. Convenience methods delegate here.


readonly mouse: Mouse

Defined in: driver/src/api.ts:183

One physical mouse implementation. Locator actions delegate here after planning.


readonly scrollback: ScrollbackApi

Defined in: driver/src/api.ts:255


readonly selection: SelectionApi

Defined in: driver/src/api.ts:256


readonly sessionId: string

Defined in: driver/src/api.ts:173


readonly shell: ShellApi

Defined in: driver/src/api.ts:179

Shell command boundaries and prompt state when the child emits OSC 133.


readonly terminalProfile: TerminalProfileId

Defined in: driver/src/api.ts:177

Immutable terminal profile used to decode the very first PTY byte.


readonly terminalState: TerminalState

Defined in: driver/src/api.ts:187

Emulator facts captured together at the current screen revision.


readonly window: TerminalWindow

Defined in: driver/src/api.ts:185

Terminal-window focus reports, distinct from semantic element focus.

appLogs(): readonly AppLogEvent[]

Defined in: driver/src/api.ts:273

Bounded, oldest-first application-log history, including entries emitted while launchTerminal() was still starting. Consumers should subscribe to app-log first and then seed from this snapshot to avoid a startup gap.

readonly AppLogEvent[]


optional bindOperationBudget(budget): void

Defined in: driver/src/api.ts:189

Binds one attempt-wide budget before any user operation starts.

OperationBudget

void


cell(pos): CellSnapshot

Defined in: driver/src/api.ts:213

number

number

CellSnapshot


checkpoint(): ObservationStamp

Defined in: driver/src/api.ts:194

Atomic identity of the currently committed terminal/semantic observation.

ObservationStamp


close(): Promise<void>

Defined in: driver/src/api.ts:289

Idempotent; bounded physical cleanup. Never sends signals implicitly.

Promise<void>


contract(): EffectiveSessionContract | null

Defined in: driver/src/api.ts:192

Frozen negotiated contract, or null until negotiation has completed.

EffectiveSessionContract | null


crashReport(): CrashReport | null

Defined in: driver/src/api.ts:280

What the session knew when the program died unexpectedly, or null — for a live session, a clean exit, or one the harness asked for via close() or signal(). Available as soon as the exit event fires.

CrashReport | null


diagnostics(): readonly SessionDiagnostic[]

Defined in: driver/src/api.ts:266

Bounded, oldest-first log of what the session decided behind the scenes: dropped or superseded revisions, unverified markers, adapter negotiation, protocol violations. The same entries are emitted as diagnostic events.

readonly SessionDiagnostic[]


getByLabel(text, opts?): SemanticLocator

Defined in: driver/src/api.ts:217

string | RegExp

boolean

SemanticLocator


getByRole(role, opts?): SemanticLocator

Defined in: driver/src/api.ts:216

"application" | "region" | "dialog" | "alert" | "status" | "list" | "listitem" | "menu" | "menuitem" | "button" | "checkbox" | "radio" | "tab" | "textbox" | "heading" | "text" | "progressbar" | "separator" | "scrollbar" | "table" | "row" | "cell" | "generic"

RoleLocatorOptions

SemanticLocator


getByScreenText(text, opts?): ScreenLocator

Defined in: driver/src/api.ts:221

Physical terminal-grid text, optionally narrowed by occurrence or style.

string | RegExp

ScreenTextLocatorOptions

ScreenLocator


getByTestId(testId): SemanticLocator

Defined in: driver/src/api.ts:222

string

SemanticLocator


getByText(text, opts?): SemanticLocator

Defined in: driver/src/api.ts:219

Semantic text only. Never falls back to the terminal grid.

string | RegExp

TextLocatorOptions

SemanticLocator


locator(selector): SemanticLocator

Defined in: driver/src/api.ts:224

Advanced Termwright semantic selector: ‘dialog button.primary:focused’, ‘#id’.

string

SemanticLocator


locatorForRef(ref): SemanticLocator

Defined in: driver/src/api.ts:231

Rebuilds a locator from a ref returned by a resolved target. ('semantic:n8@42' for a semantic node, 'screen:r,c,w,h@7' for a grid match). The ref stays bound to its revision: resolving it after that revision was superseded raises stale-snapshot.

`semantic:${string}@${number}`

SemanticLocator

locatorForRef(ref): ScreenLocator

Defined in: driver/src/api.ts:232

`screen:${number},${number},${number},${number}@${number}`

ScreenLocator

locatorForRef(ref): SemanticLocator | ScreenLocator

Defined in: driver/src/api.ts:233

LocatorRef

SemanticLocator | ScreenLocator


ownedProcessResources(): OwnedProcessResourceUsage | null

Defined in: driver/src/api.ts:286

Native whole-tree accounting captured immediately before PTY disposal. Returns null when the backend cannot make an authoritative claim.

OwnedProcessResourceUsage | null


paste(text): Promise<void>

Defined in: driver/src/api.ts:238

ExecutableValue

Promise<void>


press(keys): Promise<void>

Defined in: driver/src/api.ts:236

string

Promise<void>


resize(size): Promise<ResizeReceipt>

Defined in: driver/src/api.ts:240

number

number

Promise<ResizeReceipt>


screen(): ScreenSnapshot

Defined in: driver/src/api.ts:211

ScreenSnapshot


semanticTree(): SemanticSnapshot | null

Defined in: driver/src/api.ts:212

SemanticSnapshot | null


settled(opts?): Promise<EffectiveSessionContract>

Defined in: driver/src/api.ts:210

Waits for the one frozen Effective Session Contract and, for a semantic session, for the first paired tree. There is no provisional capability API.

WaitOptions

Promise<EffectiveSessionContract>


signal(sig): Promise<void>

Defined in: driver/src/api.ts:241

"INT" | "TERM" | "KILL" | "HUP"

Promise<void>


title(): string

Defined in: driver/src/api.ts:251

string


type(text): Promise<void>

Defined in: driver/src/api.ts:237

ExecutableValue

Promise<void>


waitForCheckpointChange(options): Promise<ObservationStamp>

Defined in: driver/src/api.ts:196

Wait until a committed observation newer than after is available.

object & WaitOptions

Promise<ObservationStamp>


waitForCommittedObservation(opts?): Promise<ObservationStamp>

Defined in: driver/src/api.ts:205

Waits until currently observable parser work, semantic frame pairing and provider-evidence invalidation have committed. This cannot predict a future semantic frame before either of its causal signals reaches the driver, and it is not a quiet/global-idle heuristic.

WaitOptions

Promise<ObservationStamp>


waitForExit(opts?): Promise<ExitStatus>

Defined in: driver/src/api.ts:250

WaitOptions

Promise<ExitStatus>


waitForQuiet(opts?): Promise<void>

Defined in: driver/src/api.ts:247

Heuristic only: waits for a stated interval with no screen or semantic change.

object & WaitOptions

Promise<void>


waitForRender(opts): Promise<void>

Defined in: driver/src/api.ts:245

object & WaitOptions

Promise<void>


waitForShellPrompt(opts?): Promise<void>

Defined in: driver/src/api.ts:249

Authoritative: waits for an OSC 133 prompt marker from shell integration.

WaitOptions

Promise<void>


waitForText(text, opts?): Promise<void>

Defined in: driver/src/api.ts:244

string | RegExp

WaitOptions

Promise<void>


waitForTitle(text, opts?): Promise<void>

Defined in: driver/src/api.ts:252

string | RegExp

WaitOptions

Promise<void>


write(bytes): Promise<void>

Defined in: driver/src/api.ts:239

string | Uint8Array<ArrayBufferLike>

Promise<void>