MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / openTerminal

Function openTerminal

desktop/terminal/manager.ts:111–173  ·  view source on GitHub ↗
(request: TerminalOpenRequest)

Source from the content-addressed store, hash-verified

109}
110
111export async function openTerminal(request: TerminalOpenRequest): Promise<TerminalSessionSnapshot> {
112 const cwd = request.cwd ?? request.projectId
113 const sessionId = makeSessionId(request)
114 const existing = getTerminalSession(sessionId)
115
116 if (existing) {
117 existing.snapshot = {
118 ...existing.snapshot,
119 cols: request.cols,
120 rows: request.rows,
121 updatedAt: nowIso(),
122 }
123
124 if (existing.process) {
125 existing.process.resize(request.cols, request.rows)
126 } else if (isRestartableTerminalStatus(existing.snapshot.status)) {
127 existing.snapshot = {
128 ...existing.snapshot,
129 status: 'starting',
130 exitCode: null,
131 exitSignal: null,
132 updatedAt: nowIso(),
133 }
134 void ensureProcessStarted(existing, 'restarted')
135 }
136
137 return existing.snapshot
138 }
139
140 const history = readTranscript(getTranscriptPath(sessionId))
141 const snapshot: TerminalSessionSnapshot = {
142 sessionId,
143 projectId: request.projectId,
144 sessionPath: request.sessionPath ?? null,
145 cwd,
146 launchMode: request.launchMode ?? 'shell',
147 status: 'starting',
148 pid: null,
149 cols: request.cols,
150 rows: request.rows,
151 history,
152 hasVisibleContent:
153 (request.launchMode ?? 'shell') === 'shell' || hasVisibleTerminalContent(history),
154 exitCode: null,
155 exitSignal: null,
156 updatedAt: nowIso(),
157 }
158
159 const record: TerminalSessionRecord = {
160 snapshot,
161 process: null,
162 restartPromise: null,
163 transcriptPath: getTranscriptPath(sessionId),
164 inputBuffer: '',
165 suppressOutputVisibilityUntilInput: false,
166 persistTimer: null,
167 cleanup: [],
168 }

Callers

nothing calls this directly

Calls 10

makeSessionIdFunction · 0.90
getTerminalSessionFunction · 0.90
nowIsoFunction · 0.90
readTranscriptFunction · 0.90
getTranscriptPathFunction · 0.90
setTerminalSessionFunction · 0.90
ensureProcessStartedFunction · 0.85
resizeMethod · 0.65

Tested by

no test coverage detected