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

Method writeStdin

packages/runtime/src/shell-run-manager.ts:336–479  ·  view source on GitHub ↗
(input: ShellRunWriteInput)

Source from the content-addressed store, hash-verified

334 }
335
336 async writeStdin(input: ShellRunWriteInput): Promise<ShellRunToolResult> {
337 validateWriteStdinInput(input);
338 const target = parseShellRunResourceRef(input.ref);
339 if (!target) throw backgroundTaskRefError(input.ref);
340 const live = this.liveResource(input.sessionId, target.shellRunId);
341 if (!live) return this.writeStdinWithoutLive(input, target.shellRunId);
342 if (live.mode !== 'pty') throw new Error('WriteStdin requires a PTY background task ref');
343 if (live.driverExit) {
344 const record = await this.markObserved(await live.finished.join());
345 return shellRunContent(
346 record,
347 ptyControlOperation(input, {
348 inputQueued: false,
349 resizeApplied: false,
350 resizeChanged: false,
351 }),
352 );
353 }
354 if (!isPtyControlOpen(live)) {
355 throw new ShellRunPtyControlClosedError();
356 }
357 if (input.abortSignal?.aborted)
358 throw abortError('WriteStdin aborted before the control operation was committed');
359
360 let inputQueued = false;
361 let resizeApplied = false;
362 let resizeChanged = false;
363 let operationFailed = false;
364 let exitBeforeControlCut = false;
365 const controlCut = live.collector.mutateAndSnapshotAtCut(() => {
366 if (input.abortSignal?.aborted) {
367 throw abortError('WriteStdin aborted before the control operation was committed');
368 }
369 if (live.driverExit) {
370 exitBeforeControlCut = true;
371 return;
372 }
373 if (live.termination) throw new ShellRunPtyControlClosedError();
374 const terminalInput =
375 input.input ??
376 (input.actions
377 ? encodeTerminalInputActions(input.actions, {
378 ...live.collector.currentInputState(),
379 ...(input.size ? { cols: input.size.cols, rows: input.size.rows } : {}),
380 })
381 : undefined);
382 if (input.size) {
383 const currentSize = live.collector.currentSize();
384 if (currentSize.cols === input.size.cols && currentSize.rows === input.size.rows) {
385 resizeApplied = true;
386 } else {
387 live.driver.resize(input.size.cols, input.size.rows);
388 resizeApplied = true;
389 resizeChanged = true;
390 try {
391 live.collector.resize(input.size.cols, input.size.rows);
392 } catch (error) {
393 operationFailed = true;

Callers

nothing calls this directly

Calls 15

liveResourceMethod · 0.95
writeStdinWithoutLiveMethod · 0.95
markObservedMethod · 0.95
persistObservationMethod · 0.95
isTerminalShellRunStatusFunction · 0.90
validateWriteStdinInputFunction · 0.85
parseShellRunResourceRefFunction · 0.85
backgroundTaskRefErrorFunction · 0.85
shellRunContentFunction · 0.85
ptyControlOperationFunction · 0.85

Tested by

no test coverage detected