MCPcopy Create free account
hub / github.com/apache/maka / startPty

Method startPty

packages/runtime/src/shell-run-manager.ts:805–905  ·  view source on GitHub ↗
(
    input: ShellRunBashInput,
    shellRunId: string,
    timeoutMs: number | undefined,
    stack: PtyStack,
    slotReservation: ShellRunSlotReservation,
    sessionEpoch: number,
  )

Source from the content-addressed store, hash-verified

803 }
804
805 private async startPty(
806 input: ShellRunBashInput,
807 shellRunId: string,
808 timeoutMs: number | undefined,
809 stack: PtyStack,
810 slotReservation: ShellRunSlotReservation,
811 sessionEpoch: number,
812 ): Promise<LivePtyShellRun> {
813 const pending: Array<(live: LivePtyShellRun) => void> = [];
814 let live: LivePtyShellRun | undefined;
815 let driver: PtyProcessDriver | undefined;
816 const dispatch = (callback: (target: LivePtyShellRun) => void): void => {
817 if (live) callback(live);
818 else pending.push(callback);
819 };
820 let collector: PtyScreenCollector | undefined;
821 let startingRecord: ShellRunRecord | undefined;
822 try {
823 collector = new PtyScreenCollector({
824 stack,
825 cols: PTY_INITIAL_COLS,
826 rows: PTY_INITIAL_ROWS,
827 onProtocolReply: (data) => {
828 if (!live || !driver)
829 throw new Error('PTY protocol reply arrived before driver admission');
830 if (live.driverExit || live.termination || live.integrityFailure) return;
831 driver.write(data);
832 },
833 onDirty: () => dispatch((target) => this.scheduleAutomaticFlush(target)),
834 onFailure: (error) => dispatch((target) => this.handleIntegrityFailure(target, error)),
835 });
836 const plan = buildPtyShellSpawnPlan(
837 input.shell ?? defaultShellPlan(),
838 input.command,
839 input.env ?? process.env,
840 );
841 startingRecord = await this.createStartingRecord(
842 input,
843 shellRunId,
844 timeoutMs,
845 collector.lastGoodSnapshot(),
846 );
847 this.assertStartupAllowed(input.sessionId, sessionEpoch, input.abortSignal);
848 driver = new PtyProcessDriver({
849 stack,
850 file: plan.file,
851 args: plan.args,
852 cwd: input.cwd,
853 env: plan.env ?? input.env ?? process.env,
854 cols: PTY_INITIAL_COLS,
855 rows: PTY_INITIAL_ROWS,
856 onData: (data) => dispatch((target) => this.onPtyData(target, data)),
857 onExit: (exit) => {
858 dispatch((target) => {
859 this.publishPtyData(target);
860 this.onNativeRootExit(target);
861 });
862 dispatch((target) => this.onDriverExit(target, { mode: 'pty', value: exit }));

Callers 1

startMethod · 0.95

Calls 15

createStartingRecordMethod · 0.95
assertStartupAllowedMethod · 0.95
onPtyDataMethod · 0.95
publishPtyDataMethod · 0.95
onNativeRootExitMethod · 0.95
onDriverExitMethod · 0.95
createLiveBaseMethod · 0.95
armTimeoutMethod · 0.95

Tested by

no test coverage detected