matex-cli 1.1.1 ā 1.1.2
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/dist/index.js +61 -18
- package/dist/index.js.map +1 -1
- package/dist/utils/command-executor.d.ts +10 -1
- package/dist/utils/command-executor.d.ts.map +1 -1
- package/dist/utils/command-executor.js +4 -1
- package/dist/utils/command-executor.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +70 -22
- package/src/utils/command-executor.ts +16 -2
package/dist/index.js
CHANGED
|
@@ -93,24 +93,67 @@ if (args.length > 0 && !args[0].startsWith('-') && !knownCommands.includes(args[
|
|
|
93
93
|
process.exit(1);
|
|
94
94
|
}
|
|
95
95
|
const client = new client_1.MatexAPIClient(apiKey, config_2.configManager.getBaseURL());
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
96
|
+
// Get current directory context
|
|
97
|
+
const fs = require('fs');
|
|
98
|
+
const files = fs.readdirSync(process.cwd()).slice(0, 20).join(', '); // fast list
|
|
99
|
+
const context = `Current directory: ${process.cwd()}\nFiles: ${files}`;
|
|
100
|
+
let messages = [
|
|
101
|
+
{
|
|
102
|
+
role: 'system', content: `You are MATEXCodex, an expert agentic coding assistant.
|
|
103
|
+
1. Your goal is to COMPLETE the user's task.
|
|
104
|
+
2. You can execute shell commands by wrapping them in code blocks (bash, sh, zsh).
|
|
105
|
+
3. PREFER simple one-line shell commands (like 'mkdir', 'touch', 'npm install') over complex scripts.
|
|
106
|
+
4. If you need to create a file, use 'echo "content" > file.js' or similar.
|
|
107
|
+
5. If a command fails, I will send you the error - FIX IT and try again.
|
|
108
|
+
6. Look at the current directory context to avoid "file not found" errors.
|
|
109
|
+
${context}`
|
|
110
|
+
},
|
|
111
|
+
{ role: 'user', content: prompt }
|
|
112
|
+
];
|
|
113
|
+
let loopCount = 0;
|
|
114
|
+
const MAX_LOOPS = 5;
|
|
115
|
+
while (loopCount < MAX_LOOPS) {
|
|
116
|
+
loopCount++;
|
|
117
|
+
spinner_1.spinner.start(loopCount === 1 ? 'Generating plan...' : 'Analyzing result...');
|
|
118
|
+
const response = await client.chat({
|
|
119
|
+
messages,
|
|
120
|
+
model: 'matexcodex',
|
|
121
|
+
temperature: 0.3,
|
|
122
|
+
max_tokens: 8000,
|
|
123
|
+
stream: false,
|
|
124
|
+
});
|
|
125
|
+
spinner_1.spinner.stop();
|
|
126
|
+
// Display response
|
|
127
|
+
console.log(chalk_1.default.cyan(`\nš» MATEXCodex (Step ${loopCount}):\n`));
|
|
128
|
+
console.log(chalk_1.default.white(response));
|
|
129
|
+
console.log();
|
|
130
|
+
// Auto-execute commands (Ollama-style)
|
|
131
|
+
const { executeWithPermission } = await Promise.resolve().then(() => __importStar(require('./utils/command-executor')));
|
|
132
|
+
const result = await executeWithPermission(response);
|
|
133
|
+
if (result.executed) {
|
|
134
|
+
if (result.success) {
|
|
135
|
+
// Success!
|
|
136
|
+
if (loopCount > 1) {
|
|
137
|
+
console.log(chalk_1.default.green('ā
Fix succeeded!'));
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// Failure - Loop back
|
|
143
|
+
console.log(chalk_1.default.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
144
|
+
messages.push({ role: 'assistant', content: response });
|
|
145
|
+
messages.push({
|
|
146
|
+
role: 'user',
|
|
147
|
+
content: `ā Command failed with error:\n${result.error}\n\nPlease fix this. If the file doesn't exist, create it first. Or use a different command.`
|
|
148
|
+
});
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// No command to execute - we are done
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
114
157
|
}
|
|
115
158
|
catch (error) {
|
|
116
159
|
spinner_1.spinner.fail('Failed');
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAkD;AAClD,wCAA4C;AAC5C,0CAA8C;AAC9C,8CAAkD;AAClD,0CAA8C;AAC9C,wCAA4C;AAC5C,2CAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,8CAAkD;AAClD,wCAA4C;AAC5C,0CAA8C;AAC9C,8CAAkD;AAClD,0CAA8C;AAC9C,wCAA4C;AAC5C,2CAA+C;AAC/C,yCAA2D;AAC3D,6CAA0C;AAE1C,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACF,IAAI,CAAC,OAAO,CAAC;KACb,WAAW,CAAC,+EAA+E,CAAC;KAC5F,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,mBAAmB;AACnB,MAAM,MAAM,GAAG;EACb,eAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC;EACvD,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,eAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,eAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,OAAO,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC;EAC7G,eAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC;CACxD,CAAC;AAEF,sBAAsB;AACtB,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EA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AAC,CAAC,CAAC;wBACrE,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;wBACxD,QAAQ,CAAC,IAAI,CAAC;4BACV,IAAI,EAAE,MAAM;4BACZ,OAAO,EAAE,iCAAiC,MAAM,CAAC,KAAK,8FAA8F;yBACvJ,CAAC,CAAC;wBACH,SAAS;oBACb,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,sCAAsC;oBACtC,MAAM;gBACV,CAAC;YACL,CAAC;QACL,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YAClB,iBAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACvB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACL,CAAC,CAAC,EAAE,CAAC;AACT,CAAC;KAAM,CAAC;IACJ,2BAA2B;IAC3B,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5B,mCAAmC;IACnC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpB,OAAO,CAAC,UAAU,EAAE,CAAC;IACzB,CAAC;AACL,CAAC"}
|
|
@@ -22,7 +22,16 @@ export declare function executeCommand(command: string, shell?: string): Promise
|
|
|
22
22
|
/**
|
|
23
23
|
* Execute commands with user permission
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export interface ExecutionResult {
|
|
26
|
+
success: boolean;
|
|
27
|
+
executed: boolean;
|
|
28
|
+
output?: string;
|
|
29
|
+
error?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Execute commands with user permission
|
|
33
|
+
*/
|
|
34
|
+
export declare function executeWithPermission(response: string): Promise<ExecutionResult>;
|
|
26
35
|
/**
|
|
27
36
|
* Command history for undo/rollback
|
|
28
37
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-executor.d.ts","sourceRoot":"","sources":["../../src/utils/command-executor.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,YAAY;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CAsBhE;AA0BD;;GAEG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAoB3E;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAYjH;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"command-executor.d.ts","sourceRoot":"","sources":["../../src/utils/command-executor.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,YAAY;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CAsBhE;AA0BD;;GAEG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAoB3E;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAYjH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CA4CtF;AAED;;GAEG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,OAAO,CAAqE;IAEpF,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAQrC,UAAU;iBAVwB,MAAM;mBAAa,IAAI;iBAAW,OAAO;;IAc3E,KAAK;CAGR;AAED,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
|
|
@@ -100,7 +100,7 @@ async function executeCommand(command, shell) {
|
|
|
100
100
|
async function executeWithPermission(response) {
|
|
101
101
|
const commands = extractCommands(response);
|
|
102
102
|
if (commands.length === 0) {
|
|
103
|
-
return;
|
|
103
|
+
return { success: true, executed: false };
|
|
104
104
|
}
|
|
105
105
|
console.log(chalk_1.default.cyan(`\n\nš§ Found ${commands.length} executable command(s)\n`));
|
|
106
106
|
for (let i = 0; i < commands.length; i++) {
|
|
@@ -120,15 +120,18 @@ async function executeWithPermission(response) {
|
|
|
120
120
|
console.log(chalk_1.default.white(stderr));
|
|
121
121
|
}
|
|
122
122
|
console.log(chalk_1.default.green('ā Command completed successfully!\n'));
|
|
123
|
+
return { success: true, executed: true, output: stdout, error: stderr }; // Return first successful result (or last if multiple?) limits to 1 for now or we need array
|
|
123
124
|
}
|
|
124
125
|
catch (error) {
|
|
125
126
|
console.error(chalk_1.default.red(`\nā Error: ${error.message}\n`));
|
|
127
|
+
return { success: false, executed: true, error: error.message };
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
else {
|
|
129
131
|
console.log(chalk_1.default.gray('Skipped.\n'));
|
|
130
132
|
}
|
|
131
133
|
}
|
|
134
|
+
return { success: true, executed: false }; // Skipped all
|
|
132
135
|
}
|
|
133
136
|
/**
|
|
134
137
|
* Command history for undo/rollback
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-executor.js","sourceRoot":"","sources":["../../src/utils/command-executor.ts"],"names":[],"mappings":";;;;;;AAiBA,0CAsBC;AA6BD,sCAoBC;AAKD,wCAYC;
|
|
1
|
+
{"version":3,"file":"command-executor.js","sourceRoot":"","sources":["../../src/utils/command-executor.ts"],"names":[],"mappings":";;;;;;AAiBA,0CAsBC;AA6BD,sCAoBC;AAKD,wCAYC;AAeD,sDA4CC;AApKD,kDAA0B;AAC1B,iDAAqC;AACrC,+BAAiC;AACjC,wDAAgC;AAEhC,MAAM,SAAS,GAAG,IAAA,gBAAS,EAAC,oBAAI,CAAC,CAAC;AASlC;;GAEG;AACH,SAAgB,eAAe,CAAC,QAAgB;IAC5C,MAAM,QAAQ,GAAmB,EAAE,CAAC;IAEpC,uCAAuC;IACvC,MAAM,cAAc,GAAG,2BAA2B,CAAC;IACnD,IAAI,KAAK,CAAC;IAEV,OAAO,CAAC,KAAK,GAAG,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC;QACpC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAE7B,8BAA8B;QAC9B,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,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AE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,6FAA6F;YAC1K,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBAClB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,cAAc,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;gBAC1D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;YACpE,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QAC1C,CAAC;IACL,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,cAAc;AAC7D,CAAC;AAED;;GAEG;AACH,MAAa,cAAc;IAA3B;QACY,YAAO,GAAkE,EAAE,CAAC;IAiBxF,CAAC;IAfG,GAAG,CAAC,OAAe,EAAE,OAAgB;QACjC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YACd,OAAO;YACP,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO;SACV,CAAC,CAAC;IACP,CAAC;IAED,UAAU;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IAED,KAAK;QACD,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACtB,CAAC;CACJ;AAlBD,wCAkBC;AAEY,QAAA,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { modelsCommand } from './commands/models';
|
|
|
9
9
|
import { codeCommand } from './commands/code';
|
|
10
10
|
import { devCommand } from './commands/dev';
|
|
11
11
|
import { configManager } from './utils/config';
|
|
12
|
-
import { MatexAPIClient } from './api/client';
|
|
12
|
+
import { MatexAPIClient, ChatMessage } from './api/client';
|
|
13
13
|
import { spinner } from './utils/spinner';
|
|
14
14
|
|
|
15
15
|
const program = new Command();
|
|
@@ -65,27 +65,75 @@ if (args.length > 0 && !args[0].startsWith('-') && !knownCommands.includes(args[
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const client = new MatexAPIClient(apiKey, configManager.getBaseURL());
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
68
|
+
|
|
69
|
+
// Get current directory context
|
|
70
|
+
const fs = require('fs');
|
|
71
|
+
const files = fs.readdirSync(process.cwd()).slice(0, 20).join(', '); // fast list
|
|
72
|
+
const context = `Current directory: ${process.cwd()}\nFiles: ${files}`;
|
|
73
|
+
|
|
74
|
+
let messages: ChatMessage[] = [
|
|
75
|
+
{
|
|
76
|
+
role: 'system', content: `You are MATEXCodex, an expert agentic coding assistant.
|
|
77
|
+
1. Your goal is to COMPLETE the user's task.
|
|
78
|
+
2. You can execute shell commands by wrapping them in code blocks (bash, sh, zsh).
|
|
79
|
+
3. PREFER simple one-line shell commands (like 'mkdir', 'touch', 'npm install') over complex scripts.
|
|
80
|
+
4. If you need to create a file, use 'echo "content" > file.js' or similar.
|
|
81
|
+
5. If a command fails, I will send you the error - FIX IT and try again.
|
|
82
|
+
6. Look at the current directory context to avoid "file not found" errors.
|
|
83
|
+
${context}`
|
|
84
|
+
},
|
|
85
|
+
{ role: 'user', content: prompt }
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
let loopCount = 0;
|
|
89
|
+
const MAX_LOOPS = 5;
|
|
90
|
+
|
|
91
|
+
while (loopCount < MAX_LOOPS) {
|
|
92
|
+
loopCount++;
|
|
93
|
+
|
|
94
|
+
spinner.start(loopCount === 1 ? 'Generating plan...' : 'Analyzing result...');
|
|
95
|
+
|
|
96
|
+
const response = await client.chat({
|
|
97
|
+
messages,
|
|
98
|
+
model: 'matexcodex',
|
|
99
|
+
temperature: 0.3,
|
|
100
|
+
max_tokens: 8000,
|
|
101
|
+
stream: false,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
spinner.stop();
|
|
105
|
+
|
|
106
|
+
// Display response
|
|
107
|
+
console.log(chalk.cyan(`\nš» MATEXCodex (Step ${loopCount}):\n`));
|
|
108
|
+
console.log(chalk.white(response));
|
|
109
|
+
console.log();
|
|
110
|
+
|
|
111
|
+
// Auto-execute commands (Ollama-style)
|
|
112
|
+
const { executeWithPermission } = await import('./utils/command-executor');
|
|
113
|
+
const result = await executeWithPermission(response);
|
|
114
|
+
|
|
115
|
+
if (result.executed) {
|
|
116
|
+
if (result.success) {
|
|
117
|
+
// Success!
|
|
118
|
+
if (loopCount > 1) {
|
|
119
|
+
console.log(chalk.green('ā
Fix succeeded!'));
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
} else {
|
|
123
|
+
// Failure - Loop back
|
|
124
|
+
console.log(chalk.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
125
|
+
messages.push({ role: 'assistant', content: response });
|
|
126
|
+
messages.push({
|
|
127
|
+
role: 'user',
|
|
128
|
+
content: `ā Command failed with error:\n${result.error}\n\nPlease fix this. If the file doesn't exist, create it first. Or use a different command.`
|
|
129
|
+
});
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
// No command to execute - we are done
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
89
137
|
} catch (error: any) {
|
|
90
138
|
spinner.fail('Failed');
|
|
91
139
|
console.error(chalk.red(`\nā ${error.message}`));
|
|
@@ -108,11 +108,21 @@ export async function executeCommand(command: string, shell?: string): Promise<{
|
|
|
108
108
|
/**
|
|
109
109
|
* Execute commands with user permission
|
|
110
110
|
*/
|
|
111
|
-
export
|
|
111
|
+
export interface ExecutionResult {
|
|
112
|
+
success: boolean;
|
|
113
|
+
executed: boolean;
|
|
114
|
+
output?: string;
|
|
115
|
+
error?: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Execute commands with user permission
|
|
120
|
+
*/
|
|
121
|
+
export async function executeWithPermission(response: string): Promise<ExecutionResult> {
|
|
112
122
|
const commands = extractCommands(response);
|
|
113
123
|
|
|
114
124
|
if (commands.length === 0) {
|
|
115
|
-
return;
|
|
125
|
+
return { success: true, executed: false };
|
|
116
126
|
}
|
|
117
127
|
|
|
118
128
|
console.log(chalk.cyan(`\n\nš§ Found ${commands.length} executable command(s)\n`));
|
|
@@ -141,13 +151,17 @@ export async function executeWithPermission(response: string): Promise<void> {
|
|
|
141
151
|
}
|
|
142
152
|
|
|
143
153
|
console.log(chalk.green('ā Command completed successfully!\n'));
|
|
154
|
+
return { success: true, executed: true, output: stdout, error: stderr }; // Return first successful result (or last if multiple?) limits to 1 for now or we need array
|
|
144
155
|
} catch (error: any) {
|
|
145
156
|
console.error(chalk.red(`\nā Error: ${error.message}\n`));
|
|
157
|
+
return { success: false, executed: true, error: error.message };
|
|
146
158
|
}
|
|
147
159
|
} else {
|
|
148
160
|
console.log(chalk.gray('Skipped.\n'));
|
|
149
161
|
}
|
|
150
162
|
}
|
|
163
|
+
|
|
164
|
+
return { success: true, executed: false }; // Skipped all
|
|
151
165
|
}
|
|
152
166
|
|
|
153
167
|
/**
|