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/fix-indexing-status-consent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Keep codebase indexing status current and support workspace paths with non-ASCII characters.
74 changes: 54 additions & 20 deletions packages/kilo-vscode/src/KiloProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
private indexingProjectId: string | undefined
private indexingSettingsRequest = 0
private indexingStatusRequest = 0
private indexingTarget?: { source: string; directory: string; projectId?: string }
private slimEditMetadata = true

private pendingFollowup: Followup | null = null
Expand Down Expand Up @@ -1800,6 +1801,9 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
(payload, directory) => {
const event = unwrapSyncEvent(payload)
if (!event) return false
if (event.type === "indexing.status" && directory) {
return sameDirectory(directory, this.indexingScope.directory)
}
if (
directory &&
directory !== "global" &&
Expand Down Expand Up @@ -1857,6 +1861,8 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
this.postConnectionState(error)

if (state === "connected") {
const target = this.indexingScope
this.fetchAndSendIndexingStatus(target.directory, target.projectId)
this.flushPendingKiloModel()
// Fire config warnings independently so a failure in the
// sequential await chain doesn't prevent warnings from being shown
Expand Down Expand Up @@ -2907,6 +2913,13 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
}
}

private get indexingScope() {
const source = this.getWorkspaceDirectory(this.currentSession?.id)
const target = this.indexingTarget
if (target && (target.source === source || sameDirectory(target.source, source))) return target
return { source, directory: source, projectId: undefined }
}

private async fetchAndSendIndexingStatus(directory?: string, projectId?: string): Promise<void> {
if (!this.client || !this.extensionContext) {
if (this.cachedIndexingStatusMessage) {
Expand All @@ -2917,15 +2930,20 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper

const config = this.connectionService.getServerConfig()
if (!config) return
const request = ++this.indexingStatusRequest
const source = this.getWorkspaceDirectory(this.currentSession?.id)
const dir = directory ?? source
if (!dir) return
const target = { source, directory: dir, projectId }
this.indexingTarget = target

try {
const dir = directory ?? this.getWorkspaceDirectory(this.currentSession?.id)
if (!dir) return
const store = indexingConsentStore(this.extensionContext)
const project = await store.project(dir)
if (target !== this.indexingScope) return
target.directory = project.root
const request = ++this.indexingStatusRequest
Comment thread
marius-kilocode marked this conversation as resolved.
const status = await this.syncIndexingConsent(project.root, store.enabled(project.id), config)
if (request !== this.indexingStatusRequest) return
if (request !== this.indexingStatusRequest || target !== this.indexingScope) return
const message = {
type: "indexingStatusLoaded",
status,
Expand Down Expand Up @@ -3807,9 +3825,24 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
await this.sendIndexingSettings(project.id)
const config = this.connectionService.getServerConfig()
if (!config) return
if (this.indexingProjectId !== project.id) {
await this.syncIndexingConsent(project.root, enabled, config)
return
}
const target = {
source: this.getWorkspaceDirectory(this.currentSession?.id),
directory: project.root,
projectId: project.id,
}
this.indexingTarget = target
const request = ++this.indexingStatusRequest
const status = await this.syncIndexingConsent(project.root, enabled, config)
if (request !== this.indexingStatusRequest || this.indexingProjectId !== project.id) return
if (
(enabled && request !== this.indexingStatusRequest) ||
target !== this.indexingScope ||
this.indexingProjectId !== project.id
)
return
const message = { type: "indexingStatusLoaded", status, projectId: project.id }
this.cachedIndexingStatusMessage = message
this.postMessage(message)
Expand All @@ -3826,7 +3859,7 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
headers: {
Authorization: `Basic ${auth}`,
"Content-Type": "application/json",
"x-kilo-directory": dir,
"x-kilo-directory": encodeURIComponent(dir),
},
body: JSON.stringify({ enabled }),
})
Expand Down Expand Up @@ -4753,6 +4786,20 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
* Filters events by project ID and tracked session IDs so each webview only sees its own sessions.
*/
private handleEvent(event: ProviderEvent, directory?: string): void {
if (event.type === "indexing.status") {
const target = this.indexingScope
if (directory && !sameDirectory(directory, target.directory)) return
this.indexingStatusRequest++
const message = {
type: "indexingStatusLoaded",
status: event.properties.status,
projectId: target.projectId,
}
this.cachedIndexingStatusMessage = message
this.postMessage(message)
return
}

if (event.type === "kilo-sessions.remote-status-changed") {
this.remoteService?.updateFromEvent({ enabled: event.properties.enabled, connected: event.properties.connected })
return
Expand Down Expand Up @@ -4859,13 +4906,7 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
// message.part.* events are always session-scoped; drop if session unknown.
if (!sessionID && isSessionScopedPartEvent(event.type)) return
if (this.postModelUsageChanged(event, sessionID)) return
if (
event.type !== "indexing.status" &&
event.type !== "session.deleted" &&
sessionID &&
!this.trackedSessionIds.has(sessionID)
)
return
if (event.type !== "session.deleted" && sessionID && !this.trackedSessionIds.has(sessionID)) return

if (event.type === "message.part.updated") this.refreshGitStatusFromPart(event, sessionID)

Expand Down Expand Up @@ -4978,10 +5019,6 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
)
}

if (event.type === "indexing.status" && directory) {
if (!sameDirectory(directory, this.getWorkspaceDirectory(this.currentSession?.id))) return
}

const msg = isLegacySyncEvent(event)
? this.mapSyncEventToWebviewMessage(event)
: mapSSEEventToWebviewMessage(event, sessionID)
Expand All @@ -4996,9 +5033,6 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
this.postMessage({ ...next, revision: ++this.sandboxRevision })
return
}
if (next.type === "indexingStatusLoaded") {
this.cachedIndexingStatusMessage = next
}
this.streams.flush(sessionID)
this.postMessage(next)
const sid = event.type === "session.turn.close" ? event.properties.sessionID : sessionID
Expand Down
4 changes: 3 additions & 1 deletion packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,9 @@ describe("KiloProvider — pending session refresh on reconnect", () => {
// Find the onStateChange callback that handles "connected"
const connectedIdx = provider.indexOf('state === "connected"')
expect(connectedIdx, '"connected" state handler must exist').toBeGreaterThan(-1)
const snippet = provider.slice(connectedIdx, connectedIdx + 800)
const end = provider.indexOf("this.unsubscribeNotificationDismiss", connectedIdx)
expect(end, "notification subscription must follow connection handler").toBeGreaterThan(connectedIdx)
const snippet = provider.slice(connectedIdx, end)
expect(snippet, "must call flushPendingSessionRefresh from connected handler").toContain(
'this.flushPendingSessionRefresh("sse-connected")',
)
Expand Down
Loading
Loading