vibecodingmachine-core 2026.2.20-438 → 2026.2.26-1642

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 (202) hide show
  1. package/README.md +240 -0
  2. package/package.json +10 -2
  3. package/src/agents/Agent.js +300 -0
  4. package/src/agents/AgentAdditionService.js +311 -0
  5. package/src/agents/AgentCheckService.js +690 -0
  6. package/src/agents/AgentInstallationService.js +140 -0
  7. package/src/agents/AgentSetupService.js +467 -0
  8. package/src/agents/AgentStatus.js +183 -0
  9. package/src/agents/AgentVerificationService.js +634 -0
  10. package/src/agents/ConfigurationSchemaValidator.js +543 -0
  11. package/src/agents/EnvironmentConfigurationManager.js +602 -0
  12. package/src/agents/InstallationErrorHandler.js +372 -0
  13. package/src/agents/InstallationLog.js +363 -0
  14. package/src/agents/InstallationMethod.js +510 -0
  15. package/src/agents/InstallationOrchestrator.js +352 -0
  16. package/src/agents/InstallationProgressReporter.js +372 -0
  17. package/src/agents/InstallationRetryManager.js +322 -0
  18. package/src/agents/InstallationType.js +254 -0
  19. package/src/agents/OperationTypes.js +310 -0
  20. package/src/agents/PerformanceMetricsCollector.js +493 -0
  21. package/src/agents/SecurityValidationService.js +534 -0
  22. package/src/agents/VerificationTest.js +354 -0
  23. package/src/agents/VerificationType.js +226 -0
  24. package/src/agents/WindowsPermissionHandler.js +518 -0
  25. package/src/agents/config/AgentConfigManager.js +393 -0
  26. package/src/agents/config/AgentDefaultsRegistry.js +373 -0
  27. package/src/agents/config/ConfigValidator.js +281 -0
  28. package/src/agents/discovery/AgentDiscoveryService.js +707 -0
  29. package/src/agents/logging/AgentLogger.js +511 -0
  30. package/src/agents/status/AgentStatusManager.js +481 -0
  31. package/src/agents/storage/FileManager.js +454 -0
  32. package/src/agents/verification/AgentCommunicationTester.js +474 -0
  33. package/src/agents/verification/BaseVerifier.js +430 -0
  34. package/src/agents/verification/CommandVerifier.js +480 -0
  35. package/src/agents/verification/FileOperationVerifier.js +453 -0
  36. package/src/agents/verification/ResultAnalyzer.js +707 -0
  37. package/src/agents/verification/TestRequirementManager.js +495 -0
  38. package/src/agents/verification/VerificationRunner.js +433 -0
  39. package/src/agents/windows/BaseWindowsInstaller.js +441 -0
  40. package/src/agents/windows/ChocolateyInstaller.js +509 -0
  41. package/src/agents/windows/DirectInstaller.js +443 -0
  42. package/src/agents/windows/InstallerFactory.js +391 -0
  43. package/src/agents/windows/NpmInstaller.js +505 -0
  44. package/src/agents/windows/PowerShellInstaller.js +458 -0
  45. package/src/agents/windows/WinGetInstaller.js +390 -0
  46. package/src/analysis/analysis-reporter.js +132 -0
  47. package/src/analysis/boundary-detector.js +712 -0
  48. package/src/analysis/categorizer.js +340 -0
  49. package/src/analysis/codebase-scanner.js +384 -0
  50. package/src/analysis/line-counter.js +513 -0
  51. package/src/analysis/priority-calculator.js +679 -0
  52. package/src/analysis/report/analysis-report.js +250 -0
  53. package/src/analysis/report/package-analyzer.js +278 -0
  54. package/src/analysis/report/recommendation-generator.js +382 -0
  55. package/src/analysis/report/statistics-generator.js +515 -0
  56. package/src/analysis/reports/analysis-report-model.js +101 -0
  57. package/src/analysis/reports/recommendation-generator.js +283 -0
  58. package/src/analysis/reports/report-generators.js +191 -0
  59. package/src/analysis/reports/statistics-calculator.js +231 -0
  60. package/src/analysis/reports/trend-analyzer.js +219 -0
  61. package/src/analysis/strategy-generator.js +814 -0
  62. package/src/auto-mode/AutoModeBusinessLogic.js +836 -0
  63. package/src/config/refactoring-config.js +307 -0
  64. package/src/health-tracking/json-storage.js +38 -2
  65. package/src/ide-integration/applescript-manager-core.js +233 -0
  66. package/src/ide-integration/applescript-manager.cjs +357 -28
  67. package/src/ide-integration/applescript-manager.js +89 -3599
  68. package/src/ide-integration/cdp-manager.js +306 -0
  69. package/src/ide-integration/claude-code-cli-manager.cjs +1 -1
  70. package/src/ide-integration/continuation-handler.js +337 -0
  71. package/src/ide-integration/ide-status-checker.js +292 -0
  72. package/src/ide-integration/macos-ide-manager.js +627 -0
  73. package/src/ide-integration/macos-text-sender.js +528 -0
  74. package/src/ide-integration/response-reader.js +548 -0
  75. package/src/ide-integration/windows-automation-manager.js +121 -0
  76. package/src/ide-integration/windows-ide-manager.js +373 -0
  77. package/src/index.cjs +25 -3
  78. package/src/index.js +15 -1
  79. package/src/llm/direct-llm-manager.cjs +90 -2
  80. package/src/models/compliance-report.js +538 -0
  81. package/src/models/file-analysis.js +681 -0
  82. package/src/models/refactoring-plan.js +770 -0
  83. package/src/monitoring/alert-system.js +834 -0
  84. package/src/monitoring/compliance-progress-tracker.js +437 -0
  85. package/src/monitoring/continuous-scan-notifications.js +661 -0
  86. package/src/monitoring/continuous-scanner.js +279 -0
  87. package/src/monitoring/file-monitor/file-analyzer.js +262 -0
  88. package/src/monitoring/file-monitor/file-monitor.js +237 -0
  89. package/src/monitoring/file-monitor/watcher.js +194 -0
  90. package/src/monitoring/file-monitor.js +17 -0
  91. package/src/monitoring/notification-manager.js +437 -0
  92. package/src/monitoring/scanner-core.js +368 -0
  93. package/src/monitoring/scanner-events.js +214 -0
  94. package/src/monitoring/violation-notification-system.js +515 -0
  95. package/src/refactoring/boundaries/cohesion-analyzer.js +316 -0
  96. package/src/refactoring/boundaries/extraction-result.js +285 -0
  97. package/src/refactoring/boundaries/extraction-strategies.js +392 -0
  98. package/src/refactoring/boundaries/module-boundary.js +209 -0
  99. package/src/refactoring/boundary/boundary-detector.js +741 -0
  100. package/src/refactoring/boundary/boundary-types.js +405 -0
  101. package/src/refactoring/boundary/extraction-strategies.js +554 -0
  102. package/src/refactoring/boundary-extraction-result.js +77 -0
  103. package/src/refactoring/boundary-extraction-strategies.js +330 -0
  104. package/src/refactoring/boundary-extractor.js +384 -0
  105. package/src/refactoring/boundary-types.js +46 -0
  106. package/src/refactoring/circular/circular-dependency.js +88 -0
  107. package/src/refactoring/circular/cycle-detection.js +147 -0
  108. package/src/refactoring/circular/dependency-node.js +82 -0
  109. package/src/refactoring/circular/dependency-result.js +107 -0
  110. package/src/refactoring/circular/dependency-types.js +58 -0
  111. package/src/refactoring/circular/graph-builder.js +213 -0
  112. package/src/refactoring/circular/resolution-strategy.js +72 -0
  113. package/src/refactoring/circular/strategy-generator.js +229 -0
  114. package/src/refactoring/circular-dependency-resolver-original.js +809 -0
  115. package/src/refactoring/circular-dependency-resolver.js +200 -0
  116. package/src/refactoring/code-mover.js +761 -0
  117. package/src/refactoring/file-splitter.js +696 -0
  118. package/src/refactoring/functionality-validator.js +816 -0
  119. package/src/refactoring/import-manager.js +774 -0
  120. package/src/refactoring/module-boundary.js +107 -0
  121. package/src/refactoring/refactoring-executor.js +672 -0
  122. package/src/refactoring/refactoring-rollback.js +614 -0
  123. package/src/refactoring/test-validator.js +631 -0
  124. package/src/requirement-management/default-requirement-manager.js +321 -0
  125. package/src/requirement-management/requirement-file-parser.js +159 -0
  126. package/src/requirement-management/requirement-sequencer.js +221 -0
  127. package/src/rui/commands/AgentCommandParser.js +600 -0
  128. package/src/rui/commands/AgentCommands.js +487 -0
  129. package/src/rui/commands/AgentResponseFormatter.js +832 -0
  130. package/src/scripts/verify-full-compliance.js +269 -0
  131. package/src/sync/sync-engine-core.js +1 -0
  132. package/src/sync/sync-engine-remote-handlers.js +135 -0
  133. package/src/task-generation/automated-task-generator.js +351 -0
  134. package/src/task-generation/prioritizer.js +287 -0
  135. package/src/task-generation/task-list-updater.js +215 -0
  136. package/src/task-generation/task-management-integration.js +480 -0
  137. package/src/task-generation/task-manager-integration.js +270 -0
  138. package/src/task-generation/violation-task-generator.js +474 -0
  139. package/src/task-management/continuous-scan-integration.js +342 -0
  140. package/src/timeout-management/index.js +12 -3
  141. package/src/timeout-management/response-time-tracker.js +167 -0
  142. package/src/timeout-management/timeout-calculator.js +159 -0
  143. package/src/timeout-management/timeout-config-manager.js +172 -0
  144. package/src/utils/ast-analyzer.js +417 -0
  145. package/src/utils/current-requirement-manager.js +276 -0
  146. package/src/utils/current-requirement-operations.js +472 -0
  147. package/src/utils/dependency-mapper.js +456 -0
  148. package/src/utils/download-with-progress.js +4 -2
  149. package/src/utils/electron-update-checker.js +4 -1
  150. package/src/utils/file-size-analyzer.js +272 -0
  151. package/src/utils/import-updater.js +280 -0
  152. package/src/utils/refactoring-tools.js +512 -0
  153. package/src/utils/report-generator.js +569 -0
  154. package/src/utils/reports/report-analysis.js +218 -0
  155. package/src/utils/reports/report-types.js +55 -0
  156. package/src/utils/reports/summary-generators.js +102 -0
  157. package/src/utils/requirement-file-management.js +157 -0
  158. package/src/utils/requirement-helpers/requirement-file-ops.js +392 -0
  159. package/src/utils/requirement-helpers/requirement-mover.js +414 -0
  160. package/src/utils/requirement-helpers/requirement-parser.js +326 -0
  161. package/src/utils/requirement-helpers/requirement-status.js +320 -0
  162. package/src/utils/requirement-helpers-new.js +55 -0
  163. package/src/utils/requirement-helpers-refactored.js +367 -0
  164. package/src/utils/requirement-helpers.js +291 -1191
  165. package/src/utils/requirement-movement-operations.js +450 -0
  166. package/src/utils/requirement-movement.js +312 -0
  167. package/src/utils/requirement-parsing-helpers.js +56 -0
  168. package/src/utils/requirement-statistics.js +200 -0
  169. package/src/utils/requirement-text-utils.js +58 -0
  170. package/src/utils/rollback/rollback-handlers.js +125 -0
  171. package/src/utils/rollback/rollback-operation.js +63 -0
  172. package/src/utils/rollback/rollback-recorder.js +166 -0
  173. package/src/utils/rollback/rollback-state-manager.js +175 -0
  174. package/src/utils/rollback/rollback-types.js +33 -0
  175. package/src/utils/rollback/rollback-utils.js +110 -0
  176. package/src/utils/rollback-manager-original.js +569 -0
  177. package/src/utils/rollback-manager.js +202 -0
  178. package/src/utils/smoke-test-cli.js +362 -0
  179. package/src/utils/smoke-test-gui.js +351 -0
  180. package/src/utils/smoke-test-orchestrator.js +321 -0
  181. package/src/utils/smoke-test-runner.js +60 -0
  182. package/src/utils/smoke-test-web.js +347 -0
  183. package/src/utils/specification-helpers.js +39 -13
  184. package/src/utils/specification-migration.js +97 -0
  185. package/src/utils/test-runner.js +579 -0
  186. package/src/utils/validation-framework.js +518 -0
  187. package/src/validation/compliance-analyzer.js +197 -0
  188. package/src/validation/compliance-report-generator.js +343 -0
  189. package/src/validation/compliance-reporter.js +711 -0
  190. package/src/validation/compliance-rules.js +127 -0
  191. package/src/validation/constitution-validator-new.js +196 -0
  192. package/src/validation/constitution-validator.js +17 -0
  193. package/src/validation/file-validators.js +170 -0
  194. package/src/validation/line-limit/file-analyzer.js +201 -0
  195. package/src/validation/line-limit/line-limit-validator.js +208 -0
  196. package/src/validation/line-limit/validation-result.js +144 -0
  197. package/src/validation/line-limit-core.js +225 -0
  198. package/src/validation/line-limit-reporter.js +134 -0
  199. package/src/validation/line-limit-result.js +125 -0
  200. package/src/validation/line-limit-validator.js +41 -0
  201. package/src/validation/metrics-calculator.js +660 -0
  202. package/src/sync/sync-engine-backup.js +0 -559
package/README.md CHANGED
@@ -13,6 +13,13 @@ src/
13
13
  ├── ide-integration/ # CDP, AppleScript, quota detection
14
14
  ├── chat-management/ # Message handling, polling
15
15
  ├── autonomous-mode/ # Feature implementation logic
16
+ ├── validation/ # File size and constitutional compliance
17
+ ├── monitoring/ # Real-time file monitoring and alerts
18
+ ├── models/ # Data models for compliance reporting
19
+ ├── analysis/ # Code analysis and refactoring tools
20
+ ├── refactoring/ # Automated refactoring utilities
21
+ ├── agents/ # AI agent management and validation
22
+ ├── config/ # Configuration management
16
23
  └── utils/ # Shared utilities
17
24
  ```
18
25
 
@@ -21,8 +28,241 @@ src/
21
28
  ```javascript
22
29
  import { CDPManager } from '@vibecodingmachine/core/ide-integration/cdp-manager.js';
23
30
  import { ChatManager } from '@vibecodingmachine/core/chat-management/chat-manager.js';
31
+ import { LineLimitValidator } from '@vibecodingmachine/core/validation/line-limit-validator.js';
32
+ import { FileMonitor } from '@vibecodingmachine/core/monitoring/file-monitor.js';
33
+ ```
34
+
35
+ ## Refactoring Tools and Processes
36
+
37
+ ### 555-Line File Size Compliance
38
+
39
+ This package provides comprehensive tools for maintaining the constitutional requirement that no source file exceeds 555 lines.
40
+
41
+ #### Core Validation Tools
42
+
43
+ - **LineLimitValidator** (`src/validation/line-limit-validator.js`)
44
+ - Validates files against 555-line limit
45
+ - Provides configurable warning and critical thresholds
46
+ - Generates detailed compliance reports
47
+
48
+ - **ConstitutionValidator** (`src/validation/constitution-validator.js`)
49
+ - Validates constitutional compliance beyond file size
50
+ - Checks code structure, documentation, naming conventions
51
+ - Identifies circular dependencies and other issues
52
+
53
+ #### Monitoring and Alerting
54
+
55
+ - **FileMonitor** (`src/monitoring/file-monitor.js`)
56
+ - Real-time file system monitoring
57
+ - Automatic validation on file changes
58
+ - Configurable debouncing and filtering
59
+
60
+ - **AlertSystem** (`src/monitoring/alert-system.js`)
61
+ - Intelligent alerting for compliance issues
62
+ - Configurable severity levels and escalation
63
+ - Multiple notification channels
64
+
65
+ #### Reporting and Metrics
66
+
67
+ - **ComplianceReporter** (`src/validation/compliance-reporter.js`)
68
+ - Generates comprehensive compliance reports
69
+ - Multiple output formats (JSON, HTML, Markdown)
70
+ - Executive summaries and recommendations
71
+
72
+ - **MetricsCalculator** (`src/validation/metrics-calculator.js`)
73
+ - Calculates compliance metrics and trends
74
+ - Performance and quality indicators
75
+ - Risk assessment and technical debt analysis
76
+
77
+ #### Data Models
78
+
79
+ - **ComplianceReport** (`src/models/compliance-report.js`)
80
+ - Complete compliance data model
81
+ - File summaries and issue tracking
82
+ - Recommendation generation
83
+
84
+ ### Refactoring Utilities
85
+
86
+ #### Analysis Tools
87
+
88
+ - **CodebaseScanner** (`src/analysis/codebase-scanner.js`)
89
+ - Scans entire codebase for compliance issues
90
+ - Excludes third-party libraries automatically
91
+ - Configurable file type filtering
92
+
93
+ - **BoundaryDetector** (`src/analysis/boundary-detector.js`)
94
+ - AST-based logical boundary detection
95
+ - Identifies refactoring opportunities
96
+ - Suggests module split points
97
+
98
+ #### Automated Refactoring
99
+
100
+ - **FileSplitter** (`src/refactoring/file-splitter.js`)
101
+ - Safe automated file splitting
102
+ - AST-based code transformation
103
+ - Preserves functionality and imports
104
+
105
+ - **ImportManager** (`src/refactoring/import-manager.js`)
106
+ - Automatic import statement updates
107
+ - Circular dependency resolution
108
+ - Dependency mapping validation
109
+
110
+ ### Usage Examples
111
+
112
+ #### Basic File Validation
113
+
114
+ ```javascript
115
+ const { LineLimitValidator } = require('./validation/line-limit-validator');
116
+
117
+ const validator = new LineLimitValidator({
118
+ maxLines: 555,
119
+ warningThreshold: 500,
120
+ criticalThreshold: 800
121
+ });
122
+
123
+ const result = validator.validateFile('./src/my-file.js');
124
+ console.log(`File is ${result.isValid ? 'compliant' : 'non-compliant'}`);
125
+ ```
126
+
127
+ #### Real-time Monitoring
128
+
129
+ ```javascript
130
+ const { FileMonitor } = require('./monitoring/file-monitor');
131
+ const { AlertSystem } = require('./monitoring/alert-system');
132
+
133
+ const alertSystem = new AlertSystem({
134
+ channels: ['console', 'file'],
135
+ enableEscalation: true
136
+ });
137
+
138
+ const monitor = new FileMonitor({
139
+ watchPaths: ['./src'],
140
+ enableConstitutionalValidation: true
141
+ });
142
+
143
+ monitor.on('violationDetected', (data) => {
144
+ console.log(`Violation in ${data.filePath}: ${data.validationResults.lineCount} lines`);
145
+ });
146
+
147
+ await monitor.start();
148
+ ```
149
+
150
+ #### Generating Compliance Reports
151
+
152
+ ```javascript
153
+ const { ComplianceReporter } = require('./validation/compliance-reporter');
154
+
155
+ const reporter = new ComplianceReporter({
156
+ outputDir: './reports',
157
+ formats: ['json', 'html', 'markdown'],
158
+ includeMetrics: true
159
+ });
160
+
161
+ const reportResult = await reporter.generateReport(validationResults);
162
+ console.log(`Report saved to: ${reportResult.files[0].filePath}`);
163
+ ```
164
+
165
+ #### Automated Refactoring
166
+
167
+ ```javascript
168
+ const { FileSplitter } = require('./refactoring/file-splitter');
169
+ const { ImportManager } = require('./refactoring/import-manager');
170
+
171
+ const splitter = new FileSplitter({
172
+ maxLines: 555,
173
+ preserveFunctionality: true
174
+ });
175
+
176
+ const refactoringResult = await splitter.splitFile('./src/large-file.js');
177
+ console.log(`Split into ${refactoringResult.newFiles.length} files`);
178
+
179
+ // Update imports
180
+ const importManager = new ImportManager();
181
+ await importManager.updateImports(refactoringResult.affectedFiles);
182
+ ```
183
+
184
+ ### CLI Integration
185
+
186
+ The package integrates with the CLI through the `check-compliance` command:
187
+
188
+ ```bash
189
+ # Basic compliance check
190
+ npm run check-compliance
191
+
192
+ # Full validation with constitutional checks
193
+ npm run check-compliance:full
194
+
195
+ # CI/CD integration
196
+ npm run check-compliance:ci
197
+
198
+ # Strict validation (fails on warnings)
199
+ npm run check-compliance:strict
200
+ ```
201
+
202
+ ### Pre-commit Integration
203
+
204
+ A pre-commit hook is provided for automatic validation:
205
+
206
+ ```bash
207
+ # The hook is automatically installed at .git/hooks/pre-commit
208
+ # It validates staged files before allowing commits
209
+ ```
210
+
211
+ ### Configuration
212
+
213
+ Configuration is managed through `src/config/refactoring-config.js`:
214
+
215
+ ```javascript
216
+ module.exports = {
217
+ limits: {
218
+ maxFileSize: 555,
219
+ warningThreshold: 500,
220
+ criticalThreshold: 800
221
+ },
222
+ exclusions: [
223
+ 'node_modules',
224
+ '.git',
225
+ 'dist',
226
+ 'build'
227
+ ],
228
+ validation: {
229
+ enableConstitutional: true,
230
+ enableCircularDependencyCheck: true,
231
+ enableNamingValidation: true
232
+ }
233
+ };
24
234
  ```
25
235
 
26
236
  ## Development
27
237
 
28
238
  This package is part of the Vibe Coding Machine monorepo. See the root README for development instructions.
239
+
240
+ ### Testing
241
+
242
+ Run the package tests with:
243
+
244
+ ```bash
245
+ cd packages/core
246
+ npm test
247
+ ```
248
+
249
+ ### Contributing
250
+
251
+ When contributing to this package:
252
+
253
+ 1. Ensure all new files comply with the 555-line limit
254
+ 2. Add appropriate tests for new functionality
255
+ 3. Update documentation as needed
256
+ 4. Run compliance validation before committing
257
+
258
+ ## Constitutional Compliance
259
+
260
+ This package is designed to enforce the project's constitutional requirements:
261
+
262
+ - **File Size Limit**: No source file exceeds 555 lines
263
+ - **Code Structure**: Proper modular organization
264
+ - **Documentation**: Adequate documentation for all components
265
+ - **Testing**: Test-first development approach
266
+ - **Quality**: High code quality standards
267
+
268
+ All tools in this package are designed to help maintain these standards automatically.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vibecodingmachine-core",
3
- "version": "2026.02.20-0438",
3
+ "version": "2026.02.26-1642",
4
4
  "description": "Shared core logic for Vibe Coding Machine IDE integration",
5
5
  "main": "src/index.cjs",
6
6
  "module": "src/index.js",
@@ -18,17 +18,25 @@
18
18
  "test": "jest",
19
19
  "test:watch": "jest --watch",
20
20
  "test:coverage": "jest --coverage",
21
+ "test:unit": "jest --testPathPattern=unit",
22
+ "test:integration": "jest --testPathPattern=integration",
23
+ "test:ci": "jest --ci --coverage --watchAll=false",
24
+ "test:regression": "../../scripts/run-regression-tests.sh",
25
+ "test:package": "../../scripts/test-package.sh",
26
+ "test:comprehensive": "npm run test:unit && npm run test:integration && npm run test:regression",
21
27
  "dev": "echo 'Core package - development mode'"
22
28
  },
23
29
  "dependencies": {
24
30
  "@aws-sdk/client-bedrock-runtime": "^3.932.0",
31
+ "@aws-sdk/client-cognito-identity-provider": "^3.600.0",
25
32
  "@aws-sdk/client-dynamodb": "^3.600.0",
26
33
  "@aws-sdk/lib-dynamodb": "^3.600.0",
27
- "@aws-sdk/client-cognito-identity-provider": "^3.600.0",
28
34
  "chrome-remote-interface": "^0.33.0",
29
35
  "fs-extra": "^11.1.1",
30
36
  "jsonwebtoken": "^9.0.2",
31
37
  "jwks-rsa": "^3.2.0",
38
+ "node-fetch": "^3.3.2",
39
+ "ora": "^9.3.0",
32
40
  "ws": "^8.18.0"
33
41
  },
34
42
  "optionalDependencies": {
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Agent Entity
3
+ *
4
+ * Represents an AI coding agent that can be installed and verified.
5
+ * Follows constitutional requirements: <555 lines, test-first approach.
6
+ */
7
+
8
+ const { AgentStatus } = require('./AgentStatus');
9
+ const InstallationMethod = require('./InstallationMethod');
10
+
11
+ /**
12
+ * Agent class representing an AI coding agent
13
+ */
14
+ class Agent {
15
+ /**
16
+ * Create a new Agent instance
17
+ * @param {Object} config - Agent configuration
18
+ * @param {string} config.id - Unique identifier (e.g., "claude-code")
19
+ * @param {string} config.name - Display name (e.g., "Claude Code")
20
+ * @param {string} config.description - Brief description of the agent
21
+ * @param {boolean} config.enabled - Whether user has enabled this agent
22
+ * @param {AgentStatus} config.status - Current installation state
23
+ * @param {string} config.statusMessage - Human-readable status message
24
+ * @param {InstallationMethod[]} config.installationMethods - Available installation approaches
25
+ * @param {string[]} config.verificationCommands - Commands to verify installation
26
+ * @param {Date} config.lastChecked - Timestamp of last check attempt
27
+ * @param {Date} config.lastVerified - Timestamp of last successful verification
28
+ */
29
+ constructor(config = {}) {
30
+ this.id = config.id || '';
31
+ this.name = config.name || '';
32
+ this.description = config.description || '';
33
+ this.enabled = config.enabled !== undefined ? config.enabled : false;
34
+ this.status = config.status || AgentStatus.NOT_INSTALLED;
35
+ this.statusMessage = config.statusMessage || '';
36
+ this.installationMethods = config.installationMethods || [];
37
+ this.verificationCommands = config.verificationCommands || [];
38
+ this.lastChecked = config.lastChecked || null;
39
+ this.lastVerified = config.lastVerified || null;
40
+
41
+ this.validate();
42
+ }
43
+
44
+ /**
45
+ * Validate agent configuration
46
+ * @throws {Error} If configuration is invalid
47
+ */
48
+ validate() {
49
+ if (!this.id || typeof this.id !== 'string') {
50
+ throw new Error('Agent must have a valid non-empty string id');
51
+ }
52
+
53
+ if (!this.name || typeof this.name !== 'string') {
54
+ throw new Error('Agent must have a valid non-empty string name');
55
+ }
56
+
57
+ if (!Array.isArray(this.installationMethods) || this.installationMethods.length === 0) {
58
+ throw new Error('Agent must have at least one installation method');
59
+ }
60
+
61
+ if (this.enabled && (!Array.isArray(this.verificationCommands) || this.verificationCommands.length === 0)) {
62
+ throw new Error('Enabled agent must have verification commands');
63
+ }
64
+
65
+ // Validate installation methods
66
+ this.installationMethods.forEach((method, index) => {
67
+ if (!(method instanceof InstallationMethod)) {
68
+ throw new Error(`Installation method at index ${index} must be an InstallationMethod instance`);
69
+ }
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Update agent status
75
+ * @param {AgentStatus} newStatus - New status
76
+ * @param {string} message - Optional status message
77
+ */
78
+ updateStatus(newStatus, message = '') {
79
+ const oldStatus = this.status;
80
+ this.status = newStatus;
81
+ this.lastChecked = new Date();
82
+
83
+ if (newStatus === AgentStatus.VERIFIED) {
84
+ this.lastVerified = new Date();
85
+ }
86
+
87
+ return {
88
+ oldStatus,
89
+ newStatus,
90
+ message,
91
+ timestamp: this.lastChecked
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Check if agent is installed (not NOT_INSTALLED)
97
+ * @returns {boolean}
98
+ */
99
+ isInstalled() {
100
+ return this.status !== AgentStatus.NOT_INSTALLED;
101
+ }
102
+
103
+ /**
104
+ * Check if agent is verified and functional
105
+ * @returns {boolean}
106
+ */
107
+ isVerified() {
108
+ return this.status === AgentStatus.VERIFIED;
109
+ }
110
+
111
+ /**
112
+ * Check if agent can be checked (enabled and not disabled)
113
+ * @returns {boolean}
114
+ */
115
+ canBeChecked() {
116
+ return this.enabled && this.status !== AgentStatus.DISABLED;
117
+ }
118
+
119
+ /**
120
+ * Get installation method by type
121
+ * @param {string} type - Installation method type
122
+ * @returns {InstallationMethod|null}
123
+ */
124
+ getInstallationMethod(type) {
125
+ return this.installationMethods.find(method => method.type === type) || null;
126
+ }
127
+
128
+ /**
129
+ * Get preferred installation method (lowest priority number)
130
+ * @returns {InstallationMethod|null}
131
+ */
132
+ getPreferredInstallationMethod() {
133
+ if (this.installationMethods.length === 0) {
134
+ return null;
135
+ }
136
+
137
+ return this.installationMethods.reduce((preferred, current) => {
138
+ return (current.priority < preferred.priority) ? current : preferred;
139
+ });
140
+ }
141
+
142
+ /**
143
+ * Add installation method
144
+ * @param {InstallationMethod} method - Installation method to add
145
+ */
146
+ addInstallationMethod(method) {
147
+ if (!(method instanceof InstallationMethod)) {
148
+ throw new Error('Method must be an InstallationMethod instance');
149
+ }
150
+
151
+ // Check for duplicate types
152
+ const existing = this.getInstallationMethod(method.type);
153
+ if (existing) {
154
+ throw new Error(`Installation method of type ${method.type} already exists`);
155
+ }
156
+
157
+ this.installationMethods.push(method);
158
+ this.installationMethods.sort((a, b) => a.priority - b.priority);
159
+ }
160
+
161
+ /**
162
+ * Remove installation method
163
+ * @param {string} type - Installation method type to remove
164
+ * @returns {boolean} - True if method was removed
165
+ */
166
+ removeInstallationMethod(type) {
167
+ const index = this.installationMethods.findIndex(method => method.type === type);
168
+ if (index !== -1) {
169
+ this.installationMethods.splice(index, 1);
170
+ return true;
171
+ }
172
+ return false;
173
+ }
174
+
175
+ /**
176
+ * Convert agent to plain object
177
+ * @returns {Object}
178
+ */
179
+ toJSON() {
180
+ return {
181
+ id: this.id,
182
+ name: this.name,
183
+ description: this.description,
184
+ enabled: this.enabled,
185
+ status: this.status,
186
+ installationMethods: this.installationMethods.map(method => method.toJSON()),
187
+ verificationCommands: [...this.verificationCommands],
188
+ lastChecked: this.lastChecked,
189
+ lastVerified: this.lastVerified
190
+ };
191
+ }
192
+
193
+ /**
194
+ * Create agent from plain object data
195
+ * @param {Object} data - Plain object data
196
+ * @returns {Agent}
197
+ */
198
+ static fromJSON(data) {
199
+ let installationMethods = [];
200
+
201
+ // Handle different installation data formats
202
+ if (data.installationMethods) {
203
+ // Direct array of InstallationMethod objects
204
+ installationMethods = data.installationMethods
205
+ .map(methodData => InstallationMethod.fromJSON(methodData));
206
+ } else if (data.installation && data.installation.methods) {
207
+ // Nested format from agents.json: installation.methods[]
208
+ installationMethods = data.installation.methods
209
+ .map(methodData => InstallationMethod.fromJSON({
210
+ type: methodData.type,
211
+ command: methodData.command,
212
+ packageId: methodData.package,
213
+ verificationCommand: methodData.verifyCommand,
214
+ priority: 1
215
+ }));
216
+ }
217
+
218
+ // Extract verification commands from different formats
219
+ let verificationCommands = data.verificationCommands || [];
220
+ if (data.installation && data.installation.verification && data.installation.verification.command) {
221
+ verificationCommands = [data.installation.verification.command];
222
+ }
223
+
224
+ return new Agent({
225
+ ...data,
226
+ installationMethods,
227
+ verificationCommands
228
+ });
229
+ }
230
+
231
+ /**
232
+ * Create agent configuration for common AI agents
233
+ * @param {string} agentId - Agent identifier
234
+ * @returns {Agent|null}
235
+ */
236
+ static createCommonAgent(agentId) {
237
+ const configurations = {
238
+ 'claude-code': {
239
+ name: 'Claude Code',
240
+ description: 'Anthropic Claude Code AI assistant',
241
+ enabled: true,
242
+ verificationCommands: ['claude --version'],
243
+ installationMethods: [
244
+ // Will be populated with actual InstallationMethod instances
245
+ ]
246
+ },
247
+ 'github-copilot': {
248
+ name: 'GitHub Copilot',
249
+ description: 'GitHub Copilot CLI assistant',
250
+ enabled: true,
251
+ verificationCommands: ['gh copilot --version'],
252
+ installationMethods: []
253
+ },
254
+ 'gemini-cli': {
255
+ name: 'Gemini CLI',
256
+ description: 'Google Gemini CLI assistant',
257
+ enabled: true,
258
+ verificationCommands: ['gemini --version'],
259
+ installationMethods: []
260
+ },
261
+ 'cursor-cli': {
262
+ name: 'Cursor CLI',
263
+ description: 'Cursor AI assistant CLI',
264
+ enabled: false, // Disabled by default due to WSL requirement
265
+ verificationCommands: ['cursor --version'],
266
+ installationMethods: []
267
+ }
268
+ };
269
+
270
+ const config = configurations[agentId];
271
+ if (!config) {
272
+ return null;
273
+ }
274
+
275
+ return new Agent({
276
+ id: agentId,
277
+ ...config
278
+ });
279
+ }
280
+
281
+ /**
282
+ * Convert agent to JSON representation
283
+ * @returns {Object} Plain object representation
284
+ */
285
+ toJSON() {
286
+ return {
287
+ id: this.id,
288
+ name: this.name,
289
+ description: this.description,
290
+ enabled: this.enabled,
291
+ status: this.status,
292
+ installationMethods: this.installationMethods.map(method => method.toJSON()),
293
+ verificationCommands: this.verificationCommands,
294
+ lastChecked: this.lastChecked,
295
+ lastVerified: this.lastVerified
296
+ };
297
+ }
298
+ }
299
+
300
+ module.exports = Agent;