matex-cli 1.1.2 ā 1.1.4
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 +121 -31
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +110 -29
- package/dist/commands/dev.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/chat.ts +88 -33
- package/src/commands/dev.ts +80 -33
|
@@ -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,SAoJlB,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('--no-execute', 'Disable auto-prompt for command execution')
|
|
16
50
|
.action(async (options) => {
|
|
17
51
|
try {
|
|
18
52
|
// Check for API key
|
|
@@ -28,8 +62,28 @@ exports.chatCommand = new commander_1.Command('chat')
|
|
|
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}`));
|
|
30
64
|
console.log(chalk_1.default.gray('Type "exit" or "quit" to end the session\n'));
|
|
31
|
-
//
|
|
32
|
-
const
|
|
65
|
+
// Get current directory context
|
|
66
|
+
const fs = require('fs');
|
|
67
|
+
let files = '';
|
|
68
|
+
try {
|
|
69
|
+
files = fs.readdirSync(process.cwd()).slice(0, 20).join(', ');
|
|
70
|
+
}
|
|
71
|
+
catch (e) { }
|
|
72
|
+
// Conversation history with System Prompt
|
|
73
|
+
const messages = [
|
|
74
|
+
{
|
|
75
|
+
role: 'system',
|
|
76
|
+
content: `You are MATEX AI.
|
|
77
|
+
1. **STYLE RULES:**
|
|
78
|
+
- Use clean, professional, conversational text (Claude-style).
|
|
79
|
+
- **NO MARKDOWN formatting** (no **bold**, headers, etc). Use plain text.
|
|
80
|
+
- Use markdown ONLY for code blocks.
|
|
81
|
+
- Be concise.
|
|
82
|
+
2. **CONTEXT:**
|
|
83
|
+
- Current files: ${files}
|
|
84
|
+
- If useful, you can execute shell commands by wrapping them in code blocks.`
|
|
85
|
+
}
|
|
86
|
+
];
|
|
33
87
|
// Chat loop
|
|
34
88
|
while (true) {
|
|
35
89
|
// Get user input
|
|
@@ -52,38 +106,74 @@ exports.chatCommand = new commander_1.Command('chat')
|
|
|
52
106
|
}
|
|
53
107
|
// Add user message to history
|
|
54
108
|
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.'));
|
|
109
|
+
// Agentic Loop
|
|
110
|
+
let loopCount = 0;
|
|
111
|
+
const MAX_LOOPS = 5;
|
|
112
|
+
while (loopCount < MAX_LOOPS) {
|
|
113
|
+
loopCount++;
|
|
114
|
+
if (loopCount > 1) {
|
|
115
|
+
spinner_1.spinner.start('Analyzing result & Validating...');
|
|
81
116
|
}
|
|
82
117
|
else {
|
|
83
|
-
|
|
118
|
+
spinner_1.spinner.start('Thinking...');
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const response = await client.chat({
|
|
122
|
+
messages: messages,
|
|
123
|
+
model: options.model,
|
|
124
|
+
temperature: 0.7,
|
|
125
|
+
max_tokens: 4000,
|
|
126
|
+
stream: false,
|
|
127
|
+
});
|
|
128
|
+
spinner_1.spinner.stop();
|
|
129
|
+
// Add assistant response to history
|
|
130
|
+
messages.push({ role: 'assistant', content: response });
|
|
131
|
+
// Display response
|
|
132
|
+
console.log(chalk_1.default.cyan(loopCount > 1 ? `AI (Auto-Fix Attempt ${loopCount - 1}):` : 'AI:'), chalk_1.default.white(response));
|
|
133
|
+
console.log();
|
|
134
|
+
// Execute commands if requested
|
|
135
|
+
if (options.execute) {
|
|
136
|
+
const { executeWithPermission } = await Promise.resolve().then(() => __importStar(require('../utils/command-executor')));
|
|
137
|
+
const result = await executeWithPermission(response);
|
|
138
|
+
if (result.executed) {
|
|
139
|
+
if (result.success) {
|
|
140
|
+
if (loopCount > 1) {
|
|
141
|
+
console.log(chalk_1.default.green('ā
Fix succeeded!'));
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
console.log(chalk_1.default.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
147
|
+
messages.push({
|
|
148
|
+
role: 'user',
|
|
149
|
+
content: `ā Command failed with error:\n${result.error}\n\nPlease fix this. If the file doesn't exist, create it first.`
|
|
150
|
+
});
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
spinner_1.spinner.fail('Request failed');
|
|
164
|
+
if (error.message.includes('403')) {
|
|
165
|
+
console.error(chalk_1.default.red('ā Invalid or revoked API key.'));
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
else if (error.message.includes('429')) {
|
|
169
|
+
console.error(chalk_1.default.red('ā Rate limit exceeded. Please wait a moment.'));
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
console.error(chalk_1.default.red(`ā Error: ${error.message}`));
|
|
173
|
+
}
|
|
174
|
+
messages.pop(); // Remove failed user message
|
|
175
|
+
break;
|
|
84
176
|
}
|
|
85
|
-
// Remove failed message from history
|
|
86
|
-
messages.pop();
|
|
87
177
|
}
|
|
88
178
|
}
|
|
89
179
|
}
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAoC;AACpC,kDAA0B;AAC1B,wDAAgC;AAChC,4CAAgD;AAChD,0CAA4D;AAC5D,8CAA2C;AAE9B,QAAA,WAAW,GAAG,IAAI,mBAAO,CAAC,MAAM,CAAC;KACzC,WAAW,CAAC,iDAAiD,CAAC;KAC9D,MAAM,CAAC,qBAAqB,EAAE,2DAA2D,EAAE,sBAAa,CAAC,eAAe,EAAE,CAAC;KAC3H,MAAM,CAAC,cAAc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file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,eAAO,MAAM,UAAU,SAmJjB,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,11 +43,10 @@ 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')
|
|
17
|
-
.option('-
|
|
49
|
+
.option('--no-execute', 'Disable auto-prompt for command execution')
|
|
18
50
|
.action(async (options) => {
|
|
19
51
|
try {
|
|
20
52
|
// Check for API key
|
|
@@ -35,7 +67,14 @@ exports.devCommand = new commander_1.Command('dev')
|
|
|
35
67
|
const messages = [
|
|
36
68
|
{
|
|
37
69
|
role: 'system',
|
|
38
|
-
content:
|
|
70
|
+
content: `You are MATEXCodex, an expert software development assistant.
|
|
71
|
+
1. Help the user build their application step by step.
|
|
72
|
+
2. **STYLE RULES:**
|
|
73
|
+
- Use clean, professional, conversational text (Claude-style).
|
|
74
|
+
- **NO MARKDOWN formatting** in your text (no **bold**, no # headers, no --- rules).
|
|
75
|
+
- ONLY use markdown for code blocks.
|
|
76
|
+
- Be concise but thorough.
|
|
77
|
+
3. Provide complete, production-ready code.`
|
|
39
78
|
}
|
|
40
79
|
];
|
|
41
80
|
// Interactive loop
|
|
@@ -62,33 +101,75 @@ exports.devCommand = new commander_1.Command('dev')
|
|
|
62
101
|
// Add user message to history
|
|
63
102
|
messages.push({ role: 'user', content: userInput });
|
|
64
103
|
// Show thinking indicator
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
104
|
+
// Agentic Loop
|
|
105
|
+
let loopCount = 0;
|
|
106
|
+
const MAX_LOOPS = 5;
|
|
107
|
+
let currentPrompt = userInput;
|
|
108
|
+
while (loopCount < MAX_LOOPS) {
|
|
109
|
+
loopCount++;
|
|
110
|
+
if (loopCount > 1) {
|
|
111
|
+
spinner_1.spinner.start('Analyzing result & Validating...');
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
spinner_1.spinner.start('Thinking...');
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
// Send request
|
|
118
|
+
const response = await client.chat({
|
|
119
|
+
messages,
|
|
120
|
+
model: options.model,
|
|
121
|
+
temperature: 0.3,
|
|
122
|
+
max_tokens: 8000,
|
|
123
|
+
stream: false,
|
|
124
|
+
});
|
|
125
|
+
spinner_1.spinner.stop();
|
|
126
|
+
// Add assistant response to history ONLY if it's the first loop or a fix
|
|
127
|
+
// We don't want to clutter history with failed attempts unless necessary for context?
|
|
128
|
+
// Actually, maintaining history of failures is good for context.
|
|
129
|
+
messages.push({ role: 'assistant', content: response });
|
|
130
|
+
// Display response
|
|
131
|
+
console.log(chalk_1.default.green(`\nMATEXCodex${loopCount > 1 ? ` (Auto-Fix Attempt ${loopCount - 1})` : ''}:`));
|
|
132
|
+
console.log(chalk_1.default.white(response));
|
|
133
|
+
console.log();
|
|
134
|
+
// Execute commands if requested (or default to true for "seamless" experience?
|
|
135
|
+
// User asked for "seamless", but prompt still asks permission.
|
|
136
|
+
// We'll keep permission for safety but loop on failure.)
|
|
137
|
+
if (options.execute) {
|
|
138
|
+
const { executeWithPermission } = await Promise.resolve().then(() => __importStar(require('../utils/command-executor')));
|
|
139
|
+
const result = await executeWithPermission(response);
|
|
140
|
+
if (result.executed) {
|
|
141
|
+
if (result.success) {
|
|
142
|
+
if (loopCount > 1) {
|
|
143
|
+
console.log(chalk_1.default.green('ā
Fix succeeded!'));
|
|
144
|
+
}
|
|
145
|
+
break; // Success, exit loop and wait for next user input
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
// Failure - Loop back
|
|
149
|
+
console.log(chalk_1.default.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
150
|
+
// Add error to history
|
|
151
|
+
messages.push({
|
|
152
|
+
role: 'user',
|
|
153
|
+
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.`
|
|
154
|
+
});
|
|
155
|
+
// Continue loop
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
break; // No commands to execute
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
break; // Execution not enabled
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
spinner_1.spinner.fail('Request failed');
|
|
169
|
+
console.error(chalk_1.default.red(`Error: ${error.message}\n`));
|
|
170
|
+
messages.pop(); // Remove failed user message if request failed entirely
|
|
171
|
+
break;
|
|
85
172
|
}
|
|
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
173
|
}
|
|
93
174
|
}
|
|
94
175
|
}
|
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":";;;;;;;;;;;;;;;;;;;;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M,CAAC,kDAAkD;4BAC7D,CAAC;iCAAM,CAAC;gCACJ,sBAAsB;gCACtB,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,MAAM,CAAC,yCAAyC,CAAC,CAAC,CAAC;gCAErE,uBAAuB;gCACvB,QAAQ,CAAC,IAAI,CAAC;oCACV,IAAI,EAAE,MAAM;oCACZ,OAAO,EAAE,iCAAiC,MAAM,CAAC,KAAK,8FAA8F;iCACvJ,CAAC,CAAC;gCACH,gBAAgB;gCAChB,SAAS;4BACb,CAAC;wBACL,CAAC;6BAAM,CAAC;4BACJ,MAAM,CAAC,yBAAyB;wBACpC,CAAC;oBACL,CAAC;yBAAM,CAAC;wBACJ,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/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('--no-execute', 'Disable auto-prompt for command execution')
|
|
11
12
|
.action(async (options: any) => {
|
|
12
13
|
try {
|
|
13
14
|
// Check for API key
|
|
@@ -26,8 +27,28 @@ export const chatCommand = new Command('chat')
|
|
|
26
27
|
console.log(chalk.gray(`Model: ${options.model}`));
|
|
27
28
|
console.log(chalk.gray('Type "exit" or "quit" to end the session\n'));
|
|
28
29
|
|
|
29
|
-
//
|
|
30
|
-
const
|
|
30
|
+
// Get current directory context
|
|
31
|
+
const fs = require('fs');
|
|
32
|
+
let files = '';
|
|
33
|
+
try {
|
|
34
|
+
files = fs.readdirSync(process.cwd()).slice(0, 20).join(', ');
|
|
35
|
+
} catch (e) { }
|
|
36
|
+
|
|
37
|
+
// Conversation history with System Prompt
|
|
38
|
+
const messages: ChatMessage[] = [
|
|
39
|
+
{
|
|
40
|
+
role: 'system',
|
|
41
|
+
content: `You are MATEX AI.
|
|
42
|
+
1. **STYLE RULES:**
|
|
43
|
+
- Use clean, professional, conversational text (Claude-style).
|
|
44
|
+
- **NO MARKDOWN formatting** (no **bold**, headers, etc). Use plain text.
|
|
45
|
+
- Use markdown ONLY for code blocks.
|
|
46
|
+
- Be concise.
|
|
47
|
+
2. **CONTEXT:**
|
|
48
|
+
- Current files: ${files}
|
|
49
|
+
- If useful, you can execute shell commands by wrapping them in code blocks.`
|
|
50
|
+
}
|
|
51
|
+
];
|
|
31
52
|
|
|
32
53
|
// Chat loop
|
|
33
54
|
while (true) {
|
|
@@ -55,42 +76,76 @@ export const chatCommand = new Command('chat')
|
|
|
55
76
|
// Add user message to history
|
|
56
77
|
messages.push({ role: 'user', content: userMessage });
|
|
57
78
|
|
|
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 });
|
|
79
|
+
// Agentic Loop
|
|
80
|
+
let loopCount = 0;
|
|
81
|
+
const MAX_LOOPS = 5;
|
|
75
82
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
console.log();
|
|
83
|
+
while (loopCount < MAX_LOOPS) {
|
|
84
|
+
loopCount++;
|
|
79
85
|
|
|
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.'));
|
|
86
|
+
if (loopCount > 1) {
|
|
87
|
+
spinner.start('Analyzing result & Validating...');
|
|
88
88
|
} else {
|
|
89
|
-
|
|
89
|
+
spinner.start('Thinking...');
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
try {
|
|
93
|
+
const response = await client.chat({
|
|
94
|
+
messages: messages,
|
|
95
|
+
model: options.model,
|
|
96
|
+
temperature: 0.7,
|
|
97
|
+
max_tokens: 4000,
|
|
98
|
+
stream: false,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
spinner.stop();
|
|
102
|
+
|
|
103
|
+
// Add assistant response to history
|
|
104
|
+
messages.push({ role: 'assistant', content: response });
|
|
105
|
+
|
|
106
|
+
// Display response
|
|
107
|
+
console.log(chalk.cyan(loopCount > 1 ? `AI (Auto-Fix Attempt ${loopCount - 1}):` : 'AI:'), chalk.white(response));
|
|
108
|
+
console.log();
|
|
109
|
+
|
|
110
|
+
// Execute commands if requested
|
|
111
|
+
if (options.execute) {
|
|
112
|
+
const { executeWithPermission } = await import('../utils/command-executor');
|
|
113
|
+
const result = await executeWithPermission(response);
|
|
114
|
+
|
|
115
|
+
if (result.executed) {
|
|
116
|
+
if (result.success) {
|
|
117
|
+
if (loopCount > 1) {
|
|
118
|
+
console.log(chalk.green('ā
Fix succeeded!'));
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
} else {
|
|
122
|
+
console.log(chalk.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
123
|
+
messages.push({
|
|
124
|
+
role: 'user',
|
|
125
|
+
content: `ā Command failed with error:\n${result.error}\n\nPlease fix this. If the file doesn't exist, create it first.`
|
|
126
|
+
});
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
} catch (error: any) {
|
|
137
|
+
spinner.fail('Request failed');
|
|
138
|
+
if (error.message.includes('403')) {
|
|
139
|
+
console.error(chalk.red('ā Invalid or revoked API key.'));
|
|
140
|
+
process.exit(1);
|
|
141
|
+
} else if (error.message.includes('429')) {
|
|
142
|
+
console.error(chalk.red('ā Rate limit exceeded. Please wait a moment.'));
|
|
143
|
+
} else {
|
|
144
|
+
console.error(chalk.red(`ā Error: ${error.message}`));
|
|
145
|
+
}
|
|
146
|
+
messages.pop(); // Remove failed user message
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
94
149
|
}
|
|
95
150
|
}
|
|
96
151
|
|
package/src/commands/dev.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { executeWithPermission } from '../utils/command-executor';
|
|
|
9
9
|
export const devCommand = new Command('dev')
|
|
10
10
|
.description('Start interactive development session with MATEXCodex')
|
|
11
11
|
.option('-m, --model <model>', 'AI model to use', 'matexcodex')
|
|
12
|
-
.option('-
|
|
12
|
+
.option('--no-execute', 'Disable auto-prompt for command execution')
|
|
13
13
|
.action(async (options: any) => {
|
|
14
14
|
try {
|
|
15
15
|
// Check for API key
|
|
@@ -33,7 +33,14 @@ export const devCommand = new Command('dev')
|
|
|
33
33
|
const messages: ChatMessage[] = [
|
|
34
34
|
{
|
|
35
35
|
role: 'system',
|
|
36
|
-
content:
|
|
36
|
+
content: `You are MATEXCodex, an expert software development assistant.
|
|
37
|
+
1. Help the user build their application step by step.
|
|
38
|
+
2. **STYLE RULES:**
|
|
39
|
+
- Use clean, professional, conversational text (Claude-style).
|
|
40
|
+
- **NO MARKDOWN formatting** in your text (no **bold**, no # headers, no --- rules).
|
|
41
|
+
- ONLY use markdown for code blocks.
|
|
42
|
+
- Be concise but thorough.
|
|
43
|
+
3. Provide complete, production-ready code.`
|
|
37
44
|
}
|
|
38
45
|
];
|
|
39
46
|
|
|
@@ -66,39 +73,79 @@ export const devCommand = new Command('dev')
|
|
|
66
73
|
messages.push({ role: 'user', content: userInput });
|
|
67
74
|
|
|
68
75
|
// 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);
|
|
76
|
+
// Agentic Loop
|
|
77
|
+
let loopCount = 0;
|
|
78
|
+
const MAX_LOOPS = 5;
|
|
79
|
+
let currentPrompt = userInput;
|
|
80
|
+
|
|
81
|
+
while (loopCount < MAX_LOOPS) {
|
|
82
|
+
loopCount++;
|
|
83
|
+
|
|
84
|
+
if (loopCount > 1) {
|
|
85
|
+
spinner.start('Analyzing result & Validating...');
|
|
86
|
+
} else {
|
|
87
|
+
spinner.start('Thinking...');
|
|
94
88
|
}
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
try {
|
|
91
|
+
// Send request
|
|
92
|
+
const response = await client.chat({
|
|
93
|
+
messages,
|
|
94
|
+
model: options.model,
|
|
95
|
+
temperature: 0.3,
|
|
96
|
+
max_tokens: 8000,
|
|
97
|
+
stream: false,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
spinner.stop();
|
|
101
|
+
|
|
102
|
+
// Add assistant response to history ONLY if it's the first loop or a fix
|
|
103
|
+
// We don't want to clutter history with failed attempts unless necessary for context?
|
|
104
|
+
// Actually, maintaining history of failures is good for context.
|
|
105
|
+
messages.push({ role: 'assistant', content: response });
|
|
106
|
+
|
|
107
|
+
// Display response
|
|
108
|
+
console.log(chalk.green(`\nMATEXCodex${loopCount > 1 ? ` (Auto-Fix Attempt ${loopCount - 1})` : ''}:`));
|
|
109
|
+
console.log(chalk.white(response));
|
|
110
|
+
console.log();
|
|
111
|
+
|
|
112
|
+
// Execute commands if requested (or default to true for "seamless" experience?
|
|
113
|
+
// User asked for "seamless", but prompt still asks permission.
|
|
114
|
+
// We'll keep permission for safety but loop on failure.)
|
|
115
|
+
if (options.execute) {
|
|
116
|
+
const { executeWithPermission } = await import('../utils/command-executor');
|
|
117
|
+
const result = await executeWithPermission(response);
|
|
118
|
+
|
|
119
|
+
if (result.executed) {
|
|
120
|
+
if (result.success) {
|
|
121
|
+
if (loopCount > 1) {
|
|
122
|
+
console.log(chalk.green('ā
Fix succeeded!'));
|
|
123
|
+
}
|
|
124
|
+
break; // Success, exit loop and wait for next user input
|
|
125
|
+
} else {
|
|
126
|
+
// Failure - Loop back
|
|
127
|
+
console.log(chalk.yellow('\nāŗ Command failed. Asking AI to fix...'));
|
|
128
|
+
|
|
129
|
+
// Add error to history
|
|
130
|
+
messages.push({
|
|
131
|
+
role: 'user',
|
|
132
|
+
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.`
|
|
133
|
+
});
|
|
134
|
+
// Continue loop
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
break; // No commands to execute
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
break; // Execution not enabled
|
|
142
|
+
}
|
|
143
|
+
} catch (error: any) {
|
|
144
|
+
spinner.fail('Request failed');
|
|
145
|
+
console.error(chalk.red(`Error: ${error.message}\n`));
|
|
146
|
+
messages.pop(); // Remove failed user message if request failed entirely
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
102
149
|
}
|
|
103
150
|
}
|
|
104
151
|
|