MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / subscribe

Method subscribe

crates/opencode-server/src/pty.rs:297–317  ·  view source on GitHub ↗

Returns a snapshot of the current output buffer, the cumulative cursor position, a broadcast receiver for live output, and a clone of the PTY writer so the WebSocket handler can forward input. This is the primary integration point for the `/{id}/connect` WebSocket endpoint, mirroring the TS `Pty.connect` behaviour: - replay buffered output from a caller-supplied cursor - subscribe to live output

(&self, id: &str)

Source from the content-addressed store, hash-verified

295 /// - subscribe to live output via the broadcast channel
296 /// - write user input into the PTY
297 pub async fn subscribe(&self, id: &str) -> Result<PtySubscription, PtyError> {
298 let sessions = self.sessions.read().await;
299 let (_, inner) = sessions
300 .get(id)
301 .ok_or_else(|| PtyError::SessionNotFound(id.to_string()))?;
302
303 let (buffer_snapshot, buffer_start, cursor) = {
304 let buf = inner.output_buffer.lock().unwrap();
305 let cursor = *inner.cursor.lock().unwrap();
306 let buffer_start = cursor - buf.len();
307 (buf.clone(), buffer_start, cursor)
308 };
309
310 Ok(PtySubscription {
311 buffer: buffer_snapshot,
312 buffer_start,
313 cursor,
314 rx: inner.output_tx.subscribe(),
315 writer: inner.writer.clone(),
316 })
317 }
318}
319
320/// Handle returned by [`PtyManager::subscribe`] containing everything needed

Callers 3

pty_connectFunction · 0.45
global_event_streamFunction · 0.45
event_streamFunction · 0.45

Calls 3

readMethod · 0.80
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected