@ytspar/sweetlink 1.15.0 → 1.16.1
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/claude-agents/sweetlink-visual-iterative.md +453 -0
- package/claude-context/sweetlink-architecture.md +352 -0
- package/claude-context/sweetlink-cdp-guide.md +385 -0
- package/claude-context/ui-verification-mandate.md +65 -0
- package/claude-skills/console-check-sweetlink/SKILL.md +330 -0
- package/claude-skills/console-check-sweetlink/evals/evals.json +35 -0
- package/claude-skills/console-check-sweetlink/examples.md +394 -0
- package/claude-skills/resize-for-claude/SKILL.md +97 -0
- package/claude-skills/resize-for-claude/evals/evals.json +23 -0
- package/claude-skills/responsive-screenshots/SKILL.md +366 -0
- package/claude-skills/responsive-screenshots/evals/evals.json +23 -0
- package/claude-skills/responsive-screenshots/examples.md +441 -0
- package/claude-skills/screenshot/evals/evals.json +35 -0
- package/dist/cli/sweetlink-dev.js +0 -0
- package/dist/cli/sweetlink.js +0 -0
- package/dist/daemon/index.js +0 -0
- package/package.json +49 -28
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
# Sweetlink Architecture - Autonomous Development Bridge
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Sweetlink is a websocket-based bridge that enables LLM agents (like Claude) to autonomously interact with a running web application for debugging, development, and visual verification.
|
|
6
|
+
|
|
7
|
+
**Key Innovation**: Instead of relying on MCP screenshot tools (which are token-heavy and often don't fit in context), sweetlink provides a lightweight CLI that connects directly to the running webapp via websockets.
|
|
8
|
+
|
|
9
|
+
**Inspired by**: [Peter Steinberger's sweetlink implementation](https://x.com/steipete/status/1981998733736001727) which enables agents to "debug everything completely autonomous e2e."
|
|
10
|
+
|
|
11
|
+
## Core Architecture
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
┌─────────────────┐ WebSocket ┌──────────────────┐
|
|
15
|
+
│ CLI Tool │◄──────────────────────────►│ Webapp (Remix) │
|
|
16
|
+
│ (sweetlink) │ ws://localhost:9223 │ Dev Server │
|
|
17
|
+
└─────────────────┘ └──────────────────┘
|
|
18
|
+
│ │
|
|
19
|
+
│ │
|
|
20
|
+
│ CDP Connection │ Client Bridge
|
|
21
|
+
│ http://127.0.0.1:9222 │
|
|
22
|
+
│ │
|
|
23
|
+
▼ ▼
|
|
24
|
+
┌─────────────────┐ ┌──────────────────┐
|
|
25
|
+
│ Chrome DevTools │ │ Browser Client │
|
|
26
|
+
│ Protocol │ │ (html2canvas) │
|
|
27
|
+
└─────────────────┘ └──────────────────┘
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Components
|
|
31
|
+
|
|
32
|
+
### 1. WebSocket Server (Remix Dev Server)
|
|
33
|
+
|
|
34
|
+
**Location**: Embedded in Remix development server
|
|
35
|
+
**Port**: 9223 (configurable)
|
|
36
|
+
**Purpose**: Accept commands from CLI and route to browser client
|
|
37
|
+
|
|
38
|
+
**Commands**:
|
|
39
|
+
|
|
40
|
+
- `screenshot` - Capture screenshot of current page or specific element
|
|
41
|
+
- `query-dom` - Query DOM elements and return data
|
|
42
|
+
- `get-logs` - Retrieve console logs from browser
|
|
43
|
+
- `exec-js` - Execute arbitrary JavaScript in browser context
|
|
44
|
+
- `get-network` - Get network request data
|
|
45
|
+
|
|
46
|
+
**Response Format**:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface CommandResponse {
|
|
50
|
+
success: boolean;
|
|
51
|
+
data?: any;
|
|
52
|
+
error?: string;
|
|
53
|
+
timestamp: number;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. CLI Tool (`tools/sweetlink.ts`)
|
|
58
|
+
|
|
59
|
+
**Purpose**: Command-line interface for sending commands to webapp
|
|
60
|
+
**Auto-Detection**: Checks for Chrome DevTools Protocol at http://127.0.0.1:9222
|
|
61
|
+
|
|
62
|
+
**Command Priority**:
|
|
63
|
+
|
|
64
|
+
1. **CDP Available**: Use Puppeteer to connect directly to Chrome via CDP
|
|
65
|
+
2. **CDP Unavailable**: Fall back to websocket command to browser client
|
|
66
|
+
|
|
67
|
+
**Commands**:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Screenshot entire page
|
|
71
|
+
pnpm sweetlink screenshot --no-wait
|
|
72
|
+
|
|
73
|
+
# Screenshot specific element
|
|
74
|
+
pnpm sweetlink screenshot --no-wait --selector ".company-card"
|
|
75
|
+
|
|
76
|
+
# Query DOM
|
|
77
|
+
pnpm sweetlink query --selector "h1" --property "innerText"
|
|
78
|
+
|
|
79
|
+
# Get console logs
|
|
80
|
+
pnpm sweetlink logs
|
|
81
|
+
|
|
82
|
+
# Execute JavaScript
|
|
83
|
+
pnpm sweetlink exec --code "document.title"
|
|
84
|
+
|
|
85
|
+
# Get network requests
|
|
86
|
+
pnpm sweetlink network --filter "api"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**CDP Detection Logic**:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
async function detectCDP(): Promise<boolean> {
|
|
93
|
+
try {
|
|
94
|
+
const response = await fetch('http://127.0.0.1:9222/json/version');
|
|
95
|
+
return response.ok;
|
|
96
|
+
} catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 3. Browser Client Bridge (DevToolbar Extension)
|
|
103
|
+
|
|
104
|
+
**Location**: `app/components/dev/SweetlinkBridge.tsx`
|
|
105
|
+
**Purpose**: Receive websocket commands and execute in browser
|
|
106
|
+
|
|
107
|
+
**Capabilities**:
|
|
108
|
+
|
|
109
|
+
- Take screenshots using html2canvas
|
|
110
|
+
- Query DOM elements
|
|
111
|
+
- Capture console logs
|
|
112
|
+
- Execute JavaScript
|
|
113
|
+
- Return network request data
|
|
114
|
+
|
|
115
|
+
**Implementation**:
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// Connect to websocket server
|
|
119
|
+
const ws = new WebSocket('ws://localhost:9223');
|
|
120
|
+
|
|
121
|
+
ws.onmessage = async (event) => {
|
|
122
|
+
const command = JSON.parse(event.data);
|
|
123
|
+
|
|
124
|
+
switch (command.type) {
|
|
125
|
+
case 'screenshot':
|
|
126
|
+
const screenshot = await html2canvas(document.body);
|
|
127
|
+
ws.send(JSON.stringify({
|
|
128
|
+
success: true,
|
|
129
|
+
data: screenshot.toDataURL()
|
|
130
|
+
}));
|
|
131
|
+
break;
|
|
132
|
+
// ... other commands
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 4. CDP Integration (`tools/sweetlink-cdp.ts`)
|
|
138
|
+
|
|
139
|
+
**Purpose**: Use Chrome DevTools Protocol for more reliable screenshots and debugging
|
|
140
|
+
|
|
141
|
+
**When to Use**:
|
|
142
|
+
|
|
143
|
+
- Chrome launched with `--remote-debugging-port=9222`
|
|
144
|
+
- More reliable than html2canvas
|
|
145
|
+
- Can capture full page, specific viewports
|
|
146
|
+
- Access to network tab, console, performance data
|
|
147
|
+
|
|
148
|
+
**Starting Chrome with CDP**:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# macOS
|
|
152
|
+
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
|
|
153
|
+
--remote-debugging-port=9222 \
|
|
154
|
+
--user-data-dir=/tmp/chrome-debug
|
|
155
|
+
|
|
156
|
+
# Linux
|
|
157
|
+
google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Puppeteer Usage**:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import puppeteer from 'puppeteer-core';
|
|
164
|
+
|
|
165
|
+
const browser = await puppeteer.connect({
|
|
166
|
+
browserURL: 'http://127.0.0.1:9222'
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const pages = await browser.pages();
|
|
170
|
+
const page = pages.find(p => p.url().includes('localhost:3000'));
|
|
171
|
+
|
|
172
|
+
// Take screenshot
|
|
173
|
+
const screenshot = await page.screenshot({
|
|
174
|
+
fullPage: true,
|
|
175
|
+
type: 'png'
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Advantages Over MCP Screenshot Tools
|
|
180
|
+
|
|
181
|
+
### 1. Token Efficiency
|
|
182
|
+
|
|
183
|
+
- **MCP Tools**: Large accessibility tree snapshots, verbose element descriptions
|
|
184
|
+
- **Sweetlink**: Compact JSON responses, base64 images, structured data
|
|
185
|
+
|
|
186
|
+
### 2. Autonomous Looping
|
|
187
|
+
|
|
188
|
+
- Agent can repeatedly take screenshots and adjust code until design is correct
|
|
189
|
+
- No manual intervention required
|
|
190
|
+
- Faster iteration cycles
|
|
191
|
+
|
|
192
|
+
### 3. Rich Data Access
|
|
193
|
+
|
|
194
|
+
- Console logs with stack traces
|
|
195
|
+
- Network request/response data
|
|
196
|
+
- DOM query results
|
|
197
|
+
- Performance metrics (via CDP)
|
|
198
|
+
|
|
199
|
+
### 4. No External Dependencies
|
|
200
|
+
|
|
201
|
+
- No separate MCP server process
|
|
202
|
+
- Embedded in development workflow
|
|
203
|
+
- Works with existing dev server
|
|
204
|
+
|
|
205
|
+
## Implementation Plan
|
|
206
|
+
|
|
207
|
+
### Phase 1: WebSocket Server
|
|
208
|
+
|
|
209
|
+
1. Add websocket upgrade handler to Remix dev server
|
|
210
|
+
2. Implement command routing
|
|
211
|
+
3. Add basic health check endpoint
|
|
212
|
+
|
|
213
|
+
### Phase 2: CLI Tool
|
|
214
|
+
|
|
215
|
+
1. Create `tools/sweetlink.ts` with command structure
|
|
216
|
+
2. Implement CDP auto-detection
|
|
217
|
+
3. Add screenshot command with CDP fallback
|
|
218
|
+
4. Add DOM query and logs commands
|
|
219
|
+
|
|
220
|
+
### Phase 3: Browser Bridge
|
|
221
|
+
|
|
222
|
+
1. Create `SweetlinkBridge.tsx` component
|
|
223
|
+
2. Add to DevToolbar
|
|
224
|
+
3. Implement screenshot capture (html2canvas)
|
|
225
|
+
4. Implement console log collection
|
|
226
|
+
5. Implement DOM querying
|
|
227
|
+
|
|
228
|
+
### Phase 4: CDP Integration
|
|
229
|
+
|
|
230
|
+
1. Create `tools/sweetlink-cdp.ts` helper
|
|
231
|
+
2. Implement Puppeteer connection
|
|
232
|
+
3. Add full-page screenshot capability
|
|
233
|
+
4. Add network request inspection
|
|
234
|
+
|
|
235
|
+
### Phase 5: Documentation & Testing
|
|
236
|
+
|
|
237
|
+
1. Create usage guide
|
|
238
|
+
2. Add examples for common scenarios
|
|
239
|
+
3. Test with visual development agent
|
|
240
|
+
4. Document Chrome CDP setup
|
|
241
|
+
|
|
242
|
+
## Usage Examples
|
|
243
|
+
|
|
244
|
+
### Example 1: Autonomous Card Layout Debugging
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
# Claude agent workflow:
|
|
248
|
+
# 1. Make changes to card component
|
|
249
|
+
# 2. Take screenshot to verify
|
|
250
|
+
pnpm sweetlink screenshot --no-wait --output ".tmp/screenshots/card-layout.png"
|
|
251
|
+
|
|
252
|
+
# 3. Check console for errors
|
|
253
|
+
pnpm sweetlink logs --filter "error"
|
|
254
|
+
|
|
255
|
+
# 4. If issues, query DOM to inspect card structure
|
|
256
|
+
pnpm sweetlink query --selector ".card" --count
|
|
257
|
+
|
|
258
|
+
# 5. Repeat until layout is correct
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Example 2: Network Request Debugging
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
# Check API responses
|
|
265
|
+
pnpm sweetlink network --filter "/api/companies"
|
|
266
|
+
|
|
267
|
+
# Get specific request details
|
|
268
|
+
pnpm sweetlink network --url "/api/companies/123" --details
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Example 3: Performance Analysis
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
# Get console performance metrics
|
|
275
|
+
pnpm sweetlink logs --filter "performance"
|
|
276
|
+
|
|
277
|
+
# Take screenshot with timing overlay
|
|
278
|
+
pnpm sweetlink screenshot --no-wait --performance-overlay
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Dependencies
|
|
282
|
+
|
|
283
|
+
### Required npm packages
|
|
284
|
+
|
|
285
|
+
```json
|
|
286
|
+
{
|
|
287
|
+
"ws": "^8.18.0", // WebSocket server
|
|
288
|
+
"html2canvas": "^1.4.1", // Browser screenshots
|
|
289
|
+
"puppeteer-core": "^23.10.4", // CDP integration
|
|
290
|
+
"@types/ws": "^8.5.13" // TypeScript types
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Optional (for enhanced features)
|
|
295
|
+
|
|
296
|
+
```json
|
|
297
|
+
{
|
|
298
|
+
"sharp": "^0.33.5", // Image optimization
|
|
299
|
+
"pixelmatch": "^6.0.0" // Screenshot diffing
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## Configuration
|
|
304
|
+
|
|
305
|
+
### `.env` additions
|
|
306
|
+
|
|
307
|
+
```bash
|
|
308
|
+
# Sweetlink WebSocket port
|
|
309
|
+
SWEETLINK_WS_PORT=9223
|
|
310
|
+
|
|
311
|
+
# Chrome DevTools Protocol port
|
|
312
|
+
CHROME_CDP_PORT=9222
|
|
313
|
+
|
|
314
|
+
# Enable/disable sweetlink in development
|
|
315
|
+
ENABLE_SWEETLINK=true
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Remix server integration
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
// server.ts or vite.config.ts
|
|
322
|
+
if (process.env.NODE_ENV === 'development' && process.env.ENABLE_SWEETLINK === 'true') {
|
|
323
|
+
const { initSweetlink } = await import('./tools/sweetlink-server');
|
|
324
|
+
await initSweetlink({ port: process.env.SWEETLINK_WS_PORT || 9223 });
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Security Considerations
|
|
329
|
+
|
|
330
|
+
1. **Development Only**: Never enable in production
|
|
331
|
+
2. **Localhost Binding**: WebSocket server only binds to 127.0.0.1
|
|
332
|
+
3. **No Authentication**: Assumes trusted local environment
|
|
333
|
+
4. **Command Validation**: Sanitize and validate all commands
|
|
334
|
+
5. **Execution Limits**: Rate limiting on expensive operations
|
|
335
|
+
|
|
336
|
+
## Future Enhancements
|
|
337
|
+
|
|
338
|
+
1. **Screenshot Diffing**: Compare before/after changes automatically
|
|
339
|
+
2. **Video Recording**: Record interaction sessions
|
|
340
|
+
3. **Performance Profiling**: CPU, memory, network waterfalls
|
|
341
|
+
4. **Accessibility Audits**: Automated a11y checks
|
|
342
|
+
5. **Visual Regression**: Automated visual regression testing
|
|
343
|
+
6. **Multi-Tab Support**: Work with multiple browser tabs
|
|
344
|
+
7. **Remote Development**: Secure tunnel for remote debugging
|
|
345
|
+
|
|
346
|
+
## References
|
|
347
|
+
|
|
348
|
+
- Peter Steinberger's tweets: [Thread about sweetlink implementation]
|
|
349
|
+
- Chrome DevTools Protocol: https://chromedevtools.github.io/devtools-protocol/
|
|
350
|
+
- Puppeteer: https://pptr.dev/
|
|
351
|
+
- html2canvas: https://html2canvas.hertzen.com/
|
|
352
|
+
- WebSocket API: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|