trace.ai-cli 1.1.0 → 1.1.1

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.
@@ -1,8 +1,550 @@
1
1
  const fetch = require('node-fetch');
2
2
  const { encryptData, decryptData } = require('../utils/encryption');
3
+ const { getSystemInfo, formatBytes } = require('./systemInfoService');
4
+
5
+ /**
6
+ * Use AI to determine what system information is being requested
7
+ * @param {string} prompt - The user's prompt
8
+ * @param {Object} basicInfo - Basic system information for context
9
+ * @returns {Object} Object containing the determined query
10
+ */
11
+ async function determineSystemInfoQuery(prompt, basicInfo) {
12
+ try {
13
+ // Create a prompt for the AI to analyze the user's query
14
+ const analysisPrompt = `
15
+ Based on the user's query: "${prompt}", determine which system information they are requesting.
16
+
17
+ Available system information categories:
18
+ - basic: Basic system overview (platform, architecture, hostname, uptime)
19
+ - cpu: CPU information (model, cores, speed, load)
20
+ - memory: Memory information (total, used, free)
21
+ - disk: Disk information (size, used, available)
22
+ - network: Network information (interfaces, IP addresses, MAC)
23
+ - process: Process information (PID, Node.js version, memory usage)
24
+ - environment: Environment variables (PATH, SHELL, etc.)
25
+ - all: All system information
26
+
27
+ Analyze the query and return the most relevant category or categories.
28
+ If the query mentions IP address, network interfaces, or connectivity, include 'network'.
29
+ If the query mentions storage, hard drive, or space, include 'disk'.
30
+ If the query mentions RAM, memory usage, or available memory, include 'memory'.
31
+ If the query mentions processor, cores, or CPU usage, include 'cpu'.
32
+ If the query mentions environment variables or paths, include 'environment'.
33
+ If the query mentions running processes or applications, include 'process'.
34
+ If the query is general or unclear, include 'basic'.
35
+ If the query asks for everything or all information, include 'all'.
36
+
37
+ Return only the category keywords separated by spaces.
38
+ `;
39
+
40
+ // Use the AI to analyze the query
41
+ const models = ['kimi', 'mvrk', 'gma3'];
42
+
43
+ const modelRequests = models.map(model =>
44
+ fetch('https://traceai.dukeindustries7.workers.dev/', {
45
+ method: 'POST',
46
+ headers: { 'Content-Type': 'application/json' },
47
+ body: encryptData({
48
+ a: model,
49
+ q: analysisPrompt,
50
+ r: [],
51
+ i: [],
52
+ c: JSON.stringify(basicInfo)
53
+ })
54
+ })
55
+ .then(res => res.text())
56
+ .then(text => {
57
+ try {
58
+ return decryptData(text);
59
+ } catch (e) {
60
+ console.error('Error decrypting data:', e.message);
61
+ return { text: null };
62
+ }
63
+ })
64
+ .catch(err => {
65
+ console.error('Error in model request:', err.message);
66
+ return { text: null };
67
+ })
68
+ );
69
+
70
+ const responses = await Promise.all(modelRequests);
71
+ // Ensure we have valid responses and filter out any null or undefined values
72
+ const validResponses = responses.filter(r => r && typeof r === 'object');
73
+ const responseTexts = validResponses
74
+ .filter(r => r.text && typeof r.text === 'string') // Ensure text exists and is a string
75
+ .map(r => r.text);
76
+
77
+ // Combine the responses to get the most accurate determination
78
+ let categories = new Set();
79
+
80
+ // Check if we have any valid responses
81
+ if (responseTexts && responseTexts.length > 0) {
82
+ for (const text of responseTexts) {
83
+ if (text && typeof text === 'string') {
84
+ const words = text.toLowerCase().trim().split(/\s+/);
85
+ for (const word of words) {
86
+ if (word && ['basic', 'cpu', 'memory', 'disk', 'network', 'process', 'environment', 'all'].includes(word)) {
87
+ categories.add(word);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ } else {
93
+ // No valid responses, default to basic
94
+ console.log('No valid AI responses for system info query, defaulting to basic');
95
+ categories.add('basic');
96
+ }
97
+
98
+ // If 'all' is included, just return that
99
+ if (categories.has('all')) {
100
+ return { query: 'all' };
101
+ }
102
+
103
+ // If no categories were determined, default to basic
104
+ if (categories.size === 0) {
105
+ categories.add('basic');
106
+ }
107
+
108
+ // Convert the set to a space-separated string
109
+ const query = Array.from(categories).join(' ');
110
+
111
+ return { query };
112
+ } catch (error) {
113
+ console.error('❌ Error determining system info query:', error.message);
114
+ // Default to basic info if there's an error
115
+ return { query: 'basic' };
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Check if a prompt is related to system information
121
+ * @param {string} prompt - The user's prompt
122
+ * @returns {boolean} True if the prompt is related to system information
123
+ */
124
+ function isSystemInfoQuery(prompt) {
125
+ // Always return true for /system commands - we'll let the AI determine relevance
126
+ return true;
127
+ }
128
+
129
+ /**
130
+ * Format system information into a readable response
131
+ * @param {Object} sysInfo - System information object
132
+ * @param {string} prompt - The original prompt
133
+ * @returns {string} Formatted response
134
+ */
135
+ function formatSystemInfoResponse(sysInfo, prompt) {
136
+ let response = `Here's the system information you requested:\n\n`;
137
+
138
+ // Check if we have any system information
139
+ const hasInfo = Object.keys(sysInfo).length > 0;
140
+
141
+ if (!hasInfo) {
142
+ response = `I couldn't find specific system information for your query: "${prompt}"\n\n`;
143
+ response += `You can ask about:\n`;
144
+ response += `- Basic system information (platform, architecture, hostname, manufacturer, model)\n`;
145
+ response += `- CPU information (model, cores, speed, load, temperature, manufacturer)\n`;
146
+ response += `- Memory information (total, used, free, active, available, swap)\n`;
147
+ response += `- Disk information (size, used, available, file systems, block devices)\n`;
148
+ response += `- Network information (interfaces, IP addresses, connections, wifi, latency)\n`;
149
+ response += `- Process information (running processes, services, resource usage)\n`;
150
+ response += `- Environment variables (PATH, SHELL, user info, etc.)\n\n`;
151
+ response += `Try queries like:\n`;
152
+ response += `- "What's my IP address?" (network)\n`;
153
+ response += `- "How much disk space do I have?" (disk)\n`;
154
+ response += `- "What's my CPU usage?" (cpu)\n`;
155
+ response += `- "Show me all system information" (all)\n\n`;
156
+ return response;
157
+ }
158
+
159
+ if (sysInfo.basic) {
160
+ const basic = sysInfo.basic;
161
+ response += `📱 **System Overview**\n`;
162
+ response += `- Platform: ${basic.platform} (${basic.type} ${basic.release})\n`;
163
+ response += `- Architecture: ${basic.arch}\n`;
164
+ response += `- Hostname: ${basic.hostname}\n`;
165
+ response += `- Uptime: ${Math.floor(basic.uptime / 3600)} hours ${Math.floor((basic.uptime % 3600) / 60)} minutes\n`;
166
+
167
+ // Add enhanced system information if available
168
+ if (basic.manufacturer) response += `- Manufacturer: ${basic.manufacturer}\n`;
169
+ if (basic.model) response += `- Model: ${basic.model}\n`;
170
+ if (basic.version) response += `- Version: ${basic.version}\n`;
171
+ if (basic.serial) response += `- Serial Number: ${basic.serial}\n`;
172
+ if (basic.uuid) response += `- UUID: ${basic.uuid}\n`;
173
+ if (basic.sku) response += `- SKU: ${basic.sku}\n`;
174
+ if (basic.virtual) response += `- Virtualization: ${basic.virtual ? 'Yes' : 'No'}\n`;
175
+ if (basic.distro) response += `- Distribution: ${basic.distro}\n`;
176
+ if (basic.codename) response += `- Codename: ${basic.codename}\n`;
177
+ if (basic.kernel) response += `- Kernel: ${basic.kernel}\n`;
178
+
179
+ response += `\n`;
180
+ }
181
+
182
+ if (sysInfo.cpu) {
183
+ const cpu = sysInfo.cpu;
184
+ response += `💻 **CPU Information**\n`;
185
+ response += `- Model: ${cpu.model}\n`;
186
+ response += `- Cores: ${cpu.cores}\n`;
187
+ response += `- Speed: ${cpu.speed} MHz\n`;
188
+ response += `- Load Average: ${cpu.loadAvg.map(load => load.toFixed(2)).join(', ')}\n`;
189
+
190
+ // Add enhanced CPU information if available
191
+ if (cpu.manufacturer) response += `- Manufacturer: ${cpu.manufacturer}\n`;
192
+ if (cpu.brand) response += `- Brand: ${cpu.brand}\n`;
193
+ if (cpu.physicalCores) response += `- Physical Cores: ${cpu.physicalCores}\n`;
194
+ if (cpu.processors) response += `- Processors: ${cpu.processors}\n`;
195
+ if (cpu.socket) response += `- Socket: ${cpu.socket}\n`;
196
+ if (cpu.vendor) response += `- Vendor: ${cpu.vendor}\n`;
197
+ if (cpu.family) response += `- Family: ${cpu.family}\n`;
198
+ if (cpu.stepping) response += `- Stepping: ${cpu.stepping}\n`;
199
+ if (cpu.virtualization) response += `- Virtualization: ${cpu.virtualization}\n`;
200
+ if (cpu.cache) {
201
+ response += `- Cache:\n`;
202
+ Object.entries(cpu.cache).forEach(([level, size]) => {
203
+ response += ` - ${level}: ${size}\n`;
204
+ });
205
+ }
206
+ if (cpu.temperature) response += `- Temperature: ${cpu.temperature}°C\n`;
207
+ if (cpu.currentLoad) response += `- Current Load: ${cpu.currentLoad.toFixed(2)}%\n`;
208
+ if (cpu.currentLoadUser) response += `- User Load: ${cpu.currentLoadUser.toFixed(2)}%\n`;
209
+ if (cpu.currentLoadSystem) response += `- System Load: ${cpu.currentLoadSystem.toFixed(2)}%\n`;
210
+
211
+ response += `\n`;
212
+ }
213
+
214
+ if (sysInfo.memory) {
215
+ const memory = sysInfo.memory;
216
+ response += `🧠 **Memory Information**\n`;
217
+ response += `- Total: ${memory.total}\n`;
218
+ response += `- Used: ${memory.used} (${memory.usagePercent})\n`;
219
+ response += `- Free: ${memory.free}\n`;
220
+
221
+ // Add enhanced memory information if available
222
+ if (memory.active) response += `- Active: ${memory.active}\n`;
223
+ if (memory.available) response += `- Available: ${memory.available}\n`;
224
+ if (memory.buffers) response += `- Buffers: ${memory.buffers}\n`;
225
+ if (memory.cached) response += `- Cached: ${memory.cached}\n`;
226
+ if (memory.slab) response += `- Slab: ${memory.slab}\n`;
227
+ if (memory.swapTotal) response += `- Swap Total: ${memory.swapTotal}\n`;
228
+ if (memory.swapUsed) response += `- Swap Used: ${memory.swapUsed}\n`;
229
+ if (memory.swapFree) response += `- Swap Free: ${memory.swapFree}\n`;
230
+
231
+ // Add memory layout information if available
232
+ if (memory.layout && Array.isArray(memory.layout) && memory.layout.length > 0) {
233
+ response += `- Memory Modules:\n`;
234
+ memory.layout.forEach((module, index) => {
235
+ response += ` - Module ${index + 1}:\n`;
236
+ if (module.size) response += ` - Size: ${formatBytes(module.size)}\n`;
237
+ if (module.bank) response += ` - Bank: ${module.bank}\n`;
238
+ if (module.type) response += ` - Type: ${module.type}\n`;
239
+ if (module.clockSpeed) response += ` - Clock Speed: ${module.clockSpeed} MHz\n`;
240
+ if (module.formFactor) response += ` - Form Factor: ${module.formFactor}\n`;
241
+ if (module.manufacturer) response += ` - Manufacturer: ${module.manufacturer}\n`;
242
+ if (module.partNum) response += ` - Part Number: ${module.partNum}\n`;
243
+ if (module.serialNum) response += ` - Serial Number: ${module.serialNum}\n`;
244
+ if (module.voltageConfigured) response += ` - Voltage: ${module.voltageConfigured} V\n`;
245
+ });
246
+ }
247
+
248
+ response += `\n`;
249
+ }
250
+
251
+ if (sysInfo.disk) {
252
+ response += `💾 **Disk Information**\n`;
253
+
254
+ // Handle enhanced disk information
255
+ if (sysInfo.disk.fsSize && Array.isArray(sysInfo.disk.fsSize)) {
256
+ response += `- File Systems:\n`;
257
+ sysInfo.disk.fsSize.forEach(fs => {
258
+ response += ` - ${fs.fs} (${fs.type}):\n`;
259
+ response += ` - Mount: ${fs.mount}\n`;
260
+ response += ` - Size: ${fs.size ? formatBytes(fs.size) : 'N/A'}\n`;
261
+ response += ` - Used: ${fs.used ? formatBytes(fs.used) : 'N/A'} (${fs.use ? fs.use.toFixed(1) + '%' : 'N/A'})\n`;
262
+ response += ` - Available: ${fs.available ? formatBytes(fs.available) : 'N/A'}\n`;
263
+ });
264
+ } else if (Array.isArray(sysInfo.disk)) {
265
+ // Windows format (legacy)
266
+ sysInfo.disk.forEach(disk => {
267
+ response += `- Drive ${disk.drive}:\n`;
268
+ response += ` - Size: ${disk.size}\n`;
269
+ response += ` - Used: ${disk.used} (${disk.usagePercent})\n`;
270
+ response += ` - Free: ${disk.free}\n`;
271
+ });
272
+ } else if (sysInfo.disk.error) {
273
+ response += `- Error retrieving disk information: ${sysInfo.disk.error}\n`;
274
+ } else if (sysInfo.disk.filesystem) {
275
+ // Unix format (legacy)
276
+ response += `- Filesystem: ${sysInfo.disk.filesystem}\n`;
277
+ response += `- Size: ${sysInfo.disk.size}\n`;
278
+ response += `- Used: ${sysInfo.disk.used} (${sysInfo.disk.usagePercent})\n`;
279
+ response += `- Available: ${sysInfo.disk.available}\n`;
280
+ response += `- Mounted on: ${sysInfo.disk.mountedOn}\n`;
281
+ }
282
+
283
+ // Add block devices information if available
284
+ if (sysInfo.disk.blockDevices && Array.isArray(sysInfo.disk.blockDevices)) {
285
+ response += `- Block Devices:\n`;
286
+ sysInfo.disk.blockDevices.forEach(device => {
287
+ response += ` - ${device.name}:\n`;
288
+ if (device.type) response += ` - Type: ${device.type}\n`;
289
+ if (device.size) response += ` - Size: ${formatBytes(device.size)}\n`;
290
+ if (device.physical) response += ` - Physical: ${device.physical}\n`;
291
+ if (device.uuid) response += ` - UUID: ${device.uuid}\n`;
292
+ if (device.label) response += ` - Label: ${device.label}\n`;
293
+ if (device.model) response += ` - Model: ${device.model}\n`;
294
+ if (device.serial) response += ` - Serial: ${device.serial}\n`;
295
+ if (device.removable !== undefined) response += ` - Removable: ${device.removable ? 'Yes' : 'No'}\n`;
296
+ if (device.protocol) response += ` - Protocol: ${device.protocol}\n`;
297
+ });
298
+ }
299
+
300
+ // Add disk layout information if available
301
+ if (sysInfo.disk.diskLayout && Array.isArray(sysInfo.disk.diskLayout)) {
302
+ response += `- Disk Layout:\n`;
303
+ sysInfo.disk.diskLayout.forEach(disk => {
304
+ response += ` - ${disk.device}:\n`;
305
+ if (disk.type) response += ` - Type: ${disk.type}\n`;
306
+ if (disk.name) response += ` - Name: ${disk.name}\n`;
307
+ if (disk.vendor) response += ` - Vendor: ${disk.vendor}\n`;
308
+ if (disk.size) response += ` - Size: ${formatBytes(disk.size)}\n`;
309
+ if (disk.bytesPerSector) response += ` - Bytes Per Sector: ${disk.bytesPerSector}\n`;
310
+ if (disk.totalCylinders) response += ` - Total Cylinders: ${disk.totalCylinders}\n`;
311
+ if (disk.totalHeads) response += ` - Total Heads: ${disk.totalHeads}\n`;
312
+ if (disk.totalSectors) response += ` - Total Sectors: ${disk.totalSectors}\n`;
313
+ if (disk.totalTracks) response += ` - Total Tracks: ${disk.totalTracks}\n`;
314
+ if (disk.tracksPerCylinder) response += ` - Tracks Per Cylinder: ${disk.tracksPerCylinder}\n`;
315
+ if (disk.sectorsPerTrack) response += ` - Sectors Per Track: ${disk.sectorsPerTrack}\n`;
316
+ if (disk.firmwareRevision) response += ` - Firmware Revision: ${disk.firmwareRevision}\n`;
317
+ if (disk.serialNum) response += ` - Serial Number: ${disk.serialNum}\n`;
318
+ if (disk.interfaceType) response += ` - Interface Type: ${disk.interfaceType}\n`;
319
+ });
320
+ }
321
+
322
+ response += `\n`;
323
+ }
324
+
325
+ if (sysInfo.network) {
326
+ response += `🌐 **Network Information**\n`;
327
+
328
+ // Handle enhanced network interfaces information
329
+ if (sysInfo.network.interfaces && Array.isArray(sysInfo.network.interfaces)) {
330
+ response += `- Interfaces:\n`;
331
+ sysInfo.network.interfaces.forEach(iface => {
332
+ if (!iface.internal) { // Only show external interfaces
333
+ response += ` - ${iface.iface}:\n`;
334
+ if (iface.ifaceName) response += ` - Name: ${iface.ifaceName}\n`;
335
+ if (iface.ip4) response += ` - IPv4: ${iface.ip4}\n`;
336
+ if (iface.ip6) response += ` - IPv6: ${iface.ip6}\n`;
337
+ if (iface.mac) response += ` - MAC: ${iface.mac}\n`;
338
+ if (iface.speed) response += ` - Speed: ${iface.speed} Mbps\n`;
339
+ if (iface.type) response += ` - Type: ${iface.type}\n`;
340
+ if (iface.operstate) response += ` - State: ${iface.operstate}\n`;
341
+ if (iface.carrier !== undefined) response += ` - Carrier: ${iface.carrier ? 'Yes' : 'No'}\n`;
342
+ if (iface.mtu) response += ` - MTU: ${iface.mtu}\n`;
343
+ if (iface.dhcp !== undefined) response += ` - DHCP: ${iface.dhcp ? 'Yes' : 'No'}\n`;
344
+ }
345
+ });
346
+ } else if (Array.isArray(sysInfo.network)) {
347
+ // Legacy format
348
+ sysInfo.network.forEach(net => {
349
+ if (!net.internal) { // Only show external interfaces
350
+ response += `- Interface: ${net.interface}\n`;
351
+ response += ` - IP Address: ${net.address}\n`;
352
+ response += ` - Netmask: ${net.netmask}\n`;
353
+ response += ` - MAC: ${net.mac}\n`;
354
+ }
355
+ });
356
+ }
357
+
358
+ // Add network stats if available
359
+ if (sysInfo.network.stats && Array.isArray(sysInfo.network.stats)) {
360
+ response += `- Network Stats:\n`;
361
+ sysInfo.network.stats.forEach(stat => {
362
+ if (!stat.iface.includes('lo')) { // Skip loopback
363
+ response += ` - ${stat.iface}:\n`;
364
+ if (stat.rx_bytes) response += ` - Received: ${formatBytes(stat.rx_bytes)}\n`;
365
+ if (stat.tx_bytes) response += ` - Sent: ${formatBytes(stat.tx_bytes)}\n`;
366
+ if (stat.rx_errors) response += ` - Receive Errors: ${stat.rx_errors}\n`;
367
+ if (stat.tx_errors) response += ` - Send Errors: ${stat.tx_errors}\n`;
368
+ if (stat.rx_dropped) response += ` - Receive Dropped: ${stat.rx_dropped}\n`;
369
+ if (stat.tx_dropped) response += ` - Send Dropped: ${stat.tx_dropped}\n`;
370
+ }
371
+ });
372
+ }
373
+
374
+ // Add connection information if available
375
+ if (sysInfo.network.connections && sysInfo.network.connections.length > 0) {
376
+ const connections = sysInfo.network.connections;
377
+ const totalConnections = connections.length;
378
+ const establishedCount = connections.filter(conn => conn.state === 'ESTABLISHED').length;
379
+ const listeningCount = connections.filter(conn => conn.state === 'LISTEN').length;
380
+
381
+ response += `- Connections:\n`;
382
+ response += ` - Total: ${totalConnections}\n`;
383
+ response += ` - Established: ${establishedCount}\n`;
384
+ response += ` - Listening: ${listeningCount}\n`;
385
+
386
+ // Show top 5 connections
387
+ if (totalConnections > 0) {
388
+ response += ` - Top 5 Connections:\n`;
389
+ connections.slice(0, 5).forEach(conn => {
390
+ response += ` - ${conn.protocol} ${conn.localAddress}:${conn.localPort} -> ${conn.peerAddress}:${conn.peerPort} (${conn.state})\n`;
391
+ });
392
+ }
393
+ }
394
+
395
+ // Add wifi networks if available
396
+ if (sysInfo.network.wifiNetworks && Array.isArray(sysInfo.network.wifiNetworks)) {
397
+ response += `- WiFi Networks:\n`;
398
+ sysInfo.network.wifiNetworks.forEach(network => {
399
+ response += ` - ${network.ssid}:\n`;
400
+ if (network.bssid) response += ` - BSSID: ${network.bssid}\n`;
401
+ if (network.mode) response += ` - Mode: ${network.mode}\n`;
402
+ if (network.channel) response += ` - Channel: ${network.channel}\n`;
403
+ if (network.frequency) response += ` - Frequency: ${network.frequency} MHz\n`;
404
+ if (network.signalLevel) response += ` - Signal Level: ${network.signalLevel} dBm\n`;
405
+ if (network.quality) response += ` - Quality: ${network.quality}/100\n`;
406
+ if (network.security) response += ` - Security: ${network.security.join(', ')}\n`;
407
+ });
408
+ }
409
+
410
+ // Add internet connectivity information if available
411
+ if (sysInfo.network.internetLatency !== undefined) {
412
+ response += `- Internet Connectivity:\n`;
413
+ response += ` - Latency: ${sysInfo.network.internetLatency.toFixed(2)} ms\n`;
414
+ }
415
+
416
+ // Add public IP if available
417
+ if (sysInfo.network.publicIp) {
418
+ response += `- Public IP: ${sysInfo.network.publicIp}\n`;
419
+ }
420
+
421
+ response += `\n`;
422
+ }
423
+
424
+ if (sysInfo.environment) {
425
+ response += `🔧 **Environment Variables**\n`;
426
+
427
+ // Add user information if available
428
+ if (sysInfo.environment.user) {
429
+ const user = sysInfo.environment.user;
430
+ response += `- User Information:\n`;
431
+ if (user.username) response += ` - Username: ${user.username}\n`;
432
+ if (user.uid) response += ` - UID: ${user.uid}\n`;
433
+ if (user.gid) response += ` - GID: ${user.gid}\n`;
434
+ if (user.shell) response += ` - Shell: ${user.shell}\n`;
435
+ if (user.homedir) response += ` - Home Directory: ${user.homedir}\n`;
436
+ }
437
+
438
+ // Add shell history if available
439
+ if (sysInfo.environment.shell && sysInfo.environment.shell.length > 0) {
440
+ response += `- Recent Shell Commands:\n`;
441
+ sysInfo.environment.shell.slice(0, 5).forEach((cmd, index) => {
442
+ response += ` - ${index + 1}: ${cmd}\n`;
443
+ });
444
+ }
445
+
446
+ // Add environment variables
447
+ if (sysInfo.environment.variables) {
448
+ response += `- Environment Variables:\n`;
449
+ for (const [key, value] of Object.entries(sysInfo.environment.variables)) {
450
+ response += ` - ${key}: ${value}\n`;
451
+ }
452
+ } else {
453
+ // Legacy format
454
+ for (const [key, value] of Object.entries(sysInfo.environment)) {
455
+ if (typeof value === 'string') {
456
+ response += `- ${key}: ${value}\n`;
457
+ }
458
+ }
459
+ }
460
+
461
+ response += `\n`;
462
+ }
463
+
464
+ if (sysInfo.process) {
465
+ response += `⚙️ **Process Information**\n`;
466
+
467
+ // Add current process information
468
+ if (sysInfo.process.current) {
469
+ const current = sysInfo.process.current;
470
+ response += `- Current Process:\n`;
471
+ if (current.pid) response += ` - PID: ${current.pid}\n`;
472
+ if (current.ppid) response += ` - Parent PID: ${current.ppid}\n`;
473
+ if (current.name) response += ` - Name: ${current.name}\n`;
474
+ if (current.cpu) response += ` - CPU Usage: ${current.cpu.toFixed(2)}%\n`;
475
+ if (current.memory) response += ` - Memory Usage: ${formatBytes(current.memory)}\n`;
476
+ if (current.started) response += ` - Started: ${new Date(current.started).toLocaleString()}\n`;
477
+ if (current.state) response += ` - State: ${current.state}\n`;
478
+ if (current.path) response += ` - Path: ${current.path}\n`;
479
+ if (current.command) response += ` - Command: ${current.command}\n`;
480
+ if (current.params) response += ` - Parameters: ${current.params.join(' ')}\n`;
481
+ } else {
482
+ // Legacy format
483
+ response += `- PID: ${sysInfo.process.pid}\n`;
484
+ response += `- Node.js Version: ${sysInfo.process.version}\n`;
485
+ response += `- Current Directory: ${sysInfo.process.cwd}\n`;
486
+ response += `- Memory Usage: ${Math.round(sysInfo.process.memoryUsage.rss / (1024 * 1024))} MB\n`;
487
+ }
488
+
489
+ // Add process summary if available
490
+ if (sysInfo.process.summary) {
491
+ const summary = sysInfo.process.summary;
492
+ response += `- Process Summary:\n`;
493
+ if (summary.total) response += ` - Total: ${summary.total}\n`;
494
+ if (summary.running) response += ` - Running: ${summary.running}\n`;
495
+ if (summary.blocked) response += ` - Blocked: ${summary.blocked}\n`;
496
+ if (summary.sleeping) response += ` - Sleeping: ${summary.sleeping}\n`;
497
+ if (summary.unknown) response += ` - Unknown: ${summary.unknown}\n`;
498
+ }
499
+
500
+ // Add top processes if available
501
+ if (sysInfo.process.list && Array.isArray(sysInfo.process.list)) {
502
+ response += `- Top Processes (by CPU):\n`;
503
+ sysInfo.process.list.slice(0, 10).forEach((proc, index) => {
504
+ response += ` - ${index + 1}: ${proc.name} (PID: ${proc.pid})\n`;
505
+ response += ` - CPU: ${proc.cpu.toFixed(2)}%, Memory: ${formatBytes(proc.mem)}\n`;
506
+ });
507
+ }
508
+
509
+ // Add services if available
510
+ if (sysInfo.process.services && Array.isArray(sysInfo.process.services)) {
511
+ response += `- System Services:\n`;
512
+ sysInfo.process.services.slice(0, 10).forEach((service, index) => {
513
+ response += ` - ${index + 1}: ${service.name} (${service.running ? 'Running' : 'Stopped'})\n`;
514
+ if (service.pids && service.pids.length > 0) {
515
+ response += ` - PIDs: ${service.pids.join(', ')}\n`;
516
+ }
517
+ if (service.startmode) response += ` - Start Mode: ${service.startmode}\n`;
518
+ });
519
+ }
520
+
521
+ response += `\n`;
522
+ }
523
+
524
+ return response;
525
+ }
3
526
 
4
527
  async function processWithAI(prompt, context = '') {
5
528
  try {
529
+ // Check if the prompt is related to system information
530
+ if (isSystemInfoQuery(prompt)) {
531
+ try {
532
+ // First get basic system info to provide context
533
+ const basicInfo = await getSystemInfo('basic');
534
+
535
+ // Use AI to determine what system information is being requested
536
+ const aiResponse = await determineSystemInfoQuery(prompt, basicInfo);
537
+
538
+ // Get the specific system information based on AI's determination
539
+ const systemInfo = await getSystemInfo(aiResponse.query);
540
+ return formatSystemInfoResponse(systemInfo, prompt);
541
+ } catch (sysError) {
542
+ console.error('❌ System info error:', sysError.message);
543
+ // If system info fails, fall back to AI processing
544
+ }
545
+ }
546
+
547
+ // Regular AI processing
6
548
  const models = ['kimi', 'mvrk', 'gma3', 'dsv3', 'qw32b', 'ms24b', 'll70b', 'qw3', 'mp4', 'nlm3'];
7
549
 
8
550
  const modelRequests = models.map(model =>
@@ -46,5 +588,8 @@ async function processWithAI(prompt, context = '') {
46
588
  }
47
589
 
48
590
  module.exports = {
49
- processWithAI
591
+ processWithAI,
592
+ determineSystemInfoQuery,
593
+ isSystemInfoQuery,
594
+ formatSystemInfoResponse
50
595
  };