vibecodingmachine-core 2026.2.26-1739 → 2026.3.9-850

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 (192) hide show
  1. package/package.json +1 -1
  2. package/src/agents/AgentCheckDiscoveryService.js +180 -0
  3. package/src/agents/AgentCheckService.js +18 -261
  4. package/src/agents/AgentCheckStatisticsService.js +195 -0
  5. package/src/agents/EnvironmentConfigurationManager.js +31 -380
  6. package/src/agents/InstallationType.js +19 -6
  7. package/src/agents/SimpleAgentCheckService.js +472 -0
  8. package/src/agents/config-managers/ConfigUtils.js +72 -0
  9. package/src/agents/config-managers/DefaultConfig.js +58 -0
  10. package/src/agents/config-managers/EnvVarLoader.js +66 -0
  11. package/src/agents/config-managers/FileConfigLoader.js +124 -0
  12. package/src/agents/config-managers/TypeConverters.js +61 -0
  13. package/src/agents/config-managers/VariableMappings.js +92 -0
  14. package/src/agents/discovery/AgentDiscoveryService-refactored.js +272 -0
  15. package/src/agents/discovery/AgentDiscoveryService.js +29 -403
  16. package/src/agents/discovery/agent-validator.js +262 -0
  17. package/src/agents/discovery/discovery-results.js +176 -0
  18. package/src/agents/discovery/discovery-scanner.js +268 -0
  19. package/src/agents/discovery/discovery-utils.js +161 -0
  20. package/src/agents/discovery/executable-analyzer.js +290 -0
  21. package/src/agents/discovery/history-manager.js +310 -0
  22. package/src/agents/verification/ResultAnalyzer-refactored.js +341 -0
  23. package/src/agents/verification/ResultAnalyzer.js +30 -431
  24. package/src/agents/verification/analysis-utils.js +310 -0
  25. package/src/agents/verification/batch-analyzer.js +440 -0
  26. package/src/agents/verification/pattern-recognizer.js +369 -0
  27. package/src/agents/verification/report-generator.js +320 -0
  28. package/src/agents/verification/test-analyzer.js +290 -0
  29. package/src/agents/windows/InstallerFactory.js +4 -0
  30. package/src/agents/windows/VSCodeExtensionInstaller.js +404 -0
  31. package/src/analysis/analysis-engine.js +314 -0
  32. package/src/analysis/ast-analyzer.js +342 -0
  33. package/src/analysis/boundary-detector-refactored.js +378 -0
  34. package/src/analysis/boundary-detector.js +200 -603
  35. package/src/analysis/boundary-scanner.js +609 -0
  36. package/src/analysis/boundary-types.js +118 -0
  37. package/src/analysis/boundary-utils.js +293 -0
  38. package/src/analysis/deadline-priority-calculator.js +18 -0
  39. package/src/analysis/detection-methods.js +347 -0
  40. package/src/analysis/importance-priority-calculator.js +18 -0
  41. package/src/analysis/priority/factor-calculators.js +204 -0
  42. package/src/analysis/priority/factor-helpers.js +71 -0
  43. package/src/analysis/priority/priority-constants.js +73 -0
  44. package/src/analysis/priority/priority-factor-calculators.js +301 -0
  45. package/src/analysis/priority/reasons-generator.js +44 -0
  46. package/src/analysis/priority-calculator.js +15 -580
  47. package/src/analysis/strategy-generator.js +16 -66
  48. package/src/analysis/type-priority-calculator.js +18 -0
  49. package/src/analysis/urgency-priority-calculator.js +18 -0
  50. package/src/auto-mode/AutoModeBusinessLogic.js +2 -40
  51. package/src/commands/disable-requirement.js +60 -0
  52. package/src/commands/disable-spec.js +60 -0
  53. package/src/commands/enable-requirement.js +60 -0
  54. package/src/commands/enable-spec.js +60 -0
  55. package/src/commands/registry.js +1 -6
  56. package/src/commands/requirements.js +8 -2
  57. package/src/ide-integration/applescript-manager.cjs +9 -24
  58. package/src/ide-integration/cdp-handlers/chat-reader.js +44 -0
  59. package/src/ide-integration/cdp-handlers/connection-handler.js +88 -0
  60. package/src/ide-integration/cdp-handlers/continuation-handler.js +314 -0
  61. package/src/ide-integration/cdp-handlers/message-submitter.js +75 -0
  62. package/src/ide-integration/cdp-handlers/text-sender.js +138 -0
  63. package/src/ide-integration/cdp-manager.js +28 -573
  64. package/src/ide-integration/claude-code-cli-manager.cjs +48 -12
  65. package/src/ide-integration/ide-openers/claude-opener.js +171 -0
  66. package/src/ide-integration/ide-openers/cursor-opener.js +53 -0
  67. package/src/ide-integration/ide-openers/other-ides-opener.js +230 -0
  68. package/src/ide-integration/ide-openers/vscode-opener.js +147 -0
  69. package/src/ide-integration/macos-ide-manager.js +20 -582
  70. package/src/ide-integration/macos-quota-checker.js +164 -0
  71. package/src/ide-integration/macos-text-sender.js +19 -38
  72. package/src/ide-integration/provider-manager.cjs +52 -7
  73. package/src/index.cjs +6 -0
  74. package/src/index.js +10 -0
  75. package/src/llm/direct-llm-manager.cjs +501 -0
  76. package/src/localization/translations/en-part1.js +363 -0
  77. package/src/localization/translations/en-part2.js +320 -0
  78. package/src/localization/translations/en.js +4 -687
  79. package/src/localization/translations/es-part1.js +363 -0
  80. package/src/localization/translations/es-part2.js +320 -0
  81. package/src/localization/translations/es.js +4 -688
  82. package/src/models/file-analysis-collection.js +139 -0
  83. package/src/models/file-analysis-metrics.js +50 -0
  84. package/src/models/file-analysis.js +15 -262
  85. package/src/models/plan-manager.js +410 -0
  86. package/src/models/refactoring-models.js +380 -0
  87. package/src/models/refactoring-plan-refactored.js +81 -0
  88. package/src/models/refactoring-plan.js +2 -663
  89. package/src/monitoring/alert-system.js +4 -45
  90. package/src/monitoring/continuous-scan-notifications.js +37 -191
  91. package/src/monitoring/notification-handlers/base-handler.js +58 -0
  92. package/src/monitoring/notification-handlers/error-handler.js +36 -0
  93. package/src/monitoring/notification-handlers/index.js +21 -0
  94. package/src/monitoring/notification-handlers/new-violation-handler.js +91 -0
  95. package/src/monitoring/notification-handlers/progress-handler.js +48 -0
  96. package/src/monitoring/notification-handlers/resolved-violation-handler.js +54 -0
  97. package/src/monitoring/notification-handlers/threshold-handler.js +36 -0
  98. package/src/provider-registry.js +8 -0
  99. package/src/refactoring/boundary/boundary-detector-refactored.js +58 -0
  100. package/src/refactoring/boundary/boundary-detector.js +26 -596
  101. package/src/refactoring/boundary/detectors/boundary-analyzers.js +281 -0
  102. package/src/refactoring/boundary/detectors/boundary-core.js +167 -0
  103. package/src/refactoring/boundary/detectors/class-detector.js +247 -0
  104. package/src/refactoring/boundary/detectors/config-detector.js +270 -0
  105. package/src/refactoring/boundary/detectors/constant-detector.js +269 -0
  106. package/src/refactoring/boundary/detectors/function-detector.js +248 -0
  107. package/src/refactoring/boundary/detectors/module-detector.js +249 -0
  108. package/src/refactoring/boundary/detectors/object-detector.js +247 -0
  109. package/src/refactoring/boundary/detectors/type-detectors.js +338 -0
  110. package/src/refactoring/boundary/detectors/utility-detector.js +270 -0
  111. package/src/refactoring/circular-dependency-resolver-original.js +16 -76
  112. package/src/refactoring/code-mover-refactored.js +309 -0
  113. package/src/refactoring/code-mover.js +48 -355
  114. package/src/refactoring/execution-status.js +18 -0
  115. package/src/refactoring/execution-strategies.js +172 -0
  116. package/src/refactoring/file-splitter-core.js +568 -0
  117. package/src/refactoring/file-splitter-types.js +136 -0
  118. package/src/refactoring/file-splitter.js +2 -682
  119. package/src/refactoring/functionality-validator.js +11 -51
  120. package/src/refactoring/import-manager-refactored.js +385 -0
  121. package/src/refactoring/import-manager.js +112 -487
  122. package/src/refactoring/import-models.js +189 -0
  123. package/src/refactoring/import-parser.js +306 -0
  124. package/src/refactoring/move-executor.js +431 -0
  125. package/src/refactoring/move-utils.js +368 -0
  126. package/src/refactoring/operation-executor.js +76 -0
  127. package/src/refactoring/plan-creator.js +36 -0
  128. package/src/refactoring/plan-executor.js +143 -0
  129. package/src/refactoring/plan-validator.js +68 -0
  130. package/src/refactoring/refactoring-executor-result.js +70 -0
  131. package/src/refactoring/refactoring-executor.js +34 -569
  132. package/src/refactoring/refactoring-operation.js +94 -0
  133. package/src/refactoring/refactoring-plan.js +69 -0
  134. package/src/refactoring/refactoring-rollback.js +22 -527
  135. package/src/refactoring/rollback-handlers/RollbackExecutor.js +107 -0
  136. package/src/refactoring/rollback-handlers/RollbackManager.js +265 -0
  137. package/src/refactoring/rollback-handlers/RollbackOperation.js +105 -0
  138. package/src/refactoring/rollback-handlers/RollbackResult.js +109 -0
  139. package/src/refactoring/rollback-handlers/RollbackStatistics.js +77 -0
  140. package/src/refactoring/test-validator.js +32 -448
  141. package/src/refactoring/validation/baseline-runner.js +71 -0
  142. package/src/refactoring/validation/report-generator.js +136 -0
  143. package/src/refactoring/validation/result-comparator.js +92 -0
  144. package/src/refactoring/validation/test-suite.js +59 -0
  145. package/src/refactoring/validation/test-validation-result.js +83 -0
  146. package/src/refactoring/validation/validation-runner.js +95 -0
  147. package/src/refactoring/validation/validation-status.js +18 -0
  148. package/src/rui/commands/AgentCommandParser.js +60 -369
  149. package/src/rui/commands/AgentResponseFormatter.js +7 -47
  150. package/src/rui/commands/parsers/CommandMapper.js +148 -0
  151. package/src/rui/commands/parsers/CommandValidator.js +228 -0
  152. package/src/rui/commands/parsers/ComponentExtractor.js +100 -0
  153. package/src/rui/commands/parsers/TokenParser.js +69 -0
  154. package/src/rui/commands/parsers/tokenizer.js +153 -0
  155. package/src/utils/current-requirement-operations.js +50 -1
  156. package/src/utils/report-generator.js +18 -514
  157. package/src/utils/report-generators/analysis-generator.js +115 -0
  158. package/src/utils/report-generators/base-generator.js +141 -0
  159. package/src/utils/report-generators/compliance-generator.js +41 -0
  160. package/src/utils/report-generators/format-handlers.js +185 -0
  161. package/src/utils/report-generators/refactoring-generator.js +46 -0
  162. package/src/utils/report-generators/validation-generator.js +63 -0
  163. package/src/utils/requirement-enable-disable.js +265 -0
  164. package/src/utils/requirement-helpers/requirement-file-ops.js +69 -1
  165. package/src/utils/requirement-helpers/requirement-mover.js +88 -1
  166. package/src/utils/requirement-helpers.js +5 -2
  167. package/src/utils/smoke-test-cli.js +45 -8
  168. package/src/utils/specification-enable-disable.js +122 -0
  169. package/src/utils/specification-helpers.js +30 -4
  170. package/src/utils/specification-migration.js +5 -5
  171. package/src/utils/test-comparator.js +118 -0
  172. package/src/utils/test-config.js +54 -0
  173. package/src/utils/test-executor.js +133 -0
  174. package/src/utils/test-parser.js +215 -0
  175. package/src/utils/test-runner-baseline.js +63 -0
  176. package/src/utils/test-runner-core.js +98 -0
  177. package/src/utils/test-runner-report.js +39 -0
  178. package/src/utils/test-runner-validation.js +71 -0
  179. package/src/utils/test-runner.js +11 -535
  180. package/src/validation/comparison-analyzer.js +333 -0
  181. package/src/validation/compliance-reporter-new.js +282 -0
  182. package/src/validation/compliance-reporter-refactored.js +344 -0
  183. package/src/validation/compliance-reporter.js +278 -591
  184. package/src/validation/compliance-utils.js +278 -0
  185. package/src/validation/html-generator.js +446 -0
  186. package/src/validation/metrics/category-calculator.js +137 -0
  187. package/src/validation/metrics/metrics-helpers.js +155 -0
  188. package/src/validation/metrics/overview-calculator.js +85 -0
  189. package/src/validation/metrics/overview-metrics.js +41 -0
  190. package/src/validation/metrics/quality-calculator.js +166 -0
  191. package/src/validation/metrics/size-calculator.js +69 -0
  192. package/src/validation/metrics-calculator.js +27 -551
@@ -0,0 +1,124 @@
1
+ /**
2
+ * File Configuration Loader Module
3
+ *
4
+ * Handles loading and saving configuration files.
5
+ * Follows constitutional requirements: <555 lines, test-first approach.
6
+ */
7
+
8
+ const fs = require('fs').promises;
9
+ const path = require('path');
10
+
11
+ /**
12
+ * Load configuration from override file
13
+ * @param {string} overrideFile - Path to override file
14
+ * @param {Object} logger - Logger instance
15
+ * @returns {Promise<Object>} - Override configuration
16
+ */
17
+ async function loadOverrideFile(overrideFile, logger) {
18
+ try {
19
+ const exists = await fs.access(overrideFile).then(() => true).catch(() => false);
20
+ if (!exists) return {};
21
+
22
+ const content = await fs.readFile(overrideFile, 'utf8');
23
+ const config = JSON.parse(content);
24
+
25
+ if (logger) {
26
+ logger.debug('Loaded override file configuration', {
27
+ file: overrideFile,
28
+ keys: Object.keys(config)
29
+ });
30
+ }
31
+
32
+ return config;
33
+ } catch (error) {
34
+ if (logger) {
35
+ logger.warn('Failed to load override file', {
36
+ file: overrideFile,
37
+ error: error.message
38
+ });
39
+ }
40
+ return {};
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Load configuration from file
46
+ * @param {string} filePath - Path to config file
47
+ * @param {Object} logger - Logger instance
48
+ * @returns {Promise<Object>} - File configuration
49
+ */
50
+ async function loadConfigFile(filePath, logger) {
51
+ try {
52
+ const content = await fs.readFile(filePath, 'utf8');
53
+ const config = JSON.parse(content);
54
+
55
+ if (logger) {
56
+ logger.debug('Loaded config file', {
57
+ file: filePath,
58
+ keys: Object.keys(config)
59
+ });
60
+ }
61
+
62
+ return config;
63
+ } catch (error) {
64
+ if (logger) {
65
+ logger.warn('Failed to load config file', {
66
+ file: filePath,
67
+ error: error.message
68
+ });
69
+ }
70
+ return {};
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Save configuration to file
76
+ * @param {string} filePath - Path to save file
77
+ * @param {Object} config - Configuration to save
78
+ * @param {Object} logger - Logger instance
79
+ * @returns {Promise<Object>} - Save result
80
+ */
81
+ async function saveConfigFile(filePath, config, logger) {
82
+ const result = {
83
+ success: false,
84
+ error: null,
85
+ filePath
86
+ };
87
+
88
+ try {
89
+ // Ensure directory exists
90
+ const dir = path.dirname(filePath);
91
+ await fs.mkdir(dir, { recursive: true });
92
+
93
+ // Save configuration
94
+ const content = JSON.stringify(config, null, 2);
95
+ await fs.writeFile(filePath, content, 'utf8');
96
+
97
+ result.success = true;
98
+
99
+ if (logger) {
100
+ logger.info('Configuration saved successfully', {
101
+ file: filePath,
102
+ keys: Object.keys(config)
103
+ });
104
+ }
105
+
106
+ } catch (error) {
107
+ result.error = error.message;
108
+
109
+ if (logger) {
110
+ logger.error('Failed to save configuration', {
111
+ file: filePath,
112
+ error: error.message
113
+ });
114
+ }
115
+ }
116
+
117
+ return result;
118
+ }
119
+
120
+ module.exports = {
121
+ loadOverrideFile,
122
+ loadConfigFile,
123
+ saveConfigFile
124
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Type Converters Module
3
+ *
4
+ * Provides type conversion functions for configuration values.
5
+ * Follows constitutional requirements: <555 lines, test-first approach.
6
+ */
7
+
8
+ /**
9
+ * Get type converters
10
+ * @returns {Object} - Type conversion functions
11
+ */
12
+ function getTypeConverters() {
13
+ return {
14
+ 'boolean': (value) => {
15
+ if (typeof value === 'boolean') return value;
16
+ const str = String(value).toLowerCase();
17
+ return str === 'true' || str === '1' || str === 'yes' || str === 'on';
18
+ },
19
+ 'number': (value) => {
20
+ const num = Number(value);
21
+ return isNaN(num) ? 0 : num;
22
+ },
23
+ 'string': (value) => String(value),
24
+ 'array': (value) => {
25
+ if (Array.isArray(value)) return value;
26
+ const str = String(value);
27
+ try {
28
+ return JSON.parse(str);
29
+ } catch {
30
+ return str.split(',').map(s => s.trim()).filter(s => s);
31
+ }
32
+ },
33
+ 'object': (value) => {
34
+ if (typeof value === 'object' && value !== null) return value;
35
+ const str = String(value);
36
+ try {
37
+ return JSON.parse(str);
38
+ } catch {
39
+ return {};
40
+ }
41
+ }
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Get variable type from default value
47
+ * @param {*} defaultValue - Default value
48
+ * @returns {string} - Variable type
49
+ */
50
+ function getVariableType(defaultValue) {
51
+ if (typeof defaultValue === 'boolean') return 'boolean';
52
+ if (typeof defaultValue === 'number') return 'number';
53
+ if (Array.isArray(defaultValue)) return 'array';
54
+ if (typeof defaultValue === 'object' && defaultValue !== null) return 'object';
55
+ return 'string';
56
+ }
57
+
58
+ module.exports = {
59
+ getTypeConverters,
60
+ getVariableType
61
+ };
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Variable Mappings Module
3
+ *
4
+ * Defines environment variable to configuration path mappings.
5
+ * Follows constitutional requirements: <555 lines, test-first approach.
6
+ */
7
+
8
+ /**
9
+ * Get default variable mappings
10
+ * @returns {Object} - Variable mappings
11
+ */
12
+ function getDefaultVariableMappings() {
13
+ return {
14
+ // Installation settings
15
+ 'INSTALL_TIMEOUT': 'installation.timeout',
16
+ 'MAX_CONCURRENT_INSTALLATIONS': 'installation.maxConcurrent',
17
+ 'RETRY_ATTEMPTS': 'installation.retryAttempts',
18
+ 'RETRY_DELAY': 'installation.retryDelay',
19
+ 'AUTO_ELEVATE': 'installation.autoElevate',
20
+
21
+ // Logging settings
22
+ 'LOG_LEVEL': 'logging.level',
23
+ 'LOG_FILE': 'logging.file',
24
+ 'LOG_FORMAT': 'logging.format',
25
+ 'VERBOSE_LOGGING': 'logging.verbose',
26
+
27
+ // Cache settings
28
+ 'CACHE_DIR': 'cache.directory',
29
+ 'CACHE_SIZE': 'cache.maxSize',
30
+ 'CACHE_TTL': 'cache.ttl',
31
+
32
+ // Network settings
33
+ 'HTTP_TIMEOUT': 'network.timeout',
34
+ 'HTTP_PROXY': 'network.proxy',
35
+ 'HTTP_USER_AGENT': 'network.userAgent',
36
+ 'RATE_LIMIT_DELAY': 'network.rateLimitDelay',
37
+
38
+ // Security settings
39
+ 'SECURITY_STRICT_MODE': 'security.strictMode',
40
+ 'SECURITY_MAX_FILE_SIZE': 'security.maxFileSize',
41
+ 'SECURITY_ALLOWED_EXTENSIONS': 'security.allowedExtensions',
42
+
43
+ // Performance settings
44
+ 'PERFORMANCE_MONITORING': 'performance.monitoring',
45
+ 'PERFORMANCE_METRICS_FILE': 'performance.metricsFile',
46
+ 'PERFORMANCE_FLUSH_INTERVAL': 'performance.flushInterval',
47
+
48
+ // Agent settings
49
+ 'DEFAULT_AGENTS_FILE': 'agents.defaultFile',
50
+ 'AGENT_DISCOVERY_ENABLED': 'agents.discoveryEnabled',
51
+ 'AGENT_AUTO_UPDATE': 'agents.autoUpdate'
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Get variable descriptions
57
+ * @returns {Object} - Variable descriptions
58
+ */
59
+ function getVariableDescriptions() {
60
+ return {
61
+ 'INSTALL_TIMEOUT': 'Installation timeout in milliseconds',
62
+ 'MAX_CONCURRENT_INSTALLATIONS': 'Maximum concurrent installations',
63
+ 'RETRY_ATTEMPTS': 'Number of retry attempts for failed operations',
64
+ 'RETRY_DELAY': 'Delay between retry attempts in milliseconds',
65
+ 'AUTO_ELEVATE': 'Automatically request administrator privileges',
66
+ 'LOG_LEVEL': 'Logging level (error, warn, info, debug)',
67
+ 'LOG_FILE': 'Path to log file',
68
+ 'LOG_FORMAT': 'Log format (json, text)',
69
+ 'VERBOSE_LOGGING': 'Enable verbose logging',
70
+ 'CACHE_DIR': 'Cache directory path',
71
+ 'CACHE_SIZE': 'Maximum cache size in bytes',
72
+ 'CACHE_TTL': 'Cache time-to-live in milliseconds',
73
+ 'HTTP_TIMEOUT': 'HTTP request timeout in milliseconds',
74
+ 'HTTP_PROXY': 'HTTP proxy URL',
75
+ 'HTTP_USER_AGENT': 'HTTP user agent string',
76
+ 'RATE_LIMIT_DELAY': 'Delay for rate limiting in milliseconds',
77
+ 'SECURITY_STRICT_MODE': 'Enable strict security mode',
78
+ 'SECURITY_MAX_FILE_SIZE': 'Maximum allowed file size in bytes',
79
+ 'SECURITY_ALLOWED_EXTENSIONS': 'Comma-separated list of allowed file extensions',
80
+ 'PERFORMANCE_MONITORING': 'Enable performance monitoring',
81
+ 'PERFORMANCE_METRICS_FILE': 'Path to performance metrics file',
82
+ 'PERFORMANCE_FLUSH_INTERVAL': 'Performance metrics flush interval in milliseconds',
83
+ 'DEFAULT_AGENTS_FILE': 'Path to default agents configuration file',
84
+ 'AGENT_DISCOVERY_ENABLED': 'Enable automatic agent discovery',
85
+ 'AGENT_AUTO_UPDATE': 'Enable automatic agent updates'
86
+ };
87
+ }
88
+
89
+ module.exports = {
90
+ getDefaultVariableMappings,
91
+ getVariableDescriptions
92
+ };
@@ -0,0 +1,272 @@
1
+ /**
2
+ * Agent Discovery Service
3
+ *
4
+ * Discovers and manages new agent CLI tools.
5
+ * Follows constitutional requirements: <555 lines, test-first approach.
6
+ */
7
+
8
+ const fs = require('fs').promises;
9
+ const path = require('path');
10
+ const DiscoveryScanner = require('./discovery-scanner');
11
+ const { DiscoveryResult } = require('./discovery-results');
12
+
13
+ /**
14
+ * Agent Discovery Service class
15
+ */
16
+ class AgentDiscoveryService {
17
+ /**
18
+ * Create discovery service instance
19
+ * @param {Object} options - Service options
20
+ */
21
+ constructor(options = {}) {
22
+ this.configManager = options.configManager || null;
23
+ this.logger = options.logger || null;
24
+ this.fileManager = options.fileManager || null;
25
+ this.discoveryPaths = options.discoveryPaths || ['/usr/local/bin', '/opt/bin', '/usr/bin/local/bin', '/snap/bin'];
26
+ this.timeout = options.timeout || 30000;
27
+ this.maxConcurrency = options.maxConcurrency || 3;
28
+ this.discoveryHistoryFile = options.discoveryHistoryFile || './discovery-history.json';
29
+ this.discoveryStatusFile = options.discoveryStatusFile || './discovery-status.json';
30
+
31
+ // Create scanner instance
32
+ this.scanner = new DiscoveryScanner({
33
+ discoveryPaths: this.discoveryPaths,
34
+ timeout: this.timeout,
35
+ maxConcurrency: this.maxConcurrency,
36
+ logger: this.logger
37
+ });
38
+ }
39
+
40
+ /**
41
+ * Discover agents from configured paths
42
+ * @returns {Promise<Object>} - Discovery result
43
+ */
44
+ async discoverAgents() {
45
+ const startTime = Date.now();
46
+
47
+ try {
48
+ if (this.logger) {
49
+ await this.logger.info('Starting agent discovery', {
50
+ paths: this.discoveryPaths,
51
+ timeout: this.timeout
52
+ });
53
+ }
54
+
55
+ // Run discovery scan
56
+ const result = await this.scanner.scanAllPaths();
57
+
58
+ // Save discovery history
59
+ await this.saveDiscoveryHistory(result);
60
+
61
+ // Update discovery status
62
+ await this.updateDiscoveryStatus(result);
63
+
64
+ const duration = Date.now() - startTime;
65
+
66
+ if (this.logger) {
67
+ await this.logger.info('Agent discovery completed', {
68
+ duration,
69
+ ...result.getSummary()
70
+ });
71
+ }
72
+
73
+ return {
74
+ success: true,
75
+ result: result.toJSON(),
76
+ duration,
77
+ timestamp: new Date().toISOString()
78
+ };
79
+
80
+ } catch (error) {
81
+ const duration = Date.now() - startTime;
82
+
83
+ if (this.logger) {
84
+ await this.logger.error('Agent discovery failed', {
85
+ error: error.message,
86
+ duration
87
+ });
88
+ }
89
+
90
+ return {
91
+ success: false,
92
+ error: error.message,
93
+ duration,
94
+ timestamp: new Date().toISOString()
95
+ };
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Get discovery history
101
+ * @param {number} limit - Maximum number of entries
102
+ * @returns {Promise<Array>} - Discovery history
103
+ */
104
+ async getDiscoveryHistory(limit = 50) {
105
+ try {
106
+ const data = await fs.readFile(this.discoveryHistoryFile, 'utf8');
107
+ const history = JSON.parse(data);
108
+ return Array.isArray(history) ? history.slice(-limit) : [];
109
+ } catch (error) {
110
+ return [];
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Get current discovery status
116
+ * @returns {Promise<Object>} - Current status
117
+ */
118
+ async getDiscoveryStatus() {
119
+ try {
120
+ const data = await fs.readFile(this.discoveryStatusFile, 'utf8');
121
+ return JSON.parse(data);
122
+ } catch (error) {
123
+ return {
124
+ status: 'idle',
125
+ lastDiscovery: null,
126
+ totalDiscovered: 0
127
+ };
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Save discovery history
133
+ * @param {DiscoveryResult} result - Discovery result
134
+ * @returns {Promise<void>}
135
+ */
136
+ async saveDiscoveryHistory(result) {
137
+ try {
138
+ const history = await this.getDiscoveryHistory(1000); // Get more for internal use
139
+ const newEntry = {
140
+ timestamp: new Date().toISOString(),
141
+ sessionId: result.sessionId,
142
+ summary: result.getSummary()
143
+ };
144
+
145
+ history.push(newEntry);
146
+
147
+ // Keep only last 100 entries
148
+ const trimmedHistory = history.slice(-100);
149
+
150
+ await fs.writeFile(
151
+ this.discoveryHistoryFile,
152
+ JSON.stringify(trimmedHistory, null, 2),
153
+ 'utf8'
154
+ );
155
+ } catch (error) {
156
+ if (this.logger) {
157
+ await this.logger.warn('Failed to save discovery history', {
158
+ error: error.message
159
+ });
160
+ }
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Update discovery status
166
+ * @param {DiscoveryResult} result - Discovery result
167
+ * @returns {Promise<void>}
168
+ */
169
+ async updateDiscoveryStatus(result) {
170
+ try {
171
+ const status = {
172
+ status: 'completed',
173
+ lastDiscovery: new Date().toISOString(),
174
+ sessionId: result.sessionId,
175
+ totalDiscovered: result.agents.length,
176
+ summary: result.getSummary()
177
+ };
178
+
179
+ await fs.writeFile(
180
+ this.discoveryStatusFile,
181
+ JSON.stringify(status, null, 2),
182
+ 'utf8'
183
+ );
184
+ } catch (error) {
185
+ if (this.logger) {
186
+ await this.logger.warn('Failed to update discovery status', {
187
+ error: error.message
188
+ });
189
+ }
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Clear discovery history
195
+ * @returns {Promise<void>}
196
+ */
197
+ async clearDiscoveryHistory() {
198
+ try {
199
+ await fs.writeFile(this.discoveryHistoryFile, '[]', 'utf8');
200
+
201
+ if (this.logger) {
202
+ await this.logger.info('Discovery history cleared');
203
+ }
204
+ } catch (error) {
205
+ if (this.logger) {
206
+ await this.logger.error('Failed to clear discovery history', {
207
+ error: error.message
208
+ });
209
+ }
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Get service information
215
+ * @returns {Object} - Service info
216
+ */
217
+ getServiceInfo() {
218
+ return {
219
+ discoveryPaths: this.discoveryPaths,
220
+ timeout: this.timeout,
221
+ maxConcurrency: this.maxConcurrency,
222
+ historyFile: this.discoveryHistoryFile,
223
+ statusFile: this.discoveryStatusFile,
224
+ features: [
225
+ 'filesystem scanning',
226
+ 'agent verification',
227
+ 'confidence scoring',
228
+ 'discovery history',
229
+ 'status tracking'
230
+ ],
231
+ limitations: [
232
+ 'limited to configured paths',
233
+ 'depends on file system permissions',
234
+ 'confidence scoring based on heuristics'
235
+ ]
236
+ };
237
+ }
238
+
239
+ /**
240
+ * Create discovery service with default configuration
241
+ * @param {Object} config - Configuration overrides
242
+ * @returns {AgentDiscoveryService} - Service instance
243
+ */
244
+ static createDefault(config = {}) {
245
+ return new AgentDiscoveryService({
246
+ discoveryPaths: ['/usr/local/bin', '/opt/bin', '/usr/bin/local/bin', '/snap/bin'],
247
+ timeout: 30000,
248
+ maxConcurrency: 3,
249
+ discoveryHistoryFile: './discovery-history.json',
250
+ discoveryStatusFile: './discovery-status.json',
251
+ ...config
252
+ });
253
+ }
254
+
255
+ /**
256
+ * Create discovery service for development
257
+ * @param {Object} config - Configuration overrides
258
+ * @returns {AgentDiscoveryService} - Development service instance
259
+ */
260
+ static createForDevelopment(config = {}) {
261
+ return new AgentDiscoveryService({
262
+ discoveryPaths: ['./test-agents', '/usr/local/bin'],
263
+ timeout: 10000,
264
+ maxConcurrency: 2,
265
+ discoveryHistoryFile: './dev-discovery-history.json',
266
+ discoveryStatusFile: './dev-discovery-status.json',
267
+ ...config
268
+ });
269
+ }
270
+ }
271
+
272
+ module.exports = AgentDiscoveryService;