Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ consumes the ticket. Expiry stops an unowned daemon; if the old owner is still
connected, expiry simply cancels the handoff. `shutdown` always stops the daemon,
including during handoff. No ownership or handoff state is persisted.

### Local transport boundary

`src/transport/` owns endpoint listening/connecting, byte-stream I/O,
disconnect monitoring, response completion, and cancellation. Authentication,
protocol framing, dispatch, subscriptions, and ownership stay shared in the
daemon; runtime-directory/registration wiring is platform-specific. The Unix
backend preserves half-close when completing subscriptions so queued final
frames are not discarded on macOS. Shutdown cancellation is a separate operation
that wakes partial requests and blocked subscription writes before joining.

The planned Windows backend keeps protocol 7 and the registration fields
`instance_id`, `pid`, `protocol`, `socket`, and `token`. Treat `socket` as an opaque
local endpoint: on Windows it will be `\\.\pipe\opencode-pty-<instance_id>`, not a
filesystem socket. A random per-instance name, exclusive first pipe instance,
current-user access control, and rejection of remote clients protect the endpoint;
the private registration file remains the discovery and authentication source.
Named-pipe completion will use explicit bounded, cancellable delivery rather than
pretending to support Unix half-close. This boundary alone does not implement
Windows transport or daemon support.

## Architecture

```text
Expand Down
15 changes: 7 additions & 8 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ use crate::protocol::{
read_subscription_event, write_frame,
};
use crate::service::{CreateTerminal, TerminalId, TerminalInfo, TerminalRows};
#[cfg(unix)]
use crate::transport::Connection;

const START_TIMEOUT: Duration = Duration::from_secs(5);

pub struct TerminalClient {
registration: Registration,
#[cfg(unix)]
owner: Option<(std::os::unix::net::UnixStream, std::process::Child)>,
owner: Option<(Connection, std::process::Child)>,
}

#[derive(Debug)]
Expand All @@ -41,7 +43,7 @@ pub struct RemoteReplay {

#[cfg(unix)]
pub struct TerminalSubscription {
stream: std::os::unix::net::UnixStream,
stream: Connection,
pub terminal: TerminalInfo,
pub role: AttachmentRole,
pub generation: u64,
Expand All @@ -58,7 +60,6 @@ impl TerminalSubscription {
impl TerminalClient {
#[cfg(unix)]
pub fn start() -> Result<Self> {
use std::os::unix::net::UnixStream;
use std::os::unix::process::CommandExt;
use std::process::{Command, Stdio};

Expand All @@ -82,7 +83,7 @@ impl TerminalClient {
if let Ok(registration) = read_registration()
&& registration.pid == child.id()
{
let mut stream = UnixStream::connect(&registration.socket)?;
let mut stream = Connection::connect(&registration.socket)?;
stream.set_read_timeout(Some(START_TIMEOUT))?;
stream.set_write_timeout(Some(START_TIMEOUT))?;
write_frame(
Expand Down Expand Up @@ -304,8 +305,7 @@ impl TerminalClient {
role: AttachmentRole,
takeover: bool,
) -> Result<TerminalSubscription> {
use std::os::unix::net::UnixStream;
let mut stream = UnixStream::connect(&self.registration.socket)?;
let mut stream = Connection::connect(&self.registration.socket)?;
write_frame(
&mut stream,
&Envelope {
Expand Down Expand Up @@ -362,8 +362,7 @@ impl TerminalClient {

#[cfg(unix)]
fn request(&self, request: Request) -> Result<Response> {
use std::os::unix::net::UnixStream;
let mut stream = UnixStream::connect(&self.registration.socket).with_context(|| {
let mut stream = Connection::connect(&self.registration.socket).with_context(|| {
format!(
"failed to connect to {}",
self.registration.socket.display()
Expand Down
Loading
Loading