Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

PTY.ts

58 lines1.4 KB

1/**
2 * PtyAdapter - Terminal PTY adapter service contract.
3 *
4 * Defines the process primitives required by terminal session management
5 * without binding to a specific PTY implementation.
6 *
7 * @module PtyAdapter
8 */
9import { Effect, Schema, ServiceMap } from "effect";
10​
11/**
12 * PtyError - Error type for PTY adapter operations.
13 */
14export class PtySpawnError extends Schema.TaggedErrorClass<PtySpawnError>()("PtySpawnError", {
15 adapter: Schema.String,
16 message: Schema.String,
17 cause: Schema.optional(Schema.Defect),
18}) {}
19​
20export interface PtyExitEvent {
21 exitCode: number;
22 signal: number | null;
24​
25export interface PtyProcess {
26 readonly pid: number;
27 write(data: string): void;
28 resize(cols: number, rows: number): void;
29 kill(signal?: string): void;
30 onData(callback: (data: string) => void): () => void;
31 onExit(callback: (event: PtyExitEvent) => void): () => void;
33​
34export interface PtySpawnInput {
35 shell: string;
36 args?: string[];
37 cwd: string;
38 cols: number;
39 rows: number;
40 env: NodeJS.ProcessEnv;
42​
43/**
44 * PtyAdapterShape - Service API for spawning and controlling PTY processes.
45 */
46export interface PtyAdapterShape {
47 /**
48 * Spawn a PTY process for a terminal session.
49 */
50 spawn(input: PtySpawnInput): Effect.Effect<PtyProcess, PtySpawnError>;
52​
53/**
54 * PtyAdapter - Service tag for PTY process integration.
55 */
56export class PtyAdapter extends ServiceMap.Service<PtyAdapter, PtyAdapterShape>()(
57 "t3/terminal/Services/PTY/PtyAdapter",
58) {}