matex-cli 1.1.1 ā 1.1.3
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/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +124 -31
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +112 -28
- package/dist/commands/dev.js.map +1 -1
- 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/commands/chat.ts +91 -33
- package/src/commands/dev.ts +82 -32
- package/src/index.ts +70 -22
- package/src/utils/command-executor.ts +16 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,WAAW,SAuJlB,CAAC"}
|
package/dist/commands/chat.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -13,6 +46,7 @@ const spinner_1 = require("../utils/spinner");
|
|
|
13
46
|
exports.chatCommand = new commander_1.Command('chat')
|
|
14
47
|
.description('Start an interactive chat session with MATEX AI')
|
|
15
48
|
.option('-m, --model <model>', 'AI model to use (matexcodex, matexai, elite, matexspirit)', config_1.configManager.getDefaultModel())
|
|
49
|
+
.option('-x, --execute', 'Auto-prompt for command execution')
|
|
16
50
|
.action(async (options) => {
|
|
17
51
|
try {
|
|
18
52
|
// Check for API key
|
|
@@ -27,9 +61,32 @@ exports.chatCommand = new commander_1.Command('chat')
|
|
|
27
61
|
// Welcome message
|
|
28
62
|
console.log(chalk_1.default.bold.cyan('\nš¤ MATEX AI Interactive Chat'));
|
|
29
63
|
console.log(chalk_1.default.gray(`Model: ${options.model}`));
|
|
64
|
+
if (!options.execute) {
|
|
65
|
+
console.log(chalk_1.default.yellow('š” Tip: Run with --execute to enable auto-fix & shell commands'));
|
|
66
|
+
}
|
|
30
67
|
console.log(chalk_1.default.gray('Type "exit" or "quit" to end the session\n'));
|
|
31
|
-
//
|
|
32
|
-
const
|
|
68
|
+
// Get current directory context
|
|
69
|
+
const fs = require('fs');
|
|
70
|
+
let files = '';
|
|
71
|
+
try {
|
|
72
|
+
files = fs.readdirSync(process.cwd()).slice(0, 20).join(', ');
|
|
73
|
+
}
|
|
74
|
+
catch (e) { }
|
|
75
|
+
// Conversation history with System Prompt
|
|
76
|
+
const messages = [
|
|
77
|
+
{
|
|
78
|
+
role: 'system',
|
|
79
|
+
content: `You are MATEX AI.
|
|
80
|
+
1. **STYLE RULES:**
|
|
81
|
+
- Use clean, professional, conversational text (Claude-style).
|
|
82
|
+
- **NO MARKDOWN formatting** (no **bold**, headers, etc). Use plain text.
|
|
83
|
+
- Use markdown ONLY for code blocks.
|
|
84
|
+
- Be concise.
|
|
85
|
+
2. **CONTEXT:**
|
|
86
|
+
- Current files: ${files}
|
|
87
|
+
- If useful, you can execute shell commands by wrapping them in code blocks.`
|
|
88
|
+
}
|
|
89
|
+
];
|
|
33
90
|
// Chat loop
|
|
34
91
|
while (true) {
|
|
35
92
|
// Get user input
|
|
@@ -52,38 +109,74 @@ exports.chatCommand = new commander_1.Command('chat')
|
|
|
52
109
|
}
|
|
53
110
|
// Add user message to history
|
|
54
111
|
messages.push({ role: 'user', content: userMessage });
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
temperature: 0.7,
|
|
63
|
-
max_tokens: 4000,
|
|
64
|
-
stream: false,
|
|
65
|
-
});
|
|
66
|
-
spinner_1.spinner.stop();
|
|
67
|
-
// Add assistant response to history
|
|
68
|
-
messages.push({ role: 'assistant', content: response });
|
|
69
|
-
// Display response
|
|
70
|
-
console.log(chalk_1.default.cyan('AI:'), chalk_1.default.white(response));
|
|
71
|
-
console.log();
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
spinner_1.spinner.fail('Request failed');
|
|
75
|
-
if (error.message.includes('403')) {
|
|
76
|
-
console.error(chalk_1.default.red('ā Invalid or revoked API key.'));
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
else if (error.message.includes('429')) {
|
|
80
|
-
console.error(chalk_1.default.red('ā Rate limit exceeded. Please wait a moment.'));
|
|
112
|
+
// Agentic Loop
|
|
113
|
+
let loopCount = 0;
|
|
114
|
+
const MAX_LOOPS = 5;
|
|
115
|
+
while (loopCount < MAX_LOOPS) {
|
|
116
|
+
loopCount++;
|
|
117
|
+
if (loopCount > 1) {
|
|
118
|
+
spinner_1.spinner.start('Analyzing result & Validating...');
|
|
81
119
|
}
|
|
82
120
|
else {
|
|
83
|
-
|
|
121
|
+
spinner_1.spinner.start('Thinking...');
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const response = await client.chat({
|
|
125
|
+
messages: messages,
|
|
126
|
+
model: options.model,
|
|
127
|
+
temperature: 0.7,
|
|
128
|
+
max_tokens: 4000,
|
|
129
|
+
stream: false,
|
|
130
|
+
});
|
|
131
|
+
spinner_1.spinner.stop();
|
|
132
|
+
// Add assistant response to history
|
|
133
|
+
messages.push({ role: 'assistant', content: response });
|
|
134
|
+
// Display response
|
|
135
|
+
console.log(chalk_1.default.cyan(loopCount > 1 ? `AI (Auto-Fix Attempt ${loopCount - 1}):` : 'AI:'), chalk_1.default.white(response));
|
|
136
|
+
console.log();
|
|
137
|
+
// Execute commands if requested
|
|
138
|
+
if (options.execute) {
|
|
139
|
+
const { executeWithPermission } = await Promise.resolve().then(() => __importStar(require('../utils/command-executor')));
|
|
140
|
+
const result = await executeWithPermission(response);
|
|
141
|
+
if (result.executed) {
|
|
142
|
+
if (result.success) {
|
|
143
|
+
if (loopCount > 1) {
|
|
144
|
+
console.log(chalk_1.default.green('ā
Fix succeeded!'));
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
console.log(chalk_1.default.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
150
|
+
messages.push({
|
|
151
|
+
role: 'user',
|
|
152
|
+
content: `ā Command failed with error:\n${result.error}\n\nPlease fix this. If the file doesn't exist, create it first.`
|
|
153
|
+
});
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
spinner_1.spinner.fail('Request failed');
|
|
167
|
+
if (error.message.includes('403')) {
|
|
168
|
+
console.error(chalk_1.default.red('ā Invalid or revoked API key.'));
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
else if (error.message.includes('429')) {
|
|
172
|
+
console.error(chalk_1.default.red('ā Rate limit exceeded. Please wait a moment.'));
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
console.error(chalk_1.default.red(`ā Error: ${error.message}`));
|
|
176
|
+
}
|
|
177
|
+
messages.pop(); // Remove failed user message
|
|
178
|
+
break;
|
|
84
179
|
}
|
|
85
|
-
// Remove failed message from history
|
|
86
|
-
messages.pop();
|
|
87
180
|
}
|
|
88
181
|
}
|
|
89
182
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":";;;;;;;;;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V,CAAC;YACL,CAAC;QACL,CAAC;IAEL,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,2BAA2B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,eAAO,MAAM,UAAU,SAsJjB,CAAC"}
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -10,7 +43,6 @@ const inquirer_1 = __importDefault(require("inquirer"));
|
|
|
10
43
|
const config_1 = require("../utils/config");
|
|
11
44
|
const client_1 = require("../api/client");
|
|
12
45
|
const spinner_1 = require("../utils/spinner");
|
|
13
|
-
const command_executor_1 = require("../utils/command-executor");
|
|
14
46
|
exports.devCommand = new commander_1.Command('dev')
|
|
15
47
|
.description('Start interactive development session with MATEXCodex')
|
|
16
48
|
.option('-m, --model <model>', 'AI model to use', 'matexcodex')
|
|
@@ -30,12 +62,22 @@ exports.devCommand = new commander_1.Command('dev')
|
|
|
30
62
|
console.log(chalk_1.default.cyan.bold('\nš MATEX Development Session'));
|
|
31
63
|
console.log(chalk_1.default.gray('ā'.repeat(50)));
|
|
32
64
|
console.log(chalk_1.default.white(`Model: ${chalk_1.default.cyan(options.model)}`));
|
|
65
|
+
if (!options.execute) {
|
|
66
|
+
console.log(chalk_1.default.yellow('š” Tip: Run with --execute to enable auto-fix & shell commands'));
|
|
67
|
+
}
|
|
33
68
|
console.log(chalk_1.default.gray('Type your requests, or "exit" to quit\n'));
|
|
34
69
|
// Conversation history
|
|
35
70
|
const messages = [
|
|
36
71
|
{
|
|
37
72
|
role: 'system',
|
|
38
|
-
content:
|
|
73
|
+
content: `You are MATEXCodex, an expert software development assistant.
|
|
74
|
+
1. Help the user build their application step by step.
|
|
75
|
+
2. **STYLE RULES:**
|
|
76
|
+
- Use clean, professional, conversational text (Claude-style).
|
|
77
|
+
- **NO MARKDOWN formatting** in your text (no **bold**, no # headers, no --- rules).
|
|
78
|
+
- ONLY use markdown for code blocks.
|
|
79
|
+
- Be concise but thorough.
|
|
80
|
+
3. Provide complete, production-ready code.`
|
|
39
81
|
}
|
|
40
82
|
];
|
|
41
83
|
// Interactive loop
|
|
@@ -62,33 +104,75 @@ exports.devCommand = new commander_1.Command('dev')
|
|
|
62
104
|
// Add user message to history
|
|
63
105
|
messages.push({ role: 'user', content: userInput });
|
|
64
106
|
// Show thinking indicator
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
107
|
+
// Agentic Loop
|
|
108
|
+
let loopCount = 0;
|
|
109
|
+
const MAX_LOOPS = 5;
|
|
110
|
+
let currentPrompt = userInput;
|
|
111
|
+
while (loopCount < MAX_LOOPS) {
|
|
112
|
+
loopCount++;
|
|
113
|
+
if (loopCount > 1) {
|
|
114
|
+
spinner_1.spinner.start('Analyzing result & Validating...');
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
spinner_1.spinner.start('Thinking...');
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
// Send request
|
|
121
|
+
const response = await client.chat({
|
|
122
|
+
messages,
|
|
123
|
+
model: options.model,
|
|
124
|
+
temperature: 0.3,
|
|
125
|
+
max_tokens: 8000,
|
|
126
|
+
stream: false,
|
|
127
|
+
});
|
|
128
|
+
spinner_1.spinner.stop();
|
|
129
|
+
// Add assistant response to history ONLY if it's the first loop or a fix
|
|
130
|
+
// We don't want to clutter history with failed attempts unless necessary for context?
|
|
131
|
+
// Actually, maintaining history of failures is good for context.
|
|
132
|
+
messages.push({ role: 'assistant', content: response });
|
|
133
|
+
// Display response
|
|
134
|
+
console.log(chalk_1.default.green(`\nMATEXCodex${loopCount > 1 ? ` (Auto-Fix Attempt ${loopCount - 1})` : ''}:`));
|
|
135
|
+
console.log(chalk_1.default.white(response));
|
|
136
|
+
console.log();
|
|
137
|
+
// Execute commands if requested (or default to true for "seamless" experience?
|
|
138
|
+
// User asked for "seamless", but prompt still asks permission.
|
|
139
|
+
// We'll keep permission for safety but loop on failure.)
|
|
140
|
+
if (options.execute) {
|
|
141
|
+
const { executeWithPermission } = await Promise.resolve().then(() => __importStar(require('../utils/command-executor')));
|
|
142
|
+
const result = await executeWithPermission(response);
|
|
143
|
+
if (result.executed) {
|
|
144
|
+
if (result.success) {
|
|
145
|
+
if (loopCount > 1) {
|
|
146
|
+
console.log(chalk_1.default.green('ā
Fix succeeded!'));
|
|
147
|
+
}
|
|
148
|
+
break; // Success, exit loop and wait for next user input
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// Failure - Loop back
|
|
152
|
+
console.log(chalk_1.default.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
153
|
+
// Add error to history
|
|
154
|
+
messages.push({
|
|
155
|
+
role: 'user',
|
|
156
|
+
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.`
|
|
157
|
+
});
|
|
158
|
+
// Continue loop
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
break; // No commands to execute
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
break; // Execution not enabled
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
spinner_1.spinner.fail('Request failed');
|
|
172
|
+
console.error(chalk_1.default.red(`Error: ${error.message}\n`));
|
|
173
|
+
messages.pop(); // Remove failed user message if request failed entirely
|
|
174
|
+
break;
|
|
85
175
|
}
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
spinner_1.spinner.fail('Request failed');
|
|
89
|
-
console.error(chalk_1.default.red(`Error: ${error.message}\n`));
|
|
90
|
-
// Remove the failed user message
|
|
91
|
-
messages.pop();
|
|
92
176
|
}
|
|
93
177
|
}
|
|
94
178
|
}
|
package/dist/commands/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAoC;AACpC,kDAA0B;AAC1B,wDAAgC;AAChC,4CAAgD;AAChD,0CAA4D;AAC5D,8CAA2C;AAG9B,QAAA,UAAU,GAAG,IAAI,mBAAO,CAAC,KAAK,CAAC;KACvC,WAAW,CAAC,uDAAuD,CAAC;KACpE,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,CAAC;KAC9D,MAAM,CAAC,eAAe,EAAE,kDAAkD,CAAC;KAC3E,MAAM,CAAC,KAAK,EAAE,OAAY,EAAE,EAAE;IAC3B,IAAI,CAAC;QACD,oBAAoB;QACpB,MAAM,MAAM,GAAG,sBAAa,CAAC,SAAS,EAAE,CAAC;QACzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC,CAAC;YACr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BACJ,MAAM,CAAC,wBAAwB;oBACnC,CAAC;gBACL,CAAC;gBAAC,OAAO,KAAU,EAAE,CAAC;oBAClB,iBAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;oBAC/B,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,UAAU,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;oBACtD,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,wDAAwD;oBACxE,MAAM;gBACV,CAAC;YACL,CAAC;QACL,CAAC;IAEL,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,cAAc,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC,CAAC"}
|
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,eAA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
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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,EAAE,CAAC"}
|
package/package.json
CHANGED
package/src/commands/chat.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { spinner } from '../utils/spinner';
|
|
|
8
8
|
export const chatCommand = new Command('chat')
|
|
9
9
|
.description('Start an interactive chat session with MATEX AI')
|
|
10
10
|
.option('-m, --model <model>', 'AI model to use (matexcodex, matexai, elite, matexspirit)', configManager.getDefaultModel())
|
|
11
|
+
.option('-x, --execute', 'Auto-prompt for command execution')
|
|
11
12
|
.action(async (options: any) => {
|
|
12
13
|
try {
|
|
13
14
|
// Check for API key
|
|
@@ -24,10 +25,33 @@ export const chatCommand = new Command('chat')
|
|
|
24
25
|
// Welcome message
|
|
25
26
|
console.log(chalk.bold.cyan('\nš¤ MATEX AI Interactive Chat'));
|
|
26
27
|
console.log(chalk.gray(`Model: ${options.model}`));
|
|
28
|
+
if (!options.execute) {
|
|
29
|
+
console.log(chalk.yellow('š” Tip: Run with --execute to enable auto-fix & shell commands'));
|
|
30
|
+
}
|
|
27
31
|
console.log(chalk.gray('Type "exit" or "quit" to end the session\n'));
|
|
28
32
|
|
|
29
|
-
//
|
|
30
|
-
const
|
|
33
|
+
// Get current directory context
|
|
34
|
+
const fs = require('fs');
|
|
35
|
+
let files = '';
|
|
36
|
+
try {
|
|
37
|
+
files = fs.readdirSync(process.cwd()).slice(0, 20).join(', ');
|
|
38
|
+
} catch (e) { }
|
|
39
|
+
|
|
40
|
+
// Conversation history with System Prompt
|
|
41
|
+
const messages: ChatMessage[] = [
|
|
42
|
+
{
|
|
43
|
+
role: 'system',
|
|
44
|
+
content: `You are MATEX AI.
|
|
45
|
+
1. **STYLE RULES:**
|
|
46
|
+
- Use clean, professional, conversational text (Claude-style).
|
|
47
|
+
- **NO MARKDOWN formatting** (no **bold**, headers, etc). Use plain text.
|
|
48
|
+
- Use markdown ONLY for code blocks.
|
|
49
|
+
- Be concise.
|
|
50
|
+
2. **CONTEXT:**
|
|
51
|
+
- Current files: ${files}
|
|
52
|
+
- If useful, you can execute shell commands by wrapping them in code blocks.`
|
|
53
|
+
}
|
|
54
|
+
];
|
|
31
55
|
|
|
32
56
|
// Chat loop
|
|
33
57
|
while (true) {
|
|
@@ -55,42 +79,76 @@ export const chatCommand = new Command('chat')
|
|
|
55
79
|
// Add user message to history
|
|
56
80
|
messages.push({ role: 'user', content: userMessage });
|
|
57
81
|
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
// Send request
|
|
63
|
-
const response = await client.chat({
|
|
64
|
-
messages: messages,
|
|
65
|
-
model: options.model,
|
|
66
|
-
temperature: 0.7,
|
|
67
|
-
max_tokens: 4000,
|
|
68
|
-
stream: false,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
spinner.stop();
|
|
72
|
-
|
|
73
|
-
// Add assistant response to history
|
|
74
|
-
messages.push({ role: 'assistant', content: response });
|
|
82
|
+
// Agentic Loop
|
|
83
|
+
let loopCount = 0;
|
|
84
|
+
const MAX_LOOPS = 5;
|
|
75
85
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.log();
|
|
86
|
+
while (loopCount < MAX_LOOPS) {
|
|
87
|
+
loopCount++;
|
|
79
88
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (error.message.includes('403')) {
|
|
84
|
-
console.error(chalk.red('ā Invalid or revoked API key.'));
|
|
85
|
-
break;
|
|
86
|
-
} else if (error.message.includes('429')) {
|
|
87
|
-
console.error(chalk.red('ā Rate limit exceeded. Please wait a moment.'));
|
|
89
|
+
if (loopCount > 1) {
|
|
90
|
+
spinner.start('Analyzing result & Validating...');
|
|
88
91
|
} else {
|
|
89
|
-
|
|
92
|
+
spinner.start('Thinking...');
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
try {
|
|
96
|
+
const response = await client.chat({
|
|
97
|
+
messages: messages,
|
|
98
|
+
model: options.model,
|
|
99
|
+
temperature: 0.7,
|
|
100
|
+
max_tokens: 4000,
|
|
101
|
+
stream: false,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
spinner.stop();
|
|
105
|
+
|
|
106
|
+
// Add assistant response to history
|
|
107
|
+
messages.push({ role: 'assistant', content: response });
|
|
108
|
+
|
|
109
|
+
// Display response
|
|
110
|
+
console.log(chalk.cyan(loopCount > 1 ? `AI (Auto-Fix Attempt ${loopCount - 1}):` : 'AI:'), chalk.white(response));
|
|
111
|
+
console.log();
|
|
112
|
+
|
|
113
|
+
// Execute commands if requested
|
|
114
|
+
if (options.execute) {
|
|
115
|
+
const { executeWithPermission } = await import('../utils/command-executor');
|
|
116
|
+
const result = await executeWithPermission(response);
|
|
117
|
+
|
|
118
|
+
if (result.executed) {
|
|
119
|
+
if (result.success) {
|
|
120
|
+
if (loopCount > 1) {
|
|
121
|
+
console.log(chalk.green('ā
Fix succeeded!'));
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
} else {
|
|
125
|
+
console.log(chalk.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
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.`
|
|
129
|
+
});
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
} catch (error: any) {
|
|
140
|
+
spinner.fail('Request failed');
|
|
141
|
+
if (error.message.includes('403')) {
|
|
142
|
+
console.error(chalk.red('ā Invalid or revoked API key.'));
|
|
143
|
+
process.exit(1);
|
|
144
|
+
} else if (error.message.includes('429')) {
|
|
145
|
+
console.error(chalk.red('ā Rate limit exceeded. Please wait a moment.'));
|
|
146
|
+
} else {
|
|
147
|
+
console.error(chalk.red(`ā Error: ${error.message}`));
|
|
148
|
+
}
|
|
149
|
+
messages.pop(); // Remove failed user message
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
94
152
|
}
|
|
95
153
|
}
|
|
96
154
|
|
package/src/commands/dev.ts
CHANGED
|
@@ -27,13 +27,23 @@ export const devCommand = new Command('dev')
|
|
|
27
27
|
console.log(chalk.cyan.bold('\nš MATEX Development Session'));
|
|
28
28
|
console.log(chalk.gray('ā'.repeat(50)));
|
|
29
29
|
console.log(chalk.white(`Model: ${chalk.cyan(options.model)}`));
|
|
30
|
+
if (!options.execute) {
|
|
31
|
+
console.log(chalk.yellow('š” Tip: Run with --execute to enable auto-fix & shell commands'));
|
|
32
|
+
}
|
|
30
33
|
console.log(chalk.gray('Type your requests, or "exit" to quit\n'));
|
|
31
34
|
|
|
32
35
|
// Conversation history
|
|
33
36
|
const messages: ChatMessage[] = [
|
|
34
37
|
{
|
|
35
38
|
role: 'system',
|
|
36
|
-
content:
|
|
39
|
+
content: `You are MATEXCodex, an expert software development assistant.
|
|
40
|
+
1. Help the user build their application step by step.
|
|
41
|
+
2. **STYLE RULES:**
|
|
42
|
+
- Use clean, professional, conversational text (Claude-style).
|
|
43
|
+
- **NO MARKDOWN formatting** in your text (no **bold**, no # headers, no --- rules).
|
|
44
|
+
- ONLY use markdown for code blocks.
|
|
45
|
+
- Be concise but thorough.
|
|
46
|
+
3. Provide complete, production-ready code.`
|
|
37
47
|
}
|
|
38
48
|
];
|
|
39
49
|
|
|
@@ -66,39 +76,79 @@ export const devCommand = new Command('dev')
|
|
|
66
76
|
messages.push({ role: 'user', content: userInput });
|
|
67
77
|
|
|
68
78
|
// Show thinking indicator
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
spinner.stop();
|
|
82
|
-
|
|
83
|
-
// Add assistant response to history
|
|
84
|
-
messages.push({ role: 'assistant', content: response });
|
|
85
|
-
|
|
86
|
-
// Display response
|
|
87
|
-
console.log(chalk.green('\nMATEXCodex:'));
|
|
88
|
-
console.log(chalk.white(response));
|
|
89
|
-
console.log();
|
|
90
|
-
|
|
91
|
-
// Execute commands if requested
|
|
92
|
-
if (options.execute) {
|
|
93
|
-
await executeWithPermission(response);
|
|
79
|
+
// Agentic Loop
|
|
80
|
+
let loopCount = 0;
|
|
81
|
+
const MAX_LOOPS = 5;
|
|
82
|
+
let currentPrompt = userInput;
|
|
83
|
+
|
|
84
|
+
while (loopCount < MAX_LOOPS) {
|
|
85
|
+
loopCount++;
|
|
86
|
+
|
|
87
|
+
if (loopCount > 1) {
|
|
88
|
+
spinner.start('Analyzing result & Validating...');
|
|
89
|
+
} else {
|
|
90
|
+
spinner.start('Thinking...');
|
|
94
91
|
}
|
|
95
92
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
try {
|
|
94
|
+
// Send request
|
|
95
|
+
const response = await client.chat({
|
|
96
|
+
messages,
|
|
97
|
+
model: options.model,
|
|
98
|
+
temperature: 0.3,
|
|
99
|
+
max_tokens: 8000,
|
|
100
|
+
stream: false,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
spinner.stop();
|
|
104
|
+
|
|
105
|
+
// Add assistant response to history ONLY if it's the first loop or a fix
|
|
106
|
+
// We don't want to clutter history with failed attempts unless necessary for context?
|
|
107
|
+
// Actually, maintaining history of failures is good for context.
|
|
108
|
+
messages.push({ role: 'assistant', content: response });
|
|
109
|
+
|
|
110
|
+
// Display response
|
|
111
|
+
console.log(chalk.green(`\nMATEXCodex${loopCount > 1 ? ` (Auto-Fix Attempt ${loopCount - 1})` : ''}:`));
|
|
112
|
+
console.log(chalk.white(response));
|
|
113
|
+
console.log();
|
|
114
|
+
|
|
115
|
+
// Execute commands if requested (or default to true for "seamless" experience?
|
|
116
|
+
// User asked for "seamless", but prompt still asks permission.
|
|
117
|
+
// We'll keep permission for safety but loop on failure.)
|
|
118
|
+
if (options.execute) {
|
|
119
|
+
const { executeWithPermission } = await import('../utils/command-executor');
|
|
120
|
+
const result = await executeWithPermission(response);
|
|
121
|
+
|
|
122
|
+
if (result.executed) {
|
|
123
|
+
if (result.success) {
|
|
124
|
+
if (loopCount > 1) {
|
|
125
|
+
console.log(chalk.green('ā
Fix succeeded!'));
|
|
126
|
+
}
|
|
127
|
+
break; // Success, exit loop and wait for next user input
|
|
128
|
+
} else {
|
|
129
|
+
// Failure - Loop back
|
|
130
|
+
console.log(chalk.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
131
|
+
|
|
132
|
+
// Add error to history
|
|
133
|
+
messages.push({
|
|
134
|
+
role: 'user',
|
|
135
|
+
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.`
|
|
136
|
+
});
|
|
137
|
+
// Continue loop
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
break; // No commands to execute
|
|
142
|
+
}
|
|
143
|
+
} else {
|
|
144
|
+
break; // Execution not enabled
|
|
145
|
+
}
|
|
146
|
+
} catch (error: any) {
|
|
147
|
+
spinner.fail('Request failed');
|
|
148
|
+
console.error(chalk.red(`Error: ${error.message}\n`));
|
|
149
|
+
messages.pop(); // Remove failed user message if request failed entirely
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
102
152
|
}
|
|
103
153
|
}
|
|
104
154
|
|
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
|
/**
|