Repository navigation
Description
Overview
Wire PtySessionManager into nodespaced by implementing the AgentSessionService gRPC handler. This exposes PTY session operations — launch, stream output, write input, resize, terminate, list — as gRPC RPCs that the Tauri UI and CLI can call. It is the interface layer between the gRPC boundary and the PTY engine.
Problem Statement
PtySessionManager exists as an in-process Rust API after #1118. Without a gRPC handler it is unreachable from the Tauri UI or CLI. AgentSessionService is the gRPC service defined in agent_session_service.proto that exposes every session operation to all clients.
Proposed Solution
Implement the tonic AgentSessionService trait, inject an Arc<PtySessionManager> and Arc<GraphContextAssembler> via the handler struct, and register the service with the nodespaced gRPC server. StreamOutput is a server-streaming RPC that subscribes to the session's broadcast channel and forwards OutputChunk messages until the session ends or the client disconnects.
Acceptance Criteria
-
AgentSessionServicehandler is registered with thenodespacedgRPC server -
LaunchSessioncreates a PTY session and returns the session ID -
StreamOutputopens a server-streaming response that deliversOutputChunkmessages in real time -
WriteInputforwards bytes to the PTY stdin -
ResizeTerminalresizes the PTY -
TerminateSessionkills the session and triggers cleanup -
ListSessionsreturns metadata for all active sessions - Client disconnecting from
StreamOutputdoes not kill the session (session continues running) - Integration test: launch a session running
echo hello, verifyStreamOutputdelivers the output -
cargo build --bin nodespacedsucceeds - Code passes
bun run quality:fix
Technical Specifications
Files to create/modify
packages/daemon/src/services/agent_session_service.rs(NEW) — tonicAgentSessionServicetrait implementationpackages/daemon/src/services/mod.rs— exposeagent_session_servicemodulepackages/daemon/src/main.rs— instantiatePtySessionManagerandGraphContextAssembler; registerAgentSessionServiceServerpackages/daemon/Cargo.toml— addpackages/agentpath dependency
Handler struct
pub struct AgentSessionHandler {
manager: Arc<PtySessionManager>,
assembler: Arc<GraphContextAssembler>,
}StreamOutput implementation
async fn stream_output(&self, req: Request<StreamOutputRequest>)
-> Result<Response<Self::StreamOutputStream>, Status>
{
let id = parse_uuid(&req.get_ref().session_id)?;
let mut rx = self.manager
.get(&id).ok_or(Status::not_found("session not found"))?
.subscribe_output();
let stream = async_stream::stream! {
loop {
match rx.recv().await {
Ok(chunk) => yield Ok(chunk),
Err(RecvError::Lagged(_)) => continue,
Err(RecvError::Closed) => break,
}
}
};
Ok(Response::new(Box::pin(stream)))
}Proto message reference
From packages/daemon/proto/agent_session_service.proto (defined in #1111):
service AgentSessionService {
rpc LaunchSession(LaunchSessionRequest) returns (LaunchSessionResponse);
rpc StreamOutput(StreamOutputRequest) returns (stream OutputChunk);
rpc WriteInput(WriteInputRequest) returns (WriteInputResponse);
rpc ResizeTerminal(ResizeRequest) returns (ResizeResponse);
rpc TerminateSession(TerminateSessionRequest) returns (TerminateSessionResponse);
rpc ListSessions(ListSessionsRequest) returns (ListSessionsResponse);
}LaunchSessionRequest fields
message LaunchSessionRequest {
string agent_type = 1; // "claude_code" | "codex" | "gemini" | "pi" | "opencode"
optional string prompt = 2; // initial prompt passed as CLI argument
uint32 cols = 3;
uint32 rows = 4;
}Reference files
packages/daemon/proto/agent_session_service.proto— service definition (from Define protobuf schema and set up tonic/prost build pipeline for nodespaced #1111)packages/daemon/src/services/node_service.rs— pattern for tonic service implementation (from Implement nodespaced binary: gRPC server startup and NodeService registration #1112)packages/agent/src/pty/manager.rs— PtySessionManager API (from Implement PtySessionManager and PtySession in packages/agent #1118)
Dependencies
- Define protobuf schema and set up tonic/prost build pipeline for nodespaced #1111
- Implement nodespaced binary: gRPC server startup and NodeService registration #1112
- Implement PtySessionManager and PtySession in packages/agent #1118
Non-Goals
- Tauri UI for sessions (next issue)
- CLI session commands (separate issue)
- Session capture to ai-chat node (separate issue)
Activity
malibio commentedon May 18, 2026
Starting work in isolated worktree (worktree-issue-1119-agent-session-service). Baseline: Frontend 3918 passed / 128 files (92.57s). Note: fresh worktree required bunx svelte-kit sync to generate .svelte-kit/tsconfig.json before tests would run.
Implement AgentSessionService gRPC handler (closes #1119) (#1148)