@tensorspark/dravix-code 1.5.0 → 1.5.1
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/cli/commands.js +35 -28
- package/dist/cli/index.js +60 -171
- package/dist/cli/repl.js +979 -1087
- package/dist/utils/display.js +637 -177
- package/dist/utils/layout.js +210 -56
- package/package.json +1 -1
package/dist/cli/commands.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { execFileSync } from 'child_process';
|
|
2
|
+
import chalk from 'chalk';
|
|
2
3
|
import { buildContext } from '../services/context.js';
|
|
3
|
-
import {
|
|
4
|
+
import { printHelp, printInfo, renderCompactHeader, colors, clipVis, } from '../utils/display.js';
|
|
4
5
|
import { logout, getSavedUser, checkPlan } from '../services/auth.js';
|
|
5
6
|
import { undoLastSession, listUndoSessions } from '../services/undo.js';
|
|
6
|
-
export async function handleCommand(cmd, cwd, clearHistory, addFileToContext, getLastAI, retryLast) {
|
|
7
|
+
export async function handleCommand(cmd, cwd, clearHistory, addFileToContext, getLastAI, retryLast, ui) {
|
|
7
8
|
const parts = cmd.trim().split(/\s+/);
|
|
8
9
|
const name = parts[0].toLowerCase();
|
|
9
10
|
if (name === '/exit' || name === '/quit') {
|
|
10
|
-
|
|
11
|
+
ui?.layout?.cleanup(true, true);
|
|
12
|
+
console.log(colors.muted(' Goodbye!\n'));
|
|
11
13
|
process.exit(0);
|
|
12
14
|
}
|
|
13
15
|
if (name === '/logout') {
|
|
14
16
|
logout();
|
|
15
|
-
|
|
17
|
+
ui?.layout?.cleanup(true, true);
|
|
18
|
+
console.log(colors.muted(' Signed out. Run dravix again to authenticate.\n'));
|
|
16
19
|
process.exit(0);
|
|
17
20
|
}
|
|
18
21
|
if (name === '/whoami') {
|
|
@@ -23,12 +26,11 @@ export async function handleCommand(cmd, cwd, clearHistory, addFileToContext, ge
|
|
|
23
26
|
}
|
|
24
27
|
const plan = email ? await checkPlan(email) : 'Free';
|
|
25
28
|
const planBadge = plan === 'Plus'
|
|
26
|
-
?
|
|
27
|
-
:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
colors.
|
|
31
|
-
'\n ' + colors.muted(' Plan ') + planBadge + '\n\n');
|
|
29
|
+
? chalk.bgHex('#312e81').hex('#c7d2fe').bold(' PLUS ')
|
|
30
|
+
: chalk.bgHex('#1e293b').hex('#94a3b8')(' FREE ');
|
|
31
|
+
process.stdout.write('\n ' + colors.success('✓') + ' ' + colors.text.bold(n) +
|
|
32
|
+
colors.muted(' · ') + colors.subtext(email ?? '') +
|
|
33
|
+
'\n ' + colors.muted('Plan ') + planBadge + '\n\n');
|
|
32
34
|
return true;
|
|
33
35
|
}
|
|
34
36
|
if (name === '/help') {
|
|
@@ -38,23 +40,28 @@ export async function handleCommand(cmd, cwd, clearHistory, addFileToContext, ge
|
|
|
38
40
|
if (name === '/clear' || name === '/new') {
|
|
39
41
|
clearHistory();
|
|
40
42
|
process.stdout.write(`\x1b]0;Dravix Code — AI-powered coding assistant\x07`);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
console.log(colors.success('
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
if (ui?.layout) {
|
|
44
|
+
ui.layout.clearChat({ cwd, meta: ui.meta });
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.clear();
|
|
48
|
+
}
|
|
49
|
+
renderCompactHeader(cwd, ui?.meta);
|
|
50
|
+
console.log(' ' + colors.success('✓') + ' ' + colors.text('New session started') +
|
|
51
|
+
colors.muted(' · use ') + colors.primary('/resume') + colors.muted(' to return to saved chats\n'));
|
|
52
|
+
if (ui?.layout) {
|
|
53
|
+
ui.layout.chatRow = Math.min(6, ui.layout.scrollEnd);
|
|
54
|
+
}
|
|
53
55
|
return true;
|
|
54
56
|
}
|
|
55
57
|
if (name === '/files') {
|
|
56
58
|
const ctx = buildContext(cwd);
|
|
57
|
-
|
|
59
|
+
const cols = process.stdout.columns ?? 80;
|
|
60
|
+
console.log('');
|
|
61
|
+
for (const line of ctx.split('\n')) {
|
|
62
|
+
console.log(' ' + colors.subtext(clipVis(line, Math.max(cols - 6, 20))));
|
|
63
|
+
}
|
|
64
|
+
console.log('');
|
|
58
65
|
return true;
|
|
59
66
|
}
|
|
60
67
|
if (name === '/retry') {
|
|
@@ -90,10 +97,10 @@ export async function handleCommand(cmd, cwd, clearHistory, addFileToContext, ge
|
|
|
90
97
|
return true;
|
|
91
98
|
}
|
|
92
99
|
if (name === '/model') {
|
|
93
|
-
process.stdout.write('\n ' + colors.primary('Dravix 3 Titanium') +
|
|
100
|
+
process.stdout.write('\n ' + colors.primary.bold('Dravix 3 Titanium') +
|
|
94
101
|
colors.muted(' + ') +
|
|
95
|
-
colors.
|
|
96
|
-
colors.muted(' · by
|
|
102
|
+
colors.accent.bold('Dravix 3.5 Quantum') +
|
|
103
|
+
colors.muted(' · by TensorSpark\n\n'));
|
|
97
104
|
return true;
|
|
98
105
|
}
|
|
99
106
|
if (name === '/undo') {
|
|
@@ -112,8 +119,8 @@ export async function handleCommand(cmd, cwd, clearHistory, addFileToContext, ge
|
|
|
112
119
|
printInfo('No undo history found.');
|
|
113
120
|
}
|
|
114
121
|
else {
|
|
115
|
-
console.log('\n ' + colors.primary('Undo History'));
|
|
116
|
-
console.log(' ' + colors.dim('─'.repeat(
|
|
122
|
+
console.log('\n ' + colors.primary.bold('Undo History'));
|
|
123
|
+
console.log(' ' + colors.dim('─'.repeat(42)));
|
|
117
124
|
for (const s of sessions.slice(0, 10)) {
|
|
118
125
|
const time = new Date(s.timestamp).toLocaleString();
|
|
119
126
|
console.log(' ' + colors.muted('·') + ' ' + colors.text(time) + ' ' + colors.muted(`${s.ops} operation(s)`));
|
package/dist/cli/index.js
CHANGED
|
@@ -5,12 +5,12 @@ import * as os from 'os';
|
|
|
5
5
|
import { randomBytes, createHash } from 'crypto';
|
|
6
6
|
import { execSync } from 'child_process';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
|
-
import { banner, printHelp, printError, colors } from '../utils/display.js';
|
|
8
|
+
import { banner, printHelp, printError, renderWelcomeCard, colors, Spinner, clipVis, padVis, visWidth, } from '../utils/display.js';
|
|
9
|
+
import { ChatLayout } from '../utils/layout.js';
|
|
9
10
|
import { startRepl } from './repl.js';
|
|
10
11
|
import { isLoggedIn, logout, getSavedUser, saveConfig, checkPlan, AUTH_URL } from '../services/auth.js';
|
|
11
|
-
import { checkUsage
|
|
12
|
+
import { checkUsage } from '../services/usage.js';
|
|
12
13
|
const POLL_URL = 'https://dravix.app/cli-auth.php';
|
|
13
|
-
const SPINNER = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
14
14
|
const VISITED_FILE = path.join(os.homedir(), '.dravix-code', 'visited.json');
|
|
15
15
|
// ── Project visit tracking ─────────────────────────────────────
|
|
16
16
|
function projectHash(cwd) {
|
|
@@ -34,39 +34,43 @@ function markProjectVisited(hash) {
|
|
|
34
34
|
}
|
|
35
35
|
async function showFirstTimeDialog(projectName) {
|
|
36
36
|
const cols = process.stdout.columns ?? 80;
|
|
37
|
-
const W = Math.min(cols - 6,
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return ' ' + BC('│ ') + text + ' '.repeat(pad) + BC(' │');
|
|
47
|
-
}
|
|
48
|
-
function btnRow(leftBtn, rightText) {
|
|
49
|
-
const lv = leftBtn.replace(/\x1b\[[0-9;]*m/g, '').length;
|
|
50
|
-
const rv = rightText.replace(/\x1b\[[0-9;]*m/g, '').length;
|
|
51
|
-
return ' ' + BC('│ ') + leftBtn + rightText + ' '.repeat(Math.max(W - lv - rv, 0)) + BC(' │');
|
|
52
|
-
}
|
|
37
|
+
const W = Math.min(Math.max(cols - 6, 40), 58);
|
|
38
|
+
const inner = W - 4;
|
|
39
|
+
const BC = colors.brand;
|
|
40
|
+
const P = colors.primary;
|
|
41
|
+
const Wt = colors.text;
|
|
42
|
+
const M = colors.muted;
|
|
43
|
+
const G = colors.success;
|
|
44
|
+
const R = colors.error;
|
|
45
|
+
const boxRow = (content) => ' ' + BC('│') + ' ' + padVis(content, inner) + ' ' + BC('│');
|
|
53
46
|
console.clear();
|
|
54
|
-
console.log('
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
console.log(
|
|
58
|
-
console.log(
|
|
59
|
-
console.log(
|
|
60
|
-
console.log(
|
|
61
|
-
console.log(
|
|
62
|
-
console.log(
|
|
63
|
-
console.log(
|
|
64
|
-
console.log(' ' + BC('╰' + '─'.repeat(W
|
|
47
|
+
console.log('');
|
|
48
|
+
const title = ' ◆ Dravix Code ';
|
|
49
|
+
const dashes = Math.max(W - 3 - visWidth(title), 2);
|
|
50
|
+
console.log(' ' + BC('╭─') + P.bold(title) + BC('─'.repeat(dashes) + '╮'));
|
|
51
|
+
console.log(boxRow(M('Trust and open workspace?')));
|
|
52
|
+
console.log(boxRow(''));
|
|
53
|
+
console.log(boxRow(Wt.bold(clipVis(projectName, inner))));
|
|
54
|
+
console.log(' ' + BC('├' + '─'.repeat(W - 2) + '┤'));
|
|
55
|
+
console.log(boxRow(`${G.bold('[ Enter ]')} ${Wt('Yes, open workspace')}`));
|
|
56
|
+
console.log(boxRow(`${R.bold('[ Esc ]')} ${M('No, exit')}`));
|
|
57
|
+
console.log(' ' + BC('╰' + '─'.repeat(W - 2) + '╯'));
|
|
65
58
|
console.log('');
|
|
66
59
|
return new Promise((resolve) => {
|
|
67
60
|
process.stdin.setRawMode(true);
|
|
68
61
|
process.stdin.resume();
|
|
69
62
|
process.stdin.setEncoding('utf8');
|
|
63
|
+
function cleanup() {
|
|
64
|
+
process.stdin.removeListener('data', onKey);
|
|
65
|
+
try {
|
|
66
|
+
process.stdin.setRawMode(false);
|
|
67
|
+
}
|
|
68
|
+
catch { }
|
|
69
|
+
try {
|
|
70
|
+
process.stdin.pause();
|
|
71
|
+
}
|
|
72
|
+
catch { }
|
|
73
|
+
}
|
|
70
74
|
function onKey(data) {
|
|
71
75
|
if (data === '\r' || data === '\n') {
|
|
72
76
|
cleanup();
|
|
@@ -77,9 +81,6 @@ async function showFirstTimeDialog(projectName) {
|
|
|
77
81
|
resolve(false);
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
|
-
function cleanup() {
|
|
81
|
-
process.stdin.removeListener('data', onKey);
|
|
82
|
-
}
|
|
83
84
|
process.stdin.on('data', onKey);
|
|
84
85
|
});
|
|
85
86
|
}
|
|
@@ -97,107 +98,36 @@ async function pollSession(sessionId) {
|
|
|
97
98
|
catch { /* network error — keep polling */ }
|
|
98
99
|
return null;
|
|
99
100
|
}
|
|
100
|
-
async function showWelcome() {
|
|
101
|
-
const cols = process.stdout.columns ?? 80;
|
|
102
|
-
const W = Math.min(cols, 64);
|
|
103
|
-
const P = colors.primary;
|
|
104
|
-
const PB = colors.primary.bold;
|
|
105
|
-
const DIM = colors.muted;
|
|
106
|
-
const G = colors.success;
|
|
107
|
-
const White = colors.text;
|
|
108
|
-
const Muted = colors.muted;
|
|
109
|
-
const line = () => DIM(' ' + '─'.repeat(W - 4));
|
|
110
|
-
const pad = (s, w) => s + ' '.repeat(Math.max(w - s.length, 0));
|
|
111
|
-
console.clear();
|
|
112
|
-
banner();
|
|
113
|
-
console.log(' ' + White.bold('Welcome to Dravix Code') + Muted(' — your AI coding partner'));
|
|
114
|
-
console.log(' ' + Muted('Works like Claude Code, Cursor, Copilot — but in your terminal.') + '\n');
|
|
115
|
-
const boxW = Math.min(W - 4, 58);
|
|
116
|
-
const inner = boxW - 2;
|
|
117
|
-
const BC = DIM;
|
|
118
|
-
const row = (icon, text) => {
|
|
119
|
-
const content = ` ${icon} ${text}`;
|
|
120
|
-
const padded = pad(content, inner);
|
|
121
|
-
return ' ' + BC('│') + White(padded) + BC('│');
|
|
122
|
-
};
|
|
123
|
-
console.log(' ' + BC('╭' + '─'.repeat(boxW - 2) + '╮'));
|
|
124
|
-
console.log(' ' + BC('│') + P(pad(' Capabilities', inner)) + BC('│'));
|
|
125
|
-
console.log(' ' + BC('├' + '─'.repeat(boxW - 2) + '┤'));
|
|
126
|
-
console.log(row(G('✓'), 'Write, edit and create code with AI'));
|
|
127
|
-
console.log(row(G('✓'), 'Search and understand any codebase'));
|
|
128
|
-
console.log(row(G('✓'), 'Run commands and fix errors automatically'));
|
|
129
|
-
console.log(row(G('✓'), 'Read files, folders and project structure'));
|
|
130
|
-
console.log(row(G('✓'), 'Works with TypeScript, Python, Go and more'));
|
|
131
|
-
console.log(' ' + BC('╰' + '─'.repeat(boxW - 2) + '╯') + '\n');
|
|
132
|
-
console.log(' ' + Muted('Powered by ') +
|
|
133
|
-
P.bold('Dravix 3 Titanium') +
|
|
134
|
-
Muted(' + ') +
|
|
135
|
-
P.bold('Dravix 3.5 Quantum'));
|
|
136
|
-
console.log(line() + '\n');
|
|
137
|
-
console.log(' ' + Muted('Sign in with your Google account to get started.') + '\n');
|
|
138
|
-
const enterKey = chalk.bgHex('#312e81').hex('#c7d2fe').bold(' Enter ');
|
|
139
|
-
const escKey = chalk.hex('#374151').bold(' Esc ');
|
|
140
|
-
console.log(' ' + enterKey + Muted(' Sign in with Google'));
|
|
141
|
-
console.log(' ' + escKey + Muted(' Cancel') + '\n');
|
|
142
|
-
console.log(line() + '\n');
|
|
143
|
-
return new Promise((resolve) => {
|
|
144
|
-
process.stdin.setRawMode(true);
|
|
145
|
-
process.stdin.resume();
|
|
146
|
-
process.stdin.setEncoding('utf8');
|
|
147
|
-
function onKey(data) {
|
|
148
|
-
if (data === '\r' || data === '\n') {
|
|
149
|
-
cleanup();
|
|
150
|
-
resolve(true);
|
|
151
|
-
}
|
|
152
|
-
else if (data === '\x1b' || data === '\x03' || data === 'n' || data === 'N') {
|
|
153
|
-
cleanup();
|
|
154
|
-
resolve(false);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
function cleanup() {
|
|
158
|
-
process.stdin.removeListener('data', onKey);
|
|
159
|
-
process.stdin.setRawMode(false);
|
|
160
|
-
process.stdin.pause();
|
|
161
|
-
}
|
|
162
|
-
process.stdin.on('data', onKey);
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
101
|
async function browserAuth() {
|
|
166
102
|
const sessionId = randomBytes(16).toString('hex');
|
|
167
103
|
const authUrl = `${AUTH_URL}?session=${sessionId}`;
|
|
168
104
|
const DIM = colors.muted;
|
|
169
105
|
const W = colors.text;
|
|
170
|
-
const P = colors.primary;
|
|
171
106
|
const cols = process.stdout.columns ?? 80;
|
|
172
|
-
const
|
|
107
|
+
const rule = colors.dim(' ' + '─'.repeat(Math.min(Math.max(cols - 4, 36), 60)));
|
|
173
108
|
console.clear();
|
|
174
109
|
banner();
|
|
175
|
-
console.log(
|
|
176
|
-
console.log('\n ' + DIM('
|
|
177
|
-
console.log('
|
|
178
|
-
console.log(' ' + DIM('
|
|
179
|
-
console.log(' ' + DIM('
|
|
180
|
-
console.log(
|
|
181
|
-
|
|
110
|
+
console.log(rule);
|
|
111
|
+
console.log('\n ' + DIM('1. ') + W('Open this link in your browser:') + '\n');
|
|
112
|
+
console.log(' ' + colors.primary(link(authUrl)) + '\n');
|
|
113
|
+
console.log(' ' + DIM('2. ') + W('Sign in to your Dravix account and authorize access'));
|
|
114
|
+
console.log(' ' + DIM('3. ') + W('Return here — authentication completes automatically') + '\n');
|
|
115
|
+
console.log(rule + '\n');
|
|
116
|
+
const spin = new Spinner();
|
|
117
|
+
spin.start('Waiting for authentication...', { showElapsed: true });
|
|
182
118
|
await new Promise((resolve, reject) => {
|
|
183
119
|
let done = false;
|
|
184
|
-
const spinnerInterval = setInterval(() => {
|
|
185
|
-
if (done)
|
|
186
|
-
return;
|
|
187
|
-
process.stdout.write(`\r ${colors.muted(SPINNER[frameIdx % SPINNER.length])} ${colors.muted('Waiting for authentication...')}`);
|
|
188
|
-
frameIdx++;
|
|
189
|
-
}, 80);
|
|
190
120
|
const poll = async () => {
|
|
191
121
|
if (done)
|
|
192
122
|
return;
|
|
193
123
|
const result = await pollSession(sessionId);
|
|
194
124
|
if (result) {
|
|
195
125
|
done = true;
|
|
196
|
-
|
|
197
|
-
process.stdout.write('\r\x1b[K');
|
|
126
|
+
spin.stop(true);
|
|
198
127
|
saveConfig({ token: result.token, name: result.name, email: result.email });
|
|
199
|
-
console.log(' ' + colors.success('✓') + ' ' + W('Signed in as ') +
|
|
200
|
-
|
|
128
|
+
console.log(' ' + colors.success('✓') + ' ' + W('Signed in as ') +
|
|
129
|
+
colors.primary.bold(result.name) + DIM(' · ') + colors.muted(result.email));
|
|
130
|
+
console.log('\n' + rule + '\n');
|
|
201
131
|
resolve();
|
|
202
132
|
return;
|
|
203
133
|
}
|
|
@@ -207,8 +137,7 @@ async function browserAuth() {
|
|
|
207
137
|
setTimeout(() => {
|
|
208
138
|
if (!done) {
|
|
209
139
|
done = true;
|
|
210
|
-
|
|
211
|
-
process.stdout.write('\r\x1b[K');
|
|
140
|
+
spin.stop(true);
|
|
212
141
|
reject(new Error('Authentication timed out after 5 minutes.'));
|
|
213
142
|
}
|
|
214
143
|
}, 300_000);
|
|
@@ -232,19 +161,13 @@ async function main() {
|
|
|
232
161
|
console.log(colors.muted('\n Signed out.\n'));
|
|
233
162
|
process.exit(0);
|
|
234
163
|
}
|
|
235
|
-
let justAuthenticated = false;
|
|
236
164
|
if (arg === '--login') {
|
|
237
|
-
if (isLoggedIn()) {
|
|
238
|
-
banner();
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
165
|
+
if (!isLoggedIn()) {
|
|
241
166
|
await browserAuth();
|
|
242
|
-
justAuthenticated = true;
|
|
243
167
|
}
|
|
244
168
|
}
|
|
245
169
|
else if (!isLoggedIn()) {
|
|
246
170
|
await browserAuth();
|
|
247
|
-
justAuthenticated = true;
|
|
248
171
|
}
|
|
249
172
|
const { name, email } = getSavedUser();
|
|
250
173
|
const cwd = (arg && !arg.startsWith('--')) ? path.resolve(arg) : process.cwd();
|
|
@@ -253,66 +176,32 @@ async function main() {
|
|
|
253
176
|
email ? checkPlan(email) : Promise.resolve('Free'),
|
|
254
177
|
token ? checkUsage(token) : Promise.resolve(null),
|
|
255
178
|
]);
|
|
256
|
-
const C = colors.primary;
|
|
257
|
-
const DIM = colors.muted;
|
|
258
|
-
const W = colors.text;
|
|
259
|
-
const planBadge = plan === 'Plus'
|
|
260
|
-
? colors.accent.bold('Plus')
|
|
261
|
-
: colors.muted('Free');
|
|
262
179
|
// ── First-time project check ──────────────────────────────
|
|
263
180
|
const pHash = projectHash(cwd);
|
|
264
181
|
const visited = getVisitedProjects();
|
|
265
182
|
if (!visited.includes(pHash)) {
|
|
266
|
-
const open = await showFirstTimeDialog(path.basename(cwd));
|
|
183
|
+
const open = await showFirstTimeDialog(path.basename(cwd) || cwd);
|
|
267
184
|
if (!open) {
|
|
268
185
|
console.log(chalk.hex('#6b7280')('\n Exited.\n'));
|
|
269
186
|
process.exit(0);
|
|
270
187
|
}
|
|
271
188
|
markProjectVisited(pHash);
|
|
272
|
-
// Erase dialog: move cursor to each line and overwrite with spaces
|
|
273
|
-
const termCols = process.stdout.columns ?? 80;
|
|
274
|
-
const blank = ' '.repeat(termCols);
|
|
275
|
-
for (let i = 1; i <= 13; i++)
|
|
276
|
-
process.stdout.write(`\x1b[${i};1H${blank}`);
|
|
277
|
-
process.stdout.write('\x1b[1;1H');
|
|
278
|
-
}
|
|
279
|
-
const rows = process.stdout.rows ?? 24;
|
|
280
|
-
const cols = process.stdout.columns ?? 80;
|
|
281
|
-
// FULL-SCREEN: clear everything including scrollback, set scroll region for chat (bottom 3 rows fixed)
|
|
282
|
-
process.stdout.write('\x1b[2J\x1b[3J'); // Clear screen + scrollback buffer
|
|
283
|
-
process.stdout.write(`\x1b[1;${rows - 3}r`); // Scroll region = chat area (rows 1 to rows-3)
|
|
284
|
-
process.stdout.write('\x1b[1;1H'); // Move to top-left
|
|
285
|
-
// Draw the app (ONE logo only)
|
|
286
|
-
banner();
|
|
287
|
-
console.log(DIM(' ' + '─'.repeat(45)));
|
|
288
|
-
console.log(colors.muted(' User ') + W(name ?? 'Unknown') + DIM(' · ') + colors.muted(email ?? ''));
|
|
289
|
-
console.log(colors.muted(' Plan ') + planBadge);
|
|
290
|
-
if (usage) {
|
|
291
|
-
const { bar, pct } = usageBar(usage.tokens_used, usage.limit);
|
|
292
|
-
const barColor = pct >= 80 ? colors.error
|
|
293
|
-
: pct >= 50 ? colors.warn
|
|
294
|
-
: colors.success;
|
|
295
|
-
const resetStr = formatResetTime(usage);
|
|
296
|
-
console.log(colors.muted(' Tokens ') +
|
|
297
|
-
barColor(bar) + ' ' +
|
|
298
|
-
colors.subtext(fmtNum(usage.tokens_used) + ' / ' + fmtNum(usage.limit)) +
|
|
299
|
-
DIM(' · resets in ' + resetStr));
|
|
300
189
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
190
|
+
const sessionMeta = { name, email, plan, usage };
|
|
191
|
+
const layout = new ChatLayout();
|
|
192
|
+
// Enter clean full-screen canvas and render welcome card inside scroll region
|
|
193
|
+
layout.enterFullScreen();
|
|
194
|
+
const welcomeLines = renderWelcomeCard(cwd, sessionMeta);
|
|
195
|
+
layout.chatRow = Math.min(welcomeLines + 1, layout.scrollEnd);
|
|
196
|
+
layout.init({ cwd, meta: sessionMeta, focusCursor: false });
|
|
197
|
+
layout.enterChat();
|
|
307
198
|
const cleanup = () => {
|
|
308
|
-
|
|
309
|
-
process.stdout.write('\x1b[2J'); // Clear screen
|
|
310
|
-
process.stdout.write('\x1b[1;1H'); // Move to top
|
|
199
|
+
layout.cleanup(true);
|
|
311
200
|
};
|
|
312
201
|
process.on('exit', cleanup);
|
|
313
202
|
process.on('SIGINT', () => { cleanup(); process.exit(0); });
|
|
314
203
|
process.on('SIGTERM', () => { cleanup(); process.exit(0); });
|
|
315
|
-
await startRepl(cwd);
|
|
204
|
+
await startRepl(cwd, sessionMeta, layout);
|
|
316
205
|
}
|
|
317
206
|
main().catch((err) => {
|
|
318
207
|
const msg = err instanceof Error ? err.message : String(err);
|