Skip to content

feat: add Kilo SDK-backed provider adapter#4089

Closed
Githubguy132010 wants to merge 17 commits into
pingdotgg:mainfrom
Githubguy132010:feat/kilo-provider-adapter
Closed

feat: add Kilo SDK-backed provider adapter#4089
Githubguy132010 wants to merge 17 commits into
pingdotgg:mainfrom
Githubguy132010:feat/kilo-provider-adapter

Conversation

@Githubguy132010

@Githubguy132010 Githubguy132010 commented Jul 17, 2026

Copy link
Copy Markdown

What Changed

Add a first-party kilo provider adapter that runs Kilo via @kilocode/sdk (managed kilo serve + SSE), not CLI scraping.

  • Contracts: KiloSettings (enabled, binaryPath, customModels), model defaults/display name, raw event source kilo.sdk.event
  • Server: kiloRuntime, KiloProvider, KiloAdapter, KiloDriver, BUILT_IN_DRIVERS + runtime layer wiring
  • Models inventory as flattened providerID/modelID from connected upstreams
  • Session/stream: start, promptAsync, interrupt, best-effort permission replies (once/always/reject)
  • Agents hidden in v1: default agent code; plan interaction mode → agent plan
  • UI: KiloIcon, settings card, model picker entry
  • Unit tests for runtime helpers, probe/flatten, adapter core paths, registry hydration

Why

Users need Kilo as a top-level T3 provider with the same reliability pattern as OpenCode (SDK + managed server), not a brittle CLI wrapper. Scope stays v1: no agent picker, no external server URL/password settings, no hard resume guarantees, text-gen intentionally unsupported.

UI Changes

  • New Kilo logo in provider icon map / settings
  • Kilo appears in model picker (sidebar badge: new) and provider settings with binary path only

No motion/interaction changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes (N/A — no animation changes)

Note

Medium Risk
Large new adapter with child-process lifecycle and subtle concurrent turn/interrupt races; mitigated by extensive tests and scope finalizers, but it is new core provider infrastructure parallel to OpenCode.

Overview
Adds Kilo as a first-party provider using @kilocode/sdk (managed kilo serve, Basic auth, SSE) instead of CLI scraping, following the same driver/runtime/adapter pattern as OpenCode.

Contracts & UI: KiloSettings (enabled, binaryPath, customModels), kilo driver kind, default models, raw event source kilo.sdk.event, settings card, KiloIcon, and model-picker entry.

Server: KiloRuntime spawns/supervises the local server and loads upstream inventory; KiloProvider probes the CLI and flattens connected providerID/modelID models (plus custom slugs); KiloAdapter maps SDK events to ProviderRuntimeEvent, handles sessions/turns, permissions, user-input, read/rollback, and race-safe interrupt/steer logic (session-wide session.abort, compare-and-set on idle/busy). KiloDriver wires snapshot, adapter, and stub KiloTextGeneration (git/title ops fail with a clear message). Registered in BUILT_IN_DRIVERS with KiloRuntimeLive on the server runtime layer.

v1 behavior: default agent code, plan mode → plan; no agent picker, no external server URL settings, no Kilo text generation.

Reviewed by Cursor Bugbot for commit 5797ecf. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add Kilo SDK-backed provider adapter, driver, and runtime integration

  • Introduces a full KiloRuntime service (kiloRuntime.ts) that spawns and manages a local Kilo server process, connects to it, and loads provider/model inventory via the @kilocode/sdk.
  • Adds KiloDriver (KiloDriver.ts) and KiloAdapter (KiloAdapter.ts) to handle session lifecycle, turn management, permission replies, and error mapping.
  • Adds KiloProvider (KiloProvider.ts) with a probing pipeline that classifies failures (ENOENT, auth, quarantine) into structured provider snapshots with installed/version/auth status.
  • Registers Kilo in contracts (KILO_DRIVER_KIND, default models, display name), server settings (KiloSettings), built-in driver registry, and web UI provider picker and settings panel.
  • Text generation operations (commit message, PR content, branch name, thread title) return explicit TextGenerationError indicating Kilo does not yet support git text generation.
  • Risk: KiloRuntimeLive is now merged into the server's RuntimeCoreDependenciesLive, meaning any startup failure in Kilo runtime initialization affects the full server boot path.

Macroscope summarized 5797ecf.

Add a first-party `kilo` provider that spawns managed `kilo serve`,
inventories connected models as providerID/modelID, and streams turns
via @kilocode/sdk (OpenCode-shaped runtime/adapter pattern).
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 442fcb70-21c5-4c85-8e40-3a3b63e2c068

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Jul 17, 2026
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts Outdated
Comment thread apps/server/src/provider/kiloRuntime.ts Outdated
Comment thread apps/server/src/provider/kiloRuntime.ts
Comment thread apps/server/src/provider/kiloRuntime.ts
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread pnpm-lock.yaml Outdated
Comment thread apps/server/src/provider/kiloRuntime.ts
@macroscopeapp

macroscopeapp Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces an entirely new provider integration (Kilo) with ~3800 lines of new code including driver, adapter, runtime process management, and UI integration. New features adding user-facing capabilities and external SDK integrations warrant human review.

You can customize Macroscope's approvability policy. Learn more.

Keep draining Kilo serve stdout/stderr after ready, terminate on startup
timeout, clear interrupt/failed turn state, and drop phantom lockfile deps.
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts Outdated
Avoid racing concurrent startSession calls that replace the map entry
while an earlier call is still tearing down the previous context.
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread apps/server/src/provider/kiloRuntime.ts Outdated
Treat unexpected clean event-stream ends as session transport errors, and
stop retaining stdout/stderr after ready while still draining pipes.
Prevents clean-stream-end teardown from racing permission-reply tests.
Avoid hanging the adapter layer teardown while still preventing clean
stream-end from racing mid-test permission replies.
Stop retaining stdout/stderr after ready while still draining pipes.
Leave clean SSE completion silent (matches OpenCode) so finite test
streams do not race session teardown.
Comment thread apps/server/src/provider/kiloRuntime.ts
Avoid dropping concurrent stderr diagnostics between URL detection and
startup completion.
Serialize steer-vs-open with Ref.modify so two idle sendTurn calls cannot
both emit turn.started or orphan the first turn id.
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts Outdated
Avoid wiping a turn that concurrent steers still rely on when the
original promptAsync fails after steer reuse.
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Clear activeTurnId before remote abort and skip ready reset if a newer
claim arrived; fail startSession when the session dies during event-pump setup.
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts Outdated
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts Outdated
Githubguy132010 and others added 2 commits July 19, 2026 15:37
Cursor Bugbot review of 4dd769b flagged three race conditions in the
Kilo adapter lifecycle. Each was an ownership bug on activeTurnId where
concurrent steer / interrupt / idle events could clear or emit lifecycle
events for a turn the caller no longer owned.

- ensureSessionContext is now an Effect.fn so it surfaces
  ProviderAdapterSessionNotFoundError / ProviderAdapterSessionClosedError
  on the Effect error channel instead of as defects; stopSession does
  the same. Matches OpenCodeAdapter and lets callers recover from
  unknown or closed threads.
- session.status idle handler uses Ref.modify to compare-and-set: it
  only clears activeTurnId and emits turn.completed when the ref still
  matches the turn id it observed at the top of the handler. A
  concurrent interrupt or steer no longer gets its claim clobbered by a
  late idle.
- interruptTurn records whether the call actually owned the claimed
  turn; if the requested turn id is stale (e.g. interrupted twice, or
  a newer claim exists), session.abort is skipped so the SDK abort
  cannot cancel an unrelated newer turn.

Adds three regression tests covering each path.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts Outdated
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts Outdated
- Compare-and-delete in onSessionEnd/onSessionClosed so a concurrent
  startSession replacing the entry isn't orphaned.
- Read the live activeTurnId for late session.status=busy events instead
  of a stale snapshot, avoiding resurrecting an already-interrupted turn.
- Split interruptTurn so it clears the claim BEFORE session.abort and
  restores it on abort failure, emitting turn.completed(failed) when
  the abort RPC fails after we owned the claim.
- Drop unused ProviderDriverKind import and stale PROVIDER argument
  from providerModelsFromSettings calls in KiloProvider.
- Register kilo: { enabled: false } in ProviderRegistry.test default
  settings so the registry stays correct when Kilo is added.
Comment thread apps/server/src/provider/Layers/KiloAdapter.ts
…bort

Cursor Bugbot flagged a race in interruptTurn: clearing activeTurnId
before calling session.abort opens a window where a concurrent sendTurn
can claim a fresh turn id which the in-flight (session-wide) abort RPC
then unintentionally cancels. Leave the claim in place across the abort,
clear it once the RPC resolves, and drop the now-unneeded restore logic
in the abort-failure path.

Adds a regression test that pins interruptTurn inside the abort RPC and
verifies a concurrent sendTurn steers into the existing turn id instead
of opening a new one.

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
@juliusmarminge

Copy link
Copy Markdown
Member

we'll start adding new providers after orchestrator has merged (#2829)

@Githubguy132010
Githubguy132010 deleted the feat/kilo-provider-adapter branch July 20, 2026 15:34
@Githubguy132010

Copy link
Copy Markdown
Author

we'll start adding new providers after orchestrator has merged (#2829)

Understood. Will implement it again when #2829 merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants