Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:1jehuang Jcode handle client

From Leeroopedia
Knowledge Sources
Domains Systems_Architecture, Concurrency
Last Updated 2026-10-18 00:00 GMT

Overview

Concrete tool for handling client connections, creating or resuming sessions, and managing the client-to-session lifecycle provided by the jcode server module.

Description

The handle_client function processes an incoming client connection. It reads the client's request (CreateSession or ResumeSession), creates a new session with an animal-noun name or resumes an existing one by ID, and registers the session in the shared SessionAgents map. The Client API provides resume_session() and resume_session_with_options() for resuming sessions with options like client_has_local_history and allow_session_takeover.

Usage

  • Create session: Client sends Request::CreateSession with working directory and optional system prompt.
  • Resume session: Client sends Request::ResumeSession with session ID.
  • Session takeover: A second client can resume a session already in use, with optional takeover.

Code Reference

Source Location

  • Repository: jcode
  • File: crates/jcode-app-core/src/server/client_lifecycle.rs, crates/jcode-app-core/src/server/client_api.rs

Signature

// client_lifecycle.rs
pub(crate) async fn handle_client(
    stream: Stream,
    sessions: SessionAgents,
    // ... additional server state
)

// client_api.rs
impl Client {
    pub fn resume_session(&self, session_id: &str) -> Result<u64>
    pub fn resume_session_with_options(
        &self,
        session_id: &str,
        client_has_local_history: bool,
        allow_session_takeover: bool,
    ) -> Result<u64>
    pub fn reload(&self) -> Result<()>
    pub fn reload_with_force(&self, force: bool) -> Result<()>
}

Import

// Internal server functions, called from the accept loop.
// Client API: use crate::server::Client;

I/O Contract

Inputs

Name Type Required Description
stream Stream Yes /// Connected client stream
session_id &str Yes (resume) /// Session ID to resume
client_has_local_history bool No /// Whether client has local message history
allow_session_takeover bool No /// Allow taking over an in-use session

Outputs

Name Type Description
ServerEvent event /// SessionCreated or session state snapshot
session Session /// New or resumed Session with Agent in SessionAgents map

Usage Examples

Client Creates a Session

// Client-side: sends CreateSession request over socket
let client = Client::connect_with_path(socket_path())?;
let session = client.create_session("My Project")?;
println!("Session: {} ({})", session.name, session.id);

Client Resumes a Session

let client = Client::connect_with_path(socket_path())?;
let session_id = "clever-penguin";
client.resume_session_with_options(session_id, true, false)?;

Related Pages

Implements Principle

Requires Environment

Uses Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment