Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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/scheduled-wakeup-status.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": minor
---

Show a clock status on Agent Manager tabs and worktrees when a session is waiting for a scheduled wakeup.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions packages/kilo-ui/src/components/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ const icons: Record<string, { path: string; viewBox: string }> = {
viewBox: "0 0 20 20",
path: `<circle cx="10" cy="10" r="7.5" stroke="currentColor"/><circle cx="10" cy="10" r="4.5" stroke="currentColor"/><circle cx="10" cy="10" r="1.5" fill="currentColor"/>`,
},
clock: {
viewBox: "0 0 20 20",
path: `<circle cx="10" cy="10" r="7" stroke="currentColor" stroke-width="1.25"/><path d="M10 5.75V10L13.25 11.75" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>`,
},
local: {
viewBox: "0 0 20 20",
path: `<rect x="2.5" y="3.5" width="15" height="10" rx="1" stroke="currentColor"/><path d="M6 16.5H14" stroke="currentColor" stroke-linecap="square"/><path d="M10 13.5V16.5" stroke="currentColor"/>`,
Expand Down
58 changes: 57 additions & 1 deletion packages/kilo-vscode/src/KiloProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { removeMcp } from "./kilo-provider/remove-config-item"
import { MarketplaceService } from "./services/marketplace"
import type { RemoteStatusService } from "./services/RemoteStatusService"
import { resolveProjectDirectory } from "./project-directory"
import { seedSessionStatuses } from "./session-status"
import { seedSessionStatuses, seedSessionWakeups } from "./session-status"
import { normalizeEnhancePromptErrorMessage } from "./enhance-prompt-error"
import { retry } from "./services/cli-backend/retry"
import { integratedBrowserUseSystemChrome } from "./services/browser-automation/chrome-setting"
Expand Down Expand Up @@ -442,6 +442,8 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
private readonly refreshes = new Map<string, number>()
private readonly anacondaDesktop = new AnacondaDesktopBridge()
private sessionStatusMap = new Map<string, SessionStatus["type"]>() // Latest status used for destructive config warnings.
private wakeupSessions = new Set<string>() // Sessions with a pending wakeup at the last seed.
private wakeupSeeding = false // In-flight guard so concurrent transitions share one seed.
private activity: Activity = "idle"
private active = false
private caption: string | undefined
Expand Down Expand Up @@ -803,6 +805,7 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
this.postMessage({ type: "gitStatus", repo: this.cachedGitRepo })

void this.seedSessionStatusMap()
void this.seedSessionWakeups()

this.sendRemoteStatus()
}
Expand Down Expand Up @@ -1952,6 +1955,11 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
// for the busy-session warning on Save.
if (event.type === "session.status") return true

// session.wakeup must also always pass through. Wakeups are cheap and
// worktree sessions without an open tab still need their scheduled
// indicator kept current.
if (event.type === "session.wakeup") return true

// session.deleted must always pass through so the webview can run its cleanup
// (messages, parts, stash, todos, permissions, drafts, etc.) — including for
// sessions that were never explicitly tracked here (e.g. child sessions
Expand Down Expand Up @@ -3285,6 +3293,39 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
)
}

private async seedSessionWakeups(): Promise<void> {
if (!this.client || this.connectionState !== "connected") return
if (this.wakeupSeeding) return
this.wakeupSeeding = true
try {
const { seen, complete } = await seedSessionWakeups(
this.client,
this.connectionService.getKnownDirectories(),
(message) => this.postMessage(message),
(sessionID) => !this.removedSessionIds.has(sessionID),
)
// Only reconcile when every directory answered. A failed directory is
// absent from `seen`, so clearing on a partial result would drop valid
// wakeups for that directory's sessions.
if (complete) {
// A wakeup that fired or was cancelled while disconnected is absent
// from the seed response, so clear any session the previous seed saw.
for (const sessionID of this.wakeupSessions) {
if (!seen.has(sessionID)) this.postMessage({ type: "sessionWakeup", sessionID, pending: 0 })
}
this.wakeupSessions = seen
Comment thread
marius-kilocode marked this conversation as resolved.
Resolved
} else {
// Keep tracking sessions from failed directories so a later complete
// seed can still reconcile them.
this.wakeupSessions = new Set([...this.wakeupSessions, ...seen])
}
} catch (error) {
console.error("[Kilo New] KiloProvider: Failed to seed session wakeups:", error)
} finally {
this.wakeupSeeding = false
}
}

/**
* Fetch the latest merged config and push it as configUpdated.
* Called when global.config.updated SSE fires (config changed without a full dispose).
Expand Down Expand Up @@ -5131,6 +5172,20 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
return
}

// session.wakeup also passes the pre-filter for all providers. Forward it
// before the trackedSessionIds guard so worktree sessions without an open
// tab keep their scheduled indicator current.
if (event.type === "session.wakeup") {
const sid = event.properties.sessionID
if (this.removedSessionIds.has(sid)) return
// Track live sessions too, so a wakeup cancelled while disconnected is
// still reconciled to zero by the next complete seed.
if (event.properties.pending > 0) this.wakeupSessions.add(sid)
else this.wakeupSessions.delete(sid)
this.postMessage({ type: "sessionWakeup", sessionID: sid, pending: event.properties.pending })
return
}

// Extract sessionID from the event
if (event.type === "session.created" && this.adoptPendingFollowup(event.properties.info)) {
return
Expand Down Expand Up @@ -5854,6 +5909,7 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
this.requests.clear()
this.epochs.clear()
this.sessionStatusMap.clear()
this.wakeupSessions.clear()
this.ignoreController?.dispose()
this.chatAutocomplete?.dispose()
disposeGitChangesTarget()
Expand Down
77 changes: 44 additions & 33 deletions packages/kilo-vscode/src/kilo-provider-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export type WebviewMessage =
message: Record<string, unknown>
}
| { type: "sessionStatus"; sessionID: string; status: string; attempt?: number; message?: string; next?: number }
| { type: "sessionWakeup"; sessionID: string; pending: number }
| {
type: "sessionTurnClosed"
sessionID: string
Expand Down Expand Up @@ -531,42 +532,46 @@ function statusExtra(info: Extract<Event, { type: "session.status" }>["propertie
return {}
}

export function mapSSEEventToWebviewMessage(event: StreamEvent, sessionID: string | undefined): WebviewMessage {
if (event.type === "sync") {
switch (event.name) {
case "message.updated.1": {
const info = event.data.info
return {
type: "messageCreated",
message: {
...info,
createdAt: new Date(info.time.created).toISOString(),
},
}
function mapSyncEvent(event: SyncEvent, sessionID: string | undefined): WebviewMessage {
switch (event.name) {
case "message.updated.1": {
const info = event.data.info
return {
type: "messageCreated",
message: {
...info,
createdAt: new Date(info.time.created).toISOString(),
},
}
case "message.removed.1":
return {
type: "messageRemoved",
sessionID: event.data.sessionID,
messageID: event.data.messageID,
}
case "message.part.updated.1":
case "message.part.removed.1":
return mapPartEvent(event, sessionID)
case "session.created.1":
return {
type: "sessionCreated",
session: sessionToWebview(event.data.info),
}
case "session.updated.1":
return null
case "session.deleted.1":
return {
type: "sessionDeleted",
sessionID: event.data.sessionID,
}
}
case "message.removed.1":
return {
type: "messageRemoved",
sessionID: event.data.sessionID,
messageID: event.data.messageID,
}
case "message.part.updated.1":
case "message.part.removed.1":
return mapPartEvent(event, sessionID)
case "session.created.1":
return {
type: "sessionCreated",
session: sessionToWebview(event.data.info),
}
case "session.updated.1":
return null
case "session.deleted.1":
return {
type: "sessionDeleted",
sessionID: event.data.sessionID,
}
default:
return null
}
}

export function mapSSEEventToWebviewMessage(event: StreamEvent, sessionID: string | undefined): WebviewMessage {
if (event.type === "sync") return mapSyncEvent(event, sessionID)
if (event.type === "message.part.delta") return mapPartEvent(event, sessionID)
switch (event.type) {
case "session.status": {
Expand All @@ -580,6 +585,12 @@ export function mapSSEEventToWebviewMessage(event: StreamEvent, sessionID: strin
...extra,
}
}
case "session.wakeup":
return {
type: "sessionWakeup" as const,
sessionID: event.properties.sessionID,
pending: event.properties.pending,
}
case "session.turn.close":
return {
type: "sessionTurnClosed",
Expand Down
1 change: 1 addition & 0 deletions packages/kilo-vscode/src/kilo-provider/native-tab-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const icons: Record<Activity, string> = {
waiting: "⚠",
error: "⚠",
done: "✓",
scheduled: "◷",
}

export const nativeTitle = (session: Session | null, state: Activity = "idle", label?: string) => {
Expand Down
50 changes: 26 additions & 24 deletions packages/kilo-vscode/src/services/cli-backend/connection-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,31 @@ function resolveSyncSessionId(
return event.data.sessionID
}

const sessionScopedTransientEvents = new Set<string>([
"session.status",
"session.turn.open",
"session.turn.close",
"session.idle",
"session.error",
"session.wakeup",
"todo.updated",
"message.part.delta",
"permission.asked",
"permission.replied",
"question.asked",
"question.replied",
"question.rejected",
"suggestion.shown",
"suggestion.accepted",
"suggestion.dismissed",
"session.network.asked",
"session.network.replied",
"session.network.rejected",
"session.network.restored",
])

function resolveTransientSessionId(event: TransientPayload): string | undefined {
switch (event.type) {
case "session.status":
case "session.turn.open":
case "session.turn.close":
case "session.idle":
case "session.error":
case "todo.updated":
case "message.part.delta":
case "permission.asked":
case "permission.replied":
case "question.asked":
case "question.replied":
case "question.rejected":
case "suggestion.shown":
case "suggestion.accepted":
case "suggestion.dismissed":
case "session.network.asked":
case "session.network.replied":
case "session.network.rejected":
case "session.network.restored":
return event.properties.sessionID
default:
return undefined
}
if (!sessionScopedTransientEvents.has(event.type)) return undefined
const properties = (event as { properties?: { sessionID?: string } }).properties
return properties?.sessionID
}
34 changes: 34 additions & 0 deletions packages/kilo-vscode/src/session-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,37 @@ export async function seedSessionStatuses(
console.error("[Kilo New] KiloProvider: Failed to seed session statuses:", error)
}
}

/**
* Fetch pending wakeup counts for every known directory and seed the webview.
* Wakeups are directory scoped, unlike session status, so each directory needs
* its own request. A failed directory is logged and skipped: one missing
* directory must not blank the others. Returns the session IDs that still hold
* a wakeup and whether every directory answered, so the caller can reconcile a
* previous seed to zero only when the result is complete.
*/
export async function seedSessionWakeups(
client: KiloClient,
dirs: string[],
post: (msg: unknown) => void,
accept?: (sessionID: string) => boolean,
): Promise<{ seen: Set<string>; complete: boolean }> {
const seen = new Set<string>()
let complete = true
await Promise.all(
dirs.map(async (dir) => {
try {
const result = await client.kilocode.wakeups({ directory: dir }, { throwOnError: true })
for (const item of result.data ?? []) {
if (accept && !accept(item.sessionID)) continue
seen.add(item.sessionID)
post({ type: "sessionWakeup", sessionID: item.sessionID, pending: item.pending })
}
} catch (error) {
complete = false
console.error(`[Kilo New] KiloProvider: Failed to seed session wakeups for ${dir}:`, error)
}
}),
)
return { seen, complete }
}
10 changes: 10 additions & 0 deletions packages/kilo-vscode/tests/unit/connection-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ describe("resolveEventSessionId", () => {
expect(resolveEventSessionId(event, noLookup)).toBe("s3")
})

it("routes session.wakeup events", () => {
const event = {
id: "e6-wakeup",
type: "session.wakeup",
properties: { sessionID: "s12", pending: 2 },
} satisfies Payload

expect(resolveEventSessionId(event, noLookup)).toBe("s12")
})

it("routes transient message deltas", () => {
const event = {
id: "e7",
Expand Down
4 changes: 2 additions & 2 deletions packages/kilo-vscode/tests/unit/early-message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ describe("routeEarlyMessage activity", () => {
it("forwards authoritative webview presentation state without interpreting session events", async () => {
const calls: unknown[] = []
const ctx = { activity: (state: unknown) => calls.push(state) } as Ctx
for (const state of ["busy", "waiting", "done", "error", "idle"]) {
for (const state of ["busy", "waiting", "done", "scheduled", "error", "idle"]) {
expect(await routeEarlyMessage({ type: "sessionActivity", state }, ctx)).toBe(true)
}
expect(calls).toEqual(["busy", "waiting", "done", "error", "idle"])
expect(calls).toEqual(["busy", "waiting", "done", "scheduled", "error", "idle"])
})
})

Expand Down
Loading
Loading