@@ -183,59 +183,59 @@ These steps ensure that:
183183
184184To add a new configuration item to the system , the following changes are necessary :
185185
186- 1. ** Feature - Specific Class ** (if applicable )
186+ 1. ** Feature - Specific Class ** (if applicable )
187187
188188 - For settings that affect specific features (e .g ., Terminal , Browser , etc .)
189189 - Add a static property to store the value
190190 - Add getter / setter methods to access and modify the value
191191
192- 2. ** Schema Definition **
192+ 2. ** Schema Definition **
193193
194194 - Add the item to globalSettingsSchema in schemas / index .ts
195195 - Add the item to globalSettingsRecord in schemas / index .ts
196196
197- 3. ** Type Definitions **
197+ 3. ** Type Definitions **
198198
199199 - Add the item to exports / types .ts
200200 - Add the item to exports / roo - code .d .ts
201201 - Add the item to shared / ExtensionMessage .ts
202202 - Add the item to shared / WebviewMessage .ts
203203
204- 4. ** UI Component **
204+ 4. ** UI Component **
205205
206206 - Create or update a component in webview - ui / src / components / settings /
207207 - Add appropriate slider / input controls with min / max / step values
208208 - Ensure the props are passed correctly to the component in SettingsView .tsx
209209 - Update the component ' s props interface to include the new settings
210210
211- 5. ** Translations **
211+ 5. ** Translations **
212212
213213 - Add label and description in webview - ui / src / i18n / locales / en / settings .json
214214 - Update all other languages
215215 - If any language content is changed , synchronize all other languages with that change
216216 - Translations must be performed within " translation" mode so change modes for that purpose
217217
218- 6. ** State Management **
218+ 6. ** State Management **
219219
220220 - Add the item to the destructuring in SettingsView .tsx
221221 - Add the item to the handleSubmit function in SettingsView.tsx
222222 - Add the item to getStateToPostToWebview in ClineProvider.ts
223223 - Add the item to getState in ClineProvider.ts with appropriate default values
224224 - Add the item to the initialization in resolveWebviewView in ClineProvider.ts
225225
226- 7. ** Message Handling **
226+ 7. ** Message Handling **
227227
228228 - Add a case for the item in webviewMessageHandler .ts
229229
230- 8. ** Implementation - Specific Logic **
230+ 8. ** Implementation - Specific Logic **
231231
232232 - Implement any feature - specific behavior triggered by the setting
233233 - Examples :
234234 - Environment variables for terminal settings
235235 - API configuration changes for provider settings
236236 - UI behavior modifications for display settings
237237
238- 9. ** Testing **
238+ 9. ** Testing **
239239
240240 - Add test cases for the new settings in appropriate test files
241241 - Verify settings persistence and state updates
@@ -305,40 +305,139 @@ To add a new configuration item to the system, the following changes are necessa
305305
30630611. ** Debugging Settings Persistence Issues **
307307
308- If a setting is not persisting across reload , check the following :
308+ If a setting is not persisting across reload , check the following :
309309
310- 1. ** Complete Chain of Persistence ** :
310+ 1. ** Complete Chain of Persistence ** :
311311
312- - Verify that the setting is added to all required locations :
313- - globalSettingsSchema and globalSettingsRecord in schemas / index .ts
314- - Initial state in ExtensionStateContextProvider
315- - getState method in ClineProvider .ts
316- - getStateToPostToWebview method in ClineProvider .ts
317- - resolveWebviewView method in ClineProvider .ts (if feature - specific )
318- - A break in any part of this chain can prevent persistence
312+ - Verify that the setting is added to all required locations :
313+ - globalSettingsSchema and globalSettingsRecord in schemas / index .ts
314+ - Initial state in ExtensionStateContextProvider
315+ - getState method in ClineProvider .ts
316+ - getStateToPostToWebview method in ClineProvider .ts
317+ - resolveWebviewView method in ClineProvider .ts (if feature - specific )
318+ - A break in any part of this chain can prevent persistence
319319
320- 2. ** Default Values Consistency ** :
320+ 2. ** Default Values Consistency ** :
321321
322- - Ensure default values are consistent across all locations
323- - Inconsistent defaults can cause unexpected behavior
322+ - Ensure default values are consistent across all locations
323+ - Inconsistent defaults can cause unexpected behavior
324324
325- 3. ** Message Handling ** :
325+ 3. ** Message Handling ** :
326326
327- - Confirm the webviewMessageHandler .ts has a case for the setting
328- - Verify the message type matches what's sent from the UI
327+ - Confirm the webviewMessageHandler .ts has a case for the setting
328+ - Verify the message type matches what's sent from the UI
329329
330- 4. ** UI Integration ** :
330+ 4. ** UI Integration ** :
331331
332- - Check that the setting is included in the handleSubmit function in SettingsView.tsx
333- - Ensure the UI component correctly updates the state
332+ - Check that the setting is included in the handleSubmit function in SettingsView.tsx
333+ - Ensure the UI component correctly updates the state
334334
335- 5. ** Type Definitions ** :
335+ 5. ** Type Definitions ** :
336336
337- - Verify the setting is properly typed in all relevant interfaces
338- - Check for typos in property names across different files
337+ - Verify the setting is properly typed in all relevant interfaces
338+ - Check for typos in property names across different files
339339
340- 6. ** Storage Mechanism ** :
341- - For complex settings , ensure proper serialization / deserialization
342- - Check that the setting is being correctly stored in VSCode ' s globalState
340+ 6. ** Storage Mechanism ** :
341+ - For complex settings , ensure proper serialization / deserialization
342+ - Check that the setting is being correctly stored in VSCode ' s globalState
343343
344344 These checks help identify and resolve common issues with settings persistence .
345+
346+ 12. ** Advanced Troubleshooting : The Complete Settings Persistence Chain **
347+
348+ Settings persistence requires a complete chain of state management across multiple components . Understanding this chain is critical for both humans and AI to effectively troubleshoot persistence issues :
349+
350+ 1. ** Schema Definition (Entry Point )** :
351+
352+ - Settings must be properly defined in ` globalSettingsSchema ` and ` globalSettingsRecord `
353+ - Enum values should use proper zod schemas : ` z.enum(["value1", "value2"]) `
354+ - Example :
355+
356+ ` ` ` typescript
357+ // In schemas/index.ts
358+ export const globalSettingsSchema = z.object({
359+ // Existing settings...
360+ commandRiskLevel: z.enum(["readOnly", "reversibleChanges", "complexChanges"]).optional(),
361+ })
362+
363+ const globalSettingsRecord: GlobalSettingsRecord = {
364+ // Existing settings...
365+ commandRiskLevel: undefined,
366+ }
367+ ` ` `
368+
369+ 2. ** UI Component (User Interaction )** :
370+
371+ - Must use consistent components (Select vs . select ) with other similar settings
372+ - Must use ` setCachedStateField ` for state updates , not direct state setting
373+ - Must generate the correct message type through `vscode.postMessage`
374+ - Example:
375+ ```tsx
376+ // In a settings component
377+ <Select value = {commandRiskLevel} onValueChange = {(value ) => setCachedStateField (" commandRiskLevel" , value )}>
378+ <SelectTrigger className = " w-full" >
379+ <SelectValue placeholder = {t(" settings:common.select" )} />
380+ </SelectTrigger >
381+ <SelectContent >
382+ <SelectGroup >
383+ <SelectItem value = " readOnly" >{t("label.readOnly")}< / SelectItem >
384+ {/* Other options... */ }
385+ < / SelectGroup >
386+ < / SelectContent >
387+ < / Select >
388+ ```
389+
390+ 3. ** Message Handler (State Saving )** :
391+
392+ - Must use correct message type in `webviewMessageHandler.ts`
393+ - Must use `updateGlobalState` with properly typed values
394+ - Must call `postStateToWebview` after updates
395+ - Example:
396+ ```typescript
397+ // In webviewMessageHandler.ts
398+ case " commandRiskLevel" :
399+ await updateGlobalState (
400+ " commandRiskLevel" ,
401+ (message .text ?? " readOnly" ) as " readOnly" | " reversibleChanges" | " complexChanges"
402+ )
403+ await provider .postStateToWebview ()
404+ break
405+ ```
406+
407+ 4. ** State Retrieval (Reading State )** :
408+
409+ - In ` getState ` , state must be properly retrieved from stateValues
410+ - In ` getStateToPostToWebview ` , the setting must be in the destructured parameters
411+ - The setting must be included in the return value
412+ - Use ` contextProxy.getGlobalState ` for direct access when needed
413+ - Example :
414+
415+ ` ` ` typescript
416+ // In ClineProvider.ts getStateToPostToWebview
417+ const {
418+ // Other state properties...
419+ commandRiskLevel,
420+ } = await this.getState()
421+
422+ return {
423+ // Other state properties...
424+ commandRiskLevel: commandRiskLevel ?? "readOnly",
425+ }
426+ ` ` `
427+
428+ 5. ** Debugging Strategies ** :
429+
430+ - ** Follow the State Flow ** : Watch the setting ' s value at each step in the chain
431+ - ** Type Safety ** : Ensure the same type is used throughout the chain
432+ - **Component Consistency**: Use the same pattern as other working settings
433+ - **Check Return Values**: Ensure the setting is included in all return objects
434+ - **State vs. Configuration**: Understand when to use state vs. VSCode configuration
435+
436+ 6. ** Common Pitfalls ** :
437+ - ** Type Mismatch ** : Using string where an enum is expected
438+ - **Chain Breaks**: Missing the setting in return objects
439+ - **UI Inconsistency**: Using different component patterns
440+ - **DefaultValue Issues**: Inconsistent default values across components
441+ - **Missing Schema**: Not adding to schema or record definitions
442+
443+ Remember: A break at ANY point in this chain can cause persistence failures. When troubleshooting, systematically check each link in the chain to identify where the issue occurs.
0 commit comments