Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@marius-kilocode
Copy link
Collaborator

@marius-kilocode marius-kilocode commented Jan 19, 2026

Summary

This PR adds mode selection functionality to the Agent Manager, allowing users to select and switch modes (code, architect, debug, etc.) for CLI sessions.

Features

Mode Selection for New Sessions

  • Added mode selector dropdown in the new agent form
  • Users can select the mode before starting a new CLI session
  • Mode is passed to CLI via KILO_MODE environment variable

Mode Switching During Sessions

  • Added mode selector in the session header for running sessions
  • Mode can be changed during a session via CLI JSON-IO API (setMode message)
  • UI updates automatically when mode changes via modeChanged event

UI Improvements

  • Model selector moved below textarea in new agent form for better layout
  • Mode selector uses same styling as model selector (subtle, visible on hover)
  • Dropdown arrows point in correct direction based on dropdown position

Technical Changes

  • Added mode field to startSessionMessageSchema and agentSessionSchema
  • Added setMode message handler in AgentManagerProvider
  • Added modeChanged event handling in useStdinJsonHandler
  • Created ModeSelector and SessionModeSelector components
  • Added mode atoms to Agent Manager state management
  • Consolidated DEFAULT_MODE_SLUG constant across codebase
  • Added translations for mode selection UI in all supported languages

Testing

  • Verified mode selection works when starting new sessions
  • Verified mode switching works during running sessions
  • Verified UI updates correctly when mode changes
  • Verified lint passes with no errors
image image

@changeset-bot
Copy link

changeset-bot bot commented Jan 19, 2026

🦋 Changeset detected

Latest commit: 649196f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@marius-kilocode marius-kilocode requested a review from a team January 19, 2026 18:19
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Jan 19, 2026

Code Review Summary

Status: No New Issues Found | Recommendation: Address existing feedback before merge

Overview

This PR adds mode selection to Agent Manager for CLI sessions. The implementation is well-structured with:

  • Mode selector in new agent form for selecting mode when starting sessions
  • Mode selector in session header for switching modes during running sessions
  • Proper state management with Jotai atoms and localStorage persistence
  • Full i18n support across all locales

Previous Review Feedback

The existing inline comments from previous reviewers cover the main areas for improvement:

Category Issue
Architecture SessionModeSelector appears duplicated with ModeSelector - consider consolidation
Types jsonOutput.ts types could be formalized
i18n Missing translation key in ModeSelector.tsx line 26
Documentation Placeholder issue number in useModeOptions.ts TODO comment
Naming Portal container uses roo-portal instead of kilo-portal
Files Reviewed (35 files)

Core Changes:

  • .changeset/agent-manager-mode-selection.md - Changeset
  • cli/src/constants/modes/defaults.ts - Import DEFAULT_MODE_SLUG from types
  • cli/src/state/hooks/useStdinJsonHandler.ts - Add setMode handler
  • cli/src/ui/utils/jsonOutput.ts - Add JsonIoMessage types and outputJsonIoMessage
  • packages/agent-runtime/src/host/ExtensionHost.ts - Add mode option and custom modes handling
  • packages/types/src/modes.ts - Export DEFAULT_MODE_SLUG

Agent Manager UI:

  • webview-ui/src/kilocode/agent-manager/components/AgentManagerApp.tsx - Add portal container
  • webview-ui/src/kilocode/agent-manager/components/ChatInput.tsx - Add SessionModeSelector
  • webview-ui/src/kilocode/agent-manager/components/ModeSelector.tsx - New component
  • webview-ui/src/kilocode/agent-manager/components/SessionDetail.tsx - Add mode selection
  • webview-ui/src/kilocode/agent-manager/components/SessionModeSelector.tsx - New component
  • webview-ui/src/kilocode/agent-manager/hooks/useModeOptions.ts - New hook
  • webview-ui/src/kilocode/agent-manager/state/atoms/modes.ts - New atoms
  • webview-ui/src/kilocode/agent-manager/state/atoms/sessions.ts - Add mode field
  • webview-ui/src/kilocode/agent-manager/state/hooks/useAgentManagerMessages.ts - Handle mode messages

Styling:

  • webview-ui/src/kilocode/agent-manager/components/AgentManagerApp.css - Mode selector styles
  • webview-ui/src/components/ui/select-dropdown.tsx - Add overscroll-contain

i18n (20 locale files):

  • Added selectMode and modeTooltip translations

Automated review by Kilo Code

Addresses PR review comment about duplication between ModeSelector and
SessionModeSelector. The shared hook builds mode dropdown options from
available modes, with optional translation support for the organization
modes header.
- Add mode to CreateSessionOptions interface in AgentRegistry
- Store mode when creating sessions with DEFAULT_MODE_SLUG fallback
- Add mode to PendingProcessInfo interface in CliProcessHandler
- Pass mode through all session creation paths
- Remove global effectiveModeSlugAtom fallback in SessionModeSelector
- Each session now stores and uses its own mode independently

This fixes the bug where changing the mode in the new session form
would affect the displayed mode in all running sessions.
@marius-kilocode
Copy link
Collaborator Author

@iscekic thanks for the review. I addressed the comments. Additionally the implementation still had a bug that would lead into multiple sessions sharing the same mode change. That's also fixed now.

@marius-kilocode marius-kilocode enabled auto-merge (squash) January 20, 2026 11:33
…n modes

Organization modes were failing with 'KiloCode token + baseUrl is required
to fetch models' because the agent process didn't have access to the mode
configurations. This fix:

1. Adds customModes parameter to RuntimeProcessHandler.buildAgentConfig()
2. Adds customModes parameter to RuntimeProcessHandler.spawnProcess()
3. Updates AgentManagerProvider.spawnAgentWithCommonSetup() to fetch
   custom modes (including organization modes) and pass them to the
   agent process

Now the agent process receives all custom mode configurations at startup,
eliminating the need to fetch them from the API during runtime.
The extension expects { type: 'mode', text: mode } webview messages,
not { type: 'setMode', mode }. Updated setSessionMode() to send the
correct message format via IPC.
… modes

The CustomModesManager.getCustomModes() method reads organization modes from
globalState.get('customModes'). In agent processes, customModes were only
stored in the currentState but not in globalState, causing organization modes
to fail with 'KiloCode token + baseUrl is required to fetch models' error.

This fix stores customModes in globalState when the ExtensionHost initializes,
ensuring CustomModesManager can find organization modes in agent processes.
…odeChanged callback

The RuntimeProcessHandler was not detecting mode changes from state updates
sent by the agent process. This fix:
- Adds sessionModes map to track current mode for each session
- Detects mode changes in handleExtensionMessage when processing state updates
- Calls onModeChanged callback when mode changes are detected
- Cleans up sessionModes when sessions are terminated
…gging

Added logging to trace custom modes flow:
- AgentManagerProvider: logs mode slugs and sources when fetching custom modes
- RuntimeProcessHandler: logs mode and custom modes in buildAgentConfig
- agent-runtime process.ts: logs custom modes received from parent
- ExtensionHost: logs custom modes storage in globalState
…dcoded 'code'

The ExtensionHost was hardcoding mode to 'code' in the initial state instead
of using the mode passed via options. This fix:
- Adds 'mode' field to ExtensionHostOptions interface
- Passes mode from ExtensionServiceOptions to ExtensionHostOptions
- Uses options.mode (with 'code' fallback) in initial state
- Adds logging to show the initial mode being set
@marius-kilocode
Copy link
Collaborator Author

@iscekic I merged the IPC rewrite of the agent manager. I had to disable organizational modes for now, we ship them later. Mode selection should work fine now with this.

- Disable organization modes temporarily (require additional API config work)
- Use i18n for SessionModeSelector title
- Make previousMode optional in ModeChangedMessage interface
- Remove debug logging
Copy link
Collaborator

@iscekic iscekic left a comment

Choose a reason for hiding this comment

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

I'm probably going to have to build on this in #5252 - so lets merge this first.

When resuming a session, the mode was not being passed to spawnAgentWithCommonSetup,
causing the agent to always start in 'code' mode regardless of the original session mode.

Now the mode is properly restored from either:
1. sessionData.metadata.mode (from server)
2. session.mode (from local registry)

This ensures that when a user resumes a session that was started in a custom mode
(e.g., 'Brian Mode'), the agent will continue using that mode.
…esume

The mode was being passed to buildAgentConfig (for the agent process) but not
to registry.createSession when creating a new session entry for a resume.
This caused the UI to show 'code' mode even though the agent was running
in the correct mode.

Now the mode is passed to both:
1. buildAgentConfig - for the agent process configuration
2. registry.createSession - for the UI session state
@marius-kilocode marius-kilocode merged commit a94f8f0 into main Jan 22, 2026
12 checks passed
@marius-kilocode marius-kilocode deleted the feat/agent-manager-mode-selection branch January 22, 2026 17:06
maywzh pushed a commit to maywzh/kilocode that referenced this pull request Jan 25, 2026
* feat(agent-manager): add mode selection for CLI sessions

* refactor: extract shared useModeOptions hook to reduce duplication

Addresses PR review comment about duplication between ModeSelector and
SessionModeSelector. The shared hook builds mode dropdown options from
available modes, with optional translation support for the organization
modes header.

* fix: move css-prefix test to src directory for Node.js environment

* fix: isolate mode state per session in Agent Manager

- Add mode to CreateSessionOptions interface in AgentRegistry
- Store mode when creating sessions with DEFAULT_MODE_SLUG fallback
- Add mode to PendingProcessInfo interface in CliProcessHandler
- Pass mode through all session creation paths
- Remove global effectiveModeSlugAtom fallback in SessionModeSelector
- Each session now stores and uses its own mode independently

This fixes the bug where changing the mode in the new session form
would affect the displayed mode in all running sessions.

* fix: add onModeChanged callback to RuntimeProcessHandlerCallbacks and pass mode to createSession

* fix(agent-manager): pass customModes to agent process for organization modes

Organization modes were failing with 'KiloCode token + baseUrl is required
to fetch models' because the agent process didn't have access to the mode
configurations. This fix:

1. Adds customModes parameter to RuntimeProcessHandler.buildAgentConfig()
2. Adds customModes parameter to RuntimeProcessHandler.spawnProcess()
3. Updates AgentManagerProvider.spawnAgentWithCommonSetup() to fetch
   custom modes (including organization modes) and pass them to the
   agent process

Now the agent process receives all custom mode configurations at startup,
eliminating the need to fetch them from the API during runtime.

* fix(agent-manager): fix mid-session mode switching message format

The extension expects { type: 'mode', text: mode } webview messages,
not { type: 'setMode', mode }. Updated setSessionMode() to send the
correct message format via IPC.

* fix(agent-runtime): store customModes in globalState for organization modes

The CustomModesManager.getCustomModes() method reads organization modes from
globalState.get('customModes'). In agent processes, customModes were only
stored in the currentState but not in globalState, causing organization modes
to fail with 'KiloCode token + baseUrl is required to fetch models' error.

This fix stores customModes in globalState when the ExtensionHost initializes,
ensuring CustomModesManager can find organization modes in agent processes.

* fix(agent-manager): detect mode changes in state updates and call onModeChanged callback

The RuntimeProcessHandler was not detecting mode changes from state updates
sent by the agent process. This fix:
- Adds sessionModes map to track current mode for each session
- Detects mode changes in handleExtensionMessage when processing state updates
- Calls onModeChanged callback when mode changes are detected
- Cleans up sessionModes when sessions are terminated

* chore(agent-manager): add detailed logging for organization mode debugging

Added logging to trace custom modes flow:
- AgentManagerProvider: logs mode slugs and sources when fetching custom modes
- RuntimeProcessHandler: logs mode and custom modes in buildAgentConfig
- agent-runtime process.ts: logs custom modes received from parent
- ExtensionHost: logs custom modes storage in globalState

* fix(agent-runtime): use options.mode for initial state instead of hardcoded 'code'

The ExtensionHost was hardcoding mode to 'code' in the initial state instead
of using the mode passed via options. This fix:
- Adds 'mode' field to ExtensionHostOptions interface
- Passes mode from ExtensionServiceOptions to ExtensionHostOptions
- Uses options.mode (with 'code' fallback) in initial state
- Adds logging to show the initial mode being set

* chore: add detailed logging for API configuration debugging

* fix(agent-manager): address PR review comments

- Disable organization modes temporarily (require additional API config work)
- Use i18n for SessionModeSelector title
- Make previousMode optional in ModeChangedMessage interface
- Remove debug logging

* fix(agent-manager): add portal container for dropdown scrolling

* fix(ui): add overscroll-contain to dropdown for scroll wheel support

* fix(agent-manager): add overflow-y and overscroll-behavior to mode selector content

* Fix comment

* fix(agent-manager): restore mode when resuming sessions

When resuming a session, the mode was not being passed to spawnAgentWithCommonSetup,
causing the agent to always start in 'code' mode regardless of the original session mode.

Now the mode is properly restored from either:
1. sessionData.metadata.mode (from server)
2. session.mode (from local registry)

This ensures that when a user resumes a session that was started in a custom mode
(e.g., 'Brian Mode'), the agent will continue using that mode.

* fix(agent-manager): pass mode to registry when creating session for resume

The mode was being passed to buildAgentConfig (for the agent process) but not
to registry.createSession when creating a new session entry for a resume.
This caused the UI to show 'code' mode even though the agent was running
in the correct mode.

Now the mode is passed to both:
1. buildAgentConfig - for the agent process configuration
2. registry.createSession - for the UI session state
maywzh pushed a commit to maywzh/kilocode that referenced this pull request Jan 25, 2026
* feat(agent-manager): add mode selection for CLI sessions

* refactor: extract shared useModeOptions hook to reduce duplication

Addresses PR review comment about duplication between ModeSelector and
SessionModeSelector. The shared hook builds mode dropdown options from
available modes, with optional translation support for the organization
modes header.

* fix: move css-prefix test to src directory for Node.js environment

* fix: isolate mode state per session in Agent Manager

- Add mode to CreateSessionOptions interface in AgentRegistry
- Store mode when creating sessions with DEFAULT_MODE_SLUG fallback
- Add mode to PendingProcessInfo interface in CliProcessHandler
- Pass mode through all session creation paths
- Remove global effectiveModeSlugAtom fallback in SessionModeSelector
- Each session now stores and uses its own mode independently

This fixes the bug where changing the mode in the new session form
would affect the displayed mode in all running sessions.

* fix: add onModeChanged callback to RuntimeProcessHandlerCallbacks and pass mode to createSession

* fix(agent-manager): pass customModes to agent process for organization modes

Organization modes were failing with 'KiloCode token + baseUrl is required
to fetch models' because the agent process didn't have access to the mode
configurations. This fix:

1. Adds customModes parameter to RuntimeProcessHandler.buildAgentConfig()
2. Adds customModes parameter to RuntimeProcessHandler.spawnProcess()
3. Updates AgentManagerProvider.spawnAgentWithCommonSetup() to fetch
   custom modes (including organization modes) and pass them to the
   agent process

Now the agent process receives all custom mode configurations at startup,
eliminating the need to fetch them from the API during runtime.

* fix(agent-manager): fix mid-session mode switching message format

The extension expects { type: 'mode', text: mode } webview messages,
not { type: 'setMode', mode }. Updated setSessionMode() to send the
correct message format via IPC.

* fix(agent-runtime): store customModes in globalState for organization modes

The CustomModesManager.getCustomModes() method reads organization modes from
globalState.get('customModes'). In agent processes, customModes were only
stored in the currentState but not in globalState, causing organization modes
to fail with 'KiloCode token + baseUrl is required to fetch models' error.

This fix stores customModes in globalState when the ExtensionHost initializes,
ensuring CustomModesManager can find organization modes in agent processes.

* fix(agent-manager): detect mode changes in state updates and call onModeChanged callback

The RuntimeProcessHandler was not detecting mode changes from state updates
sent by the agent process. This fix:
- Adds sessionModes map to track current mode for each session
- Detects mode changes in handleExtensionMessage when processing state updates
- Calls onModeChanged callback when mode changes are detected
- Cleans up sessionModes when sessions are terminated

* chore(agent-manager): add detailed logging for organization mode debugging

Added logging to trace custom modes flow:
- AgentManagerProvider: logs mode slugs and sources when fetching custom modes
- RuntimeProcessHandler: logs mode and custom modes in buildAgentConfig
- agent-runtime process.ts: logs custom modes received from parent
- ExtensionHost: logs custom modes storage in globalState

* fix(agent-runtime): use options.mode for initial state instead of hardcoded 'code'

The ExtensionHost was hardcoding mode to 'code' in the initial state instead
of using the mode passed via options. This fix:
- Adds 'mode' field to ExtensionHostOptions interface
- Passes mode from ExtensionServiceOptions to ExtensionHostOptions
- Uses options.mode (with 'code' fallback) in initial state
- Adds logging to show the initial mode being set

* chore: add detailed logging for API configuration debugging

* fix(agent-manager): address PR review comments

- Disable organization modes temporarily (require additional API config work)
- Use i18n for SessionModeSelector title
- Make previousMode optional in ModeChangedMessage interface
- Remove debug logging

* fix(agent-manager): add portal container for dropdown scrolling

* fix(ui): add overscroll-contain to dropdown for scroll wheel support

* fix(agent-manager): add overflow-y and overscroll-behavior to mode selector content

* Fix comment

* fix(agent-manager): restore mode when resuming sessions

When resuming a session, the mode was not being passed to spawnAgentWithCommonSetup,
causing the agent to always start in 'code' mode regardless of the original session mode.

Now the mode is properly restored from either:
1. sessionData.metadata.mode (from server)
2. session.mode (from local registry)

This ensures that when a user resumes a session that was started in a custom mode
(e.g., 'Brian Mode'), the agent will continue using that mode.

* fix(agent-manager): pass mode to registry when creating session for resume

The mode was being passed to buildAgentConfig (for the agent process) but not
to registry.createSession when creating a new session entry for a resume.
This caused the UI to show 'code' mode even though the agent was running
in the correct mode.

Now the mode is passed to both:
1. buildAgentConfig - for the agent process configuration
2. registry.createSession - for the UI session state
catrielmuller pushed a commit that referenced this pull request Jan 26, 2026
* feat(agent-manager): add mode selection for CLI sessions

* refactor: extract shared useModeOptions hook to reduce duplication

Addresses PR review comment about duplication between ModeSelector and
SessionModeSelector. The shared hook builds mode dropdown options from
available modes, with optional translation support for the organization
modes header.

* fix: move css-prefix test to src directory for Node.js environment

* fix: isolate mode state per session in Agent Manager

- Add mode to CreateSessionOptions interface in AgentRegistry
- Store mode when creating sessions with DEFAULT_MODE_SLUG fallback
- Add mode to PendingProcessInfo interface in CliProcessHandler
- Pass mode through all session creation paths
- Remove global effectiveModeSlugAtom fallback in SessionModeSelector
- Each session now stores and uses its own mode independently

This fixes the bug where changing the mode in the new session form
would affect the displayed mode in all running sessions.

* fix: add onModeChanged callback to RuntimeProcessHandlerCallbacks and pass mode to createSession

* fix(agent-manager): pass customModes to agent process for organization modes

Organization modes were failing with 'KiloCode token + baseUrl is required
to fetch models' because the agent process didn't have access to the mode
configurations. This fix:

1. Adds customModes parameter to RuntimeProcessHandler.buildAgentConfig()
2. Adds customModes parameter to RuntimeProcessHandler.spawnProcess()
3. Updates AgentManagerProvider.spawnAgentWithCommonSetup() to fetch
   custom modes (including organization modes) and pass them to the
   agent process

Now the agent process receives all custom mode configurations at startup,
eliminating the need to fetch them from the API during runtime.

* fix(agent-manager): fix mid-session mode switching message format

The extension expects { type: 'mode', text: mode } webview messages,
not { type: 'setMode', mode }. Updated setSessionMode() to send the
correct message format via IPC.

* fix(agent-runtime): store customModes in globalState for organization modes

The CustomModesManager.getCustomModes() method reads organization modes from
globalState.get('customModes'). In agent processes, customModes were only
stored in the currentState but not in globalState, causing organization modes
to fail with 'KiloCode token + baseUrl is required to fetch models' error.

This fix stores customModes in globalState when the ExtensionHost initializes,
ensuring CustomModesManager can find organization modes in agent processes.

* fix(agent-manager): detect mode changes in state updates and call onModeChanged callback

The RuntimeProcessHandler was not detecting mode changes from state updates
sent by the agent process. This fix:
- Adds sessionModes map to track current mode for each session
- Detects mode changes in handleExtensionMessage when processing state updates
- Calls onModeChanged callback when mode changes are detected
- Cleans up sessionModes when sessions are terminated

* chore(agent-manager): add detailed logging for organization mode debugging

Added logging to trace custom modes flow:
- AgentManagerProvider: logs mode slugs and sources when fetching custom modes
- RuntimeProcessHandler: logs mode and custom modes in buildAgentConfig
- agent-runtime process.ts: logs custom modes received from parent
- ExtensionHost: logs custom modes storage in globalState

* fix(agent-runtime): use options.mode for initial state instead of hardcoded 'code'

The ExtensionHost was hardcoding mode to 'code' in the initial state instead
of using the mode passed via options. This fix:
- Adds 'mode' field to ExtensionHostOptions interface
- Passes mode from ExtensionServiceOptions to ExtensionHostOptions
- Uses options.mode (with 'code' fallback) in initial state
- Adds logging to show the initial mode being set

* chore: add detailed logging for API configuration debugging

* fix(agent-manager): address PR review comments

- Disable organization modes temporarily (require additional API config work)
- Use i18n for SessionModeSelector title
- Make previousMode optional in ModeChangedMessage interface
- Remove debug logging

* fix(agent-manager): add portal container for dropdown scrolling

* fix(ui): add overscroll-contain to dropdown for scroll wheel support

* fix(agent-manager): add overflow-y and overscroll-behavior to mode selector content

* Fix comment

* fix(agent-manager): restore mode when resuming sessions

When resuming a session, the mode was not being passed to spawnAgentWithCommonSetup,
causing the agent to always start in 'code' mode regardless of the original session mode.

Now the mode is properly restored from either:
1. sessionData.metadata.mode (from server)
2. session.mode (from local registry)

This ensures that when a user resumes a session that was started in a custom mode
(e.g., 'Brian Mode'), the agent will continue using that mode.

* fix(agent-manager): pass mode to registry when creating session for resume

The mode was being passed to buildAgentConfig (for the agent process) but not
to registry.createSession when creating a new session entry for a resume.
This caused the UI to show 'code' mode even though the agent was running
in the correct mode.

Now the mode is passed to both:
1. buildAgentConfig - for the agent process configuration
2. registry.createSession - for the UI session state
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.

3 participants