Repository navigation
Expand file tree
/
Copy pathlauncher-tui.mjs
More file actions
171 lines (150 loc) · 6.49 KB
/
Copy pathlauncher-tui.mjs
File metadata and controls
171 lines (150 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env node
// ═══════════════════════════════════════════════════════════
// FILE: launcher-tui.mjs
// TUI split‑pane launcher for MAX
// Top pane: Clean chat conversation
// Bottom pane: Tool calls, file reads, shell output
// Input at bottom of screen
// ═══════════════════════════════════════════════════════════
import blessed from 'blessed';
import { createInterface } from 'node:readline';
import chalk from 'chalk';
import figlet from 'figlet';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
// ═══════════════════════════════════════════════════════════
// TUI SETUP
// ═══════════════════════════════════════════════════════════
const screen = blessed.screen({
smartCSR: true,
title: 'MAX TUI',
fullUnicode: true,
});
// Top pane — chat conversation
const chatPane = blessed.box({
parent: screen,
top: 0,
left: 0,
width: '100%',
height: '70%',
label: ' {bold}💬 MAX Chat{/bold} ',
border: { type: 'line' },
style: { border: { fg: 'cyan' } },
scrollable: true,
alwaysScroll: true,
keys: true,
vi: true,
scrollbar: { ch: ' ', track: { bg: 'gray' }, style: { inverse: true } },
});
// Bottom pane — tool activity
const toolPane = blessed.box({
parent: screen,
top: '70%',
left: 0,
width: '100%',
height: '30%',
label: ' {bold}🛠️ Tool Activity{/bold} ',
border: { type: 'line' },
style: { border: { fg: 'yellow' } },
scrollable: true,
alwaysScroll: true,
keys: true,
vi: true,
scrollbar: { ch: ' ', track: { bg: 'gray' }, style: { inverse: true } },
});
// Input bar
const input = blessed.textbox({
parent: screen,
bottom: 0,
left: 0,
width: '100%',
height: 3,
inputOnFocus: true,
border: { type: 'line' },
style: { border: { fg: 'green' }, fg: 'white', bg: 'black' },
keys: true,
vi: true,
});
// ═══════════════════════════════════════════════════════════
// PANE HELPERS
// ═══════════════════════════════════════════════════════════
function addChatMessage(sender, message, color = 'white') {
const time = new Date().toLocaleTimeString();
const line = `{${color}-fg}{bold}${sender}:{/bold} ${message}{/}`;
chatPane.pushLine(`[${time}] ${line}`);
chatPane.setScrollPerc(100);
screen.render();
}
function addToolOutput(output) {
const time = new Date().toLocaleTimeString();
toolPane.pushLine(`[${time}] ${output}`);
toolPane.setScrollPerc(100);
screen.render();
}
// ═══════════════════════════════════════════════════════════
// BOOT ANIMATION
// ═══════════════════════════════════════════════════════════
async function bootAnimation() {
screen.clearRegion(0, screen.height, 0, screen.width);
const banner = await new Promise((resolve) => {
figlet('MAX', { font: 'Standard', horizontalLayout: 'full' }, (err, data) => {
if (err) resolve('MAX');
resolve(data);
});
});
addChatMessage('SYSTEM', banner, 'magenta');
addChatMessage('SYSTEM', `v${packageJson.version} — Autonomous Engineering Agent`, 'gray');
addChatMessage('SYSTEM', '──────────────────────────────────────', 'gray');
screen.render();
}
// ═══════════════════════════════════════════════════════════
// CHAT LOOP (simplified — same as launcher.mjs but with pane output)
// ═══════════════════════════════════════════════════════════
let conversation = [];
async function handleInput(inputText) {
inputText = inputText.trim();
if (!inputText) return;
addChatMessage('YOU', inputText, 'green');
conversation.push({ role: 'user', content: inputText });
// Simulate MAX processing (this would be replaced with actual MAX API call)
addToolOutput('Processing...');
await new Promise(resolve => setTimeout(resolve, 300));
// For demo: echo with tool simulation
const response = `I heard: "${inputText}". I'll process that now.`;
addChatMessage('MAX', response, 'cyan');
conversation.push({ role: 'assistant', content: response });
// Simulate tool calls
if (inputText.includes('file')) {
addToolOutput('TOOL: file:read → reading launcher.mjs');
}
if (inputText.includes('shell')) {
addToolOutput('TOOL: shell:run → npm test');
}
if (inputText.includes('help')) {
addToolOutput('TOOL: goals:add → queue investigation');
}
}
// ═══════════════════════════════════════════════════════════
// START
// ═══════════════════════════════════════════════════════════
async function start() {
await bootAnimation();
input.focus();
input.on('submit', async (value) => {
input.clearValue();
screen.render();
await handleInput(value);
});
screen.key(['C-c'], () => {
screen.destroy();
process.exit(0);
});
screen.render();
}
start().catch(err => {
console.error('TUI failed:', err);
process.exit(1);
});