Skip to content

Commit 9f4f1a9

Browse files
author
GitLab CI
committed
feat: reset_app + snapshot as built-in serve commands
- reset_app clears localStorage/sessionStorage/cookies and reloads - Auto re-scans tools after reset - snapshot tool callable via tools/call endpoint
1 parent f592978 commit 9f4f1a9

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

lib/src/cli/serve.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,59 @@ Future<void> _handleRequest(
239239
}
240240

241241
print(' 🔧 Calling tool: $toolName');
242+
243+
// Built-in tools handled by serve
244+
if (toolName == 'reset_app') {
245+
final clearStorage = toolArgs['clear_storage'] ?? true;
246+
final clearCookies = toolArgs['clear_cookies'] ?? true;
247+
final actions = <String>[];
248+
if (clearStorage) {
249+
await cdp.call('Runtime.evaluate', {
250+
'expression': 'localStorage.clear(); sessionStorage.clear();',
251+
'returnByValue': true,
252+
});
253+
actions.add('storage cleared');
254+
}
255+
if (clearCookies) {
256+
try {
257+
await cdp.call('Network.enable');
258+
await cdp.call('Network.clearBrowserCookies');
259+
} catch (_) {}
260+
actions.add('cookies cleared');
261+
}
262+
await cdp.call('Page.reload', {'ignoreCache': true});
263+
await Future.delayed(const Duration(seconds: 2));
264+
// Re-scan tools after reset
265+
state.tools = await _discoverTools(cdp);
266+
state.updatedAt = DateTime.now();
267+
actions.add('page reloaded');
268+
response
269+
..statusCode = 200
270+
..headers.contentType = ContentType.json
271+
..write(jsonEncode({
272+
'success': true,
273+
'actions': actions,
274+
'tools': state.tools.length,
275+
}));
276+
await response.close();
277+
return;
278+
}
279+
280+
if (toolName == 'snapshot') {
281+
// Redirect to /snapshot
282+
final result = await cdp.call('Runtime.evaluate', {
283+
'expression': _snapshotJs,
284+
'returnByValue': true,
285+
});
286+
final text = result['result']?['value'] as String? ?? '';
287+
response
288+
..statusCode = 200
289+
..headers.contentType = ContentType.json
290+
..write(jsonEncode({'snapshot': text, 'length': text.length}));
291+
await response.close();
292+
return;
293+
}
294+
242295
final result = await cdp.callTool(toolName, toolArgs);
243296
response
244297
..statusCode = 200

0 commit comments

Comments
 (0)