@fenwave/agent 1.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.
@@ -0,0 +1,11 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(grep:*)",
5
+ "Bash(find:*)",
6
+ "Bash(ls:*)",
7
+ "Bash(cd /Users/seif/Work/Fenwave Platform/fenwave-agent && npm pack:*)",
8
+ "Bash(node -p:*)"
9
+ ]
10
+ }
11
+ }
package/Dockerfile ADDED
@@ -0,0 +1,12 @@
1
+ FROM node:18-alpine
2
+
3
+ WORKDIR /app
4
+
5
+ COPY package.json package-lock.json* ./
6
+ RUN npm ci --only=production
7
+
8
+ COPY . .
9
+
10
+ EXPOSE 3001
11
+
12
+ CMD ["node", "index.js"]
package/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2025 Fenwave (Fenleap). All Rights Reserved.
2
+
3
+ PROPRIETARY SOFTWARE LICENSE
4
+
5
+ This software and associated documentation files (the "Software") are the
6
+ proprietary property of Fenwave (Fenleap) and are protected by copyright law.
7
+
8
+ TERMS AND CONDITIONS:
9
+
10
+ 1. LICENSE GRANT: Fenwave grants authorized customers a limited, non-exclusive,
11
+ non-transferable license to use the Software solely for their internal
12
+ business purposes in connection with Fenwave services.
13
+
14
+ 2. RESTRICTIONS: You may NOT:
15
+ - Copy, modify, or distribute the Software
16
+ - Reverse engineer, decompile, or disassemble the Software
17
+ - Create derivative works based on the Software
18
+ - Sublicense, rent, lease, or lend the Software
19
+ - Use the Software for any purpose other than as authorized by Fenwave
20
+
21
+ 3. OWNERSHIP: Fenwave retains all right, title, and interest in and to the
22
+ Software, including all intellectual property rights.
23
+
24
+ 4. NO WARRANTY: THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.
25
+
26
+ 5. LIMITATION OF LIABILITY: IN NO EVENT SHALL FENWAVE BE LIABLE FOR ANY
27
+ DAMAGES ARISING FROM THE USE OF THIS SOFTWARE.
28
+
29
+ For licensing inquiries, contact: support@fenwave.com
package/README.md ADDED
@@ -0,0 +1,434 @@
1
+ # Fenwave Agent
2
+
3
+ The Fenwave Agent is a command-line tool that runs locally on developer machines to manage Docker containers, registries, and local development environments. It communicates with the Fenwave Backstage platform for authentication and session management.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Architecture](#architecture)
8
+ - [Prerequisites](#prerequisites)
9
+ - [Installation](#installation)
10
+ - [Configuration](#configuration)
11
+ - [Usage](#usage)
12
+ - [Security](#security)
13
+ - [Troubleshooting](#troubleshooting)
14
+ - [Development](#development)
15
+
16
+ ## Architecture
17
+
18
+ The Fenwave Agent consists of three main components:
19
+
20
+ 1. **Agent CLI** - Command-line interface for managing the agent and Docker operations
21
+ 2. **WebSocket Server** - Handles real-time communication with the Fenwave DevApp web application
22
+ 3. **Fenwave DevApp** - Next.js web application that provides a dashboard for managing containers, images, volumes, and more
23
+
24
+ ### Communication Flow
25
+
26
+ ```
27
+ ┌─────────────────────┐
28
+ │ Backstage Backend │
29
+ │ (Authentication) │
30
+ └──────────┬──────────┘
31
+
32
+ │ HTTPS (Session Creation)
33
+
34
+
35
+ ┌──────────────┐ WebSocket (Port 3001) ┌─────────────────┐
36
+ │ Agent CLI │◄────────────────────────────────────►│ Fenwave DevApp │
37
+ │ (Node.js) │ │ (Next.js) │
38
+ └──────┬───────┘ └────────┬────────┘
39
+ │ │
40
+ │ Docker API │ HTTP API
41
+ │ │
42
+ ▼ ▼
43
+ ┌─────────────┐ ┌─────────────────┐
44
+ │ Docker │ │ Browser UI │
45
+ │ Engine │ │ (localhost) │
46
+ └─────────────┘ └─────────────────┘
47
+ ```
48
+
49
+ ### WebSocket Authentication
50
+
51
+ The agent uses token-based authentication for WebSocket connections:
52
+
53
+ 1. **Token Generation**: Agent generates a cryptographically secure 256-bit random token on startup
54
+ 2. **Token Storage**: Token is saved to `~/.fenwave/ws-token` with restricted permissions (0600)
55
+ 3. **Token Sharing**: The token file is mounted as a read-only volume in the Fenwave DevApp Docker container
56
+ 4. **Authentication Flow**:
57
+ - Client connects to WebSocket → Server sends `auth_required` challenge
58
+ - Client reads token from `/api/ws-token` endpoint → Sends `auth` message with token
59
+ - Server validates token → Responds with `auth_success` or `auth_error`
60
+ - Only authenticated clients can send/receive messages
61
+
62
+ ## Prerequisites
63
+
64
+ Before installing the Fenwave Agent, ensure you have:
65
+
66
+ - **Docker Desktop** (version 20.10 or later)
67
+ - Download: https://www.docker.com/products/docker-desktop
68
+ - Verify: `docker --version`
69
+
70
+ - **Node.js** (version 18 or later)
71
+ - Download: https://nodejs.org
72
+ - Verify: `node --version`
73
+
74
+ - **AWS CLI** (for ECR authentication)
75
+ - Download: https://aws.amazon.com/cli/
76
+ - Verify: `aws --version`
77
+ - Configure AWS credentials with ECR access
78
+
79
+ - **Backstage Access**
80
+ - Access to your organization's Fenwave Backstage instance
81
+ - Valid user credentials
82
+
83
+ ## Installation
84
+
85
+ ### Option 1: Via Backstage (Recommended)
86
+
87
+ 1. Log in to your Fenwave Backstage instance
88
+ 2. Navigate to the Agent Installer page
89
+ 3. Click "Generate Installation Token"
90
+ 4. Follow the platform-specific installation instructions
91
+ 5. The installer will:
92
+ - Download the agent binary
93
+ - Configure AWS credentials
94
+ - Authenticate with Backstage
95
+ - Pull the Fenwave DevApp Docker image
96
+ - Start the agent
97
+
98
+ ### Option 2: Manual Installation
99
+
100
+ 1. **Clone the repository**:
101
+ ```bash
102
+ git clone <repository-url>
103
+ cd local-env/agent
104
+ ```
105
+
106
+ 2. **Install dependencies**:
107
+ ```bash
108
+ npm install
109
+ ```
110
+
111
+ 3. **Configure environment**:
112
+ ```bash
113
+ cp .env.example .env
114
+ # Edit .env with your configuration
115
+ ```
116
+
117
+ 4. **Link the CLI globally** (optional):
118
+ ```bash
119
+ npm link
120
+ ```
121
+
122
+ 5. **Configure AWS credentials**:
123
+ ```bash
124
+ aws configure
125
+ # Enter your AWS Access Key ID and Secret Access Key
126
+ ```
127
+
128
+ ## Configuration
129
+
130
+ The agent stores its configuration in `~/.fenwave/config/agent.json`. Configuration is set during the `fenwave init` command and persists across agent restarts and npm package updates.
131
+
132
+ **Configuration file location:** `~/.fenwave/config/agent.json`
133
+
134
+ **Available options:**
135
+
136
+ | Option | Description | Default |
137
+ |--------|-------------|---------|
138
+ | `backendUrl` | Backstage backend URL | `http://localhost:7007` |
139
+ | `frontendUrl` | Backstage frontend URL | `http://localhost:3000` |
140
+ | `appBuilderUrl` | App Builder API URL | Same as `backendUrl` |
141
+ | `containerName` | Docker container name for Fenwave DevApp | `fenwave-devapp` |
142
+ | `containerPort` | Port for Fenwave DevApp HTTP server | `3003` |
143
+ | `wsPort` | Port for WebSocket server | `3001` |
144
+ | `agentRootDir` | Directory for agent data (relative to home) | `.fenwave` |
145
+ | `registriesDir` | Subdirectory for registry data | `registries` |
146
+ | `containerDataDir` | Container data mount path | `/data` |
147
+ | `awsRegion` | AWS region for ECR | `eu-west-1` |
148
+ | `awsAccountId` | AWS account ID for ECR | Set from Backstage |
149
+ | `dockerImage` | Docker image to use | Computed from AWS config |
150
+ | `authTimeoutMs` | Authentication timeout in milliseconds | `60000` |
151
+
152
+ **Configure during initialization:**
153
+ ```bash
154
+ fenwave init \
155
+ --token <registration-token> \
156
+ --backend-url http://localhost:7007 \
157
+ --frontend-url http://localhost:3000 \
158
+ --aws-region eu-west-1
159
+ ```
160
+
161
+ Note: The AWS Account ID is automatically retrieved from Backstage during device registration.
162
+
163
+ **View current configuration:**
164
+ ```bash
165
+ cat ~/.fenwave/config/agent.json
166
+ ```
167
+
168
+ **Environment variable fallback:** If the configuration file doesn't exist, the agent will fall back to environment variables (for backwards compatibility).
169
+
170
+ ### Directory Structure
171
+
172
+ The agent creates the following directory structure in your home directory:
173
+
174
+ ```
175
+ ~/.fenwave/
176
+ ├── config/
177
+ │ └── agent.json # Agent configuration (0600 permissions)
178
+ ├── session/
179
+ │ └── config.json # Backstage session information
180
+ ├── device/
181
+ │ └── credential.json # Device credentials (encrypted)
182
+ ├── setup/
183
+ │ └── state.json # Setup wizard state
184
+ ├── agent/
185
+ │ └── info.json # Agent runtime information
186
+ ├── npm/
187
+ │ └── token # NPM authentication token
188
+ ├── ws-token # WebSocket authentication token (0600 permissions)
189
+ └── registries/ # Docker registry configurations
190
+ ├── dockerhub.json
191
+ ├── ecr.json
192
+ └── ...
193
+ ```
194
+
195
+ ## Usage
196
+
197
+ ### Starting the Agent
198
+
199
+ ```bash
200
+ # Start the agent (authenticates with Backstage)
201
+ fenwave login
202
+
203
+ # The agent will:
204
+ # 1. Open your browser for Backstage authentication
205
+ # 2. Create a session with the Backstage backend
206
+ # 3. Authenticate with AWS ECR
207
+ # 4. Pull the latest Fenwave DevApp Docker image
208
+ # 5. Start the Fenwave DevApp container
209
+ # 6. Start the WebSocket server
210
+
211
+ # After successful startup, you'll see:
212
+ # ✅ Fenwave Agent Started Successfully
213
+ # 🌐 Fenwave DevApp Dashboard: http://localhost:3003
214
+ # 🔌 WebSocket Server: ws://localhost:3001
215
+ # 👤 User: user:default/your-username
216
+ ```
217
+
218
+ ### Accessing the Dashboard
219
+
220
+ Once the agent is running, open your browser to:
221
+
222
+ ```
223
+ http://localhost:3003
224
+ ```
225
+
226
+ The dashboard provides:
227
+ - **Containers**: View, start, stop, restart, and delete containers
228
+ - **Images**: Pull, push, tag, and delete Docker images
229
+ - **Volumes**: Create, backup, restore, and delete volumes
230
+ - **Apps**: Deploy and manage multi-container applications
231
+ - **Registries**: Connect to Docker registries (Docker Hub, ECR, private registries)
232
+ - **Logs**: Stream real-time container logs
233
+ - **Metrics**: View system and container resource usage
234
+ - **Terminal**: Execute commands in running containers
235
+
236
+ ### Agent Commands
237
+
238
+ ```bash
239
+ # Start agent and authenticate
240
+ fenwave login
241
+
242
+ # Logout and clear session
243
+ fenwave logout
244
+
245
+ # Check agent status
246
+ fenwave status
247
+
248
+ # Show agent version
249
+ fenwave --version
250
+
251
+ # Get help
252
+ fenwave --help
253
+ ```
254
+
255
+ ### Docker Operations
256
+
257
+ All Docker operations are performed through the web dashboard at `http://localhost:3003`. The agent provides a WebSocket API for:
258
+
259
+ - Container management (start, stop, restart, delete, create, inspect)
260
+ - Image management (pull, push, tag, delete, inspect)
261
+ - Volume management (create, delete, inspect, backup, restore)
262
+ - Registry management (connect, disconnect, list images)
263
+ - Log streaming (real-time container logs)
264
+ - Metrics collection (system and container stats)
265
+ - Terminal sessions (exec into containers)
266
+
267
+ ## Security
268
+
269
+ ### Authentication & Authorization
270
+
271
+ 1. **Backstage Authentication**: Users must authenticate with Backstage before using the agent
272
+ 2. **Session Management**: Sessions are stored locally with expiration timestamps
273
+ 3. **WebSocket Token**: Cryptographically secure random token for WebSocket authentication
274
+ 4. **File Permissions**: Sensitive files (session.json, ws-token) use restrictive permissions (0600)
275
+
276
+ ### Network Security
277
+
278
+ 1. **Local-Only Communication**: WebSocket server only accepts connections from localhost
279
+ 2. **No External Exposure**: The agent does not expose any ports to the internet
280
+ 3. **TLS for Backstage**: Communication with Backstage backend uses HTTPS
281
+ 4. **ECR Authentication**: AWS credentials required for Docker image pulling
282
+
283
+ ### Best Practices
284
+
285
+ 1. **Never share your session token** - Each user has a unique session
286
+ 2. **Keep Docker updated** - Use the latest Docker Desktop version
287
+ 3. **Rotate AWS credentials regularly** - Follow your organization's security policies
288
+ 4. **Monitor agent logs** - Check for suspicious activity
289
+ 5. **Use strong Backstage passwords** - Enable 2FA if available
290
+
291
+ ## Troubleshooting
292
+
293
+ ### Agent won't start
294
+
295
+ **Problem**: Agent fails to start with authentication errors
296
+
297
+ **Solutions**:
298
+ 1. Check Backstage is running: `curl http://localhost:7007/api/health`
299
+ 2. Clear existing session: `rm ~/.fenwave/session.json`
300
+ 3. Verify internet connectivity
301
+ 4. Check firewall settings
302
+
303
+ ### Docker image pull fails
304
+
305
+ **Problem**: Failed to pull local-env image from ECR
306
+
307
+ **Solutions**:
308
+ 1. Verify AWS credentials: `aws sts get-caller-identity`
309
+ 2. Check ECR access: `aws ecr describe-repositories --region eu-west-1`
310
+ 3. Authenticate manually: `aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin <account>.dkr.ecr.eu-west-1.amazonaws.com`
311
+ 4. Check network/VPN connection
312
+
313
+ ### WebSocket connection fails
314
+
315
+ **Problem**: Fenwave DevApp cannot connect to agent
316
+
317
+ **Solutions**:
318
+ 1. Check agent is running: `docker ps | grep fenwave-devapp`
319
+ 2. Verify WebSocket server is listening: `lsof -i :3001`
320
+ 3. Check token file exists: `ls -la ~/.fenwave/ws-token`
321
+ 4. Restart the agent: `fenwave logout && fenwave login`
322
+ 5. Check browser console for detailed error messages
323
+
324
+ ### Container won't start
325
+
326
+ **Problem**: Fenwave DevApp container fails to start
327
+
328
+ **Solutions**:
329
+ 1. Check Docker is running: `docker info`
330
+ 2. Verify port 3003 is available: `lsof -i :3003`
331
+ 3. Check container logs: `docker logs fenwave-devapp`
332
+ 4. Remove existing container: `docker rm -f fenwave-devapp`
333
+ 5. Pull latest image: `docker pull <ecr-image>`
334
+
335
+ ### Session expired
336
+
337
+ **Problem**: Agent reports session expired
338
+
339
+ **Solutions**:
340
+ 1. Logout and login again: `fenwave logout && fenwave login`
341
+ 2. Check Backstage backend is accessible
342
+ 3. Verify system clock is synchronized
343
+
344
+ ## Development
345
+
346
+ ### Running in Development Mode
347
+
348
+ ```bash
349
+ # Install dependencies
350
+ npm install
351
+
352
+ # Set up environment
353
+ cp .env.example .env
354
+
355
+ # Run the agent locally (without Docker)
356
+ node index.js login
357
+
358
+ # For Fenwave DevApp development (build from source)
359
+ # Set DOCKER_IMAGE=fenwave-devapp in .env
360
+ # Build image: docker build -t fenwave-devapp ..
361
+ ```
362
+
363
+ ### Building the Docker Image
364
+
365
+ ```bash
366
+ # Build production image
367
+ cd ../ # Go to local-env root
368
+ docker build -f Dockerfile.prod -t fenwave-devapp:latest .
369
+
370
+ # Test the image
371
+ docker run -d \
372
+ --name fenwave-devapp-test \
373
+ -p 3003:3003 \
374
+ -v ~/.fenwave:/app/.fenwave:ro \
375
+ -e NEXT_PUBLIC_WS_URL=ws://host.docker.internal:3001 \
376
+ fenwave-devapp:latest
377
+
378
+ # Check logs
379
+ docker logs -f fenwave-devapp-test
380
+ ```
381
+
382
+ ### Publishing to ECR
383
+
384
+ ```bash
385
+ # Run the publish script
386
+ cd ../ # Go to local-env root
387
+ ./scripts/publish-image.sh v1.0.0
388
+
389
+ # The script will:
390
+ # 1. Authenticate with AWS ECR
391
+ # 2. Build the Docker image
392
+ # 3. Tag with version and 'latest'
393
+ # 4. Push to ECR
394
+ ```
395
+
396
+ ### Project Structure
397
+
398
+ ```
399
+ agent/
400
+ ├── index.js # Main entry point
401
+ ├── auth.js # Authentication & session management
402
+ ├── containerManager.js # Docker container operations
403
+ ├── websocket-server.js # WebSocket server setup
404
+ ├── cli-commands.js # CLI command definitions
405
+ ├── docker-actions/ # WebSocket action handlers
406
+ │ ├── containers.js # Container operations
407
+ │ ├── images.js # Image operations
408
+ │ ├── volumes.js # Volume operations
409
+ │ ├── apps.js # Application management
410
+ │ ├── registry.js # Registry operations
411
+ │ ├── logs.js # Log streaming
412
+ │ ├── metrics.js # Metrics collection
413
+ │ ├── terminal.js # Terminal sessions
414
+ │ └── general.js # General utilities
415
+ ├── store/ # Persistent storage
416
+ │ ├── agentStore.js # Agent info storage
417
+ │ └── registryStore.js # Registry configurations
418
+ ├── package.json # Dependencies
419
+ ├── .env.example # Environment template
420
+ └── README.md # This file
421
+ ```
422
+
423
+ ## Support
424
+
425
+ For issues, questions, or feature requests:
426
+
427
+ 1. Check the [Troubleshooting](#troubleshooting) section
428
+ 2. Review the [Fenwave documentation](https://docs.fenwave.com)
429
+ 3. Contact your Fenwave administrator
430
+ 4. File an issue in the repository (if applicable)
431
+
432
+ ## License
433
+
434
+ Copyright © 2025 Fenwave. All rights reserved.