Skip to content

refactor: extract one session-host module from tole-cli (merge Sessions and TuiSession) #525

Closed

Description

@ajianaz

What problem does this solve?

Session hosting is implemented twice, inside tole-cli:

  • session_host.rs (~1000 lines): Sessions / SessionState (admission, busy flag, claim), open_session, run_session_turn, resume_session_turn. Used by serve, acp and mcp.
  • tui_host.rs: TuiSession { Mutex<Inner> } with its own storage handle, registry, compaction settings, /new, /resume, index registration. Used by the TUI only.

Deletion test: if either vanished, the busy-flag, open and index logic would reappear in the other. Any new client (desktop, remote) would add a third copy. Also, session_host.rs mixes session hosting with tool setup (register_gitea, detect_github_repo, github_repo_from_remote_url) and UpdatePlanTool, which belong with the tool roster.

Proposed solution

One deep module (new crate, working name tole-session) with a small interface and the machinery behind it:

  • open / create / resume a session (jail, approver, sessions dir, index registration)
  • run a turn (observer + cancel token), resume a turn, interrupt, detach, cancel
  • read entries after a seq (feeds the event stream in the serve issue)
  • list sessions; settings that live in registers (model, effort, name, compaction request)

Constraints:

  • Depends on tole-core only; never on tole-cli or tole-tui (no cycle).
  • tole-core is untouched and stays platform-agnostic.
  • Behavior-preserving: serve, acp, mcp and the TUI all go through it; no new capability in this issue.
  • Tool registration (gitea/github, plan tool) moves out of the host into the tool roster.

Delivery in small PRs (Cora review times out beyond ~15–20 files):

  1. Move Sessions / SessionState / open_session / turn runners verbatim into the new crate; tole-cli re-exports.
  2. Migrate TuiSession onto it.
  3. Move tool registration to the roster.

Open questions

  • Crate name and publishing: crates.io currently gets tole-core then tole-cli via publish.yml; a new crate changes the order (check tole-tui too). Publish it, or keep it publish = false until the interface settles?
  • Does the interface stay sync (std Mutex, blocking turns, as today) or does the remote face want async? Proposal: keep sync inside, adapt at the edges.

Alternatives considered

  • Leave as is and add a third host for desktop: rejected, it triples the busy/jail/approval logic that must stay identical.
  • Put it into tole-core: rejected, it needs storage paths, index and process-level config (core stays host-free).

Acceptance criteria

  • One module owns open/turn/cancel/interrupt/detach/list; tui_host.rs no longer holds its own session lifecycle.
  • No behavior change: existing serve, acp, mcp, TUI tests pass unchanged.
  • session_host.rs no longer contains tool registration.
  • tole-core public API unchanged; embedders still build --no-default-features.
  • Publish plan decided and publish.yml updated if needed.

Part of #523.

Activity

  1. added
    enhancement
    on Nov 10, 2026
  2. ajianaz commented on Nov 10, 2026

    @ajianaz
    ContributorAuthor

    Status after #547, #548, #549, #550 (2026-11-10)

    Decided with the owner: do this as shared primitives inside tole-cli (no new tole-session crate until a second consumer exists, i.e. the GPUI desktop, #527), keep the API synchronous, deliver in small behavior-preserving PRs. Not a literal merge of TuiSession into Sessions: the TUI is one swappable session behind one mutex and adds things the server faces do not have (settling a parked turn, compaction, the footer).

    Shipped

    Acceptance criteria

    • [~] One module owns open/turn/cancel/interrupt/detach/list; tui_host.rs no longer holds its own session lifecycle. Partly: create + index, the turn, and the settings are shared. TuiSession still owns its single storage handle and switch_session (reopening a session by id through the index, with its own id rules and messages), and Sessions/SessionState (busy claim, cancel, interrupt, detach) are not used by the TUI.
    • No behavior change: serve, acp, mcp and TUI tests pass unchanged (workspace 1187 tests); error text preserved.
    • session_host.rs no longer contains tool registration.
    • tole-core public API unchanged; --no-default-features builds.
    • [~] Publish plan: no new crate, so publish.yml is unchanged. Revisit when the crate is cut.

    Left

    1. TuiSession::switch_session / open-existing lifecycle (needs a decision on the six variants of "open session by id": id charset, index lookup vs sessions dir, error text).
    2. Whether the TUI should use Sessions/SessionState at all (busy/cancel/interrupt/detach), or keep its single-session wrapper.
    3. Cutting a tole-session crate and the publish order, when feat(desktop): tole-desktop — GPUI desktop client (first graphical client) #527 gives it a second consumer.

    Leaving this issue open for those.


    Generated by Claude Code

  3. ajianaz commented on Nov 10, 2026

    @ajianaz
    ContributorAuthor

    Closing #525. Status against the acceptance criteria, checked on current develop:

    • One module owns open/turn/cancel/interrupt/detach/list; tui_host.rs no longer holds its own lifecycle: met as shared primitives, deliberately not as one merged type (decided with the maintainer: "shared primitives, TUI keeps its wrapper"). session_host is the one place that creates and registers a session (create_session, used by serve, acp, mcp and the TUI's /new), turn_runner is the one turn runner (run_turn_on, run_turn_with, resume_turn_on), and session_settings is the one writer of the fact/* registers (model, effort, name, compaction request). TuiSession keeps only what is TUI-specific: one open handle that it swaps, the footer, and the /resume picker over the index.
    • No behavior change: met. serve, acp, mcp and the TUI test suites pass unchanged across the whole series.
    • session_host.rs no longer contains tool registration: met. register_gitea, detect_github_repo, github_repo_from_remote_url and UpdatePlanTool live in tool_roster.rs (verified: no references left in session_host.rs).
    • tole-core public API unchanged; embedders build --no-default-features: met, core was not touched.
    • Publish plan decided: no new crate, so publish.yml needs no change (tole-tui was already in the order, core then tui then cli).

    Decided not to do, with the reason:

    • No tole-session crate yet. One consumer outside the module does not justify a new published crate (AGENTS.md: adding code is a last resort). Revisit when the GPUI client needs the host as a library. The module boundary is already clean, so extraction is a move.
    • Sync API kept, as proposed; a remote face adapts at the edge.
    • No shared "open existing session" helper. Both callers reduce to JsonlStorage::open after resolving the file (the TUI via the global index, the server under its workspace), so a helper would add an abstraction with nothing behind it.

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions