@feardread/fear 1.0.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.
Files changed (99) hide show
  1. package/FEAR.js +459 -0
  2. package/FEARServer.js +280 -0
  3. package/controllers/agent.js +438 -0
  4. package/controllers/auth/index.js +345 -0
  5. package/controllers/auth/token.js +50 -0
  6. package/controllers/blog.js +105 -0
  7. package/controllers/brand.js +10 -0
  8. package/controllers/cart.js +425 -0
  9. package/controllers/category.js +9 -0
  10. package/controllers/coupon.js +63 -0
  11. package/controllers/crud/crud.js +508 -0
  12. package/controllers/crud/index.js +36 -0
  13. package/controllers/email.js +34 -0
  14. package/controllers/enquiry.js +65 -0
  15. package/controllers/events.js +9 -0
  16. package/controllers/order.js +125 -0
  17. package/controllers/payment.js +31 -0
  18. package/controllers/product.js +147 -0
  19. package/controllers/review.js +247 -0
  20. package/controllers/tag.js +10 -0
  21. package/controllers/task.js +10 -0
  22. package/controllers/upload.js +41 -0
  23. package/controllers/user.js +401 -0
  24. package/index.js +7 -0
  25. package/libs/agent/index.js +561 -0
  26. package/libs/agent/modules/ai/ai.js +285 -0
  27. package/libs/agent/modules/ai/chat.js +518 -0
  28. package/libs/agent/modules/ai/config.js +688 -0
  29. package/libs/agent/modules/ai/operations.js +787 -0
  30. package/libs/agent/modules/analyze/api.js +546 -0
  31. package/libs/agent/modules/analyze/dorks.js +395 -0
  32. package/libs/agent/modules/ccard/README.md +454 -0
  33. package/libs/agent/modules/ccard/audit.js +479 -0
  34. package/libs/agent/modules/ccard/checker.js +674 -0
  35. package/libs/agent/modules/ccard/payment-processors.json +16 -0
  36. package/libs/agent/modules/ccard/validator.js +629 -0
  37. package/libs/agent/modules/code/analyzer.js +303 -0
  38. package/libs/agent/modules/code/jquery.js +1093 -0
  39. package/libs/agent/modules/code/react.js +1536 -0
  40. package/libs/agent/modules/code/refactor.js +499 -0
  41. package/libs/agent/modules/crypto/exchange.js +564 -0
  42. package/libs/agent/modules/net/proxy.js +409 -0
  43. package/libs/agent/modules/security/cve.js +442 -0
  44. package/libs/agent/modules/security/monitor.js +360 -0
  45. package/libs/agent/modules/security/scanner.js +300 -0
  46. package/libs/agent/modules/security/vulnerability.js +506 -0
  47. package/libs/agent/modules/security/web.js +465 -0
  48. package/libs/agent/modules/utils/browser.js +492 -0
  49. package/libs/agent/modules/utils/colorizer.js +285 -0
  50. package/libs/agent/modules/utils/manager.js +478 -0
  51. package/libs/cloud/index.js +228 -0
  52. package/libs/config/db.js +21 -0
  53. package/libs/config/validator.js +82 -0
  54. package/libs/db/index.js +318 -0
  55. package/libs/emailer/imap.js +126 -0
  56. package/libs/emailer/info.js +41 -0
  57. package/libs/emailer/smtp.js +77 -0
  58. package/libs/handler/async.js +3 -0
  59. package/libs/handler/error.js +66 -0
  60. package/libs/handler/index.js +161 -0
  61. package/libs/logger/index.js +49 -0
  62. package/libs/logger/morgan.js +24 -0
  63. package/libs/passport/passport.js +109 -0
  64. package/libs/search/api.js +384 -0
  65. package/libs/search/features.js +219 -0
  66. package/libs/search/service.js +64 -0
  67. package/libs/swagger/config.js +18 -0
  68. package/libs/swagger/index.js +35 -0
  69. package/libs/validator/index.js +254 -0
  70. package/models/blog.js +31 -0
  71. package/models/brand.js +12 -0
  72. package/models/cart.js +14 -0
  73. package/models/category.js +11 -0
  74. package/models/coupon.js +9 -0
  75. package/models/customer.js +0 -0
  76. package/models/enquiry.js +29 -0
  77. package/models/events.js +13 -0
  78. package/models/order.js +94 -0
  79. package/models/product.js +32 -0
  80. package/models/review.js +14 -0
  81. package/models/tag.js +10 -0
  82. package/models/task.js +11 -0
  83. package/models/user.js +68 -0
  84. package/package.json +12 -0
  85. package/routes/agent.js +615 -0
  86. package/routes/auth.js +13 -0
  87. package/routes/blog.js +19 -0
  88. package/routes/brand.js +15 -0
  89. package/routes/cart.js +105 -0
  90. package/routes/category.js +16 -0
  91. package/routes/coupon.js +15 -0
  92. package/routes/enquiry.js +14 -0
  93. package/routes/events.js +16 -0
  94. package/routes/mail.js +170 -0
  95. package/routes/order.js +19 -0
  96. package/routes/product.js +22 -0
  97. package/routes/review.js +11 -0
  98. package/routes/task.js +12 -0
  99. package/routes/user.js +17 -0
@@ -0,0 +1,561 @@
1
+ // agent.js - Enhanced with separate chat sessions and background services
2
+ const readline = require('readline');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const colorizer = require('./modules/utils/colorizer');
6
+
7
+ const SecurityAgent = function () {
8
+ this.modules = {};
9
+ this.commands = {};
10
+ this.commandHistory = [];
11
+ this.historyIndex = 0;
12
+ this.maxHistory = 100;
13
+ this.backgroundServices = new Map();
14
+ this.serviceStatus = new Map();
15
+
16
+ // Module definitions with metadata
17
+ this.definitions = [
18
+ // Security
19
+ { name: 'scanner', file: './modules/security/scanner', displayName: 'Security Scanner' },
20
+ { name: 'webScraper', file: './modules/security/web', displayName: 'Web Scraper' },
21
+ { name: 'vulnAssessment', file: './modules/security/vulnerability', displayName: 'Vuln Assessment' },
22
+ { name: 'trafficMonitor', file: './modules/security/monitor', displayName: 'Traffic Monitor' },
23
+ { name: 'cveDatabase', file: './modules/security/cve', displayName: 'CVE Database' },
24
+ // AI
25
+ { name: 'aiAnalyzer', file: './modules/ai/ai', displayName: 'AI Analyzer' },
26
+ { name: 'aiChat', file: './modules/ai/chat', displayName: 'AI Chat Session' },
27
+ { name: 'codeAnalyzer', file: './modules/code/analyzer', displayName: 'Code Analyzer' },
28
+ // Analysis
29
+ { name: 'googleDorks', file: './modules/analyze/dorks', displayName: 'Google Dorks' },
30
+ { name: 'apiTester', file: './modules/analyze/api', displayName: 'API Tester' },
31
+ // Coding
32
+ { name: 'codeRefactor', file: './modules/code/refactor', displayName: 'Code Refactor' },
33
+ { name: 'htmlToReact', file: './modules/code/react', displayName: 'HTML to React' },
34
+ { name: 'JQueryToReact', file: './modules/code/jquery', displayName: 'jQuery to React' },
35
+ // CC / Bin validation
36
+ { name: 'cardValidator', file: './modules/ccard/validator', displayName: 'Card Validator' },
37
+ { name: 'cardStatusChecker', file: './modules/ccard/checker', displayName: 'Card Payment Checker' },
38
+ { name: 'cryptoChecker', file: './modules/crypto/exchange', displayName: 'Crypto Exchange' },
39
+ // Utils Services
40
+ { name: 'fileBrowser', file: './modules/utils/browser', displayName: 'File Browser' },
41
+ { name: 'proxyManager', file: './modules/net/proxy', displayName: 'Proxy Manager' },
42
+ { name: 'serviceManager', file: './modules/utils/manager', displayName: 'Service Manager' }
43
+ ];
44
+
45
+ // Command to module mappings
46
+ this.mappings = {
47
+ // File browser commands
48
+ 'ls': { module: 'fileBrowser', method: 'list', description: 'List files and directories' },
49
+ 'cd': { module: 'fileBrowser', method: 'cd', description: 'Change directory' },
50
+ 'pwd': { module: 'fileBrowser', method: 'pwd', description: 'Show current directory' },
51
+ 'cat': { module: 'fileBrowser', method: 'cat', description: 'Display file contents' },
52
+ 'less': { module: 'fileBrowser', method: 'less', description: 'View file (paginated)' },
53
+ 'find': { module: 'fileBrowser', method: 'find', description: 'Search for files' },
54
+ 'file-info': { module: 'fileBrowser', method: 'info', description: 'Show file information' },
55
+ 'tree': { module: 'fileBrowser', method: 'tree', description: 'Display directory tree' },
56
+ 'bookmark': { module: 'fileBrowser', method: 'bookmark', description: 'Manage bookmarks' },
57
+ 'browse-help': { module: 'fileBrowser', method: 'showHelp', description: 'File browser help' },
58
+
59
+ // Scanner commands
60
+ 'scan-ports': { module: 'scanner', method: 'scanPorts', description: 'Scan network ports' },
61
+ 'check-deps': { module: 'scanner', method: 'checkDependencies', description: 'Check dependencies' },
62
+ 'network-info': { module: 'scanner', method: 'getNetworkInfo', description: 'Show network info' },
63
+ 'security-audit': { module: 'scanner', method: 'securityAudit', description: 'Run security audit' },
64
+
65
+ // Code analyzer commands
66
+ 'analyze-code': { module: 'codeAnalyzer', method: 'analyzeCode', description: 'Analyze code file' },
67
+ 'analyze-project': { module: 'codeAnalyzer', method: 'analyzeProject', description: 'Analyze project' },
68
+
69
+ // Traffic monitor commands
70
+ 'monitor-traffic': { module: 'trafficMonitor', method: 'startMonitoring', description: 'Start traffic monitoring' },
71
+ 'stop-monitor': { module: 'trafficMonitor', method: 'stopMonitoring', description: 'Stop monitoring' },
72
+ 'traffic-stats': { module: 'trafficMonitor', method: 'showStats', description: 'Show traffic stats' },
73
+ 'export-traffic': { module: 'trafficMonitor', method: 'exportData', description: 'Export traffic data' },
74
+
75
+ // AI analyzer commands - EXPANDED
76
+ 'ai-setup': { module: 'aiAnalyzer', method: 'setup', description: 'Configure AI provider' },
77
+ 'ai-provider': { module: 'aiAnalyzer', method: 'setProvider', description: 'Switch AI provider' },
78
+ 'ai-status': { module: 'aiAnalyzer', method: 'status', description: 'Show AI module status' },
79
+ 'ai-help': { module: 'aiAnalyzer', method: 'help', description: 'Show AI commands help' },
80
+ 'ai-analyze': { module: 'aiAnalyzer', method: 'analyzeCode', description: 'AI security analysis' },
81
+ 'ai-batch': { module: 'aiAnalyzer', method: 'analyzeBatch', description: 'Batch analyze files' },
82
+ 'ai-compare': { module: 'aiAnalyzer', method: 'compareCodeVersions', description: 'Compare code versions' },
83
+ 'ai-threat': { module: 'aiAnalyzer', method: 'threatAssessment', description: 'Threat assessment' },
84
+ 'ai-explain': { module: 'aiAnalyzer', method: 'explainVulnerability', description: 'Explain vulnerability' },
85
+ 'ai-generate': { module: 'aiAnalyzer', method: 'generateNodeCode', description: 'Generate Node.js code' },
86
+ 'ai-improve': { module: 'aiAnalyzer', method: 'suggestImprovements', description: 'Security recommendations' },
87
+ 'ai-scan': { module: 'aiAnalyzer', method: 'quickScan', description: 'Quick security scan' },
88
+ 'ai-ask': { module: 'aiAnalyzer', method: 'quickChat', description: 'Quick AI question' },
89
+
90
+ // AI Chat Session commands (separate from main AI)
91
+ 'chat': { module: 'aiChat', method: 'startSession', description: 'Start interactive chat session' },
92
+ 'chat-quick': { module: 'aiChat', method: 'quickQuery', description: 'Quick chat query' },
93
+ 'chat-history': { module: 'aiChat', method: 'showHistory', description: 'Show chat history' },
94
+ 'chat-save': { module: 'aiChat', method: 'saveSession', description: 'Save chat session' },
95
+ 'chat-load': { module: 'aiChat', method: 'loadSession', description: 'Load chat session' },
96
+ 'chat-clear': { module: 'aiChat', method: 'clearHistory', description: 'Clear chat history' },
97
+ 'chat-export': { module: 'aiChat', method: 'exportChat', description: 'Export chat to file' },
98
+
99
+ // Background Services commands
100
+ 'service-start': { module: 'serviceManager', method: 'startService', description: 'Start background service' },
101
+ 'service-stop': { module: 'serviceManager', method: 'stopService', description: 'Stop background service' },
102
+ 'service-status': { module: 'serviceManager', method: 'serviceStatus', description: 'Show service status' },
103
+ 'service-list': { module: 'serviceManager', method: 'listServices', description: 'List all services' },
104
+ 'service-logs': { module: 'serviceManager', method: 'showLogs', description: 'Show service logs' },
105
+ 'service-restart': { module: 'serviceManager', method: 'restartService', description: 'Restart service' },
106
+
107
+ // CVE database commands
108
+ 'search-cve': { module: 'cveDatabase', method: 'searchCVE', description: 'Search CVE database' },
109
+ 'check-cwe': { module: 'cveDatabase', method: 'checkCWE', description: 'Check CWE details' },
110
+ 'check-package': { module: 'cveDatabase', method: 'checkPackage', description: 'Check package vulnerabilities' },
111
+ 'check-exploits': { module: 'cveDatabase', method: 'checkExploits', description: 'Search exploits' },
112
+ 'scan-deps': { module: 'cveDatabase', method: 'scanDependencies', description: 'Scan dependencies for CVEs' },
113
+ 'export-cve': { module: 'cveDatabase', method: 'exportCVEReport', description: 'Export CVE report' },
114
+
115
+ // API tester commands
116
+ 'test-endpoint': { module: 'apiTester', method: 'testEndpoint', description: 'Test API endpoint' },
117
+ 'test-collection': { module: 'apiTester', method: 'testCollection', description: 'Test API collection' },
118
+ 'export-report': { module: 'apiTester', method: 'exportReport', description: 'Export test report' },
119
+
120
+ // Code refactor commands
121
+ 'refactor-file': { module: 'codeRefactor', method: 'refactorFile', description: 'Refactor JavaScript file' },
122
+ 'refactor-project': { module: 'codeRefactor', method: 'refactorProject', description: 'Refactor project' },
123
+ 'analyze-refactor': { module: 'codeRefactor', method: 'analyzeCode', description: 'Analyze for refactoring' },
124
+ 'compare-refactor': { module: 'codeRefactor', method: 'compareVersions', description: 'Compare versions' },
125
+ // Web scraper commands
126
+ 'scrape': { module: 'webScraper', method: 'scrape', description: 'Scrape webpage' },
127
+ 'scrape-links': { module: 'webScraper', method: 'scrapeLinks', description: 'Extract links' },
128
+ 'scrape-images': { module: 'webScraper', method: 'scrapeImages', description: 'Extract images' },
129
+ 'export-scrape': { module: 'webScraper', method: 'exportScrape', description: 'Export scraped data' },
130
+ 'analyze-headers': { module: 'webScraper', method: 'analyzeSecurityHeaders', description: 'Analyze security headers' },
131
+ // Vulnerability assessment commands
132
+ 'vuln-assess': { module: 'vulnAssessment', method: 'assess', description: 'Run vulnerability assessment' },
133
+ 'export-vuln': { module: 'vulnAssessment', method: 'exportResults', description: 'Export vulnerability results' },
134
+ // Proxy Manager commands
135
+ 'check-ip': { module: 'proxyManager', method: 'checkPublicIp', description: 'Check current public IP' },
136
+ 'configure-proxifly': { module: 'proxyManager', method: 'configureProxifly', description: 'Configure Proxifly API' },
137
+ 'configure-proxy5': { module: 'proxyManager', method: 'configureProxy5', description: 'Configure Proxy5 credentials' },
138
+ 'fetch-proxies': { module: 'proxyManager', method: 'fetchProxies', description: 'Fetch proxies from Proxifly' },
139
+ 'add-proxy5': { module: 'proxyManager', method: 'addProxy5Proxies', description: 'Add Proxy5 proxies' },
140
+ 'list-proxies': { module: 'proxyManager', method: 'displayProxyList', description: 'List available proxies' },
141
+ 'select-proxy': { module: 'proxyManager', method: 'selectProxy', description: 'Select and activate proxy' },
142
+ 'test-proxy': { module: 'proxyManager', method: 'testProxy', description: 'Test current proxy' },
143
+ 'clear-proxy': { module: 'proxyManager', method: 'clearProxy', description: 'Clear active proxy' },
144
+ 'proxy-status': { module: 'proxyManager', method: 'showStatus', description: 'Show proxy status' },
145
+ 'proxy-help': { module: 'proxyManager', method: 'showHelp', description: 'Proxy manager help' },
146
+ // HTML to React commands
147
+ 'html-to-react': { module: 'htmlToReact', method: 'convert', description: 'Convert HTML to React' },
148
+ 'batch-convert': { module: 'htmlToReact', method: 'convertBatch', description: 'Batch convert HTML files' },
149
+ 'analyze-html': { module: 'htmlToReact', method: 'analyzeHTML', description: 'Analyze HTML structure' },
150
+
151
+ // jQuery to React commands
152
+ 'jquery-to-react': { module: 'JQueryToReact', method: 'convert', description: 'Convert jQuery to React' },
153
+ 'jq-batch-convert': { module: 'JQueryToReact', method: 'convertBatch', description: 'Batch convert jQuery files' },
154
+ 'analyze-jquery': { module: 'JQueryToReact', method: 'analyzeBatch', description: 'Analyze jQuery structure' },
155
+
156
+ // CC and BIN validation
157
+ 'validate-card': { module: 'cardValidator', method: 'validateCard', description: 'Validate card number format' },
158
+ 'validate-batch': { module: 'cardValidator', method: 'validateBatch', description: 'Batch validate cards' },
159
+ 'analyze-bin': { module: 'cardValidator', method: 'analyzeBIN', description: 'Analyze BIN number' },
160
+ 'show-test-cards': { module: 'cardValidator', method: 'showTestCards', description: 'Show official test cards' },
161
+ 'explain-algorithm': { module: 'cardValidator', method: 'explainAlgorithm', description: 'Explain validation algorithms' },
162
+ 'card-security-report': { module: 'cardValidator', method: 'securityReport', description: 'Generate security report' },
163
+
164
+ 'check-card-status': { module: 'cardStatusChecker', method: 'checkCardStatus', description: 'Check single card' },
165
+ 'check-card-batch': { module: 'cardStatusChecker', method: 'checkCardBatch', description: 'Check card batch' },
166
+ 'configure-card-checker': { module: 'cardStatusChecker', method: 'configure', description: 'Configure card checker' },
167
+ 'card-checker-help': { module: 'cardStatusChecker', method: 'showHelp', description: 'Show help menu' },
168
+
169
+ 'compare-rates': { module: 'cryptoChecker', method: 'compareRates', description: 'Compare crypto rates' },
170
+ 'crypto-price': { module: 'cryptoChecker', method: 'getPrice', description: 'Get cryptocurrency price' },
171
+ 'track-portfolio': { module: 'cryptoChecker', method: 'trackPortfolio', description: 'Track cryptos' },
172
+ 'crypto-convert': { module: 'cryptoChecker', method: 'convert', description: 'Convert cryptocurrencies' },
173
+ 'market-summary': { module: 'cryptoChecker', method: 'marketSummary', description: 'Market summary' },
174
+ 'export-rates': { module: 'cryptoChecker', method: 'exportRates', description: 'Export rates' },
175
+ 'crypto-help': { module: 'cryptoChecker', method: 'showHelp', description: 'Crypto help' },
176
+
177
+ // Google Dorks commands
178
+ 'list-dorks': { module: 'googleDorks', method: 'listDorks', description: 'List dork templates' },
179
+ 'generate-dork': { module: 'googleDorks', method: 'generateDork', description: 'Generate dorks' },
180
+ 'custom-dork': { module: 'googleDorks', method: 'customDork', description: 'Create custom dork' },
181
+ 'dork-categories': { module: 'googleDorks', method: 'showCategories', description: 'Show categories' },
182
+ 'save-dorks': { module: 'googleDorks', method: 'saveDorks', description: 'Save dorks' },
183
+ 'load-custom-dorks': { module: 'googleDorks', method: 'loadCustomDorks', description: 'Load custom dorks' },
184
+ 'advanced-dorks': { module: 'googleDorks', method: 'generateAdvancedDorks', description: 'Advanced dorks' },
185
+ 'dork-help': { module: 'googleDorks', method: 'showHelp', description: 'Dorks help' },
186
+ };
187
+
188
+ this.loadModules();
189
+ this.registerCommands();
190
+
191
+ this.logo = `
192
+
193
+ @@@@@@@@ @@@@@@@@ @@@@@@ @@@@@@@
194
+ @@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@
195
+ @@! @@! @@! @@@ @@! @@@
196
+ !@! !@! !@! @!@ !@! @!@
197
+ @!!!:! @!!!:! @!@!@!@! @!@!!@!
198
+ !!!!!: !!!!!: !!!@!!!! !!@!@!
199
+ !!: !!: !!: !!! !!: :!!
200
+ :!: :!: :!: !:! :!: !:!
201
+ :: :: :::: :: ::: :: :::
202
+ : : :: :: : : : : : :
203
+ `;
204
+
205
+ }
206
+
207
+ SecurityAgent.prototype = {
208
+
209
+ loadModules() {
210
+ console.log(colorizer.dim('Loading modules...'));
211
+
212
+ this.definitions.forEach(moduleDef => {
213
+ let output = '';
214
+ try {
215
+ const ModuleClass = require(moduleDef.file);
216
+ this.modules[moduleDef.name] = new ModuleClass(this);
217
+ console.log(colorizer.dim(' [OK] ' + moduleDef.displayName));
218
+ } catch (err) {
219
+ console.log(colorizer.warning(' [SKIP] ' + moduleDef.displayName + ' - ' + err.message));
220
+ }
221
+ });
222
+
223
+ console.log();
224
+ },
225
+
226
+ registerCommands() {
227
+ Object.entries(this.mappings).forEach(([cmd, config]) => {
228
+ const module = this.modules[config.module];
229
+ if (module && typeof module[config.method] === 'function') {
230
+ this.commands[cmd] = args => module[config.method](args);
231
+ }
232
+ });
233
+
234
+ // Add built-in commands
235
+ this.commands['help'] = () => this.showHelp();
236
+ this.commands['status'] = () => this.showStatus();
237
+ this.commands['history'] = () => this.showHistory();
238
+ this.commands['clear'] = () => this.clearScreen();
239
+ this.commands['banner'] = () => this.showBanner();
240
+ this.commands['version'] = () => this.showVersion();
241
+ this.commands['tips'] = () => this.showTips();
242
+ this.commands['exit'] = () => this.exit();
243
+ },
244
+
245
+ start() {
246
+ this.showBanner();
247
+ this.showStatus();
248
+
249
+ const rl = readline.createInterface({
250
+ input: process.stdin,
251
+ output: process.stdout,
252
+ prompt: this.getPrompt(),
253
+ completer: line => this.autocomplete(line)
254
+ });
255
+
256
+ rl.prompt();
257
+
258
+ rl.on('line', input => {
259
+ const trimmed = input.trim();
260
+
261
+ if (trimmed) {
262
+ this.addToHistory(trimmed);
263
+ this.executeCommand(trimmed)
264
+ .then(() => rl.prompt())
265
+ .catch(() => rl.prompt());
266
+ } else {
267
+ rl.prompt();
268
+ }
269
+ });
270
+
271
+ rl.on('close', () => {
272
+ this.exit();
273
+ });
274
+
275
+ return Promise.resolve();
276
+ },
277
+
278
+ showBanner() {
279
+ const banner = [
280
+ '=============================================================',
281
+ '║ ║',
282
+ '║ SECURITY AI AGENT v2.4 ║',
283
+ '║ Advanced Security Testing Framework ║',
284
+ '║ ║',
285
+ '=============================================================',
286
+ ];
287
+
288
+ console.log(colorizer.header(this.logo));
289
+ console.log(colorizer.bright(colorizer.cyan(banner.join('\n'))));
290
+ console.log();
291
+ },
292
+
293
+ showStatus() {
294
+ console.log(colorizer.section('System Status'));
295
+
296
+ this.definitions.forEach(moduleDef => {
297
+ const module = this.modules[moduleDef.name];
298
+ const status = module ? colorizer.green('[READY]') : colorizer.red('[UNAVAILABLE]');
299
+
300
+ // Special status for AI modules
301
+ if (moduleDef.name === 'aiAnalyzer' && module) {
302
+ const configured = module.isConfigured && module.isConfigured();
303
+ const provider = module.getProviderName && module.getProviderName();
304
+ const aiStatus = configured ?
305
+ colorizer.green('[READY - ' + provider + ']') :
306
+ colorizer.yellow('[NOT CONFIGURED]');
307
+ console.log(colorizer.cyan(' ' + moduleDef.displayName.padEnd(20)) + aiStatus);
308
+ } else if (moduleDef.name === 'aiChat' && module) {
309
+ const configured = module.isConfigured && module.isConfigured();
310
+ const chatStatus = configured ?
311
+ colorizer.green('[READY]') :
312
+ colorizer.yellow('[NOT CONFIGURED]');
313
+ console.log(colorizer.cyan(' ' + moduleDef.displayName.padEnd(20)) + chatStatus);
314
+ } else {
315
+ console.log(colorizer.cyan(' ' + moduleDef.displayName.padEnd(20)) + status);
316
+ }
317
+ });
318
+
319
+ // Show background services status
320
+ if (this.backgroundServices.size > 0) {
321
+ console.log();
322
+ console.log(colorizer.section('Background Services'));
323
+ this.backgroundServices.forEach((service, name) => {
324
+ const status = this.serviceStatus.get(name);
325
+ const statusText = status === 'running' ?
326
+ colorizer.green('[RUNNING]') :
327
+ colorizer.dim('[STOPPED]');
328
+ console.log(colorizer.cyan(' ' + name.padEnd(20)) + statusText);
329
+ });
330
+ }
331
+
332
+ console.log();
333
+ console.log(colorizer.magenta('Type "help" for commands, "chat" for AI chat, "exit" to quit'));
334
+ console.log();
335
+ },
336
+
337
+ getPrompt() {
338
+ const timestamp = new Date().toLocaleTimeString('en-US', {
339
+ hour12: false,
340
+ hour: '2-digit',
341
+ minute: '2-digit'
342
+ });
343
+
344
+ let prompt = colorizer.bright(colorizer.cyan('[' + timestamp + '] '));
345
+
346
+ if (this.modules.fileBrowser && this.modules.fileBrowser.currentPath) {
347
+ const cwd = path.basename(this.modules.fileBrowser.currentPath);
348
+ prompt += colorizer.dim('(' + cwd + ') ');
349
+ }
350
+
351
+ // Show active services count
352
+ const activeServices = Array.from(this.serviceStatus.values())
353
+ .filter(status => status === 'running').length;
354
+ if (activeServices > 0) {
355
+ prompt += colorizer.yellow(`[${activeServices} services] `);
356
+ }
357
+
358
+ prompt += colorizer.bright(colorizer.green('FEAR >> '));
359
+ return prompt;
360
+ },
361
+
362
+ executeCommand(input) {
363
+ const [cmd, ...args] = input.split(' ');
364
+
365
+ if (this.commands[cmd]) {
366
+ return Promise.resolve()
367
+ .then(() => this.commands[cmd](args))
368
+ .catch(err => {
369
+ console.log(colorizer.error(err.message));
370
+ if (err.stack && process.env.DEBUG) {
371
+ console.log(colorizer.dim(err.stack));
372
+ }
373
+ });
374
+ } else {
375
+ console.log(colorizer.error('Unknown command: ' + cmd));
376
+ console.log(colorizer.info('Type "help" for available commands'));
377
+ return Promise.resolve();
378
+ }
379
+ },
380
+
381
+ autocomplete(line) {
382
+ const completions = Object.keys(this.commands);
383
+ const hits = completions.filter(c => c.startsWith(line));
384
+ return [hits.length ? hits : completions, line];
385
+ },
386
+
387
+ addToHistory(cmd) {
388
+ this.commandHistory.push(cmd);
389
+ if (this.commandHistory.length > this.maxHistory) {
390
+ this.commandHistory.shift();
391
+ }
392
+ },
393
+
394
+ showHistory() {
395
+ console.log(colorizer.section('Command History'));
396
+
397
+ if (this.commandHistory.length === 0) {
398
+ console.log(colorizer.dim(' No commands in history'));
399
+ } else {
400
+ const recent = this.commandHistory.slice(-20);
401
+ recent.forEach((cmd, i) => {
402
+ const num = this.commandHistory.length - recent.length + i + 1;
403
+ console.log(colorizer.numbered(num, cmd));
404
+ });
405
+ }
406
+ console.log();
407
+ return Promise.resolve();
408
+ },
409
+
410
+ showVersion() {
411
+ console.log(colorizer.section('Version Information'));
412
+ console.log(colorizer.cyan(' Agent Version: ') + colorizer.bright('2.4.0'));
413
+ console.log(colorizer.cyan(' Node Version: ') + colorizer.bright(process.version));
414
+ console.log(colorizer.cyan(' Platform: ') + colorizer.bright(process.platform));
415
+ console.log(colorizer.cyan(' Architecture: ') + colorizer.bright(process.arch));
416
+
417
+ const moduleCount = Object.keys(this.modules).length;
418
+ const commandCount = Object.keys(this.commands).length;
419
+
420
+ console.log(colorizer.cyan(' Loaded Modules: ') + colorizer.bright(moduleCount));
421
+ console.log(colorizer.cyan(' Available Commands: ') + colorizer.bright(commandCount));
422
+ console.log();
423
+ return Promise.resolve();
424
+ },
425
+
426
+ clearScreen() {
427
+ console.clear();
428
+ process.stdout.write('\x1Bc');
429
+ },
430
+
431
+ showHelp() {
432
+ console.log(colorizer.box('Security AI Agent - Command Reference'));
433
+
434
+ const categories = {
435
+ 'File Browser': [
436
+ 'ls', 'cd', 'pwd', 'cat', 'less', 'find', 'file-info', 'tree', 'bookmark', 'browse-help'
437
+ ],
438
+ 'AI Analysis (Main)': [
439
+ 'ai-setup', 'ai-provider', 'ai-status', 'ai-help', 'ai-analyze', 'ai-batch',
440
+ 'ai-compare', 'ai-threat', 'ai-explain', 'ai-generate', 'ai-improve', 'ai-scan', 'ai-ask'
441
+ ],
442
+ 'AI Chat (Separate Session)': [
443
+ 'chat', 'chat-quick', 'chat-history', 'chat-save', 'chat-load', 'chat-clear', 'chat-export'
444
+ ],
445
+ 'Background Services': [
446
+ 'service-start', 'service-stop', 'service-status', 'service-list', 'service-logs', 'service-restart'
447
+ ],
448
+ 'Network Scanning': [
449
+ 'scan-ports', 'network-info', 'check-deps', 'security-audit'
450
+ ],
451
+ 'Code Analysis': [
452
+ 'analyze-code', 'analyze-project'
453
+ ],
454
+ 'Traffic Monitoring': [
455
+ 'monitor-traffic', 'stop-monitor', 'traffic-stats', 'export-traffic'
456
+ ],
457
+ 'CVE & Security': [
458
+ 'search-cve', 'check-cwe', 'check-package', 'check-exploits', 'scan-deps', 'export-cve'
459
+ ],
460
+ 'Proxy Management': [
461
+ 'check-ip', 'configure-proxifly', 'configure-proxy5', 'fetch-proxies',
462
+ 'add-proxy5', 'list-proxies', 'select-proxy', 'test-proxy', 'clear-proxy',
463
+ 'proxy-status', 'proxy-help'
464
+ ],
465
+ 'System': [
466
+ 'help', 'status', 'history', 'banner', 'version', 'tips', 'clear', 'exit'
467
+ ]
468
+ };
469
+
470
+ Object.entries(categories).forEach(([category, commands]) => {
471
+ console.log(colorizer.section(category.toUpperCase()));
472
+ commands.forEach(cmd => {
473
+ const config = this.mappings[cmd];
474
+ const desc = config ? config.description : 'Show ' + cmd.replace('-', ' ');
475
+ console.log(colorizer.bullet(cmd.padEnd(25) + ' - ' + colorizer.dim(desc)));
476
+ });
477
+ console.log();
478
+ });
479
+
480
+ console.log(colorizer.info('Quick Start:'));
481
+ console.log(colorizer.dim(' • Run "chat" to start AI conversation (separate from analysis)'));
482
+ console.log(colorizer.dim(' • Run "service-list" to see available background services'));
483
+ console.log(colorizer.dim(' • Run "ai-setup" to configure AI analysis tools'));
484
+ console.log();
485
+
486
+ return Promise.resolve();
487
+ },
488
+
489
+ showTips() {
490
+ console.log(colorizer.section('💡 Tips & Tricks'));
491
+ console.log();
492
+
493
+ console.log(colorizer.cyan('New Features:'));
494
+ console.log(colorizer.dim(' • Separate AI Chat: Use "chat" for conversational AI'));
495
+ console.log(colorizer.dim(' • Background Services: Run tasks in the background'));
496
+ console.log(colorizer.dim(' • Service Management: Start/stop/monitor services'));
497
+ console.log();
498
+
499
+ console.log(colorizer.cyan('Chat vs AI Commands:'));
500
+ console.log(colorizer.dim(' • "chat" - Conversational AI with context retention'));
501
+ console.log(colorizer.dim(' • "ai-analyze" - Security-focused code analysis'));
502
+ console.log(colorizer.dim(' • "ai-ask" - Quick single questions'));
503
+ console.log();
504
+
505
+ console.log(colorizer.cyan('Background Services:'));
506
+ console.log(colorizer.dim(' • Auto-monitoring: Continuous security scanning'));
507
+ console.log(colorizer.dim(' • Scheduled tasks: Run operations on schedule'));
508
+ console.log(colorizer.dim(' • Log aggregation: Collect and analyze logs'));
509
+ console.log();
510
+
511
+ return Promise.resolve();
512
+ },
513
+
514
+ // Background service management
515
+ registerService(name, service) {
516
+ this.backgroundServices.set(name, service);
517
+ this.serviceStatus.set(name, 'stopped');
518
+ },
519
+
520
+ startService(name) {
521
+ const service = this.backgroundServices.get(name);
522
+ if (service && service.start) {
523
+ service.start();
524
+ this.serviceStatus.set(name, 'running');
525
+ return true;
526
+ }
527
+ return false;
528
+ },
529
+
530
+ stopService(name) {
531
+ const service = this.backgroundServices.get(name);
532
+ if (service && service.stop) {
533
+ service.stop();
534
+ this.serviceStatus.set(name, 'stopped');
535
+ return true;
536
+ }
537
+ return false;
538
+ },
539
+
540
+ exit() {
541
+ console.log(colorizer.cyan('\nShutting down...'));
542
+
543
+ // Stop all background services
544
+ this.backgroundServices.forEach((service, name) => {
545
+ if (this.serviceStatus.get(name) === 'running') {
546
+ console.log(colorizer.dim(` Stopping ${name}...`));
547
+ this.stopService(name);
548
+ }
549
+ });
550
+
551
+ // Cleanup modules
552
+ if (this.modules.trafficMonitor && this.modules.trafficMonitor.stopMonitoring) {
553
+ this.modules.trafficMonitor.stopMonitoring();
554
+ }
555
+
556
+ console.log(colorizer.bright(colorizer.cyan('Goodbye!\n')));
557
+ process.exit(0);
558
+ }
559
+ };
560
+
561
+ module.exports = SecurityAgent;