The ExtensionStateContext manages the state for the extension using Jotai, a state management library for React. Here's an overview of how the state is structured and managed:
The main state is contained in the extensionStateAtom
, which is a derived atom combining various individual state atoms. The state includes:
- version
- claudeMessages
- taskHistory
- useUdiff
- currentTask
- currentTaskId
- shouldShowAnnouncement
- shouldShowKoduPromo
- apiConfiguration
- uriScheme
- maxRequestsPerTask
- customInstructions
- fingerprint
- technicalBackground
- alwaysAllowReadOnly
- experimentalTerminal
- fpjsKey
- extensionName
- themeName
- user
- alwaysAllowWriteOnly
- creativeMode
- Individual atoms are created for each piece of state using
atom()
from Jotai. - The
extensionStateAtom
combines all individual atoms into a single state object. - The
ExtensionStateProvider
component manages the state updates:- It sets up event listeners for messages from the extension.
- Updates the state based on received messages.
- Provides the state to child components.
- The
useExtensionState
hook allows components to access the state and update functions:- It returns the current state and setter functions for various state properties.
State updates occur through:
- Message events from the extension (e.g., 'claudeMessages', 'state', 'action').
- Setter functions provided by the
useExtensionState
hook.
This structure allows for centralized state management and easy access to state and update functions throughout the application.