gravity-core 1.0.2 → 1.0.4

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/SETUP.md CHANGED
@@ -1,260 +1,137 @@
1
- # Gravity - Complete Setup Guide
1
+ # Gravity Setup Guide
2
2
 
3
- **Gravity** enables AI assistants (Kiro, Cursor, VSCode, etc.) to diagnose CSS layout issues in real browser tabs.
3
+ Complete step-by-step guide to set up Gravity for your IDE.
4
4
 
5
- ## 🎯 What It Does
5
+ ## Prerequisites
6
6
 
7
- When you ask an AI "why is my modal not showing?", Gravity:
8
- 1. Connects to your browser via extension
9
- 2. Inspects the actual DOM element
10
- 3. Analyzes its position, styles, and visibility
11
- 4. Returns specific issues and fixes
7
+ - Node.js 16+ installed
8
+ - Chrome or Edge browser
9
+ - Administrator access (for Windows registry modification)
12
10
 
13
- ## 📋 Prerequisites
11
+ ## Installation Steps
14
12
 
15
- - **Node.js 16+** - [Download](https://nodejs.org)
16
- - **Chrome or Edge browser** - Already have it? Great!
17
- - **Any IDE** - VSCode, Cursor, Kiro, Warp, or any tool with MCP support
18
-
19
- ## 🚀 Installation (3 Steps)
20
-
21
- ### Step 1: Install npm Package
13
+ ### Step 1: Install the Package
22
14
 
23
15
  ```bash
24
16
  npm install gravity-core
25
17
  ```
26
18
 
27
- ### Step 2: Load Chrome Extension
28
-
29
- 1. Clone or download the extension folder from the repo
30
- 2. Open Chrome → `chrome://extensions`
31
- 3. Enable **"Developer mode"** (top right)
32
- 4. Click **"Load unpacked"**
33
- 5. Select the `extension/` folder
34
- 6. ✅ Extension loaded!
35
-
36
- ### Step 3: Connect Extension to Tab
37
-
38
- 1. Open any website in Chrome/Edge
39
- 2. Click the **Gravity** extension icon (top right)
40
- 3. Click **"Connect to Tab"**
41
- 4. Status turns **🟢 Green** = Connected!
42
-
43
- **The extension now runs a WebSocket server on port 9224** - the MCP server connects to it automatically!
44
-
45
- ---
46
-
47
- ## 💻 Configure Your IDE
19
+ Or globally:
48
20
 
49
- ### VSCode
21
+ ```bash
22
+ npm install -g gravity-core
23
+ ```
50
24
 
51
- 1. Open `.vscode/settings.json` (or create it)
52
- 2. Add MCP server config:
25
+ ### Step 2: Extract Chrome Extension
53
26
 
54
- ```json
55
- {
56
- "mcpServers": {
57
- "gravity": {
58
- "command": "npx",
59
- "args": ["gravity-core"],
60
- "disabled": false
61
- }
62
- }
63
- }
27
+ ```bash
28
+ gravity setup-extension
64
29
  ```
65
30
 
66
- 3. Restart VSCode
67
- 4. Open any HTML/CSS file
68
- 5. Ask the AI: "Diagnose the #modal element"
31
+ This creates `~/.gravity-extension/` with all extension files.
69
32
 
70
- ### Cursor
33
+ **What it does:**
34
+ - Copies extension files from the package
35
+ - Creates the directory in your home folder
36
+ - Prints the path for the next step
71
37
 
72
- Same as VSCode - add to `.cursor/settings.json`:
38
+ ### Step 3: Setup Native Host (Windows Only)
73
39
 
74
- ```json
75
- {
76
- "mcpServers": {
77
- "gravity": {
78
- "command": "npx",
79
- "args": ["gravity-core"],
80
- "disabled": false
81
- }
82
- }
83
- }
40
+ ```bash
41
+ gravity setup-native-host
84
42
  ```
85
43
 
86
- ### Kiro
87
-
88
- Add to `.kiro/settings/mcp.json`:
89
-
90
- ```json
91
- {
92
- "mcpServers": {
93
- "gravity": {
94
- "command": "npx",
95
- "args": ["gravity-core"],
96
- "disabled": false
97
- }
98
- }
99
- }
100
- ```
44
+ This command:
101
45
 
102
- Restart Kiro. Now ask the AI:
103
- - "Check if browser is connected"
104
- - "Diagnose the #modal element"
105
- - "Highlight the .button element"
46
+ 1. **Auto-detects extension ID**
47
+ - Scans Chrome's extension directory
48
+ - Finds the Gravity extension by name
49
+ - No manual ID lookup needed
106
50
 
107
- ### Warp
51
+ 2. **Asks for confirmation**
52
+ ```
53
+ ⚠️ Gravity needs to add a native-messaging registry entry. Proceed? (y/n)
54
+ ```
55
+ - Type `y` to proceed
56
+ - Type `n` to cancel
108
57
 
109
- Add to `.warp/config.json`:
58
+ 3. **Copies native host files**
59
+ - Creates `~/.gravity-host/` directory
60
+ - Copies native messaging host files
110
61
 
111
- ```json
112
- {
113
- "mcpServers": {
114
- "gravity": {
115
- "command": "npx",
116
- "args": ["gravity-core"],
117
- "disabled": false
118
- }
119
- }
120
- }
121
- ```
62
+ 4. **Patches manifest**
63
+ - Inserts your extension ID
64
+ - Updates path to native host executable
122
65
 
123
- ### Any IDE with MCP Support
66
+ 5. **Writes registry key**
67
+ - Adds entry to Windows registry
68
+ - Location: `HKCU\Software\Google\Chrome\NativeMessagingHosts\com.devtools.bridge`
124
69
 
125
- Add this to your IDE's MCP configuration:
70
+ 6. **Optionally restarts Chrome**
71
+ ```
72
+ ⚠️ Chrome is currently running. Restart Chrome for changes to take effect? (y/n)
73
+ ```
74
+ - Type `y` to restart Chrome
75
+ - Type `n` to restart manually later
126
76
 
127
- ```json
128
- {
129
- "mcpServers": {
130
- "gravity": {
131
- "command": "npx",
132
- "args": ["gravity-core"],
133
- "disabled": false
134
- }
135
- }
136
- }
137
- ```
77
+ ### Step 4: Load Extension in Chrome
138
78
 
139
- ---
79
+ 1. Open Chrome and go to `chrome://extensions`
80
+ 2. Enable "Developer mode" (toggle in top right corner)
81
+ 3. Click "Load unpacked"
82
+ 4. Select the `~/.gravity-extension` folder
83
+ 5. The Gravity extension should now appear in your extensions list
140
84
 
141
- ## 🔄 How It Works
85
+ ### Step 5: Test Connection
142
86
 
87
+ ```bash
88
+ gravity test-connection
143
89
  ```
144
- Your IDE (VSCode, Cursor, Kiro, etc.)
145
-
146
- MCP Server (gravity-core)
147
-
148
- WebSocket Connection (port 9224)
149
-
150
- Chrome Extension (running WebSocket server)
151
-
152
- Chrome Debugger API
153
-
154
- Browser Tab (DOM, CSS, Layout data)
155
- ```
156
-
157
- **Flow:**
158
- 1. You ask AI to diagnose an element
159
- 2. IDE sends request to MCP server
160
- 3. MCP server connects to extension via WebSocket on port 9224
161
- 4. Extension uses Chrome Debugger API to query browser
162
- 5. Results flow back to your IDE
163
- 6. AI shows you the issues and fixes
164
90
 
165
- ---
91
+ This verifies everything is working:
166
92
 
167
- ## 📊 Example Output
168
-
169
- ```json
170
- {
171
- "element": "#modal",
172
- "found": true,
173
- "issues": [
174
- {
175
- "type": "offscreen-right",
176
- "severity": "high",
177
- "message": "Element extends 50px beyond right edge of viewport",
178
- "suggestion": "Add max-width: 100% or use overflow: hidden on parent"
179
- }
180
- ],
181
- "position": {
182
- "left": 100,
183
- "top": 50,
184
- "width": 500,
185
- "height": 300
186
- },
187
- "viewport": {
188
- "width": 1920,
189
- "height": 1080
190
- }
191
- }
93
+ ```
94
+ ✅ Registry key exists
95
+ ✅ Manifest file exists
96
+ ✅ Manifest valid
97
+ ✅ Extension ID configured: chrome-extension://xxxxx/
98
+ ✅ Native host executable found
99
+ WebSocket connection successful
100
+
101
+ 🎉 Gravity is ready! All checks passed.
192
102
  ```
193
103
 
194
- ---
195
-
196
- ## 🎯 Common Workflows
197
-
198
- ### Workflow 1: Fix Offscreen Element (VSCode)
199
-
200
- 1. **Browser**: Open page with broken layout
201
- 2. **Extension**: Click icon → "Connect to Tab" (🟢 Green)
202
- 3. **VSCode**: Open CSS file
203
- 4. **VSCode**: Ask AI: "Diagnose the .modal element"
204
- 5. **AI**: Shows "Element extends 50px beyond right edge"
205
- 6. **You**: Add `max-width: 100%` to CSS
206
- 7. **Browser**: Refreshes automatically
207
- 8. **AI**: Diagnose again → ✅ Fixed!
208
-
209
- ### Workflow 2: Debug Hidden Element (Kiro)
210
-
211
- 1. **Browser**: Open page with hidden element
212
- 2. **Extension**: Click icon → "Connect to Tab" (🟢 Green)
213
- 3. **Kiro**: Ask AI: "Why is the #button not showing?"
214
- 4. **AI**: "The element has display: none"
215
- 5. **You**: Change CSS to `display: block`
216
- 6. **AI**: Diagnose again → ✅ Visible!
217
-
218
- ### Workflow 3: Check Multiple Elements (Cursor)
219
-
220
- 1. **Browser**: Open page
221
- 2. **Extension**: Connect to tab
222
- 3. **Cursor**: Ask AI: "Check these elements: #modal, .button, .header"
223
- 4. **AI**: Shows issues for all three
224
- 5. **You**: Fix them one by one
225
-
226
- ---
227
-
228
- ## 🔧 Configuration
104
+ If any checks fail, see the Troubleshooting section below.
229
105
 
230
- ### Custom Port
106
+ ### Step 6: Configure Your IDE
231
107
 
232
- If port 9224 is in use, you can configure a different port:
108
+ #### VSCode
233
109
 
234
- 1. Edit the extension's `background.js`:
235
- ```javascript
236
- const WEBSOCKET_PORT = 9225; // Change from 9224
237
- ```
110
+ 1. Open settings: `Ctrl+Shift+P` → "Preferences: Open User Settings (JSON)"
111
+ 2. Add to your settings:
238
112
 
239
- 2. Update your IDE config with environment variable:
240
113
  ```json
241
114
  {
242
115
  "mcpServers": {
243
116
  "gravity": {
244
117
  "command": "npx",
245
118
  "args": ["gravity-core"],
246
- "env": {
247
- "GRAVITY_PORT": "9225"
248
- },
249
119
  "disabled": false
250
120
  }
251
121
  }
252
122
  }
253
123
  ```
254
124
 
255
- ### Timeout
125
+ 3. Restart VSCode
126
+
127
+ #### Cursor
128
+
129
+ Same as VSCode - add to your MCP settings.
256
130
 
257
- In your IDE config:
131
+ #### Kiro
132
+
133
+ 1. Open Kiro settings
134
+ 2. Add to MCP configuration:
258
135
 
259
136
  ```json
260
137
  {
@@ -262,197 +139,167 @@ In your IDE config:
262
139
  "gravity": {
263
140
  "command": "npx",
264
141
  "args": ["gravity-core"],
265
- "env": {
266
- "GRAVITY_TIMEOUT": "20000"
267
- },
268
142
  "disabled": false
269
143
  }
270
144
  }
271
145
  }
272
146
  ```
273
147
 
274
- ---
275
-
276
- ## 🐛 Troubleshooting
148
+ #### Other IDEs with MCP Support
277
149
 
278
- ### "Not connected to browser"
150
+ Add the same configuration to your IDE's MCP settings file.
279
151
 
280
- **Problem**: Error says "Not connected"
152
+ ### Step 7: Start Using Gravity
281
153
 
282
- **Solution**:
283
- 1. Make sure Chrome/Edge is open
284
- 2. Click extension icon → "Connect to Tab"
285
- 3. Status should turn green
286
- 4. Try again in your IDE
154
+ 1. Open a web page in Chrome
155
+ 2. Click the Gravity extension icon in your toolbar
156
+ 3. Click "Connect to Tab"
157
+ 4. Status should turn green
158
+ 5. In your IDE, ask your AI assistant:
159
+ - "Diagnose the #modal element"
160
+ - "Why is the .button not showing?"
161
+ - "Check if the browser is connected"
287
162
 
288
- ### "Extension not loaded"
163
+ ## File Locations
289
164
 
290
- **Problem**: Extension icon doesn't appear
291
-
292
- **Solution**:
293
- 1. Go to `chrome://extensions`
294
- 2. Enable "Developer mode" (top right)
295
- 3. Click "Load unpacked"
296
- 4. Select the `extension/` folder
297
- 5. Refresh the page
298
-
299
- ### "Port 9224 already in use"
165
+ Gravity stores files in your home directory:
300
166
 
301
- **Problem**: Error "Port 9224 already in use"
167
+ - `~/.gravity-extension/` - Chrome extension files
168
+ - `~/.gravity-host/` - Native messaging host files
169
+ - `~/.gravity-host/manifest.json` - Native host configuration
302
170
 
303
- **Solution**:
304
- 1. Edit extension's `background.js`
305
- 2. Change `WEBSOCKET_PORT` to 9225
306
- 3. Update IDE config with `DEVTOOLS_BRIDGE_PORT: 9225`
307
- 4. Reload extension
171
+ ## Environment Variables
308
172
 
309
- ### "Element not found"
173
+ You can customize Gravity's behavior with environment variables:
310
174
 
311
- **Problem**: Error "Element not found: #modal"
312
-
313
- **Solution**:
314
- 1. Check selector is correct
315
- 2. Make sure element exists in page
316
- 3. Try simpler selector: `div` instead of `#modal`
317
- 4. Check browser console for errors
318
-
319
- ### "Connection timeout"
320
-
321
- **Problem**: Error "Connection timeout"
322
-
323
- **Solution**:
324
- 1. Make sure extension is connected (green status)
325
- 2. Check firewall isn't blocking port 9224
326
- 3. Restart browser
327
- 4. Reload extension
328
-
329
- ---
330
-
331
- ## 📚 API Reference
175
+ ```bash
176
+ # Change WebSocket port (default: 9224)
177
+ GRAVITY_PORT=9225 gravity
332
178
 
333
- ### Gravity
179
+ # Change connection timeout (default: 10000ms)
180
+ GRAVITY_TIMEOUT=20000 gravity
181
+ ```
334
182
 
335
- ```typescript
336
- import { Gravity } from 'gravity-core';
183
+ ## Troubleshooting
337
184
 
338
- const bridge = new Gravity(options);
339
- ```
185
+ ### "Could not find Gravity extension"
340
186
 
341
- #### Options
187
+ **Problem:** `gravity setup-native-host` can't find your extension.
342
188
 
343
- ```typescript
344
- {
345
- port?: number; // Default: 9224
346
- timeout?: number; // Default: 10000 (ms)
347
- autoReconnect?: boolean; // Default: true
348
- }
349
- ```
189
+ **Solutions:**
190
+ 1. Make sure you ran `gravity setup-extension` first
191
+ 2. Load the extension in Chrome (`chrome://extensions` → "Load unpacked")
192
+ 3. Try running `gravity setup-native-host` again
350
193
 
351
- #### Methods
194
+ ### "Failed to write registry key"
352
195
 
353
- ##### `connectBrowser(port?: number): Promise<void>`
196
+ **Problem:** Registry modification failed.
354
197
 
355
- Connect to browser.
198
+ **Solutions:**
199
+ 1. Run Command Prompt as Administrator
200
+ 2. Run `gravity setup-native-host` again
201
+ 3. Check that Chrome is installed in the default location
202
+ 4. Verify you have permission to modify `HKCU\Software\Google\Chrome`
356
203
 
357
- ```javascript
358
- await bridge.connectBrowser();
359
- ```
204
+ ### "Registry key not found" (test-connection)
360
205
 
361
- ##### `disconnectBrowser(): Promise<void>`
206
+ **Problem:** Registry key doesn't exist after setup.
362
207
 
363
- Disconnect from browser.
208
+ **Solutions:**
209
+ 1. Run `gravity setup-native-host` again
210
+ 2. Make sure you confirmed the registry modification
211
+ 3. Check registry manually:
212
+ ```
213
+ reg query "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.devtools.bridge"
214
+ ```
364
215
 
365
- ```javascript
366
- await bridge.disconnectBrowser();
367
- ```
216
+ ### "WebSocket connection failed" (test-connection)
368
217
 
369
- ##### `isConnected(): boolean`
218
+ **Problem:** Can't connect to the MCP server.
370
219
 
371
- Check if connected.
220
+ **Solutions:**
221
+ 1. Start the MCP server: `gravity`
222
+ 2. Check port 9224 is not blocked by firewall
223
+ 3. Try a different port: `GRAVITY_PORT=9225 gravity`
224
+ 4. Check that the extension is loaded and connected
372
225
 
373
- ```javascript
374
- if (bridge.isConnected()) {
375
- console.log('Connected!');
376
- }
377
- ```
226
+ ### "Extension not loaded" in Chrome
378
227
 
379
- ##### `diagnoseLayout(selector: string): Promise<DiagnosticResult>`
228
+ **Problem:** Extension doesn't appear in `chrome://extensions`.
380
229
 
381
- Diagnose layout issues.
230
+ **Solutions:**
231
+ 1. Make sure you ran `gravity setup-extension`
232
+ 2. Go to `chrome://extensions`
233
+ 3. Enable "Developer mode" (toggle in top right)
234
+ 4. Click "Load unpacked"
235
+ 5. Select `~/.gravity-extension` folder
236
+ 6. Refresh the page
382
237
 
383
- ```javascript
384
- const result = await bridge.diagnoseLayout('#modal');
385
- console.log(result.issues);
386
- ```
238
+ ### "Element not found" in diagnostics
387
239
 
388
- #### Events
240
+ **Problem:** Gravity can't find the element you're asking about.
389
241
 
390
- ```javascript
391
- bridge.on('connected', () => {
392
- console.log('Connected to browser!');
393
- });
242
+ **Solutions:**
243
+ 1. Check the CSS selector is correct
244
+ 2. Make sure the element exists on the page
245
+ 3. Try a simpler selector (e.g., `div` instead of `#modal`)
246
+ 4. Make sure the extension is connected (green status)
394
247
 
395
- bridge.on('disconnected', () => {
396
- console.log('Disconnected from browser');
397
- });
248
+ ### Chrome keeps asking to restart
398
249
 
399
- bridge.on('error', (error) => {
400
- console.error('Error:', error);
401
- });
402
- ```
250
+ **Problem:** Chrome needs to restart for changes to take effect.
403
251
 
404
- ---
252
+ **Solutions:**
253
+ 1. Close Chrome completely
254
+ 2. Restart Chrome manually
255
+ 3. Or answer `y` when prompted during setup
405
256
 
406
- ## 🎓 Detected Issues
257
+ ### "Port 9224 already in use"
407
258
 
408
- Gravity detects:
259
+ **Problem:** Another application is using port 9224.
409
260
 
410
- | Issue | Severity | What It Means |
411
- |-------|----------|--------------|
412
- | `offscreen-right` | 🔴 High | Element extends beyond right edge |
413
- | `offscreen-left` | 🔴 High | Element extends beyond left edge |
414
- | `offscreen-top` | 🔴 High | Element extends beyond top edge |
415
- | `offscreen-bottom` | 🟡 Medium | Element extends beyond bottom edge |
416
- | `hidden-display` | 🔴 High | `display: none` |
417
- | `hidden-visibility` | 🔴 High | `visibility: hidden` |
418
- | `hidden-opacity` | 🔴 High | `opacity: 0` |
419
- | `low-opacity` | 🟡 Medium | `opacity < 0.1` |
420
- | `modal-no-zindex` | 🟡 Medium | Positioned element without z-index |
421
- | `modal-low-zindex` | 🟢 Low | `z-index < 100` |
422
- | `overflow-hidden` | 🟢 Low | May clip content |
261
+ **Solutions:**
262
+ 1. Use a different port: `GRAVITY_PORT=9225 gravity`
263
+ 2. Update your IDE config to use the new port
264
+ 3. Or stop the other application using port 9224
423
265
 
424
- ---
266
+ ## Uninstalling
425
267
 
426
- ## 🚀 Next Steps
268
+ To remove Gravity:
427
269
 
428
- 1. **Install package**: `npm install gravity-core`
429
- 2. **Load extension**: `chrome://extensions` → Load unpacked → select `extension/` folder
430
- 3. **Connect browser**: Click extension → "Connect to Tab"
431
- 4. **Configure IDE**: Add MCP server config (see above)
432
- 5. **Start diagnosing**: Ask your AI to diagnose elements!
270
+ 1. Remove the npm package:
271
+ ```bash
272
+ npm uninstall gravity-core
273
+ ```
433
274
 
434
- ---
275
+ 2. Remove the extension from Chrome:
276
+ - Go to `chrome://extensions`
277
+ - Find Gravity and click "Remove"
435
278
 
436
- ## 📞 Support
279
+ 3. Delete the local files (optional):
280
+ ```bash
281
+ rm -r ~/.gravity-extension
282
+ rm -r ~/.gravity-host
283
+ ```
437
284
 
438
- - **GitHub Issues**: [Report bugs](https://github.com/gravity/core/issues)
439
- - **Documentation**: [Full docs](https://gravity.dev)
440
- - **Examples**: Check `examples/` folder in repo
285
+ 4. Remove registry entry (optional, Windows):
286
+ ```
287
+ reg delete "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.devtools.bridge" /f
288
+ ```
441
289
 
442
- ---
290
+ ## Getting Help
443
291
 
444
- ## 🎉 You're Ready!
292
+ - Check the [README](./README.md) for quick start
293
+ - Review [Architecture](./ARCHITECTURE.md) for technical details
294
+ - Open an issue on [GitHub](https://github.com/DharuNamikaze/Gravity-Package/issues)
445
295
 
446
- You now have everything to diagnose layouts in real-time. Start with:
296
+ ## Next Steps
447
297
 
448
- ```bash
449
- npm install gravity-core
450
- ```
298
+ Once Gravity is set up:
451
299
 
452
- Then:
453
- 1. Load extension in Chrome
454
- 2. Connect to tab
455
- 3. Add MCP config to your IDE
456
- 4. Ask your AI to diagnose elements!
300
+ 1. **Configure your IDE** - Add MCP server configuration
301
+ 2. **Load the extension** - Go to `chrome://extensions` and load unpacked
302
+ 3. **Connect to a tab** - Click extension icon and "Connect to Tab"
303
+ 4. **Start diagnosing** - Ask your AI about layout issues
457
304
 
458
- Happy debugging! 🚀
305
+ Happy debugging! 🎉