(request: TerminalOpenRequest)
| 109 | } |
| 110 | |
| 111 | export 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 | } |
nothing calls this directly
no test coverage detected