@magpiecloud/mags 1.5.0 → 1.6.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.
Files changed (42) hide show
  1. package/API.md +381 -0
  2. package/Mags-API.postman_collection.json +374 -0
  3. package/QUICKSTART.md +283 -0
  4. package/README.md +287 -79
  5. package/bin/mags.js +161 -27
  6. package/deploy-page.sh +171 -0
  7. package/index.js +1 -163
  8. package/mags +0 -0
  9. package/mags.sh +270 -0
  10. package/nodejs/README.md +191 -0
  11. package/nodejs/bin/mags.js +1146 -0
  12. package/nodejs/index.js +326 -0
  13. package/nodejs/package.json +42 -0
  14. package/package.json +4 -15
  15. package/python/INTEGRATION.md +747 -0
  16. package/python/README.md +139 -0
  17. package/python/dist/magpie_mags-1.0.0-py3-none-any.whl +0 -0
  18. package/python/dist/magpie_mags-1.0.0.tar.gz +0 -0
  19. package/python/examples/demo.py +181 -0
  20. package/python/pyproject.toml +39 -0
  21. package/python/src/magpie_mags.egg-info/PKG-INFO +164 -0
  22. package/python/src/magpie_mags.egg-info/SOURCES.txt +9 -0
  23. package/python/src/magpie_mags.egg-info/dependency_links.txt +1 -0
  24. package/python/src/magpie_mags.egg-info/requires.txt +1 -0
  25. package/python/src/magpie_mags.egg-info/top_level.txt +1 -0
  26. package/python/src/mags/__init__.py +6 -0
  27. package/python/src/mags/client.py +283 -0
  28. package/skill.md +153 -0
  29. package/website/api.html +927 -0
  30. package/website/claude-skill.html +483 -0
  31. package/website/cookbook/hn-marketing.html +410 -0
  32. package/website/cookbook/hn-marketing.sh +50 -0
  33. package/website/cookbook.html +278 -0
  34. package/website/env.js +4 -0
  35. package/website/index.html +718 -0
  36. package/website/llms.txt +242 -0
  37. package/website/login.html +88 -0
  38. package/website/mags.md +171 -0
  39. package/website/script.js +425 -0
  40. package/website/styles.css +845 -0
  41. package/website/tokens.html +171 -0
  42. package/website/usage.html +187 -0
package/README.md CHANGED
@@ -1,34 +1,30 @@
1
- # @magpiecloud/mags
1
+ # Mags - Instant VM Execution
2
2
 
3
- Execute scripts instantly on Magpie's microVM infrastructure. VMs boot in <100ms from a warm pool.
3
+ Execute scripts instantly on Magpie's microVM infrastructure. VMs boot in <100ms from a warm pool, giving you instant access to isolated compute environments.
4
4
 
5
- ## Installation
6
-
7
- ```bash
8
- npm install -g @magpiecloud/mags
9
- ```
5
+ ## What is Mags?
10
6
 
11
- ## Quick Start
7
+ Mags is a CLI and SDK for running scripts on ephemeral microVMs. Each execution gets its own isolated VM that:
12
8
 
13
- ### 1. Login to Magpie
9
+ - Boots in <100ms (from warm pool)
10
+ - Has persistent workspaces synced to S3
11
+ - Syncs /root directory automatically every 30 seconds
12
+ - Can expose public URLs for web services
13
+ - Provides SSH access through secure proxy
14
+ - Auto-sleeps when idle and wakes on request
14
15
 
15
- ```bash
16
- mags login
17
- ```
18
-
19
- This will open your browser to create an API token. Paste the token when prompted, and it will be saved for future use.
16
+ ## Installation
20
17
 
21
- ### 2. Create a persistent VM
18
+ ### npm (recommended)
22
19
 
23
20
  ```bash
24
- mags new myproject
25
- mags ssh myproject
21
+ npm install -g @magpiecloud/mags
26
22
  ```
27
23
 
28
- ### 3. Or run a script
24
+ ### Go CLI
29
25
 
30
26
  ```bash
31
- mags run 'echo Hello World'
27
+ go install github.com/magpiecloud/mags/cmd/mags@latest
32
28
  ```
33
29
 
34
30
  ## Authentication
@@ -39,109 +35,210 @@ mags run 'echo Hello World'
39
35
  mags login
40
36
  ```
41
37
 
42
- Opens the Magpie dashboard in your browser where you can create an API token. The token is saved to `~/.mags/config.json` and used automatically for all future commands.
38
+ This opens your browser to the Magpie dashboard where you can create an API token. Paste the token when prompted, and it will be saved to `~/.mags/config.json` for all future commands.
43
39
 
44
- ### Other Auth Commands
40
+ ### Auth Commands
45
41
 
46
42
  ```bash
43
+ mags login # Authenticate with Magpie
47
44
  mags whoami # Check current authentication status
48
45
  mags logout # Remove saved credentials
49
46
  ```
50
47
 
51
- ### Environment Variable
52
-
53
- You can also set the token via environment variable (overrides saved config):
48
+ ### Environment Variable (Alternative)
54
49
 
55
50
  ```bash
56
51
  export MAGS_API_TOKEN="your-token-here"
57
52
  ```
58
53
 
59
- ## CLI Commands
54
+ ## Quick Start
55
+
56
+ ### Run a simple command
57
+
58
+ ```bash
59
+ mags run 'echo Hello World'
60
+ ```
61
+
62
+ ### Create a persistent VM
60
63
 
61
64
  ```bash
62
- # Create a persistent VM
65
+ # Create a new VM with workspace "myproject"
63
66
  mags new myproject
64
67
 
65
68
  # SSH into it
66
69
  mags ssh myproject
67
70
 
68
- # Run a simple command
69
- mags run 'echo Hello'
70
-
71
- # With persistent workspace (S3 sync)
72
- mags run -w my-project 'apk add nodejs && node --version'
73
-
74
- # Persistent VM with public URL
75
- mags run -w webapp -p --url 'python3 -m http.server 8080'
76
-
77
- # With startup command (for auto-wake)
78
- mags run -w webapp -p --url --startup-command 'npm start' 'npm install && npm start'
71
+ # Your /root directory persists to S3 automatically
72
+ ```
79
73
 
80
- # Custom port
81
- mags run -w webapp -p --url --port 3000 'npm start'
74
+ ### Run with a persistent workspace
82
75
 
83
- # Enable URL for existing job
84
- mags url <job-id>
85
- mags url <job-id> 8080
76
+ Workspaces persist data between runs using S3 sync:
86
77
 
87
- # Other commands
88
- mags status <job-id>
89
- mags logs <job-id>
90
- mags list
91
- mags stop <job-id>
78
+ ```bash
79
+ # First run - install dependencies
80
+ mags run -w myproject 'apk add python3 py3-pip && pip install requests'
92
81
 
93
- # Install Claude Code skill
94
- mags setup-claude
82
+ # Second run - dependencies are still there
83
+ mags run -w myproject 'python3 -c "import requests; print(requests.__version__)"'
95
84
  ```
96
85
 
97
- ## Claude Code Integration
98
-
99
- Install the Mags skill for Claude Code to run scripts directly from Claude:
86
+ ### Deploy a web service with public URL
100
87
 
101
88
  ```bash
102
- mags setup-claude
89
+ mags run -p --url 'python3 -m http.server 8080'
90
+ # Returns: https://abc123.apps.magpiecloud.com
103
91
  ```
104
92
 
105
- This lets you use natural language commands like:
106
- - `/mags run echo Hello World`
107
- - `/mags create a python environment with numpy and pandas`
108
- - `/mags run a flask server and give me the public URL`
93
+ ## CLI Reference
109
94
 
110
- See [mags.run/claude-skill.html](https://mags.run/claude-skill.html) for full documentation.
95
+ ### Commands
111
96
 
112
- ## CLI Flags
97
+ | Command | Description |
98
+ |---------|-------------|
99
+ | `mags login` | Authenticate with Magpie (saves token locally) |
100
+ | `mags logout` | Remove saved credentials |
101
+ | `mags whoami` | Show current authentication status |
102
+ | `mags new <workspace>` | Create a persistent VM with workspace |
103
+ | `mags run [options] <script>` | Execute a script on a microVM |
104
+ | `mags ssh <workspace>` | Open interactive SSH session to a VM |
105
+ | `mags status <job-id>` | Get job status |
106
+ | `mags logs <job-id>` | Get job logs |
107
+ | `mags list` | List recent jobs |
108
+ | `mags url <job-id> [port]` | Enable URL access for a job |
109
+ | `mags stop <job-id>` | Stop a running job |
110
+
111
+ ### Run Options
113
112
 
114
113
  | Flag | Description | Default |
115
114
  |------|-------------|---------|
116
- | `-w, --workspace` | Workspace ID for persistent storage | auto |
117
- | `-p, --persistent` | Keep VM alive for URL/SSH access | false |
115
+ | `-w, --workspace <id>` | Use persistent workspace (S3 sync) | auto-generated |
116
+ | `-p, --persistent` | Keep VM alive after script completes | false |
118
117
  | `--url` | Enable public URL access (requires -p) | false |
119
- | `--port` | Port to expose for URL access | 8080 |
120
- | `--startup-command` | Command when VM wakes from sleep | none |
118
+ | `--port <port>` | Port to expose for URL access | 8080 |
119
+ | `--startup-command <cmd>` | Command to run when VM wakes from sleep | none |
121
120
 
122
121
  ## SSH Access
123
122
 
124
- Connect to any running VM:
123
+ Connect to any running VM via SSH:
125
124
 
126
125
  ```bash
127
126
  mags ssh myproject
128
127
  ```
129
128
 
130
- Features:
131
- - Connects via secure proxy (`api.magpiecloud.com:PORT`)
132
- - Full PTY support for interactive terminals
133
- - Automatic SSH key management
134
- - Hostname: `mags-vm`
129
+ ### SSH Features
130
+
131
+ - **Secure proxy**: Connect via `api.magpiecloud.com:PORT` (agent IPs are hidden)
132
+ - **PTY support**: Full interactive terminal with colors and editors
133
+ - **Key-based auth**: Automatic SSH key management
134
+ - **Hostname**: VMs use `mags-vm` as hostname
135
+
136
+ ### SSH Session Example
137
+
138
+ ```bash
139
+ $ mags ssh myproject
140
+ Connecting to api.magpiecloud.com:40006...
141
+ (Use Ctrl+D or 'exit' to disconnect)
142
+
143
+ mags-vm:~# ls
144
+ index.html test.txt
145
+
146
+ mags-vm:~# python3 --version
147
+ Python 3.11.6
148
+
149
+ mags-vm:~# exit
150
+ ```
135
151
 
136
152
  ## Workspaces & Persistence
137
153
 
138
- Your `/root` directory automatically syncs to S3:
139
- - **Auto-sync**: Every 30 seconds while running
140
- - **On stop**: Full sync before VM terminates
141
- - **On wake**: Previous state restored
154
+ ### How It Works
155
+
156
+ When you use a workspace, Mags:
157
+
158
+ 1. Mounts a JuiceFS filesystem backed by S3
159
+ 2. Creates an OverlayFS to capture all filesystem changes
160
+ 3. Syncs your `/root` directory to S3 every 30 seconds
161
+ 4. Restores your files when you reconnect
162
+
163
+ ### What Gets Persisted
164
+
165
+ - `/root` - Your home directory (synced every 30 seconds)
166
+ - `/jfs` - Direct JuiceFS mount (instant S3 sync)
167
+ - Installed packages and dependencies
168
+ - Configuration files and dotfiles
169
+
170
+ ### Sync Behavior
171
+
172
+ | Event | Behavior |
173
+ |-------|----------|
174
+ | While running | Auto-sync every 30 seconds |
175
+ | On stop | Full sync before VM terminates |
176
+ | On wake | Previous state restored instantly |
177
+
178
+ ## Usage Examples
179
+
180
+ ### Basic Execution
181
+
182
+ ```bash
183
+ # Simple command
184
+ mags run 'echo Hello World'
185
+
186
+ # Multi-line script
187
+ mags run 'apk add curl && curl -s https://api.github.com/users/octocat | head -5'
188
+
189
+ # With environment info
190
+ mags run 'uname -a && cat /etc/os-release'
191
+ ```
192
+
193
+ ### Persistent Workspaces
194
+
195
+ ```bash
196
+ # Create a workspace with dependencies
197
+ mags run -w ml-project 'apk add python3 py3-pip && pip install numpy pandas scikit-learn'
198
+
199
+ # Run scripts using the workspace
200
+ mags run -w ml-project 'python3 train.py'
201
+
202
+ # All files in /root are persisted
203
+ mags run -w ml-project 'ls -la /root'
204
+ ```
205
+
206
+ ### Web Services
207
+
208
+ ```bash
209
+ # Simple static server
210
+ mags run -p --url 'python3 -m http.server 8080'
211
+
212
+ # Node.js app
213
+ mags run -w myapp -p --url --port 3000 'npm install && npm start'
214
+
215
+ # Flask app
216
+ mags run -w flask-app -p --url 'pip install flask && python app.py'
217
+
218
+ # Custom startup command for auto-wake
219
+ mags run -w api -p --url --startup-command 'python server.py' 'pip install -r requirements.txt && python server.py'
220
+ ```
221
+
222
+ ### Interactive Development
223
+
224
+ ```bash
225
+ # Create a persistent dev environment
226
+ mags new dev-env
227
+
228
+ # SSH in and work
229
+ mags ssh dev-env
230
+
231
+ # Inside the VM:
232
+ mags-vm:~# apk add git nodejs npm
233
+ mags-vm:~# git clone https://github.com/user/repo
234
+ mags-vm:~# cd repo && npm install
235
+ mags-vm:~# npm run dev
236
+ ```
142
237
 
143
238
  ## Node.js SDK
144
239
 
240
+ For programmatic access, use the SDK:
241
+
145
242
  ```javascript
146
243
  const Mags = require('@magpiecloud/mags');
147
244
 
@@ -156,11 +253,17 @@ console.log(result.logs);
156
253
  // Run with workspace
157
254
  const { requestId } = await mags.run('python script.py', {
158
255
  workspaceId: 'myproject',
159
- persistent: true
256
+ persistent: true,
257
+ startupCommand: 'python server.py'
160
258
  });
161
259
 
162
260
  // Get status
163
261
  const status = await mags.status(requestId);
262
+ console.log(status);
263
+
264
+ // Get logs
265
+ const logs = await mags.logs(requestId);
266
+ logs.logs.forEach(l => console.log(l.message));
164
267
 
165
268
  // Enable URL access
166
269
  await mags.enableUrl(requestId, 8080);
@@ -172,6 +275,74 @@ const jobs = await mags.list({ page: 1, pageSize: 10 });
172
275
  await mags.stop(requestId);
173
276
  ```
174
277
 
278
+ ## API Endpoints
279
+
280
+ For direct API access:
281
+
282
+ | Endpoint | Method | Description |
283
+ |----------|--------|-------------|
284
+ | `/api/v1/mags-jobs` | POST | Submit a new job |
285
+ | `/api/v1/mags-jobs` | GET | List jobs (paginated) |
286
+ | `/api/v1/mags-jobs/{id}/status` | GET | Get job status |
287
+ | `/api/v1/mags-jobs/{id}/logs` | GET | Get job logs |
288
+ | `/api/v1/mags-jobs/{id}/access` | POST | Enable SSH/URL access |
289
+ | `/api/v1/mags-jobs/{id}` | PATCH | Update job settings |
290
+
291
+ ### Example API Request
292
+
293
+ ```bash
294
+ curl -X POST https://api.magpiecloud.com/api/v1/mags-jobs \
295
+ -H "Authorization: Bearer $MAGS_API_TOKEN" \
296
+ -H "Content-Type: application/json" \
297
+ -d '{
298
+ "script": "echo Hello World",
299
+ "type": "inline",
300
+ "workspace_id": "myproject",
301
+ "persistent": true
302
+ }'
303
+ ```
304
+
305
+ ## Job Status Values
306
+
307
+ | Status | Description |
308
+ |--------|-------------|
309
+ | `pending` | Job queued, waiting for VM |
310
+ | `running` | Script executing |
311
+ | `sleeping` | Persistent VM idle (wakes on request) |
312
+ | `completed` | Script finished successfully |
313
+ | `error` | Script failed |
314
+
315
+ ## VM Environment
316
+
317
+ Each VM runs Alpine Linux with hostname `mags-vm` and includes:
318
+
319
+ - `/root` - Persistent home directory (synced to S3)
320
+ - `/jfs` - Direct JuiceFS mount
321
+ - Common tools: curl, wget, git, python3, nodejs
322
+ - Package manager: `apk add <package>`
323
+
324
+ ### Installing Packages
325
+
326
+ ```bash
327
+ # Python packages
328
+ mags run 'apk add python3 py3-pip && pip install requests flask pandas'
329
+
330
+ # Node.js packages
331
+ mags run 'apk add nodejs npm && npm install -g express'
332
+
333
+ # System packages
334
+ mags run 'apk add ffmpeg imagemagick'
335
+ ```
336
+
337
+ ## Performance
338
+
339
+ | Metric | Value |
340
+ |--------|-------|
341
+ | Warm start | <100ms |
342
+ | Cold start | ~4 seconds |
343
+ | Script overhead | ~50ms |
344
+ | Workspace sync | Every 30 seconds |
345
+
175
346
  ## Environment Variables
176
347
 
177
348
  | Variable | Description | Default |
@@ -179,12 +350,49 @@ await mags.stop(requestId);
179
350
  | `MAGS_API_TOKEN` | Your API token (required) | - |
180
351
  | `MAGS_API_URL` | API endpoint | https://api.magpiecloud.com |
181
352
 
182
- ## Performance
353
+ ## Troubleshooting
354
+
355
+ ### "API token required"
356
+
357
+ Set your API token:
358
+ ```bash
359
+ mags login
360
+ # or
361
+ export MAGS_API_TOKEN="your-token-here"
362
+ ```
363
+
364
+ ### "Job timed out"
365
+
366
+ Increase the timeout or check if your script is hanging:
367
+ ```bash
368
+ mags run --timeout 600 'long-running-script.sh'
369
+ ```
370
+
371
+ ### "Workspace not found"
372
+
373
+ Workspace IDs are case-sensitive. Check with:
374
+ ```bash
375
+ mags list
376
+ ```
377
+
378
+ ### URL not accessible
379
+
380
+ Make sure you're using both `-p` (persistent) and `--url` flags, and your app is listening on the correct port:
381
+ ```bash
382
+ mags run -p --url --port 3000 'node server.js'
383
+ ```
384
+
385
+ ### SSH connection issues
386
+
387
+ SSH connects through our proxy. If you have issues:
388
+ 1. Ensure the job is running: `mags status <id>`
389
+ 2. Try reconnecting: `mags ssh <workspace>`
390
+
391
+ ## Support
183
392
 
184
- - **Warm start**: <100ms (VM from pool)
185
- - **Cold start**: ~4 seconds (new VM boot)
186
- - **Script overhead**: ~50ms
187
- - **Workspace sync**: Every 30 seconds
393
+ - Documentation: https://magpiecloud.com/docs/mags
394
+ - Issues: https://github.com/magpiecloud/mags/issues
395
+ - Dashboard: https://magpiecloud.com/mags
188
396
 
189
397
  ## License
190
398