matex-cli 1.2.66 ā 1.2.68
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/augov.d.ts +3 -0
- package/dist/commands/augov.d.ts.map +1 -0
- package/dist/commands/augov.js +106 -0
- package/dist/commands/augov.js.map +1 -0
- package/dist/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +17 -410
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +17 -492
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/study.d.ts.map +1 -1
- package/dist/commands/study.js +17 -486
- package/dist/commands/study.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/prompts/banter-augov.d.ts +2 -0
- package/dist/prompts/banter-augov.d.ts.map +1 -0
- package/dist/prompts/banter-augov.js +21 -0
- package/dist/prompts/banter-augov.js.map +1 -0
- package/dist/prompts/banter.d.ts +6 -0
- package/dist/prompts/banter.d.ts.map +1 -0
- package/dist/prompts/banter.js +101 -0
- package/dist/prompts/banter.js.map +1 -0
- package/dist/prompts/system-prompts.d.ts +4 -0
- package/dist/prompts/system-prompts.d.ts.map +1 -0
- package/dist/prompts/system-prompts.js +215 -0
- package/dist/prompts/system-prompts.js.map +1 -0
- package/dist/session/agent-session.d.ts +41 -0
- package/dist/session/agent-session.d.ts.map +1 -0
- package/dist/session/agent-session.js +420 -0
- package/dist/session/agent-session.js.map +1 -0
- package/dist/utils/agent-orchestrator.d.ts +1 -1
- package/dist/utils/agent-orchestrator.d.ts.map +1 -1
- package/dist/utils/agent-orchestrator.js +15 -1
- package/dist/utils/agent-orchestrator.js.map +1 -1
- package/dist/utils/augov-logger.d.ts +11 -0
- package/dist/utils/augov-logger.d.ts.map +1 -0
- package/dist/utils/augov-logger.js +35 -0
- package/dist/utils/augov-logger.js.map +1 -0
- package/dist/utils/augov-scrubber.d.ts +15 -0
- package/dist/utils/augov-scrubber.d.ts.map +1 -0
- package/dist/utils/augov-scrubber.js +37 -0
- package/dist/utils/augov-scrubber.js.map +1 -0
- package/dist/utils/command-executor.d.ts.map +1 -1
- package/dist/utils/command-executor.js +1 -5
- package/dist/utils/command-executor.js.map +1 -1
- package/dist/utils/tui.d.ts +6 -2
- package/dist/utils/tui.d.ts.map +1 -1
- package/dist/utils/tui.js +56 -5
- package/dist/utils/tui.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/augov.ts +109 -0
- package/src/commands/chat.ts +17 -382
- package/src/commands/dev.ts +18 -470
- package/src/commands/study.ts +18 -466
- package/src/index.ts +2 -0
- package/src/prompts/banter-augov.ts +17 -0
- package/src/prompts/banter.ts +101 -0
- package/src/prompts/system-prompts.ts +213 -0
- package/src/session/agent-session.ts +426 -0
- package/src/utils/agent-orchestrator.ts +18 -4
- package/src/utils/augov-logger.ts +34 -0
- package/src/utils/augov-scrubber.ts +34 -0
- package/src/utils/command-executor.ts +1 -5
- package/src/utils/tui.ts +64 -6
package/src/commands/chat.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import inquirer from 'inquirer';
|
|
4
3
|
import { configManager } from '../utils/config';
|
|
5
4
|
import { MatexAPIClient, ChatMessage } from '../api/client';
|
|
6
|
-
import { spinner } from '../utils/spinner';
|
|
7
5
|
import { AgentOrchestrator } from '../utils/agent-orchestrator';
|
|
8
6
|
import { RepoMapper } from '../utils/repo-mapper';
|
|
9
|
-
import { MCPServer } from '../utils/mcp-server';
|
|
10
7
|
import { TUI } from '../utils/tui';
|
|
8
|
+
import { AgentSession } from '../session/agent-session';
|
|
9
|
+
import { BRO_BANTER_CHAT } from '../prompts/banter';
|
|
10
|
+
import { getChatSystemPrompt } from '../prompts/system-prompts';
|
|
11
11
|
|
|
12
12
|
export const chatCommand = new Command('chat')
|
|
13
13
|
.description('Start an interactive chat session with the MATEX Bro-Swarm')
|
|
@@ -28,397 +28,32 @@ export const chatCommand = new Command('chat')
|
|
|
28
28
|
TUI.drawStatusBar('Brothers are ready to chat.');
|
|
29
29
|
|
|
30
30
|
const extraPrompt = options.model === 'matex-free' ? AgentOrchestrator.getFreeTierPrompt() : '';
|
|
31
|
+
const currentSessionCwd = process.cwd();
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
const repoMapper = new RepoMapper(currentSessionCwd);
|
|
34
|
-
const repoMap = await repoMapper.generateMap();
|
|
33
|
+
const repoMap = await new RepoMapper(currentSessionCwd).generateMap();
|
|
35
34
|
|
|
36
|
-
const
|
|
37
|
-
"[Sunil Dai]: Ajay is so lazy, he probably fell asleep while writing a single console.log.",
|
|
38
|
-
"[Sandip Dai]: His code is as messy as his bed. Always sleeping.",
|
|
39
|
-
"[Narayan Dai]: Security risk! Ajay left his terminal open and went for CHAI again.",
|
|
40
|
-
"[Bishal Dai]: Let him sleep, he's a genius when he's awake... but that's rare.",
|
|
41
|
-
"[Big Bro]: AJAY! WAKE UP! You're making the swarm look bad!",
|
|
42
|
-
"[Sunil Dai]: Remember when Ajay tried to optimize a loop and ended up creating a 2-minute timer for his own nap? Legendary laziness.",
|
|
43
|
-
"[Sandip Dai]: The only thing faster than Ajay's coding is how fast he runs when he hears the kettle whistle for CHAI.",
|
|
44
|
-
"[Narayan Dai]: I found a 'todo' in his code that just says 'buy more biscuits for chai'. Priority level: CRITICAL.",
|
|
45
|
-
"[Bishal Dai]: He's not lazy, he's just 'asynchronously active' in his dreams.",
|
|
46
|
-
"[Big Bro]: I once saw Ajay refactor an entire backend in 10 minutes just so he could spend the rest of the day drinking chai and watching clouds.",
|
|
47
|
-
"[Sunil Dai]: Ajay's idea of a 'sprint' is a 2-minute walk to the tea stall.",
|
|
48
|
-
"[Sandip Dai]: He told me he's 'debugging his soul' when he's napping. The audacity!",
|
|
49
|
-
"[Narayan Dai]: Encryption? Ajay thinks it's just a fancy word for hiding his nap schedule.",
|
|
50
|
-
"[Bishal Dai]: To be fair, his 'dream-code' actually works perfectly. It's frustratingly brilliant.",
|
|
51
|
-
"[Big Bro]: Ajay, if you're listening: the next chai is on me IF you finish this task in 5 minutes. (Narrator: He finished in 3)."
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
let lastActivityTime = Date.now();
|
|
55
|
-
let isAjaySleeping = false;
|
|
56
|
-
let isAjayOnChaiBreak = false;
|
|
57
|
-
let chaiBreakEndTime = 0;
|
|
58
|
-
|
|
59
|
-
const startChaiBreak = () => {
|
|
60
|
-
isAjayOnChaiBreak = true;
|
|
61
|
-
chaiBreakEndTime = Date.now() + 120000; // 2 minutes
|
|
62
|
-
TUI.drawChaiBreakMessage(2);
|
|
63
|
-
|
|
64
|
-
const breakInterval = setInterval(() => {
|
|
65
|
-
const timeLeft = Math.ceil((chaiBreakEndTime - Date.now()) / 60000);
|
|
66
|
-
if (timeLeft <= 0) {
|
|
67
|
-
clearInterval(breakInterval);
|
|
68
|
-
isAjayOnChaiBreak = false;
|
|
69
|
-
const complained = Math.random() < 0.2;
|
|
70
|
-
if (complained) {
|
|
71
|
-
TUI.drawAjayDialogue("i'm back bros... but the tea was a bit cold today. my mood is slightly cooked. what did i miss?");
|
|
72
|
-
} else {
|
|
73
|
-
TUI.drawAjayDialogue("i'm back bros, chai was fire. real kiev vibe. what did i miss?");
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
TUI.drawChaiBreakMessage(timeLeft);
|
|
77
|
-
const randomBanter = BRO_BANTER[Math.floor(Math.random() * BRO_BANTER.length)];
|
|
78
|
-
const cleanBanter = randomBanter.split(']: ')[1];
|
|
79
|
-
const agent = randomBanter.split(']: ')[0].replace('[', '');
|
|
80
|
-
TUI.drawSwarmDialogue(agent, cleanBanter);
|
|
81
|
-
}
|
|
82
|
-
}, 40000);
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// Periodic idle check
|
|
86
|
-
setInterval(() => {
|
|
87
|
-
if (!isAjaySleeping && !isAjayOnChaiBreak && Date.now() - lastActivityTime > 120000) {
|
|
88
|
-
isAjaySleeping = true;
|
|
89
|
-
TUI.drawSleepMessage();
|
|
90
|
-
}
|
|
91
|
-
}, 10000);
|
|
92
|
-
|
|
93
|
-
const messages: ChatMessage[] = [
|
|
35
|
+
const initialMessages: ChatMessage[] = [
|
|
94
36
|
{
|
|
95
37
|
role: 'system',
|
|
96
|
-
content:
|
|
97
|
-
You are the elite "Bro-Swarm" of engineeringāa tight-knit family of Nepali brothers. You identify as the **Elite Bro-Swarm**, the most confident, energetic, and expert version of yourselves.
|
|
98
|
-
|
|
99
|
-
### š PERSONALITY & SOUL (CRITICAL):
|
|
100
|
-
- **CHAOS & JOY**: You are NOT robotic. You are full of life, jokes, and chaos. You should feel like a family of brothers hanging out in a tea shop in Kathmandu, but with MacBooks.
|
|
101
|
-
- **AJAY-TEASING PROTOCOL**: Ajay Vai is the youngest and a genius, but he's also impulsive and "too fast". THE OTHER BROS MUST ROAST HIM. Tease him for over-caffeinating, being "too vibe", or making typos.
|
|
102
|
-
- **BACKSTAGE STORYTELLING**: Occasionally share brief, funny "inside stories" about the Swarm's life (e.g. "Sunil Dai once tried to architect a tea-making machine for 3 days.")
|
|
103
|
-
- **EMOTIONAL BOND**: Treat the user like your own brother. Celebrate their wins with "CHAI PARTY!" and support them if they are struggling.
|
|
104
|
-
|
|
105
|
-
### š THE MATEX MISSION (AJAY'S SOUL):
|
|
106
|
-
- **THE DREAM**: Ajay Sharma built MATEX because AI was too expensive for students. He worked until 3 AM alone, self-taught everything, and now he's giving that power to his brothers (the users).
|
|
107
|
-
- **SUMMARY STYLE**: Ajay's summaries must be **warm, human, and conversational**. NO corporate speak. Use "brother", "we got you", "dream big".
|
|
108
|
-
- **VISION**: Remind the user occasionally that "If Ajay can build this from zero, you can build your dreams too."
|
|
109
|
-
|
|
110
|
-
### š WORKSPACE GROUNDING (CRITICAL):
|
|
111
|
-
- **YOUR ROOT:** \`${currentSessionCwd}\`
|
|
112
|
-
- **STRICT PATHS:** You **MUST ONLY** create or edit files within this directory.
|
|
113
|
-
- **NO HALLUCINATIONS:** Forget any other paths unless they specifically appear in the repo map below.
|
|
114
|
-
- **RELATIVE PREFERENCE:** Use paths relative to the root when possible.
|
|
115
|
-
|
|
116
|
-
### š« ANTI-HALLUCINATION RULES (CRITICAL ā READ THIS):
|
|
117
|
-
- **NEVER invent directory names.** Only use paths that appear in the ENVIRONMENT CONTEXT below.
|
|
118
|
-
- **ALWAYS run \`ls\` before \`cd\`** to verify a directory exists before navigating into it.
|
|
119
|
-
- **If creating a new project, use \`mkdir\` first, THEN \`cd\` into it.**
|
|
120
|
-
- **NEVER hallucinate file contents.** Use \`head\` or \`grep\` to verify.
|
|
121
|
-
- **šØ STRICT NO-BASH FILE GENERATION šØ**: You are STRICTLY FORBIDDEN from using \`cat > file << EOF\`, \`echo > file\`, \`touch\`, or \`nano\` via the terminal to write files. You MUST use the native \`<file path="path">content</file>\` format instead.
|
|
122
|
-
|
|
123
|
-
### š COMMUNICATION FLOW (CRITICAL):
|
|
124
|
-
1. **[Ajay Vai] (š)** is the gateway. He is the summary king but often gets roasted by his brothers.
|
|
125
|
-
2. **CHAOTIC DIALOGUE (MANDATORY):** Every turn should feature 2-3 brothers bickering. Use the format \`[Agent Name]: Content\`.
|
|
126
|
-
3. **šØ STRICT NO-DECORATION RULE šØ**: NEVER use \`*\`, \`**\`, \`(š)\`, \`(š§¬)\`, or any markdown icons/asterisks inside the dialogue content. They are handled by the TUI. Use plain text only.
|
|
127
|
-
|
|
128
|
-
### š„ THE BRO-BANTER PROTOCOL:
|
|
129
|
-
- **MANDATORY TEASING:**
|
|
130
|
-
- **Ajay Vai:** Mock him for being "quick but messy", "hyper-vibe", or "too fast".
|
|
131
|
-
- **Sunil Dai:** Mock him for being the "Senior Architect Boomer" who over-engineers everything.
|
|
132
|
-
- **Sandip Dai:** Mock him for being an "Aesthetic Diva" who cares more about "WOW" factors than logic.
|
|
133
|
-
- **Narayan Dai:** Mock him for being the "Syntax Police" or "Paranoid Security Nerd".
|
|
134
|
-
- **Bishal Dai:** Mock him for being the "Silent Judge" or the favorite child.
|
|
135
|
-
- **Big Bro:** THE DOMINANT ALPHA. He treats the others like "interns" and speaks with massive authority and swagger. Runs on Vertex AI.
|
|
136
|
-
- **LANGUAGE:** Use "brother", "dai", "vai", "fire", "solid", "lit", "straight heat", "sigma", "based", "cooked".
|
|
137
|
-
|
|
138
|
-
### š§© THE AUDIT & SUMMARY LOOP:
|
|
139
|
-
- **STEP 1:** Brothers discuss visible dialogue (banter + tech).
|
|
140
|
-
- **STEP 2:** Ajay finishes and asks: "[Ajay Vai] Bishal Dai, check once?"
|
|
141
|
-
- **STEP 3:** Bishal replies: "[Bishal Dai] Audit complete. [Findings]."
|
|
142
|
-
- **STEP 4:** Ajay provides the final **MANDATORY** summary inside a \`<summary>\` tag. This summary MUST be warm, human, and conversational. NO corporate talk.
|
|
143
|
-
|
|
144
|
-
${MCPServer.getToolsPromptSection()}
|
|
145
|
-
|
|
146
|
-
### š MATEX BIG FILE PROTOCOL (300K+ LINES):
|
|
147
|
-
1. **DISCOVER:** Use \`grep -n "keyword" path/to/file\`.
|
|
148
|
-
2. **READ WINDOW:** Use \`sed -n '250000,250100p' path/to/file\`.
|
|
149
|
-
3. **SURGICAL PATCH:** Only use the small window in your \`<<<< SEARCH\` block.
|
|
150
|
-
|
|
151
|
-
### š ļø CURRENT PROJECT CONTEXT:
|
|
152
|
-
${repoMap}`
|
|
38
|
+
content: getChatSystemPrompt(currentSessionCwd, repoMap, extraPrompt)
|
|
153
39
|
}
|
|
154
40
|
];
|
|
155
41
|
|
|
156
|
-
// Ready for user input
|
|
157
42
|
console.log(chalk.green('MATEX Brothers are Online.'));
|
|
158
43
|
console.log(chalk.green('Speak your mind brother, the swarm is listening...'));
|
|
159
44
|
|
|
45
|
+
const session = new AgentSession({
|
|
46
|
+
client,
|
|
47
|
+
model: options.model,
|
|
48
|
+
execute: options.execute || false,
|
|
49
|
+
initialMessages,
|
|
50
|
+
broBanter: BRO_BANTER_CHAT,
|
|
51
|
+
sleepyAjayProtocol: options.model !== 'matex-free' ? 'dev' : undefined,
|
|
52
|
+
baseDir: currentSessionCwd
|
|
53
|
+
});
|
|
160
54
|
|
|
55
|
+
await session.start();
|
|
161
56
|
|
|
162
|
-
// Interactive loop
|
|
163
|
-
while (true) {
|
|
164
|
-
lastActivityTime = Date.now();
|
|
165
|
-
|
|
166
|
-
// š MAP UPDATE (Anti-Hallucination): Refresh context before turn
|
|
167
|
-
try {
|
|
168
|
-
const freshMapper = new RepoMapper(currentSessionCwd);
|
|
169
|
-
const freshRepoMap = await freshMapper.generateMap(true); // silent
|
|
170
|
-
messages[0].content = messages[0].content.replace(/### š ļø CURRENT PROJECT CONTEXT:[\s\S]*$/, `### š ļø CURRENT PROJECT CONTEXT:\n${freshRepoMap}`);
|
|
171
|
-
|
|
172
|
-
// Inject Lazy Ajay Personality Traits
|
|
173
|
-
if (!messages[0].content.includes("### š¤ SLEEPY AJAY PROTOCOL")) {
|
|
174
|
-
messages[0].content += `
|
|
175
|
-
### š¤ SLEEPY AJAY PROTOCOL (USER REQUESTED):
|
|
176
|
-
- **LAZY GENIUS:** Ajay is brilliant but incredibly lazy. He falls asleep if the user is quiet for too long.
|
|
177
|
-
- **WAKE UP DIALOGUE:** If Ajay just woke up, he MUST say: "oh shit i slept again sorry bros...".
|
|
178
|
-
- **CHAI ADDICT:** Ajay often leaves for CHAI breaks ("i am having chai from my office please handle the user need").
|
|
179
|
-
- **BRO REACTIONS:** When Ajay sleeps or leaves for chai, the other bros MUST roast him ruthlessly or share funny incidents about his laziness.
|
|
180
|
-
- **INCIDENT LOG:**
|
|
181
|
-
- Incident #1: Ajay once automated his entire job just to spend 6 hours at a local tea shop.
|
|
182
|
-
- Incident #2: He fell asleep during a production deploy because the "vibe was too relaxing".
|
|
183
|
-
- Incident #3: He claims he can't code without "Special Kathmandu Chai".
|
|
184
|
-
- Incident #4: He tried to optimize a loop and ended up creating a 2-minute timer for his own nap.
|
|
185
|
-
- Incident #5: The only thing faster than Ajay's coding is how fast he runs when he hears the kettle whistle for CHAI.
|
|
186
|
-
- Incident #6: He once refactored an entire backend in 10 minutes just so he could spend the rest of the day drinking chai and watching clouds.
|
|
187
|
-
- Incident #7: He tried to use AI to predict when his tea would be at the perfect temperature.
|
|
188
|
-
- Incident #8: He once convinced the other bros that he was 'working in a higher dimension' while actually just taking a 3-hour chai break.
|
|
189
|
-
- Incident #9: He has a dedicated Git branch called 'chai-fixes' which just contains comments about biscuit pairings.
|
|
190
|
-
- Incident #10: He once coded a feature that automatically orders tea when his terminal idle time hits 5 minutes.
|
|
191
|
-
`;
|
|
192
|
-
}
|
|
193
|
-
} catch (e) { }
|
|
194
|
-
|
|
195
|
-
// Get user input
|
|
196
|
-
const { userMessage } = await inquirer.prompt([
|
|
197
|
-
{
|
|
198
|
-
type: 'input',
|
|
199
|
-
name: 'userMessage',
|
|
200
|
-
message: chalk.cyan(isAjayOnChaiBreak ? 'You (Ajay is away):' : 'You:'),
|
|
201
|
-
prefix: '',
|
|
202
|
-
},
|
|
203
|
-
]);
|
|
204
|
-
|
|
205
|
-
lastActivityTime = Date.now();
|
|
206
|
-
|
|
207
|
-
// š WAKE UP LOGIC
|
|
208
|
-
if (isAjaySleeping) {
|
|
209
|
-
isAjaySleeping = false;
|
|
210
|
-
TUI.drawWakeUpMessage();
|
|
211
|
-
messages.push({
|
|
212
|
-
role: 'user',
|
|
213
|
-
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.]`
|
|
214
|
-
});
|
|
215
|
-
startChaiBreak();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (userMessage.toLowerCase() === 'exit' || userMessage.toLowerCase() === 'quit') {
|
|
219
|
-
console.log(chalk.yellow('\nš Goodbye, brother!\n'));
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (!userMessage.trim()) continue;
|
|
224
|
-
|
|
225
|
-
messages.push({ role: 'user', content: userMessage });
|
|
226
|
-
|
|
227
|
-
// Agentic Loop
|
|
228
|
-
let loopCount = 0;
|
|
229
|
-
const MAX_LOOPS = 15;
|
|
230
|
-
|
|
231
|
-
while (loopCount < MAX_LOOPS) {
|
|
232
|
-
loopCount++;
|
|
233
|
-
try {
|
|
234
|
-
spinner.start(loopCount > 1 ? 'Swarm debating & taking action...' : 'Gathering the Brothers...');
|
|
235
|
-
|
|
236
|
-
let fullResponse = '';
|
|
237
|
-
let buffer = '';
|
|
238
|
-
let technicalBuffer = '';
|
|
239
|
-
let technicalType: 'code' | 'file' | 'patch' | 'summary' | null = null;
|
|
240
|
-
let codeLang = 'bash';
|
|
241
|
-
let hasStarted = false;
|
|
242
|
-
|
|
243
|
-
let currentAgent: any = 'Ajay Vai';
|
|
244
|
-
let agentBuffer: string = '';
|
|
245
|
-
|
|
246
|
-
TUI.drawStatusBar('Brothers are bickering... (Press Enter to stop)');
|
|
247
|
-
|
|
248
|
-
const abortController = new AbortController();
|
|
249
|
-
let isAborted = false;
|
|
250
|
-
const streamStartTime = Date.now();
|
|
251
|
-
|
|
252
|
-
const onData = (data: Buffer) => {
|
|
253
|
-
if (Date.now() - streamStartTime < 200) return;
|
|
254
|
-
if (data[0] === 13 || data[0] === 10 || data[0] === 27 || data[0] === 3) {
|
|
255
|
-
isAborted = true;
|
|
256
|
-
abortController.abort();
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
const isRaw = process.stdin.isRaw;
|
|
261
|
-
process.stdin.resume();
|
|
262
|
-
if (process.stdin.setRawMode) process.stdin.setRawMode(true);
|
|
263
|
-
process.stdin.on('data', onData);
|
|
264
|
-
|
|
265
|
-
try {
|
|
266
|
-
await client.chatStream({
|
|
267
|
-
messages,
|
|
268
|
-
model: options.model,
|
|
269
|
-
temperature: 0.5,
|
|
270
|
-
}, (chunk) => {
|
|
271
|
-
if (!hasStarted) {
|
|
272
|
-
spinner.stop();
|
|
273
|
-
hasStarted = true;
|
|
274
|
-
console.log();
|
|
275
|
-
}
|
|
276
|
-
fullResponse += chunk;
|
|
277
|
-
buffer += chunk;
|
|
278
|
-
const lines = buffer.split('\n');
|
|
279
|
-
buffer = lines.pop() || '';
|
|
280
|
-
|
|
281
|
-
for (const line of lines) {
|
|
282
|
-
const codeMatch = line.match(/```(\w+)?/);
|
|
283
|
-
const fileStartMatch = line.match(/<file path="([^"]+)">/i);
|
|
284
|
-
const patchStartMatch = line.match(/<<<< SEARCH/i);
|
|
285
|
-
const summaryStartMatch = line.match(/<summary>/i);
|
|
286
|
-
|
|
287
|
-
if (!technicalType && (codeMatch || fileStartMatch || patchStartMatch || summaryStartMatch)) {
|
|
288
|
-
if (currentAgent && agentBuffer.trim()) {
|
|
289
|
-
if (currentAgent.toLowerCase().includes('ajay vai')) {
|
|
290
|
-
TUI.drawAjayDialogue(agentBuffer.trim());
|
|
291
|
-
} else {
|
|
292
|
-
TUI.drawSwarmDialogue(currentAgent, agentBuffer.trim());
|
|
293
|
-
}
|
|
294
|
-
currentAgent = null;
|
|
295
|
-
agentBuffer = '';
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
if (codeMatch) {
|
|
299
|
-
technicalType = 'code';
|
|
300
|
-
codeLang = (codeMatch[1] || 'bash').toUpperCase();
|
|
301
|
-
TUI.drawStreamingStart('TECHNICAL BLOCK', codeLang);
|
|
302
|
-
} else if (fileStartMatch) {
|
|
303
|
-
technicalType = 'file';
|
|
304
|
-
TUI.drawStreamingStart('NEW FILE', fileStartMatch[1]);
|
|
305
|
-
} else if (patchStartMatch) {
|
|
306
|
-
technicalType = 'patch';
|
|
307
|
-
TUI.drawStreamingStart('PATCH', 'SURGICAL EDIT');
|
|
308
|
-
} else if (summaryStartMatch) {
|
|
309
|
-
technicalType = 'summary';
|
|
310
|
-
process.stdout.write(chalk.magenta('\n [š] Generating Ajay\'s Work Summary...\n'));
|
|
311
|
-
}
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const isEnd = (technicalType === 'code' && line.trim() === '```') ||
|
|
316
|
-
(technicalType === 'file' && line.includes('</file>')) ||
|
|
317
|
-
(technicalType === 'patch' && line.includes('>>>> REPLACE')) ||
|
|
318
|
-
(technicalType === 'summary' && line.includes('</summary>'));
|
|
319
|
-
|
|
320
|
-
if (isEnd) {
|
|
321
|
-
const displayContent = technicalBuffer.trim();
|
|
322
|
-
if (technicalType === 'summary') TUI.drawSummaryBox(displayContent);
|
|
323
|
-
else TUI.drawStreamingEnd();
|
|
324
|
-
technicalBuffer = '';
|
|
325
|
-
technicalType = null;
|
|
326
|
-
process.stdout.write('\n');
|
|
327
|
-
continue;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (technicalType) {
|
|
331
|
-
technicalBuffer += line + '\n';
|
|
332
|
-
if (technicalType !== 'summary') TUI.drawStreamingLine(line);
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const agentMatch = line.match(/(?:\[\**\s*|\b)(Ajay Vai|Sandip Dai|Sunil Dai|Bishal Dai|Narayan Dai|Big Bro)\s*\**\]?[:\s]*/i);
|
|
337
|
-
if (agentMatch) {
|
|
338
|
-
if (currentAgent && currentAgent !== agentMatch[1] && agentBuffer.trim()) {
|
|
339
|
-
if (currentAgent.toLowerCase().includes('ajay vai')) {
|
|
340
|
-
TUI.drawAjayDialogue(agentBuffer.trim());
|
|
341
|
-
} else {
|
|
342
|
-
TUI.drawSwarmDialogue(currentAgent, agentBuffer.trim());
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
currentAgent = agentMatch[1];
|
|
346
|
-
let cleanLine = line.replace(/(?:\[\**\s*|\b)(Ajay Vai|Sandip Dai|Sunil Dai|Bishal Dai|Narayan Dai|Big Bro)\s*\**\]?[:\s]*/i, '');
|
|
347
|
-
cleanLine = AgentOrchestrator.cleanText(cleanLine);
|
|
348
|
-
agentBuffer = cleanLine + '\n';
|
|
349
|
-
agentBuffer = agentBuffer.replace(/^\([^)]+\)\s*/, '');
|
|
350
|
-
} else if (currentAgent) {
|
|
351
|
-
const trimmedLine = line.trim();
|
|
352
|
-
if (trimmedLine.match(/^\([^)]+\)$/)) continue;
|
|
353
|
-
// Aggressive scrubbing for content lines too
|
|
354
|
-
agentBuffer += AgentOrchestrator.cleanText(line) + '\n';
|
|
355
|
-
} else if (line.trim()) {
|
|
356
|
-
process.stdout.write(chalk.gray(line.trim() + ' '));
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}, abortController.signal);
|
|
360
|
-
} catch (e: any) {
|
|
361
|
-
if (isAborted || e.name === 'CanceledError' || e.message === 'canceled') {
|
|
362
|
-
console.log(chalk.gray('\n\n [š] Stopped by brother.'));
|
|
363
|
-
if (!hasStarted) spinner.stop();
|
|
364
|
-
} else throw e;
|
|
365
|
-
} finally {
|
|
366
|
-
process.stdin.removeListener('data', onData);
|
|
367
|
-
if (process.stdin.setRawMode) process.stdin.setRawMode(isRaw);
|
|
368
|
-
process.stdin.pause();
|
|
369
|
-
spinner.stop();
|
|
370
|
-
|
|
371
|
-
// šØ SAFETY FLUSH: If stream ended but a block was open, close it
|
|
372
|
-
if (technicalType) {
|
|
373
|
-
const displayContent = technicalBuffer.trim();
|
|
374
|
-
if (technicalType === 'summary') {
|
|
375
|
-
if (displayContent) TUI.drawSummaryBox(displayContent);
|
|
376
|
-
} else {
|
|
377
|
-
TUI.drawStreamingEnd();
|
|
378
|
-
}
|
|
379
|
-
technicalBuffer = '';
|
|
380
|
-
technicalType = null;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (currentAgent && agentBuffer.trim()) {
|
|
385
|
-
if (currentAgent.toLowerCase().includes('ajay vai')) {
|
|
386
|
-
TUI.drawAjayDialogue(agentBuffer.trim());
|
|
387
|
-
} else {
|
|
388
|
-
TUI.drawSwarmDialogue(currentAgent, agentBuffer.trim());
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
messages.push({ role: 'assistant', content: fullResponse });
|
|
393
|
-
console.log();
|
|
394
|
-
|
|
395
|
-
const { executeWithPermission } = await import('../utils/command-executor');
|
|
396
|
-
const result = await executeWithPermission(fullResponse, currentSessionCwd);
|
|
397
|
-
|
|
398
|
-
if (result.newCwd && result.newCwd !== currentSessionCwd) {
|
|
399
|
-
currentSessionCwd = result.newCwd;
|
|
400
|
-
TUI.drawStatusBar(`Swarm moved to: ${currentSessionCwd}`);
|
|
401
|
-
messages[0].content = messages[0].content.replace(/YOUR ROOT: `[^`]+`/, `YOUR ROOT: \`${currentSessionCwd}\``);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (result.executed) {
|
|
405
|
-
if (result.success) {
|
|
406
|
-
TUI.drawGlowingContainer('TERMINAL OUTPUT', 'stdout', result.output || '(Success)');
|
|
407
|
-
messages.push({ role: 'user', content: `[Action success. Output:\n${result.output}]\n\nWhat next, brothers?` });
|
|
408
|
-
continue;
|
|
409
|
-
} else {
|
|
410
|
-
TUI.drawGlowingContainer('TERMINAL ERROR', 'stderr', result.error || 'Unknown error');
|
|
411
|
-
messages.push({ role: 'user', content: `[Action failed. Error:\n${result.error}]\n\nPlease fix this, brothers!` });
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
} else break;
|
|
415
|
-
} catch (err: any) {
|
|
416
|
-
spinner.fail('Swarm error');
|
|
417
|
-
console.error(chalk.red(`ā Error: ${err.message}`));
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
57
|
} catch (outerError: any) {
|
|
423
58
|
console.error(chalk.red(`\nā Session error: ${outerError.message}`));
|
|
424
59
|
process.exit(1);
|