Skip to content

feat: CLI backend integration for VSCode extension#134

Merged
markijbema merged 10 commits intomark/top-bar-buttonsfrom
mark/cli-backend-integration
Feb 5, 2026
Merged

feat: CLI backend integration for VSCode extension#134
markijbema merged 10 commits intomark/top-bar-buttonsfrom
mark/cli-backend-integration

Conversation

@markijbema
Copy link
Contributor

@markijbema markijbema commented Feb 5, 2026

Summary

This PR implements CLI backend integration to enable communication between the VSCode extension and the Kilo CLI backend server.

Implementation Plan Reference

See cli-backend-integration-plan-v2.md for the detailed implementation plan.

Key Features

Server Lifecycle Management

  • Start/stop CLI backend server as child process
  • Health check monitoring with automatic restart
  • Graceful shutdown on extension deactivation

HTTP Client

  • REST API client for backend communication
  • Request/response handling with proper error management
  • Configurable base URL and timeout settings

SSE Streaming Client

  • Server-Sent Events client for real-time streaming responses
  • Event-based architecture for handling partial responses
  • Automatic reconnection handling

Webview Integration

  • Message passing between webview and extension host
  • Bridging webview requests to CLI backend
  • Streaming response forwarding to webview

Files Changed

New Files

  • src/services/cli-backend/types.ts - Type definitions for API requests/responses
  • src/services/cli-backend/server-manager.ts - Server lifecycle management
  • src/services/cli-backend/http-client.ts - REST API client
  • src/services/cli-backend/sse-client.ts - SSE streaming client
  • src/services/cli-backend/index.ts - Main exports
  • src/types/eventsource.d.ts - EventSource type declarations

Modified Files

  • package.json - Added eventsource dependency
  • src/KiloProvider.ts - Integrated with CLI backend services
  • src/extension.ts - Updated to pass extension context
  • .vscodeignore - Updated exclusions
CleanShot 2026-02-05 at 15 06 58@2x

@markijbema markijbema force-pushed the mark/cli-backend-integration branch from dc83b2d to 8674c36 Compare February 5, 2026 12:14
@markijbema markijbema changed the base branch from dev to mark/top-bar-buttons February 5, 2026 12:15
Implement CLI backend integration to enable communication between the
VSCode extension and the Kilo CLI backend server.

New files:
- src/services/cli-backend/types.ts - Type definitions for API requests/responses
- src/services/cli-backend/server-manager.ts - Server lifecycle management
- src/services/cli-backend/http-client.ts - REST API client for backend communication
- src/services/cli-backend/sse-client.ts - SSE streaming client for real-time events
- src/services/cli-backend/index.ts - Main exports
- src/types/eventsource.d.ts - EventSource type declarations

Modified files:
- package.json - Added eventsource dependency
- src/KiloProvider.ts - Integrated with CLI backend services
- src/extension.ts - Updated to pass extension context
- .vscodeignore - Updated exclusions

Key features:
- Server lifecycle management (start/stop/health checks)
- HTTP client for REST API communication
- SSE client for streaming responses
- Webview integration for message passing
@markijbema markijbema force-pushed the mark/cli-backend-integration branch from 988c0cf to ac47928 Compare February 5, 2026 12:26
Update all debug console.log statements to use the prefix '[Kilo New]'
followed by the component name for consistent logging across the CLI
backend integration.

Changed prefixes:
- [KiloProvider] -> [Kilo New] KiloProvider:
- [ServerManager] -> [Kilo New] ServerManager:
- [CLI Server] -> [Kilo New] ServerManager:
- [SSEClient] -> [Kilo New] SSE:
- [Webview/App] -> [Kilo New] App:
The path was using '../../../opencode/bin/kilo' which resolved to
'kilo-with-vscode/opencode/bin/kilo' instead of the correct
'kilo-with-vscode/packages/opencode/bin/kilo'.

Fixed by changing to '../../opencode/bin/kilo' which correctly navigates
from packages/kilo-vscode/dist/ to packages/opencode/bin/kilo.
* Get or start the server instance
*/
async getServer(): Promise<ServerInstance> {
console.log('[Kilo New] ServerManager: 🔍 getServer called');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix this everywhere because i now have 2 kilo extensions running and i want to find these messages

process: ChildProcess
}

export class ServerManager {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some point we have to think about how exactly we want to do this, for production we probably need a release per platform. For now my criterium is that this 'just works' when i run the extension from my vscode.

@markijbema markijbema force-pushed the mark/cli-backend-integration branch from 5ff07b9 to 7a0d3b6 Compare February 5, 2026 14:05
@markijbema markijbema marked this pull request as ready for review February 5, 2026 14:06
@markijbema markijbema requested a review from RSO February 5, 2026 14:06
@@ -0,0 +1,180 @@
import EventSource from "eventsource"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: eventsource is declared with export = but imported as default

packages/kilo-vscode/src/types/eventsource.d.ts uses export = EventSource, which (with the current packages/kilo-vscode/tsconfig.json not enabling esModuleInterop) can make import EventSource from "eventsource" fail type-checking. Use a require-style import here (or enable esModuleInterop).

Suggested change
import EventSource from "eventsource"
import EventSource = require("eventsource")

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That suggested change is wild and wrong, as it still does import.

type: "permission.replied"
properties: { sessionID: string; requestID: string; reply: "once" | "always" | "reject" }
}
| { type: "todo.updated"; properties: { sessionID: string; items: TodoItem[] } }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: SSE todo.updated payload shape doesn't match server (todos vs items)

Server publishes todo.updated with properties.todos (see packages/opencode/src/session/todo.ts), but the VS Code client expects properties.items in packages/kilo-vscode/src/services/cli-backend/types.ts. This will silently drop todo updates at runtime.

Suggested change
| { type: "todo.updated"; properties: { sessionID: string; items: TodoItem[] } }
| { type: "todo.updated"; properties: { sessionID: string; todos: TodoItem[] } }


// Create HttpClient and SSEClient instances
this.httpClient = new HttpClient(config);
this.sseClient = new SSEClient(config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Re-resolving the webview can leak old SSE/EventSource connections

initializeConnection() always replaces this.sseClient / this.httpClient without disposing previous instances. If the webview is resolved multiple times (reload / view recreated), this can leave the old EventSource connected and duplicate event delivery. Consider disposing existing clients (or guarding initializeConnection() so it only runs once per extension activation).

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Feb 5, 2026

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 2
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

CRITICAL

File Line Issue
packages/kilo-vscode/src/services/cli-backend/sse-client.ts 1 eventsource export = typing vs default import can break type-checking

WARNING

File Line Issue
packages/kilo-vscode/src/services/cli-backend/types.ts 73 todo.updated payload mismatch (todos on server vs items on client) prevents todo updates
packages/kilo-vscode/src/KiloProvider.ts 86 Re-resolving the webview can leak/duplicate SSE connections (no disposal/guard before reconnect)
Files Reviewed (11 files)

@@ -0,0 +1,180 @@
import EventSource from "eventsource"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That suggested change is wild and wrong, as it still does import.

@markijbema markijbema merged commit 635ff72 into mark/top-bar-buttons Feb 5, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants