Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1f63786
compat with turbo
iscekic Nov 27, 2025
208abbd
add session client and trpc client
iscekic Nov 27, 2025
2852ab9
add session manager
iscekic Nov 27, 2025
fe49822
centralize deps
iscekic Nov 27, 2025
2210e7d
improve deps interface
iscekic Nov 27, 2025
5c50b85
move to shared/sessions
iscekic Nov 27, 2025
1eb7251
revert unintended changes
iscekic Nov 27, 2025
92af5be
simplify deps
iscekic Nov 28, 2025
edc1ddb
make SessionManager a singleton
iscekic Nov 28, 2025
ef094f5
migrate cli to use shared session manager
iscekic Nov 28, 2025
dc002b6
add tests
iscekic Nov 28, 2025
e16cd2d
remove unused import
iscekic Nov 28, 2025
652392a
use relative imports
iscekic Nov 28, 2025
5da85b7
small fixes
iscekic Nov 28, 2025
b6e8bee
remove extra interface
iscekic Nov 28, 2025
6b1cfb8
fix test on windows
iscekic Nov 28, 2025
e4d39f1
integrate SessionManager into extension
iscekic Nov 28, 2025
aaa2e99
add platform param
iscekic Nov 28, 2025
2fe3693
treat session manager as singleton
iscekic Nov 28, 2025
dd409b9
disallow accessing static instance directly
iscekic Nov 28, 2025
1bb2998
fix failing test
iscekic Nov 28, 2025
3feafad
tie task to session
iscekic Nov 28, 2025
63f0b4d
add tests
iscekic Nov 28, 2025
49d1d37
add more tests
iscekic Nov 28, 2025
47f04b7
remove ai slop
iscekic Nov 28, 2025
7c4b6cf
fix tests
iscekic Nov 28, 2025
f317419
remove unnecessary comments
iscekic Nov 28, 2025
3ce690e
use actual editor name for platform
iscekic Nov 28, 2025
302861c
let compiler infer return types
iscekic Nov 28, 2025
ad6cfb6
fix tests
iscekic Nov 28, 2025
895717c
remove unused imports
iscekic Nov 28, 2025
dc303bf
remove more unused imports
iscekic Nov 28, 2025
ca1f788
Merge branch 'main' into track-sessions-from-the-extension
iscekic Dec 1, 2025
30a1d50
Merge branch 'track-sessions-from-the-extension' of github.com:Kilo-O…
iscekic Dec 1, 2025
9a994fd
separate file for session manager utils
iscekic Dec 1, 2025
c6ea973
Merge branch 'main' into track-sessions-from-the-extension
iscekic Dec 1, 2025
a8bb4c7
delete barrel file
iscekic Dec 1, 2025
d86a1a6
consistency in utils
iscekic Dec 1, 2025
7d02a66
Merge branch 'main' into track-sessions-from-the-extension
iscekic Dec 1, 2025
0911e4a
fix build issue
iscekic Dec 1, 2025
1831796
add changeset
iscekic Dec 1, 2025
7fbea75
improve types
iscekic Dec 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/lucky-chicken-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"kilo-code": minor
"@kilocode/cli": patch
---

use shared session manager from extension folder
35 changes: 25 additions & 10 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import type { CLIOptions } from "./types/cli.js"
import type { CLIConfig, ProviderConfig } from "./config/types.js"
import { getModelIdKey } from "./constants/providers/models.js"
import type { ProviderName } from "./types/messages.js"
import { TrpcClient } from "./services/trpcClient.js"
import { SessionService } from "./services/session.js"
import { KiloCodePathProvider, ExtensionMessengerAdapter } from "./services/session-adapters.js"
import { getKiloToken } from "./config/persistence.js"
import { SessionManager } from "../../src/shared/kilocode/cli-sessions/core/SessionManager.js"

/**
* Main application class that orchestrates the CLI lifecycle
Expand All @@ -37,7 +37,7 @@ export class CLI {
private ui: Instance | null = null
private options: CLIOptions
private isInitialized = false
private sessionService: SessionService | null = null
private sessionService: SessionManager | null = null

constructor(options: CLIOptions = {}) {
this.options = options
Expand Down Expand Up @@ -135,16 +135,31 @@ export class CLI {
const kiloToken = getKiloToken(config)

if (kiloToken) {
TrpcClient.init(kiloToken)
logs.debug("TrpcClient initialized with kiloToken", "CLI")
const pathProvider = new KiloCodePathProvider()
const extensionMessenger = new ExtensionMessengerAdapter(this.service)

this.sessionService = SessionManager.init({
pathProvider,
logger: logs,
extensionMessenger,
getToken: () => Promise.resolve(kiloToken),
onSessionCreated: (message) => {
if (this.options.json) {
console.log(JSON.stringify(message))
}
},
onSessionRestored: () => {
if (this.store) {
this.store.set(taskResumedViaContinueOrSessionAtom, true)
}
},
platform: "cli",
})
logs.debug("SessionManager initialized with dependencies", "CLI")

this.sessionService = SessionService.init(this.service, this.store, this.options.json)
logs.debug("SessionService initialized with ExtensionService", "CLI")

// Set workspace directory for git operations (important for parallel mode/worktrees)
const workspace = this.options.workspace || process.cwd()
this.sessionService.setWorkspaceDirectory(workspace)
logs.debug("SessionService workspace directory set", "CLI", { workspace })
logs.debug("SessionManager workspace directory set", "CLI", { workspace })

if (this.options.session) {
await this.sessionService.restoreSession(this.options.session)
Expand Down
22 changes: 11 additions & 11 deletions cli/src/commands/__tests__/new.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"
import { newCommand } from "../new.js"
import type { CommandContext } from "../core/types.js"
import { createMockContext } from "./helpers/mockContext.js"
import { SessionService } from "../../services/session.js"
import { SessionManager } from "../../../../src/shared/kilocode/cli-sessions/core/SessionManager.js"

describe("/new command", () => {
let mockContext: CommandContext
let mockSessionService: Partial<SessionService> & { destroy: ReturnType<typeof vi.fn> }
let mockSessionManager: Partial<SessionManager> & { destroy: ReturnType<typeof vi.fn> }

beforeEach(() => {
// Mock process.stdout.write to capture terminal clearing
Expand All @@ -20,14 +20,14 @@ describe("/new command", () => {
input: "/new",
})

// Mock SessionService
mockSessionService = {
// Mock SessionManager
mockSessionManager = {
destroy: vi.fn().mockResolvedValue(undefined),
sessionId: "test-session-id",
}

// Mock SessionService.init to return our mock
vi.spyOn(SessionService, "init").mockReturnValue(mockSessionService as unknown as SessionService)
// Mock SessionManager.init to return our mock
vi.spyOn(SessionManager, "init").mockReturnValue(mockSessionManager as unknown as SessionManager)
})

afterEach(() => {
Expand Down Expand Up @@ -74,13 +74,13 @@ describe("/new command", () => {
it("should clear the session", async () => {
await newCommand.handler(mockContext)

expect(SessionService.init).toHaveBeenCalled()
expect(mockSessionService.destroy).toHaveBeenCalledTimes(1)
expect(SessionManager.init).toHaveBeenCalled()
expect(mockSessionManager.destroy).toHaveBeenCalledTimes(1)
})

it("should continue execution even if session clearing fails", async () => {
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {})
mockSessionService.destroy.mockRejectedValue(new Error("Session error"))
mockSessionManager.destroy.mockRejectedValue(new Error("Session error"))

await newCommand.handler(mockContext)

Expand Down Expand Up @@ -121,7 +121,7 @@ describe("/new command", () => {
callOrder.push("clearTask")
})

mockSessionService.destroy = vi.fn().mockImplementation(async () => {
mockSessionManager.destroy = vi.fn().mockImplementation(async () => {
callOrder.push("sessionDestroy")
})

Expand Down Expand Up @@ -164,7 +164,7 @@ describe("/new command", () => {

// Verify all cleanup operations were performed
expect(mockContext.clearTask).toHaveBeenCalled()
expect(mockSessionService.destroy).toHaveBeenCalled()
expect(mockSessionManager.destroy).toHaveBeenCalled()
expect(mockContext.replaceMessages).toHaveBeenCalled()

// Verify welcome message was replaced
Expand Down
Loading