Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
af2c45a
fix(jetbrains): make gh/PR focus sync responsive without overwhelming…
kirillk Aug 31, 2026
23007e1
fix(jetbrains): keep PR lookups to one at a time
kirillk Aug 31, 2026
c35dc1c
test(jetbrains): wait for both update cycles in the session hook test
kirillk Aug 31, 2026
c9a01dc
test(jetbrains): wait for dropped run state after async termination
kirillk Aug 31, 2026
7e5ddc0
feat(jetbrains): show PR review and CI status on worktree rows
kirillk Aug 31, 2026
aebd040
feat(jetbrains): show PR detail on worktree row hover
kirillk Aug 31, 2026
2eac9d5
fix(jetbrains): keep a PR visible when gh refuses review fields
kirillk Aug 31, 2026
f14bc5e
fix(jetbrains): stop remeasuring worktree rows on every poll
kirillk Aug 31, 2026
6d7939f
fix(jetbrains): release a popup body that could not be placed
kirillk Aug 31, 2026
12c0aff
fix(jetbrains): quiet the PR indicators and line them up on worktree …
kirillk Aug 31, 2026
3f13f5f
fix(jetbrains): stack the worktree row popup one fact per line
kirillk Aug 31, 2026
59c68e1
fix(jetbrains): wrap the popup PR title and shrink the running dot
kirillk Aug 31, 2026
3e4f957
fix(jetbrains): scroll the popup PR title instead of wrapping it
kirillk Aug 31, 2026
52c8af5
fix(jetbrains): give the popup scrollbar its own room and double the …
kirillk Aug 31, 2026
cad7d81
fix(jetbrains): measure a popup row's real width and pad it further
kirillk Aug 31, 2026
8d0c414
Merge remote-tracking branch 'origin/main' into brave-dune
kirillk Aug 31, 2026
6e33fdf
chore(jetbrains): accept a dev-sha suffix on a local build version
kirillk Aug 31, 2026
fc8077b
fix(jetbrains): report a spent GitHub budget instead of blanking the …
kirillk Aug 31, 2026
b6d02ec
fix(jetbrains): double the dwell before a worktree row popup opens
kirillk Aug 31, 2026
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
5 changes: 5 additions & 0 deletions .changeset/jetbrains-gh-focus-freshness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kilocode/kilo-jetbrains": patch
---

Show pull request and gh authorization changes right after you come back to the IDE. Returning from a long absence now reloads immediately instead of waiting out the poll, refreshes that arrive during a burst of window or tab switches are no longer dropped, and closing a dialog no longer triggers a needless lookup. A newly created worktree also gets its pull request badge without waiting for the cache to expire.
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,23 @@ class KiloWorktreeRpcApiImpl : KiloWorktreeRpcApi {
return synced.filter { Files.isDirectory(Path.of(it.path)) }
}

override suspend fun ghStatus(directory: String, github: Boolean): GhAvailability = withContext(Dispatchers.IO) {
probeGh(Path.of(directory).normalize(), "rpc", github)
override suspend fun ghStatus(directory: String, github: Boolean, maxAge: Long?): GhAvailability = withContext(Dispatchers.IO) {
probeGh(Path.of(directory).normalize(), "rpc", github, maxAge)
}

override suspend fun prStatus(directory: String): WorktreePrListDto = withContext(Dispatchers.IO) {
override suspend fun prStatus(directory: String, maxAge: Long?): WorktreePrListDto = withContext(Dispatchers.IO) {
val now = System.currentTimeMillis()
prs[directory]?.takeIf { now - it.time < PR_TTL }?.let { return@withContext it.value }
prs[directory]?.takeIf { usable(it.time, now, PR_TTL, maxAge) }?.let { return@withContext it.value }
val root = Path.of(directory).normalize()
// A gone directory reports nothing and is not cached, so a real availability problem found
// from a live directory still reaches the UI.
if (!Files.isDirectory(root)) {
LOG.info("pr status skipped, directory does not exist: $root")
return@withContext WorktreePrListDto()
}
val available = ghAvailable(root)
// A caller that rejected the cached PR list would not accept a cached availability verdict
// from the same moment either, so the ceiling carries into the gh probe.
val available = ghAvailable(root, maxAge = maxAge)
if (available != GhAvailability.OK) return@withContext WorktreePrListDto(available).also { prs[directory] = Timed(now, it) }
// Sync the worktree list before the per-worktree lookups so a worktree that was added and
// then deleted on disk is pruned instead of resolved from a directory that no longer exists.
Expand All @@ -229,21 +231,21 @@ class KiloWorktreeRpcApiImpl : KiloWorktreeRpcApi {
dto
}

override suspend fun branchStatus(directory: String, github: Boolean): BranchStatusDto = withContext(Dispatchers.IO) {
override suspend fun branchStatus(directory: String, github: Boolean, maxAge: Long?): BranchStatusDto = withContext(Dispatchers.IO) {
val now = System.currentTimeMillis()
// Keyed by directory + mode so flipping the GitHub integration setting cannot serve a
// cross-mode entry (a disabled-mode entry always has a null pr; an enabled-mode entry may
// not) for up to PR_TTL after the flip.
val key = "$directory|$github"
branches[key]?.takeIf { now - it.time < PR_TTL }?.let { return@withContext it.value }
branches[key]?.takeIf { usable(it.time, now, PR_TTL, maxAge) }?.let { return@withContext it.value }
val root = Path.of(directory).normalize()
if (!Files.isDirectory(root)) {
LOG.info("branch status skipped, directory does not exist: $root")
return@withContext BranchStatusDto()
}
val branch = runGit(root, "branch", "--show-current").stdout.trim()
val worktree = isLinkedWorktree(root)
val availability = ghAvailable(root, github)
val availability = ghAvailable(root, github, maxAge)
val lookup = if (github && availability == GhAvailability.OK && branch.isNotBlank()) {
resolver.resolve(directory, branch, baseBranch(root))
} else {
Expand Down Expand Up @@ -661,17 +663,19 @@ class KiloWorktreeRpcApiImpl : KiloWorktreeRpcApi {
* Resolves git/gh availability. When [github] is false, only git presence is checked and `gh`
* is never spawned — used while the user has turned off the GitHub integration setting.
*/
private fun ghAvailable(root: Path, github: Boolean = true): GhAvailability {
private fun ghAvailable(root: Path, github: Boolean = true, maxAge: Long? = null): GhAvailability {
if (!Files.isDirectory(root)) {
LOG.info("gh availability skipped dir=$root missing=true")
return GhAvailability.OK
}
val status = probeGh(root, "availability", github)
val status = probeGh(root, "availability", github, maxAge)
// A git-only probe can only return GIT_MISSING or OK, so the gh-binary re-check below is
// unreachable while github is false; the guard documents that explicitly.
if (!github || status != GhAvailability.MISSING) return status
val now = System.currentTimeMillis()
ghProbe?.takeIf { now - it.time < GH_PROBE_TTL }?.let { return it.value }
// Installing gh is the transition this long-lived entry hides, so a caller demanding
// freshness must be able to re-check the binary and not just the auth verdict.
ghProbe?.takeIf { usable(it.time, now, GH_PROBE_TTL, maxAge) }?.let { return it.value }
val res = runGh(root, "--version")
val value = if (res.ok) GhAvailability.OK else GhAvailability.MISSING
ghProbe = Timed(now, value)
Expand All @@ -683,7 +687,7 @@ class KiloWorktreeRpcApiImpl : KiloWorktreeRpcApi {
* spawns `gh` or touches [ghCache] (the cache mixes gh-auth verdicts with a boolean this probe
* would otherwise poison with a git-only "OK").
*/
private fun probeGh(root: Path, reason: String, github: Boolean = true): GhAvailability = synchronized(ghLock) {
private fun probeGh(root: Path, reason: String, github: Boolean = true, maxAge: Long? = null): GhAvailability = synchronized(ghLock) {
// A stale/removed worktree directory makes the process spawn fail, which would be
// misreported as GIT_MISSING. Treat a missing directory as "nothing to report" and
// don't cache it, so the next probe on a real directory still runs.
Expand All @@ -693,13 +697,13 @@ class KiloWorktreeRpcApiImpl : KiloWorktreeRpcApi {
}
val now = System.currentTimeMillis()
if (github) {
ghCache?.takeIf { now - it.time < GH_STATUS_TTL }?.let {
LOG.info("gh probe cache hit reason=$reason value=${it.value}")
ghCache?.takeIf { usable(it.time, now, GH_STATUS_TTL, maxAge) }?.let {
LOG.info("gh probe cache hit reason=$reason value=${it.value} ageMs=${now - it.time}")
return@synchronized it.value
}
}
val start = System.currentTimeMillis()
LOG.info("gh probe start reason=$reason dir=$root github=$github")
LOG.info("gh probe start reason=$reason dir=$root github=$github maxAge=${maxAge ?: "default"}")
val git = runGit(root, "--version")
if (!git.ok) {
// The directory can disappear between the check above and the spawn; a failed working
Expand Down Expand Up @@ -730,6 +734,17 @@ class KiloWorktreeRpcApiImpl : KiloWorktreeRpcApi {

}

/**
* Whether a cache entry written at [time] may still be served. [maxAge] is the caller's own ceiling
* on staleness: it can only tighten [ttl], never extend it, so an event-driven request can reject an
* entry the poll would have accepted while no caller is able to pin stale data in place past the TTL.
* A [maxAge] of 0 (or below) rejects every entry and forces the work to run.
*/
internal fun usable(time: Long, now: Long, ttl: Long, maxAge: Long?): Boolean {
val limit = maxAge?.coerceIn(0, ttl) ?: ttl
return now - time < limit
}

/** True when a process failed because its working directory is gone, not because the tool is absent. */
internal fun badDir(text: String): Boolean {
val msg = text.lowercase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,54 @@ class KiloWorktreeRpcApiImplTest {
assertEquals(GhAvailability.OK, api.prStatus(repo.resolve("missing").toString()).availability)
}

@Test
fun `a cache entry is usable only within both the ttl and the caller ceiling`() {
assertTrue(usable(time = 0, now = 89_999, ttl = 90_000, maxAge = null))
assertFalse(usable(time = 0, now = 90_000, ttl = 90_000, maxAge = null))

// A ceiling tightens: an entry the TTL alone would have served can be rejected, which is the
// only way a caller returning to the IDE can get past a cache filled before it left.
assertTrue(usable(time = 0, now = 9_999, ttl = 90_000, maxAge = 10_000))
assertFalse(usable(time = 0, now = 10_000, ttl = 90_000, maxAge = 10_000))

// ...and never extends, so no caller can pin stale data beyond the TTL.
assertFalse(usable(time = 0, now = 120_000, ttl = 90_000, maxAge = Long.MAX_VALUE))

// Zero forces the work to run, and a negative value is clamped to that rather than inverting
// the comparison into "always fresh".
assertFalse(usable(time = 0, now = 0, ttl = 90_000, maxAge = 0))
assertFalse(usable(time = 0, now = 0, ttl = 90_000, maxAge = -1))
}

@Test
fun `branch status serves its cache until a caller demands a fresher answer`() = runBlocking {
initRepo()
val dir = repo.resolve(".kilo").resolve("worktrees").resolve("cached")
git(repo, "worktree", "add", "-b", "feature/cached", dir.toString())
assertEquals("feature/cached", api.branchStatus(dir.toString()).branch)

git(dir, "checkout", "-b", "feature/moved")

// The default ceiling accepts the entry written above, so a change made meanwhile is invisible
// for as long as it lives — the staleness a returning caller has to be able to reject.
assertEquals("feature/cached", api.branchStatus(dir.toString()).branch)
assertEquals("feature/moved", api.branchStatus(dir.toString(), maxAge = 0).branch)
}

@Test
fun `branch status keeps serving the cache for a ceiling wider than the entry age`() = runBlocking {
initRepo()
val dir = repo.resolve(".kilo").resolve("worktrees").resolve("wide")
git(repo, "worktree", "add", "-b", "feature/wide", dir.toString())
assertEquals("feature/wide", api.branchStatus(dir.toString()).branch)

git(dir, "checkout", "-b", "feature/other")

// A returning caller passes the length of its absence, not zero: work that happened while it
// was away is still current, so a ceiling the entry fits inside must reuse it.
assertEquals("feature/wide", api.branchStatus(dir.toString(), maxAge = 60_000).branch)
}

@Test
fun `branch status skips a missing directory without caching the empty result`() = runBlocking {
initRepo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ internal class KiloToolWindowSetupService(
val listener = object : ContentManagerListener {
override fun selectionChanged(event: ContentManagerEvent) {
if (event.operation != ContentManagerEvent.ContentOperation.add) return
// Either direction: switching tabs is a deliberate act that often follows an
// authorization or PR change made elsewhere. The coordinator drops the submit
// when a probe is already running or too recent, so tab churn cannot stack up
// gh calls. Chat needs nothing further — SessionUi re-reads branch/PR state
// itself once it becomes showing.
// Only on the way in: opening the Agent Manager is a deliberate act that often
// follows an authorization or PR change made elsewhere, and this is the tab whose
// banner and badges read gh state. Switching to Chat reveals no gh-dependent UI —
// SessionUi re-reads branch/PR state itself once it becomes showing — so probing
// then only spends a call to warm a cache nothing is waiting on.
if (event.content !== agentContent) return
// The coordinator folds a submit that cannot run now into one trailing probe, so
// tab churn cannot stack up gh calls.
service<GhStatusCoordinator>().sync("tab-switch")
if (event.content === agentContent) agentManagerPanel.refresh()
agentManagerPanel.refresh()
}
}
toolWindow.contentManager.addContentManagerListener(listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ class AgentManagerPanel(
if (list.select(key)) list.focusList()
item(key)?.takeIf { controller.progress(it.id) == null }?.let { open(it, focus = false) }
}
// A fresh worktree changes what git reports, so bypass the refresh throttle instead of
// leaving the new row without its stats and PR badge until the next poll.
// A fresh worktree changes what git reports, so bypass both the refresh throttle and the
// backend's PR cache — that cache was populated before this worktree existed, so serving it
// would leave the new row without its badge until the entry aged out.
controller.onCreated = { created ->
project?.service<WorktreeStatusService>()?.refreshStats()
project?.service<WorktreeStatusService>()?.refreshPr(force = true)
project?.service<WorktreeStatusService>()?.refreshPr(force = true, maxAge = 0)
autoRunSetupScript(created)
}
controller.onReload = { sync() }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ai.kilocode.client.agentManager.worktree

/**
* How long the IDE spent out of focus, so a return can be answered in proportion to the absence
* rather than by a flat throttle.
*
* Both gh availability and pull-request state are things the user changes elsewhere — `gh auth login`
* in a terminal, a PR merged in a browser — so the chance that a cached answer went stale scales with
* the time away. A 400ms flicker cannot have contained any of that; a five-minute absence very likely
* did.
*
* Driven by `ApplicationActivationListener.applicationDeactivated`, which the platform already limits
* to focus leaving the application entirely (it fires only for a `WINDOW_DEACTIVATED` with no opposite
* window, so a popup or dialog that keeps focus inside the IDE never reaches it). The platform's own
* `delayedApplicationDeactivated` additionally waits out `application.deactivation.timeout` before
* confirming, because a heavyweight transient window can still produce that event; [REAL] applies the
* same predicate at return time instead, which needs no `Window` and no proactive timer.
*/
internal class Away(private val now: () -> Long) {
private var at: Long? = null

/** Records that focus left the application. */
fun left() {
at = now()
}

/**
* Consumes the pending absence and reports its length in milliseconds, or null when there was no
* absence worth acting on — the case a caller should answer by doing nothing at all.
*/
fun back(): Long? {
val start = at ?: return null
at = null
return (now() - start).takeIf { it >= REAL }
}

companion object {
/**
* Below this an absence is indistinguishable from a transient window that never meant to take
* focus out of the IDE, so returning from one is not evidence of anything. Mirrors the
* platform's `application.deactivation.timeout` default, the delay it waits before confirming
* a deactivation for the same reason.
*/
const val REAL = 1_500L

/**
* Absences at or past this point stop being explainable as window churn, so the caches
* covering them are no longer evidence about the current state.
*/
const val FRESH = 10_000L

/**
* The freshness ceiling a return from an absence of [gone] justifies: the absence itself once
* it is long enough to have contained an external change, and null below that to accept
* whatever the caches already hold.
*
* Passing the absence rather than zero is deliberate. Work done *during* the absence — a poll
* that ran while the window sat in the background, another panel's lookup — is still current
* and worth reusing; only answers that predate the departure have to be rejected.
*/
fun ceiling(gone: Long): Long? = gone.takeIf { it >= FRESH }
}
}
Loading
Loading