@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.
@@ -0,0 +1,181 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as os from 'os';
4
+ const UNDO_DIR = path.join(os.homedir(), '.dravix-code', 'undo');
5
+ let currentSession = null;
6
+ // Initialize undo directory
7
+ function ensureUndoDir() {
8
+ fs.mkdirSync(UNDO_DIR, { recursive: true });
9
+ }
10
+ // Generate unique session ID
11
+ function generateSessionId() {
12
+ return Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
13
+ }
14
+ // Start a new undo session (before a batch of operations)
15
+ export function startUndoSession() {
16
+ ensureUndoDir();
17
+ const id = generateSessionId();
18
+ currentSession = {
19
+ id,
20
+ timestamp: new Date().toISOString(),
21
+ operations: [],
22
+ };
23
+ return id;
24
+ }
25
+ // Backup a file before modification
26
+ export function backupFile(filePath, cwd) {
27
+ try {
28
+ if (!fs.existsSync(filePath))
29
+ return null;
30
+ const relPath = path.relative(cwd, filePath).replace(/\\/g, '/');
31
+ const backupId = currentSession?.id ?? generateSessionId();
32
+ const backupDir = path.join(UNDO_DIR, backupId);
33
+ fs.mkdirSync(backupDir, { recursive: true });
34
+ // Create backup with path-based naming
35
+ const backupName = relPath.replace(/[/\\]/g, '__');
36
+ const backupPath = path.join(backupDir, backupName);
37
+ fs.copyFileSync(filePath, backupPath);
38
+ return backupPath;
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ }
44
+ // Record a write operation for undo
45
+ export function recordWrite(filePath, backupPath) {
46
+ if (!currentSession)
47
+ return;
48
+ currentSession.operations.push({
49
+ type: 'write',
50
+ path: filePath,
51
+ backupPath: backupPath ?? undefined,
52
+ });
53
+ }
54
+ // Record an edit operation for undo
55
+ export function recordEdit(filePath, backupPath) {
56
+ if (!currentSession)
57
+ return;
58
+ currentSession.operations.push({
59
+ type: 'edit',
60
+ path: filePath,
61
+ backupPath: backupPath ?? undefined,
62
+ });
63
+ }
64
+ // Record a delete operation for undo
65
+ export function recordDelete(filePath) {
66
+ if (!currentSession)
67
+ return;
68
+ let content = '';
69
+ try {
70
+ content = fs.readFileSync(filePath, 'utf-8');
71
+ }
72
+ catch { /* ignore */ }
73
+ currentSession.operations.push({
74
+ type: 'delete',
75
+ path: filePath,
76
+ deletedContent: content || undefined,
77
+ });
78
+ }
79
+ // Save the current undo session
80
+ export function saveUndoSession() {
81
+ if (!currentSession || currentSession.operations.length === 0)
82
+ return;
83
+ ensureUndoDir();
84
+ const sessionPath = path.join(UNDO_DIR, `${currentSession.id}.json`);
85
+ fs.writeFileSync(sessionPath, JSON.stringify(currentSession, null, 2), 'utf-8');
86
+ }
87
+ // Undo the last session
88
+ export function undoLastSession(cwd) {
89
+ ensureUndoDir();
90
+ // Find the most recent session file
91
+ const files = fs.readdirSync(UNDO_DIR)
92
+ .filter(f => f.endsWith('.json'))
93
+ .sort()
94
+ .reverse();
95
+ if (files.length === 0) {
96
+ return { success: false, message: 'No undo history found' };
97
+ }
98
+ const sessionPath = path.join(UNDO_DIR, files[0]);
99
+ const session = JSON.parse(fs.readFileSync(sessionPath, 'utf-8'));
100
+ let restored = 0;
101
+ let errors = 0;
102
+ // Process operations in reverse order
103
+ for (const op of session.operations.reverse()) {
104
+ try {
105
+ if (op.type === 'write' || op.type === 'edit') {
106
+ // Restore from backup
107
+ if (op.backupPath && fs.existsSync(op.backupPath)) {
108
+ fs.copyFileSync(op.backupPath, op.path);
109
+ restored++;
110
+ }
111
+ else {
112
+ errors++;
113
+ }
114
+ }
115
+ else if (op.type === 'delete') {
116
+ // Recreate the deleted file
117
+ if (op.deletedContent !== undefined) {
118
+ fs.mkdirSync(path.dirname(op.path), { recursive: true });
119
+ fs.writeFileSync(op.path, op.deletedContent, 'utf-8');
120
+ restored++;
121
+ }
122
+ else {
123
+ errors++;
124
+ }
125
+ }
126
+ }
127
+ catch {
128
+ errors++;
129
+ }
130
+ }
131
+ // Clean up session file and backup directory
132
+ try {
133
+ fs.unlinkSync(sessionPath);
134
+ const backupDir = path.join(UNDO_DIR, session.id);
135
+ if (fs.existsSync(backupDir)) {
136
+ fs.rmSync(backupDir, { recursive: true });
137
+ }
138
+ }
139
+ catch { /* ignore */ }
140
+ const msg = `Undone: ${restored} operation(s) restored` +
141
+ (errors > 0 ? `, ${errors} error(s)` : '') +
142
+ ` from ${new Date(session.timestamp).toLocaleString()}`;
143
+ return { success: restored > 0, message: msg };
144
+ }
145
+ // Get list of available undo sessions
146
+ export function listUndoSessions() {
147
+ ensureUndoDir();
148
+ const files = fs.readdirSync(UNDO_DIR).filter(f => f.endsWith('.json'));
149
+ return files.map(f => {
150
+ try {
151
+ const session = JSON.parse(fs.readFileSync(path.join(UNDO_DIR, f), 'utf-8'));
152
+ return {
153
+ id: session.id,
154
+ timestamp: session.timestamp,
155
+ ops: session.operations.length,
156
+ };
157
+ }
158
+ catch {
159
+ return { id: f.replace('.json', ''), timestamp: '', ops: 0 };
160
+ }
161
+ }).sort((a, b) => b.timestamp.localeCompare(a.timestamp));
162
+ }
163
+ // Clean up old undo sessions (older than 7 days)
164
+ export function cleanupOldSessions() {
165
+ ensureUndoDir();
166
+ const files = fs.readdirSync(UNDO_DIR).filter(f => f.endsWith('.json'));
167
+ const cutoff = Date.now() - 7 * 24 * 60 * 60 * 1000;
168
+ for (const f of files) {
169
+ try {
170
+ const session = JSON.parse(fs.readFileSync(path.join(UNDO_DIR, f), 'utf-8'));
171
+ if (new Date(session.timestamp).getTime() < cutoff) {
172
+ fs.unlinkSync(path.join(UNDO_DIR, f));
173
+ const backupDir = path.join(UNDO_DIR, session.id);
174
+ if (fs.existsSync(backupDir)) {
175
+ fs.rmSync(backupDir, { recursive: true });
176
+ }
177
+ }
178
+ }
179
+ catch { /* ignore */ }
180
+ }
181
+ }
@@ -0,0 +1,60 @@
1
+ const USAGE_URL = 'https://dravix.app/cli-usage.php';
2
+ export async function checkUsage(cliToken) {
3
+ try {
4
+ const res = await fetch(USAGE_URL, {
5
+ method: 'POST',
6
+ headers: { 'Content-Type': 'application/json' },
7
+ body: JSON.stringify({ action: 'check', token: cliToken }),
8
+ });
9
+ if (!res.ok)
10
+ return null;
11
+ return await res.json();
12
+ }
13
+ catch {
14
+ return null;
15
+ }
16
+ }
17
+ export async function reportUsage(cliToken, tokens) {
18
+ try {
19
+ const res = await fetch(USAGE_URL, {
20
+ method: 'POST',
21
+ headers: { 'Content-Type': 'application/json' },
22
+ body: JSON.stringify({ action: 'add', token: cliToken, tokens }),
23
+ });
24
+ if (!res.ok)
25
+ return null;
26
+ return await res.json();
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ // Estimate tokens from text (~4 chars per token)
33
+ export function estimateTokens(text) {
34
+ return Math.max(1, Math.ceil(text.length / 4));
35
+ }
36
+ // Format time until reset — uses server-side seconds to avoid timezone issues
37
+ export function formatResetTime(info) {
38
+ const secs = typeof info === 'string'
39
+ ? Math.max(0, Math.floor((new Date(info).getTime() - Date.now()) / 1000))
40
+ : (info.reset_in_seconds ?? 0);
41
+ if (secs <= 0)
42
+ return 'soon';
43
+ const h = Math.floor(secs / 3600);
44
+ const m = Math.floor((secs % 3600) / 60);
45
+ if (h > 0)
46
+ return `${h}h ${m}m`;
47
+ return `${m}m`;
48
+ }
49
+ // Format number with K suffix
50
+ export function fmtNum(n) {
51
+ return n >= 1000 ? (n / 1000).toFixed(1).replace('.0', '') + 'k' : String(n);
52
+ }
53
+ // Progress bar: ████████░░░░ pct%
54
+ export function usageBar(used, limit, width = 18) {
55
+ const pct = Math.min(Math.round((used / limit) * 100), 100);
56
+ const filled = Math.round((pct / 100) * width);
57
+ const empty = width - filled;
58
+ const bar = '█'.repeat(filled) + '░'.repeat(empty);
59
+ return { bar, pct };
60
+ }
@@ -0,0 +1,265 @@
1
+ import chalk from 'chalk';
2
+ import { readFileSync } from 'fs';
3
+ import { fileURLToPath } from 'url';
4
+ import { dirname, join } from 'path';
5
+ const _dir = dirname(fileURLToPath(import.meta.url));
6
+ const _pkg = JSON.parse(readFileSync(join(_dir, '../../package.json'), 'utf-8'));
7
+ export const VERSION = _pkg.version;
8
+ export const colors = {
9
+ primary: chalk.hex('#6366f1'),
10
+ accent: chalk.hex('#818cf8'),
11
+ success: chalk.hex('#34d399'),
12
+ error: chalk.hex('#f87171'),
13
+ warn: chalk.hex('#fbbf24'),
14
+ muted: chalk.hex('#6b7280'),
15
+ ai: chalk.hex('#c4b5fd'),
16
+ dim: chalk.hex('#374151'),
17
+ bg: chalk.hex('#0d1117'),
18
+ surface: chalk.hex('#161b22'),
19
+ border: chalk.hex('#30363d'),
20
+ text: chalk.hex('#e2e8f0'),
21
+ subtext: chalk.hex('#94a3b8'),
22
+ };
23
+ export function banner() {
24
+ console.log(colors.primary.bold(`
25
+ ██████╗ ██████╗ █████╗ ██╗ ██╗██╗██╗ ██╗
26
+ ██╔══██╗██╔══██╗██╔══██╗██║ ██║██║╚██╗██╔╝
27
+ ██║ ██║██████╔╝███████║██║ ██║██║ ╚███╔╝
28
+ ██║ ██║██╔══██╗██╔══██║╚██╗ ██╔╝██║ ██╔██╗
29
+ ██████╔╝██║ ██║██║ ██║ ╚████╔╝ ██║██╔╝ ██╗
30
+ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝`));
31
+ console.log(colors.primary.bold(' Code') + colors.muted(` v${VERSION} · `) + colors.accent('AI-powered coding assistant'));
32
+ console.log(colors.dim(' ─────────────────────────────────────────────\n'));
33
+ }
34
+ export function printAI(chunk) {
35
+ process.stdout.write(colors.ai(chunk));
36
+ }
37
+ export function printOpResult(result) {
38
+ if (result.type === 'created') {
39
+ console.log(colors.success(' ✓') + colors.text(' Created ') + colors.muted(result.path ?? ''));
40
+ }
41
+ else if (result.type === 'skipped') {
42
+ console.log(colors.muted(' ·') + colors.text(' Unchanged ') + colors.muted(result.path ?? ''));
43
+ }
44
+ else if (result.type === 'folder_created') {
45
+ console.log(colors.success(' ✓') + colors.text(' Created dir ') + colors.muted(result.path ?? ''));
46
+ }
47
+ else if (result.type === 'deleted') {
48
+ console.log(colors.error(' ✗') + colors.text(' Deleted ') + colors.muted(result.path ?? ''));
49
+ }
50
+ else if (result.type === 'modified') {
51
+ const diff = result.diff ?? [];
52
+ const adds = diff.filter(d => d.kind === 'add').length;
53
+ const removes = diff.filter(d => d.kind === 'remove').length;
54
+ const cols = process.stdout.columns ?? 80;
55
+ const displayAdds = adds > 0 ? adds : (result.linesAfter ?? 0) - Math.min(result.linesBefore ?? 0, result.linesAfter ?? 0);
56
+ const displayRemoves = removes > 0 ? removes : (result.linesBefore ?? 0) - Math.min(result.linesBefore ?? 0, result.linesAfter ?? 0);
57
+ const statStr = [
58
+ (adds > 0 || result.linesAfter !== undefined) && displayAdds > 0 ? colors.success.bold(`+${displayAdds}`) : '',
59
+ (removes > 0 || result.linesBefore !== undefined) && displayRemoves > 0 ? colors.error.bold(`-${displayRemoves}`) : '',
60
+ ].filter(Boolean).join(' ');
61
+ const pathStr = colors.text(result.path ?? '');
62
+ const iconStr = colors.warn(' ~');
63
+ const labelStr = colors.subtext(' Updated ');
64
+ const statPad = statStr ? ' ' + statStr : '';
65
+ console.log(iconStr + labelStr + pathStr + statPad);
66
+ const totalChanges = displayAdds + displayRemoves;
67
+ if (totalChanges > 30) {
68
+ if (result.linesBefore !== undefined && result.linesAfter !== undefined) {
69
+ const delta = result.linesAfter - result.linesBefore;
70
+ const deltaStr = delta > 0 ? colors.success(`+${delta}`) : delta < 0 ? colors.error(`${delta}`) : '=0';
71
+ console.log(colors.muted(` ${result.linesBefore} → ${result.linesAfter} lines (${deltaStr})`));
72
+ }
73
+ else {
74
+ console.log(colors.muted(` ${totalChanges} lines changed`));
75
+ }
76
+ console.log(colors.muted(` ${colors.muted('···')} ${colors.success(`+${displayAdds}`)} added, ${colors.error(`-${displayRemoves}`)} removed ${colors.muted('(more lines not shown)')}`));
77
+ return;
78
+ }
79
+ if (diff.length === 0 && result.linesBefore !== undefined) {
80
+ const delta = (result.linesAfter ?? 0) - (result.linesBefore ?? 0);
81
+ const deltaStr = delta > 0 ? colors.success(`+${delta} lines`) : delta < 0 ? colors.error(`${delta} lines`) : 'no line count change';
82
+ console.log(colors.muted(` ${result.linesBefore} → ${result.linesAfter} lines (${deltaStr})`));
83
+ return;
84
+ }
85
+ if (diff.length === 0 || (adds === 0 && removes === 0)) {
86
+ console.log(colors.muted(' (formatting / whitespace change)'));
87
+ return;
88
+ }
89
+ const CONTEXT = 2;
90
+ const MAX_SIDE = 20;
91
+ const show = new Uint8Array(diff.length);
92
+ for (let i = 0; i < diff.length; i++) {
93
+ if (diff[i].kind !== 'context') {
94
+ for (let c = Math.max(0, i - CONTEXT); c <= Math.min(diff.length - 1, i + CONTEXT); c++)
95
+ show[c] = 1;
96
+ }
97
+ }
98
+ const maxTextW = cols - 12;
99
+ const clip = (t) => t.length > maxTextW ? t.slice(0, maxTextW - 1) + '…' : t;
100
+ const renderLine = (line) => {
101
+ const num = String(line.lineNo).padStart(5, ' ');
102
+ if (line.kind === 'remove') {
103
+ const content = ` ${num} ${colors.error('-')} ${clip(line.text)}`;
104
+ console.log(' ' + colors.error('▌') + chalk.bgHex('#1c0a0a')(content.padEnd(cols - 3)));
105
+ }
106
+ else if (line.kind === 'add') {
107
+ const content = ` ${num} ${colors.success('+')} ${clip(line.text)}`;
108
+ console.log(' ' + colors.success('▌') + chalk.bgHex('#021a0e')(content.padEnd(cols - 3)));
109
+ }
110
+ else {
111
+ console.log(colors.dim(` ${num} ${clip(line.text)}`));
112
+ }
113
+ };
114
+ const hunks = [];
115
+ let curHunk = [];
116
+ let lastIdx = -1;
117
+ for (let i = 0; i < diff.length; i++) {
118
+ if (!show[i])
119
+ continue;
120
+ if (lastIdx >= 0 && i > lastIdx + 1) {
121
+ hunks.push(curHunk);
122
+ curHunk = [];
123
+ }
124
+ lastIdx = i;
125
+ curHunk.push(diff[i]);
126
+ }
127
+ if (curHunk.length > 0)
128
+ hunks.push(curHunk);
129
+ let shownRemoves = 0;
130
+ let shownAdds = 0;
131
+ for (let h = 0; h < hunks.length; h++) {
132
+ if (shownRemoves >= MAX_SIDE && shownAdds >= MAX_SIDE)
133
+ break;
134
+ if (h > 0)
135
+ console.log(colors.dim(' ╌╌╌'));
136
+ const hunk = hunks[h];
137
+ const before = [];
138
+ const hRemoves = [];
139
+ const hAdds = [];
140
+ let pendingCtx = [];
141
+ let seenChange = false;
142
+ for (const line of hunk) {
143
+ if (line.kind === 'context') {
144
+ if (!seenChange)
145
+ before.push(line);
146
+ else
147
+ pendingCtx.push(line);
148
+ }
149
+ else {
150
+ seenChange = true;
151
+ pendingCtx = [];
152
+ if (line.kind === 'remove')
153
+ hRemoves.push(line);
154
+ else
155
+ hAdds.push(line);
156
+ }
157
+ }
158
+ for (const l of before)
159
+ renderLine(l);
160
+ for (const l of hRemoves) {
161
+ if (shownRemoves >= MAX_SIDE)
162
+ break;
163
+ renderLine(l);
164
+ shownRemoves++;
165
+ }
166
+ for (const l of hAdds) {
167
+ if (shownAdds >= MAX_SIDE)
168
+ break;
169
+ renderLine(l);
170
+ shownAdds++;
171
+ }
172
+ for (const l of pendingCtx)
173
+ renderLine(l);
174
+ }
175
+ const hiddenRemoves = removes - shownRemoves;
176
+ const hiddenAdds = adds - shownAdds;
177
+ if (hiddenRemoves > 0 || hiddenAdds > 0) {
178
+ const parts = [
179
+ hiddenRemoves > 0 ? colors.error(`-${hiddenRemoves}`) : '',
180
+ hiddenAdds > 0 ? colors.success(`+${hiddenAdds}`) : '',
181
+ ].filter(Boolean).join(' ');
182
+ console.log(colors.muted(` … ${parts} more lines not shown`));
183
+ }
184
+ }
185
+ else if (result.type === 'run') {
186
+ const cmd = result.message ?? '';
187
+ const cols = process.stdout.columns ?? 80;
188
+ console.log(colors.primary(' $') + ' ' + colors.text(cmd));
189
+ if (result.output) {
190
+ const outLines = result.output.split('\n').filter(l => l.trim()).slice(0, 20);
191
+ if (outLines.length > 0) {
192
+ const maxW = Math.min(Math.max(...outLines.map(l => l.length), 10) + 2, cols - 8);
193
+ console.log(colors.dim(' ╭' + '─'.repeat(maxW)));
194
+ for (const line of outLines) {
195
+ const clipped = line.length > maxW - 2 ? line.slice(0, maxW - 3) + '…' : line;
196
+ console.log(colors.dim(' │') + ' ' + colors.subtext(clipped));
197
+ }
198
+ console.log(colors.dim(' ╰' + '─'.repeat(maxW)));
199
+ }
200
+ }
201
+ }
202
+ else if (result.type === 'error') {
203
+ const msg = result.message ?? '';
204
+ const cols = process.stdout.columns ?? 80;
205
+ const errLines = msg.split('\n').filter(l => l.trim());
206
+ if (errLines.length <= 1) {
207
+ console.log(colors.error(' ✗') + colors.text(' ' + msg));
208
+ }
209
+ else {
210
+ console.log(colors.error(' ✗') + colors.text(' ' + errLines[0]));
211
+ const rest = errLines.slice(1);
212
+ const maxW = Math.min(Math.max(...rest.map(l => l.length), 10) + 2, cols - 8);
213
+ console.log(chalk.hex('#450a0a')(' ╭' + '─'.repeat(maxW)));
214
+ for (const line of rest) {
215
+ const clipped = line.length > maxW - 2 ? line.slice(0, maxW - 3) + '…' : line;
216
+ console.log(chalk.hex('#450a0a')(' │') + ' ' + colors.error(clipped));
217
+ }
218
+ console.log(chalk.hex('#450a0a')(' ╰' + '─'.repeat(maxW)));
219
+ }
220
+ }
221
+ }
222
+ export function printError(msg) {
223
+ console.log('\n' + colors.error(' ✗ ') + colors.text(msg) + '\n');
224
+ }
225
+ export function printInfo(msg) {
226
+ console.log(colors.muted(' ' + msg));
227
+ }
228
+ export function printHelp() {
229
+ const C = colors.primary;
230
+ const DIM = colors.muted;
231
+ const W = colors.text;
232
+ const cols = process.stdout.columns ?? 80;
233
+ const line = DIM(' ' + '─'.repeat(Math.min(cols - 4, 60)));
234
+ console.log(`
235
+ ${colors.primary.bold(' Commands')}
236
+ ${line}
237
+ ${C('/files')} ${W('List project files and git status')}
238
+ ${C('/resume')} ${W('Resume a saved conversation')}
239
+ ${C('/retry')} ${W('Resend your last message')}
240
+ ${C('/copy')} ${W('Copy last AI response to clipboard')}
241
+ ${C('/model')} ${W('Show current AI model')}
242
+ ${C('/clear')} ${W('Clear screen')}
243
+ ${C('/whoami')} ${W('Show signed-in user')}
244
+ ${C('/logout')} ${W('Sign out from Dravix Code')}
245
+ ${C('/help')} ${W('Show this help')}
246
+ ${C('/exit')} ${W('Exit Dravix Code')}
247
+
248
+ ${colors.primary.bold(' Keyboard shortcuts')}
249
+ ${line}
250
+ ${C('Tab')} ${W('Path autocomplete')}
251
+ ${C('@')} ${W('File picker — attach file')}
252
+ ${C('$')} ${W('Run subagent')}
253
+ ${C('Ctrl+C')} ${W('Cancel AI response')}
254
+ ${C('Ctrl+L')} ${W('Clear screen')}
255
+ ${C('↑ ↓')} ${W('Navigate items')}
256
+ ${C('Esc')} ${W('Close picker')}
257
+
258
+ ${colors.primary.bold(' Tips')}
259
+ ${line}
260
+ ${colors.muted('·')} ${W('Start typing while AI responds — your message queues automatically')}
261
+ ${colors.muted('·')} ${W('Mention a filename to auto-inject its content')}
262
+ ${colors.muted('·')} ${W('Approve changes:')} ${C('y')} ${DIM('yes')} ${C('a')} ${DIM('always')} ${C('n')} ${DIM('no')}
263
+ ${colors.muted('·')} ${W('Use /resume to continue a previous conversation')}
264
+ `);
265
+ }
@@ -0,0 +1,17 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ export function readFile(filePath) {
4
+ try {
5
+ return fs.readFileSync(filePath, 'utf-8');
6
+ }
7
+ catch {
8
+ return null;
9
+ }
10
+ }
11
+ export function writeFile(filePath, content) {
12
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
13
+ fs.writeFileSync(filePath, content, 'utf-8');
14
+ }
15
+ export function fileExists(filePath) {
16
+ return fs.existsSync(filePath);
17
+ }
@@ -0,0 +1,82 @@
1
+ import chalk from 'chalk';
2
+ export class ChatLayout {
3
+ rows;
4
+ cols;
5
+ constructor() {
6
+ this.rows = process.stdout.rows ?? 24;
7
+ this.cols = process.stdout.columns ?? 80;
8
+ }
9
+ // Scroll region occupies rows 1 … scrollEnd
10
+ get scrollEnd() { return Math.max(this.rows - 3, 5); }
11
+ get divRow() { return this.rows - 2; } // ────── divider
12
+ get inputRow() { return this.rows - 1; } // › user input
13
+ get hintRow() { return this.rows; } // Tab / @ / … hints
14
+ makeSep() {
15
+ return chalk.hex('#374151')(' ' + '─'.repeat(Math.max(this.cols - 4, 40)));
16
+ }
17
+ /** Full-screen mode: hide everything outside the app */
18
+ enterFullScreen() {
19
+ this.rows = process.stdout.rows ?? 24;
20
+ this.cols = process.stdout.columns ?? 80;
21
+ // Clear entire screen first
22
+ process.stdout.write('\x1b[2J');
23
+ // Set scroll region to ENTIRE terminal (rows 1 to rows)
24
+ // This hides everything outside the app
25
+ process.stdout.write(`\x1b[1;${this.rows}r`);
26
+ // Move to top-left
27
+ process.stdout.write('\x1b[1;1H');
28
+ }
29
+ /** Call once at the start of startRepl — sets scroll region + draws divider. */
30
+ init() {
31
+ this.rows = process.stdout.rows ?? 24;
32
+ this.cols = process.stdout.columns ?? 80;
33
+ // Set scroll region for chat (excluding bottom 3 rows for divider/input/hints)
34
+ process.stdout.write(`\x1b[1;${this.scrollEnd}r`);
35
+ this.redrawDivider();
36
+ }
37
+ /** Redraw the divider line at divRow (outside the scroll region). */
38
+ redrawDivider() {
39
+ process.stdout.write(`\x1b[${this.divRow};1H\x1b[2K${this.makeSep()}`);
40
+ }
41
+ /** Place cursor at inputRow, optionally with text. */
42
+ posInput(prompt, text = '') {
43
+ process.stdout.write(`\x1b[${this.inputRow};1H\x1b[2K${prompt}${text}`);
44
+ }
45
+ /** Clear the input and hint rows. */
46
+ clearInput() {
47
+ process.stdout.write(`\x1b[${this.inputRow};1H\x1b[2K`);
48
+ process.stdout.write(`\x1b[${this.hintRow};1H\x1b[2K`);
49
+ }
50
+ /** Write hint text at hintRow without moving cursor. */
51
+ drawHint(hint) {
52
+ process.stdout.write('\x1b7');
53
+ process.stdout.write(`\x1b[${this.hintRow};1H\x1b[2K${hint}`);
54
+ process.stdout.write('\x1b8');
55
+ }
56
+ /** Move cursor to the bottom of the scroll region (ready for chat output). */
57
+ enterChat() {
58
+ process.stdout.write(`\x1b[${this.scrollEnd};1H`);
59
+ }
60
+ /** Handle terminal resize: recalculate dimensions and redraw fixed rows. */
61
+ resize() {
62
+ this.rows = process.stdout.rows ?? 24;
63
+ this.cols = process.stdout.columns ?? 80;
64
+ process.stdout.write(`\x1b[1;${this.scrollEnd}r`);
65
+ this.redrawDivider();
66
+ process.stdout.write(`\x1b[${this.inputRow};1H\x1b[2K`);
67
+ process.stdout.write(`\x1b[${this.hintRow};1H\x1b[2K`);
68
+ process.stdout.write(`\x1b[${this.inputRow};1H`);
69
+ }
70
+ /** Clear all chat lines in the scroll region. */
71
+ clearScrollRegion() {
72
+ for (let r = 1; r <= this.scrollEnd; r++) {
73
+ process.stdout.write(`\x1b[${r};1H\x1b[2K`);
74
+ }
75
+ process.stdout.write(`\x1b[1;1H`);
76
+ }
77
+ /** Reset scroll region and clean up on process exit. */
78
+ cleanup() {
79
+ process.stdout.write('\x1b[r');
80
+ process.stdout.write(`\x1b[${this.rows};1H\n`);
81
+ }
82
+ }
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@tensorspark/dravix-code",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.5.0",
4
+ "description": "AI-powered coding assistant CLI — Dravix Code",
5
+ "type": "module",
6
+ "bin": {
7
+ "dravix": "dist/cli/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "node node_modules/typescript/lib/tsc.js",
14
+ "start": "node dist/cli/index.js",
15
+ "dev": "node node_modules/typescript/lib/tsc.js --watch",
16
+ "prepublishOnly": "node node_modules/typescript/lib/tsc.js"
17
+ },
18
+ "dependencies": {
19
+ "chalk": "^5.3.0"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^20.0.0",
23
+ "typescript": "^5.4.0"
24
+ },
25
+ "keywords": [
26
+ "ai",
27
+ "cli",
28
+ "coding-assistant",
29
+ "dravix",
30
+ "tensorspark"
31
+ ],
32
+ "license": "MIT",
33
+ "homepage": "https://dravix.app",
34
+ "engines": {
35
+ "node": ">=18.0.0"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.