MCPcopy Index your code
hub / github.com/Waishnav/devspace / write

Method write

src/process-sessions.ts:239–271  ·  view source on GitHub ↗
(input: WriteStdinInput)

Source from the content-addressed store, hash-verified

237 }
238
239 async write(input: WriteStdinInput): Promise<ProcessSnapshot> {
240 const session = this.getOwnedSession(input.workspaceId, input.sessionId);
241 const chars = input.chars ?? "";
242 const interactionRequested =
243 chars.length > 0 || input.columns !== undefined || input.rows !== undefined;
244
245 if (input.columns !== undefined || input.rows !== undefined) {
246 session.columns = terminalSize(input.columns, session.columns);
247 session.rows = terminalSize(input.rows, session.rows);
248 if (!session.process?.resize) {
249 throw new Error(`Process session ${session.id} is not a PTY and cannot be resized.`);
250 }
251 session.process.resize(session.columns, session.rows);
252 }
253
254 const interruptRequested = chars.includes("\u0003") && session.running;
255 if (interruptRequested) {
256 session.process?.kill("SIGINT");
257 }
258 const writableChars = chars.replaceAll("\u0003", "");
259 if (writableChars && session.running) session.process?.write(writableChars);
260
261 if ((interactionRequested || !session.buffer.hasOutput()) && session.running) {
262 const fallback = interactionRequested ? DEFAULT_INTERACTIVE_YIELD_MS : DEFAULT_POLL_YIELD_MS;
263 const maximum = interactionRequested ? MAX_COMMAND_YIELD_MS : MAX_POLL_YIELD_MS;
264 const yieldTimeMs = boundedInteger(input.yieldTimeMs, fallback, maximum);
265 await this.waitForExit(session, yieldTimeMs);
266 }
267
268 const snapshot = this.consume(session, input.maxOutputTokens);
269 if (!session.running) this.removeSession(session.id);
270 return snapshot;
271 }
272
273 terminate(workspaceId: string, sessionId: number): void {
274 const session = this.getOwnedSession(workspaceId, sessionId);

Callers

nothing calls this directly

Calls 10

getOwnedSessionMethod · 0.95
waitForExitMethod · 0.95
consumeMethod · 0.95
removeSessionMethod · 0.95
terminalSizeFunction · 0.85
boundedIntegerFunction · 0.85
resizeMethod · 0.80
hasOutputMethod · 0.80
killMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected