Skip to content

feat(cloud-panel): persist selected repository across new sessions#3414

Open
kilo-code-bot[bot] wants to merge 1 commit into
mainfrom
feat/persist-selected-repo-cloud-panel
Open

feat(cloud-panel): persist selected repository across new sessions#3414
kilo-code-bot[bot] wants to merge 1 commit into
mainfrom
feat/persist-selected-repo-cloud-panel

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot Bot commented May 22, 2026

Summary

  • Adds getLastUsedRepo / setLastUsedRepo helpers to model-preferences.ts, following the same safeLocalStorage pattern used for model and variant persistence. The value is stored as JSON { fullName, platform } under cloud-agent:last-used-repo:personal or cloud-agent:last-used-repo:organization:<id>.
  • Calls setLastUsedRepo inside handleRepoSelect whenever the selection is user-initiated (clicking or typing in the repo picker).
  • On component mount, the auto-select useEffect now checks localStorage first and pre-selects the matching repository from unifiedRepositories before falling back to the most-recently-used repo from the server query. If the stored repo is no longer in the user's repository list the effect silently falls through to the existing fallback behaviour.

Verification

  1. Open the Cloud session panel and select a non-default repository.
  2. Click New Session (navigates to /cloud, remounting the panel).
  3. Confirm the previously selected repository is restored rather than cleared.
  4. Clear localStorage (cloud-agent:last-used-repo:personal) and verify the panel falls back to the most recent repo from the server (original behaviour).

Visual Changes

N/A

Reviewer Notes

  • The as LastUsedRepo cast in getLastUsedRepo is guarded by explicit typeof checks for both required string fields (fullName, platform), so the cast does not hide real uncertainty.
  • Full pnpm typecheck was skipped because the monorepo build was killed by resource limits in this environment; targeted tsc --noEmit on the web app returned no errors.

Built for Evgeny Shurakov by Kilo for Slack

@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented May 22, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/components/cloud-agent-next/model-preferences.ts 28 platform validated as string but cast to RepositoryPlatform union — invalid values are not rejected
Issue Detail

model-preferences.tsgetLastUsedRepo platform validation (line 28)

RepositoryPlatform is the union 'github' | 'gitlab', but the guard only checks typeof ... === 'string'. Any arbitrary string stored in localStorage (e.g. from a corrupted entry, a future platform rename, or a tampered value) passes validation and is cast to LastUsedRepo via as LastUsedRepo.

In the current auto-select flow the impact is minimal: handleRepoSelect(match.fullName, false) is called with userInitiated=false, so setLastUsedRepo is not called again and setSelectedPlatform reads the platform from unifiedRepositories (live data), not from the stored saved.platform. However, saved.platform is stored in the returned object and could be consumed directly in future callers, making the weak guard a latent bug.

Suggested fix: add an explicit membership check before the cast:

const VALID_PLATFORMS: RepositoryPlatform[] = ['github', 'gitlab'];
...
typeof (parsed as Record<string, unknown>).platform === 'string' &&
VALID_PLATFORMS.includes((parsed as Record<string, unknown>).platform as RepositoryPlatform)
Files Reviewed (2 files)
  • apps/web/src/components/cloud-agent-next/model-preferences.ts — 1 issue
  • apps/web/src/components/cloud-agent-next/NewSessionPanel.tsx — no issues

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-4.6 · 447,860 tokens

Review guidance: REVIEW.md from base branch main

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants