Skip to content

feat(jetbrains): run configs from worktree editor - #13278

Merged
kirillk merged 19 commits into
mainfrom
investigate-jetbrains-agent-manager-run-feature
Aug 28, 2026
Merged

feat(jetbrains): run configs from worktree editor#13278
kirillk merged 19 commits into
mainfrom
investigate-jetbrains-agent-manager-run-feature

Conversation

@kirillk

@kirillk kirillk commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Issue

No linked issue; requested directly in this development session.

Context

JetBrains Agent Manager worktree sessions need a more IDE-native way to run per-worktree processes than manually opening terminals. This adds a Run dropdown to the worktree editor header that lists supported IDE run configurations and starts them against the selected worktree while keeping output in the native Run tool window.

Implementation

The feature adds a split-mode RPC surface for run configurations and a backend project service that reuses IntelliJ's normal execution pipeline rather than reimplementing runners. Supported configurations are transplanted into transient per-worktree clones: Gradle/external-system configs are pointed at the worktree project path, and command-line-style configs get their working directory plus WORKTREE_PATH / REPO_PATH env vars set to the worktree context. Module-classpath configs are intentionally excluded because they would execute the main checkout's compiled classes.

The worktree editor header now includes a Run button. Its popup lists currently running worktree processes with Stop and Show Output actions, supported startable run configs, and an Open in New Frame escape hatch. The popup includes the requested hint that full run/debug support should use a separate IDE frame. Process state is tracked through ExecutionManager.EXECUTION_TOPIC, and stopping uses the recorded ProcessHandler so user-initiated stops from the Run tool window stay in sync.

Tests cover backend filtering/transplant/caching/state transitions, RPC project resolution, and popup rows/actions.

Screenshots / Video

Screen Shot 2026-08-28 at 9 24 02 AM

Manual/local verification

  • Agent executed: ./gradlew typecheck test from packages/kilo-jetbrains/ — passed.
  • Push hook executed: bun turbo typecheck --filter=!@kilocode/kilo-jetbrains — passed from cache.
  • Push hook executed: bun turbo typecheck --filter=@kilocode/kilo-jetbrains — passed.

Reviewer test steps

  1. Open a project with JetBrains Agent Manager worktrees and at least one supported run configuration, such as a Gradle task.
  2. Open a worktree session editor tab.
  3. Click the new Run dropdown in the worktree header.
  4. Confirm supported configs appear, the bottom hint says to open in a new frame for full run/debug support, and the Open in New Frame action is present.
  5. Start a supported config and confirm a Run tool window tab appears with the worktree-labeled config name.
  6. Reopen the dropdown and confirm Stop and Show Output actions appear for the running process.
  7. Stop the process and confirm the running state clears.

Blocked checks and substitute verification

  • runIdeSplitMode smoke verification was not run in this agent session. Substitute verification was backend/frontend unit coverage plus ./gradlew typecheck test for the JetBrains plugin.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

Get in Touch

N/A

@kilo-code-bot

kilo-code-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/WorktreeControllerTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeRunRpcApi.kt
Previous Review Summaries (8 snapshots, latest commit c65cb69)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c65cb69)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • .changeset/jetbrains-worktree-header-run-dropdown.md
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreePrHeaderView.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunControl.kt
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle*.properties
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/WorktreePrHeaderViewTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunControlTest.kt

Previous review (commit 441fc80)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/AgentManagerPanelTest.kt

Previous review (commit 1747e05)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/rpc/KiloRunRpcApiImpl.kt
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunManager.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/run/WorktreeRunManagerTest.kt

Previous review (commit ab7fca9)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunManager.kt 286 release() can miss an in-flight run/build and leave a process on a deleted worktree
packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/rpc/KiloRunRpcApiImpl.kt 69 normalizeWorkspacePath is the wrong identity check for open projects
Files Reviewed (21 files)
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/rpc/KiloRunRpcApiImpl.kt - 1 issue
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunManager.kt - 1 issue
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/rpc/KiloRunRpcApiImplTest.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/run/WorktreeRunManagerTest.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinator.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/KiloRunService.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeController.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunControl.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunPopup.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunStatusService.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeSessionEditorPanel.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeStatusService.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/app/KiloWorkspaceService.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/app/ProjectRoot.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/KiloRunServiceTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunControlTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunPopupTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeProjectRoot.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeRunRpcApi.kt
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/rpc/KiloRunRpcApi.kt
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle_*.properties

Fix these issues in Kilo Cloud

Previous review (commit 9162a87)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunManager.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinator.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinatorTest.kt

Previous review (commit 11ba989)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinator.kt 132 ProjectRoot.get() is outside runCatching, so a throw leaves busy stuck and stalls GitHub status
packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunManager.kt 175 Build and Rebuild use different keys, so they can run in parallel on the same worktree
Files Reviewed (28 files)
  • .changeset/jetbrains-split-mode-run-configs.md
  • .changeset/jetbrains-worktree-run-configs.md
  • .kilo/plans/jetbrains-split-mode-project-root.md
  • packages/kilo-jetbrains/AGENTS.md
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/rpc/KiloRunRpcApiImpl.kt
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunAdapter.kt
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunManager.kt - 1 issue
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/run/WorktreeRunAdapterTest.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/run/WorktreeRunManagerTest.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinator.kt - 1 issue
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/KiloRunService.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunControl.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunPopup.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeStatusService.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/app/ProjectRoot.kt
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle.properties
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/AgentManagerPanelTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhBannerTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/GhStatusCoordinatorTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunControlTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunPopupTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeStatusServiceTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/app/ProjectRootTest.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeProjectRoot.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeRunRpcApi.kt
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/testing/FakeWorkspaceRpcApi.kt
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/rpc/KiloRunRpcApi.kt
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/rpc/dto/RunConfigDto.kt

Fix these issues in Kilo Cloud

Previous review (commit 0af7cd6)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunAdapter.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/run/WorktreeRunAdapterTest.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/run/WorktreeRunManagerTest.kt

Previous review (commit db41227)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunAdapter.kt 58 Replacing externalProjectPath / working directory with the worktree root drops nested Gradle/Maven project paths
Files Reviewed (19 files)
  • .changeset/jetbrains-worktree-run-configs.md
  • bun.lock
  • packages/kilo-jetbrains/backend/build.gradle.kts
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/rpc/KiloRunRpcApiImpl.kt
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/rpc/KiloRunRpcApiProvider.kt
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunAdapter.kt - 1 issue
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/run/WorktreeRunManager.kt
  • packages/kilo-jetbrains/backend/src/main/resources/kilo.jetbrains.backend.xml
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/rpc/KiloRunRpcApiImplTest.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/run/WorktreeRunManagerTest.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/KiloRunService.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreePrHeaderView.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunControl.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunPopup.kt
  • packages/kilo-jetbrains/frontend/src/main/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeSessionEditorPanel.kt
  • packages/kilo-jetbrains/frontend/src/main/resources/messages/KiloBundle.properties
  • packages/kilo-jetbrains/frontend/src/test/kotlin/ai/kilocode/client/agentManager/worktree/WorktreeRunPopupTest.kt
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/rpc/KiloRunRpcApi.kt
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/rpc/dto/RunConfigDto.kt

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 179.4K · Output: 9.6K · Cached: 713.9K

Review guidance: REVIEW.md from base branch main

Setting externalProjectPath/workingDirectory to the worktree root dropped nested
project paths, so a subproject task such as :runIdeSplitMode configured against
$PROJECT_DIR$/packages/kilo-jetbrains would run from the wrong project.

Map the configured path onto the worktree instead, keeping paths that are already
inside the worktree (managed worktrees live under <repo>/.kilo/worktrees/<name>)
and paths outside the checkout untouched. Also treat a null clone() result as
unsupported rather than crashing the run.
Resolve the backend project root before worktree run, stats, PR, and GitHub status calls so split-mode frontend paths are not sent to backend RPCs.

Delegate worktree process stopping to the platform Stop action semantics and expose Kill only for handlers that support force termination.
Adds Build/Rebuild rows to the worktree Run popup that run the project's external-system build tasks against the worktree's own copy of each linked root, reusing the existing run tracking, Stop, and output pipeline.

Also fixes worktree Run failing with 'System property idea.debugger.dispatch.port is not set' when the sandbox IDE itself was launched via Debug: the leaked DEBUGGER_ENABLED env is now explicitly cleared for transplanted and synthesized worktree executions.
…-agent-manager-run-feature

# Conflicts:
#	bun.lock
Resolve the GitHub status probe root inside runCatching so a failed or blank resolution clears the busy flag instead of latching the probe loop.

Share one transient settings slot per (root, worktree) for Build and Rebuild so switching between them restarts the sibling process instead of running two Gradle builds on the same worktree.
Review follow-ups on the worktree Run/Build feature and the split-mode
project-root resolution.

Correctness:
- Stop a replaced clone's process before swapping in a fresh one. The
  platform's restart matches run settings by identity, so editing a source
  configuration between runs previously left the old process running and
  unreachable from the popup (for Gradle runIde* that means two sandboxes
  per checkout).
- Re-establish the backend run-state stream with backoff. A completed or
  failed stream (backend project not resolved yet, reconnect) used to
  freeze the run indicator for the rest of the editor's life, while the
  rest of the popup kept working, so the failure was invisible.
- Cache only a genuine backend resolution in ProjectRoot. The resolver
  fell back to the caller's hint, i.e. the synthetic JetBrains Client path
  in split mode, and cached it for the project lifetime, permanently
  breaking run/stats/PR/gh calls after one transient RPC failure.
- Stop processes started in a worktree before it is removed, so git no
  longer deletes the working directory from under a live process.

Threading and platform contracts:
- Run configuration lookup, cloning, and serialization now happen inside a
  read action; third-party configurations touch the project model there.
- Read the worktree name store on Dispatchers.IO instead of the RPC thread.
- Serialize clone-cache mutation with a mutex so a double dispatch cannot
  create two clones that both execute and lose one process's tracking.

Leaks and performance:
- Drop the unbounded map of every clone ever executed in favour of an
  identity scan over the bounded clone cache, and prune entries on release.
- Share one backend states subscription across all worktree editors via a
  new project-level WorktreeRunStatusService, instead of one stream each.
- Register the session editor panel and the run control's cleanup before
  the resources they own, so a failure mid-construction cannot leak a
  coroutine scope or a stream reference.

Also: rethrow CancellationException in KiloRunService instead of turning it
into a failed result, route notifications through KiloNotifications, resolve
projects with the same path normalization the workspace API uses, and drop
the popup's test-only default arguments.
Add translations for the worktree run popup keys introduced by this PR across all JetBrains locale bundles.

Remove the committed planning document from the PR so JetBrains changes follow the package guidance to keep .kilo/plans files out of commits.
…check

Address PR review on the worktree run feature.

release() no longer misses a run/build whose exec is already in flight.
It now takes the clone lock, marks the worktree released, and keeps the
cached clone so a delayed processStarted still resolves its key; that
started process is stopped instead of tracked, so nothing keeps running
against a directory about to be deleted. Terminated processes drop their
released clones in the listener, and a fresh run/build clears its own
worktree so a path recreated later works again.

resolve() matches open projects with FileUtil.pathsEqual after a
best-effort Path.normalize instead of the workspace URL decoder. The
decoder returned null on a lone '%' (e.g. .../100%done) and compared
case-sensitively, which broke every call for such roots and regressed
Windows/macOS path identity.
WorktreeController.remove calls service<KiloRunService>().release(...) to
stop worktree run processes before removal. AgentManagerPanelTest never
replaced that app service, so the call went through the real durable RPC
path with no backend and the removal coroutine never reached
service.remove(...), failing the merged-in "deleting a worktree closes and
releases its worktree session editor" test.

Replace KiloRunService with FakeRunRpcApi in setUp, matching the pattern
already used for KiloWorktreeService/GhStatusCoordinator in this test and
for KiloRunService in WorktreeRunControlTest.
Make the build and run menu discoverable and keep the worktree header compact by placing Open next and showing Terminal as an icon.
@kirillk
kirillk enabled auto-merge August 28, 2026 19:45
@kirillk
kirillk disabled auto-merge August 28, 2026 20:01
kirillk and others added 2 commits August 28, 2026 16:25
WorktreeController now releases run processes before deletion, but its tests left KiloRunService connected to the real backend. Register the existing fake RPC so removal completes deterministically without a backend.

Cover release-before-delete ordering and duplicate removal while release is pending.
@kirillk
kirillk merged commit 5e02825 into main Aug 28, 2026
24 checks passed
@kirillk
kirillk deleted the investigate-jetbrains-agent-manager-run-feature branch August 28, 2026 20:43
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.

2 participants