nexusforge-cli 1.0.0
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/bin/nexusforge +2 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +367 -0
- package/dist/index.js.map +1 -0
- package/dist/services/api.d.ts +51 -0
- package/dist/services/api.d.ts.map +1 -0
- package/dist/services/api.js +143 -0
- package/dist/services/api.js.map +1 -0
- package/dist/services/auth.d.ts +30 -0
- package/dist/services/auth.d.ts.map +1 -0
- package/dist/services/auth.js +180 -0
- package/dist/services/auth.js.map +1 -0
- package/dist/services/executor.d.ts +36 -0
- package/dist/services/executor.d.ts.map +1 -0
- package/dist/services/executor.js +206 -0
- package/dist/services/executor.js.map +1 -0
- package/dist/types/index.d.ts +85 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/config.d.ts +60 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +149 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/theme.d.ts +78 -0
- package/dist/utils/theme.d.ts.map +1 -0
- package/dist/utils/theme.js +140 -0
- package/dist/utils/theme.js.map +1 -0
- package/package.json +57 -0
- package/src/index.ts +427 -0
- package/src/services/api.ts +198 -0
- package/src/services/auth.ts +222 -0
- package/src/services/executor.ts +250 -0
- package/src/types/index.ts +104 -0
- package/src/utils/config.ts +172 -0
- package/src/utils/theme.ts +163 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NexusForge CLI Authentication Service
|
|
3
|
+
*
|
|
4
|
+
* Handles device authorization flow (like Claude Code):
|
|
5
|
+
* 1. CLI requests device code
|
|
6
|
+
* 2. CLI displays verification URL
|
|
7
|
+
* 3. User opens URL in browser and authorizes
|
|
8
|
+
* 4. CLI polls for authorization
|
|
9
|
+
* 5. CLI saves token on success
|
|
10
|
+
*/
|
|
11
|
+
import open from 'open';
|
|
12
|
+
import ora from 'ora';
|
|
13
|
+
import { style, displaySystemMessage } from '../utils/theme.js';
|
|
14
|
+
import * as config from '../utils/config.js';
|
|
15
|
+
const POLL_INTERVAL_MS = 5000; // 5 seconds
|
|
16
|
+
const MAX_POLL_ATTEMPTS = 180; // 15 minutes max
|
|
17
|
+
/**
|
|
18
|
+
* Start the device authorization flow
|
|
19
|
+
*/
|
|
20
|
+
export async function startDeviceAuth() {
|
|
21
|
+
const apiUrl = config.getApiUrl();
|
|
22
|
+
console.log('');
|
|
23
|
+
displaySystemMessage('Starting authentication...', 'info');
|
|
24
|
+
console.log('');
|
|
25
|
+
try {
|
|
26
|
+
// Step 1: Request device code
|
|
27
|
+
const deviceCodeResponse = await requestDeviceCode(apiUrl);
|
|
28
|
+
// Step 2: Display verification URL
|
|
29
|
+
console.log(style.divider());
|
|
30
|
+
console.log('');
|
|
31
|
+
console.log(style.assistant(' To authenticate, open this URL in your browser:'));
|
|
32
|
+
console.log('');
|
|
33
|
+
console.log(style.prompt(` ${deviceCodeResponse.verification_uri_complete}`));
|
|
34
|
+
console.log('');
|
|
35
|
+
console.log(style.muted(` Or go to ${deviceCodeResponse.verification_uri}`));
|
|
36
|
+
console.log(style.muted(` and enter code: ${style.prompt(deviceCodeResponse.user_code)}`));
|
|
37
|
+
console.log('');
|
|
38
|
+
console.log(style.divider());
|
|
39
|
+
console.log('');
|
|
40
|
+
// Try to open browser automatically
|
|
41
|
+
try {
|
|
42
|
+
await open(deviceCodeResponse.verification_uri_complete);
|
|
43
|
+
displaySystemMessage('Browser opened automatically', 'info');
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
displaySystemMessage('Could not open browser. Please copy the URL above.', 'warning');
|
|
47
|
+
}
|
|
48
|
+
console.log('');
|
|
49
|
+
// Step 3: Poll for authorization
|
|
50
|
+
const spinner = ora({
|
|
51
|
+
text: 'Waiting for authorization...',
|
|
52
|
+
color: 'cyan',
|
|
53
|
+
}).start();
|
|
54
|
+
const authResult = await pollForAuthorization(apiUrl, deviceCodeResponse.device_code, deviceCodeResponse.interval * 1000, spinner);
|
|
55
|
+
if (authResult) {
|
|
56
|
+
spinner.succeed(style.success('Authenticated successfully!'));
|
|
57
|
+
// Save auth data
|
|
58
|
+
config.saveAuth({
|
|
59
|
+
accessToken: authResult.access_token,
|
|
60
|
+
refreshToken: authResult.refresh_token,
|
|
61
|
+
userId: authResult.user?.id,
|
|
62
|
+
username: authResult.user?.username,
|
|
63
|
+
email: authResult.user?.email,
|
|
64
|
+
});
|
|
65
|
+
console.log('');
|
|
66
|
+
displaySystemMessage(`Welcome, ${authResult.user?.username || 'user'}!`, 'success');
|
|
67
|
+
console.log('');
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
spinner.fail(style.error('Authentication failed or timed out'));
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
77
|
+
displaySystemMessage(`Authentication error: ${errorMessage}`, 'error');
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Request a device code from the API
|
|
83
|
+
*/
|
|
84
|
+
async function requestDeviceCode(apiUrl) {
|
|
85
|
+
const response = await fetch(`${apiUrl}/cli/auth/device`, {
|
|
86
|
+
method: 'POST',
|
|
87
|
+
headers: {
|
|
88
|
+
'Content-Type': 'application/json',
|
|
89
|
+
},
|
|
90
|
+
body: JSON.stringify({ client_id: 'nexusforge-cli' }),
|
|
91
|
+
});
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
throw new Error(`Failed to get device code: ${response.statusText}`);
|
|
94
|
+
}
|
|
95
|
+
return response.json();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Poll for authorization status
|
|
99
|
+
*/
|
|
100
|
+
async function pollForAuthorization(apiUrl, deviceCode, intervalMs, spinner) {
|
|
101
|
+
let attempts = 0;
|
|
102
|
+
while (attempts < MAX_POLL_ATTEMPTS) {
|
|
103
|
+
attempts++;
|
|
104
|
+
await sleep(intervalMs);
|
|
105
|
+
try {
|
|
106
|
+
const response = await fetch(`${apiUrl}/cli/auth/device/${deviceCode}`);
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const status = await response.json();
|
|
111
|
+
switch (status.status) {
|
|
112
|
+
case 'authorized':
|
|
113
|
+
return status;
|
|
114
|
+
case 'denied':
|
|
115
|
+
spinner.fail(style.error('Authorization denied by user'));
|
|
116
|
+
return null;
|
|
117
|
+
case 'expired':
|
|
118
|
+
spinner.fail(style.error('Authorization code expired'));
|
|
119
|
+
return null;
|
|
120
|
+
case 'pending':
|
|
121
|
+
// Keep polling
|
|
122
|
+
spinner.text = `Waiting for authorization... (${Math.floor(attempts * intervalMs / 1000)}s)`;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Network error, keep trying
|
|
128
|
+
spinner.text = 'Waiting for authorization... (connection issue, retrying)';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Check if current token is valid
|
|
135
|
+
*/
|
|
136
|
+
export async function checkAuth() {
|
|
137
|
+
const token = config.getAccessToken();
|
|
138
|
+
if (!token) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
const apiUrl = config.getApiUrl();
|
|
142
|
+
try {
|
|
143
|
+
// Try to get user info with current token
|
|
144
|
+
const response = await fetch(`${apiUrl}/auth/me`, {
|
|
145
|
+
headers: {
|
|
146
|
+
Authorization: `Bearer ${token}`,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
return response.ok;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Logout - clear stored credentials
|
|
157
|
+
*/
|
|
158
|
+
export function logout() {
|
|
159
|
+
config.clearAuth();
|
|
160
|
+
displaySystemMessage('Logged out successfully', 'success');
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get current user info
|
|
164
|
+
*/
|
|
165
|
+
export function getCurrentUser() {
|
|
166
|
+
if (!config.isAuthenticated()) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
username: config.get('username'),
|
|
171
|
+
email: config.get('email'),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Sleep helper
|
|
176
|
+
*/
|
|
177
|
+
function sleep(ms) {
|
|
178
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/services/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAC;AAG7C,MAAM,gBAAgB,GAAG,IAAI,CAAC,CAAC,YAAY;AAC3C,MAAM,iBAAiB,GAAG,GAAG,CAAC,CAAC,iBAAiB;AAEhD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAElC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,oBAAoB,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,EAAE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AO;QACL,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;QAChC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC;KAC3B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NexusForge CLI Command Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes shell commands and streams output.
|
|
5
|
+
* Provides Claude Code-like command execution capabilities.
|
|
6
|
+
*/
|
|
7
|
+
import type { CommandResult } from '../types/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Check if a command is potentially dangerous
|
|
10
|
+
*/
|
|
11
|
+
export declare function isDangerous(command: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Execute a command and return the result
|
|
14
|
+
*/
|
|
15
|
+
export declare function executeCommand(command: string, cwd?: string): Promise<CommandResult>;
|
|
16
|
+
/**
|
|
17
|
+
* Execute a command with streaming output
|
|
18
|
+
*/
|
|
19
|
+
export declare function executeCommandStream(command: string, cwd?: string, onStdout?: (data: string) => void, onStderr?: (data: string) => void): Promise<CommandResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Display command result in terminal
|
|
22
|
+
*/
|
|
23
|
+
export declare function displayCommandResult(result: CommandResult): void;
|
|
24
|
+
/**
|
|
25
|
+
* Parse AI response for executable commands
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseCommandsFromResponse(content: string): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Get current working directory
|
|
30
|
+
*/
|
|
31
|
+
export declare function getCwd(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Change working directory
|
|
34
|
+
*/
|
|
35
|
+
export declare function changeCwd(path: string): boolean;
|
|
36
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../src/services/executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAuBvD;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAUpD;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,aAAa,CAAC,CAkDxB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,MAAM,EACf,GAAG,CAAC,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EACjC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAChC,OAAO,CAAC,aAAa,CAAC,CAmExB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAmBhE;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBnE;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAE/B;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAO/C"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NexusForge CLI Command Executor
|
|
3
|
+
*
|
|
4
|
+
* Executes shell commands and streams output.
|
|
5
|
+
* Provides Claude Code-like command execution capabilities.
|
|
6
|
+
*/
|
|
7
|
+
import { spawn, exec } from 'child_process';
|
|
8
|
+
import { promisify } from 'util';
|
|
9
|
+
import { style, displaySystemMessage } from '../utils/theme.js';
|
|
10
|
+
import * as api from './api.js';
|
|
11
|
+
const execAsync = promisify(exec);
|
|
12
|
+
// Dangerous commands that should be blocked or warned
|
|
13
|
+
const DANGEROUS_COMMANDS = [
|
|
14
|
+
'rm -rf /',
|
|
15
|
+
'rm -rf ~',
|
|
16
|
+
'rm -rf *',
|
|
17
|
+
'mkfs',
|
|
18
|
+
':(){:|:&};:',
|
|
19
|
+
'dd if=/dev/zero',
|
|
20
|
+
'chmod -R 777 /',
|
|
21
|
+
'> /dev/sda',
|
|
22
|
+
];
|
|
23
|
+
const DANGEROUS_PATTERNS = [
|
|
24
|
+
/rm\s+-rf\s+\/(?!\w)/,
|
|
25
|
+
/curl.*\|.*(?:bash|sh)/,
|
|
26
|
+
/wget.*\|.*(?:bash|sh)/,
|
|
27
|
+
/>\s*\/dev\/sd/,
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Check if a command is potentially dangerous
|
|
31
|
+
*/
|
|
32
|
+
export function isDangerous(command) {
|
|
33
|
+
const normalizedCmd = command.toLowerCase().trim();
|
|
34
|
+
// Check exact matches
|
|
35
|
+
if (DANGEROUS_COMMANDS.some((dangerous) => normalizedCmd.includes(dangerous))) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
// Check patterns
|
|
39
|
+
return DANGEROUS_PATTERNS.some((pattern) => pattern.test(command));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Execute a command and return the result
|
|
43
|
+
*/
|
|
44
|
+
export async function executeCommand(command, cwd) {
|
|
45
|
+
const startTime = Date.now();
|
|
46
|
+
const workingDir = cwd || process.cwd();
|
|
47
|
+
try {
|
|
48
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
49
|
+
cwd: workingDir,
|
|
50
|
+
timeout: 300000, // 5 minute timeout
|
|
51
|
+
maxBuffer: 10 * 1024 * 1024, // 10MB buffer
|
|
52
|
+
});
|
|
53
|
+
const duration = Date.now() - startTime;
|
|
54
|
+
// Log to API (fire and forget)
|
|
55
|
+
api.logCommandExecution({
|
|
56
|
+
command,
|
|
57
|
+
workingDirectory: workingDir,
|
|
58
|
+
exitCode: 0,
|
|
59
|
+
output: stdout.substring(0, 1000),
|
|
60
|
+
duration,
|
|
61
|
+
}).catch(() => { });
|
|
62
|
+
return {
|
|
63
|
+
command,
|
|
64
|
+
exitCode: 0,
|
|
65
|
+
stdout,
|
|
66
|
+
stderr,
|
|
67
|
+
duration,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const duration = Date.now() - startTime;
|
|
72
|
+
const execError = error;
|
|
73
|
+
// Log to API
|
|
74
|
+
api.logCommandExecution({
|
|
75
|
+
command,
|
|
76
|
+
workingDirectory: workingDir,
|
|
77
|
+
exitCode: execError.code || 1,
|
|
78
|
+
output: execError.stderr?.substring(0, 1000),
|
|
79
|
+
duration,
|
|
80
|
+
}).catch(() => { });
|
|
81
|
+
return {
|
|
82
|
+
command,
|
|
83
|
+
exitCode: execError.code || 1,
|
|
84
|
+
stdout: execError.stdout || '',
|
|
85
|
+
stderr: execError.stderr || (error instanceof Error ? error.message : 'Unknown error'),
|
|
86
|
+
duration,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Execute a command with streaming output
|
|
92
|
+
*/
|
|
93
|
+
export async function executeCommandStream(command, cwd, onStdout, onStderr) {
|
|
94
|
+
const startTime = Date.now();
|
|
95
|
+
const workingDir = cwd || process.cwd();
|
|
96
|
+
return new Promise((resolve) => {
|
|
97
|
+
// Determine shell based on platform
|
|
98
|
+
const shell = process.platform === 'win32' ? 'cmd.exe' : '/bin/bash';
|
|
99
|
+
const shellArgs = process.platform === 'win32' ? ['/c', command] : ['-c', command];
|
|
100
|
+
const child = spawn(shell, shellArgs, {
|
|
101
|
+
cwd: workingDir,
|
|
102
|
+
env: process.env,
|
|
103
|
+
});
|
|
104
|
+
let stdout = '';
|
|
105
|
+
let stderr = '';
|
|
106
|
+
child.stdout.on('data', (data) => {
|
|
107
|
+
const text = data.toString();
|
|
108
|
+
stdout += text;
|
|
109
|
+
if (onStdout) {
|
|
110
|
+
onStdout(text);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
child.stderr.on('data', (data) => {
|
|
114
|
+
const text = data.toString();
|
|
115
|
+
stderr += text;
|
|
116
|
+
if (onStderr) {
|
|
117
|
+
onStderr(text);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
child.on('close', (code) => {
|
|
121
|
+
const duration = Date.now() - startTime;
|
|
122
|
+
const exitCode = code ?? 0;
|
|
123
|
+
// Log to API
|
|
124
|
+
api.logCommandExecution({
|
|
125
|
+
command,
|
|
126
|
+
workingDirectory: workingDir,
|
|
127
|
+
exitCode,
|
|
128
|
+
output: stdout.substring(0, 1000),
|
|
129
|
+
duration,
|
|
130
|
+
}).catch(() => { });
|
|
131
|
+
resolve({
|
|
132
|
+
command,
|
|
133
|
+
exitCode,
|
|
134
|
+
stdout,
|
|
135
|
+
stderr,
|
|
136
|
+
duration,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
child.on('error', (error) => {
|
|
140
|
+
const duration = Date.now() - startTime;
|
|
141
|
+
resolve({
|
|
142
|
+
command,
|
|
143
|
+
exitCode: 1,
|
|
144
|
+
stdout: '',
|
|
145
|
+
stderr: error.message,
|
|
146
|
+
duration,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Display command result in terminal
|
|
153
|
+
*/
|
|
154
|
+
export function displayCommandResult(result) {
|
|
155
|
+
console.log('');
|
|
156
|
+
console.log(style.muted(`$ ${result.command}`));
|
|
157
|
+
console.log('');
|
|
158
|
+
if (result.stdout) {
|
|
159
|
+
console.log(result.stdout);
|
|
160
|
+
}
|
|
161
|
+
if (result.stderr && result.exitCode !== 0) {
|
|
162
|
+
console.log(style.error(result.stderr));
|
|
163
|
+
}
|
|
164
|
+
const statusColor = result.exitCode === 0 ? 'success' : 'error';
|
|
165
|
+
displaySystemMessage(`Exit code: ${result.exitCode} (${result.duration}ms)`, statusColor);
|
|
166
|
+
console.log('');
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Parse AI response for executable commands
|
|
170
|
+
*/
|
|
171
|
+
export function parseCommandsFromResponse(content) {
|
|
172
|
+
const commands = [];
|
|
173
|
+
// Match code blocks with bash/shell/sh language
|
|
174
|
+
const codeBlockRegex = /```(?:bash|shell|sh|zsh|terminal)\n([\s\S]*?)```/g;
|
|
175
|
+
let match;
|
|
176
|
+
while ((match = codeBlockRegex.exec(content)) !== null) {
|
|
177
|
+
const code = match[1].trim();
|
|
178
|
+
// Split by newlines and filter empty lines
|
|
179
|
+
const lines = code.split('\n').filter((line) => {
|
|
180
|
+
const trimmed = line.trim();
|
|
181
|
+
// Skip comments and empty lines
|
|
182
|
+
return trimmed && !trimmed.startsWith('#');
|
|
183
|
+
});
|
|
184
|
+
commands.push(...lines);
|
|
185
|
+
}
|
|
186
|
+
return commands;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get current working directory
|
|
190
|
+
*/
|
|
191
|
+
export function getCwd() {
|
|
192
|
+
return process.cwd();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Change working directory
|
|
196
|
+
*/
|
|
197
|
+
export function changeCwd(path) {
|
|
198
|
+
try {
|
|
199
|
+
process.chdir(path);
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../src/services/executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC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GAEG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NexusForge CLI Type Definitions
|
|
3
|
+
*/
|
|
4
|
+
export interface CLIConfig {
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
accessToken?: string;
|
|
7
|
+
refreshToken?: string;
|
|
8
|
+
userId?: number;
|
|
9
|
+
username?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
defaultModel: string;
|
|
12
|
+
theme: 'dark' | 'light';
|
|
13
|
+
autoExecute: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface DeviceCodeResponse {
|
|
16
|
+
device_code: string;
|
|
17
|
+
user_code: string;
|
|
18
|
+
verification_uri: string;
|
|
19
|
+
verification_uri_complete: string;
|
|
20
|
+
expires_in: number;
|
|
21
|
+
interval: number;
|
|
22
|
+
}
|
|
23
|
+
export interface DeviceAuthStatus {
|
|
24
|
+
status: 'pending' | 'authorized' | 'expired' | 'denied';
|
|
25
|
+
access_token?: string;
|
|
26
|
+
refresh_token?: string;
|
|
27
|
+
token_type?: string;
|
|
28
|
+
expires_in?: number;
|
|
29
|
+
user?: {
|
|
30
|
+
id: number;
|
|
31
|
+
username: string;
|
|
32
|
+
email: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface CLISession {
|
|
36
|
+
session_id: string;
|
|
37
|
+
session_token: string;
|
|
38
|
+
conversation_id: string;
|
|
39
|
+
expires_at: string;
|
|
40
|
+
user_id: number;
|
|
41
|
+
sync_command: string;
|
|
42
|
+
}
|
|
43
|
+
export interface ChatMessage {
|
|
44
|
+
role: 'user' | 'assistant' | 'system';
|
|
45
|
+
content: string;
|
|
46
|
+
timestamp?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface ChatResponse {
|
|
49
|
+
conversation_id: string;
|
|
50
|
+
message: ChatMessage;
|
|
51
|
+
suggested_actions?: SuggestedAction[];
|
|
52
|
+
}
|
|
53
|
+
export interface SuggestedAction {
|
|
54
|
+
type: 'command' | 'file_edit' | 'file_create' | 'file_read';
|
|
55
|
+
description: string;
|
|
56
|
+
command?: string;
|
|
57
|
+
path?: string;
|
|
58
|
+
content?: string;
|
|
59
|
+
diff?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface FileContext {
|
|
62
|
+
path: string;
|
|
63
|
+
content: string;
|
|
64
|
+
language?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface WSMessage {
|
|
67
|
+
type: 'message' | 'chunk' | 'done' | 'error' | 'ping' | 'pong';
|
|
68
|
+
content?: string;
|
|
69
|
+
conversation_id?: string;
|
|
70
|
+
message?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface SlashCommand {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
aliases?: string[];
|
|
76
|
+
handler: (args: string[]) => Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
export interface CommandResult {
|
|
79
|
+
command: string;
|
|
80
|
+
exitCode: number;
|
|
81
|
+
stdout: string;
|
|
82
|
+
stderr: string;
|
|
83
|
+
duration: number;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,C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
+
/**
|
|
2
|
+
* NexusForge CLI Configuration Manager
|
|
3
|
+
*
|
|
4
|
+
* Stores authentication tokens and settings in ~/.nexusforge/config.json
|
|
5
|
+
*/
|
|
6
|
+
import Conf from 'conf';
|
|
7
|
+
import type { CLIConfig } from '../types/index.js';
|
|
8
|
+
declare const config: Conf<CLIConfig>;
|
|
9
|
+
/**
|
|
10
|
+
* Get the full configuration
|
|
11
|
+
*/
|
|
12
|
+
export declare function getConfig(): CLIConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Get a specific config value
|
|
15
|
+
*/
|
|
16
|
+
export declare function get<K extends keyof CLIConfig>(key: K): CLIConfig[K];
|
|
17
|
+
/**
|
|
18
|
+
* Set a specific config value
|
|
19
|
+
*/
|
|
20
|
+
export declare function set<K extends keyof CLIConfig>(key: K, value: CLIConfig[K]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Check if user is authenticated
|
|
23
|
+
*/
|
|
24
|
+
export declare function isAuthenticated(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Save authentication data after successful login
|
|
27
|
+
*/
|
|
28
|
+
export declare function saveAuth(data: {
|
|
29
|
+
accessToken: string;
|
|
30
|
+
refreshToken?: string;
|
|
31
|
+
userId?: number;
|
|
32
|
+
username?: string;
|
|
33
|
+
email?: string;
|
|
34
|
+
}): void;
|
|
35
|
+
/**
|
|
36
|
+
* Clear authentication data (logout)
|
|
37
|
+
*/
|
|
38
|
+
export declare function clearAuth(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Get the API URL
|
|
41
|
+
*/
|
|
42
|
+
export declare function getApiUrl(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Set the API URL
|
|
45
|
+
*/
|
|
46
|
+
export declare function setApiUrl(url: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Get the access token
|
|
49
|
+
*/
|
|
50
|
+
export declare function getAccessToken(): string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Get the config file path (for debugging)
|
|
53
|
+
*/
|
|
54
|
+
export declare function getConfigPath(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Reset config to defaults
|
|
57
|
+
*/
|
|
58
|
+
export declare function resetConfig(): void;
|
|
59
|
+
export { config };
|
|
60
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AA+CnD,QAAA,MAAM,MAAM,iBAIV,CAAC;AAEH;;GAEG;AACH,wBAAgB,SAAS,IAAI,SAAS,CAYrC;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,GAAG,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEnE;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAEhF;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAGzC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,IAAI,CAeP;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,IAAI,CAMhC;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAE3C;AAED;;GAEG;AACH,wBAAgB,c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