buildhive-agent 1.0.0-beta.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.
- package/README.md +166 -0
- package/dist/__tests__/fakes/FakeDockerManager.d.ts +115 -0
- package/dist/__tests__/fakes/FakeDockerManager.d.ts.map +1 -0
- package/dist/__tests__/fakes/FakeDockerManager.js +203 -0
- package/dist/__tests__/fakes/FakeDockerManager.js.map +1 -0
- package/dist/acceptanceChecker.d.ts +26 -0
- package/dist/acceptanceChecker.d.ts.map +1 -0
- package/dist/acceptanceChecker.js +64 -0
- package/dist/acceptanceChecker.js.map +1 -0
- package/dist/advancedAgent.d.ts +161 -0
- package/dist/advancedAgent.d.ts.map +1 -0
- package/dist/advancedAgent.js +604 -0
- package/dist/advancedAgent.js.map +1 -0
- package/dist/agent.d.ts +101 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +490 -0
- package/dist/agent.js.map +1 -0
- package/dist/api/jobStatusApi.d.ts +88 -0
- package/dist/api/jobStatusApi.d.ts.map +1 -0
- package/dist/api/jobStatusApi.js +240 -0
- package/dist/api/jobStatusApi.js.map +1 -0
- package/dist/autoUpdater.d.ts +135 -0
- package/dist/autoUpdater.d.ts.map +1 -0
- package/dist/autoUpdater.js +494 -0
- package/dist/autoUpdater.js.map +1 -0
- package/dist/cacheManager.d.ts +108 -0
- package/dist/cacheManager.d.ts.map +1 -0
- package/dist/cacheManager.js +300 -0
- package/dist/cacheManager.js.map +1 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +749 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/index.d.ts +30 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +35 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +45 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +269 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +193 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +90 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/validation.d.ts +28 -0
- package/dist/config/validation.d.ts.map +1 -0
- package/dist/config/validation.js +397 -0
- package/dist/config/validation.js.map +1 -0
- package/dist/docker.d.ts +96 -0
- package/dist/docker.d.ts.map +1 -0
- package/dist/docker.js +411 -0
- package/dist/docker.js.map +1 -0
- package/dist/enhancedJobExecutor.d.ts +81 -0
- package/dist/enhancedJobExecutor.d.ts.map +1 -0
- package/dist/enhancedJobExecutor.js +223 -0
- package/dist/enhancedJobExecutor.js.map +1 -0
- package/dist/executors/executorFactory.d.ts +46 -0
- package/dist/executors/executorFactory.d.ts.map +1 -0
- package/dist/executors/executorFactory.js +80 -0
- package/dist/executors/executorFactory.js.map +1 -0
- package/dist/executors/index.d.ts +7 -0
- package/dist/executors/index.d.ts.map +1 -0
- package/dist/executors/index.js +6 -0
- package/dist/executors/index.js.map +1 -0
- package/dist/executors/nativeExecutor.d.ts +60 -0
- package/dist/executors/nativeExecutor.d.ts.map +1 -0
- package/dist/executors/nativeExecutor.js +311 -0
- package/dist/executors/nativeExecutor.js.map +1 -0
- package/dist/executors/types.d.ts +38 -0
- package/dist/executors/types.d.ts.map +1 -0
- package/dist/executors/types.js +9 -0
- package/dist/executors/types.js.map +1 -0
- package/dist/healthMonitor.d.ts +213 -0
- package/dist/healthMonitor.d.ts.map +1 -0
- package/dist/healthMonitor.js +547 -0
- package/dist/healthMonitor.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/jobExecutor.d.ts +117 -0
- package/dist/jobExecutor.d.ts.map +1 -0
- package/dist/jobExecutor.js +458 -0
- package/dist/jobExecutor.js.map +1 -0
- package/dist/lifecycleExecutor.d.ts +54 -0
- package/dist/lifecycleExecutor.d.ts.map +1 -0
- package/dist/lifecycleExecutor.js +230 -0
- package/dist/lifecycleExecutor.js.map +1 -0
- package/dist/main.d.ts +15 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +77 -0
- package/dist/main.js.map +1 -0
- package/dist/metrics.d.ts +103 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +360 -0
- package/dist/metrics.js.map +1 -0
- package/dist/recipes/builtinRecipes.d.ts +11 -0
- package/dist/recipes/builtinRecipes.d.ts.map +1 -0
- package/dist/recipes/builtinRecipes.js +688 -0
- package/dist/recipes/builtinRecipes.js.map +1 -0
- package/dist/recipes/index.d.ts +18 -0
- package/dist/recipes/index.d.ts.map +1 -0
- package/dist/recipes/index.js +17 -0
- package/dist/recipes/index.js.map +1 -0
- package/dist/recipes/recipeRegistry.d.ts +49 -0
- package/dist/recipes/recipeRegistry.d.ts.map +1 -0
- package/dist/recipes/recipeRegistry.js +264 -0
- package/dist/recipes/recipeRegistry.js.map +1 -0
- package/dist/recipes/types.d.ts +116 -0
- package/dist/recipes/types.d.ts.map +1 -0
- package/dist/recipes/types.js +10 -0
- package/dist/recipes/types.js.map +1 -0
- package/dist/recovery.d.ts +133 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +299 -0
- package/dist/recovery.js.map +1 -0
- package/dist/registration/apiClient.d.ts +44 -0
- package/dist/registration/apiClient.d.ts.map +1 -0
- package/dist/registration/apiClient.js +149 -0
- package/dist/registration/apiClient.js.map +1 -0
- package/dist/registration/index.d.ts +41 -0
- package/dist/registration/index.d.ts.map +1 -0
- package/dist/registration/index.js +141 -0
- package/dist/registration/index.js.map +1 -0
- package/dist/registration/machineId.d.ts +30 -0
- package/dist/registration/machineId.d.ts.map +1 -0
- package/dist/registration/machineId.js +89 -0
- package/dist/registration/machineId.js.map +1 -0
- package/dist/registration/types.d.ts +32 -0
- package/dist/registration/types.d.ts.map +1 -0
- package/dist/registration/types.js +9 -0
- package/dist/registration/types.js.map +1 -0
- package/dist/resourceGovernor.d.ts +57 -0
- package/dist/resourceGovernor.d.ts.map +1 -0
- package/dist/resourceGovernor.js +125 -0
- package/dist/resourceGovernor.js.map +1 -0
- package/dist/security/secretManager.d.ts +107 -0
- package/dist/security/secretManager.d.ts.map +1 -0
- package/dist/security/secretManager.js +361 -0
- package/dist/security/secretManager.js.map +1 -0
- package/dist/security.d.ts +134 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +470 -0
- package/dist/security.js.map +1 -0
- package/dist/storage/artifactUploader.d.ts +155 -0
- package/dist/storage/artifactUploader.d.ts.map +1 -0
- package/dist/storage/artifactUploader.js +554 -0
- package/dist/storage/artifactUploader.js.map +1 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/capabilities.d.ts +23 -0
- package/dist/utils/capabilities.d.ts.map +1 -0
- package/dist/utils/capabilities.js +200 -0
- package/dist/utils/capabilities.js.map +1 -0
- package/dist/utils/logger.d.ts +20 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +188 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/sdkScanner.d.ts +105 -0
- package/dist/utils/sdkScanner.d.ts.map +1 -0
- package/dist/utils/sdkScanner.js +459 -0
- package/dist/utils/sdkScanner.js.map +1 -0
- package/dist/websocketClient.d.ts +154 -0
- package/dist/websocketClient.d.ts.map +1 -0
- package/dist/websocketClient.js +422 -0
- package/dist/websocketClient.js.map +1 -0
- package/package.json +64 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,749 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* BuildHive Agent CLI
|
|
4
|
+
*
|
|
5
|
+
* Command-line interface for managing the BuildHive agent.
|
|
6
|
+
* Provides commands for registration, starting/stopping the agent, and status checks.
|
|
7
|
+
*
|
|
8
|
+
* Requirements: MVP.4.1.1, MVP.4.1.2, MVP.4.3.3
|
|
9
|
+
*/
|
|
10
|
+
import { Command } from 'commander';
|
|
11
|
+
import inquirer from 'inquirer';
|
|
12
|
+
import { BuildHiveAgent } from './agent.js';
|
|
13
|
+
import { loadConfig } from './config/index.js';
|
|
14
|
+
import { AgentRegistration } from './registration/index.js';
|
|
15
|
+
import { createLogger } from './utils/logger.js';
|
|
16
|
+
import { promises as fs } from 'fs';
|
|
17
|
+
import { join } from 'path';
|
|
18
|
+
import os from 'os';
|
|
19
|
+
const logger = createLogger('cli');
|
|
20
|
+
const program = new Command();
|
|
21
|
+
// Package info
|
|
22
|
+
const VERSION = '1.0.0';
|
|
23
|
+
program
|
|
24
|
+
.name('buildhive-agent')
|
|
25
|
+
.description('BuildHive CI Agent - Distributed build execution agent')
|
|
26
|
+
.version(VERSION);
|
|
27
|
+
/**
|
|
28
|
+
* Init command - One-liner setup wizard (Task 2.1.1)
|
|
29
|
+
* Guides the user through full agent setup in a single interactive flow.
|
|
30
|
+
*/
|
|
31
|
+
program
|
|
32
|
+
.command('init')
|
|
33
|
+
.description('Initialize and set up the BuildHive agent (one-liner setup)')
|
|
34
|
+
.option('-y, --yes', 'Accept all defaults without prompting')
|
|
35
|
+
.action(async (options) => {
|
|
36
|
+
console.log('=== BuildHive Agent Setup ===\n');
|
|
37
|
+
console.log('This wizard will guide you through setting up the BuildHive agent.\n');
|
|
38
|
+
try {
|
|
39
|
+
// Step 1: Gather configuration via prompts
|
|
40
|
+
let serverUrl = 'http://localhost:3001';
|
|
41
|
+
let agentName = `agent-${os.hostname()}`;
|
|
42
|
+
if (!options.yes) {
|
|
43
|
+
const answers = await inquirer.prompt([
|
|
44
|
+
{
|
|
45
|
+
type: 'input',
|
|
46
|
+
name: 'serverUrl',
|
|
47
|
+
message: 'BuildHive server URL:',
|
|
48
|
+
default: serverUrl,
|
|
49
|
+
validate: (input) => {
|
|
50
|
+
try {
|
|
51
|
+
new URL(input);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return 'Please enter a valid URL (e.g. http://localhost:3001)';
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'input',
|
|
61
|
+
name: 'agentName',
|
|
62
|
+
message: 'Agent name:',
|
|
63
|
+
default: agentName,
|
|
64
|
+
},
|
|
65
|
+
]);
|
|
66
|
+
serverUrl = answers.serverUrl;
|
|
67
|
+
agentName = answers.agentName;
|
|
68
|
+
}
|
|
69
|
+
// Step 2: Scan installed SDKs
|
|
70
|
+
console.log('\n[1/5] Scanning installed SDKs...');
|
|
71
|
+
const { scanInstalledSDKs, generateTagsFromSDKs } = await import('./utils/sdkScanner.js');
|
|
72
|
+
const sdkResult = await scanInstalledSDKs();
|
|
73
|
+
const sdkTags = generateTagsFromSDKs(sdkResult);
|
|
74
|
+
const detectedTools = Object.keys(sdkResult).filter(k => sdkResult[k] !== undefined);
|
|
75
|
+
console.log(` Detected ${detectedTools.length} tool(s): ${detectedTools.join(', ')}`);
|
|
76
|
+
if (sdkTags.length > 0) {
|
|
77
|
+
console.log(` Generated ${sdkTags.length} capability tag(s): ${sdkTags.join(', ')}`);
|
|
78
|
+
}
|
|
79
|
+
// Step 3: Validate Docker is running
|
|
80
|
+
console.log('\n[2/5] Checking Docker...');
|
|
81
|
+
try {
|
|
82
|
+
const { execSync } = await import('child_process');
|
|
83
|
+
execSync('docker info', { stdio: 'pipe' });
|
|
84
|
+
console.log(' Docker is running.');
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
console.error(' Docker does not appear to be running.');
|
|
88
|
+
console.error(' Please start Docker and re-run: npx buildhive-agent init');
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
// Step 4: Test server connectivity
|
|
92
|
+
console.log(`\n[3/5] Connecting to server at ${serverUrl}...`);
|
|
93
|
+
const { BuildHiveApiClient } = await import('./registration/apiClient.js');
|
|
94
|
+
const apiClient = new BuildHiveApiClient(serverUrl);
|
|
95
|
+
const connected = await apiClient.testConnection();
|
|
96
|
+
if (!connected) {
|
|
97
|
+
console.error(` Cannot reach server at ${serverUrl}.`);
|
|
98
|
+
console.error(' Please verify the server is running and the URL is correct.');
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
console.log(' Server is reachable.');
|
|
102
|
+
// Step 5: Register the agent (generates agentId + apiKey)
|
|
103
|
+
console.log('\n[4/5] Registering agent...');
|
|
104
|
+
const registration = new AgentRegistration(serverUrl);
|
|
105
|
+
const config = await registration.registerAgent({
|
|
106
|
+
platformUrl: serverUrl,
|
|
107
|
+
name: agentName,
|
|
108
|
+
tags: ['docker', ...sdkTags],
|
|
109
|
+
maxConcurrentJobs: 1,
|
|
110
|
+
});
|
|
111
|
+
console.log(` Agent registered. ID: ${config.agentId}`);
|
|
112
|
+
// Step 5: Write config file
|
|
113
|
+
const configDir = join(os.homedir(), '.buildhive');
|
|
114
|
+
const configPath = join(configDir, 'config.json');
|
|
115
|
+
await fs.mkdir(configDir, { recursive: true });
|
|
116
|
+
await fs.writeFile(configPath, JSON.stringify({
|
|
117
|
+
serverUrl,
|
|
118
|
+
agentId: config.agentId,
|
|
119
|
+
apiKey: config.apiKey,
|
|
120
|
+
agentName,
|
|
121
|
+
}, null, 2), 'utf-8');
|
|
122
|
+
console.log(` Config saved to ${configPath}`);
|
|
123
|
+
// Step 6: Send first heartbeat to verify end-to-end
|
|
124
|
+
console.log('\n[5/5] Sending first heartbeat...');
|
|
125
|
+
try {
|
|
126
|
+
await apiClient.sendHeartbeat({
|
|
127
|
+
agentId: config.agentId,
|
|
128
|
+
status: 'ONLINE',
|
|
129
|
+
currentLoad: 0,
|
|
130
|
+
activeJobs: 0,
|
|
131
|
+
}, config.apiKey);
|
|
132
|
+
console.log(' Heartbeat sent successfully.');
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Non-fatal — agent is set up, heartbeat can be retried at runtime
|
|
136
|
+
console.warn(' Heartbeat failed (non-fatal). The agent will retry on start.');
|
|
137
|
+
}
|
|
138
|
+
console.log('\n=== Setup complete! ===');
|
|
139
|
+
console.log(` Agent name : ${agentName}`);
|
|
140
|
+
console.log(` Agent ID : ${config.agentId}`);
|
|
141
|
+
console.log(` Server : ${serverUrl}`);
|
|
142
|
+
console.log(` Config : ${configPath}`);
|
|
143
|
+
console.log('\nNext steps:');
|
|
144
|
+
console.log(' Start the agent : buildhive-agent start');
|
|
145
|
+
console.log(' Check status : buildhive-agent status');
|
|
146
|
+
console.log(' View logs : buildhive-agent logs\n');
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
console.error('\n[ERROR] Setup failed:', error instanceof Error ? error.message : error);
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
/**
|
|
154
|
+
* Register command - Interactive agent registration
|
|
155
|
+
*/
|
|
156
|
+
program
|
|
157
|
+
.command('register')
|
|
158
|
+
.description('Register agent with BuildHive platform')
|
|
159
|
+
.option('-u, --url <url>', 'Platform URL')
|
|
160
|
+
.option('-n, --name <name>', 'Agent name')
|
|
161
|
+
.option('-t, --tags <tags>', 'Comma-separated tags')
|
|
162
|
+
.option('-j, --jobs <number>', 'Maximum concurrent jobs', '1')
|
|
163
|
+
.option('-c, --config <path>', 'Configuration file path')
|
|
164
|
+
.option('-y, --yes', 'Skip confirmation prompts')
|
|
165
|
+
.action(async (options) => {
|
|
166
|
+
try {
|
|
167
|
+
console.log('=== BuildHive Agent Registration ===\n');
|
|
168
|
+
let platformUrl = options.url;
|
|
169
|
+
let agentName = options.name;
|
|
170
|
+
let tags = options.tags ? options.tags.split(',').map((t) => t.trim()) : [];
|
|
171
|
+
let maxJobs = parseInt(options.jobs);
|
|
172
|
+
// Interactive prompts if options not provided
|
|
173
|
+
if (!options.yes) {
|
|
174
|
+
const answers = await inquirer.prompt([
|
|
175
|
+
{
|
|
176
|
+
type: 'input',
|
|
177
|
+
name: 'platformUrl',
|
|
178
|
+
message: 'BuildHive Platform URL:',
|
|
179
|
+
default: platformUrl || 'http://localhost:3001',
|
|
180
|
+
when: !platformUrl,
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
type: 'input',
|
|
184
|
+
name: 'agentName',
|
|
185
|
+
message: 'Agent name:',
|
|
186
|
+
default: agentName || `agent-${os.hostname()}`,
|
|
187
|
+
when: !agentName,
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
type: 'input',
|
|
191
|
+
name: 'tags',
|
|
192
|
+
message: 'Tags (comma-separated):',
|
|
193
|
+
default: tags.length > 0 ? tags.join(',') : 'docker,linux',
|
|
194
|
+
when: tags.length === 0,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
type: 'number',
|
|
198
|
+
name: 'maxJobs',
|
|
199
|
+
message: 'Maximum concurrent jobs:',
|
|
200
|
+
default: maxJobs || 1,
|
|
201
|
+
when: !maxJobs,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
type: 'confirm',
|
|
205
|
+
name: 'confirm',
|
|
206
|
+
message: 'Proceed with registration?',
|
|
207
|
+
default: true,
|
|
208
|
+
},
|
|
209
|
+
]);
|
|
210
|
+
if (answers.confirm === false) {
|
|
211
|
+
console.log('Registration cancelled.');
|
|
212
|
+
process.exit(0);
|
|
213
|
+
}
|
|
214
|
+
platformUrl = platformUrl || answers.platformUrl;
|
|
215
|
+
agentName = agentName || answers.agentName;
|
|
216
|
+
tags =
|
|
217
|
+
tags.length > 0
|
|
218
|
+
? tags
|
|
219
|
+
: answers.tags.split(',').map((t) => t.trim());
|
|
220
|
+
maxJobs = maxJobs || answers.maxJobs;
|
|
221
|
+
}
|
|
222
|
+
// Perform registration
|
|
223
|
+
console.log('\nRegistering agent...');
|
|
224
|
+
const registration = new AgentRegistration(platformUrl);
|
|
225
|
+
const config = await registration.registerAgent({
|
|
226
|
+
platformUrl,
|
|
227
|
+
name: agentName,
|
|
228
|
+
tags,
|
|
229
|
+
maxConcurrentJobs: maxJobs,
|
|
230
|
+
configPath: options.config,
|
|
231
|
+
});
|
|
232
|
+
console.log('\n✓ Agent registered successfully!');
|
|
233
|
+
console.log(` Agent ID: ${config.agentId}`);
|
|
234
|
+
console.log(` Name: ${config.name}`);
|
|
235
|
+
console.log(` Platform: ${config.platformUrl}`);
|
|
236
|
+
console.log(` Config saved to: ${options.config ||
|
|
237
|
+
join(os.homedir(), '.buildhive', 'buildhive-agent.json')}`);
|
|
238
|
+
console.log('\nYou can now start the agent with: buildhive-agent start');
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
console.error('\n✗ Registration failed:', error instanceof Error ? error.message : error);
|
|
242
|
+
process.exit(1);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
/**
|
|
246
|
+
* Start command - Start the agent
|
|
247
|
+
*/
|
|
248
|
+
program
|
|
249
|
+
.command('start')
|
|
250
|
+
.description('Start the BuildHive agent')
|
|
251
|
+
.option('-c, --config <path>', 'Configuration file path')
|
|
252
|
+
.option('-d, --daemon', 'Run as daemon (background process)')
|
|
253
|
+
.action(async (options) => {
|
|
254
|
+
try {
|
|
255
|
+
console.log('Starting BuildHive Agent...\n');
|
|
256
|
+
// Load configuration
|
|
257
|
+
const config = await loadConfig();
|
|
258
|
+
console.log(`Agent: ${config.name}`);
|
|
259
|
+
console.log(`Platform: ${config.platformUrl}\n`);
|
|
260
|
+
// Create PID file directory
|
|
261
|
+
const pidDir = join(os.homedir(), '.buildhive');
|
|
262
|
+
await fs.mkdir(pidDir, { recursive: true });
|
|
263
|
+
// Write PID file
|
|
264
|
+
const pidFile = join(pidDir, 'agent.pid');
|
|
265
|
+
await fs.writeFile(pidFile, process.pid.toString(), 'utf-8');
|
|
266
|
+
// Create and start agent
|
|
267
|
+
const agent = await BuildHiveAgent.create(config);
|
|
268
|
+
// Handle graceful shutdown
|
|
269
|
+
const shutdown = async (signal) => {
|
|
270
|
+
console.log(`\nReceived ${signal}, shutting down gracefully...`);
|
|
271
|
+
try {
|
|
272
|
+
await agent.stop();
|
|
273
|
+
// Remove PID file
|
|
274
|
+
try {
|
|
275
|
+
await fs.unlink(pidFile);
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
logger.error('Failed to remove PID file:', error);
|
|
279
|
+
}
|
|
280
|
+
console.log('Agent stopped successfully');
|
|
281
|
+
process.exit(0);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
console.error('Error during shutdown:', error);
|
|
285
|
+
process.exit(1);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
289
|
+
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
290
|
+
process.on('SIGQUIT', () => shutdown('SIGQUIT'));
|
|
291
|
+
// Handle uncaught exceptions
|
|
292
|
+
process.on('uncaughtException', (error) => {
|
|
293
|
+
logger.error('Uncaught exception:', error);
|
|
294
|
+
shutdown('uncaughtException').catch(() => process.exit(1));
|
|
295
|
+
});
|
|
296
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
297
|
+
logger.error('Unhandled rejection at:', promise, 'reason:', reason);
|
|
298
|
+
shutdown('unhandledRejection').catch(() => process.exit(1));
|
|
299
|
+
});
|
|
300
|
+
// Start the agent
|
|
301
|
+
await agent.start();
|
|
302
|
+
console.log('BuildHive Agent started successfully');
|
|
303
|
+
console.log(`PID: ${process.pid}`);
|
|
304
|
+
console.log('Press Ctrl+C to stop\n');
|
|
305
|
+
// Keep process alive
|
|
306
|
+
if (!options.daemon) {
|
|
307
|
+
setInterval(() => {
|
|
308
|
+
// Keep alive
|
|
309
|
+
}, 1000);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
console.error('\n✗ Failed to start agent:', error instanceof Error ? error.message : error);
|
|
314
|
+
process.exit(1);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
/**
|
|
318
|
+
* Stop command - Stop the agent (for daemon mode)
|
|
319
|
+
*/
|
|
320
|
+
program
|
|
321
|
+
.command('stop')
|
|
322
|
+
.description('Stop the BuildHive agent daemon')
|
|
323
|
+
.action(async () => {
|
|
324
|
+
try {
|
|
325
|
+
const pidFile = join(os.homedir(), '.buildhive', 'agent.pid');
|
|
326
|
+
// Check if PID file exists
|
|
327
|
+
try {
|
|
328
|
+
await fs.access(pidFile);
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
console.error('Agent is not running (PID file not found)');
|
|
332
|
+
process.exit(1);
|
|
333
|
+
}
|
|
334
|
+
// Read PID from file
|
|
335
|
+
const pidContent = await fs.readFile(pidFile, 'utf-8');
|
|
336
|
+
const pid = parseInt(pidContent.trim());
|
|
337
|
+
if (isNaN(pid)) {
|
|
338
|
+
console.error('Invalid PID file content');
|
|
339
|
+
await fs.unlink(pidFile); // Clean up invalid PID file
|
|
340
|
+
process.exit(1);
|
|
341
|
+
}
|
|
342
|
+
// Check if process exists
|
|
343
|
+
try {
|
|
344
|
+
process.kill(pid, 0); // Signal 0 checks if process exists
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
if (error.code === 'ESRCH') {
|
|
348
|
+
console.log('Agent process not found, cleaning up PID file');
|
|
349
|
+
await fs.unlink(pidFile);
|
|
350
|
+
process.exit(0);
|
|
351
|
+
}
|
|
352
|
+
throw error;
|
|
353
|
+
}
|
|
354
|
+
// Send SIGTERM to gracefully stop the agent
|
|
355
|
+
console.log(`Stopping BuildHive Agent (PID: ${pid})...`);
|
|
356
|
+
process.kill(pid, 'SIGTERM');
|
|
357
|
+
// Wait for process to stop
|
|
358
|
+
let attempts = 0;
|
|
359
|
+
const maxAttempts = 30; // Wait up to 15 seconds
|
|
360
|
+
while (attempts < maxAttempts) {
|
|
361
|
+
try {
|
|
362
|
+
process.kill(pid, 0);
|
|
363
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
364
|
+
attempts++;
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
if (error.code === 'ESRCH') {
|
|
368
|
+
// Process stopped
|
|
369
|
+
await fs.unlink(pidFile);
|
|
370
|
+
console.log('✓ Agent stopped successfully');
|
|
371
|
+
process.exit(0);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
// If still running after timeout, force kill
|
|
376
|
+
console.warn('Agent did not stop gracefully, forcing shutdown...');
|
|
377
|
+
process.kill(pid, 'SIGKILL');
|
|
378
|
+
await fs.unlink(pidFile);
|
|
379
|
+
console.log('✓ Agent stopped (forced)');
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
console.error('\n✗ Failed to stop agent:', error instanceof Error ? error.message : error);
|
|
383
|
+
process.exit(1);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
/**
|
|
387
|
+
* Status command - Show agent status
|
|
388
|
+
*/
|
|
389
|
+
program
|
|
390
|
+
.command('status')
|
|
391
|
+
.description('Show agent status')
|
|
392
|
+
.option('-c, --config <path>', 'Configuration file path')
|
|
393
|
+
.action(async (options) => {
|
|
394
|
+
try {
|
|
395
|
+
const config = await loadConfig();
|
|
396
|
+
console.log('=== BuildHive Agent Status ===\n');
|
|
397
|
+
console.log(`Name: ${config.name}`);
|
|
398
|
+
console.log(`Agent ID: ${config.agentId}`);
|
|
399
|
+
console.log(`Platform: ${config.platformUrl}`);
|
|
400
|
+
console.log(`Max Concurrent Jobs: ${config.maxConcurrentJobs}`);
|
|
401
|
+
console.log(`Tags: ${config.tags.join(', ')}`);
|
|
402
|
+
console.log('\nConfiguration:');
|
|
403
|
+
console.log(` Heartbeat Interval: ${config.heartbeatInterval}s`);
|
|
404
|
+
console.log(` Job Timeout: ${config.jobTimeoutMinutes}m`);
|
|
405
|
+
console.log(` Log Level: ${config.logLevel}`);
|
|
406
|
+
console.log(` Metrics Enabled: ${config.enableMetrics ? 'Yes' : 'No'}`);
|
|
407
|
+
// Check if agent is running
|
|
408
|
+
const pidFile = join(os.homedir(), '.buildhive', 'agent.pid');
|
|
409
|
+
let isRunning = false;
|
|
410
|
+
let pid = null;
|
|
411
|
+
try {
|
|
412
|
+
const pidContent = await fs.readFile(pidFile, 'utf-8');
|
|
413
|
+
pid = parseInt(pidContent.trim());
|
|
414
|
+
if (!isNaN(pid)) {
|
|
415
|
+
try {
|
|
416
|
+
process.kill(pid, 0); // Check if process exists
|
|
417
|
+
isRunning = true;
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
if (error.code === 'ESRCH') {
|
|
421
|
+
// Process not found, clean up stale PID file
|
|
422
|
+
await fs.unlink(pidFile);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
// PID file doesn't exist or couldn't be read
|
|
429
|
+
}
|
|
430
|
+
console.log(`\nRunning: ${isRunning ? `Yes (PID: ${pid})` : 'No'}`);
|
|
431
|
+
if (!isRunning) {
|
|
432
|
+
console.log('\nTo start the agent, run: buildhive-agent start');
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
console.error('\n✗ Failed to get status:', error instanceof Error ? error.message : error);
|
|
437
|
+
process.exit(1);
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
/**
|
|
441
|
+
* Config command - Show or edit configuration
|
|
442
|
+
*/
|
|
443
|
+
program
|
|
444
|
+
.command('config')
|
|
445
|
+
.description('Show configuration')
|
|
446
|
+
.option('-c, --config <path>', 'Configuration file path')
|
|
447
|
+
.option('--show', 'Show full configuration (default)')
|
|
448
|
+
.action(async (options) => {
|
|
449
|
+
try {
|
|
450
|
+
const configPath = options.config ||
|
|
451
|
+
join(os.homedir(), '.buildhive', 'buildhive-agent.json');
|
|
452
|
+
// Check if config exists
|
|
453
|
+
try {
|
|
454
|
+
await fs.access(configPath);
|
|
455
|
+
}
|
|
456
|
+
catch {
|
|
457
|
+
console.error(`Configuration file not found: ${configPath}`);
|
|
458
|
+
console.log('\nRegister the agent first with: buildhive-agent register');
|
|
459
|
+
process.exit(1);
|
|
460
|
+
}
|
|
461
|
+
// Read and display config
|
|
462
|
+
const configContent = await fs.readFile(configPath, 'utf8');
|
|
463
|
+
const config = JSON.parse(configContent);
|
|
464
|
+
console.log('=== BuildHive Agent Configuration ===\n');
|
|
465
|
+
console.log(`Config file: ${configPath}\n`);
|
|
466
|
+
// Mask sensitive fields
|
|
467
|
+
const displayConfig = { ...config };
|
|
468
|
+
if (displayConfig.apiKey) {
|
|
469
|
+
displayConfig.apiKey = '****' + displayConfig.apiKey.slice(-4);
|
|
470
|
+
}
|
|
471
|
+
console.log(JSON.stringify(displayConfig, null, 2));
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
console.error('\n✗ Failed to read configuration:', error instanceof Error ? error.message : error);
|
|
475
|
+
process.exit(1);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
/**
|
|
479
|
+
* Test command - Test connection to platform
|
|
480
|
+
*/
|
|
481
|
+
program
|
|
482
|
+
.command('test')
|
|
483
|
+
.description('Test connection to BuildHive platform')
|
|
484
|
+
.option('-c, --config <path>', 'Configuration file path')
|
|
485
|
+
.action(async (options) => {
|
|
486
|
+
try {
|
|
487
|
+
console.log('Testing connection to BuildHive platform...\n');
|
|
488
|
+
const config = await loadConfig();
|
|
489
|
+
const { BuildHiveApiClient } = await import('./registration/apiClient.js');
|
|
490
|
+
const apiClient = new BuildHiveApiClient(config.platformUrl);
|
|
491
|
+
const connected = await apiClient.testConnection();
|
|
492
|
+
if (connected) {
|
|
493
|
+
console.log('✓ Successfully connected to BuildHive platform');
|
|
494
|
+
console.log(` URL: ${config.platformUrl}`);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
console.error('✗ Failed to connect to BuildHive platform');
|
|
498
|
+
console.error(` URL: ${config.platformUrl}`);
|
|
499
|
+
process.exit(1);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
console.error('\n✗ Connection test failed:', error instanceof Error ? error.message : error);
|
|
504
|
+
process.exit(1);
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
/**
|
|
508
|
+
* Logs command - View agent logs
|
|
509
|
+
*/
|
|
510
|
+
program
|
|
511
|
+
.command('logs')
|
|
512
|
+
.description('View BuildHive agent logs')
|
|
513
|
+
.option('-f, --follow', 'Follow log output (like tail -f)')
|
|
514
|
+
.option('-n, --lines <number>', 'Number of lines to show', '50')
|
|
515
|
+
.action(async (options) => {
|
|
516
|
+
try {
|
|
517
|
+
const logFile = join(os.homedir(), '.buildhive', 'logs', 'buildhive-agent.log');
|
|
518
|
+
// Check if log file exists
|
|
519
|
+
try {
|
|
520
|
+
await fs.access(logFile);
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
console.error(`Log file not found: ${logFile}`);
|
|
524
|
+
console.log('\nThe agent may not have been started yet.');
|
|
525
|
+
process.exit(1);
|
|
526
|
+
}
|
|
527
|
+
const numLines = parseInt(options.lines);
|
|
528
|
+
if (options.follow) {
|
|
529
|
+
// Follow mode: Use tail -f equivalent
|
|
530
|
+
console.log(`Following logs from: ${logFile}`);
|
|
531
|
+
console.log('Press Ctrl+C to stop\n');
|
|
532
|
+
const { spawn } = await import('child_process');
|
|
533
|
+
const tail = spawn('tail', ['-f', '-n', numLines.toString(), logFile]);
|
|
534
|
+
tail.stdout.on('data', (data) => {
|
|
535
|
+
process.stdout.write(data);
|
|
536
|
+
});
|
|
537
|
+
tail.stderr.on('data', (data) => {
|
|
538
|
+
process.stderr.write(data);
|
|
539
|
+
});
|
|
540
|
+
tail.on('close', (code) => {
|
|
541
|
+
process.exit(code || 0);
|
|
542
|
+
});
|
|
543
|
+
// Handle Ctrl+C
|
|
544
|
+
process.on('SIGINT', () => {
|
|
545
|
+
tail.kill();
|
|
546
|
+
process.exit(0);
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
// Show last N lines
|
|
551
|
+
const logContent = await fs.readFile(logFile, 'utf-8');
|
|
552
|
+
const lines = logContent.split('\n');
|
|
553
|
+
const displayLines = lines.slice(-numLines);
|
|
554
|
+
console.log(`Last ${numLines} lines from: ${logFile}\n`);
|
|
555
|
+
displayLines.forEach(line => {
|
|
556
|
+
if (line.trim()) {
|
|
557
|
+
console.log(line);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
catch (error) {
|
|
563
|
+
console.error('\n✗ Failed to read logs:', error instanceof Error ? error.message : error);
|
|
564
|
+
process.exit(1);
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
/**
|
|
568
|
+
* Doctor command — comprehensive health check for agent readiness
|
|
569
|
+
*/
|
|
570
|
+
program
|
|
571
|
+
.command('doctor')
|
|
572
|
+
.description('Run diagnostic checks on the agent environment')
|
|
573
|
+
.action(async () => {
|
|
574
|
+
console.log('BuildHive Agent Doctor\n');
|
|
575
|
+
console.log('Running diagnostic checks...\n');
|
|
576
|
+
const checks = [];
|
|
577
|
+
// 1. Node.js version
|
|
578
|
+
const nodeVersion = process.versions.node;
|
|
579
|
+
const nodeMajor = parseInt(nodeVersion.split('.')[0]);
|
|
580
|
+
checks.push({
|
|
581
|
+
name: 'Node.js version',
|
|
582
|
+
status: nodeMajor >= 18 ? 'pass' : 'fail',
|
|
583
|
+
detail: nodeMajor >= 18 ? `v${nodeVersion} (>= 18 required)` : `v${nodeVersion} — upgrade to >= 18`,
|
|
584
|
+
});
|
|
585
|
+
// 2. Docker installed
|
|
586
|
+
let dockerVersion = '';
|
|
587
|
+
try {
|
|
588
|
+
const { execSync } = await import('child_process');
|
|
589
|
+
dockerVersion = execSync('docker --version', { timeout: 5000 }).toString().trim();
|
|
590
|
+
checks.push({ name: 'Docker installed', status: 'pass', detail: dockerVersion });
|
|
591
|
+
}
|
|
592
|
+
catch {
|
|
593
|
+
checks.push({ name: 'Docker installed', status: 'fail', detail: 'Docker not found. Install: https://docs.docker.com/get-docker/' });
|
|
594
|
+
}
|
|
595
|
+
// 3. Docker daemon running
|
|
596
|
+
if (dockerVersion) {
|
|
597
|
+
try {
|
|
598
|
+
const { execSync } = await import('child_process');
|
|
599
|
+
execSync('docker info', { timeout: 10000, stdio: 'pipe' });
|
|
600
|
+
checks.push({ name: 'Docker daemon running', status: 'pass', detail: 'Docker daemon is responsive' });
|
|
601
|
+
}
|
|
602
|
+
catch {
|
|
603
|
+
checks.push({ name: 'Docker daemon running', status: 'fail', detail: 'Docker daemon not running. Start Docker Desktop or run: sudo systemctl start docker' });
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
// 4. Config file exists
|
|
607
|
+
let configLoaded = false;
|
|
608
|
+
try {
|
|
609
|
+
const config = await loadConfig();
|
|
610
|
+
configLoaded = true;
|
|
611
|
+
checks.push({ name: 'Config file', status: 'pass', detail: `Loaded — agent: ${config.name || config.agentId}` });
|
|
612
|
+
// 5. Platform URL reachable
|
|
613
|
+
try {
|
|
614
|
+
const { default: axios } = await import('axios');
|
|
615
|
+
const resp = await axios.get(`${config.platformUrl}/health/live`, { timeout: 5000 });
|
|
616
|
+
checks.push({ name: 'Platform connectivity', status: 'pass', detail: `${config.platformUrl} — ${resp.data?.status || 'OK'}` });
|
|
617
|
+
}
|
|
618
|
+
catch (err) {
|
|
619
|
+
checks.push({ name: 'Platform connectivity', status: 'fail', detail: `Cannot reach ${config.platformUrl} — ${err.code || err.message}` });
|
|
620
|
+
}
|
|
621
|
+
// 6. API key configured
|
|
622
|
+
if (config.apiKey && config.apiKey.length > 10) {
|
|
623
|
+
checks.push({ name: 'API key configured', status: 'pass', detail: `Key: ****${config.apiKey.slice(-4)}` });
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
checks.push({ name: 'API key configured', status: 'fail', detail: 'No API key. Run: buildhive-agent init' });
|
|
627
|
+
}
|
|
628
|
+
// 7. Agent ID set
|
|
629
|
+
if (config.agentId) {
|
|
630
|
+
checks.push({ name: 'Agent ID', status: 'pass', detail: config.agentId });
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
checks.push({ name: 'Agent ID', status: 'fail', detail: 'No agent ID. Run: buildhive-agent register' });
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
catch {
|
|
637
|
+
checks.push({ name: 'Config file', status: 'fail', detail: 'No config found. Run: buildhive-agent init' });
|
|
638
|
+
}
|
|
639
|
+
// 8. Disk space
|
|
640
|
+
try {
|
|
641
|
+
const si = await import('systeminformation');
|
|
642
|
+
const disks = await si.fsSize();
|
|
643
|
+
const rootDisk = disks.find(d => d.mount === '/' || d.mount === 'C:\\') || disks[0];
|
|
644
|
+
if (rootDisk) {
|
|
645
|
+
const freeGB = rootDisk.available / (1024 ** 3);
|
|
646
|
+
checks.push({
|
|
647
|
+
name: 'Disk space',
|
|
648
|
+
status: freeGB > 10 ? 'pass' : freeGB > 5 ? 'warn' : 'fail',
|
|
649
|
+
detail: `${freeGB.toFixed(1)} GB free${freeGB < 10 ? ' (recommend > 10 GB)' : ''}`,
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
catch {
|
|
654
|
+
checks.push({ name: 'Disk space', status: 'warn', detail: 'Could not check disk space' });
|
|
655
|
+
}
|
|
656
|
+
// 9. Memory
|
|
657
|
+
const totalMemGB = os.totalmem() / (1024 ** 3);
|
|
658
|
+
const freeMemGB = os.freemem() / (1024 ** 3);
|
|
659
|
+
checks.push({
|
|
660
|
+
name: 'Memory',
|
|
661
|
+
status: freeMemGB > 2 ? 'pass' : freeMemGB > 1 ? 'warn' : 'fail',
|
|
662
|
+
detail: `${freeMemGB.toFixed(1)} GB free / ${totalMemGB.toFixed(1)} GB total`,
|
|
663
|
+
});
|
|
664
|
+
// 10. Log directory writable
|
|
665
|
+
try {
|
|
666
|
+
const logDir = join(os.homedir(), '.buildhive', 'logs');
|
|
667
|
+
await fs.mkdir(logDir, { recursive: true });
|
|
668
|
+
const testFile = join(logDir, '.doctor-test');
|
|
669
|
+
await fs.writeFile(testFile, 'test', 'utf-8');
|
|
670
|
+
await fs.unlink(testFile);
|
|
671
|
+
checks.push({ name: 'Log directory', status: 'pass', detail: logDir });
|
|
672
|
+
}
|
|
673
|
+
catch {
|
|
674
|
+
checks.push({ name: 'Log directory', status: 'fail', detail: 'Cannot write to ~/.buildhive/logs/' });
|
|
675
|
+
}
|
|
676
|
+
// 11. Agent already running?
|
|
677
|
+
try {
|
|
678
|
+
const pidFile = join(os.homedir(), '.buildhive', 'agent.pid');
|
|
679
|
+
const pidContent = await fs.readFile(pidFile, 'utf-8');
|
|
680
|
+
const pid = parseInt(pidContent.trim());
|
|
681
|
+
try {
|
|
682
|
+
process.kill(pid, 0);
|
|
683
|
+
checks.push({ name: 'Agent process', status: 'pass', detail: `Running (PID ${pid})` });
|
|
684
|
+
}
|
|
685
|
+
catch {
|
|
686
|
+
checks.push({ name: 'Agent process', status: 'warn', detail: `Stale PID file (PID ${pid} not found)` });
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
catch {
|
|
690
|
+
checks.push({ name: 'Agent process', status: 'warn', detail: 'Not running' });
|
|
691
|
+
}
|
|
692
|
+
// 12. SDK detection
|
|
693
|
+
try {
|
|
694
|
+
const { execSync } = await import('child_process');
|
|
695
|
+
const sdks = [];
|
|
696
|
+
const trySDK = (cmd, name) => {
|
|
697
|
+
try {
|
|
698
|
+
execSync(`${cmd} --version`, { timeout: 3000, stdio: 'pipe' });
|
|
699
|
+
sdks.push(name);
|
|
700
|
+
}
|
|
701
|
+
catch { /* skip */ }
|
|
702
|
+
};
|
|
703
|
+
trySDK('node', 'Node.js');
|
|
704
|
+
trySDK('java', 'Java');
|
|
705
|
+
trySDK('python3', 'Python');
|
|
706
|
+
trySDK('go', 'Go');
|
|
707
|
+
trySDK('rustc', 'Rust');
|
|
708
|
+
trySDK('dotnet', '.NET');
|
|
709
|
+
trySDK('gradle', 'Gradle');
|
|
710
|
+
trySDK('mvn', 'Maven');
|
|
711
|
+
checks.push({ name: 'SDKs detected', status: sdks.length > 0 ? 'pass' : 'warn', detail: sdks.join(', ') || 'None' });
|
|
712
|
+
}
|
|
713
|
+
catch {
|
|
714
|
+
checks.push({ name: 'SDKs detected', status: 'warn', detail: 'Could not detect SDKs' });
|
|
715
|
+
}
|
|
716
|
+
// --- Print results ---
|
|
717
|
+
const icons = { pass: '✓', fail: '✗', warn: '!' };
|
|
718
|
+
const colors = { pass: '\x1b[32m', fail: '\x1b[31m', warn: '\x1b[33m' };
|
|
719
|
+
const reset = '\x1b[0m';
|
|
720
|
+
let failures = 0;
|
|
721
|
+
let warnings = 0;
|
|
722
|
+
for (const check of checks) {
|
|
723
|
+
const icon = icons[check.status];
|
|
724
|
+
const color = colors[check.status];
|
|
725
|
+
console.log(` ${color}${icon}${reset} ${check.name}: ${check.detail}`);
|
|
726
|
+
if (check.status === 'fail')
|
|
727
|
+
failures++;
|
|
728
|
+
if (check.status === 'warn')
|
|
729
|
+
warnings++;
|
|
730
|
+
}
|
|
731
|
+
console.log('');
|
|
732
|
+
if (failures === 0 && warnings === 0) {
|
|
733
|
+
console.log('\x1b[32m✓ All checks passed — agent is ready to run!\x1b[0m');
|
|
734
|
+
}
|
|
735
|
+
else if (failures === 0) {
|
|
736
|
+
console.log(`\x1b[33m! ${warnings} warning(s) — agent can run but review above.\x1b[0m`);
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
console.log(`\x1b[31m✗ ${failures} check(s) failed — fix before starting agent.\x1b[0m`);
|
|
740
|
+
}
|
|
741
|
+
process.exit(failures > 0 ? 1 : 0);
|
|
742
|
+
});
|
|
743
|
+
// Parse command line arguments
|
|
744
|
+
program.parse();
|
|
745
|
+
// Show help if no command provided
|
|
746
|
+
if (!process.argv.slice(2).length) {
|
|
747
|
+
program.outputHelp();
|
|
748
|
+
}
|
|
749
|
+
//# sourceMappingURL=cli.js.map
|