Skip to content

Conversation

@iscekic
Copy link
Collaborator

@iscekic iscekic commented Nov 18, 2025

Context

This PR implements session management for the Kilo Code CLI, enabling users to persist their work across sessions, share sessions with others, and restore previous work states. Sessions automatically capture conversation history, task metadata, UI messages, and git state (including uncommitted changes and untracked files).

Implementation

Core Components

Session Management Service (SessionService)

  • Singleton service managing session lifecycle and synchronization
  • Automatic session creation on first task interaction
  • Periodic sync (1s interval) of conversation state to backend
  • Git state capture including uncommitted changes and untracked files
  • Session restoration with automatic task switching
  • Title generation using LLM for long prompts (>140 chars)
  • Workspace-specific session persistence

Session API Client (SessionClient)

  • tRPC client wrapper for session endpoints
  • CRUD operations: create, get, update, delete, list, search
  • Blob upload/download via signed URLs
  • Session sharing and forking support

tRPC Client (TrpcClient)

  • Generic HTTP client for backend communication
  • Bearer token authentication
  • GET/POST request handling
  • Environment-aware endpoint configuration

CLI Integration

Command Line Options

  • --session <sessionId>: Restore a specific session
  • --fork <shareId>: Fork a shared session
  • Mutual exclusivity validation between --fork and --session

Session Command (/session)

New slash command with subcommands:

  • show: Display current session ID
  • list: List all sessions with pagination
  • search <query>: Search sessions by title/ID
  • select <sessionId>: Restore a session
  • share: Share current session publicly
  • fork <shareId>: Fork a shared session
  • delete <sessionId>: Delete a session
  • rename <name>: Rename current session
  • Session ID autocomplete for select and delete subcommands

Modified Commands

  • /new: Clears session on new conversation
  • --continue: Falls back to session restoration before task history

Extension Integration

File Save Hooks

  • Emits apiMessagesSaved event on API conversation save
  • Emits taskMessagesSaved event on UI messages save
  • Emits taskMetadataSaved event on metadata save
  • Events include task ID and file path for session sync

Message Handlers

  • addTaskToHistory: Registers restored sessions in task history
  • singleCompletion: LLM completion endpoint for title generation

State Management

  • Listens to file save events
  • Updates SessionService paths for automatic sync
  • Renamed taskResumedViaContinueAtom to taskResumedViaContinueOrSessionAtom

Configuration

Config Schema

  • Added kiloToken field for backend authentication

Config Persistence

  • Automatic fallback: uses kilocodeToken from provider as kiloToken if missing
  • Applied during config load for seamless migration

Auth Wizard

  • Saves kilocodeToken to kiloToken field during authentication

Git State Management

Capture (SessionService.getGitState())

  • Repository URL from git remotes
  • Current HEAD commit SHA
  • Current branch name
  • Unified diff including:
    • Uncommitted changes
    • Untracked files (via --intent-to-add)
    • First commit handling (diff against empty tree)
  • Automatic cleanup of temporary git state

Restoration (SessionService.executeGitRestore())

  • Stash current work before restoration
  • Checkout to target commit/branch
  • Apply patch from session
  • Pop stashed work after restoration
  • Graceful error handling for each step

Screenshots

image image image image image image image

How to Test

Try the new /session command and the new --fork and --session flags.

@iscekic iscekic self-assigned this Nov 18, 2025
@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2025

🦋 Changeset detected

Latest commit: 2bbaa64

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@kilocode/cli Minor
kilo-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@iscekic iscekic marked this pull request as ready for review November 26, 2025 19:07
@iscekic
Copy link
Collaborator Author

iscekic commented Nov 26, 2025

Most of it is tests I promise 😅

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 35 changed files in this pull request and generated no new comments.

Copy link
Contributor

@catrielmuller catrielmuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change a the new kiloToken config parameter with a util function that extract token form the configured provider.


const session = await sessionClient.create({
...basePayload,
created_on_platform: process.env.KILO_PLATFORM || "cli",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandemicsyn This should be overridden when a session is initialized by cloud agents to cloud_agent

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 35 changed files in this pull request and generated no new comments.

@iscekic iscekic merged commit 84a5471 into main Nov 27, 2025
18 checks passed
@iscekic iscekic deleted the add-session-support branch November 27, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants