@mmmbuto/nexuscli 0.7.6 → 0.7.7

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 (33) hide show
  1. package/README.md +12 -4
  2. package/bin/nexuscli.js +6 -6
  3. package/frontend/dist/assets/{index-CikJbUR5.js → index-BAY_sRAu.js} +1704 -1704
  4. package/frontend/dist/assets/{index-Bn_l1e6e.css → index-CHOlrfA0.css} +1 -1
  5. package/frontend/dist/index.html +2 -2
  6. package/lib/server/.env.example +1 -1
  7. package/lib/server/db.js.old +225 -0
  8. package/lib/server/docs/API_WRAPPER_CONTRACT.md +682 -0
  9. package/lib/server/docs/ARCHITECTURE.md +441 -0
  10. package/lib/server/docs/DATABASE_SCHEMA.md +783 -0
  11. package/lib/server/docs/DESIGN_PRINCIPLES.md +598 -0
  12. package/lib/server/docs/NEXUSCHAT_ANALYSIS.md +488 -0
  13. package/lib/server/docs/PIPELINE_INTEGRATION.md +636 -0
  14. package/lib/server/docs/README.md +272 -0
  15. package/lib/server/docs/UI_DESIGN.md +916 -0
  16. package/lib/server/lib/pty-adapter.js +15 -1
  17. package/lib/server/routes/chat.js +70 -8
  18. package/lib/server/routes/codex.js +61 -7
  19. package/lib/server/routes/gemini.js +66 -12
  20. package/lib/server/routes/sessions.js +7 -2
  21. package/lib/server/server.js +2 -0
  22. package/lib/server/services/base-cli-wrapper.js +137 -0
  23. package/lib/server/services/claude-wrapper.js +11 -1
  24. package/lib/server/services/cli-loader.js.backup +446 -0
  25. package/lib/server/services/codex-output-parser.js +8 -0
  26. package/lib/server/services/codex-wrapper.js +13 -4
  27. package/lib/server/services/context-bridge.js +24 -20
  28. package/lib/server/services/gemini-wrapper.js +26 -8
  29. package/lib/server/services/session-manager.js +20 -0
  30. package/lib/server/services/workspace-manager.js +1 -1
  31. package/lib/server/tests/performance.test.js +1 -1
  32. package/lib/server/tests/services.test.js +2 -2
  33. package/package.json +1 -1
@@ -0,0 +1,598 @@
1
+ # NexusCLI Design Principles - Three Pillars
2
+
3
+ **Version**: 0.1.0
4
+ **Created**: 2025-11-17
5
+ **Status**: Core Requirements
6
+
7
+ ---
8
+
9
+ ## 🎯 Three Pillars
10
+
11
+ NexusCLI is built on **three fundamental principles**:
12
+
13
+ ```
14
+ ┌─────────────────────────────────────────────────────────┐
15
+ │ │
16
+ │ 1. LIGHTWEIGHT 2. PORTABLE 3. CHATGPT UI │
17
+ │ │
18
+ │ • Minimal deps • Linux native • Chat style │
19
+ │ • Low memory • Termux support • Streaming │
20
+ │ • Fast startup • ARM64/x86_64 • Markdown │
21
+ │ • Single binary • No systemd req • Mobile-first │
22
+ │ │
23
+ └─────────────────────────────────────────────────────────┘
24
+ ```
25
+
26
+ ---
27
+
28
+ ## 🪶 Pillar 1: LIGHTWEIGHT
29
+
30
+ ### Philosophy
31
+ **"Zero bloat. Maximum efficiency."**
32
+
33
+ Every dependency, every line of code must justify its existence.
34
+
35
+ ### Requirements
36
+
37
+ #### Backend
38
+ - **Max dependencies**: 10 npm packages
39
+ - **Memory footprint**: < 50MB idle
40
+ - **Startup time**: < 1 second
41
+ - **Binary size**: < 20MB (if bundled)
42
+
43
+ **Allowed Dependencies**:
44
+ ```json
45
+ {
46
+ "express": "^4.18.2", // HTTP server (minimal)
47
+ "cors": "^2.8.5", // CORS middleware
48
+ "node-pty": "^1.0.0", // PTY spawning (only in wrapper)
49
+ "uuid": "^9.0.0" // Job ID generation
50
+ }
51
+ ```
52
+
53
+ **Forbidden**:
54
+ - ❌ Heavy ORMs (Sequelize, TypeORM)
55
+ - ❌ GraphQL servers
56
+ - ❌ Webpack/complex bundlers (use esbuild if needed)
57
+ - ❌ Lodash (use native JS)
58
+
59
+ #### Frontend
60
+ - **Bundle size**: < 500KB gzipped
61
+ - **Framework**: React (already familiar from NexusChat)
62
+ - **Build tool**: Vite (fast, minimal config)
63
+ - **UI library**: None (custom CSS or Tailwind CDN)
64
+
65
+ **Optimization**:
66
+ ```javascript
67
+ // vite.config.js
68
+ export default defineConfig({
69
+ build: {
70
+ minify: 'esbuild',
71
+ rollupOptions: {
72
+ output: {
73
+ manualChunks: undefined, // Single chunk for small apps
74
+ }
75
+ }
76
+ }
77
+ })
78
+ ```
79
+
80
+ #### Storage
81
+ - **No databases**: SQLite only if absolutely needed
82
+ - **Prefer**: JSON files (like NexusChat session-manager)
83
+ - **Max file size**: 10MB per job result
84
+
85
+ ---
86
+
87
+ ## 📱 Pillar 2: PORTABLE (Linux + Termux)
88
+
89
+ ### Philosophy
90
+ **"Run anywhere. Zero platform lock-in."**
91
+
92
+ Must work on desktop Linux, VPS servers, AND Android Termux.
93
+
94
+ ### Target Platforms
95
+
96
+ | Platform | Arch | Package Manager | Priority |
97
+ |----------|------|-----------------|----------|
98
+ | **Ubuntu/Debian** | x86_64 | apt + npm | High |
99
+ | **Termux (Android)** | aarch64 | pkg + npm | **Critical** |
100
+ | **Alpine Linux** | x86_64 | apk + npm | Medium |
101
+ | **Raspberry Pi** | armv7l | apt + npm | Low |
102
+
103
+ ### Termux Compatibility Requirements
104
+
105
+ #### 1. No systemd
106
+ **Problem**: Termux doesn't have systemd
107
+
108
+ **Solution**: Use process managers or tmux
109
+ ```bash
110
+ # Instead of systemd service
111
+ tmux new-session -d -s nexuscli 'npm run start'
112
+
113
+ # Or use PM2 (if user wants)
114
+ pm2 start backend/server.js --name nexuscli
115
+ ```
116
+
117
+ #### 2. Storage Paths
118
+ **Problem**: Termux uses non-standard paths
119
+
120
+ **Termux Filesystem**:
121
+ ```
122
+ $PREFIX = /data/data/com.termux/files/usr
123
+ $HOME = /data/data/com.termux/files/home
124
+ ```
125
+
126
+ **Configuration**:
127
+ ```javascript
128
+ // config.js
129
+ const isTermux = process.env.PREFIX?.includes('com.termux');
130
+
131
+ const PATHS = isTermux ? {
132
+ storage: `${process.env.HOME}/.nexuscli/jobs`,
133
+ config: `${process.env.HOME}/.nexuscli/config.json`,
134
+ logs: `${process.env.HOME}/.nexuscli/logs`,
135
+ } : {
136
+ storage: '/var/lib/nexuscli/jobs',
137
+ config: '/etc/nexuscli/config.json',
138
+ logs: '/var/log/nexuscli',
139
+ };
140
+ ```
141
+
142
+ #### 3. Port Configuration
143
+ **Problem**: Termux typically uses high ports (> 1024)
144
+
145
+ **Default Ports**:
146
+ - Control Plane: `4000` (configurable via env)
147
+ - Wrapper: `5000` (configurable via env)
148
+
149
+ ```javascript
150
+ const PORT = process.env.NEXUSCLI_PORT || 4000;
151
+ ```
152
+
153
+ #### 4. Network Access
154
+ **Problem**: Termux may be behind NAT/firewall
155
+
156
+ **Solution**: Support reverse tunnels (like SA56Work in CLAUDE.md)
157
+ ```bash
158
+ # Wrapper on Termux device
159
+ ssh -R 4000:localhost:4000 vps3 -N &
160
+
161
+ # Control plane accessible via VPS3
162
+ curl http://vps3:4000/health
163
+ ```
164
+
165
+ ### Installation (One Command)
166
+
167
+ **Linux**:
168
+ ```bash
169
+ curl -fsSL https://cli.wellanet.dev/install.sh | bash
170
+ ```
171
+
172
+ **Termux**:
173
+ ```bash
174
+ pkg install nodejs
175
+ npm install -g nexuscli
176
+ nexuscli start
177
+ ```
178
+
179
+ **From Source** (both):
180
+ ```bash
181
+ git clone https://github.com/dag/nexuscli
182
+ cd nexuscli
183
+ npm install
184
+ npm start
185
+ ```
186
+
187
+ ### Architecture: Minimal Dependencies
188
+
189
+ **Native Tools Only**:
190
+ - ✅ `bash` (always available)
191
+ - ✅ `node` (npm install)
192
+ - ✅ `git` (optional, for updates)
193
+
194
+ **No Custom Binaries**:
195
+ - ❌ No Docker dependency
196
+ - ❌ No database servers
197
+ - ❌ No additional runtimes (Python, Ruby, etc.)
198
+
199
+ ---
200
+
201
+ ## 💬 Pillar 3: CHATGPT-STYLE UI
202
+
203
+ ### Philosophy
204
+ **"Conversation, not configuration."**
205
+
206
+ Users interact via natural chat interface, not complex dashboards.
207
+
208
+ ### UI Paradigm
209
+
210
+ **ChatGPT Model**:
211
+ ```
212
+ ┌──────────────────────────────────────────────┐
213
+ │ NexusCLI [User] ▼ │
214
+ ├──────────────────────────────────────────────┤
215
+ │ │
216
+ │ ┌──────────────────────────────────────┐ │
217
+ │ │ 🤖 System │ │
218
+ │ │ Welcome to NexusCLI. 3 nodes online. │ │
219
+ │ │ Type a command or ask what to do. │ │
220
+ │ └──────────────────────────────────────┘ │
221
+ │ │
222
+ │ ┌──────────────────────────────────────┐ │
223
+ │ │ 👤 You │ │
224
+ │ │ Run 'systemctl status nginx' on all │ │
225
+ │ │ production nodes │ │
226
+ │ └──────────────────────────────────────┘ │
227
+ │ │
228
+ │ ┌──────────────────────────────────────┐ │
229
+ │ │ 🤖 NexusCLI │ │
230
+ │ │ Executing on 3 nodes: │ │
231
+ │ │ │ │
232
+ │ │ [prod-001] ✅ nginx active (running) │ │
233
+ │ │ [prod-002] ✅ nginx active (running) │ │
234
+ │ │ [prod-003] ⚠️ nginx inactive (dead) │ │
235
+ │ │ │ │
236
+ │ │ 2/3 nodes healthy. Check prod-003? │ │
237
+ │ └──────────────────────────────────────┘ │
238
+ │ │
239
+ │ ┌──────────────────────────────────────┐ │
240
+ │ │ Type your command or question... │ │
241
+ │ └──────────────────────────────────────┘ │
242
+ └──────────────────────────────────────────────┘
243
+ ```
244
+
245
+ ### Key Features
246
+
247
+ #### 1. Conversational Interface
248
+
249
+ **Natural Language Input** (future AI enhancement):
250
+ ```
251
+ User: "Check if nginx is running on all nodes"
252
+ System: "Executing: systemctl status nginx"
253
+ ```
254
+
255
+ **For MVP**: Direct command input
256
+ ```
257
+ User: "systemctl status nginx"
258
+ System: "Select nodes: [all] [prod-001, prod-002] [staging-*]"
259
+ ```
260
+
261
+ #### 2. Streaming Responses
262
+
263
+ **Real-time Output** (SSE from wrapper):
264
+ ```
265
+ 🔧 Executing on prod-001...
266
+ ● nginx.service - A high performance web server
267
+ Loaded: loaded (/lib/systemd/system/nginx.service)
268
+ Active: active (running) since...
269
+ ✅ Completed (exit code: 0)
270
+ ```
271
+
272
+ **Progressive Rendering**:
273
+ - Status updates appear as they happen
274
+ - No "loading..." spinners - show actual work
275
+ - Collapsible sections for tool output
276
+
277
+ #### 3. Markdown Support
278
+
279
+ **Code Blocks**:
280
+ ````markdown
281
+ ```bash
282
+ systemctl status nginx
283
+ ```
284
+
285
+ **Output:**
286
+ ```
287
+ ● nginx.service - running
288
+ Active: active (running)
289
+ ```
290
+ ````
291
+
292
+ **Syntax Highlighting**: Prism.js or highlight.js (CDN, no bundle)
293
+
294
+ #### 4. Mobile-First Design
295
+
296
+ **Responsive Layout**:
297
+ ```css
298
+ /* Mobile (Termux on phone) */
299
+ @media (max-width: 768px) {
300
+ .chat-message {
301
+ font-size: 14px;
302
+ padding: 12px;
303
+ }
304
+ .input-box {
305
+ position: fixed;
306
+ bottom: 0;
307
+ width: 100%;
308
+ }
309
+ }
310
+
311
+ /* Desktop */
312
+ @media (min-width: 769px) {
313
+ .chat-container {
314
+ max-width: 800px;
315
+ margin: 0 auto;
316
+ }
317
+ }
318
+ ```
319
+
320
+ **Touch-Friendly**:
321
+ - Large tap targets (44x44px minimum)
322
+ - Swipe gestures for navigation
323
+ - No hover-only interactions
324
+
325
+ ### Component Structure
326
+
327
+ ```jsx
328
+ // App.jsx
329
+ <ChatContainer>
330
+ <Header>
331
+ <Logo />
332
+ <NodeStatus online={3} total={5} />
333
+ </Header>
334
+
335
+ <MessageList>
336
+ {messages.map(msg => (
337
+ <Message
338
+ role={msg.role} // 'user' | 'assistant' | 'system'
339
+ content={msg.content} // Markdown string
340
+ streaming={msg.streaming}
341
+ />
342
+ ))}
343
+ </MessageList>
344
+
345
+ <InputBox
346
+ onSubmit={handleSubmit}
347
+ placeholder="Type command or ask a question..."
348
+ />
349
+ </ChatContainer>
350
+ ```
351
+
352
+ ### Streaming Implementation
353
+
354
+ **Frontend** (same pattern as NexusChat):
355
+ ```javascript
356
+ async function executeCommand(command, nodeIds) {
357
+ // Create job
358
+ const { jobId } = await fetch('/api/v1/jobs', {
359
+ method: 'POST',
360
+ body: JSON.stringify({ command, nodeIds }),
361
+ }).then(r => r.json());
362
+
363
+ // Stream output
364
+ const eventSource = new EventSource(`/api/v1/jobs/${jobId}/stream`);
365
+
366
+ eventSource.onmessage = (event) => {
367
+ const data = JSON.parse(event.data);
368
+
369
+ if (data.type === 'output_chunk') {
370
+ appendToMessage(data.text); // Incremental update
371
+ }
372
+
373
+ if (data.type === 'status') {
374
+ showStatus(data.category, data.message, data.icon);
375
+ }
376
+
377
+ if (data.type === 'done') {
378
+ markComplete();
379
+ eventSource.close();
380
+ }
381
+ };
382
+ }
383
+ ```
384
+
385
+ ---
386
+
387
+ ## 🎨 Visual Design
388
+
389
+ ### Color Scheme (ChatGPT-inspired)
390
+
391
+ ```css
392
+ :root {
393
+ /* Dark mode (default for CLI users) */
394
+ --bg-primary: #1a1a1a;
395
+ --bg-secondary: #2a2a2a;
396
+ --text-primary: #ececec;
397
+ --text-secondary: #9b9b9b;
398
+ --accent: #667eea;
399
+ --success: #4ade80;
400
+ --warning: #fbbf24;
401
+ --error: #ef4444;
402
+
403
+ /* User message */
404
+ --user-bg: #2a2a2a;
405
+
406
+ /* Assistant message */
407
+ --assistant-bg: #1f1f1f;
408
+ }
409
+ ```
410
+
411
+ ### Typography
412
+
413
+ ```css
414
+ body {
415
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI',
416
+ 'Roboto', 'Oxygen', 'Ubuntu', sans-serif;
417
+ font-size: 16px;
418
+ line-height: 1.6;
419
+ }
420
+
421
+ code {
422
+ font-family: 'Fira Code', 'Consolas', monospace;
423
+ font-size: 14px;
424
+ }
425
+ ```
426
+
427
+ ---
428
+
429
+ ## 📦 Deployment Models
430
+
431
+ ### 1. Standalone (Termux on Phone)
432
+
433
+ **Use Case**: Single-user, local commands on phone
434
+
435
+ ```bash
436
+ # On Pixel9Pro (Termux)
437
+ npm install -g nexuscli
438
+ nexuscli start
439
+
440
+ # Access via browser
441
+ am start -a android.intent.action.VIEW -d http://localhost:4000
442
+ ```
443
+
444
+ **Architecture**:
445
+ ```
446
+ Termux (Android)
447
+ ├── nexuscli-backend (port 4000)
448
+ ├── Browser (Chrome/Firefox)
449
+ └── Local CLI tools (bash, git, python)
450
+ ```
451
+
452
+ ### 2. Client-Server (Termux → VPS)
453
+
454
+ **Use Case**: Control remote servers from phone
455
+
456
+ ```bash
457
+ # On Termux (client)
458
+ nexuscli connect https://cli.wellanet.dev
459
+
460
+ # On VPS (server)
461
+ nexuscli server --public
462
+ ```
463
+
464
+ **Architecture**:
465
+ ```
466
+ Termux (Android) → HTTPS → VPS1 (Control Plane)
467
+
468
+ nexus-wrapper (nodes)
469
+ ```
470
+
471
+ ### 3. Distributed (Full Infrastructure)
472
+
473
+ **Use Case**: Production orchestration
474
+
475
+ ```bash
476
+ # VPS1: Control Plane
477
+ nexuscli server --mode control-plane
478
+
479
+ # VPS2, VPS3, etc: Wrappers
480
+ nexuscli server --mode wrapper --register http://vps1:4000
481
+ ```
482
+
483
+ **Architecture**: (same as ARCHITECTURE.md)
484
+
485
+ ---
486
+
487
+ ## 🔒 Security (Lightweight)
488
+
489
+ ### Minimal Auth
490
+
491
+ **API Keys** (no complex JWT):
492
+ ```bash
493
+ # Generate key
494
+ nexuscli generate-key
495
+
496
+ # Use key
497
+ curl -H "X-API-Key: abc123" http://localhost:4000/api/v1/nodes
498
+ ```
499
+
500
+ **Config File**:
501
+ ```json
502
+ {
503
+ "apiKeys": [
504
+ {
505
+ "key": "abc123",
506
+ "name": "my-phone",
507
+ "created": "2025-11-17T10:00:00Z"
508
+ }
509
+ ]
510
+ }
511
+ ```
512
+
513
+ ### No Complex RBAC
514
+
515
+ **Simple Roles**:
516
+ - `admin`: Can execute any command
517
+ - `readonly`: Can only view job results
518
+
519
+ **No Per-Node Permissions** (too complex for lightweight)
520
+
521
+ ---
522
+
523
+ ## 📊 Performance Targets (Revised)
524
+
525
+ | Metric | Target | Priority |
526
+ |--------|--------|----------|
527
+ | Backend startup | < 500ms | Critical |
528
+ | Frontend load | < 2s (3G) | High |
529
+ | Memory (idle) | < 50MB | Critical |
530
+ | Memory (5 jobs) | < 100MB | High |
531
+ | Bundle size | < 500KB gz | Medium |
532
+ | SSE latency | < 50ms | High |
533
+
534
+ ---
535
+
536
+ ## 🚀 Implementation Priorities
537
+
538
+ ### Phase 1: MVP (Lightweight + ChatGPT UI)
539
+
540
+ **Week 1**:
541
+ - ✅ Bootstrap done
542
+ - [ ] Implement chat UI (React + SSE)
543
+ - [ ] Basic job execution (single node)
544
+ - [ ] Markdown rendering
545
+
546
+ **Week 2**:
547
+ - [ ] Multi-node support
548
+ - [ ] Command history
549
+ - [ ] Mobile responsive design
550
+
551
+ ### Phase 2: Portability (Termux Support)
552
+
553
+ **Week 3**:
554
+ - [ ] Termux compatibility testing
555
+ - [ ] Path detection (Linux vs Termux)
556
+ - [ ] Installation script
557
+ - [ ] NPM package publishing
558
+
559
+ ### Phase 3: Polish
560
+
561
+ **Week 4+**:
562
+ - [ ] Syntax highlighting (code blocks)
563
+ - [ ] Dark/light theme toggle
564
+ - [ ] Export conversation/results
565
+ - [ ] Keyboard shortcuts (Ctrl+K, Ctrl+L)
566
+
567
+ ---
568
+
569
+ ## 🎯 Success Criteria
570
+
571
+ **Lightweight**:
572
+ - [x] < 10 npm dependencies (backend)
573
+ - [ ] Starts in < 1 second
574
+ - [ ] Runs on 512MB RAM VPS
575
+
576
+ **Portable**:
577
+ - [ ] Works on Termux (aarch64)
578
+ - [ ] Single `npm install` setup
579
+ - [ ] No systemd requirement
580
+
581
+ **ChatGPT UI**:
582
+ - [ ] Chat-style conversation flow
583
+ - [ ] Real-time streaming output
584
+ - [ ] Markdown + code block rendering
585
+ - [ ] Mobile-responsive (320px+)
586
+
587
+ ---
588
+
589
+ ## 📚 Related Documents
590
+
591
+ - [Architecture Overview](./ARCHITECTURE.md) - System design
592
+ - [API Contract](./API_WRAPPER_CONTRACT.md) - API specification
593
+ - [NexusChat Analysis](./NEXUSCHAT_ANALYSIS.md) - Reference implementation
594
+
595
+ ---
596
+
597
+ _Design principles based on: ChatGPT UX + Termux constraints + Production learnings_
598
+ _Generated by Claude Code (Sonnet 4.5) - 2025-11-17_