@ytspar/sweetlink 0.0.1 → 1.0.0-canary.19cb05c

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.
Files changed (128) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +579 -28
  3. package/dist/browser/SweetlinkBridge.d.ts +69 -0
  4. package/dist/browser/SweetlinkBridge.d.ts.map +1 -0
  5. package/dist/browser/SweetlinkBridge.js +360 -0
  6. package/dist/browser/SweetlinkBridge.js.map +1 -0
  7. package/dist/browser/commands/dom.d.ts +11 -0
  8. package/dist/browser/commands/dom.d.ts.map +1 -0
  9. package/dist/browser/commands/dom.js +79 -0
  10. package/dist/browser/commands/dom.js.map +1 -0
  11. package/dist/browser/commands/exec.d.ts +14 -0
  12. package/dist/browser/commands/exec.d.ts.map +1 -0
  13. package/dist/browser/commands/exec.js +47 -0
  14. package/dist/browser/commands/exec.js.map +1 -0
  15. package/dist/browser/commands/index.d.ts +10 -0
  16. package/dist/browser/commands/index.d.ts.map +1 -0
  17. package/dist/browser/commands/index.js +10 -0
  18. package/dist/browser/commands/index.js.map +1 -0
  19. package/dist/browser/commands/logs.d.ts +11 -0
  20. package/dist/browser/commands/logs.d.ts.map +1 -0
  21. package/dist/browser/commands/logs.js +25 -0
  22. package/dist/browser/commands/logs.js.map +1 -0
  23. package/dist/browser/commands/screenshot.d.ts +16 -0
  24. package/dist/browser/commands/screenshot.d.ts.map +1 -0
  25. package/dist/browser/commands/screenshot.js +118 -0
  26. package/dist/browser/commands/screenshot.js.map +1 -0
  27. package/dist/browser/consoleCapture.d.ts +107 -0
  28. package/dist/browser/consoleCapture.d.ts.map +1 -0
  29. package/dist/browser/consoleCapture.js +215 -0
  30. package/dist/browser/consoleCapture.js.map +1 -0
  31. package/dist/browser/hmr.d.ts +25 -0
  32. package/dist/browser/hmr.d.ts.map +1 -0
  33. package/dist/browser/hmr.js +97 -0
  34. package/dist/browser/hmr.js.map +1 -0
  35. package/dist/browser/screenshotUtils.d.ts +102 -0
  36. package/dist/browser/screenshotUtils.d.ts.map +1 -0
  37. package/dist/browser/screenshotUtils.js +143 -0
  38. package/dist/browser/screenshotUtils.js.map +1 -0
  39. package/dist/browser.d.ts +2 -0
  40. package/dist/browser.d.ts.map +1 -0
  41. package/dist/browser.js +5 -0
  42. package/dist/browser.js.map +1 -0
  43. package/dist/cdp.d.ts +99 -0
  44. package/dist/cdp.d.ts.map +1 -0
  45. package/dist/cdp.js +347 -0
  46. package/dist/cdp.js.map +1 -0
  47. package/dist/cli/sweetlink-dev.d.ts +14 -0
  48. package/dist/cli/sweetlink-dev.d.ts.map +1 -0
  49. package/dist/cli/sweetlink-dev.js +36 -0
  50. package/dist/cli/sweetlink-dev.js.map +1 -0
  51. package/dist/cli/sweetlink.d.ts +9 -0
  52. package/dist/cli/sweetlink.d.ts.map +1 -0
  53. package/dist/cli/sweetlink.js +1018 -0
  54. package/dist/cli/sweetlink.js.map +1 -0
  55. package/dist/index.d.ts +17 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +22 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/playwright.d.ts +29 -0
  60. package/dist/playwright.d.ts.map +1 -0
  61. package/dist/playwright.js +172 -0
  62. package/dist/playwright.js.map +1 -0
  63. package/dist/ruler.d.ts +82 -0
  64. package/dist/ruler.d.ts.map +1 -0
  65. package/dist/ruler.js +293 -0
  66. package/dist/ruler.js.map +1 -0
  67. package/dist/server/anthropic.d.ts +19 -0
  68. package/dist/server/anthropic.d.ts.map +1 -0
  69. package/dist/server/anthropic.js +26 -0
  70. package/dist/server/anthropic.js.map +1 -0
  71. package/dist/server/constants.d.ts +17 -0
  72. package/dist/server/constants.d.ts.map +1 -0
  73. package/dist/server/constants.js +17 -0
  74. package/dist/server/constants.js.map +1 -0
  75. package/dist/server/handlers/designReview.d.ts +27 -0
  76. package/dist/server/handlers/designReview.d.ts.map +1 -0
  77. package/dist/server/handlers/designReview.js +165 -0
  78. package/dist/server/handlers/designReview.js.map +1 -0
  79. package/dist/server/handlers/hmr.d.ts +21 -0
  80. package/dist/server/handlers/hmr.d.ts.map +1 -0
  81. package/dist/server/handlers/hmr.js +81 -0
  82. package/dist/server/handlers/hmr.js.map +1 -0
  83. package/dist/server/handlers/index.d.ts +12 -0
  84. package/dist/server/handlers/index.d.ts.map +1 -0
  85. package/dist/server/handlers/index.js +12 -0
  86. package/dist/server/handlers/index.js.map +1 -0
  87. package/dist/server/handlers/outline.d.ts +19 -0
  88. package/dist/server/handlers/outline.d.ts.map +1 -0
  89. package/dist/server/handlers/outline.js +41 -0
  90. package/dist/server/handlers/outline.js.map +1 -0
  91. package/dist/server/handlers/schema.d.ts +19 -0
  92. package/dist/server/handlers/schema.d.ts.map +1 -0
  93. package/dist/server/handlers/schema.js +49 -0
  94. package/dist/server/handlers/schema.js.map +1 -0
  95. package/dist/server/handlers/screenshot.d.ts +51 -0
  96. package/dist/server/handlers/screenshot.d.ts.map +1 -0
  97. package/dist/server/handlers/screenshot.js +101 -0
  98. package/dist/server/handlers/screenshot.js.map +1 -0
  99. package/dist/server/handlers/settings.d.ts +53 -0
  100. package/dist/server/handlers/settings.d.ts.map +1 -0
  101. package/dist/server/handlers/settings.js +69 -0
  102. package/dist/server/handlers/settings.js.map +1 -0
  103. package/dist/server/index.d.ts +33 -0
  104. package/dist/server/index.d.ts.map +1 -0
  105. package/dist/server/index.js +539 -0
  106. package/dist/server/index.js.map +1 -0
  107. package/dist/server/subscriptions.d.ts +26 -0
  108. package/dist/server/subscriptions.d.ts.map +1 -0
  109. package/dist/server/subscriptions.js +35 -0
  110. package/dist/server/subscriptions.js.map +1 -0
  111. package/dist/server.d.ts +8 -0
  112. package/dist/server.d.ts.map +1 -0
  113. package/dist/server.js +8 -0
  114. package/dist/server.js.map +1 -0
  115. package/dist/types.d.ts +132 -0
  116. package/dist/types.d.ts.map +1 -0
  117. package/dist/types.js +8 -0
  118. package/dist/types.js.map +1 -0
  119. package/dist/urlUtils.d.ts +75 -0
  120. package/dist/urlUtils.d.ts.map +1 -0
  121. package/dist/urlUtils.js +121 -0
  122. package/dist/urlUtils.js.map +1 -0
  123. package/dist/viewportUtils.d.ts +51 -0
  124. package/dist/viewportUtils.d.ts.map +1 -0
  125. package/dist/viewportUtils.js +70 -0
  126. package/dist/viewportUtils.js.map +1 -0
  127. package/package.json +98 -6
  128. package/scripts/setup-claude-context.mjs +101 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ytspar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,45 +1,596 @@
1
1
  # @ytspar/sweetlink
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
3
+ [![npm](https://img.shields.io/npm/v/@ytspar/sweetlink)](https://www.npmjs.com/package/@ytspar/sweetlink)
4
4
 
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
5
+ > Autonomous development toolkit for Claude AI agents - screenshots, DOM queries, console logs, and JavaScript execution via WebSocket and Chrome DevTools Protocol
6
6
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
7
+ ## Overview
8
8
 
9
- ## Purpose
9
+ Sweetlink enables Claude AI agents to autonomously debug, test, and iterate on web applications through real-time browser interaction. It provides a WebSocket bridge between your development server and CLI tools, allowing AI assistants to take screenshots, inspect DOM, capture console logs, and execute JavaScript - all without human intervention.
10
10
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@ytspar/sweetlink`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
11
+ **Inspired by**: [Peter Steinberger's autonomous debugging implementation](https://x.com/steipete/status/1981998733736001727) - "Now my agent can debug everything completely autonomous e2e."
15
12
 
16
- ## What is OIDC Trusted Publishing?
13
+ ## Features
17
14
 
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
15
+ - **📸 Screenshots** - Capture full page or element-specific screenshots (html2canvas + CDP)
16
+ - **🖱️ Screenshot Button** - One-click screenshot capture with console logs from browser UI
17
+ - **🔍 DOM Queries** - Query and inspect DOM elements with CSS selectors
18
+ - **📊 Console Logs** - Capture and filter browser console output with JSON/summary formats
19
+ - **⚡ JavaScript Execution** - Run arbitrary JavaScript in browser context
20
+ - **🖱️ Click Elements** - Click elements by selector, text content, or both
21
+ - **🌐 Network Inspection** - Monitor network requests (CDP only)
22
+ - **🔄 Page Refresh** - Soft or hard refresh the browser from CLI
23
+ - **🔄 Auto Reconnection** - Browser client automatically reconnects on disconnect
24
+ - **🎯 Token Efficient** - ~1000 tokens/screenshot vs ~5000 for MCP tools
25
+ - **📝 LLM-Optimized Output** - Summary format with deduplication for context efficiency
26
+ - **🚀 Zero Setup** - Works immediately with any web app
19
27
 
20
- ## Setup Instructions
28
+ ## Screenshot Button
21
29
 
22
- To properly configure OIDC trusted publishing for this package:
30
+ The browser UI includes a convenient screenshot button (📸) that allows developers and AI agents to instantly capture the current page state along with console logs. When clicked:
23
31
 
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
32
+ 1. **Captures full page screenshot** using html2canvas
33
+ 2. **Saves screenshot** to `.tmp/sweetlink-screenshots/screenshot-[timestamp].png`
34
+ 3. **Saves console logs** to `.tmp/sweetlink-screenshots/screenshot-[timestamp]-logs.txt`
35
+ 4. **Logs include**: timestamp, URL, dimensions, and all console messages
28
36
 
29
- ## DO NOT USE THIS PACKAGE
37
+ This provides AI agents with easy access to visual state and debugging information without requiring CLI commands.
30
38
 
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
39
+ **File Location Rationale**: Files are saved to `.tmp/sweetlink-screenshots/` (relative to project root) for easy agent access - keeps screenshots with the project and is typically gitignored via `.tmp/` patterns.
36
40
 
37
- ## More Information
41
+ ## Installation
38
42
 
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
43
+ ```bash
44
+ npm install @ytspar/sweetlink
45
+ # or
46
+ pnpm add @ytspar/sweetlink
47
+ # or
48
+ yarn add @ytspar/sweetlink
42
49
 
43
- ---
50
+ # Install canary (latest from main)
51
+ pnpm add @ytspar/sweetlink@canary
52
+ ```
44
53
 
45
- **Maintained for OIDC setup purposes only**
54
+ ## Quick Start
55
+
56
+ ### 1. Add Sweetlink Server to Your Dev Setup
57
+
58
+ #### For Remix Apps
59
+
60
+ ```typescript
61
+ // server.ts or entry.server.tsx
62
+ import { initSweetlink } from '@ytspar/sweetlink';
63
+
64
+ if (process.env.NODE_ENV === 'development') {
65
+ const port = parseInt(process.env.SWEETLINK_WS_PORT || '9223', 10);
66
+ initSweetlink({ port });
67
+ console.log(`[Sweetlink] WebSocket server started on ws://localhost:${port}`);
68
+ }
69
+ ```
70
+
71
+ #### For Next.js Apps
72
+
73
+ ```typescript
74
+ // next.config.js
75
+ const { initSweetlink } = require('@ytspar/sweetlink');
76
+
77
+ if (process.env.NODE_ENV === 'development') {
78
+ initSweetlink({ port: 9223 });
79
+ }
80
+
81
+ module.exports = {
82
+ // your next config...
83
+ }
84
+ ```
85
+
86
+ #### For Vite Apps
87
+
88
+ ```typescript
89
+ // vite.config.ts
90
+ import { defineConfig } from 'vite';
91
+ import { initSweetlink } from '@ytspar/sweetlink';
92
+
93
+ if (process.env.NODE_ENV === 'development') {
94
+ initSweetlink({ port: 9223 });
95
+ }
96
+
97
+ export default defineConfig({
98
+ // your vite config...
99
+ });
100
+ ```
101
+
102
+ ### 2. Add Browser Bridge Component
103
+
104
+ #### Basic Usage (Standard Tailwind Colors)
105
+
106
+ ```typescript
107
+ // app/root.tsx (Remix) or _app.tsx (Next.js) or App.tsx (React)
108
+ import { SweetlinkBridge } from '@ytspar/sweetlink/browser';
109
+
110
+ export default function App() {
111
+ return (
112
+ <>
113
+ {/* Your app content */}
114
+ {process.env.NODE_ENV === 'development' && <SweetlinkBridge />}
115
+ </>
116
+ );
117
+ }
118
+ ```
119
+
120
+ #### Custom Theme Colors
121
+
122
+ ```typescript
123
+ import { SweetlinkBridge } from '@ytspar/sweetlink/browser';
124
+
125
+ export default function App() {
126
+ return (
127
+ <>
128
+ {/* Your app content */}
129
+ {process.env.NODE_ENV === 'development' && (
130
+ <SweetlinkBridge
131
+ connectedStyles="bg-terminal-green/20 border-terminal-green text-terminal-green"
132
+ disconnectedStyles="bg-gray-700/20 border-gray-600 text-gray-400"
133
+ />
134
+ )}
135
+ </>
136
+ );
137
+ }
138
+ ```
139
+
140
+ ### 3. Add CLI Scripts to package.json
141
+
142
+ ```json
143
+ {
144
+ "scripts": {
145
+ "dev": "run-p dev:app sweetlink:dev",
146
+ "dev:app": "remix dev",
147
+ "sweetlink:dev": "sweetlink-dev",
148
+ "sweetlink": "sweetlink"
149
+ },
150
+ "devDependencies": {
151
+ "npm-run-all": "^4.1.5"
152
+ }
153
+ }
154
+ ```
155
+
156
+ ### 4. Start Development
157
+
158
+ ```bash
159
+ pnpm dev
160
+ ```
161
+
162
+ You should see:
163
+
164
+ ```
165
+ [Sweetlink] WebSocket server started on ws://localhost:9223
166
+ 💿 Remix App Server started at http://localhost:3000
167
+ [Sweetlink] Connected to server
168
+ ```
169
+
170
+ ## CLI Usage
171
+
172
+ ### Screenshots
173
+
174
+ ```bash
175
+ # Full page screenshot
176
+ pnpm sweetlink screenshot
177
+
178
+ # Element screenshot
179
+ pnpm sweetlink screenshot --selector ".company-card"
180
+
181
+ # Full page with custom output
182
+ pnpm sweetlink screenshot --full-page --output page.png
183
+
184
+ # Force CDP method (requires Chrome debugging)
185
+ pnpm sweetlink screenshot --force-cdp
186
+ ```
187
+
188
+ ### DOM Queries
189
+
190
+ ```bash
191
+ # Query elements
192
+ pnpm sweetlink query --selector "h1"
193
+
194
+ # Get element property
195
+ pnpm sweetlink query --selector ".card" --property "offsetWidth"
196
+ ```
197
+
198
+ ### Console Logs
199
+
200
+ ```bash
201
+ # Get all logs
202
+ pnpm sweetlink logs
203
+
204
+ # Filter by error
205
+ pnpm sweetlink logs --filter "error"
206
+
207
+ # JSON output (full array)
208
+ pnpm sweetlink logs --format json
209
+
210
+ # LLM-optimized summary (deduplicated, sorted by severity)
211
+ pnpm sweetlink logs --format summary
212
+
213
+ # Text format with deduplication
214
+ pnpm sweetlink logs --dedupe
215
+ ```
216
+
217
+ #### Log Output Formats
218
+
219
+ | Format | Description | Best For |
220
+ |--------|-------------|----------|
221
+ | `text` (default) | Human-readable timestamped lines | Manual debugging |
222
+ | `json` | Full JSON array with all entries | Programmatic access |
223
+ | `summary` | Compact JSON with deduplication | LLM context optimization |
224
+
225
+ **Summary format example:**
226
+ ```json
227
+ {
228
+ "url": "http://localhost:3000",
229
+ "capturedAt": "2025-01-27T...",
230
+ "totalLogs": 47,
231
+ "uniqueLogs": 3,
232
+ "byLevel": { "error": 2, "warn": 0, "log": 1 },
233
+ "logs": [
234
+ { "level": "error", "message": "...", "count": 25 },
235
+ { "level": "log", "message": "...", "count": 22 }
236
+ ]
237
+ }
238
+ ```
239
+
240
+ ### Page Refresh
241
+
242
+ ```bash
243
+ # Soft refresh (reload page)
244
+ pnpm sweetlink refresh
245
+
246
+ # Hard refresh (clear cache and reload)
247
+ pnpm sweetlink refresh --hard
248
+ ```
249
+
250
+ ### JavaScript Execution
251
+
252
+ ```bash
253
+ # Execute JavaScript
254
+ pnpm sweetlink exec --code "document.title"
255
+
256
+ # Count elements
257
+ pnpm sweetlink exec --code "document.querySelectorAll('.card').length"
258
+ ```
259
+
260
+ ### Click Elements
261
+
262
+ ```bash
263
+ # Click by CSS selector
264
+ pnpm sweetlink click --selector "button.submit"
265
+
266
+ # Click by text content
267
+ pnpm sweetlink click --text "Submit"
268
+
269
+ # Combine selector + text for precise matching
270
+ pnpm sweetlink click --selector "th" --text "Rank"
271
+ pnpm sweetlink click --selector "a" --text "BACK TO LIST"
272
+
273
+ # Select nth match (0-based index)
274
+ pnpm sweetlink click --selector ".tab" --index 2
275
+ ```
276
+
277
+ **Options:**
278
+ | Option | Description |
279
+ |--------|-------------|
280
+ | `--selector` | CSS selector to find elements |
281
+ | `--text` | Find element by text content |
282
+ | `--index` | Select nth match when multiple found (default: 0) |
283
+
284
+ **Debugging:** Use `DEBUG=1 pnpm sweetlink click ...` to see generated JavaScript.
285
+
286
+ ### Network Requests (CDP Required)
287
+
288
+ ```bash
289
+ # Get all network requests
290
+ pnpm sweetlink network
291
+
292
+ # Filter by URL
293
+ pnpm sweetlink network --filter "/api/"
294
+ ```
295
+
296
+ ## Chrome DevTools Protocol (CDP) Setup
297
+
298
+ For native Chrome rendering and network inspection:
299
+
300
+ ```bash
301
+ # macOS
302
+ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
303
+
304
+ # Linux
305
+ google-chrome --remote-debugging-port=9222
306
+
307
+ # Windows
308
+ "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
309
+ ```
310
+
311
+ Set environment variable (optional):
312
+
313
+ ```bash
314
+ export CHROME_CDP_PORT=9222
315
+ ```
316
+
317
+ ## Programmatic API
318
+
319
+ ### Server
320
+
321
+ ```typescript
322
+ import { initSweetlink, closeSweetlink } from '@ytspar/sweetlink';
323
+
324
+ // Start server
325
+ const wss = initSweetlink({ port: 9223 });
326
+
327
+ // Close server
328
+ closeSweetlink();
329
+ ```
330
+
331
+ ### CDP Integration
332
+
333
+ ```typescript
334
+ import {
335
+ detectCDP,
336
+ getCDPBrowser,
337
+ screenshotViaCDP,
338
+ getNetworkRequestsViaCDP
339
+ } from '@ytspar/sweetlink/cdp';
340
+
341
+ // Check if CDP is available
342
+ const hasCDP = await detectCDP();
343
+
344
+ // Take screenshot via CDP
345
+ const result = await screenshotViaCDP({
346
+ output: 'screenshot.png',
347
+ fullPage: true
348
+ });
349
+
350
+ // Get network requests
351
+ const requests = await getNetworkRequestsViaCDP({
352
+ filter: '/api/'
353
+ });
354
+ ```
355
+
356
+ ### Browser Component
357
+
358
+ ```typescript
359
+ import { SweetlinkBridge } from '@ytspar/sweetlink/browser';
360
+ import type { SweetlinkBridgeProps } from '@ytspar/sweetlink/browser';
361
+
362
+ // Default usage (connects to ws://localhost:9223, standard colors)
363
+ <SweetlinkBridge />
364
+
365
+ // Custom theme colors (terminal green)
366
+ <SweetlinkBridge
367
+ connectedStyles="bg-terminal-green/20 border-terminal-green text-terminal-green"
368
+ disconnectedStyles="bg-gray-700/20 border-gray-600 text-gray-400"
369
+ />
370
+
371
+ // Custom WebSocket URL
372
+ <SweetlinkBridge wsUrl="ws://localhost:9224" />
373
+ ```
374
+
375
+ #### SweetlinkBridgeProps
376
+
377
+ | Prop | Type | Default | Description |
378
+ |------|------|---------|-------------|
379
+ | `connectedStyles` | `string` | `'bg-green-500/20 border-green-500 text-green-500'` | Tailwind classes for connected state |
380
+ | `disconnectedStyles` | `string` | `'bg-gray-700/20 border-gray-600 text-gray-400'` | Tailwind classes for disconnected state |
381
+ | `wsUrl` | `string` | `'ws://localhost:9223'` | WebSocket server URL |
382
+
383
+ ## Environment Variables
384
+
385
+ | Variable | Default | Description |
386
+ |----------|---------|-------------|
387
+ | `SWEETLINK_WS_PORT` | `9223` | WebSocket server port |
388
+ | `SWEETLINK_WS_URL` | `ws://localhost:9223` | WebSocket URL (CLI) |
389
+ | `CHROME_CDP_PORT` | `9222` | Chrome DevTools Protocol port |
390
+ | `CHROME_CDP_URL` | `http://127.0.0.1:9222` | CDP URL |
391
+
392
+ ## Architecture
393
+
394
+ ```mermaid
395
+ flowchart TB
396
+ subgraph CLI["Claude AI Agent (CLI)"]
397
+ screenshot["Screenshot"]
398
+ query["DOM Query"]
399
+ logs["Logs"]
400
+ exec["Exec JS"]
401
+ end
402
+
403
+ subgraph Server["Sweetlink Server"]
404
+ mux["WebSocket Multiplexer"]
405
+ r1["Routes CLI commands to browser"]
406
+ r2["Routes browser responses to CLI"]
407
+ end
408
+
409
+ subgraph Browser["Browser (Your App)"]
410
+ subgraph Bridge["SweetlinkBridge"]
411
+ b1["Captures console logs"]
412
+ b2["Executes commands (screenshot, query, exec)"]
413
+ b3["Auto-reconnects on disconnect"]
414
+ end
415
+ html2canvas["html2canvas (screenshots)"]
416
+ end
417
+
418
+ CLI <-->|"WebSocket :9223"| Server
419
+ Server <-->|"WebSocket :9223"| Browser
420
+ ```
421
+
422
+ ## Use Cases
423
+
424
+ ### Autonomous UI Development
425
+
426
+ ```typescript
427
+ while (!designPerfect) {
428
+ // Make UI changes
429
+ await editComponent();
430
+
431
+ // Take screenshot
432
+ await exec('pnpm sweetlink screenshot --selector ".component"');
433
+
434
+ // Check for console errors
435
+ const logs = await exec('pnpm sweetlink logs --filter error');
436
+
437
+ // Iterate until perfect!
438
+ }
439
+ ```
440
+
441
+ ### Automated Testing
442
+
443
+ ```bash
444
+ # Take baseline screenshot
445
+ pnpm sweetlink screenshot --output baseline.png
446
+
447
+ # Make changes...
448
+
449
+ # Take comparison screenshot
450
+ pnpm sweetlink screenshot --output comparison.png
451
+
452
+ # Compare screenshots with image diff tool
453
+ ```
454
+
455
+ ### Debugging Production Issues
456
+
457
+ ```bash
458
+ # Get console errors
459
+ pnpm sweetlink logs --filter error
460
+
461
+ # Inspect element state
462
+ pnpm sweetlink query --selector ".error-component"
463
+
464
+ # Execute debug code
465
+ pnpm sweetlink exec --code "localStorage.getItem('debug')"
466
+ ```
467
+
468
+ ## Token Efficiency
469
+
470
+ Sweetlink is designed for token-efficient autonomous loops:
471
+
472
+ - **html2canvas screenshots**: ~131KB (~1,000 tokens)
473
+ - **CDP screenshots**: ~2.0MB (~15,000 tokens)
474
+ - **Default strategy**: Use html2canvas first, escalate to CDP only when needed
475
+
476
+ This 15x token savings enables 10+ autonomous iterations within Claude's budget.
477
+
478
+ ## Comparison with Alternatives
479
+
480
+ | Feature | Sweetlink | Playwright MCP | Manual Screenshots |
481
+ |---------|-----------|----------------|-------------------|
482
+ | Setup Time | < 1 min | 5-10 min | N/A |
483
+ | Token Cost | ~1,000 | ~5,000 | N/A |
484
+ | Auto Reconnect | ✅ | ❌ | N/A |
485
+ | Console Logs | ✅ | ✅ | ❌ |
486
+ | Network Requests | ✅ (CDP) | ✅ | ❌ |
487
+ | DOM Queries | ✅ | ✅ | ❌ |
488
+ | JS Execution | ✅ | ✅ | ❌ |
489
+ | Click Elements | ✅ | ✅ | ❌ |
490
+ | Element Screenshots | ✅ | ✅ | ❌ |
491
+ | Full Page Screenshots | ✅ | ✅ | ✅ |
492
+ | Autonomous Loops | ✅ (10+) | Limited (2-3) | ❌ |
493
+
494
+ ## When to Use Alternatives
495
+
496
+ ### Sweetlink vs Agent Browser vs Playwright
497
+
498
+ **Use Sweetlink when:**
499
+ - You're debugging/iterating on a running dev server
500
+ - You need lightweight, token-efficient screenshots (~1000 tokens vs ~5000)
501
+ - You want real-time console log capture
502
+ - Your app is already running and you just need to inspect it
503
+ - You're doing autonomous UI development loops (10+ iterations)
504
+
505
+ **Use [Agent Browser](https://github.com/vercel-labs/agent-browser) when:**
506
+ - You need full browser automation (navigation, form filling, multi-page flows)
507
+ - You're testing production sites or external URLs
508
+ - Sweetlink isn't integrated into the target application
509
+ - You need Stagehand's AI-powered element selection
510
+ - You're building autonomous agents that interact with arbitrary websites
511
+
512
+ **Use Playwright MCP when:**
513
+ - You need precise, programmatic browser control
514
+ - You're running E2E tests with assertions
515
+ - You need browser contexts, multiple tabs, or complex scenarios
516
+ - You require network interception or request mocking
517
+
518
+ ### Agent Browser Quick Start
519
+
520
+ Agent Browser is Vercel's Stagehand-based browser automation tool. It's ideal as a Sweetlink backup for scenarios requiring full browser control.
521
+
522
+ ```bash
523
+ # Install globally
524
+ npm install -g @anthropic-ai/agent-browser
525
+
526
+ # Or use npx
527
+ npx @anthropic-ai/agent-browser
528
+ ```
529
+
530
+ **Basic usage with Claude:**
531
+
532
+ ```bash
533
+ # Take screenshot of any URL
534
+ agent-browser screenshot https://example.com
535
+
536
+ # Navigate and interact
537
+ agent-browser navigate https://example.com
538
+ agent-browser click "Sign In"
539
+ agent-browser type "username" --into "Email field"
540
+
541
+ # Extract page content
542
+ agent-browser extract "main article content"
543
+ ```
544
+
545
+ **Key differences from Sweetlink:**
546
+
547
+ | Aspect | Sweetlink | Agent Browser |
548
+ |--------|-----------|---------------|
549
+ | Setup | Requires app integration | Works with any URL |
550
+ | Token cost | ~1,000/screenshot | ~3,000-5,000/screenshot |
551
+ | Best for | Dev iteration loops | Full browser automation |
552
+ | AI element selection | No (CSS selectors) | Yes (Stagehand AI) |
553
+ | Console logs | Real-time capture | Not available |
554
+ | Requires dev server | Yes | No |
555
+
556
+ **Recommended workflow:**
557
+ 1. **During development**: Use Sweetlink for fast, token-efficient iteration
558
+ 2. **For external sites or full automation**: Fall back to Agent Browser
559
+ 3. **For E2E testing with assertions**: Use Playwright directly
560
+
561
+ ## Troubleshooting
562
+
563
+ ### WebSocket Connection Fails
564
+
565
+ ```bash
566
+ # Check if port is in use
567
+ lsof -i :9223
568
+
569
+ # Try different port
570
+ SWEETLINK_WS_PORT=9224 pnpm dev
571
+ ```
572
+
573
+ ### Browser Not Connected
574
+
575
+ 1. Ensure `<SweetlinkBridge />` is rendered in your app
576
+ 2. Check browser console for connection errors
577
+ 3. Verify WebSocket server is running (`[Sweetlink] WebSocket server started...`)
578
+
579
+ ### CDP Not Available
580
+
581
+ 1. Start Chrome with debugging: `/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222`
582
+ 2. Verify CDP endpoint: `curl http://127.0.0.1:9222/json/version`
583
+ 3. Check firewall settings
584
+
585
+ ## Contributing
586
+
587
+ Contributions welcome! Please open an issue or PR at https://github.com/ytspar/devtools
588
+
589
+ ## License
590
+
591
+ MIT
592
+
593
+ ## Credits
594
+
595
+ - Inspired by [Peter Steinberger's autonomous debugging](https://x.com/steipete/status/1981998733736001727)
596
+ - Powered by html2canvas, Puppeteer, and WebSocket