Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/preserve-background-agent-dismissals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Keep dismissed background agents hidden when switching sessions or returning from History and empty chats.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ export const BackgroundAgents: Component<{ readonly?: boolean }> = (props) => {
const [open, setOpen] = createSignal(false)
const [jobs, setJobs] = createSignal<BackgroundJobInfo[]>([])
const [loaded, setLoaded] = createSignal(false)
const [hidden, setHidden] = createSignal<Set<string>>(new Set())
const [mounted, setMounted] = createSignal(false)
let pending: string | undefined
let revision = 0

createEffect(
on(session.currentSessionID, () => {
setHidden(new Set<string>())
setLoaded(false)
setJobs([])
pending = undefined
Expand Down Expand Up @@ -95,7 +93,12 @@ export const BackgroundAgents: Component<{ readonly?: boolean }> = (props) => {
return fallback()
})

const visible = createMemo(() => agents().filter((agent) => showBackgroundAgent(agent, hidden())))
const visible = createMemo(() => {
const id = session.currentSessionID()
if (!id) return []
const hidden = session.dismissedBackgroundJobs(id)
return agents().filter((agent) => showBackgroundAgent(agent, hidden))
})
const summary = createMemo(() => {
const running = visible().filter((agent) => agent.status === "running").length
const total = visible().length
Expand Down Expand Up @@ -174,13 +177,16 @@ export const BackgroundAgents: Component<{ readonly?: boolean }> = (props) => {
vscode.postMessage({ type: "cancelBackgroundJob", jobID: agent.jobID, sessionID: id, requestID: pending })
}

const hide = (ids: string[]) => {
const id = session.currentSessionID()
if (id) session.dismissBackgroundJobs(id, ids)
}

const hideFinished = () =>
setHidden(
new Set(
agents()
.filter((agent) => agent.status !== "running")
.map((agent) => agent.jobID),
),
hide(
agents()
.filter((agent) => agent.status !== "running")
.map((agent) => agent.jobID),
)

return (
Expand Down Expand Up @@ -334,7 +340,7 @@ export const BackgroundAgents: Component<{ readonly?: boolean }> = (props) => {
aria-label={`${language.t("task.backgroundAgents.dismiss")}: ${label(agent)}`}
onClick={(event: MouseEvent) => {
event.stopPropagation()
setHidden((current) => new Set(current).add(agent.jobID))
hide([agent.jobID])
}}
>
<span data-slot="task-header-agent-action-label">
Expand Down
2 changes: 2 additions & 0 deletions packages/kilo-vscode/webview-ui/src/context/session-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export interface SessionContextValue {
// Tool parts for a specific session, maintained incrementally for streaming views
getSessionToolParts: (sessionID: string) => ToolPart[]
getSessionToolCount: (sessionID: string) => number
dismissedBackgroundJobs: (sessionID: string) => ReadonlySet<string>
dismissBackgroundJobs: (sessionID: string, ids: string[]) => void

// Hidden after model changes so switching models can clear stale provider errors
// without removing messages and their checkpoint restore actions.
Expand Down
13 changes: 13 additions & 0 deletions packages/kilo-vscode/webview-ui/src/context/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ export const SessionProvider: ParentComponent = (props) => {
// Cloud session preview state
const [cloudPreviewId, setCloudPreviewId] = createSignal<string | null>(null)
const [hiddenErrors, setHiddenErrors] = createSignal<Set<string>>(new Set())
const [dismissals, setDismissals] = createStore<Record<string, ReadonlySet<string>>>({})
const dismissedBackgroundJobs = (id: string): ReadonlySet<string> => dismissals[id] ?? new Set<string>()
const dismissBackgroundJobs = (id: string, ids: string[]) => {
if (!ids.length) return
setDismissals(id, (current) => new Set([...(current ?? []), ...ids]))
}

// Live worktree diff stats from extension polling
const [worktreeStats, setWorktreeStats] = createSignal<
Expand Down Expand Up @@ -978,6 +984,11 @@ export const SessionProvider: ParentComponent = (props) => {

case "sessionDeleted":
handleSessionDeleted(message.sessionID)
setDismissals(
produce((map) => {
delete map[message.sessionID]
}),
)
break

case "messageRemoved":
Expand Down Expand Up @@ -2879,6 +2890,8 @@ export const SessionProvider: ParentComponent = (props) => {
getParts,
getSessionToolParts,
getSessionToolCount,
dismissedBackgroundJobs,
dismissBackgroundJobs,
isErrorHidden: (messageID: string) => hiddenErrors().has(messageID),
hydrateParts,
todos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export function mockSessionValue(overrides?: {
getParts: () => [],
getSessionToolParts: () => [],
getSessionToolCount: () => 0,
dismissedBackgroundJobs: () => new Set<string>(),
dismissBackgroundJobs: noop,
isErrorHidden: () => false,
hydrateParts: noop,
todos: () => [],
Expand Down
Loading