Skip to content

Commit 9dc8ef6

Browse files
committed
fix(webview-ui): align disconnect aria-label; remove unused vars; replace useSize to avoid timers in tests
1 parent 82ee0f5 commit 9dc8ef6

File tree

68 files changed

+2074
-804
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2074
-804
lines changed

packages/types/src/global-settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const globalSettingsSchema = z.object({
107107
browserToolEnabled: z.boolean().optional(),
108108
browserViewportSize: z.string().optional(),
109109
screenshotQuality: z.number().optional(),
110+
browserActionsAutoExpand: z.boolean().optional(),
110111
remoteBrowserEnabled: z.boolean().optional(),
111112
remoteBrowserHost: z.string().optional(),
112113
cachedChromeHostUrl: z.string().optional(),
@@ -297,6 +298,7 @@ export const EVALS_SETTINGS: RooCodeSettings = {
297298
browserToolEnabled: false,
298299
browserViewportSize: "900x600",
299300
screenshotQuality: 75,
301+
browserActionsAutoExpand: false,
300302
remoteBrowserEnabled: false,
301303

302304
ttsEnabled: false,

packages/types/src/message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export const clineSays = [
156156
"shell_integration_warning",
157157
"browser_action",
158158
"browser_action_result",
159+
"browser_session_status",
159160
"mcp_server_request_started",
160161
"mcp_server_response",
161162
"subtask_result",

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,32 @@ export async function presentAssistantMessage(cline: Task) {
355355
return text.replace(tagRegex, "")
356356
}
357357

358-
if (block.name !== "browser_action") {
359-
await cline.browserSession.closeBrowser()
358+
// Keep browser open during an active session so other tools can run.
359+
// Session is active if we've seen any browser_action_result and the last browser_action is not "close".
360+
try {
361+
const messages = cline.clineMessages || []
362+
const hasStarted = messages.some((m: any) => m.say === "browser_action_result")
363+
let isClosed = false
364+
for (let i = messages.length - 1; i >= 0; i--) {
365+
const m = messages[i]
366+
if (m.say === "browser_action") {
367+
try {
368+
const act = JSON.parse(m.text || "{}")
369+
isClosed = act.action === "close"
370+
} catch {}
371+
break
372+
}
373+
}
374+
const sessionActive = hasStarted && !isClosed
375+
// Only auto-close when no active browser session is present, and this isn't a browser_action
376+
if (!sessionActive && block.name !== "browser_action") {
377+
await cline.browserSession.closeBrowser()
378+
}
379+
} catch {
380+
// On any unexpected error, fall back to conservative behavior
381+
if (block.name !== "browser_action") {
382+
await cline.browserSession.closeBrowser()
383+
}
360384
}
361385

362386
if (!block.partial) {

src/core/environment/__tests__/getEnvironmentDetails.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ describe("getEnvironmentDetails", () => {
116116
deref: vi.fn().mockReturnValue(mockProvider),
117117
[Symbol.toStringTag]: "WeakRef",
118118
} as unknown as WeakRef<ClineProvider>,
119+
browserSession: {
120+
isSessionActive: vi.fn().mockReturnValue(false),
121+
} as any,
119122
}
120123

121124
// Mock other dependencies.
@@ -390,4 +393,18 @@ describe("getEnvironmentDetails", () => {
390393
const result = await getEnvironmentDetails(cline as Task)
391394
expect(result).toContain("REMINDERS")
392395
})
396+
it("should include Browser Session Status when inactive", async () => {
397+
const result = await getEnvironmentDetails(mockCline as Task)
398+
expect(result).toContain("# Browser Session Status")
399+
expect(result).toContain("Inactive - Browser is not launched")
400+
})
401+
402+
it("should include Browser Session Status with current viewport when active", async () => {
403+
;(mockCline.browserSession as any).isSessionActive = vi.fn().mockReturnValue(true)
404+
;(mockCline.browserSession as any).getViewportSize = vi.fn().mockReturnValue({ width: 1280, height: 720 })
405+
406+
const result = await getEnvironmentDetails(mockCline as Task)
407+
expect(result).toContain("Active - A browser session is currently open and ready for browser_action commands")
408+
expect(result).toContain("Current viewport size: 1280x720 pixels.")
409+
})
393410
})

src/core/environment/getEnvironmentDetails.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,38 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
237237
}
238238
}
239239

240+
// Add browser session status - Always show to prevent LLM from trying browser actions when no session is active
241+
const isBrowserActive = cline.browserSession.isSessionActive()
242+
243+
// Build viewport info for status (prefer actual viewport if available, else fallback to configured setting)
244+
const configuredViewport = (state?.browserViewportSize as string | undefined) ?? "900x600"
245+
let configuredWidth: number | undefined
246+
let configuredHeight: number | undefined
247+
if (configuredViewport.includes("x")) {
248+
const parts = configuredViewport.split("x").map((v) => Number(v))
249+
configuredWidth = parts[0]
250+
configuredHeight = parts[1]
251+
}
252+
253+
let actualWidth: number | undefined
254+
let actualHeight: number | undefined
255+
// Use optional chaining to avoid issues with tests that stub browserSession
256+
const vp = isBrowserActive ? (cline.browserSession as any).getViewportSize?.() : undefined
257+
if (vp) {
258+
actualWidth = vp.width
259+
actualHeight = vp.height
260+
}
261+
262+
const width = actualWidth ?? configuredWidth
263+
const height = actualHeight ?? configuredHeight
264+
const viewportInfo = isBrowserActive && width && height ? `\nCurrent viewport size: ${width}x${height} pixels.` : ""
265+
266+
details += `\n# Browser Session Status\n${
267+
isBrowserActive
268+
? "Active - A browser session is currently open and ready for browser_action commands"
269+
: "Inactive - Browser is not launched. Using any browser action except the browser_action with action='launch' to start a new session will result in an error."
270+
}${viewportInfo}\n`
271+
240272
if (includeFileDetails) {
241273
details += `\n\n# Current Workspace Directory (${cline.cwd.toPosix()}) Files\n`
242274
const isDesktop = arePathsEqual(cline.cwd, path.join(os.homedir(), "Desktop"))

src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap

Lines changed: 27 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/prompts/sections/rules.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ ${getEditingInstructions(diffStrategy)}
9191
- When presented with images, utilize your vision capabilities to thoroughly examine them and extract meaningful information. Incorporate these insights into your thought process as you accomplish the user's task.
9292
- At the end of each user message, you will automatically receive environment_details. This information is not written by the user themselves, but is auto-generated to provide potentially relevant context about the project structure and environment. While this information can be valuable for understanding the project context, do not treat it as a direct part of the user's request or response. Use it to inform your actions and decisions, but don't assume the user is explicitly asking about or referring to this information unless they clearly do so in their message. When using environment_details, explain your actions clearly to ensure the user understands, as they may not be aware of these details.
9393
- Before executing commands, check the "Actively Running Terminals" section in environment_details. If present, consider how these active processes might impact your task. For example, if a local development server is already running, you wouldn't need to start it again. If no active terminals are listed, proceed with command execution as normal.
94-
- MCP operations should be used one at a time, similar to other tool usage. Wait for confirmation of success before proceeding with additional operations.
94+
- MCP operations should be used one at a time, similar to other tool usage. Wait for confirmation of success before proceeding with additional operations.${
95+
supportsComputerUse
96+
? "\n- **BROWSER SESSION PERSISTENCE**: When a browser session is active (launched but not closed), you can freely use ask_followup_question, attempt_completion, and ANY other tools WITHOUT closing the browser. The browser remains open in the background and you can return to browser_action at any time. DO NOT close the browser just because you want to ask a question or use another tool - this is explicitly allowed and the browser will persist."
97+
: ""
98+
}
9599
- It is critical you wait for the user's response after each tool use, in order to confirm the success of the tool use. For example, if asked to make a todo app, you would create a file, wait for the user's response it was created successfully, then create another file if needed, wait for the user's response it was created successfully, etc.${
96100
supportsComputerUse
97-
? " Then if you want to test your work, you might use browser_action to launch the site, wait for the user's response confirming the site was launched along with a screenshot, then perhaps e.g., click a button to test functionality if needed, wait for the user's response confirming the button was clicked along with a screenshot of the new state, before finally closing the browser."
101+
? " Then if you want to test your work, you might use browser_action to launch the site, wait for the user's response confirming the site was launched along with a screenshot, then perhaps e.g., click a button to test functionality if needed, wait for the user's response confirming the button was clicked along with a screenshot of the new state. The browser will remain open throughout testing - you can ask questions, make file edits, or perform additional browser actions as needed. Only close the browser when you're completely finished with all testing."
98102
: ""
99103
}`
100104
}

0 commit comments

Comments
 (0)