thinknagent 0.1.20 → 0.1.22

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 CHANGED
@@ -1,344 +1,152 @@
1
- # thinknagent
1
+ # 🚀 thinknagent
2
2
 
3
- Official server agent for [ThinkNCollab](https://thinkncollab.com) — monitor your servers, stream logs, and access remote terminals directly from your DevOps Wall.
3
+ [![npm version](https://img.shields.io/npm/v/thinknagent.svg?style=flat-square&color=00ff88)](https://www.npmjs.com/package/thinknagent)
4
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
5
+ [![node](https://img.shields.io/badge/node-%3E%3D18.0.0-green.svg?style=flat-square)](https://nodejs.org)
6
+ [![e2ee](https://img.shields.io/badge/security-AES--256--GCM%20E2EE-brightgreen.svg?style=flat-square)](https://thinkncollab.com)
4
7
 
5
- ---
8
+ Official high-performance server agent for **[ThinkNCollab DevOps Wall](https://thinkncollab.com)** — real-time hardware metrics, event-driven log streaming, interactive Web PTY shell, APM traces, and automatic alert monitoring with **100% Client-Side AES-256-GCM End-to-End Encryption (E2EE)**.
6
9
 
7
- ## Installation
10
+ ---
8
11
 
9
- ```bash
10
- npm install -g thinknagent
11
- ```
12
+ ## ⚡ Quick Start (Zero Install / NPX)
12
13
 
13
- > **Linux/macOS only.** Requires Node.js v18+.
14
+ Connect any server in seconds with **NPX**:
14
15
 
15
- **If build error on Linux:**
16
16
  ```bash
17
- sudo apt-get install -y build-essential python3
18
- npm install -g thinknagent
19
- ```
17
+ # 1. Initialize & register with your room
18
+ npx thinknagent init --room <roomId> --role shell
20
19
 
21
- **If permission denied:**
22
- ```bash
23
- chmod +x (which thinknagent)
20
+ # 2. Start the self-healing background daemon
21
+ npx thinknagent daemon start
24
22
  ```
25
23
 
26
24
  ---
27
25
 
28
- ## Commands
29
-
30
- | Command | Description |
31
- |---------|-------------|
32
- | `thinknagent init` | Register this server with ThinkNCollab |
33
- | `thinknagent start` | Connect and start monitoring |
34
- | `thinknagent status` | Show current config and status |
35
- | `thinknagent revoke` | Clear all credentials and re-register |
36
-
37
- ---
26
+ ## 📦 Global Installation
38
27
 
39
- ## Init Options
40
-
41
- | Option | Required | Description |
42
- |--------|----------|-------------|
43
- | `--server <url>` | ✅ | ThinkNCollab server URL |
44
- | `--name <name>` | ✅ | Display name on DevOps Wall |
45
- | `--room <roomId>` | ✅ | Room ID to connect to |
46
- | `--gpu` | ❌ | Enable GPU metrics (requires nvidia-smi) |
47
- | `--logs <paths>` | ❌ | Comma-separated log file paths to stream |
48
- | `--app-path <path>` | ❌ | Path to the deployed application folder (to track and display version) |
49
-
50
- ---
51
-
52
- ## Quick Start
53
-
54
- ### Step 1 — Initialize
55
-
56
- **Basic (metrics only):**
57
28
  ```bash
58
- thinknagent init \
59
- --server YOUR_APP_SERVER \
60
- --name my-server \
61
- --room <roomId>
62
- ```
63
-
64
- **With log streaming:**
65
- ```bash
66
- thinknagent init \
67
- --server YOUR_APP_SERVER \
68
- --name my-server \
69
- --room <roomId> \
70
- --logs <YOUR_LOG_FILE>
71
- ```
72
-
73
- **With PM2 app logs:**
74
- ```bash
75
- thinknagent init \
76
- --server YOUR_APP_SERVER \
77
- --name my-server \
78
- --room <roomId> \
79
- --logs <YOUR_PM2_LOG_FILE>
80
- ```
81
-
82
- **With GPU metrics & application version tracking:**
83
- ```bash
84
- thinknagent init \
85
- --server YOUR_APP_SERVER \
86
- --name my-server \
87
- --room <roomId> \
88
- --gpu \
89
- --logs <YOUR_SYS_LOG_FILE> \
90
- --app-path /var/www/my-node-app
29
+ npm install -g thinknagent
91
30
  ```
92
31
 
93
- Get your `roomId` from the room URL:
94
- https://thinkncollab.com/rooms/YOUR_ROOM_ID_HERE
95
-
96
- ### Step 2 — Start
32
+ > **Prerequisites:** Node.js v18+ on Linux, macOS, or Windows (WSL).
97
33
 
34
+ If you encounter native build errors for interactive shell (`node-pty`):
98
35
  ```bash
99
- thinknagent start
100
- ```
36
+ # Ubuntu / Debian
37
+ sudo apt-get update && sudo apt-get install -y build-essential python3
101
38
 
102
- Output:
103
- ```
104
- Starting thinknagent — my-server
105
- Status: PENDING — waiting for Owner approval
106
- [agent] Connecting to https://thinkncollab.com...
107
- [thinknagent] Registered as <agentId> — waiting for Owner approval...
39
+ # CentOS / RHEL
40
+ sudo yum groupinstall "Development Tools" -y
108
41
  ```
109
42
 
110
- ### Step 3 — Approve in Browser
43
+ ---
111
44
 
112
- 1. Go to your room's DevOps Wall:
113
- `https://thinkncollab.com/devops/<roomId>/devops`
114
- 2. Click **Approve** on the pending agent in the sidebar.
45
+ ## 🛠️ CLI Commands
115
46
 
116
- Once approved:
117
- ```
118
- [thinknagent] Approved! Role: monitor | Room: <roomId>
119
- [agent] Active. Role: monitor | Room: <roomId>
120
- [metrics] Poller started
121
- [logs] Watching 2 file(s)
122
- [shell] Bridge ready
123
- ```
47
+ | Command | Description |
48
+ | :--- | :--- |
49
+ | `thinknagent init` | Initialize & register this node with your ThinkNCollab workspace |
50
+ | `thinknagent start` | Run agent in active foreground (ideal for testing / debugging) |
51
+ | `thinknagent daemon start` | Start detached supervisor with auto-restart protection |
52
+ | `thinknagent daemon stop` | Stop the background daemon supervisor |
53
+ | `thinknagent daemon status` | Check daemon health, PID, uptime, and system status |
54
+ | `thinknagent daemon install` | Install as an OS-level Auto-Boot Service (**Linux Systemd** or **macOS LaunchAgent**) |
55
+ | `thinknagent status` | Show current authentication state, role, token, and node info |
56
+ | `thinknagent logs` | Tail live agent daemon logs |
57
+ | `thinknagent revoke` | Clear local credentials and reset connection state |
124
58
 
125
- ### Step 4 — Run with PM2 (Keep Alive)
59
+ ---
126
60
 
127
- To run the agent in the background so that all features (metrics, logs, shell) stay permanently active and accessible after you disconnect your terminal session:
61
+ ## ⚙️ Initialization Options
128
62
 
129
63
  ```bash
130
- # Start the agent using PM2
131
- pm2 start thinknagent --name "thinknagent_logs" -- start
132
-
133
- # Save PM2 process list and configure startup
134
- pm2 save
135
- pm2 startup
64
+ thinknagent init [options]
136
65
  ```
137
66
 
138
- ---
139
-
140
- ## Features
67
+ | Option | Default | Description |
68
+ | :--- | :--- | :--- |
69
+ | `--room <roomId>` | **Required** | Your ThinkNCollab Room ID (from workspace URL) |
70
+ | `--server <url>` | `https://thinkncollab.com` | Central ThinkNCollab server URL |
71
+ | `--name <name>` | Hostname | Custom display name for this node |
72
+ | `--role <role>` | `shell` | Requested permission role: `monitor` | `shell` | `admin` |
73
+ | `--logs <paths>` | `` | Comma-separated log file paths to stream live |
74
+ | `--app-path <path>` | Current Dir | Application directory path (for auto-version & git commit tracking) |
75
+ | `--gpu` | `false` | Enable NVIDIA GPU telemetry (requires `nvidia-smi`) |
76
+ | `--force` | `false` | Overwrite existing configuration |
141
77
 
142
- ### Metrics
143
- Real-time system metrics pushed every 5 seconds — no config needed, starts automatically:
144
- - CPU usage + load average + core count
145
- - Memory usage (used / total GB)
146
- - Disk usage per mount point
147
- - Network I/O (rx/tx per second)
148
- - Top 5 processes by CPU
78
+ ### Example Commands:
149
79
 
150
- ### ≡ Log Streaming
151
- Stream any log file to the DevOps Wall in real-time:
152
80
  ```bash
153
- # Common log paths on Ubuntu
154
- /var/log/syslog # system
155
- /var/log/auth.log # auth/ssh
156
- /var/log/nginx/access.log # nginx access
157
- /var/log/nginx/error.log # nginx errors
158
- /home/ubuntu/.pm2/logs/app-out.log # pm2 stdout
159
- /home/ubuntu/.pm2/logs/app-error.log # pm2 stderr
160
- ```
161
-
162
- Pass multiple paths comma-separated:
163
- ```bash
164
- --logs /var/log/syslog,/var/log/nginx/error.log,/home/ubuntu/.pm2/logs/app-out.log
81
+ # Standard Production Server with Nginx & PM2 logs
82
+ thinknagent init \
83
+ --server https://thinkncollab.com \
84
+ --room 6a318170496c7b00a7f74260 \
85
+ --name "prod-api-01" \
86
+ --role shell \
87
+ --logs "/var/log/nginx/error.log,/home/ubuntu/.pm2/logs/app-error.log" \
88
+ --app-path /home/ubuntu/myapp
165
89
  ```
166
90
 
167
- ### ⚠ Alerts
168
- Default alert rules — configurable from DevOps Wall at runtime:
169
-
170
- | ID | Metric | Condition | Severity |
171
- |----|--------|-----------|----------|
172
- | cpu-high | CPU usage | > 85% for 60s | warning |
173
- | cpu-crit | CPU usage | > 95% for 30s | critical |
174
- | mem-high | Memory usage | > 85% for 60s | warning |
175
- | disk-root | Disk `/` | > 90% | critical |
176
-
177
- ### ▸ Shell Access
178
- Remote terminal via xterm.js in the browser. Requires `shell` or `admin` role.
179
-
180
- **How to enable shell access:**
181
-
182
- 1. Owner opens DevOps Wall
183
- 2. Changes agent role to `shell` from the UI
184
- 3. Click `▸ shell` tab → `▸ open terminal`
185
-
186
- Full bash session on your server — directly in the browser.
187
-
188
91
  ---
189
92
 
190
- ## Roles
191
-
192
- | Role | Metrics | Logs | Alerts | Shell | Edit Rules |
193
- |------|---------|------|--------|-------|------------|
194
- | monitor | ✅ | ✅ | ✅ | ❌ | ❌ |
195
- | shell | ✅ | ✅ | ✅ | ✅ | ❌ |
196
- | admin | ✅ | ✅ | ✅ | ✅ | ✅ |
93
+ ## 🔒 Security & AES-256 E2EE Architecture
197
94
 
198
- Role is assigned by the room Owner at approval time and can be changed anytime from the DevOps Wall.
95
+ `thinknagent` is built with a strict **Zero-Trust & Zero-Knowledge** security model:
199
96
 
200
- ---
97
+ 1. **Client-Side AES-256-GCM Encryption**:
98
+ - All streamed log lines and sensitive terminal output are encrypted on the server before network transmission.
99
+ - The central ThinkNCollab server acts as a blind relay and **cannot decrypt or read your logs**.
100
+ - Your browser decrypts the stream locally via the **WebCrypto API** (`e2ee-vault.js`).
201
101
 
202
- ## Security & Privacy
102
+ 2. **Double-Gate Role-Based Access Control**:
103
+ - New agents start in `PENDING` mode until explicitly approved by the workspace owner in the DevOps Wall.
104
+ - Roles (`monitor`, `shell`, `admin`) restrict remote PTY terminal execution.
203
105
 
204
- The agent is designed with a "zero-trust" approach to protect your server's credentials, logs, and shell sessions.
106
+ 3. **Isolated Shell Environment**:
107
+ - Interactive PTY shells run in a sanitized environment whitelist.
108
+ - Secrets, environment variables (`.env`), and credentials belonging to the agent process are never leaked into the subshell.
205
109
 
206
- - 🔒 **Double-Gate Authorization**: New agents connect in `PENDING` mode. They cannot stream metrics or logs until explicitly approved by the room Owner. Upon approval, they receive a signed HMAC `agentToken` for secure reconnection.
207
- - 🛡️ **Remote Shell Environment Insulation**: Spawning a shell strips all server environment variables, passing only a safe allowlist (`PATH`, `HOME`, `SHELL`, `TERM`, `LANG`). Your database credentials, cloud API keys, and environment secrets remain completely safe.
208
- - 🚫 **Path Traversal & Sensitive File Blocks**: Log files are verified using absolute path checking. They must belong to allowed directories (`/var/log`, `/home`, `/root`, `/tmp`) and are explicitly blocked if they contain sensitive directories or files like `.ssh/id_rsa`, `.env`, `/etc/passwd`, `/etc/shadow`, etc.
209
- - 💬 **SSL Transport**: All WebSocket and HTTP traffic between the agent and the server is encrypted using HTTPS/WSS.
110
+ 4. **Path Traversal Protection**:
111
+ - Log streaming strictly blocks access to `/etc/shadow`, `/etc/sudoers`, `.ssh`, `.gnupg`, and `.env` files.
210
112
 
211
113
  ---
212
114
 
213
- ## Auth Flow
214
- thinknagent init
215
- → generates agentId
216
- → saves to ~/.thinknagent/config.json
217
- thinknagent start
218
- → connects to wss://thinkncollab.com/devops
219
- → sends { agentId, name, hostname, roomId }
220
- → server creates PENDING entry
221
- → Owner approves in browser
222
- → server sends back signed agentToken
223
- → token saved to config (mode 600)
224
- → agent reconnects as ACTIVE
225
- subsequent starts
226
- → sends { agentId, agentToken }
227
- → server verifies → ACTIVE immediately
228
-
229
- ---
115
+ ## 📊 Features on ThinkNCollab DevOps Wall
230
116
 
231
- ## Config File
232
-
233
- Location: `~/.thinknagent/config.json` (permissions: 600)
234
-
235
- ```json
236
- {
237
- "agentId": "uuid-v4",
238
- "serverUrl": "ur.server.url",
239
- "name": "my-server",
240
- "roomId": "your-room-id",
241
- "agentToken": "sha256-hmac-signed-token",
242
- "role": "monitor",
243
- "gpu": false,
244
- "logs": [
245
- "/var/log/syslog",
246
- "/var/log/nginx/error.log"
247
- ],
248
- "alerts": [
249
- { "id": "cpu-high", "metric": "cpu.usage", "op": "gt", "value": 85, "for": 60, "severity": "warning" },
250
- { "id": "cpu-crit", "metric": "cpu.usage", "op": "gt", "value": 95, "for": 30, "severity": "critical" },
251
- { "id": "mem-high", "metric": "memory.usedPct", "op": "gt", "value": 85, "for": 60, "severity": "warning" },
252
- { "id": "disk-root", "metric": "disk./", "op": "gt", "value": 90, "for": 0, "severity": "critical" }
253
- ]
254
- }
255
- ```
117
+ - **◈ Live Telemetry**: CPU, Memory, Disk mounts, Network I/O, Top CPU processes, and GPU utilization streamed over persistent WebSockets.
118
+ - **≡ Encrypted Log Streams**: High-throughput chunked file watching (`chokidar`) with instant tailing and search.
119
+ - **▸ Full Interactive Web PTY**: Real-time bidirectional terminal with color, resize, and keystroke streaming.
120
+ - **⚡ APM Traces & Percentiles**: Auto-computes latency distribution (p50, p90, p95, p99) and flame graphs.
121
+ - **🚨 Dynamic Alert Engine**: Custom multi-metric threshold triggers evaluated in real-time.
256
122
 
257
123
  ---
258
124
 
259
- ## Run as a Service (Recommended)
260
-
261
- Keep the agent running after SSH disconnect:
262
-
263
- **Using pm2:**
264
- ```bash
265
- npm install -g pm2
266
- pm2 start $(which thinknagent) --name thinknagent -- start
267
- pm2 save
268
- pm2 startup
269
- ```
270
-
271
- **Using systemd:**
272
- ```bash
273
- sudo nano /etc/systemd/system/thinknagent.service
274
- ```
275
-
276
- ```ini
277
- [Unit]
278
- Description=ThinkNCollab Agent
279
- After=network.target
280
-
281
- [Service]
282
- Type=simple
283
- User=ubuntu
284
- ExecStart=/home/ubuntu/.npm-global/bin/thinknagent start
285
- Restart=always
286
- RestartSec=5
287
-
288
- [Install]
289
- WantedBy=multi-user.target
290
- ```
291
-
292
- ```bash
293
- sudo systemctl enable thinknagent
294
- sudo systemctl start thinknagent
295
- sudo systemctl status thinknagent
296
- ```
297
-
298
- ---
125
+ ## 🔄 Running Permanently (Production Setup)
299
126
 
300
- ## Troubleshooting
127
+ ### Option 1: Built-in Systemd Service (Recommended for Linux Servers)
301
128
 
302
- **Permission denied**
303
129
  ```bash
304
- chmod +x $(which thinknagent)
130
+ # Auto-generates and activates /etc/systemd/system/thinknagent.service
131
+ sudo thinknagent daemon install
305
132
  ```
306
133
 
307
- **node-pty build error**
308
- ```bash
309
- sudo apt-get install -y build-essential python3
310
- npm install -g thinknagent
311
- ```
134
+ ### Option 2: Built-in Background Supervisor
312
135
 
313
- **Registration rejected: Invalid or revoked credentials**
314
136
  ```bash
315
- thinknagent revoke
316
- thinknagent init --server https://thinkncollab.com --name my-server --room <roomId>
317
- thinknagent start
137
+ thinknagent daemon start
318
138
  ```
319
139
 
320
- **Agent connects but not showing in DevOps Wall**
140
+ ### Option 3: PM2 Process Manager
321
141
 
322
- Refresh the DevOps Wall page — the agent list updates on page load.
323
-
324
- **Metrics not updating**
325
-
326
- Make sure agent is approved and `connected: true`. Check:
327
142
  ```bash
328
- thinknagent status
143
+ pm2 start thinknagent --name "thinknagent" -- start
144
+ pm2 save
145
+ pm2 startup
329
146
  ```
330
147
 
331
148
  ---
332
149
 
333
- ## Requirements
334
-
335
- - Node.js v18+
336
- - Linux or macOS
337
- - `build-essential` + `python3` (for shell feature)
338
- - Outbound HTTPS/WSS to your ThinkNCollab server
339
-
340
- ---
341
-
342
- ## License
150
+ ## 📜 License
343
151
 
344
152
  MIT © [ThinkNCollab](https://thinkncollab.com)
@@ -23,6 +23,7 @@ program
23
23
  .option('--server <url>', 'ThinkNCollab server URL', 'https://thinkncollab.com')
24
24
  .option('--name <name>', 'Display name for this server (default: hostname)')
25
25
  .option('--gpu', 'Enable GPU metrics (requires nvidia-smi)')
26
+ .option('--interval <ms>', 'Metrics polling interval in ms (default: 1000)', '1000')
26
27
  .option('--logs <paths>', 'Comma-separated log file paths to stream')
27
28
  .option('--app-path <path>', 'Path to the deployed application folder (to track version)')
28
29
  .option('-f, --force', 'Force overwrite existing registration')
@@ -46,12 +47,14 @@ program
46
47
  const agentId = existing.agentId || uuid();
47
48
  const serverUrl = (opts.server || 'https://thinkncollab.com').replace(/\/$/, '');
48
49
  const nodeName = opts.name || os.hostname();
50
+ const intervalMs = opts.interval ? parseInt(opts.interval, 10) : (existing.interval || 1000);
49
51
 
50
52
  const cfg = {
51
53
  ...existing,
52
54
  agentId,
53
55
  serverUrl,
54
56
  name: nodeName,
57
+ interval: intervalMs,
55
58
  gpu: opts.gpu !== undefined ? !!opts.gpu : (existing.gpu || false),
56
59
  logs: opts.logs ? opts.logs.split(',').map(s => s.trim()) : (existing.logs || []),
57
60
  roomId: opts.room,
@@ -97,7 +100,8 @@ program
97
100
  program
98
101
  .command('start')
99
102
  .description('Start the agent (connect to ThinkNCollab)')
100
- .option('--dev', 'Dev mode — verbose logging')
103
+ .option('--dev', 'Dev mode — verbose logging')
104
+ .option('--interval <ms>', 'Metrics polling interval in ms (default: 1000)')
101
105
  .action((opts) => {
102
106
  if (opts.dev) process.env.THINKNAGENT_DEV = '1';
103
107
 
@@ -107,6 +111,11 @@ program
107
111
  process.exit(1);
108
112
  }
109
113
 
114
+ if (opts.interval) {
115
+ cfg.interval = parseInt(opts.interval, 10);
116
+ store.write(cfg);
117
+ }
118
+
110
119
  console.log(chalk.cyan(`\n Starting thinknagent — ${cfg.name || cfg.agentId}`));
111
120
  if (!cfg.agentToken) {
112
121
  console.log(chalk.yellow(' Status: PENDING — waiting for Owner approval in DevOps Wall\n'));
@@ -248,6 +257,20 @@ daemonCmd
248
257
  new DaemonManager().installService();
249
258
  });
250
259
 
260
+ // ── mcp (Model Context Protocol Stdio Server for LLMs & PMs) ──────────────────
261
+ program
262
+ .command('mcp')
263
+ .description('Start Model Context Protocol (MCP) server for Claude Desktop, Cursor & ChatGPT')
264
+ .option('--board <boardId>', 'Board ID to manage')
265
+ .option('--token <token>', 'ThinkNCollab API Token')
266
+ .option('--server <url>', 'ThinkNCollab API Server URL')
267
+ .action((opts) => {
268
+ if (opts.board) process.env.THINKNCOLLAB_BOARD_ID = opts.board;
269
+ if (opts.token) process.env.THINKNCOLLAB_TOKEN = opts.token;
270
+ if (opts.server) process.env.THINKNCOLLAB_API_URL = opts.server;
271
+ require('./thinkncollab-mcp');
272
+ });
273
+
251
274
  // Default banner if no arguments
252
275
  if (process.argv.length <= 2) {
253
276
  const os = require('os');