Skip to content

Commit 3115873

Browse files
committed
fix: include auto-close settings in getState and getStateToPostToWebview
The autoCloseZooOpenedFiles, autoCloseZooOpenedFilesAfterUserEdited, and autoCloseZooOpenedNewFiles settings were saved to global state but never included in the state posted back to the webview (getStateToPostToWebview) or returned by getState. This caused the checkbox to always revert to checked after saving, and the DiffViewProvider to always use the default value regardless of the user's preference. Also adds a changeset instruction to AGENTS.md. Closes #667
1 parent 8c3ae1e commit 3115873

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This file provides guidance to agents when working with code in this repository.
44

55
- Settings View Pattern: When working on `SettingsView`, inputs must bind to the local `cachedState`, NOT the live `useExtensionState()`. The `cachedState` acts as a buffer for user edits, isolating them from the `ContextProxy` source-of-truth until the user explicitly clicks "Save". Wiring inputs directly to the live state causes race conditions.
6+
- Changesets: Do NOT create `.changeset` files for each commit or code change. Changesets are managed separately by maintainers and should not be generated by agents during normal development.
67

78
## Test Placement Guidance
89

‎src/core/webview/ClineProvider.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,9 @@ export class ClineProvider
22782278
openRouterImageApiKey,
22792279
openRouterImageGenerationSelectedModel,
22802280
lockApiConfigAcrossModes,
2281+
autoCloseZooOpenedFiles,
2282+
autoCloseZooOpenedFilesAfterUserEdited,
2283+
autoCloseZooOpenedNewFiles,
22812284
} = await this.getState()
22822285

22832286
let cloudOrganizations: CloudOrganizationMembership[] = []
@@ -2457,6 +2460,9 @@ export class ClineProvider
24572460
imageGenerationProvider,
24582461
openRouterImageApiKey,
24592462
openRouterImageGenerationSelectedModel,
2463+
autoCloseZooOpenedFiles: autoCloseZooOpenedFiles ?? true,
2464+
autoCloseZooOpenedFilesAfterUserEdited: autoCloseZooOpenedFilesAfterUserEdited ?? false,
2465+
autoCloseZooOpenedNewFiles: autoCloseZooOpenedNewFiles ?? false,
24602466
openAiCodexIsAuthenticated: await (async () => {
24612467
try {
24622468
const { openAiCodexOAuthManager } = await import("../../integrations/openai-codex/oauth")
@@ -2657,6 +2663,9 @@ export class ClineProvider
26572663
imageGenerationProvider: stateValues.imageGenerationProvider,
26582664
openRouterImageApiKey: stateValues.openRouterImageApiKey,
26592665
openRouterImageGenerationSelectedModel: stateValues.openRouterImageGenerationSelectedModel,
2666+
autoCloseZooOpenedFiles: stateValues.autoCloseZooOpenedFiles,
2667+
autoCloseZooOpenedFilesAfterUserEdited: stateValues.autoCloseZooOpenedFilesAfterUserEdited,
2668+
autoCloseZooOpenedNewFiles: stateValues.autoCloseZooOpenedNewFiles,
26602669
}
26612670
}
26622671

‎src/core/webview/__tests__/ClineProvider.taskHistory.spec.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,51 @@ describe("ClineProvider Task History Synchronization", () => {
685685
})
686686
})
687687

688+
describe("auto-close settings are included in posted state", () => {
689+
it("getStateToPostToWebview returns saved autoCloseZooOpenedFiles value", async () => {
690+
await provider.resolveWebviewView(mockWebviewView)
691+
692+
// Simulate the updateSettings handler storing the value.
693+
await provider.contextProxy.setValue("autoCloseZooOpenedFiles", false)
694+
await provider.contextProxy.setValue("autoCloseZooOpenedFilesAfterUserEdited", true)
695+
await provider.contextProxy.setValue("autoCloseZooOpenedNewFiles", true)
696+
697+
const state = await provider.getStateToPostToWebview()
698+
699+
// The saved values must be present in the state posted to the webview.
700+
expect(state.autoCloseZooOpenedFiles).toBe(false)
701+
expect(state.autoCloseZooOpenedFilesAfterUserEdited).toBe(true)
702+
expect(state.autoCloseZooOpenedNewFiles).toBe(true)
703+
})
704+
705+
it("getStateToPostToWebview defaults autoCloseZooOpenedFiles to true when unset", async () => {
706+
await provider.resolveWebviewView(mockWebviewView)
707+
708+
// Ensure the settings are not set.
709+
await provider.contextProxy.setValue("autoCloseZooOpenedFiles", undefined)
710+
await provider.contextProxy.setValue("autoCloseZooOpenedFilesAfterUserEdited", undefined)
711+
await provider.contextProxy.setValue("autoCloseZooOpenedNewFiles", undefined)
712+
713+
const state = await provider.getStateToPostToWebview()
714+
715+
// Unset values should default to their documented defaults.
716+
expect(state.autoCloseZooOpenedFiles).toBe(true)
717+
expect(state.autoCloseZooOpenedFilesAfterUserEdited).toBe(false)
718+
expect(state.autoCloseZooOpenedNewFiles).toBe(false)
719+
})
720+
721+
it("getState returns saved autoCloseZooOpenedFiles value for DiffViewProvider", async () => {
722+
await provider.resolveWebviewView(mockWebviewView)
723+
724+
await provider.contextProxy.setValue("autoCloseZooOpenedFiles", false)
725+
726+
const state = await provider.getState()
727+
728+
// DiffViewProvider reads from getState(); the field must be present.
729+
expect(state.autoCloseZooOpenedFiles).toBe(false)
730+
})
731+
})
732+
688733
describe("taskHistory write lock (mutex)", () => {
689734
it("serializes concurrent updateTaskHistory calls so no entries are lost", async () => {
690735
await provider.resolveWebviewView(mockWebviewView)

0 commit comments

Comments
 (0)