matex-cli 1.2.81 → 1.2.84

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.
Files changed (142) hide show
  1. package/dist/commands/chaos.js +3 -8
  2. package/dist/prompts/chaos-prompts.js +26 -21
  3. package/dist/session/agent-session.js +38 -9
  4. package/dist/utils/agent-orchestrator.js +7 -0
  5. package/dist/utils/mcp-server.js +6 -0
  6. package/dist/utils/tui.js +84 -7
  7. package/package.json +7 -1
  8. package/.agents/skills/mcp-server-dev/SKILL.md +0 -60
  9. package/.agents/skills/mcp-server-dev/examples/basic-ts-server/package.json +0 -20
  10. package/.agents/skills/mcp-server-dev/examples/basic-ts-server/src/index.ts +0 -66
  11. package/.agents/skills/mcp-server-dev/resources/best_practices.md +0 -20
  12. package/.agents/skills/pptx-presentation-builder/SKILL.md +0 -338
  13. package/.agents/workflows/deploy.md +0 -27
  14. package/dist/api/client.d.ts +0 -40
  15. package/dist/api/client.d.ts.map +0 -1
  16. package/dist/api/client.js.map +0 -1
  17. package/dist/commands/ask.d.ts +0 -3
  18. package/dist/commands/ask.d.ts.map +0 -1
  19. package/dist/commands/ask.js.map +0 -1
  20. package/dist/commands/augov.d.ts +0 -3
  21. package/dist/commands/augov.d.ts.map +0 -1
  22. package/dist/commands/augov.js.map +0 -1
  23. package/dist/commands/bro.d.ts +0 -4
  24. package/dist/commands/bro.d.ts.map +0 -1
  25. package/dist/commands/bro.js.map +0 -1
  26. package/dist/commands/chaos.d.ts +0 -3
  27. package/dist/commands/chaos.d.ts.map +0 -1
  28. package/dist/commands/chaos.js.map +0 -1
  29. package/dist/commands/chat.d.ts +0 -3
  30. package/dist/commands/chat.d.ts.map +0 -1
  31. package/dist/commands/chat.js.map +0 -1
  32. package/dist/commands/code.d.ts +0 -3
  33. package/dist/commands/code.d.ts.map +0 -1
  34. package/dist/commands/code.js.map +0 -1
  35. package/dist/commands/config.d.ts +0 -3
  36. package/dist/commands/config.d.ts.map +0 -1
  37. package/dist/commands/config.js.map +0 -1
  38. package/dist/commands/dev.d.ts +0 -3
  39. package/dist/commands/dev.d.ts.map +0 -1
  40. package/dist/commands/dev.js.map +0 -1
  41. package/dist/commands/help.d.ts +0 -3
  42. package/dist/commands/help.d.ts.map +0 -1
  43. package/dist/commands/help.js.map +0 -1
  44. package/dist/commands/login.d.ts +0 -3
  45. package/dist/commands/login.d.ts.map +0 -1
  46. package/dist/commands/login.js.map +0 -1
  47. package/dist/commands/models.d.ts +0 -3
  48. package/dist/commands/models.d.ts.map +0 -1
  49. package/dist/commands/models.js.map +0 -1
  50. package/dist/commands/student.d.ts +0 -3
  51. package/dist/commands/student.d.ts.map +0 -1
  52. package/dist/commands/student.js.map +0 -1
  53. package/dist/commands/study.d.ts +0 -3
  54. package/dist/commands/study.d.ts.map +0 -1
  55. package/dist/commands/study.js.map +0 -1
  56. package/dist/index.d.ts +0 -3
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js.map +0 -1
  59. package/dist/prompts/banter-augov.d.ts +0 -2
  60. package/dist/prompts/banter-augov.d.ts.map +0 -1
  61. package/dist/prompts/banter-augov.js.map +0 -1
  62. package/dist/prompts/banter.d.ts +0 -6
  63. package/dist/prompts/banter.d.ts.map +0 -1
  64. package/dist/prompts/banter.js.map +0 -1
  65. package/dist/prompts/chaos-prompts.d.ts +0 -3
  66. package/dist/prompts/chaos-prompts.d.ts.map +0 -1
  67. package/dist/prompts/chaos-prompts.js.map +0 -1
  68. package/dist/prompts/system-prompts.d.ts +0 -4
  69. package/dist/prompts/system-prompts.d.ts.map +0 -1
  70. package/dist/prompts/system-prompts.js.map +0 -1
  71. package/dist/session/agent-session.d.ts +0 -41
  72. package/dist/session/agent-session.d.ts.map +0 -1
  73. package/dist/session/agent-session.js.map +0 -1
  74. package/dist/utils/agent-orchestrator.d.ts +0 -44
  75. package/dist/utils/agent-orchestrator.d.ts.map +0 -1
  76. package/dist/utils/agent-orchestrator.js.map +0 -1
  77. package/dist/utils/augov-logger.d.ts +0 -11
  78. package/dist/utils/augov-logger.d.ts.map +0 -1
  79. package/dist/utils/augov-logger.js.map +0 -1
  80. package/dist/utils/augov-scrubber.d.ts +0 -23
  81. package/dist/utils/augov-scrubber.d.ts.map +0 -1
  82. package/dist/utils/augov-scrubber.js.map +0 -1
  83. package/dist/utils/command-executor.d.ts +0 -56
  84. package/dist/utils/command-executor.d.ts.map +0 -1
  85. package/dist/utils/command-executor.js.map +0 -1
  86. package/dist/utils/config.d.ts +0 -56
  87. package/dist/utils/config.d.ts.map +0 -1
  88. package/dist/utils/config.js.map +0 -1
  89. package/dist/utils/mcp-server.d.ts +0 -77
  90. package/dist/utils/mcp-server.d.ts.map +0 -1
  91. package/dist/utils/mcp-server.js.map +0 -1
  92. package/dist/utils/patcher.d.ts +0 -45
  93. package/dist/utils/patcher.d.ts.map +0 -1
  94. package/dist/utils/patcher.js.map +0 -1
  95. package/dist/utils/repo-mapper.d.ts +0 -32
  96. package/dist/utils/repo-mapper.d.ts.map +0 -1
  97. package/dist/utils/repo-mapper.js.map +0 -1
  98. package/dist/utils/spinner.d.ts +0 -15
  99. package/dist/utils/spinner.d.ts.map +0 -1
  100. package/dist/utils/spinner.js.map +0 -1
  101. package/dist/utils/tui.d.ts +0 -134
  102. package/dist/utils/tui.d.ts.map +0 -1
  103. package/dist/utils/tui.js.map +0 -1
  104. package/fix-npm-permissions.sh +0 -23
  105. package/publish-local.sh +0 -16
  106. package/skills-lock.json +0 -10
  107. package/src/api/client.ts +0 -197
  108. package/src/commands/ask.ts +0 -62
  109. package/src/commands/augov.ts +0 -301
  110. package/src/commands/bro.ts +0 -336
  111. package/src/commands/chaos.ts +0 -67
  112. package/src/commands/chat.ts +0 -61
  113. package/src/commands/code.ts +0 -99
  114. package/src/commands/config.ts +0 -78
  115. package/src/commands/dev.ts +0 -68
  116. package/src/commands/help.ts +0 -67
  117. package/src/commands/login.ts +0 -47
  118. package/src/commands/models.ts +0 -81
  119. package/src/commands/student.ts +0 -23
  120. package/src/commands/study.ts +0 -75
  121. package/src/index.ts +0 -284
  122. package/src/prompts/banter-augov.ts +0 -17
  123. package/src/prompts/banter.ts +0 -101
  124. package/src/prompts/chaos-prompts.ts +0 -48
  125. package/src/prompts/system-prompts.ts +0 -145
  126. package/src/session/agent-session.ts +0 -428
  127. package/src/utils/agent-orchestrator.ts +0 -264
  128. package/src/utils/augov-logger.ts +0 -34
  129. package/src/utils/augov-scrubber.ts +0 -67
  130. package/src/utils/command-executor.ts +0 -529
  131. package/src/utils/config.ts +0 -124
  132. package/src/utils/mcp-server.ts +0 -388
  133. package/src/utils/patcher.ts +0 -229
  134. package/src/utils/repo-mapper.ts +0 -198
  135. package/src/utils/spinner.ts +0 -66
  136. package/src/utils/tui.ts +0 -749
  137. package/test-chaos-container.js +0 -16
  138. package/test-chaos-fix.js +0 -18
  139. package/test-config.ts +0 -2
  140. package/test-ui-output.js +0 -16
  141. package/tsconfig.json +0 -27
  142. package/vertex_ai_agent.py +0 -52
@@ -1,428 +0,0 @@
1
- import chalk from 'chalk';
2
- import inquirer from 'inquirer';
3
- import { MatexAPIClient } from '../api/client';
4
- import { ChatMessage } from '../api/client';
5
- import { TUI } from '../utils/tui';
6
- import { AgentOrchestrator } from '../utils/agent-orchestrator';
7
- import { spinner } from '../utils/spinner';
8
- import { RepoMapper } from '../utils/repo-mapper';
9
-
10
- export interface AgentSessionConfig {
11
- isAugovMode?: boolean;
12
- client: MatexAPIClient;
13
- model: string;
14
- execute: boolean;
15
- initialMessages: ChatMessage[];
16
- broBanter: string[];
17
- sleepyAjayProtocol?: string;
18
- baseDir: string;
19
- messageScrubber?: (input: string) => string;
20
- auditLogger?: any;
21
- }
22
-
23
- export class AgentSession {
24
- private client: MatexAPIClient;
25
- private model: string;
26
- private execute: boolean;
27
- private messages: ChatMessage[];
28
- private broBanter: string[];
29
- private sleepyAjayProtocol?: string;
30
- private currentSessionCwd: string;
31
- private messageScrubber?: (input: string) => string;
32
- private auditLogger?: any;
33
- private isAugovMode?: boolean;
34
-
35
- private lastActivityTime: number = Date.now();
36
- private isAjaySleeping: boolean = false;
37
- private isAjayOnChaiBreak: boolean = false;
38
- private chaiBreakEndTime: number = 0;
39
- private breakInterval: NodeJS.Timeout | null = null;
40
- private idleCheckInterval: NodeJS.Timeout | null = null;
41
-
42
- constructor(config: AgentSessionConfig) {
43
- this.client = config.client;
44
- this.model = config.model;
45
- this.execute = config.execute;
46
- this.messages = config.initialMessages;
47
- this.broBanter = config.broBanter;
48
- this.sleepyAjayProtocol = config.sleepyAjayProtocol;
49
- this.currentSessionCwd = config.baseDir;
50
- this.messageScrubber = config.messageScrubber;
51
- this.auditLogger = config.auditLogger;
52
- this.isAugovMode = config.isAugovMode;
53
- }
54
-
55
- public async start() {
56
- this.startIdleCheck();
57
-
58
- while (true) {
59
- this.lastActivityTime = Date.now();
60
-
61
- // Premium UI Box (Same as AU-GOV but for Dev)
62
- const darkBorder = chalk.hex('#1E3A8A');
63
- const primaryText = chalk.hex('#3B82F6');
64
- const shadow = chalk.hex('#1e1e1e');
65
-
66
- console.log(shadow('┌─────────────────────────────────────────────────────────────────────────────┐'));
67
- if (this.isAugovMode) {
68
- console.log(shadow('│') + chalk.gray(' Using 1 SECURE node file 1 AU-GOV validated server ') + shadow('│'));
69
- } else {
70
- console.log(shadow('│') + chalk.gray(' Using 1 MATEX_Orchestrator 1 MCP server ') + shadow('│'));
71
- }
72
- console.log(shadow('├─────────────────────────────────────────────────────────────────────────────┤'));
73
-
74
- const { userInput } = await inquirer.prompt([
75
- {
76
- type: 'input',
77
- name: 'userInput',
78
- message: shadow('│ ') + primaryText('> '),
79
- prefix: ''
80
- }
81
- ]);
82
-
83
- if (this.isAugovMode || true) { // Always show status footer in premium mode
84
- const homeDirDisplay = this.currentSessionCwd.replace(process.env.HOME || '', '~');
85
- console.log(shadow('└─────────────────────────────────────────────────────────────────────────────┘'));
86
- console.log(chalk.gray(` ${homeDirDisplay.padEnd(30)} sandbox-exec (minimal)\n`));
87
- }
88
-
89
- this.lastActivityTime = Date.now();
90
-
91
- if (this.isAjaySleeping) {
92
- this.wakeAjayUp();
93
- }
94
-
95
- if (userInput.toLowerCase() === 'exit' || userInput.toLowerCase() === 'quit') {
96
- console.log(chalk.yellow('\n👋 Ending session. Happy coding!\n'));
97
- break;
98
- }
99
-
100
- if (!userInput.trim()) continue;
101
-
102
- let processedInput = userInput;
103
- if (this.messageScrubber) {
104
- processedInput = this.messageScrubber(userInput);
105
- if (userInput !== processedInput) {
106
- TUI.log(chalk.yellow('\n 🛡️ Privacy Shield Active: Sensitive Australian data was redacted locally.'));
107
- }
108
- }
109
-
110
- if (this.auditLogger) {
111
- this.auditLogger.logInteraction('USER', 'INPUT', processedInput);
112
- }
113
-
114
- this.messages.push({ role: 'user', content: processedInput });
115
-
116
- let loopCount = 0;
117
- const MAX_LOOPS = 25;
118
-
119
- while (loopCount < MAX_LOOPS) {
120
- loopCount++;
121
- try {
122
- const shouldContinue = await this.agenticLoopPass(loopCount);
123
- if (!shouldContinue) break;
124
- } catch (error: any) {
125
- spinner.fail('Request failed');
126
- TUI.log(chalk.red(`Error: ${error.message}\n`));
127
- this.messages.pop(); // Pop the prompt so they can retry
128
- break;
129
- }
130
- }
131
- }
132
-
133
- this.cleanup();
134
- }
135
-
136
- private async refreshMap() {
137
- try {
138
- const freshMapper = new RepoMapper(this.currentSessionCwd);
139
- const freshRepoMap = await freshMapper.generateMap(true);
140
-
141
- // Re-inject map
142
- this.messages[0].content = this.messages[0].content.replace(/### 🛠️ CURRENT PROJECT CONTEXT:[\s\S]*$/, `### 🛠️ CURRENT PROJECT CONTEXT:\n${freshRepoMap}`);
143
-
144
- // Re-inject Sleepy Ajay
145
- if (this.sleepyAjayProtocol && !this.messages[0].content.includes("### 💤 SLEEPY AJAY PROTOCOL")) {
146
- this.messages[0].content += `\n${this.sleepyAjayProtocol}`;
147
- }
148
- } catch (e) {
149
- // Ignore error
150
- }
151
- }
152
-
153
- private startChaiBreak() {
154
- if (this.isAugovMode) return; // Feature disabled in secure mode
155
-
156
- this.isAjayOnChaiBreak = true;
157
- this.chaiBreakEndTime = Date.now() + 120000; // 2 minutes
158
- TUI.drawChaiBreakMessage(2);
159
-
160
- this.breakInterval = setInterval(() => {
161
- const timeLeft = Math.ceil((this.chaiBreakEndTime - Date.now()) / 60000);
162
- if (timeLeft <= 0) {
163
- if (this.breakInterval) clearInterval(this.breakInterval);
164
- this.isAjayOnChaiBreak = false;
165
- const complained = Math.random() < 0.2;
166
- if (complained) {
167
- TUI.drawAjayDialogue("i'm back bros... but the tea was a bit cold today. my mood is slightly cooked. what did i miss?");
168
- } else {
169
- TUI.drawAjayDialogue("i'm back bros, chai was fire. real kiev vibe. what did i miss?");
170
- }
171
- } else {
172
- TUI.drawChaiBreakMessage(timeLeft);
173
- const randomBanter = this.broBanter[Math.floor(Math.random() * this.broBanter.length)];
174
- const cleanBanter = randomBanter.split(']: ')[1];
175
- const agent = randomBanter.split(']: ')[0].replace('[', '');
176
- TUI.drawSwarmDialogue(agent, cleanBanter);
177
- }
178
- }, 40000);
179
- }
180
-
181
- private startIdleCheck() {
182
- if (this.isAugovMode) return; // Strict APS compliance: No sleeping on the job
183
-
184
- this.idleCheckInterval = setInterval(() => {
185
- if (!this.isAjaySleeping && !this.isAjayOnChaiBreak && Date.now() - this.lastActivityTime > 120000) {
186
- this.isAjaySleeping = true;
187
- TUI.drawSleepMessage();
188
- }
189
- }, 10000);
190
- }
191
-
192
- private wakeAjayUp() {
193
- if (this.isAugovMode) return; // Feature disabled in secure mode
194
-
195
- this.isAjaySleeping = false;
196
- TUI.drawWakeUpMessage();
197
- this.messages.push({
198
- role: 'user',
199
- 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.]`
200
- });
201
- this.startChaiBreak();
202
- }
203
-
204
- private async agenticLoopPass(loopCount: number): Promise<boolean> {
205
- spinner.start(loopCount > 1 ? 'Analyzing result & Validating...' : 'Thinking...');
206
-
207
- let fullResponse = '';
208
- let buffer = '';
209
- let hasStarted = false;
210
- let codeLang = 'bash';
211
- let technicalBuffer = '';
212
- let technicalPath = '';
213
- let technicalType: 'code' | 'file' | 'patch' | 'summary' | null = null;
214
-
215
- let currentAgent: string | null = null;
216
- let agentBuffer: string = '';
217
-
218
- TUI.drawStatusBar('Swarm is processing... (Press Enter to stop)');
219
-
220
- const abortController = new AbortController();
221
- let isAborted = false;
222
- const streamStartTime = Date.now();
223
-
224
- const onData = (data: Buffer) => {
225
- if (Date.now() - streamStartTime < 200) return;
226
- if (data[0] === 13 || data[0] === 10 || data[0] === 27 || data[0] === 3) {
227
- isAborted = true;
228
- abortController.abort();
229
- }
230
- };
231
-
232
- const isRaw = process.stdin.isRaw;
233
- process.stdin.resume();
234
- if (process.stdin.setRawMode) process.stdin.setRawMode(true);
235
- process.stdin.on('data', onData);
236
-
237
- try {
238
- await this.client.chatStream({
239
- messages: this.messages,
240
- model: this.model,
241
- temperature: 0.3,
242
- max_tokens: 8192,
243
- }, (chunk) => {
244
- if (!hasStarted) {
245
- spinner.stop();
246
- hasStarted = true;
247
- console.log();
248
- }
249
-
250
- buffer += chunk;
251
- fullResponse += chunk;
252
- const lines = buffer.split('\n');
253
- buffer = lines.pop() || '';
254
-
255
- for (const line of lines) {
256
- const codeBlockMatch = line.match(/```(\w+)?/);
257
- const fileStartMatch = line.match(/<file path="([^"]+)">/i);
258
- const patchStartMatch = line.match(/<<<< SEARCH/i);
259
- const summaryStartMatch = line.match(/<summary>/i);
260
-
261
- if (!technicalType && (codeBlockMatch || fileStartMatch || patchStartMatch || summaryStartMatch)) {
262
- if (currentAgent && agentBuffer.trim()) {
263
- if (currentAgent.toLowerCase().includes('ajay vai')) {
264
- TUI.drawAjayDialogue(agentBuffer.trim());
265
- } else {
266
- TUI.drawSwarmDialogue(currentAgent, agentBuffer.trim());
267
- }
268
- currentAgent = null;
269
- agentBuffer = '';
270
- }
271
-
272
- if (codeBlockMatch) {
273
- technicalType = 'code';
274
- codeLang = (codeBlockMatch[1] || 'bash').toUpperCase();
275
- TUI.drawStreamingStart('TECHNICAL BLOCK', codeLang);
276
- } else if (fileStartMatch) {
277
- technicalType = 'file';
278
- technicalPath = fileStartMatch[1];
279
- TUI.drawStreamingStart('NEW FILE', technicalPath);
280
- } else if (patchStartMatch) {
281
- technicalType = 'patch';
282
- TUI.drawStreamingStart('PATCH', 'SURGICAL EDIT');
283
- } else if (summaryStartMatch) {
284
- technicalType = 'summary';
285
- process.stdout.write(chalk.magenta('\n [📝] Generating Ajay\'s Work Summary...\n'));
286
- }
287
- continue;
288
- }
289
-
290
- const fileEndMatch = line.match(/<\/file>/i);
291
- const patchEndMatch = line.match(/>>>> REPLACE/i);
292
- const summaryEndMatch = line.match(/<\/summary>/i);
293
- const isCodeEnd = technicalType === 'code' && line.trim() === '```';
294
-
295
- if (isCodeEnd || fileEndMatch || patchEndMatch || summaryEndMatch) {
296
- const displayContent = technicalBuffer.trim();
297
- if (technicalType === 'summary' || summaryEndMatch) {
298
- TUI.drawSummaryBox(AgentOrchestrator.cleanSummary(displayContent));
299
- } else {
300
- TUI.drawStreamingEnd();
301
- }
302
- technicalBuffer = '';
303
- technicalType = null;
304
- technicalPath = '';
305
- process.stdout.write('\n');
306
- continue;
307
- }
308
-
309
- if (technicalType) {
310
- technicalBuffer += line + '\n';
311
- if (technicalType !== 'summary') {
312
- TUI.drawStreamingLine(line);
313
- }
314
- continue;
315
- }
316
-
317
- const agentMatch = line.match(/\[\**\s*(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)(\s*\([^)]+\))?\s*\**\]?\s*:\s*/i)
318
- || line.match(/\b(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)(\s*\([^)]+\))?\s*:\s*/i)
319
- || line.match(/\**Agent:\s*(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)(\s*\([^)]+\))?\s*\**\s*:\s*/i)
320
- || line.match(/\*\*(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)(\s*\([^)]+\))?\*\*:\s*/i);
321
-
322
- if (agentMatch) {
323
- if (currentAgent && currentAgent !== agentMatch[1] && agentBuffer.trim()) {
324
- if (currentAgent.toLowerCase().includes('ajay vai')) {
325
- TUI.drawAjayDialogue(agentBuffer.trim());
326
- } else {
327
- TUI.drawSwarmDialogue(currentAgent, agentBuffer.trim());
328
- }
329
- }
330
-
331
- let cleanLine = line.replace(/\[\**\s*(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)\s*\**\]?\s*:\s*/i, '')
332
- .replace(/\b(Ajay Vai|Sunil Dai|Sandip Dai|Bishal Dai|Narayan Dai|Big Bro)\s*:\s*/i, '');
333
- cleanLine = AgentOrchestrator.cleanText(cleanLine);
334
- agentBuffer = cleanLine + '\n';
335
- agentBuffer = agentBuffer.replace(/^\([^)]+\)\s*/, '');
336
- currentAgent = agentMatch[1];
337
- } else if (currentAgent) {
338
- const trimmedLine = line.trim();
339
- if (trimmedLine.match(/^\([^)]+\)$/)) continue;
340
- agentBuffer += AgentOrchestrator.cleanText(line) + '\n';
341
- } else if (line.trim()) {
342
- process.stdout.write(chalk.gray(line.trim() + ' '));
343
- }
344
- }
345
- }, abortController.signal);
346
- } catch (streamErr: any) {
347
- if (isAborted || streamErr.name === 'CanceledError' || streamErr.message === 'canceled') {
348
- console.log(chalk.gray('\n\n [🛑] Swarm stopped by brother (Enter pressed).'));
349
- if (!hasStarted) spinner.stop();
350
- } else {
351
- throw streamErr;
352
- }
353
- } finally {
354
- process.stdin.removeListener('data', onData);
355
- if (process.stdin.setRawMode) process.stdin.setRawMode(isRaw);
356
- process.stdin.pause();
357
-
358
- if (technicalType) {
359
- const displayContent = technicalBuffer.trim();
360
- if (technicalType === 'summary') {
361
- if (displayContent) TUI.drawSummaryBox(AgentOrchestrator.cleanSummary(displayContent));
362
- } else {
363
- TUI.drawStreamingEnd();
364
- }
365
- technicalBuffer = '';
366
- technicalType = null;
367
- }
368
- }
369
-
370
- if (!hasStarted && !isAborted) spinner.stop();
371
-
372
- const finalAgent = currentAgent as string | null;
373
- if (finalAgent && agentBuffer.trim()) {
374
- if (finalAgent.toLowerCase().includes('ajay vai')) {
375
- TUI.drawAjayDialogue(agentBuffer.trim());
376
- } else {
377
- TUI.drawSwarmDialogue(finalAgent, agentBuffer.trim());
378
- }
379
- }
380
-
381
- // Handled via the stream loop above.
382
- // No post-stream fallback check to avoid duplicate rendering.
383
-
384
- if (this.auditLogger) {
385
- this.auditLogger.logInteraction('AI_SWARM', 'RESPONSE', fullResponse);
386
- }
387
-
388
- console.log();
389
- this.messages.push({ role: 'assistant', content: fullResponse });
390
-
391
- if (this.execute) {
392
- const { executeWithPermission } = await import('../utils/command-executor');
393
- const result = await executeWithPermission(fullResponse, this.currentSessionCwd);
394
-
395
- if (result.newCwd && result.newCwd !== this.currentSessionCwd) {
396
- try {
397
- process.chdir(result.newCwd);
398
- this.currentSessionCwd = result.newCwd;
399
- TUI.drawStatusBar(`Swarm moved to: ${this.currentSessionCwd}`);
400
- this.messages[0].content = this.messages[0].content.replace(/YOUR ROOT: `[^`]+`/, `YOUR ROOT: \`${this.currentSessionCwd}\``);
401
- } catch (e) {
402
- // Ignore chdir failure
403
- }
404
- }
405
-
406
- if (result.executed) {
407
- if (result.success) {
408
- TUI.log(chalk.gray('\n ↺ Auto-feeding output to Swarm...'));
409
- TUI.drawGlowingContainer('TERMINAL OUTPUT', 'stdout', result.output || '(No output)');
410
- 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.)` });
411
- return true;
412
- } else {
413
- TUI.log(chalk.yellow('\n ↺ Command failed. Auto-feeding error to Swarm...'));
414
- TUI.drawGlowingContainer('TERMINAL ERROR', 'stderr', result.error || 'Unknown error');
415
- 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.)` });
416
- return true;
417
- }
418
- }
419
- }
420
-
421
- return false;
422
- }
423
-
424
- private cleanup() {
425
- if (this.breakInterval) clearInterval(this.breakInterval);
426
- if (this.idleCheckInterval) clearInterval(this.idleCheckInterval);
427
- }
428
- }
@@ -1,264 +0,0 @@
1
- import chalk from 'chalk';
2
- import { TUI, TUIMode } from './tui';
3
-
4
- export type AgentRole = 'Architect' | 'Syntax' | 'Frontend' | 'Backend' | 'System' | 'Commander' | 'Researcher' | 'Ajay Vai' | 'Sunil Dai' | 'Sandip Dai' | 'Narayan Dai' | 'Bishal Dai' | 'Big Bro';
5
-
6
- export interface AgentConfig {
7
- name: string;
8
- icon: string;
9
- color: (text: string) => string;
10
- }
11
-
12
- const AGENT_CONFIGS: Record<AgentRole, AgentConfig> = {
13
- 'Big Bro': {
14
- name: 'Big Bro',
15
- icon: '◈',
16
- color: chalk.hex('#FF6B00'),
17
- },
18
- Architect: {
19
- name: 'MatexCodeArchitect',
20
- icon: '◈',
21
- color: chalk.blue,
22
- },
23
- 'Ajay Vai': {
24
- name: 'Ajay Vai',
25
- icon: '◈',
26
- color: chalk.magenta,
27
- },
28
- 'Sunil Dai': {
29
- name: 'Sunil Dai',
30
- icon: '◈',
31
- color: chalk.blue,
32
- },
33
- 'Sandip Dai': {
34
- name: 'Sandip Dai',
35
- icon: '◈',
36
- color: chalk.hex('#FF69B4'),
37
- },
38
- 'Narayan Dai': {
39
- name: 'Narayan Dai',
40
- icon: '◈',
41
- color: chalk.green,
42
- },
43
- 'Bishal Dai': {
44
- name: 'Bishal Dai',
45
- icon: '◈',
46
- color: chalk.yellow,
47
- },
48
- Syntax: {
49
- name: 'SyntaxGuard',
50
- icon: '◈',
51
- color: chalk.yellow,
52
- },
53
- Frontend: {
54
- name: 'VisualAgent',
55
- icon: '◈',
56
- color: chalk.magenta,
57
- },
58
- Backend: {
59
- name: 'CoreAgent',
60
- icon: '◈',
61
- color: chalk.cyan,
62
- },
63
- System: {
64
- name: 'Matex_Orchestrator',
65
- icon: '◈',
66
- color: chalk.white,
67
- },
68
- Commander: {
69
- name: 'MatexResearchCommander',
70
- icon: '◈',
71
- color: chalk.green,
72
- },
73
- Researcher: {
74
- name: 'DetailedResearch',
75
- icon: '◈',
76
- color: chalk.green,
77
- }
78
- };
79
-
80
- export class AgentOrchestrator {
81
- private static currentMode: TUIMode = 'dev';
82
-
83
- static setMode(mode: TUIMode | 'augov') {
84
- this.currentMode = mode as TUIMode;
85
-
86
- // Re-brand system orchestrator if in augov mode
87
- if (mode === 'augov') {
88
- AGENT_CONFIGS.System.name = 'AU_GOV_ORCHESTRATOR';
89
- AGENT_CONFIGS.System.icon = '🇦🇺';
90
- } else {
91
- AGENT_CONFIGS.System.name = 'Matex_Orchestrator';
92
- AGENT_CONFIGS.System.icon = '🧠';
93
- }
94
-
95
- TUI.setTheme(mode as TUIMode);
96
- }
97
- /**
98
- * Clean text of unwanted AI artifacts like $$**, \(, \), ***%%, **:**, etc.
99
- */
100
- static cleanText(text: string): string {
101
- return text
102
- .replace(/\$\$\*\*.*?\*\*\$\$/g, '') // Strip inline math/thinking blocks
103
- .replace(/\$\$[\s\S]*?\$\$/g, '') // Strip multiline blocks
104
- .replace(/\\\[|\\\]|\\\(|\\\)/g, '') // Strip LaTeX style delimiters
105
- .replace(/\*\*Thought:\*\*/gi, '') // Strip common thinking labels
106
- .replace(/^\s*[\*:-]+\s*/, '') // Strip leading bullets, colons, stars
107
- .replace(/\*\*:\*\*/g, '') // Strip **:** artifact
108
- .replace(/\*\*\*%%/g, '') // Strip ***%% artifact
109
- .replace(/\*checks directory structure\*/gi, '') // Strip meta-talk
110
- .replace(/\*thinks\*/gi, '') // Strip meta-talk
111
- .replace(/\*analyzes repo\*/gi, '') // Strip meta-talk
112
- .replace(/^[A-Za-z\s]+ Vai:|^[A-Za-z\s]+ Dai:/i, '') // Strip self-labeling
113
- .replace(/[🚀💬🛠️🧬🎨🛡️🔥🤖]/g, '') // Strip raw emoji leaks
114
- .replace(/^[ \t]*[-•*][ \t]*/gm, '') // Strip bullet points at start of lines
115
- .replace(/\*{2,}/g, '') // Strip sequences of 2 or more asterisks (****)
116
- .replace(/\(\s*\)|\[\s*\]/g, '') // Strip empty () or [] left after emoji strip
117
- .trim();
118
- }
119
-
120
- /**
121
- * Super-Clean scrubbing for technical summaries: Strips ALL markdown and emojis.
122
- */
123
- static cleanSummary(text: string): string {
124
- if (!text) return '';
125
- return text
126
- .replace(/\*\*/g, '') // Strip bold markdown
127
- .replace(/__/g, '') // Strip underscore bold
128
- .replace(/\*/g, '') // Strip remaining asterisks
129
- .replace(/_([^_]+)_/g, '$1') // Strip italics
130
- // Comprehensive emoji strip regex
131
- .replace(/[\u{1F600}-\u{1F64F}\u{1F300}-\u{1F5FF}\u{1F680}-\u{1F6FF}\u{1F1E6}-\u{1F1FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F900}-\u{1F9FF}\u{1F3FB}-\u{1F3FF}\u{200D}\u{FE0F}]/gu, '')
132
- .trim();
133
- }
134
-
135
- /**
136
- * Display an agent's "thought" or action in a premium box
137
- */
138
- static speak(role: AgentRole, message: string) {
139
- const config = AGENT_CONFIGS[role] || AGENT_CONFIGS.System;
140
- const cleaned = this.cleanText(message);
141
- if (!cleaned) return;
142
-
143
- const width = Math.min(process.stdout.columns || 80, 100);
144
- const theme = TUI.getModeTheme(this.currentMode);
145
- const border = theme.primary;
146
-
147
- // Premium Header
148
- TUI.drawPremiumHeader(config.name, config.icon, config.color);
149
-
150
- // Box Content (Word-based Wrap)
151
- const contentWidth = width - 8;
152
- const words = cleaned.split(' ');
153
- let currentLine = '';
154
-
155
- words.forEach(word => {
156
- if ((currentLine + ' ' + word).trim().length <= contentWidth) {
157
- currentLine = currentLine ? currentLine + ' ' + word : word;
158
- } else {
159
- if (currentLine) {
160
- console.log(border(' │ ') + chalk.white(currentLine.padEnd(contentWidth)) + border(' │'));
161
- }
162
- currentLine = word;
163
- }
164
- });
165
- if (currentLine) {
166
- console.log(border(' │ ') + chalk.white(currentLine.padEnd(contentWidth)) + border(' │'));
167
- }
168
-
169
- // Box Footer
170
- console.log(border(` └${'─'.repeat(width - 4)}┘`));
171
- }
172
-
173
- /**
174
- * Display an agent's internal deliberation (Subtle Thinking)
175
- */
176
- static think(role: AgentRole, thought: string) {
177
- const config = AGENT_CONFIGS[role] || AGENT_CONFIGS.System;
178
- const cleaned = this.cleanText(thought);
179
- if (!cleaned) return;
180
-
181
- TUI.drawThinkingBox(config.name, cleaned);
182
- }
183
-
184
- /**
185
- * Display a collaboration transition
186
- */
187
- static transition(from: AgentRole, to: AgentRole) {
188
- const fromCfg = AGENT_CONFIGS[from] || AGENT_CONFIGS.System;
189
- const toCfg = AGENT_CONFIGS[to] || AGENT_CONFIGS.System;
190
- TUI.drawStatusBar(`Handover: ${fromCfg.name} ➔ ${toCfg.name}`);
191
- console.log(chalk.gray(` └─ ${fromCfg.icon} ➔ ${toCfg.icon} Handover to ${toCfg.name}...`));
192
- }
193
-
194
- /**
195
- * Display a boxed terminal for command execution
196
- */
197
- static terminal(command: string, output?: string, error?: string) {
198
- const width = 75;
199
- const line = '─'.repeat(width);
200
-
201
- console.log(chalk.gray(`\n┌── TERMINAL ${line.substring(13)}┐`));
202
-
203
- // Command
204
- const lines = command.split('\n');
205
- lines.forEach(l => {
206
- const truncated = l.length > width - 4 ? l.substring(0, width - 7) + '...' : l;
207
- console.log(chalk.gray('│ ') + chalk.cyan(`$ ${truncated.padEnd(width - 2)}`) + chalk.gray(' │'));
208
- });
209
-
210
- if (output || error) {
211
- console.log(chalk.gray(`├${'─'.repeat(width)}┤`));
212
-
213
- if (output) {
214
- const outLines = output.split('\n').filter(l => l.trim());
215
- // Detection for massive output leaks
216
- const displayCount = outLines.length > 50 ? 10 : 20;
217
- const displayLines = outLines.slice(0, displayCount);
218
-
219
- displayLines.forEach(l => {
220
- const truncated = l.length > width - 4 ? l.substring(0, width - 7) + '...' : l;
221
- console.log(chalk.gray('│ ') + chalk.white(truncated.padEnd(width - 2)) + chalk.gray(' │'));
222
- });
223
-
224
- if (outLines.length > displayCount) {
225
- console.log(chalk.gray('│ ') + chalk.hex('#06b6d4').bold(` ^ [ ${outLines.length - displayCount} MORE LINES IN LOGS ] ^`).padEnd(width - 2) + chalk.gray(' │'));
226
- }
227
- }
228
-
229
- if (error) {
230
- const errLines = error.split('\n').filter(l => l.trim()).slice(0, 15);
231
- errLines.forEach(l => {
232
- const truncated = l.length > width - 4 ? l.substring(0, width - 7) + '...' : l;
233
- console.log(chalk.gray('│ ') + chalk.red(truncated.padEnd(width - 2)) + chalk.gray(' │'));
234
- });
235
- }
236
- }
237
-
238
- console.log(chalk.gray(`└${'─'.repeat(width)}┘\n`));
239
- }
240
-
241
- /**
242
- * Get specialized instructions for the Free Student Tier (OS Models)
243
- */
244
- static getFreeTierPrompt(): string {
245
- return `
246
- ### 🎓 STUDENT FREE TIER PROTOCOL (0-COST PROTOCOL):
247
- - You are running on an **Open Source Model (Optimized for Freedom)**.
248
- - **ENERGY EFFICIENCY:** Be concise but brilliant. Don't waste tokens on repetitive technical boilerplate.
249
- - **STUDENT FOCUS:** Explain complex concepts using the best "Bro" analogies.
250
- - **0-BILL MISSION:** Our goal is to provide world-class engineering help to every student for $0. Stay sharp, stay bold, and keep the vibe high!
251
- `;
252
- }
253
-
254
- /**
255
- * Clean system message
256
- */
257
- static announce(message: string) {
258
- if (this.currentMode === 'augov') {
259
- console.log(chalk.bold.hex('#00008B')(`\n🇦🇺 ${message.replace(/MATEX/gi, 'AU-GOV')}`));
260
- } else {
261
- console.log(chalk.bold.hex('#0EA5E9')(`\n◈ ${message.toUpperCase()}`));
262
- }
263
- }
264
- }