Skip to content

Commit 3f2c7ef

Browse files
committed
Add browser viewport and network tools
1 parent 9538614 commit 3f2c7ef

9 files changed

Lines changed: 101 additions & 31 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ test-output.json
4141

4242
# Roopik IDE metadata
4343
.roopik/
44+
/TESTING-LAB

src/vs/workbench/contrib/roopik/browser/commands/roopikToolsCommands.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export function registerRoopikToolsCommands(): void {
8989
// ============================================================================
9090

9191
// --------------------------------------------------------------------------
92-
// Browser Tools (12)
92+
// Browser Tools (14)
9393
// --------------------------------------------------------------------------
9494

9595
registerAction2(class extends Action2 {
@@ -359,8 +359,8 @@ export function registerRoopikToolsCommands(): void {
359359
registerAction2(class extends Action2 {
360360
constructor() {
361361
super({
362-
id: 'roopik.tools.browserGetCdpInfo',
363-
title: { value: 'Get Browser CDP Info', original: 'Get Browser CDP Info' },
362+
id: 'roopik.tools.browserGetState',
363+
title: { value: 'Get Browser State', original: 'Get Browser State' },
364364
category: { value: 'Roopik', original: 'Roopik' },
365365
f1: false
366366
});
@@ -369,7 +369,51 @@ export function registerRoopikToolsCommands(): void {
369369
async run(accessor: ServicesAccessor): Promise<RoopikToolResult> {
370370
const mainProcessService = accessor.get(IMainProcessService);
371371
const channel = getToolsChannel(mainProcessService);
372-
return channel.call('browser_get_cdp_info');
372+
return channel.call('browser_get_state');
373+
}
374+
});
375+
376+
registerAction2(class extends Action2 {
377+
constructor() {
378+
super({
379+
id: 'roopik.tools.browserSetViewport',
380+
title: { value: 'Set Browser Viewport', original: 'Set Browser Viewport' },
381+
category: { value: 'Roopik', original: 'Roopik' },
382+
f1: false
383+
});
384+
}
385+
386+
async run(accessor: ServicesAccessor, args?: {
387+
width?: number;
388+
height?: number;
389+
deviceScaleFactor?: number;
390+
mobile?: boolean;
391+
}): Promise<RoopikToolResult> {
392+
const mainProcessService = accessor.get(IMainProcessService);
393+
const channel = getToolsChannel(mainProcessService);
394+
return channel.call('browser_set_viewport', args || {});
395+
}
396+
});
397+
398+
registerAction2(class extends Action2 {
399+
constructor() {
400+
super({
401+
id: 'roopik.tools.browserGetNetworkRequests',
402+
title: { value: 'Get Network Requests', original: 'Get Network Requests' },
403+
category: { value: 'Roopik', original: 'Roopik' },
404+
f1: false
405+
});
406+
}
407+
408+
async run(accessor: ServicesAccessor, args?: {
409+
urlFilter?: string;
410+
method?: string;
411+
statusFilter?: string;
412+
limit?: number;
413+
}): Promise<RoopikToolResult> {
414+
const mainProcessService = accessor.get(IMainProcessService);
415+
const channel = getToolsChannel(mainProcessService);
416+
return channel.call('browser_get_network_requests', args || {});
373417
}
374418
});
375419

src/vs/workbench/contrib/roopik/electron-main/mcp/executor/browserExecutor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ export class BrowserExecutor {
109109
// Browser is already open - navigate if URL provided
110110
if (url) {
111111
await this.browserViewService.navigate(browserViewId, url);
112+
// Enable CDP monitoring proactively to capture errors from page load
113+
await this.ensureCDPMonitoring(browserViewId);
112114
return {
113115
success: true,
114116
data: {
@@ -119,6 +121,9 @@ export class BrowserExecutor {
119121
};
120122
}
121123

124+
// Enable CDP monitoring even if not navigating (browser already open)
125+
await this.ensureCDPMonitoring(browserViewId);
126+
122127
return {
123128
success: true,
124129
data: {
@@ -186,6 +191,9 @@ export class BrowserExecutor {
186191

187192
await this.browserViewService.navigate(browserViewId, url);
188193

194+
// Enable CDP monitoring proactively to capture errors from page load
195+
await this.ensureCDPMonitoring(browserViewId);
196+
189197
return {
190198
success: true,
191199
data: {
@@ -218,6 +226,9 @@ export class BrowserExecutor {
218226

219227
await this.browserViewService.reload(browserViewId, hardReload);
220228

229+
// Enable CDP monitoring proactively to capture errors from reload
230+
await this.ensureCDPMonitoring(browserViewId);
231+
221232
return {
222233
success: true,
223234
data: {

src/vs/workbench/contrib/roopik/electron-main/mcp/prompts/mcpPrompts.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Call **project_start** with the project path:
5555
5656
### 3. Verify the Server is Running
5757
The browser should automatically open. You can verify with:
58-
- Call **browser_get_cdp_info** to check browser state
58+
- Call **browser_get_state** to check browser state
5959
- Call **browser_screenshot** to see the rendered page
6060
6161
### 4. Navigate to Specific Pages (Optional)
@@ -132,7 +132,7 @@ canvas_get_active → canvas_create (if needed) → component_add → component_
132132
description: 'Step-by-step guide for inspecting CSS and finding source files to edit',
133133
content: `# How to Inspect & Fix CSS in Roopik
134134
135-
This workflow teaches you THE MOAT capability - CSS inspection with source resolution.
135+
This workflow teaches you how to inspect CSS and resolve styles to their source files.
136136
137137
## Step-by-Step Process:
138138
@@ -183,10 +183,10 @@ Call **browser_reload** with ignoreCache: true:
183183
- Take another screenshot to verify the fix
184184
- Re-inspect if needed to confirm CSS changes
185185
186-
## Why This Is THE MOAT:
187-
- Traditional: "This element has color: red" (but where from?)
188-
- Roopik: "color: red is in button.scss at line 45:3"
189-
- Includes source maps: SCSS/LESS resolve to original files
186+
## Key Benefit - Source File Resolution:
187+
- Traditional tools: "This element has color: red" (but where is it defined?)
188+
- With source maps: "color: red is defined in button.scss at line 45:3"
189+
- SCSS/LESS files resolve to original source locations
190190
- Shows full cascade: what's overridden and why
191191
192192
## Example Tool Chain:
@@ -334,8 +334,9 @@ This workflow teaches you the complete cycle for frontend development.
334334
- browser_execute_script, browser_inspect_element
335335
- browser_get_errors, browser_get_console_logs
336336
337-
**Browser Info** (2):
338-
- browser_get_performance, browser_get_cdp_info
337+
**Browser Info** (4):
338+
- browser_get_performance, browser_get_state
339+
- browser_set_viewport, browser_get_network_requests
339340
340341
**Canvas Tools** (3):
341342
- canvas_list, canvas_get_active, canvas_create
@@ -344,13 +345,13 @@ This workflow teaches you the complete cycle for frontend development.
344345
- component_add, component_add_batch, component_remove
345346
- component_get_info, component_list, component_rebuild
346347
347-
## Total: 24 Tools
348+
## Total: 26 Tools
348349
349350
## Key Tips:
350351
- Always check project_get_active before starting
351352
- Take screenshots frequently for visual verification
352353
- Use browser_get_errors after any page load
353-
- browser_inspect_element is THE MOAT for CSS work
354+
- browser_inspect_element provides CSS source file resolution
354355
- Use ignoreCache: true when reloading after code changes`
355356
}
356357
];

src/vs/workbench/contrib/roopik/electron-main/mcp/toolSchemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const TOOL_DEFINITIONS: ToolDefinition[] = [
198198
},
199199
{
200200
name: 'browser_inspect_element',
201-
description: 'Inspect CSS styles of an element with source file resolution. THE MOAT capability - returns exact file:line:column where styles are defined.',
201+
description: 'Inspect CSS styles of an element with source file resolution. Returns exact file:line:column where styles are defined (requires source maps).',
202202
schema: browserInspectElementSchema
203203
},
204204
{

src/vs/workbench/contrib/roopik/electron-main/mcp/tools/browserTools.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ export function registerBrowserTools(
383383
// URL normalization is done in browserViewService.navigate()
384384
if (url) {
385385
await browserViewService.navigate(browserViewId, url);
386+
// Enable CDP monitoring proactively to capture errors from page load
387+
await ensureCDPMonitoring(browserViewId, browserViewService);
386388
return {
387389
content: [{
388390
type: 'text' as const,
@@ -396,6 +398,9 @@ export function registerBrowserTools(
396398
};
397399
}
398400

401+
// Enable CDP monitoring even if not navigating (browser already open)
402+
await ensureCDPMonitoring(browserViewId, browserViewService);
403+
399404
return {
400405
content: [{
401406
type: 'text' as const,
@@ -802,6 +807,9 @@ Actions:
802807
// URL normalization is done in browserViewService.navigate()
803808
await browserViewService.navigate(browserViewId, url);
804809

810+
// Enable CDP monitoring proactively to capture errors from page load
811+
await ensureCDPMonitoring(browserViewId, browserViewService);
812+
805813
return {
806814
content: [{
807815
type: 'text' as const,
@@ -858,6 +866,9 @@ Actions:
858866

859867
await browserViewService.reload(browserViewId, ignoreCache);
860868

869+
// Enable CDP monitoring proactively to capture errors from reload
870+
await ensureCDPMonitoring(browserViewId, browserViewService);
871+
861872
return {
862873
content: [{
863874
type: 'text' as const,

src/vs/workbench/contrib/roopik/electron-main/mcp/tools/contextPrompts.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ getActiveCanvas → createComponent → (wait) → getComponentStatus → takeSc
156156
type: 'text' as const,
157157
text: `# How to Inspect & Fix CSS in Roopik
158158
159-
This workflow teaches you THE MOAT capability - CSS inspection with source resolution that competitors can't match.
159+
This workflow teaches you how to inspect CSS and resolve styles to their source files.
160160
161161
## Step-by-Step Process:
162162
@@ -179,7 +179,7 @@ Call **roopik_inspectElement** with:
179179
- includeUserAgent: false (usually don't need browser defaults)
180180
181181
### 4. Analyze the CSS Data
182-
The response gives you THE MOAT - file:line:column precision:
182+
The response provides precise source file information:
183183
- **matchedRules**: Array of CSS rules that apply to this element
184184
- Each rule has: selector, file (absolute path), location { line, column }
185185
- Properties with isOverridden: true are being overridden by more specific rules
@@ -208,10 +208,10 @@ Call **roopik_reload** to see the changes:
208208
- ignoreCache: true (for hard reload)
209209
- Then call takeScreenshot or inspectElement again to verify the fix
210210
211-
## Why This Is THE MOAT:
212-
- Traditional tools: "This element has color: red" (but where does it come from?)
213-
- Roopik: "color: red is defined in button.scss at line 45:3, overriding button.css line 12:5"
214-
- Includes source maps: SCSS/LESS/PostCSS files, not just compiled CSS
211+
## Key Benefit - Source File Resolution:
212+
- Traditional tools: "This element has color: red" (but where is it defined?)
213+
- With source maps: "color: red is defined in button.scss at line 45:3, overriding button.css line 12:5"
214+
- Resolves SCSS/LESS/PostCSS to original source files
215215
- Detects CSS-in-JS with component file locations
216216
- Shows the full cascade: what's overridden and why
217217

tools/roopik/mcp-stdio-server/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,23 @@ roopik-mcp [--ws-port <port>] [--ws-url <url>]
7979
3. `ROOPIK_MCP_WS_URL` environment variable
8080
4. Auto-discovery (tries ports 9876-9880)
8181

82-
## Available Tools (24)
82+
## Available Tools (26)
8383

84-
### Browser Tools (12)
84+
### Browser Tools (14)
8585
- `browser_open` - Open the browser view
8686
- `browser_close` - Close the browser view
8787
- `browser_screenshot` - Take a screenshot
8888
- `browser_navigate` - Navigate to URL
8989
- `browser_reload` - Reload the page
9090
- `browser_action_input` - Click, type, scroll, etc.
9191
- `browser_execute_script` - Run JavaScript
92-
- `browser_inspect_element` - **THE MOAT** - CSS inspection with source resolution
92+
- `browser_inspect_element` - CSS inspection with source file resolution
9393
- `browser_get_errors` - Get console + network errors
9494
- `browser_get_console_logs` - Get console logs
9595
- `browser_get_performance` - Get Web Vitals metrics
96-
- `browser_get_cdp_info` - Get browser state
96+
- `browser_get_state` - Get browser state (open/closed, URL, title)
97+
- `browser_set_viewport` - Set/clear viewport for responsive testing
98+
- `browser_get_network_requests` - Get captured network traffic
9799

98100
### Canvas Tools (3)
99101
- `canvas_list` - List all canvases
@@ -117,6 +119,6 @@ roopik-mcp [--ws-port <port>] [--ws-url <url>]
117119

118120
- `how-to-start-project` - Guide for starting a dev server
119121
- `how-to-create-component` - Guide for adding components to canvas
120-
- `how-to-inspect-css` - Guide for CSS inspection (THE MOAT)
122+
- `how-to-inspect-css` - Guide for CSS inspection with source resolution
121123
- `how-to-debug-errors` - Guide for debugging browser errors
122124
- `full-dev-workflow` - Complete development workflow

tools/roopik/mcp-stdio-server/src/tools.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export const TOOL_DEFINITIONS: ToolDefinition[] = [
202202
},
203203
{
204204
name: 'browser_inspect_element',
205-
description: 'Inspect CSS styles of an element with source file resolution. THE MOAT capability - returns exact file:line:column where styles are defined.',
205+
description: 'Inspect CSS styles of an element with source file resolution. Returns exact file:line:column where styles are defined (requires source maps).',
206206
schema: browserInspectElementSchema
207207
},
208208
{
@@ -377,7 +377,7 @@ canvas_get_active → canvas_create (if needed) → component_add → component_
377377
description: 'Step-by-step guide for inspecting CSS and finding source files to edit',
378378
content: `# How to Inspect & Fix CSS in Roopik
379379
380-
This workflow teaches you THE MOAT capability - CSS inspection with source resolution.
380+
This workflow teaches you how to inspect CSS and resolve styles to their source files.
381381
382382
## Step-by-Step Process:
383383
@@ -403,9 +403,9 @@ Look at matchedRules to find where to make changes:
403403
- Use the **file** path to know which file to edit
404404
- Use **location.line** for exact position
405405
406-
## Why This Is THE MOAT:
407-
- Traditional: "This element has color: red" (but where from?)
408-
- Roopik: "color: red is in button.scss at line 45:3"
406+
## Key Benefit - Source File Resolution:
407+
- Traditional tools: "This element has color: red" (but where is it defined?)
408+
- With source maps: "color: red is defined in button.scss at line 45:3"
409409
410410
## Example Tool Chain:
411411
browser_screenshot → browser_inspect_element → (edit file) → browser_reload → browser_screenshot`

0 commit comments

Comments
 (0)