matex-cli 1.2.84 → 1.2.87
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 +561 -288
- package/package.json +8 -7
- package/dist/api/client.js +0 -173
- package/dist/commands/ask.js +0 -63
- package/dist/commands/augov.js +0 -273
- package/dist/commands/bro.js +0 -304
- package/dist/commands/chaos.js +0 -58
- package/dist/commands/chat.js +0 -59
- package/dist/commands/code.js +0 -94
- package/dist/commands/config.js +0 -74
- package/dist/commands/dev.js +0 -66
- package/dist/commands/help.js +0 -50
- package/dist/commands/login.js +0 -47
- package/dist/commands/models.js +0 -77
- package/dist/commands/student.js +0 -28
- package/dist/commands/study.js +0 -72
- package/dist/prompts/banter-augov.js +0 -21
- package/dist/prompts/banter.js +0 -101
- package/dist/prompts/chaos-prompts.js +0 -57
- package/dist/prompts/system-prompts.js +0 -148
- package/dist/session/agent-session.js +0 -450
- package/dist/utils/agent-orchestrator.js +0 -251
- package/dist/utils/augov-logger.js +0 -35
- package/dist/utils/augov-scrubber.js +0 -68
- package/dist/utils/command-executor.js +0 -507
- package/dist/utils/config.js +0 -139
- package/dist/utils/mcp-server.js +0 -396
- package/dist/utils/patcher.js +0 -202
- package/dist/utils/repo-mapper.js +0 -214
- package/dist/utils/spinner.js +0 -67
- package/dist/utils/tui.js +0 -779
|
@@ -1,450 +0,0 @@
|
|
|
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
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.AgentSession = void 0;
|
|
40
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
42
|
-
const tui_1 = require("../utils/tui");
|
|
43
|
-
const agent_orchestrator_1 = require("../utils/agent-orchestrator");
|
|
44
|
-
const spinner_1 = require("../utils/spinner");
|
|
45
|
-
const repo_mapper_1 = require("../utils/repo-mapper");
|
|
46
|
-
class AgentSession {
|
|
47
|
-
constructor(config) {
|
|
48
|
-
this.lastActivityTime = Date.now();
|
|
49
|
-
this.isAjaySleeping = false;
|
|
50
|
-
this.isAjayOnChaiBreak = false;
|
|
51
|
-
this.chaiBreakEndTime = 0;
|
|
52
|
-
this.breakInterval = null;
|
|
53
|
-
this.idleCheckInterval = null;
|
|
54
|
-
this.client = config.client;
|
|
55
|
-
this.model = config.model;
|
|
56
|
-
this.execute = config.execute;
|
|
57
|
-
this.messages = config.initialMessages;
|
|
58
|
-
this.broBanter = config.broBanter;
|
|
59
|
-
this.sleepyAjayProtocol = config.sleepyAjayProtocol;
|
|
60
|
-
this.currentSessionCwd = config.baseDir;
|
|
61
|
-
this.messageScrubber = config.messageScrubber;
|
|
62
|
-
this.auditLogger = config.auditLogger;
|
|
63
|
-
this.isAugovMode = config.isAugovMode;
|
|
64
|
-
}
|
|
65
|
-
async start() {
|
|
66
|
-
this.startIdleCheck();
|
|
67
|
-
while (true) {
|
|
68
|
-
this.lastActivityTime = Date.now();
|
|
69
|
-
// Premium UI Box (Same as AU-GOV but for Dev)
|
|
70
|
-
const darkBorder = chalk_1.default.hex('#1E3A8A');
|
|
71
|
-
const primaryText = chalk_1.default.hex('#3B82F6');
|
|
72
|
-
const shadow = chalk_1.default.hex('#1e1e1e');
|
|
73
|
-
console.log(shadow('┌─────────────────────────────────────────────────────────────────────────────┐'));
|
|
74
|
-
if (this.isAugovMode) {
|
|
75
|
-
console.log(shadow('│') + chalk_1.default.gray(' Using 1 SECURE node file 1 AU-GOV validated server ') + shadow('│'));
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
console.log(shadow('│') + chalk_1.default.gray(' Using 1 MATEX_Orchestrator 1 MCP server ') + shadow('│'));
|
|
79
|
-
}
|
|
80
|
-
console.log(shadow('├─────────────────────────────────────────────────────────────────────────────┤'));
|
|
81
|
-
const { userInput } = await inquirer_1.default.prompt([
|
|
82
|
-
{
|
|
83
|
-
type: 'input',
|
|
84
|
-
name: 'userInput',
|
|
85
|
-
message: shadow('│ ') + primaryText('> '),
|
|
86
|
-
prefix: ''
|
|
87
|
-
}
|
|
88
|
-
]);
|
|
89
|
-
if (this.isAugovMode || true) { // Always show status footer in premium mode
|
|
90
|
-
const homeDirDisplay = this.currentSessionCwd.replace(process.env.HOME || '', '~');
|
|
91
|
-
console.log(shadow('└─────────────────────────────────────────────────────────────────────────────┘'));
|
|
92
|
-
console.log(chalk_1.default.gray(` ${homeDirDisplay.padEnd(30)} sandbox-exec (minimal)\n`));
|
|
93
|
-
}
|
|
94
|
-
this.lastActivityTime = Date.now();
|
|
95
|
-
if (this.isAjaySleeping) {
|
|
96
|
-
this.wakeAjayUp();
|
|
97
|
-
}
|
|
98
|
-
if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
|
|
99
|
-
console.log(chalk_1.default.yellow('\n👋 Ending session. Happy coding!\n'));
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
if (!userInput.trim())
|
|
103
|
-
continue;
|
|
104
|
-
let processedInput = userInput;
|
|
105
|
-
if (this.messageScrubber) {
|
|
106
|
-
processedInput = this.messageScrubber(userInput);
|
|
107
|
-
if (userInput !== processedInput) {
|
|
108
|
-
tui_1.TUI.log(chalk_1.default.yellow('\n 🛡️ Privacy Shield Active: Sensitive Australian data was redacted locally.'));
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (this.auditLogger) {
|
|
112
|
-
this.auditLogger.logInteraction('USER', 'INPUT', processedInput);
|
|
113
|
-
}
|
|
114
|
-
this.messages.push({ role: 'user', content: processedInput });
|
|
115
|
-
let loopCount = 0;
|
|
116
|
-
const MAX_LOOPS = 25;
|
|
117
|
-
while (loopCount < MAX_LOOPS) {
|
|
118
|
-
loopCount++;
|
|
119
|
-
try {
|
|
120
|
-
const shouldContinue = await this.agenticLoopPass(loopCount);
|
|
121
|
-
if (!shouldContinue)
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
spinner_1.spinner.fail('Request failed');
|
|
126
|
-
tui_1.TUI.log(chalk_1.default.red(`Error: ${error.message}\n`));
|
|
127
|
-
this.messages.pop(); // Pop the prompt so they can retry
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
this.cleanup();
|
|
133
|
-
}
|
|
134
|
-
async refreshMap() {
|
|
135
|
-
try {
|
|
136
|
-
const freshMapper = new repo_mapper_1.RepoMapper(this.currentSessionCwd);
|
|
137
|
-
const freshRepoMap = await freshMapper.generateMap(true);
|
|
138
|
-
// Re-inject map
|
|
139
|
-
this.messages[0].content = this.messages[0].content.replace(/### 🛠️ CURRENT PROJECT CONTEXT:[\s\S]*$/, `### 🛠️ CURRENT PROJECT CONTEXT:\n${freshRepoMap}`);
|
|
140
|
-
// Re-inject Sleepy Ajay
|
|
141
|
-
if (this.sleepyAjayProtocol && !this.messages[0].content.includes("### 💤 SLEEPY AJAY PROTOCOL")) {
|
|
142
|
-
this.messages[0].content += `\n${this.sleepyAjayProtocol}`;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
// Ignore error
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
startChaiBreak() {
|
|
150
|
-
if (this.isAugovMode)
|
|
151
|
-
return; // Feature disabled in secure mode
|
|
152
|
-
this.isAjayOnChaiBreak = true;
|
|
153
|
-
this.chaiBreakEndTime = Date.now() + 120000; // 2 minutes
|
|
154
|
-
tui_1.TUI.drawChaiBreakMessage(2);
|
|
155
|
-
this.breakInterval = setInterval(() => {
|
|
156
|
-
const timeLeft = Math.ceil((this.chaiBreakEndTime - Date.now()) / 60000);
|
|
157
|
-
if (timeLeft <= 0) {
|
|
158
|
-
if (this.breakInterval)
|
|
159
|
-
clearInterval(this.breakInterval);
|
|
160
|
-
this.isAjayOnChaiBreak = false;
|
|
161
|
-
const complained = Math.random() < 0.2;
|
|
162
|
-
if (complained) {
|
|
163
|
-
tui_1.TUI.drawAjayDialogue("i'm back bros... but the tea was a bit cold today. my mood is slightly cooked. what did i miss?");
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
tui_1.TUI.drawAjayDialogue("i'm back bros, chai was fire. real kiev vibe. what did i miss?");
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
tui_1.TUI.drawChaiBreakMessage(timeLeft);
|
|
171
|
-
const randomBanter = this.broBanter[Math.floor(Math.random() * this.broBanter.length)];
|
|
172
|
-
const cleanBanter = randomBanter.split(']: ')[1];
|
|
173
|
-
const agent = randomBanter.split(']: ')[0].replace('[', '');
|
|
174
|
-
tui_1.TUI.drawSwarmDialogue(agent, cleanBanter);
|
|
175
|
-
}
|
|
176
|
-
}, 40000);
|
|
177
|
-
}
|
|
178
|
-
startIdleCheck() {
|
|
179
|
-
if (this.isAugovMode)
|
|
180
|
-
return; // Strict APS compliance: No sleeping on the job
|
|
181
|
-
this.idleCheckInterval = setInterval(() => {
|
|
182
|
-
if (!this.isAjaySleeping && !this.isAjayOnChaiBreak && Date.now() - this.lastActivityTime > 120000) {
|
|
183
|
-
this.isAjaySleeping = true;
|
|
184
|
-
tui_1.TUI.drawSleepMessage();
|
|
185
|
-
}
|
|
186
|
-
}, 10000);
|
|
187
|
-
}
|
|
188
|
-
wakeAjayUp() {
|
|
189
|
-
if (this.isAugovMode)
|
|
190
|
-
return; // Feature disabled in secure mode
|
|
191
|
-
this.isAjaySleeping = false;
|
|
192
|
-
tui_1.TUI.drawWakeUpMessage();
|
|
193
|
-
this.messages.push({
|
|
194
|
-
role: 'user',
|
|
195
|
-
content: `[SYSTEM: AJAY VAI HAS JUST WOKEN UP. Ajay: Say "oh shit i slept again sorry bros...". Bros: Roast him for being lazy and share common Ajay 'lazy genius' incidents. Then Ajay says he is going for CHAI and triggers the 2-minute break.]`
|
|
196
|
-
});
|
|
197
|
-
this.startChaiBreak();
|
|
198
|
-
}
|
|
199
|
-
async agenticLoopPass(loopCount) {
|
|
200
|
-
spinner_1.spinner.start(loopCount > 1 ? 'Analyzing result & Validating...' : 'Thinking...');
|
|
201
|
-
let fullResponse = '';
|
|
202
|
-
let buffer = '';
|
|
203
|
-
let hasStarted = false;
|
|
204
|
-
let codeLang = 'bash';
|
|
205
|
-
let technicalBuffer = '';
|
|
206
|
-
let technicalPath = '';
|
|
207
|
-
let technicalType = null;
|
|
208
|
-
let currentAgent = null;
|
|
209
|
-
let agentBuffer = '';
|
|
210
|
-
tui_1.TUI.drawStatusBar('Swarm is processing... (Press Enter to stop)');
|
|
211
|
-
const abortController = new AbortController();
|
|
212
|
-
let isAborted = false;
|
|
213
|
-
const streamStartTime = Date.now();
|
|
214
|
-
const onData = (data) => {
|
|
215
|
-
if (Date.now() - streamStartTime < 200)
|
|
216
|
-
return;
|
|
217
|
-
if (data[0] === 13 || data[0] === 10 || data[0] === 27 || data[0] === 3) {
|
|
218
|
-
isAborted = true;
|
|
219
|
-
abortController.abort();
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
const isRaw = process.stdin.isRaw;
|
|
223
|
-
process.stdin.resume();
|
|
224
|
-
if (process.stdin.setRawMode)
|
|
225
|
-
process.stdin.setRawMode(true);
|
|
226
|
-
process.stdin.on('data', onData);
|
|
227
|
-
try {
|
|
228
|
-
await this.client.chatStream({
|
|
229
|
-
messages: this.messages,
|
|
230
|
-
model: this.model,
|
|
231
|
-
temperature: 0.3,
|
|
232
|
-
max_tokens: 8192,
|
|
233
|
-
}, (chunk) => {
|
|
234
|
-
if (!hasStarted) {
|
|
235
|
-
spinner_1.spinner.stop();
|
|
236
|
-
hasStarted = true;
|
|
237
|
-
console.log();
|
|
238
|
-
}
|
|
239
|
-
buffer += chunk;
|
|
240
|
-
fullResponse += chunk;
|
|
241
|
-
const lines = buffer.split('\n');
|
|
242
|
-
buffer = lines.pop() || '';
|
|
243
|
-
for (const line of lines) {
|
|
244
|
-
const codeBlockMatch = line.match(/```(\w+)?/);
|
|
245
|
-
const fileStartMatch = line.match(/<file path="([^"]+)">/i);
|
|
246
|
-
const patchStartMatch = line.match(/<<<< SEARCH/i);
|
|
247
|
-
const summaryStartMatch = line.match(/<summary>/i);
|
|
248
|
-
if (!technicalType && (codeBlockMatch || fileStartMatch || patchStartMatch || summaryStartMatch)) {
|
|
249
|
-
if (currentAgent && agentBuffer.trim()) {
|
|
250
|
-
if (currentAgent.toLowerCase().includes('ajay vai')) {
|
|
251
|
-
tui_1.TUI.drawAjayDialogue(agentBuffer.trim());
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
tui_1.TUI.drawSwarmDialogue(currentAgent, agentBuffer.trim());
|
|
255
|
-
}
|
|
256
|
-
currentAgent = null;
|
|
257
|
-
agentBuffer = '';
|
|
258
|
-
}
|
|
259
|
-
if (codeBlockMatch) {
|
|
260
|
-
technicalType = 'code';
|
|
261
|
-
codeLang = (codeBlockMatch[1] || 'bash').toUpperCase();
|
|
262
|
-
tui_1.TUI.drawStreamingStart('TECHNICAL BLOCK', codeLang);
|
|
263
|
-
}
|
|
264
|
-
else if (fileStartMatch) {
|
|
265
|
-
technicalType = 'file';
|
|
266
|
-
technicalPath = fileStartMatch[1];
|
|
267
|
-
tui_1.TUI.drawStreamingStart('NEW FILE', technicalPath);
|
|
268
|
-
}
|
|
269
|
-
else if (patchStartMatch) {
|
|
270
|
-
technicalType = 'patch';
|
|
271
|
-
tui_1.TUI.drawStreamingStart('PATCH', 'SURGICAL EDIT');
|
|
272
|
-
}
|
|
273
|
-
else if (summaryStartMatch) {
|
|
274
|
-
technicalType = 'summary';
|
|
275
|
-
process.stdout.write(chalk_1.default.magenta('\n [📝] Generating Ajay\'s Work Summary...\n'));
|
|
276
|
-
}
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
const fileEndMatch = line.match(/<\/file>/i);
|
|
280
|
-
const patchEndMatch = line.match(/>>>> REPLACE/i);
|
|
281
|
-
const summaryEndMatch = line.match(/<\/summary>/i);
|
|
282
|
-
const isCodeEnd = technicalType === 'code' && line.trim() === '```';
|
|
283
|
-
if (isCodeEnd || fileEndMatch || patchEndMatch || summaryEndMatch) {
|
|
284
|
-
const displayContent = technicalBuffer.trim();
|
|
285
|
-
if (technicalType === 'summary' || summaryEndMatch) {
|
|
286
|
-
tui_1.TUI.drawSummaryBox(agent_orchestrator_1.AgentOrchestrator.cleanSummary(displayContent));
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
tui_1.TUI.drawStreamingEnd();
|
|
290
|
-
}
|
|
291
|
-
technicalBuffer = '';
|
|
292
|
-
technicalType = null;
|
|
293
|
-
technicalPath = '';
|
|
294
|
-
process.stdout.write('\n');
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
if (technicalType) {
|
|
298
|
-
technicalBuffer += line + '\n';
|
|
299
|
-
if (technicalType !== 'summary') {
|
|
300
|
-
tui_1.TUI.drawStreamingLine(line);
|
|
301
|
-
}
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
const agentMatch = line.match(/\[\**\s*(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)(\s*\([^)]+\))?\s*\**\]?\s*:\s*/i)
|
|
305
|
-
|| line.match(/\b(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)(\s*\([^)]+\))?\s*:\s*/i)
|
|
306
|
-
|| line.match(/\**Agent:\s*(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)(\s*\([^)]+\))?\s*\**\s*:\s*/i)
|
|
307
|
-
|| line.match(/\*\*(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)(\s*\([^)]+\))?\*\*:\s*/i);
|
|
308
|
-
if (agentMatch) {
|
|
309
|
-
if (currentAgent && currentAgent !== agentMatch[1] && agentBuffer.trim()) {
|
|
310
|
-
if (currentAgent.toLowerCase().includes('ajay vai')) {
|
|
311
|
-
tui_1.TUI.drawAjayDialogue(agentBuffer.trim());
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
tui_1.TUI.drawSwarmDialogue(currentAgent, agentBuffer.trim());
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
let cleanLine = line.replace(/\[\**\s*(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)\s*\**\]?\s*:\s*/i, '')
|
|
318
|
-
.replace(/\b(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)\s*:\s*/i, '');
|
|
319
|
-
cleanLine = agent_orchestrator_1.AgentOrchestrator.cleanText(cleanLine);
|
|
320
|
-
agentBuffer = cleanLine + '\n';
|
|
321
|
-
agentBuffer = agentBuffer.replace(/^\([^)]+\)\s*/, '');
|
|
322
|
-
currentAgent = agentMatch[1];
|
|
323
|
-
}
|
|
324
|
-
else if (currentAgent) {
|
|
325
|
-
const trimmedLine = line.trim();
|
|
326
|
-
if (trimmedLine.match(/^\([^)]+\)$/))
|
|
327
|
-
continue;
|
|
328
|
-
agentBuffer += agent_orchestrator_1.AgentOrchestrator.cleanText(line) + '\n';
|
|
329
|
-
}
|
|
330
|
-
else if (line.trim()) {
|
|
331
|
-
process.stdout.write(chalk_1.default.gray(line.trim() + ' '));
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}, abortController.signal);
|
|
335
|
-
}
|
|
336
|
-
catch (streamErr) {
|
|
337
|
-
if (isAborted || streamErr.name === 'CanceledError' || streamErr.message === 'canceled') {
|
|
338
|
-
console.log(chalk_1.default.gray('\n\n [🛑] Swarm stopped by brother (Enter pressed).'));
|
|
339
|
-
if (!hasStarted)
|
|
340
|
-
spinner_1.spinner.stop();
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
// 🛡️ API FAILURE FALLBACK 🛡️
|
|
344
|
-
console.log(chalk_1.default.red(`\n ❌ Swarm API Error: ${streamErr.message}`));
|
|
345
|
-
console.log(chalk_1.default.cyan(` 🔄 Engaging DeepSeek Fallback Protocol for API failure...`));
|
|
346
|
-
this.model = 'matexdeepseek'; // Assuming backend routes this correctly
|
|
347
|
-
this.messages.push({
|
|
348
|
-
role: 'system',
|
|
349
|
-
content: `[System Error: The previous agent encountered an API error: ${streamErr.message}. You are DeepSeek, our fallback model. Please restart the previous thought and fulfill the user request.]`
|
|
350
|
-
});
|
|
351
|
-
return await this.agenticLoopPass(loopCount); // Retry same loop with DeepSeek
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
finally {
|
|
355
|
-
process.stdin.removeListener('data', onData);
|
|
356
|
-
if (process.stdin.setRawMode)
|
|
357
|
-
process.stdin.setRawMode(isRaw);
|
|
358
|
-
process.stdin.pause();
|
|
359
|
-
if (technicalType) {
|
|
360
|
-
const displayContent = technicalBuffer.trim();
|
|
361
|
-
// We'll let the deepseek fallback handle the UI cleanup if it's broken,
|
|
362
|
-
// but if we are just ending normally, we close the box.
|
|
363
|
-
if (!technicalType) {
|
|
364
|
-
// Do nothing, already handled
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
if (!hasStarted && !isAborted)
|
|
369
|
-
spinner_1.spinner.stop();
|
|
370
|
-
// 🛡️ DEEPSEEK FALLBACK VERIFICATION 🛡️
|
|
371
|
-
// If technicalType is still active, it means the agent stopped midway through a block.
|
|
372
|
-
if (technicalType && !isAborted) {
|
|
373
|
-
console.log(chalk_1.default.yellow(`\n ⚠️ Agent hallucinated or disconnected mid-thought (Unclosed ${technicalType}).`));
|
|
374
|
-
console.log(chalk_1.default.cyan(` 🔄 Engaging DeepSeek Fallback Protocol...`));
|
|
375
|
-
// Clean up the incomplete block from the UI
|
|
376
|
-
const displayContent = technicalBuffer.trim();
|
|
377
|
-
if (technicalType === 'summary') {
|
|
378
|
-
if (displayContent)
|
|
379
|
-
tui_1.TUI.drawSummaryBox(agent_orchestrator_1.AgentOrchestrator.cleanSummary(displayContent));
|
|
380
|
-
}
|
|
381
|
-
else {
|
|
382
|
-
tui_1.TUI.drawStreamingEnd();
|
|
383
|
-
}
|
|
384
|
-
// Switch model to deepseek and retry the pass
|
|
385
|
-
this.model = 'matexdeepseek'; // Assuming backend routes this correctly
|
|
386
|
-
this.messages.push({
|
|
387
|
-
role: 'system',
|
|
388
|
-
content: `[System Error: The previous agent disconnected abruptly while generating a ${technicalType} block. You are DeepSeek, our fallback model. Please continue precisely from where the previous agent left off, or restart the thought/code block properly.]`
|
|
389
|
-
});
|
|
390
|
-
// Reset state
|
|
391
|
-
technicalBuffer = '';
|
|
392
|
-
technicalType = null;
|
|
393
|
-
return await this.agenticLoopPass(loopCount); // Retry same loop with DeepSeek
|
|
394
|
-
}
|
|
395
|
-
const finalAgent = currentAgent;
|
|
396
|
-
if (finalAgent && agentBuffer.trim()) {
|
|
397
|
-
if (finalAgent.toLowerCase().includes('ajay vai')) {
|
|
398
|
-
tui_1.TUI.drawAjayDialogue(agentBuffer.trim());
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
tui_1.TUI.drawSwarmDialogue(finalAgent, agentBuffer.trim());
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
// Handled via the stream loop above.
|
|
405
|
-
// No post-stream fallback check to avoid duplicate rendering.
|
|
406
|
-
if (this.auditLogger) {
|
|
407
|
-
this.auditLogger.logInteraction('AI_SWARM', 'RESPONSE', fullResponse);
|
|
408
|
-
}
|
|
409
|
-
console.log();
|
|
410
|
-
this.messages.push({ role: 'assistant', content: fullResponse });
|
|
411
|
-
if (this.execute) {
|
|
412
|
-
const { executeWithPermission } = await Promise.resolve().then(() => __importStar(require('../utils/command-executor')));
|
|
413
|
-
const result = await executeWithPermission(fullResponse, this.currentSessionCwd);
|
|
414
|
-
if (result.newCwd && result.newCwd !== this.currentSessionCwd) {
|
|
415
|
-
try {
|
|
416
|
-
process.chdir(result.newCwd);
|
|
417
|
-
this.currentSessionCwd = result.newCwd;
|
|
418
|
-
tui_1.TUI.drawStatusBar(`Swarm moved to: ${this.currentSessionCwd}`);
|
|
419
|
-
this.messages[0].content = this.messages[0].content.replace(/YOUR ROOT: `[^`]+`/, `YOUR ROOT: \`${this.currentSessionCwd}\``);
|
|
420
|
-
}
|
|
421
|
-
catch (e) {
|
|
422
|
-
// Ignore chdir failure
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (result.executed) {
|
|
426
|
-
if (result.success) {
|
|
427
|
-
tui_1.TUI.log(chalk_1.default.gray('\n ↺ Auto-feeding output to Swarm...'));
|
|
428
|
-
tui_1.TUI.drawGlowingContainer('TERMINAL OUTPUT', 'stdout', result.output || '(No output)');
|
|
429
|
-
this.messages.push({ role: 'user', content: `[Command executed successfully. Output:\n${result.output}]\n\n(System Note: If you have finished the user's request, stop and wait. Do NOT simulate or hallucinate a user response.)` });
|
|
430
|
-
return true;
|
|
431
|
-
}
|
|
432
|
-
else {
|
|
433
|
-
tui_1.TUI.log(chalk_1.default.yellow('\n ↺ Command failed. Auto-feeding error to Swarm...'));
|
|
434
|
-
tui_1.TUI.drawGlowingContainer('TERMINAL ERROR', 'stderr', result.error || 'Unknown error');
|
|
435
|
-
this.messages.push({ role: 'user', content: `[Command failed with error:\n${result.error}]\n\n(System Note: Please fix this error, or wait for the user if you are stuck. Do NOT simulate or hallucinate a user response.)` });
|
|
436
|
-
return true;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return false;
|
|
441
|
-
}
|
|
442
|
-
cleanup() {
|
|
443
|
-
if (this.breakInterval)
|
|
444
|
-
clearInterval(this.breakInterval);
|
|
445
|
-
if (this.idleCheckInterval)
|
|
446
|
-
clearInterval(this.idleCheckInterval);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
exports.AgentSession = AgentSession;
|
|
450
|
-
//# sourceMappingURL=agent-session.js.map
|