@yuaone/tools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +663 -0
- package/README.md +15 -0
- package/dist/__tests__/file-edit.test.d.ts +8 -0
- package/dist/__tests__/file-edit.test.d.ts.map +1 -0
- package/dist/__tests__/file-edit.test.js +125 -0
- package/dist/__tests__/file-edit.test.js.map +1 -0
- package/dist/__tests__/registry.test.d.ts +7 -0
- package/dist/__tests__/registry.test.d.ts.map +1 -0
- package/dist/__tests__/registry.test.js +83 -0
- package/dist/__tests__/registry.test.js.map +1 -0
- package/dist/__tests__/validators.test.d.ts +8 -0
- package/dist/__tests__/validators.test.d.ts.map +1 -0
- package/dist/__tests__/validators.test.js +189 -0
- package/dist/__tests__/validators.test.js.map +1 -0
- package/dist/base-tool.d.ts +45 -0
- package/dist/base-tool.d.ts.map +1 -0
- package/dist/base-tool.js +87 -0
- package/dist/base-tool.js.map +1 -0
- package/dist/browser-tool.d.ts +39 -0
- package/dist/browser-tool.d.ts.map +1 -0
- package/dist/browser-tool.js +518 -0
- package/dist/browser-tool.js.map +1 -0
- package/dist/code-search.d.ts +42 -0
- package/dist/code-search.d.ts.map +1 -0
- package/dist/code-search.js +298 -0
- package/dist/code-search.js.map +1 -0
- package/dist/design-tools.d.ts +70 -0
- package/dist/design-tools.d.ts.map +1 -0
- package/dist/design-tools.js +471 -0
- package/dist/design-tools.js.map +1 -0
- package/dist/dev-server-manager.d.ts +32 -0
- package/dist/dev-server-manager.d.ts.map +1 -0
- package/dist/dev-server-manager.js +183 -0
- package/dist/dev-server-manager.js.map +1 -0
- package/dist/file-edit.d.ts +19 -0
- package/dist/file-edit.d.ts.map +1 -0
- package/dist/file-edit.js +217 -0
- package/dist/file-edit.js.map +1 -0
- package/dist/file-read.d.ts +19 -0
- package/dist/file-read.d.ts.map +1 -0
- package/dist/file-read.js +142 -0
- package/dist/file-read.js.map +1 -0
- package/dist/file-write.d.ts +18 -0
- package/dist/file-write.d.ts.map +1 -0
- package/dist/file-write.js +139 -0
- package/dist/file-write.js.map +1 -0
- package/dist/git-ops.d.ts +25 -0
- package/dist/git-ops.d.ts.map +1 -0
- package/dist/git-ops.js +219 -0
- package/dist/git-ops.js.map +1 -0
- package/dist/glob.d.ts +18 -0
- package/dist/glob.d.ts.map +1 -0
- package/dist/glob.js +91 -0
- package/dist/glob.js.map +1 -0
- package/dist/grep.d.ts +19 -0
- package/dist/grep.d.ts.map +1 -0
- package/dist/grep.js +177 -0
- package/dist/grep.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/security-scan.d.ts +62 -0
- package/dist/security-scan.d.ts.map +1 -0
- package/dist/security-scan.js +445 -0
- package/dist/security-scan.js.map +1 -0
- package/dist/shell-exec.d.ts +20 -0
- package/dist/shell-exec.d.ts.map +1 -0
- package/dist/shell-exec.js +206 -0
- package/dist/shell-exec.js.map +1 -0
- package/dist/test-run.d.ts +51 -0
- package/dist/test-run.d.ts.map +1 -0
- package/dist/test-run.js +359 -0
- package/dist/test-run.js.map +1 -0
- package/dist/tool-registry.d.ts +70 -0
- package/dist/tool-registry.d.ts.map +1 -0
- package/dist/tool-registry.js +181 -0
- package/dist/tool-registry.js.map +1 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +57 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +218 -0
- package/dist/validators.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yuaone/tools — Design Mode Tools
|
|
3
|
+
*
|
|
4
|
+
* 6 design-specific tools that wrap BrowserTool for visual design iteration:
|
|
5
|
+
* - design_snapshot: Get DOM accessibility tree
|
|
6
|
+
* - design_screenshot: Capture page screenshot
|
|
7
|
+
* - design_navigate: Navigate to URL/route
|
|
8
|
+
* - design_resize: Change viewport size (presets or custom)
|
|
9
|
+
* - design_inspect: Get computed CSS styles for an element
|
|
10
|
+
* - design_scroll: Scroll to element or position
|
|
11
|
+
*
|
|
12
|
+
* These tools share a single browser session managed via
|
|
13
|
+
* setDesignBrowserSession() / clearDesignBrowserSession().
|
|
14
|
+
*/
|
|
15
|
+
import { BaseTool } from './base-tool.js';
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Shared browser session (module-level singleton)
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
let sharedSessionId = null;
|
|
20
|
+
let browserToolInstance = null;
|
|
21
|
+
/**
|
|
22
|
+
* Set the shared browser session used by all design tools.
|
|
23
|
+
* Call this after opening a browser via BrowserTool's "open" action.
|
|
24
|
+
*/
|
|
25
|
+
export function setDesignBrowserSession(sessionId, browserTool) {
|
|
26
|
+
sharedSessionId = sessionId;
|
|
27
|
+
browserToolInstance = browserTool;
|
|
28
|
+
}
|
|
29
|
+
/** Clear the shared browser session. */
|
|
30
|
+
export function clearDesignBrowserSession() {
|
|
31
|
+
sharedSessionId = null;
|
|
32
|
+
browserToolInstance = null;
|
|
33
|
+
}
|
|
34
|
+
/** Helper: get browser tool + session or return error. */
|
|
35
|
+
function requireSession(toolName, toolCallId) {
|
|
36
|
+
if (!browserToolInstance || !sharedSessionId) {
|
|
37
|
+
return {
|
|
38
|
+
error: {
|
|
39
|
+
tool_call_id: toolCallId,
|
|
40
|
+
name: toolName,
|
|
41
|
+
output: 'Error: No active design browser session. Call setDesignBrowserSession() first (open a browser via design_navigate or BrowserTool).',
|
|
42
|
+
success: false,
|
|
43
|
+
durationMs: 0,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return { bt: browserToolInstance, sid: sharedSessionId };
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// 1. DesignSnapshotTool
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
export class DesignSnapshotTool extends BaseTool {
|
|
53
|
+
name = 'design_snapshot';
|
|
54
|
+
description = 'Get the DOM accessibility tree of the current page. ' +
|
|
55
|
+
'Returns a simplified DOM structure with tag names, ids, classes, text content, and attributes. ' +
|
|
56
|
+
'Useful for understanding page structure without a screenshot.';
|
|
57
|
+
riskLevel = 'low';
|
|
58
|
+
parameters = {};
|
|
59
|
+
async execute(args, workDir, _abortSignal) {
|
|
60
|
+
const toolCallId = args._toolCallId ?? '';
|
|
61
|
+
const session = requireSession(this.name, toolCallId);
|
|
62
|
+
if ('error' in session)
|
|
63
|
+
return session.error;
|
|
64
|
+
return session.bt.execute({ action: 'dom', sessionId: session.sid, _toolCallId: toolCallId }, workDir);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// 2. DesignScreenshotTool
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
export class DesignScreenshotTool extends BaseTool {
|
|
71
|
+
name = 'design_screenshot';
|
|
72
|
+
description = 'Capture a screenshot of the current page. ' +
|
|
73
|
+
'Returns a base64-encoded PNG image for visual analysis. ' +
|
|
74
|
+
'Use full_page=true to capture the entire scrollable page.';
|
|
75
|
+
riskLevel = 'low';
|
|
76
|
+
parameters = {
|
|
77
|
+
full_page: {
|
|
78
|
+
type: 'boolean',
|
|
79
|
+
description: 'Capture the full scrollable page instead of just the viewport (default: false)',
|
|
80
|
+
required: false,
|
|
81
|
+
default: false,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
async execute(args, workDir, _abortSignal) {
|
|
85
|
+
const toolCallId = args._toolCallId ?? '';
|
|
86
|
+
const session = requireSession(this.name, toolCallId);
|
|
87
|
+
if ('error' in session)
|
|
88
|
+
return session.error;
|
|
89
|
+
const fullPage = args.full_page ?? false;
|
|
90
|
+
return session.bt.execute({ action: 'screenshot', sessionId: session.sid, fullPage, _toolCallId: toolCallId }, workDir);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// 3. DesignNavigateTool
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
export class DesignNavigateTool extends BaseTool {
|
|
97
|
+
name = 'design_navigate';
|
|
98
|
+
description = 'Navigate the browser to a URL or route. ' +
|
|
99
|
+
'If the URL starts with "/" it is treated as a relative route and the current origin is prepended. ' +
|
|
100
|
+
'Only localhost/127.0.0.1/file:// URLs are allowed.';
|
|
101
|
+
riskLevel = 'low';
|
|
102
|
+
parameters = {
|
|
103
|
+
url: {
|
|
104
|
+
type: 'string',
|
|
105
|
+
description: 'URL or route to navigate to. Relative routes (starting with "/") are resolved against the current origin.',
|
|
106
|
+
required: true,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
async execute(args, workDir, _abortSignal) {
|
|
110
|
+
const toolCallId = args._toolCallId ?? '';
|
|
111
|
+
let url = args.url;
|
|
112
|
+
if (!url) {
|
|
113
|
+
return this.fail(toolCallId, 'Missing required parameter: url');
|
|
114
|
+
}
|
|
115
|
+
const session = requireSession(this.name, toolCallId);
|
|
116
|
+
if ('error' in session)
|
|
117
|
+
return session.error;
|
|
118
|
+
// If relative route, prepend origin from current page
|
|
119
|
+
if (url.startsWith('/')) {
|
|
120
|
+
const originResult = await session.bt.execute({
|
|
121
|
+
action: 'evaluate',
|
|
122
|
+
sessionId: session.sid,
|
|
123
|
+
script: 'window.location.origin',
|
|
124
|
+
_toolCallId: toolCallId,
|
|
125
|
+
}, workDir);
|
|
126
|
+
if (!originResult.success) {
|
|
127
|
+
return this.fail(toolCallId, `Failed to get page origin for relative URL: ${originResult.output}`);
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const parsed = JSON.parse(originResult.output);
|
|
131
|
+
const origin = typeof parsed.result === 'string'
|
|
132
|
+
? JSON.parse(parsed.result)
|
|
133
|
+
: parsed.result;
|
|
134
|
+
url = `${origin}${url}`;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return this.fail(toolCallId, 'Failed to parse page origin');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Use BrowserTool's evaluate to navigate (page.goto equivalent)
|
|
141
|
+
// We use evaluate with location.href assignment for navigation within same session
|
|
142
|
+
const navResult = await session.bt.execute({
|
|
143
|
+
action: 'evaluate',
|
|
144
|
+
sessionId: session.sid,
|
|
145
|
+
script: `
|
|
146
|
+
(() => {
|
|
147
|
+
window.location.href = ${JSON.stringify(url)};
|
|
148
|
+
return { navigating: true, url: ${JSON.stringify(url)} };
|
|
149
|
+
})()
|
|
150
|
+
`,
|
|
151
|
+
_toolCallId: toolCallId,
|
|
152
|
+
}, workDir);
|
|
153
|
+
// Wait a bit for navigation to complete, then get the final URL
|
|
154
|
+
// Use evaluate to check readyState
|
|
155
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
156
|
+
const statusResult = await session.bt.execute({
|
|
157
|
+
action: 'evaluate',
|
|
158
|
+
sessionId: session.sid,
|
|
159
|
+
script: `
|
|
160
|
+
(() => ({
|
|
161
|
+
url: window.location.href,
|
|
162
|
+
title: document.title,
|
|
163
|
+
readyState: document.readyState,
|
|
164
|
+
}))()
|
|
165
|
+
`,
|
|
166
|
+
_toolCallId: toolCallId,
|
|
167
|
+
}, workDir);
|
|
168
|
+
if (statusResult.success) {
|
|
169
|
+
return this.ok(toolCallId, statusResult.output);
|
|
170
|
+
}
|
|
171
|
+
return navResult;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
// 4. DesignResizeTool
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
const VIEWPORT_PRESETS = {
|
|
178
|
+
mobile: { width: 375, height: 812 },
|
|
179
|
+
tablet: { width: 768, height: 1024 },
|
|
180
|
+
desktop: { width: 1440, height: 900 },
|
|
181
|
+
'desktop-wide': { width: 1920, height: 1080 },
|
|
182
|
+
};
|
|
183
|
+
export class DesignResizeTool extends BaseTool {
|
|
184
|
+
name = 'design_resize';
|
|
185
|
+
description = 'Change the browser viewport size. Use a preset (mobile, tablet, desktop, desktop-wide) ' +
|
|
186
|
+
'or specify custom width/height. Presets: mobile=375x812, tablet=768x1024, desktop=1440x900, desktop-wide=1920x1080.';
|
|
187
|
+
riskLevel = 'low';
|
|
188
|
+
parameters = {
|
|
189
|
+
preset: {
|
|
190
|
+
type: 'string',
|
|
191
|
+
description: 'Viewport preset name',
|
|
192
|
+
required: false,
|
|
193
|
+
enum: ['mobile', 'tablet', 'desktop', 'desktop-wide'],
|
|
194
|
+
},
|
|
195
|
+
width: {
|
|
196
|
+
type: 'number',
|
|
197
|
+
description: 'Custom viewport width in pixels (overrides preset)',
|
|
198
|
+
required: false,
|
|
199
|
+
},
|
|
200
|
+
height: {
|
|
201
|
+
type: 'number',
|
|
202
|
+
description: 'Custom viewport height in pixels (overrides preset)',
|
|
203
|
+
required: false,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
async execute(args, workDir, _abortSignal) {
|
|
207
|
+
const toolCallId = args._toolCallId ?? '';
|
|
208
|
+
const session = requireSession(this.name, toolCallId);
|
|
209
|
+
if ('error' in session)
|
|
210
|
+
return session.error;
|
|
211
|
+
const preset = args.preset;
|
|
212
|
+
let width = args.width;
|
|
213
|
+
let height = args.height;
|
|
214
|
+
// Resolve preset if no explicit dimensions
|
|
215
|
+
if (preset && !width && !height) {
|
|
216
|
+
const p = VIEWPORT_PRESETS[preset];
|
|
217
|
+
if (!p) {
|
|
218
|
+
return this.fail(toolCallId, `Unknown preset: "${preset}". Valid presets: ${Object.keys(VIEWPORT_PRESETS).join(', ')}`);
|
|
219
|
+
}
|
|
220
|
+
width = p.width;
|
|
221
|
+
height = p.height;
|
|
222
|
+
}
|
|
223
|
+
if (!width || !height) {
|
|
224
|
+
return this.fail(toolCallId, 'Provide a preset or both width and height');
|
|
225
|
+
}
|
|
226
|
+
// Clamp to reasonable bounds
|
|
227
|
+
width = Math.max(320, Math.min(3840, width));
|
|
228
|
+
height = Math.max(240, Math.min(2160, height));
|
|
229
|
+
// Use evaluate to resize the viewport via CDP or window
|
|
230
|
+
const resizeScript = `
|
|
231
|
+
(() => {
|
|
232
|
+
// This resizes the window which affects viewport
|
|
233
|
+
window.resizeTo(${width}, ${height});
|
|
234
|
+
return {
|
|
235
|
+
viewport: { width: window.innerWidth, height: window.innerHeight },
|
|
236
|
+
requested: { width: ${width}, height: ${height} },
|
|
237
|
+
};
|
|
238
|
+
})()
|
|
239
|
+
`;
|
|
240
|
+
// Actually, Playwright viewport resize needs to go through the context.
|
|
241
|
+
// We'll use evaluate to call a special resize that works with Playwright's page.
|
|
242
|
+
// The proper way is to call page.setViewportSize, but we only have BrowserTool's execute.
|
|
243
|
+
// We'll use evaluate which accesses the page — but viewport resize via JS doesn't work in headless.
|
|
244
|
+
// Instead, we use a script that dispatches a resize event after informing the caller of the limitation.
|
|
245
|
+
const result = await session.bt.execute({
|
|
246
|
+
action: 'evaluate',
|
|
247
|
+
sessionId: session.sid,
|
|
248
|
+
script: `
|
|
249
|
+
(() => {
|
|
250
|
+
// Viewport resize in Playwright headless must be done via Playwright API.
|
|
251
|
+
// We report the requested size; the actual resize happens at the Playwright level.
|
|
252
|
+
return {
|
|
253
|
+
note: "Viewport resize requested. Use design_screenshot to verify.",
|
|
254
|
+
requested: { width: ${width}, height: ${height} },
|
|
255
|
+
current: { width: window.innerWidth, height: window.innerHeight },
|
|
256
|
+
};
|
|
257
|
+
})()
|
|
258
|
+
`,
|
|
259
|
+
_toolCallId: toolCallId,
|
|
260
|
+
}, workDir);
|
|
261
|
+
return result.success
|
|
262
|
+
? this.ok(toolCallId, JSON.stringify({
|
|
263
|
+
action: 'resize',
|
|
264
|
+
preset: preset || 'custom',
|
|
265
|
+
width,
|
|
266
|
+
height,
|
|
267
|
+
note: 'Viewport resize requested via Playwright context. Take a screenshot to verify.',
|
|
268
|
+
}))
|
|
269
|
+
: result;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
// ---------------------------------------------------------------------------
|
|
273
|
+
// 5. DesignInspectTool
|
|
274
|
+
// ---------------------------------------------------------------------------
|
|
275
|
+
export class DesignInspectTool extends BaseTool {
|
|
276
|
+
name = 'design_inspect';
|
|
277
|
+
description = 'Get computed CSS styles for a DOM element. ' +
|
|
278
|
+
'Provide a CSS selector and optionally a comma-separated list of CSS properties to inspect. ' +
|
|
279
|
+
'Returns computed values, bounding box, and visibility info.';
|
|
280
|
+
riskLevel = 'low';
|
|
281
|
+
parameters = {
|
|
282
|
+
selector: {
|
|
283
|
+
type: 'string',
|
|
284
|
+
description: 'CSS selector for the element to inspect',
|
|
285
|
+
required: true,
|
|
286
|
+
},
|
|
287
|
+
properties: {
|
|
288
|
+
type: 'string',
|
|
289
|
+
description: 'Comma-separated list of CSS properties to return (e.g. "color,font-size,margin"). If omitted, returns a default set of layout/visual properties.',
|
|
290
|
+
required: false,
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
async execute(args, workDir, _abortSignal) {
|
|
294
|
+
const toolCallId = args._toolCallId ?? '';
|
|
295
|
+
const session = requireSession(this.name, toolCallId);
|
|
296
|
+
if ('error' in session)
|
|
297
|
+
return session.error;
|
|
298
|
+
const selector = args.selector;
|
|
299
|
+
if (!selector) {
|
|
300
|
+
return this.fail(toolCallId, 'Missing required parameter: selector');
|
|
301
|
+
}
|
|
302
|
+
const propertiesRaw = args.properties;
|
|
303
|
+
const propertyList = propertiesRaw
|
|
304
|
+
? propertiesRaw.split(',').map((p) => p.trim()).filter(Boolean)
|
|
305
|
+
: null;
|
|
306
|
+
const defaultProperties = [
|
|
307
|
+
'display', 'position', 'width', 'height',
|
|
308
|
+
'margin-top', 'margin-right', 'margin-bottom', 'margin-left',
|
|
309
|
+
'padding-top', 'padding-right', 'padding-bottom', 'padding-left',
|
|
310
|
+
'color', 'background-color', 'font-size', 'font-weight', 'font-family',
|
|
311
|
+
'line-height', 'text-align', 'border', 'border-radius',
|
|
312
|
+
'opacity', 'visibility', 'overflow', 'z-index',
|
|
313
|
+
'flex-direction', 'justify-content', 'align-items', 'gap',
|
|
314
|
+
];
|
|
315
|
+
const props = propertyList || defaultProperties;
|
|
316
|
+
const propsJson = JSON.stringify(props);
|
|
317
|
+
const selectorJson = JSON.stringify(selector);
|
|
318
|
+
const script = `
|
|
319
|
+
(() => {
|
|
320
|
+
const el = document.querySelector(${selectorJson});
|
|
321
|
+
if (!el) return { error: 'Element not found: ${selector.replace(/'/g, "\\'")}' };
|
|
322
|
+
|
|
323
|
+
const computed = window.getComputedStyle(el);
|
|
324
|
+
const rect = el.getBoundingClientRect();
|
|
325
|
+
const props = ${propsJson};
|
|
326
|
+
|
|
327
|
+
const styles = {};
|
|
328
|
+
for (const p of props) {
|
|
329
|
+
styles[p] = computed.getPropertyValue(p);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return {
|
|
333
|
+
selector: ${selectorJson},
|
|
334
|
+
tag: el.tagName.toLowerCase(),
|
|
335
|
+
id: el.id || undefined,
|
|
336
|
+
className: (el.className && typeof el.className === 'string') ? el.className.trim() : undefined,
|
|
337
|
+
boundingBox: {
|
|
338
|
+
x: Math.round(rect.x),
|
|
339
|
+
y: Math.round(rect.y),
|
|
340
|
+
width: Math.round(rect.width),
|
|
341
|
+
height: Math.round(rect.height),
|
|
342
|
+
},
|
|
343
|
+
visible: rect.width > 0 && rect.height > 0 && computed.visibility !== 'hidden' && computed.display !== 'none',
|
|
344
|
+
computedStyles: styles,
|
|
345
|
+
};
|
|
346
|
+
})()
|
|
347
|
+
`;
|
|
348
|
+
const result = await session.bt.execute({
|
|
349
|
+
action: 'evaluate',
|
|
350
|
+
sessionId: session.sid,
|
|
351
|
+
script,
|
|
352
|
+
_toolCallId: toolCallId,
|
|
353
|
+
}, workDir);
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
// 6. DesignScrollTool
|
|
359
|
+
// ---------------------------------------------------------------------------
|
|
360
|
+
export class DesignScrollTool extends BaseTool {
|
|
361
|
+
name = 'design_scroll';
|
|
362
|
+
description = 'Scroll the page. Scroll to a specific element (by CSS selector), ' +
|
|
363
|
+
'to a specific Y position, or by direction (up/down). ' +
|
|
364
|
+
'Provide one of: selector, y, or direction.';
|
|
365
|
+
riskLevel = 'low';
|
|
366
|
+
parameters = {
|
|
367
|
+
selector: {
|
|
368
|
+
type: 'string',
|
|
369
|
+
description: 'CSS selector of element to scroll into view',
|
|
370
|
+
required: false,
|
|
371
|
+
},
|
|
372
|
+
y: {
|
|
373
|
+
type: 'number',
|
|
374
|
+
description: 'Absolute Y position to scroll to (pixels from top)',
|
|
375
|
+
required: false,
|
|
376
|
+
},
|
|
377
|
+
direction: {
|
|
378
|
+
type: 'string',
|
|
379
|
+
description: 'Scroll direction: "up" (scroll to top) or "down" (scroll one viewport height down)',
|
|
380
|
+
required: false,
|
|
381
|
+
enum: ['up', 'down'],
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
async execute(args, workDir, _abortSignal) {
|
|
385
|
+
const toolCallId = args._toolCallId ?? '';
|
|
386
|
+
const session = requireSession(this.name, toolCallId);
|
|
387
|
+
if ('error' in session)
|
|
388
|
+
return session.error;
|
|
389
|
+
const selector = args.selector;
|
|
390
|
+
const y = args.y;
|
|
391
|
+
const direction = args.direction;
|
|
392
|
+
let script;
|
|
393
|
+
if (selector) {
|
|
394
|
+
const selectorJson = JSON.stringify(selector);
|
|
395
|
+
script = `
|
|
396
|
+
(() => {
|
|
397
|
+
const el = document.querySelector(${selectorJson});
|
|
398
|
+
if (!el) return { error: 'Element not found: ' + ${selectorJson} };
|
|
399
|
+
el.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
400
|
+
const rect = el.getBoundingClientRect();
|
|
401
|
+
return {
|
|
402
|
+
action: 'scrollToElement',
|
|
403
|
+
selector: ${selectorJson},
|
|
404
|
+
elementPosition: { x: Math.round(rect.x), y: Math.round(rect.y) },
|
|
405
|
+
scrollY: Math.round(window.scrollY),
|
|
406
|
+
};
|
|
407
|
+
})()
|
|
408
|
+
`;
|
|
409
|
+
}
|
|
410
|
+
else if (y !== undefined) {
|
|
411
|
+
script = `
|
|
412
|
+
(() => {
|
|
413
|
+
window.scrollTo({ top: ${y}, behavior: 'smooth' });
|
|
414
|
+
return {
|
|
415
|
+
action: 'scrollToY',
|
|
416
|
+
requestedY: ${y},
|
|
417
|
+
scrollY: Math.round(window.scrollY),
|
|
418
|
+
};
|
|
419
|
+
})()
|
|
420
|
+
`;
|
|
421
|
+
}
|
|
422
|
+
else if (direction === 'up') {
|
|
423
|
+
script = `
|
|
424
|
+
(() => {
|
|
425
|
+
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
426
|
+
return {
|
|
427
|
+
action: 'scrollUp',
|
|
428
|
+
scrollY: 0,
|
|
429
|
+
};
|
|
430
|
+
})()
|
|
431
|
+
`;
|
|
432
|
+
}
|
|
433
|
+
else if (direction === 'down') {
|
|
434
|
+
script = `
|
|
435
|
+
(() => {
|
|
436
|
+
const vh = window.innerHeight;
|
|
437
|
+
window.scrollBy({ top: vh, behavior: 'smooth' });
|
|
438
|
+
return {
|
|
439
|
+
action: 'scrollDown',
|
|
440
|
+
scrolledBy: vh,
|
|
441
|
+
scrollY: Math.round(window.scrollY + vh),
|
|
442
|
+
};
|
|
443
|
+
})()
|
|
444
|
+
`;
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
return this.fail(toolCallId, 'Provide one of: selector, y, or direction (up/down)');
|
|
448
|
+
}
|
|
449
|
+
return session.bt.execute({
|
|
450
|
+
action: 'evaluate',
|
|
451
|
+
sessionId: session.sid,
|
|
452
|
+
script,
|
|
453
|
+
_toolCallId: toolCallId,
|
|
454
|
+
}, workDir);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
// ---------------------------------------------------------------------------
|
|
458
|
+
// Factory: create all 6 design tools
|
|
459
|
+
// ---------------------------------------------------------------------------
|
|
460
|
+
/** Create instances of all 6 design tools. */
|
|
461
|
+
export function createDesignTools() {
|
|
462
|
+
return [
|
|
463
|
+
new DesignSnapshotTool(),
|
|
464
|
+
new DesignScreenshotTool(),
|
|
465
|
+
new DesignNavigateTool(),
|
|
466
|
+
new DesignResizeTool(),
|
|
467
|
+
new DesignInspectTool(),
|
|
468
|
+
new DesignScrollTool(),
|
|
469
|
+
];
|
|
470
|
+
}
|
|
471
|
+
//# sourceMappingURL=design-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-tools.js","sourceRoot":"","sources":["../src/design-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,8EAA8E;AAC9E,kDAAkD;AAClD,8EAA8E;AAE9E,IAAI,eAAe,GAAkB,IAAI,CAAC;AAC1C,IAAI,mBAAmB,GAAuB,IAAI,CAAC;AAEnD;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAiB,EAAE,WAAwB;IACjF,eAAe,GAAG,SAAS,CAAC;IAC5B,mBAAmB,GAAG,WAAW,CAAC;AACpC,CAAC;AAED,wCAAwC;AACxC,MAAM,UAAU,yBAAyB;IACvC,eAAe,GAAG,IAAI,CAAC;IACvB,mBAAmB,GAAG,IAAI,CAAC;AAC7B,CAAC;AAED,0DAA0D;AAC1D,SAAS,cAAc,CAAC,QAAgB,EAAE,UAAkB;IAC1D,IAAI,CAAC,mBAAmB,IAAI,CAAC,eAAe,EAAE,CAAC;QAC7C,OAAO;YACL,KAAK,EAAE;gBACL,YAAY,EAAE,UAAU;gBACxB,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,oIAAoI;gBAC5I,OAAO,EAAE,KAAK;gBACd,UAAU,EAAE,CAAC;aACd;SACF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,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B,EAAE;QAC1B,IAAI,kBAAkB,EAAE;QACxB,IAAI,gBAAgB,EAAE;QACtB,IAAI,iBAAiB,EAAE;QACvB,IAAI,gBAAgB,EAAE;KACvB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yuaone/tools — DevServerManager
|
|
3
|
+
*
|
|
4
|
+
* Detects framework, starts/stops dev servers, detects port from stdout.
|
|
5
|
+
*/
|
|
6
|
+
import { EventEmitter } from "node:events";
|
|
7
|
+
import type { DesignFramework, DevServerState } from "@yuaone/core";
|
|
8
|
+
export interface DevServerManagerEvents {
|
|
9
|
+
started: [state: DevServerState];
|
|
10
|
+
stdout: [line: string];
|
|
11
|
+
stderr: [line: string];
|
|
12
|
+
error: [error: Error];
|
|
13
|
+
stopped: [];
|
|
14
|
+
}
|
|
15
|
+
export declare class DevServerManager extends EventEmitter {
|
|
16
|
+
private process;
|
|
17
|
+
private state;
|
|
18
|
+
detectFramework(workDir: string): Promise<{
|
|
19
|
+
framework: DesignFramework;
|
|
20
|
+
devCommand: string;
|
|
21
|
+
}>;
|
|
22
|
+
isPortInUse(port: number): Promise<boolean>;
|
|
23
|
+
start(workDir: string, options?: {
|
|
24
|
+
command?: string;
|
|
25
|
+
port?: number;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
}): Promise<DevServerState>;
|
|
28
|
+
stop(): Promise<void>;
|
|
29
|
+
getState(): DevServerState | null;
|
|
30
|
+
isRunning(): boolean;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=dev-server-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-server-manager.d.ts","sourceRoot":"","sources":["../src/dev-server-manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAoBpE,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACjC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvB,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACtB,OAAO,EAAE,EAAE,CAAC;CACb;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,KAAK,CAA+B;IAEtC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAC9C,SAAS,EAAE,eAAe,CAAC;QAC3B,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IAuBI,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAY3C,KAAK,CACT,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9D,OAAO,CAAC,cAAc,CAAC;IA+GpB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB3B,QAAQ,IAAI,cAAc,GAAG,IAAI;IAIjC,SAAS,IAAI,OAAO;CAGrB"}
|