@elontools/runner 3.1.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.
- package/README.md +444 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1241 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# Runner v3 โ Node.js/TypeScript Core
|
|
2
|
+
|
|
3
|
+
Ejecutor de comandos e agente autรดnomo para Elon Tools. Executa jobs enviados pelo backend e reporta resultados em tempo real.
|
|
4
|
+
|
|
5
|
+
## ๐ Overview
|
|
6
|
+
|
|
7
|
+
- **Language:** TypeScript (Node.js)
|
|
8
|
+
- **Runtime:** Node.js 18+
|
|
9
|
+
- **Modes:** `headless` (CLI), `ui` (screen control)
|
|
10
|
+
- **Platforms:** macOS, Linux, Windows
|
|
11
|
+
|
|
12
|
+
## ๐ Quick Start
|
|
13
|
+
|
|
14
|
+
### Local Development
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# Install dependencies
|
|
18
|
+
npm install
|
|
19
|
+
|
|
20
|
+
# Compile TypeScript
|
|
21
|
+
npm run build
|
|
22
|
+
|
|
23
|
+
# Run locally
|
|
24
|
+
npm start -- --server-url=https://elontools.com --pairing-token=PT_xxx
|
|
25
|
+
|
|
26
|
+
# Or with all flags
|
|
27
|
+
npm start -- \
|
|
28
|
+
--server-url=https://elontools.com \
|
|
29
|
+
--pairing-token=PT_xxx \
|
|
30
|
+
--mode=headless
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### macOS App Bundle
|
|
34
|
+
|
|
35
|
+
O runner v3 รฉ empacotado dentro de `Elon Runner.app` para macOS.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Build for current architecture (arm64 or x86_64)
|
|
39
|
+
bash build-mac.sh
|
|
40
|
+
|
|
41
|
+
# Build specific architecture
|
|
42
|
+
bash build-mac.sh arm64
|
|
43
|
+
bash build-mac.sh x86_64
|
|
44
|
+
|
|
45
|
+
# Build universal binary (both architectures)
|
|
46
|
+
bash build-mac-universal.sh
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Resultado:** Binary instalado em `ElonRunner.app/Contents/MacOS/runner-v3`
|
|
50
|
+
|
|
51
|
+
## ๐ Structure
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
runner-v3/
|
|
55
|
+
โโโ src/
|
|
56
|
+
โ โโโ index.ts # Main entry point
|
|
57
|
+
โโโ dist/ # Compiled JavaScript (generated)
|
|
58
|
+
โโโ build/ # Build artifacts (generated)
|
|
59
|
+
โ โโโ arm64/
|
|
60
|
+
โ โโโ x86_64/
|
|
61
|
+
โ โโโ runner-v3-universal # Universal binary (optional)
|
|
62
|
+
โโโ mac-app/ # macOS Xcode project
|
|
63
|
+
โ โโโ ElonRunnerApp/
|
|
64
|
+
โ โโโ ElonRunnerApp.app/
|
|
65
|
+
โ โโโ Contents/
|
|
66
|
+
โ โ โโโ MacOS/
|
|
67
|
+
โ โ โ โโโ runner-v3 # Executable (copied by build script)
|
|
68
|
+
โ โ โโโ Resources/
|
|
69
|
+
โ โ โโโ runner-v3/ # Source files
|
|
70
|
+
โโโ package.json
|
|
71
|
+
โโโ tsconfig.json
|
|
72
|
+
โโโ build-mac.sh # Build script (single arch)
|
|
73
|
+
โโโ build-mac-universal.sh # Build script (universal)
|
|
74
|
+
โโโ README.md # This file
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## ๐ง Configuration
|
|
78
|
+
|
|
79
|
+
### Command-Line Arguments
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
runner-v3 \
|
|
83
|
+
--server-url=https://elontools.com \
|
|
84
|
+
--pairing-token=PT_xxx \
|
|
85
|
+
--runner-id=abc123 \
|
|
86
|
+
--mode=headless
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Argument | Required | Description |
|
|
90
|
+
|----------|----------|-------------|
|
|
91
|
+
| `--server-url` | Yes | Backend server URL (default: https://elontools.com) |
|
|
92
|
+
| `--pairing-token` | No* | Pairing token (PT_xxx) - required for first registration |
|
|
93
|
+
| `--runner-id` | No | Runner ID (set after registration) |
|
|
94
|
+
| `--mode` | No | `headless` or `ui` (default: headless) |
|
|
95
|
+
| `--config-path` | No | Path to config file (optional) |
|
|
96
|
+
|
|
97
|
+
*Required on first run for registration
|
|
98
|
+
|
|
99
|
+
### Environment
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
# Optional: set NODE_BIN for wrapper scripts
|
|
103
|
+
export NODE_BIN=/usr/local/bin/node
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## ๐ Lifecycle
|
|
107
|
+
|
|
108
|
+
### 1. Registration (First Run)
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
runner-v3 --server-url=... --pairing-token=PT_xxx
|
|
112
|
+
|
|
113
|
+
โ (POST /api/v1/runner-v3/register)
|
|
114
|
+
|
|
115
|
+
โ Response: { runner_id, runner_token }
|
|
116
|
+
|
|
117
|
+
โ (stored in config)
|
|
118
|
+
|
|
119
|
+
โ
Registered
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### 2. Heartbeat Loop
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
Every 30 seconds:
|
|
126
|
+
POST /api/v1/runner-v3/:id/heartbeat
|
|
127
|
+
โ { status: "online", uptime: ... }
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 3. Job Polling
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
Every 5 seconds:
|
|
134
|
+
GET /api/v1/runner-v3/:id/pull
|
|
135
|
+
โ { jobs: [...] }
|
|
136
|
+
|
|
137
|
+
For each job:
|
|
138
|
+
- Execute command
|
|
139
|
+
- Capture stdout/stderr
|
|
140
|
+
- POST /api/v1/runner-v3/:id/report
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 4. Shutdown
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
Ctrl+C or SIGTERM
|
|
147
|
+
|
|
148
|
+
โ Graceful shutdown
|
|
149
|
+
- Stop polling
|
|
150
|
+
- Send final heartbeat
|
|
151
|
+
- Exit with code 0
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## ๐ค API Integration
|
|
155
|
+
|
|
156
|
+
### Registration
|
|
157
|
+
|
|
158
|
+
**POST** `/api/v1/runner-v3/register`
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
curl -X POST https://elontools.com/api/v1/runner-v3/register \
|
|
162
|
+
-H "Authorization: Bearer PT_xxx" \
|
|
163
|
+
-H "Content-Type: application/json" \
|
|
164
|
+
-d '{
|
|
165
|
+
"mode": "headless",
|
|
166
|
+
"platform": "darwin",
|
|
167
|
+
"arch": "arm64"
|
|
168
|
+
}'
|
|
169
|
+
|
|
170
|
+
# Response:
|
|
171
|
+
{
|
|
172
|
+
"runner_id": "run_abc123...",
|
|
173
|
+
"runner_token": "rt3_xyz789..."
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Heartbeat
|
|
178
|
+
|
|
179
|
+
**POST** `/api/v1/runner-v3/:id/heartbeat`
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
curl -X POST https://elontools.com/api/v1/runner-v3/run_abc123/heartbeat \
|
|
183
|
+
-H "Authorization: Bearer rt3_xyz789" \
|
|
184
|
+
-H "Content-Type: application/json" \
|
|
185
|
+
-d '{
|
|
186
|
+
"runner_id": "run_abc123",
|
|
187
|
+
"status": "online",
|
|
188
|
+
"mode": "headless",
|
|
189
|
+
"uptime": 3600
|
|
190
|
+
}'
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Pull Jobs
|
|
194
|
+
|
|
195
|
+
**GET** `/api/v1/runner-v3/:id/pull`
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
curl https://elontools.com/api/v1/runner-v3/run_abc123/pull \
|
|
199
|
+
-H "Authorization: Bearer rt3_xyz789"
|
|
200
|
+
|
|
201
|
+
# Response:
|
|
202
|
+
{
|
|
203
|
+
"jobs": [
|
|
204
|
+
{
|
|
205
|
+
"id": "job_123",
|
|
206
|
+
"command": "ls",
|
|
207
|
+
"args": ["-la", "/tmp"]
|
|
208
|
+
}
|
|
209
|
+
]
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Report Job Result
|
|
214
|
+
|
|
215
|
+
**POST** `/api/v1/runner-v3/:id/report`
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
curl -X POST https://elontools.com/api/v1/runner-v3/run_abc123/report \
|
|
219
|
+
-H "Authorization: Bearer rt3_xyz789" \
|
|
220
|
+
-H "Content-Type: application/json" \
|
|
221
|
+
-d '{
|
|
222
|
+
"job_id": "job_123",
|
|
223
|
+
"status": "completed",
|
|
224
|
+
"output": "total 0\ndrwxr-xr-x ...",
|
|
225
|
+
"error": null
|
|
226
|
+
}'
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## ๐ Logging
|
|
230
|
+
|
|
231
|
+
Logs are printed to stdout/stderr with timestamps:
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
[2026-02-18T10:30:00.000Z] โน๏ธ Runner v3 iniciado
|
|
235
|
+
[2026-02-18T10:30:01.234Z] ๐ Registrando runner com API...
|
|
236
|
+
[2026-02-18T10:30:02.456Z] โ
Runner registrado
|
|
237
|
+
[2026-02-18T10:30:05.789Z] ๐ Heartbeat enviado
|
|
238
|
+
[2026-02-18T10:30:10.234Z] ๐ Executando job
|
|
239
|
+
[2026-02-18T10:30:15.678Z] ๐ค Job result reportado
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Log Prefixes
|
|
243
|
+
|
|
244
|
+
| Prefix | Meaning |
|
|
245
|
+
|--------|---------|
|
|
246
|
+
| โน๏ธ | Info message |
|
|
247
|
+
| โ
| Success |
|
|
248
|
+
| โ ๏ธ | Warning |
|
|
249
|
+
| โ | Error |
|
|
250
|
+
| ๐ | Heartbeat |
|
|
251
|
+
| ๐ | Job execution |
|
|
252
|
+
| ๐ | API call (register) |
|
|
253
|
+
| ๐ค | Report result |
|
|
254
|
+
|
|
255
|
+
## ๐๏ธ macOS Build Process
|
|
256
|
+
|
|
257
|
+
### Step 1: TypeScript Compilation
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
npm run build
|
|
261
|
+
# Creates: dist/index.js + source maps
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Step 2: Create Wrapper
|
|
265
|
+
|
|
266
|
+
Wrapper script that:
|
|
267
|
+
- Finds Node.js binary
|
|
268
|
+
- Executes dist/index.js with all arguments
|
|
269
|
+
- Handles errors gracefully
|
|
270
|
+
|
|
271
|
+
### Step 3: Create Binary
|
|
272
|
+
|
|
273
|
+
Combines wrapper + runner files into single executable:
|
|
274
|
+
- `build/arm64/runner-v3` (arm64 only)
|
|
275
|
+
- `build/x86_64/runner-v3` (x86_64 only)
|
|
276
|
+
- `build/runner-v3-universal` (both, via lipo)
|
|
277
|
+
|
|
278
|
+
### Step 4: Copy to App Bundle
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
ElonRunnerApp.app/
|
|
282
|
+
โโโ Contents/
|
|
283
|
+
โ โโโ MacOS/
|
|
284
|
+
โ โ โโโ runner-v3 โ Binary installed here
|
|
285
|
+
โ โโโ Resources/
|
|
286
|
+
โ โโโ runner-v3/ โ Source files for reference
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
## ๐ Debugging
|
|
290
|
+
|
|
291
|
+
### Run with detailed logging
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Set Node.js debug flag
|
|
295
|
+
DEBUG=* npm start -- --server-url=... --pairing-token=...
|
|
296
|
+
|
|
297
|
+
# Or redirect to file
|
|
298
|
+
npm start -- ... 2>&1 | tee runner.log
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Test binary directly
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
# From macOS app:
|
|
305
|
+
./ElonRunnerApp.app/Contents/MacOS/runner-v3 \
|
|
306
|
+
--server-url=https://elontools.com \
|
|
307
|
+
--pairing-token=PT_test_xxx
|
|
308
|
+
|
|
309
|
+
# Expected output:
|
|
310
|
+
# [timestamp] โน๏ธ Runner v3 iniciado
|
|
311
|
+
# [timestamp] ๐ Registrando runner com API...
|
|
312
|
+
# [timestamp] โ
Runner registrado
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### Monitor heartbeat (macOS log)
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
# From app bundle logs
|
|
319
|
+
tail -f ~/Library/Logs/ElonRunner/stdout.log
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## ๐จ Common Issues
|
|
323
|
+
|
|
324
|
+
### "Node.js not found in PATH"
|
|
325
|
+
|
|
326
|
+
**Solution:** Install Node.js via Homebrew
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
brew install node
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Or set `NODE_BIN` environment variable:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
export NODE_BIN=/usr/local/bin/node
|
|
336
|
+
./runner-v3 --server-url=...
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### "Binary not found in app bundle"
|
|
340
|
+
|
|
341
|
+
**Solution:** Run build script
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
bash build-mac.sh
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### "Permission denied"
|
|
348
|
+
|
|
349
|
+
**Solution:** Make binary executable
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
chmod +x ElonRunnerApp.app/Contents/MacOS/runner-v3
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## ๐ฏ Development Workflow
|
|
356
|
+
|
|
357
|
+
### 1. Make changes to `src/index.ts`
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
# Auto-compile on save
|
|
361
|
+
npm run dev
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### 2. Test locally
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
npm start -- --server-url=... --pairing-token=... --mode=headless
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### 3. Build for macOS app
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
bash build-mac.sh
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### 4. Test in app (Xcode)
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
# Open Xcode project
|
|
380
|
+
open mac-app/ElonRunnerApp/ElonRunnerApp.xcodeproj
|
|
381
|
+
|
|
382
|
+
# Cmd+R to build & run
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## ๐ฆ Distribution
|
|
386
|
+
|
|
387
|
+
### macOS App (.app)
|
|
388
|
+
|
|
389
|
+
```bash
|
|
390
|
+
# Build universal binary
|
|
391
|
+
bash build-mac-universal.sh
|
|
392
|
+
|
|
393
|
+
# Copy app to /Applications
|
|
394
|
+
cp -r ElonRunnerApp.app /Applications/
|
|
395
|
+
|
|
396
|
+
# Run
|
|
397
|
+
/Applications/ElonRunnerApp.app/Contents/MacOS/Elon\ Runner
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Standalone Binary
|
|
401
|
+
|
|
402
|
+
```bash
|
|
403
|
+
# Build universal
|
|
404
|
+
bash build-mac-universal.sh
|
|
405
|
+
|
|
406
|
+
# Copy to PATH
|
|
407
|
+
cp build/runner-v3-universal /usr/local/bin/runner-v3
|
|
408
|
+
chmod +x /usr/local/bin/runner-v3
|
|
409
|
+
|
|
410
|
+
# Run
|
|
411
|
+
runner-v3 --server-url=...
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
## ๐ Security
|
|
415
|
+
|
|
416
|
+
- โ
**Token Hashing:** Pairing tokens are hashed (SHA-256) server-side
|
|
417
|
+
- โ
**Bearer Auth:** Runner tokens are Bearer tokens (not exposed in logs)
|
|
418
|
+
- โ
**HTTPS only:** All API calls use HTTPS
|
|
419
|
+
- โ
**Process Isolation:** Each job runs in isolated process
|
|
420
|
+
- โ
**No Plaintext Storage:** Tokens removed from disk after registration
|
|
421
|
+
|
|
422
|
+
## ๐ References
|
|
423
|
+
|
|
424
|
+
- Backend: `apps/api/src/services/runner-v3.service.ts`
|
|
425
|
+
- API: `apps/api/src/routes/runner-v3.handler.ts`
|
|
426
|
+
- macOS App: `runner-v3/mac-app/ElonRunnerApp/`
|
|
427
|
+
|
|
428
|
+
## ๐ค Contributing
|
|
429
|
+
|
|
430
|
+
1. Make changes to `src/`
|
|
431
|
+
2. Test locally (`npm run dev` + `npm start`)
|
|
432
|
+
3. Build for macOS (`bash build-mac.sh`)
|
|
433
|
+
4. Test in app (Xcode)
|
|
434
|
+
5. Commit & push
|
|
435
|
+
|
|
436
|
+
## ๐ License
|
|
437
|
+
|
|
438
|
+
Copyright ยฉ 2026 ElonTools. All rights reserved.
|
|
439
|
+
|
|
440
|
+
---
|
|
441
|
+
|
|
442
|
+
**Last Updated:** 2026-02-18
|
|
443
|
+
**Version:** 3.0.0
|
|
444
|
+
**Status:** MVP (ready for macOS app integration)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;GAGG"}
|