-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add session sharing and forking in the extension #4145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
dcf48c1
hijack flow on /session
iscekic 4e6f5d0
add /session share command
iscekic c3dc993
Merge branch 'main' into add-session-commands
iscekic 095ab3c
add /session fork
iscekic 3521d87
update share url
iscekic a2e6ed8
fix paths
iscekic cdefd5e
Merge branch 'main' into add-session-commands
iscekic 085e092
improve messaging if share id not present
iscekic 230bcec
add changesets
iscekic afcd842
add share session button
iscekic 7d752e9
add env var disabling session functionality
iscekic 46b1745
improve command param naming
iscekic abb4ebd
improve copy
iscekic 328bf3c
handle /kilo/fork?id=xxx urls
iscekic ec3d9d9
fix copy
iscekic 36533c6
add translations
iscekic 8230d3a
Merge branch 'main' into add-session-commands
iscekic b545e27
fix failing cli test
iscekic c796a4d
improve title summary request
iscekic 030e81a
make the singleton safe to use before dependencies are initialized
iscekic 2bbfd39
correctly reinit singleton timer after destroying
iscekic 7b868e1
regenerate tests
iscekic dee5916
extract fn for /session command handling
iscekic 806bbcb
rename button component
iscekic be26d1c
add marker
iscekic 5048d4c
improve usage of SessionManager
iscekic 382b811
add back flow interruption when handling session command
iscekic aa3c6b5
extract function for finding kilocodeToken
iscekic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| update shared session url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": minor | ||
| --- | ||
|
|
||
| add session sharing and forking |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { createHash } from "crypto" | |
| import type { IPathProvider } from "../types/IPathProvider.js" | ||
| import type { ILogger } from "../types/ILogger.js" | ||
| import type { IExtensionMessenger } from "../types/IExtensionMessenger.js" | ||
| import type { ITaskDataProvider } from "../types/ITaskDataProvider.js" | ||
| import { SessionClient } from "./SessionClient.js" | ||
| import { SessionWithSignedUrls, CliSessionSharedState } from "./SessionClient.js" | ||
| import type { ClineMessage, HistoryItem } from "@roo-code/types" | ||
|
|
@@ -69,7 +70,7 @@ export class SessionManager { | |
| private readonly pathProvider: IPathProvider | ||
| private readonly logger: ILogger | ||
| private readonly extensionMessenger: IExtensionMessenger | ||
| private readonly sessionPersistenceManager: SessionPersistenceManager | ||
| public readonly sessionPersistenceManager: SessionPersistenceManager | ||
| public readonly sessionClient: SessionClient | ||
| private readonly onSessionCreated: (message: SessionCreatedMessage) => void | ||
| private readonly onSessionRestored: () => void | ||
|
|
@@ -287,14 +288,14 @@ export class SessionManager { | |
| } | ||
| } | ||
|
|
||
| async shareSession() { | ||
| const sessionId = this.sessionId | ||
| if (!sessionId) { | ||
| async shareSession(sessionId?: string) { | ||
| const sessionIdToShare = sessionId || this.sessionId | ||
| if (!sessionIdToShare) { | ||
| throw new Error("No active session") | ||
| } | ||
|
|
||
| return await this.sessionClient.share({ | ||
| session_id: sessionId, | ||
| session_id: sessionIdToShare, | ||
| shared_state: CliSessionSharedState.Public, | ||
| }) | ||
| } | ||
|
|
@@ -332,6 +333,50 @@ export class SessionManager { | |
| await this.restoreSession(session_id, rethrowError) | ||
| } | ||
|
|
||
| async getSessionFromTask(taskId: string, provider: ITaskDataProvider): Promise<string> { | ||
| try { | ||
| let sessionId = this.sessionPersistenceManager.getSessionForTask(taskId) | ||
|
|
||
| if (!sessionId) { | ||
| this.logger.debug("No existing session for task, creating new session", "SessionManager", { taskId }) | ||
|
|
||
| const { historyItem, apiConversationHistoryFilePath, uiMessagesFilePath } = | ||
| await provider.getTaskWithId(taskId) | ||
|
|
||
| const apiConversationHistory = JSON.parse(readFileSync(apiConversationHistoryFilePath, "utf8")) | ||
| const uiMessages = JSON.parse(readFileSync(uiMessagesFilePath, "utf8")) | ||
|
|
||
| const title = historyItem.task || this.getFirstMessageText(uiMessages, true) || "" | ||
|
|
||
| const session = await this.sessionClient.create({ | ||
| title, | ||
| created_on_platform: process.env.KILO_PLATFORM || this.platform, | ||
| }) | ||
|
|
||
| sessionId = session.session_id | ||
|
|
||
| this.logger.info("Created new session for task", "SessionManager", { taskId, sessionId }) | ||
|
|
||
| await this.sessionClient.uploadBlob(sessionId, "api_conversation_history", apiConversationHistory) | ||
| await this.sessionClient.uploadBlob(sessionId, "ui_messages", uiMessages) | ||
|
|
||
| this.logger.debug("Uploaded conversation blobs to session", "SessionManager", { sessionId }) | ||
|
|
||
| this.sessionPersistenceManager.setSessionForTask(taskId, sessionId) | ||
| } else { | ||
| this.logger.debug("Found existing session for task", "SessionManager", { taskId, sessionId }) | ||
| } | ||
|
|
||
| return sessionId | ||
| } catch (error) { | ||
| this.logger.error("Failed to get or create session from task", "SessionManager", { | ||
| taskId, | ||
| error: error instanceof Error ? error.message : String(error), | ||
| }) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| async destroy() { | ||
| this.logger.debug("Destroying SessionManager", "SessionManager", { | ||
| sessionId: this.sessionId, | ||
|
|
@@ -374,6 +419,10 @@ export class SessionManager { | |
| } | ||
| } | ||
|
|
||
| if (process.env.KILO_DISABLE_SESSIONS) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RSO @catrielmuller @pandemicsyn I noticed integration tests are creating sessions - once this is merged, they should probably set this env var. |
||
| return | ||
| } | ||
|
|
||
| this.isSyncing = true | ||
|
|
||
| try { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.