Skip to content

Implement AgentSessionService gRPC handler in nodespaced #1119

Closed

Description

@malibio

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

  • AgentSessionService handler is registered with the nodespaced gRPC server
  • LaunchSession creates a PTY session and returns the session ID
  • StreamOutput opens a server-streaming response that delivers OutputChunk messages in real time
  • WriteInput forwards bytes to the PTY stdin
  • ResizeTerminal resizes the PTY
  • TerminateSession kills the session and triggers cleanup
  • ListSessions returns metadata for all active sessions
  • Client disconnecting from StreamOutput does not kill the session (session continues running)
  • Integration test: launch a session running echo hello, verify StreamOutput delivers the output
  • cargo build --bin nodespaced succeeds
  • Code passes bun run quality:fix

Technical Specifications

Files to create/modify

  • packages/daemon/src/services/agent_session_service.rs (NEW) — tonic AgentSessionService trait implementation
  • packages/daemon/src/services/mod.rs — expose agent_session_service module
  • packages/daemon/src/main.rs — instantiate PtySessionManager and GraphContextAssembler; register AgentSessionServiceServer
  • packages/daemon/Cargo.toml — add packages/agent path 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

Dependencies

Non-Goals

  • Tauri UI for sessions (next issue)
  • CLI session commands (separate issue)
  • Session capture to ai-chat node (separate issue)

Activity

  1. malibio commented on May 18, 2026

    @malibio
    CollaboratorAuthor

    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.

  2. self-assigned this
    on May 18, 2026
  3. added a commit that references this issue on Jun 22, 2026
    337f89c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions