-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(jetbrains): move sessions to a worktree from the worktree editor #13756
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 @@ | ||
| --- | ||
| "@kilocode/kilo-jetbrains": minor | ||
| --- | ||
|
|
||
| Move a session into a new worktree directly from the base checkout's worktree editor tab: a "Move to Worktree" entry now leads its session list's row menu, and sessions there get the same New Worktree / Move to Worktree toolbar above the prompt that the tool window shows. The tab's header now also reports the base checkout's uncommitted changes, the ones a move would carry. |
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
23 changes: 23 additions & 0 deletions
23
...etbrains/frontend/src/main/kotlin/ai/kilocode/client/actions/MoveWorktreeSessionAction.kt
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,23 @@ | ||
| package ai.kilocode.client.actions | ||
|
|
||
| import ai.kilocode.client.agentManager.worktree.WorktreeSessionDataKeys | ||
| import com.intellij.openapi.actionSystem.ActionUpdateThread | ||
| import com.intellij.openapi.actionSystem.AnAction | ||
| import com.intellij.openapi.actionSystem.AnActionEvent | ||
| import com.intellij.openapi.project.DumbAware | ||
|
|
||
| class MoveWorktreeSessionAction : AnAction(), DumbAware { | ||
| override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.EDT | ||
|
|
||
| override fun update(e: AnActionEvent) { | ||
| val panel = e.getData(WorktreeSessionDataKeys.PANEL) | ||
| val item = e.getData(WorktreeSessionDataKeys.SESSION) | ||
| e.presentation.isEnabledAndVisible = panel != null && panel.canMove(item) | ||
| } | ||
|
|
||
| override fun actionPerformed(e: AnActionEvent) { | ||
| val panel = e.getData(WorktreeSessionDataKeys.PANEL) ?: return | ||
| val item = e.getData(WorktreeSessionDataKeys.SESSION) ?: return | ||
| if (panel.canMove(item)) panel.moveRow(item) | ||
| } | ||
| } |
77 changes: 77 additions & 0 deletions
77
...lo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/AgentManagerHost.kt
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,77 @@ | ||
| package ai.kilocode.client.agentManager | ||
|
|
||
| import ai.kilocode.client.KILO_TOOL_WINDOW_ID | ||
| import com.intellij.openapi.Disposable | ||
| import com.intellij.openapi.components.Service | ||
| import com.intellij.openapi.project.Project | ||
| import com.intellij.openapi.util.Disposer | ||
| import com.intellij.openapi.wm.ToolWindowManager | ||
| import com.intellij.util.concurrency.annotations.RequiresEdt | ||
|
|
||
| /** | ||
| * Project-level seam between a worktree session editor tab and the Agent Manager tool window panel, | ||
| * which the editor cannot reach directly (it lives inside [ai.kilocode.client.KiloToolWindowSetupService]). | ||
| * The tool window binds its two worktree flows here once it is created; an editor calls [move] / | ||
| * [newWorktree] the same way the chat branch dock does. When nothing is bound yet -- a tab restored | ||
| * before the tool window has been shown, or after a plugin reload -- the request is queued (the latest | ||
| * call wins) and the tool window is activated, which creates its content and flushes the queue via | ||
| * [bind]. | ||
| */ | ||
| @Service(Service.Level.PROJECT) | ||
| class AgentManagerHost(private val project: Project) { | ||
| private var onMove: ((String?, String, String) -> Unit)? = null | ||
| private var onNew: (() -> Unit)? = null | ||
| private var queued: (() -> Unit)? = null | ||
| // Which bind owns the callbacks currently installed. A tool window is not guaranteed to be | ||
| // disposed before its replacement is created -- a plugin reload creates the new one first -- so a | ||
| // disposer that cleared unconditionally would take the live callbacks down with the dead window. | ||
| private var generation = 0 | ||
|
|
||
| /** | ||
| * Registers the tool window's worktree flows for the lifetime of [parent] (the tool window's | ||
| * disposable). A later [bind] call from a fresh tool window setup replaces the callbacks and | ||
| * flushes anything queued while none were bound. | ||
| */ | ||
| @RequiresEdt | ||
| fun bind(parent: Disposable, move: (String?, String, String) -> Unit, newWorktree: () -> Unit) { | ||
| val gen = ++generation | ||
| onMove = move | ||
| onNew = newWorktree | ||
| Disposer.register(parent) { | ||
| if (gen != generation) return@register | ||
| onMove = null | ||
| onNew = null | ||
| } | ||
| val pending = queued | ||
| queued = null | ||
| pending?.invoke() | ||
| } | ||
|
|
||
| /** Moves [sessionId] (or just the local changes in [directory] when null) into a new worktree. */ | ||
| @RequiresEdt | ||
| fun move(sessionId: String?, directory: String, surface: String) { | ||
| val handler = onMove | ||
| if (handler != null) { | ||
| handler(sessionId, directory, surface) | ||
| return | ||
| } | ||
| queued = { onMove?.invoke(sessionId, directory, surface) } | ||
| activate() | ||
| } | ||
|
|
||
| /** Opens the New Worktree dialog. */ | ||
| @RequiresEdt | ||
| fun newWorktree() { | ||
| val handler = onNew | ||
| if (handler != null) { | ||
| handler() | ||
| return | ||
| } | ||
| queued = { onNew?.invoke() } | ||
| activate() | ||
| } | ||
|
|
||
| private fun activate() { | ||
| ToolWindowManager.getInstance(project).getToolWindow(KILO_TOOL_WINDOW_ID)?.activate(null) | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.