@tensorspark/dravix-code 0.0.0-stage → 1.5.0
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 +127 -0
- package/dist/cli/index.js +321 -0
- package/dist/cli/repl.js +3433 -0
- package/dist/services/ai.js +296 -0
- package/dist/services/auth.js +67 -0
- package/dist/services/context.js +260 -0
- package/dist/services/conversations.js +79 -0
- package/dist/services/executor.js +944 -0
- package/dist/services/undo.js +181 -0
- package/dist/services/usage.js +60 -0
- package/dist/utils/display.js +265 -0
- package/dist/utils/fileops.js +17 -0
- package/dist/utils/layout.js +82 -0
- package/package.json +38 -4
- package/README.md +0 -3
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { execFileSync } from 'child_process';
|
|
2
|
+
import { buildContext } from '../services/context.js';
|
|
3
|
+
import { banner, printHelp, printInfo, colors } from '../utils/display.js';
|
|
4
|
+
import { logout, getSavedUser, checkPlan } from '../services/auth.js';
|
|
5
|
+
import { undoLastSession, listUndoSessions } from '../services/undo.js';
|
|
6
|
+
export async function handleCommand(cmd, cwd, clearHistory, addFileToContext, getLastAI, retryLast) {
|
|
7
|
+
const parts = cmd.trim().split(/\s+/);
|
|
8
|
+
const name = parts[0].toLowerCase();
|
|
9
|
+
if (name === '/exit' || name === '/quit') {
|
|
10
|
+
console.log(colors.muted('\n Goodbye!\n'));
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
if (name === '/logout') {
|
|
14
|
+
logout();
|
|
15
|
+
console.log(colors.muted('\n Signed out. Run dravix again to authenticate.\n'));
|
|
16
|
+
process.exit(0);
|
|
17
|
+
}
|
|
18
|
+
if (name === '/whoami') {
|
|
19
|
+
const { name: n, email } = getSavedUser();
|
|
20
|
+
if (!n) {
|
|
21
|
+
printInfo('Not signed in.');
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const plan = email ? await checkPlan(email) : 'Free';
|
|
25
|
+
const planBadge = plan === 'Plus'
|
|
26
|
+
? colors.accent.bold('Plus')
|
|
27
|
+
: colors.muted('Free');
|
|
28
|
+
const W = colors.text;
|
|
29
|
+
process.stdout.write('\n ' + colors.success('✓') + ' ' + W(n) +
|
|
30
|
+
colors.subtext(' · ') + colors.muted(email ?? '') +
|
|
31
|
+
'\n ' + colors.muted(' Plan ') + planBadge + '\n\n');
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (name === '/help') {
|
|
35
|
+
printHelp();
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (name === '/clear' || name === '/new') {
|
|
39
|
+
clearHistory();
|
|
40
|
+
process.stdout.write(`\x1b]0;Dravix Code — AI-powered coding assistant\x07`);
|
|
41
|
+
console.clear();
|
|
42
|
+
banner();
|
|
43
|
+
const { name: userName } = getSavedUser();
|
|
44
|
+
const C = colors.primary;
|
|
45
|
+
const DIM = colors.subtext;
|
|
46
|
+
const W = colors.text;
|
|
47
|
+
console.log(DIM(' ─────────────────────────────────────────────'));
|
|
48
|
+
console.log(colors.success(' ✓') + W(' New session started — your chat history is saved'));
|
|
49
|
+
console.log(colors.muted(' ') + colors.muted('Use ') + C('/resume') + colors.muted(' to return to any previous conversation'));
|
|
50
|
+
console.log(DIM(' ─────────────────────────────────────────────'));
|
|
51
|
+
console.log(colors.muted(' ') + C('Tab') + colors.muted(' path complete ') + C('@') + colors.muted(' file picker ') + C('Ctrl+C') + colors.muted(' cancel ') + C('/help') + colors.muted(' commands'));
|
|
52
|
+
process.stdout.write('\n');
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (name === '/files') {
|
|
56
|
+
const ctx = buildContext(cwd);
|
|
57
|
+
console.log('\n' + colors.muted(ctx) + '\n');
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (name === '/retry') {
|
|
61
|
+
if (!retryLast) {
|
|
62
|
+
printInfo('Retry not available.');
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
retryLast();
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (name === '/copy') {
|
|
69
|
+
const text = getLastAI?.() ?? null;
|
|
70
|
+
if (!text) {
|
|
71
|
+
printInfo('No AI response to copy.');
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const buf = Buffer.from(text, 'utf-8');
|
|
76
|
+
if (process.platform === 'win32') {
|
|
77
|
+
execFileSync('clip', [], { input: buf, stdio: ['pipe', 'ignore', 'ignore'] });
|
|
78
|
+
}
|
|
79
|
+
else if (process.platform === 'darwin') {
|
|
80
|
+
execFileSync('pbcopy', [], { input: buf, stdio: ['pipe', 'ignore', 'ignore'] });
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
execFileSync('xclip', ['-selection', 'clipboard'], { input: buf, stdio: ['pipe', 'ignore', 'ignore'] });
|
|
84
|
+
}
|
|
85
|
+
printInfo('Last response copied to clipboard.');
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
printInfo('Copy failed — clipboard tool not available.');
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (name === '/model') {
|
|
93
|
+
process.stdout.write('\n ' + colors.primary('Dravix 3 Titanium') +
|
|
94
|
+
colors.muted(' + ') +
|
|
95
|
+
colors.primary('Dravix 3.5 Quantum') +
|
|
96
|
+
colors.muted(' · by Taj Special\n\n'));
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
if (name === '/undo') {
|
|
100
|
+
const result = undoLastSession(cwd);
|
|
101
|
+
if (result.success) {
|
|
102
|
+
console.log('\n ' + colors.success('✓') + ' ' + colors.text(result.message) + '\n');
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
console.log('\n ' + colors.error('✗') + ' ' + colors.muted(result.message) + '\n');
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
if (name === '/history') {
|
|
110
|
+
const sessions = listUndoSessions();
|
|
111
|
+
if (sessions.length === 0) {
|
|
112
|
+
printInfo('No undo history found.');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
console.log('\n ' + colors.primary('Undo History'));
|
|
116
|
+
console.log(' ' + colors.dim('─'.repeat(40)));
|
|
117
|
+
for (const s of sessions.slice(0, 10)) {
|
|
118
|
+
const time = new Date(s.timestamp).toLocaleString();
|
|
119
|
+
console.log(' ' + colors.muted('·') + ' ' + colors.text(time) + ' ' + colors.muted(`${s.ops} operation(s)`));
|
|
120
|
+
}
|
|
121
|
+
console.log('');
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
printInfo(`Unknown command: ${cmd} (type /help for list)`);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as os from 'os';
|
|
5
|
+
import { randomBytes, createHash } from 'crypto';
|
|
6
|
+
import { execSync } from 'child_process';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import { banner, printHelp, printError, colors } from '../utils/display.js';
|
|
9
|
+
import { startRepl } from './repl.js';
|
|
10
|
+
import { isLoggedIn, logout, getSavedUser, saveConfig, checkPlan, AUTH_URL } from '../services/auth.js';
|
|
11
|
+
import { checkUsage, usageBar, fmtNum, formatResetTime } from '../services/usage.js';
|
|
12
|
+
const POLL_URL = 'https://dravix.app/cli-auth.php';
|
|
13
|
+
const SPINNER = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
14
|
+
const VISITED_FILE = path.join(os.homedir(), '.dravix-code', 'visited.json');
|
|
15
|
+
// ── Project visit tracking ─────────────────────────────────────
|
|
16
|
+
function projectHash(cwd) {
|
|
17
|
+
return createHash('sha256').update(path.resolve(cwd)).digest('hex').slice(0, 10);
|
|
18
|
+
}
|
|
19
|
+
function getVisitedProjects() {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(fs.readFileSync(VISITED_FILE, 'utf-8'));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function markProjectVisited(hash) {
|
|
28
|
+
const visited = getVisitedProjects();
|
|
29
|
+
if (!visited.includes(hash)) {
|
|
30
|
+
visited.push(hash);
|
|
31
|
+
fs.mkdirSync(path.dirname(VISITED_FILE), { recursive: true });
|
|
32
|
+
fs.writeFileSync(VISITED_FILE, JSON.stringify(visited), 'utf-8');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function showFirstTimeDialog(projectName) {
|
|
36
|
+
const cols = process.stdout.columns ?? 80;
|
|
37
|
+
const W = Math.min(cols - 6, 56);
|
|
38
|
+
const BC = chalk.hex('#6366f1');
|
|
39
|
+
const Wt = chalk.hex('#e2e8f0');
|
|
40
|
+
const Dim = chalk.hex('#6b7280');
|
|
41
|
+
const G = chalk.hex('#34d399');
|
|
42
|
+
const R = chalk.hex('#f87171');
|
|
43
|
+
function row(text) {
|
|
44
|
+
const visible = text.replace(/\x1b\[[0-9;]*m/g, '').length;
|
|
45
|
+
const pad = Math.max(W - visible, 0);
|
|
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
|
+
}
|
|
53
|
+
console.clear();
|
|
54
|
+
console.log(' ' + BC('╭' + '─'.repeat(W + 2) + '╮'));
|
|
55
|
+
console.log(row(chalk.hex('#a78bfa').bold('Dravix Code') + Dim(' - first time in this project')));
|
|
56
|
+
console.log(' ' + BC('├' + '─'.repeat(W + 2) + '┤'));
|
|
57
|
+
console.log(row(Wt('Open Dravix Code in:')));
|
|
58
|
+
console.log(row(' ' + chalk.hex('#c4b5fd').bold(projectName)));
|
|
59
|
+
console.log(' ' + BC('├' + '─'.repeat(W + 2) + '┤'));
|
|
60
|
+
console.log(row(''));
|
|
61
|
+
console.log(btnRow(G.bold(' [ Enter ] '), Wt(' Yes, open here')));
|
|
62
|
+
console.log(btnRow(R.bold(' [ Esc ] '), Wt(' No, exit')));
|
|
63
|
+
console.log(row(''));
|
|
64
|
+
console.log(' ' + BC('╰' + '─'.repeat(W + 2) + '╯'));
|
|
65
|
+
console.log('');
|
|
66
|
+
return new Promise((resolve) => {
|
|
67
|
+
process.stdin.setRawMode(true);
|
|
68
|
+
process.stdin.resume();
|
|
69
|
+
process.stdin.setEncoding('utf8');
|
|
70
|
+
function onKey(data) {
|
|
71
|
+
if (data === '\r' || data === '\n') {
|
|
72
|
+
cleanup();
|
|
73
|
+
resolve(true);
|
|
74
|
+
}
|
|
75
|
+
else if (data === '\x1b' || data === '\x03') {
|
|
76
|
+
cleanup();
|
|
77
|
+
resolve(false);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function cleanup() {
|
|
81
|
+
process.stdin.removeListener('data', onKey);
|
|
82
|
+
}
|
|
83
|
+
process.stdin.on('data', onKey);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function link(url) {
|
|
87
|
+
return `\x1b]8;;${url}\x1b\\${url}\x1b]8;;\x1b\\`;
|
|
88
|
+
}
|
|
89
|
+
async function pollSession(sessionId) {
|
|
90
|
+
try {
|
|
91
|
+
const res = await fetch(`${POLL_URL}?action=poll&session=${sessionId}`);
|
|
92
|
+
const data = await res.json();
|
|
93
|
+
if (data.authenticated && data.token) {
|
|
94
|
+
return { token: data.token, name: data.name ?? '', email: data.email ?? '' };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch { /* network error — keep polling */ }
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
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
|
+
async function browserAuth() {
|
|
166
|
+
const sessionId = randomBytes(16).toString('hex');
|
|
167
|
+
const authUrl = `${AUTH_URL}?session=${sessionId}`;
|
|
168
|
+
const DIM = colors.muted;
|
|
169
|
+
const W = colors.text;
|
|
170
|
+
const P = colors.primary;
|
|
171
|
+
const cols = process.stdout.columns ?? 80;
|
|
172
|
+
const line = DIM(' ' + '─'.repeat(Math.min(cols - 4, 51)));
|
|
173
|
+
console.clear();
|
|
174
|
+
banner();
|
|
175
|
+
console.log(line);
|
|
176
|
+
console.log('\n ' + DIM('Step 1 — ') + W('Open this link in your browser:') + '\n');
|
|
177
|
+
console.log(' ' + colors.primary(link(authUrl)) + '\n');
|
|
178
|
+
console.log(' ' + DIM('Step 2 — ') + W('Sign in to your Dravix account and authorize access'));
|
|
179
|
+
console.log(' ' + DIM('Step 3 — ') + W('Return here — authentication completes automatically') + '\n');
|
|
180
|
+
console.log(line + '\n');
|
|
181
|
+
let frameIdx = 0;
|
|
182
|
+
await new Promise((resolve, reject) => {
|
|
183
|
+
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
|
+
const poll = async () => {
|
|
191
|
+
if (done)
|
|
192
|
+
return;
|
|
193
|
+
const result = await pollSession(sessionId);
|
|
194
|
+
if (result) {
|
|
195
|
+
done = true;
|
|
196
|
+
clearInterval(spinnerInterval);
|
|
197
|
+
process.stdout.write('\r\x1b[K');
|
|
198
|
+
saveConfig({ token: result.token, name: result.name, email: result.email });
|
|
199
|
+
console.log(' ' + colors.success('✓') + ' ' + W('Signed in as ') + colors.primary.bold(result.name) + DIM(' · ') + colors.muted(result.email));
|
|
200
|
+
console.log(DIM('\n ' + '─'.repeat(47)) + '\n');
|
|
201
|
+
resolve();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
setTimeout(poll, 2000);
|
|
205
|
+
};
|
|
206
|
+
poll();
|
|
207
|
+
setTimeout(() => {
|
|
208
|
+
if (!done) {
|
|
209
|
+
done = true;
|
|
210
|
+
clearInterval(spinnerInterval);
|
|
211
|
+
process.stdout.write('\r\x1b[K');
|
|
212
|
+
reject(new Error('Authentication timed out after 5 minutes.'));
|
|
213
|
+
}
|
|
214
|
+
}, 300_000);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async function main() {
|
|
218
|
+
if (process.platform === 'win32') {
|
|
219
|
+
try {
|
|
220
|
+
execSync('chcp 65001', { stdio: 'ignore' });
|
|
221
|
+
}
|
|
222
|
+
catch { }
|
|
223
|
+
}
|
|
224
|
+
const arg = process.argv[2];
|
|
225
|
+
if (arg === '--help' || arg === '-h') {
|
|
226
|
+
banner();
|
|
227
|
+
printHelp();
|
|
228
|
+
process.exit(0);
|
|
229
|
+
}
|
|
230
|
+
if (arg === '--logout') {
|
|
231
|
+
logout();
|
|
232
|
+
console.log(colors.muted('\n Signed out.\n'));
|
|
233
|
+
process.exit(0);
|
|
234
|
+
}
|
|
235
|
+
let justAuthenticated = false;
|
|
236
|
+
if (arg === '--login') {
|
|
237
|
+
if (isLoggedIn()) {
|
|
238
|
+
banner();
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
await browserAuth();
|
|
242
|
+
justAuthenticated = true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else if (!isLoggedIn()) {
|
|
246
|
+
await browserAuth();
|
|
247
|
+
justAuthenticated = true;
|
|
248
|
+
}
|
|
249
|
+
const { name, email } = getSavedUser();
|
|
250
|
+
const cwd = (arg && !arg.startsWith('--')) ? path.resolve(arg) : process.cwd();
|
|
251
|
+
const token = (await import('../services/auth.js')).getToken() ?? '';
|
|
252
|
+
const [plan, usage] = await Promise.all([
|
|
253
|
+
email ? checkPlan(email) : Promise.resolve('Free'),
|
|
254
|
+
token ? checkUsage(token) : Promise.resolve(null),
|
|
255
|
+
]);
|
|
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
|
+
// ── First-time project check ──────────────────────────────
|
|
263
|
+
const pHash = projectHash(cwd);
|
|
264
|
+
const visited = getVisitedProjects();
|
|
265
|
+
if (!visited.includes(pHash)) {
|
|
266
|
+
const open = await showFirstTimeDialog(path.basename(cwd));
|
|
267
|
+
if (!open) {
|
|
268
|
+
console.log(chalk.hex('#6b7280')('\n Exited.\n'));
|
|
269
|
+
process.exit(0);
|
|
270
|
+
}
|
|
271
|
+
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
|
+
}
|
|
301
|
+
console.log(colors.muted(' Project ') + W(path.basename(cwd)));
|
|
302
|
+
console.log(colors.muted(' Path ') + DIM(cwd));
|
|
303
|
+
console.log(DIM(' ' + '─'.repeat(45)));
|
|
304
|
+
console.log(colors.muted(' ') + C('Tab') + colors.muted(' path complete ') + C('@') + colors.muted(' file picker ') + C('Ctrl+C') + colors.muted(' cancel ') + C('/help') + colors.muted(' commands'));
|
|
305
|
+
process.stdout.write('\n');
|
|
306
|
+
// Start REPL and handle cleanup on exit
|
|
307
|
+
const cleanup = () => {
|
|
308
|
+
process.stdout.write('\x1b[r'); // Reset scroll region
|
|
309
|
+
process.stdout.write('\x1b[2J'); // Clear screen
|
|
310
|
+
process.stdout.write('\x1b[1;1H'); // Move to top
|
|
311
|
+
};
|
|
312
|
+
process.on('exit', cleanup);
|
|
313
|
+
process.on('SIGINT', () => { cleanup(); process.exit(0); });
|
|
314
|
+
process.on('SIGTERM', () => { cleanup(); process.exit(0); });
|
|
315
|
+
await startRepl(cwd);
|
|
316
|
+
}
|
|
317
|
+
main().catch((err) => {
|
|
318
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
319
|
+
printError(msg);
|
|
320
|
+
process.exit(1);
|
|
321
|
+
});
|