Skip to content

Commit 43494b5

Browse files
Merge 7d12560 into adee4d2
2 parents adee4d2 + 7d12560 commit 43494b5

35 files changed

Lines changed: 11372 additions & 572 deletions

‎packages/types/src/__tests__/global-settings.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,33 @@ describe("alwaysDenyUnapprovedCommands global setting", () => {
3737
it("rejects non-boolean setting values", () => {
3838
expect(() => globalSettingsSchema.parse({ alwaysDenyUnapprovedCommands: "true" })).toThrow()
3939
})
40+
41+
describe("viewStates global setting", () => {
42+
it("parses a valid per-view record", () => {
43+
const parsed = globalSettingsSchema.parse({
44+
viewStates: {
45+
"stable-view-1": { mode: "code", currentApiConfigName: "profile-a", updatedAt: 1730000000000 },
46+
"stable-view-2": {},
47+
},
48+
})
49+
expect(parsed.viewStates?.["stable-view-1"]).toEqual({
50+
mode: "code",
51+
currentApiConfigName: "profile-a",
52+
updatedAt: 1730000000000,
53+
})
54+
expect(parsed.viewStates?.["stable-view-2"]).toEqual({})
55+
expect(GLOBAL_SETTINGS_KEYS).toContain("viewStates")
56+
})
57+
58+
it("rejects invalid field values inside a view entry", () => {
59+
expect(() => globalSettingsSchema.parse({ viewStates: { v: { mode: 42 } } })).toThrow()
60+
expect(() => globalSettingsSchema.parse({ viewStates: { v: { currentApiConfigName: 42 } } })).toThrow()
61+
expect(() => globalSettingsSchema.parse({ viewStates: { v: { updatedAt: "soon" } } })).toThrow()
62+
})
63+
64+
it("rejects non-object viewStates values", () => {
65+
expect(() => globalSettingsSchema.parse({ viewStates: "not-a-record" })).toThrow()
66+
expect(() => globalSettingsSchema.parse({ viewStates: { v: "not-an-entry" } })).toThrow()
67+
})
68+
})
4069
})

‎packages/types/src/__tests__/index.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import { GLOBAL_STATE_KEYS } from "../index.js"
44

55
describe("GLOBAL_STATE_KEYS", () => {
6+
it("should contain registered durable per-view state", () => {
7+
expect(GLOBAL_STATE_KEYS).toContain("viewStates")
8+
})
9+
610
it("should contain provider settings keys", () => {
711
expect(GLOBAL_STATE_KEYS).toContain("autoApprovalEnabled")
812
})
@@ -13,6 +17,7 @@ describe("GLOBAL_STATE_KEYS", () => {
1317

1418
it("should not contain secret state keys", () => {
1519
expect(GLOBAL_STATE_KEYS).not.toContain("openRouterApiKey")
20+
expect(GLOBAL_STATE_KEYS).not.toContain("apiKey")
1621
})
1722

1823
it("should contain OpenAI Compatible base URL setting", () => {

‎packages/types/src/api.ts‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { EventEmitter } from "events"
22
import type { Socket } from "net"
33

44
import type { RooCodeEvents } from "./events.js"
5-
import type { RooCodeSettings } from "./global-settings.js"
5+
import type { GlobalState, RooCodeSettings } from "./global-settings.js"
66
import type { HistoryItem } from "./history.js"
77
import type { ProviderSettingsEntry, ProviderSettings } from "./provider-settings.js"
88
import type { IpcMessage, IpcServerEvents } from "./ipc.js"
@@ -21,18 +21,21 @@ export interface RooCodeAPI extends EventEmitter<RooCodeAPIEvents> {
2121
* Starts a new task with an optional initial message and images.
2222
* @param task Optional initial task message.
2323
* @param images Optional array of image data URIs (e.g., "data:image/webp;base64,...").
24+
* @param preserveOpenTabs When true, skips the new-tab editor cleanup (revert + close-all), preserving open tabs and dirty/unsaved editors.
2425
* @returns The ID of the new task.
2526
*/
2627
startNewTask({
2728
configuration,
2829
text,
2930
images,
3031
newTab,
32+
preserveOpenTabs,
3133
}: {
3234
configuration?: RooCodeSettings
3335
text?: string
3436
images?: string[]
3537
newTab?: boolean
38+
preserveOpenTabs?: boolean
3639
}): Promise<string>
3740
/**
3841
* Resumes a task with the given ID.
@@ -119,7 +122,9 @@ export interface RooCodeAPI extends EventEmitter<RooCodeAPIEvents> {
119122
*/
120123
getConfiguration(): RooCodeSettings
121124
/**
122-
* Sets the configuration for the current task.
125+
* Sets the configuration for the extension. Writes target the extension-host (sidebar) view:
126+
* view-local values are pinned to the sidebar's per-view state, while global values are
127+
* written to the shared ContextProxy.
123128
* @param values An object containing key-value pairs to set.
124129
*/
125130
setConfiguration(values: RooCodeSettings): Promise<void>
@@ -186,6 +191,38 @@ export interface RooCodeAPI extends EventEmitter<RooCodeAPIEvents> {
186191
setTerminalProfile(name: string | undefined): void
187192
}
188193

194+
/**
195+
* Test-only extension API surface.
196+
*
197+
* These methods expose raw global-state reads and task ask control by ID that
198+
* production callers must not rely on. The implementation is gated at runtime
199+
* against VS Code ExtensionMode.Production, so only test hosts and the e2e
200+
* harness keep access.
201+
*/
202+
export interface RooCodeTestOnlyApi {
203+
/**
204+
* Programmatically approves the pending ask for a task by ID. Intended for use in tests only.
205+
*/
206+
approveTaskAsk(taskId: string): Promise<boolean>
207+
/**
208+
* Programmatically denies the pending ask for a task by ID. Intended for use in tests only.
209+
*/
210+
denyTaskAsk(taskId: string): Promise<boolean>
211+
/**
212+
* Simulates selecting a follow-up suggestion for a task by ID, including its optional mode switch.
213+
* Intended for use in tests only.
214+
*/
215+
selectTaskFollowupSuggestion(options: { taskId: string; answer: string; mode?: string }): Promise<boolean>
216+
/**
217+
* Returns a value from VS Code globalState. Intended for use in tests only.
218+
*/
219+
getGlobalState<K extends keyof GlobalState>(key: K): GlobalState[K]
220+
/**
221+
* Writes a value to VS Code globalState. Intended for use in tests only.
222+
*/
223+
setGlobalState<K extends keyof GlobalState>(key: K, value: GlobalState[K]): Promise<void>
224+
}
225+
189226
export interface RooCodeTestAPI extends RooCodeAPI {
190227
captureWebviewThemeFixture(): Promise<WebviewThemeFixture>
191228
getLatestAnnouncementId(): string

‎packages/types/src/global-settings.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ export const MAX_CHECKPOINT_TIMEOUT_SECONDS = 60
111111
*/
112112
export const DEFAULT_CHECKPOINT_TIMEOUT_SECONDS = 15
113113

114+
/**
115+
* Persisted non-secret selections for a stable webview instance.
116+
*/
117+
export const viewStateSchema = z.object({
118+
mode: z.string().optional(),
119+
currentApiConfigName: z.string().optional(),
120+
updatedAt: z.number().optional(),
121+
})
122+
114123
/**
115124
* GlobalSettings
116125
*/
@@ -119,6 +128,7 @@ export const globalSettingsSchema = z.object({
119128
currentApiConfigName: z.string().optional(),
120129
listApiConfigMeta: z.array(providerSettingsEntrySchema).optional(),
121130
pinnedApiConfigs: z.record(z.string(), z.boolean()).optional(),
131+
viewStates: z.record(z.string(), viewStateSchema).optional(),
122132

123133
lastShownAnnouncementId: z.string().optional(),
124134
customInstructions: z.string().optional(),

‎packages/types/src/vscode-extension-host.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ export interface WebviewMessage {
653653
| "openRulesDirectory"
654654
| "themeFixtureProbeResponse"
655655
text?: string
656+
viewStateId?: string
656657
taskId?: string
657658
editedMessageContent?: string
658659
tab?: "settings" | "history" | "mcp" | "modes" | "chat" | "marketplace" | "cloud"

‎packages/types/src/vscode.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export const commandIds = [
3535
"popoutButtonClicked",
3636
"settingsButtonClicked",
3737

38+
// Editor-tab (popped-out) surface variants of the title-bar buttons. The
39+
// shared ids above target the sidebar click origin, so the tab surface
40+
// needs its own ids (see registerCommands.ts getTabProvider).
41+
"plusButtonClickedInTab",
42+
"settingsButtonClickedInTab",
43+
"marketplaceButtonClickedInTab",
44+
"historyButtonClickedInTab",
45+
3846
"openInNewTab",
3947

4048
"newTask",

0 commit comments

Comments
 (0)