@tensorspark/dravix-code 0.0.0-stage → 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.
@@ -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,236 @@
1
+ import chalk from 'chalk';
2
+ import { colors, clipVis, padVis, visWidth } from './display.js';
3
+ import { fmtNum } from '../services/usage.js';
4
+ import { basename } from 'path';
5
+ export class ChatLayout {
6
+ rows;
7
+ cols;
8
+ chatRow = 1;
9
+ didCleanup = false;
10
+ constructor() {
11
+ this.rows = process.stdout.rows ?? 24;
12
+ this.cols = process.stdout.columns ?? 80;
13
+ }
14
+ refreshSize() {
15
+ this.rows = process.stdout.rows ?? 24;
16
+ this.cols = process.stdout.columns ?? 80;
17
+ }
18
+ /** Bottom 4 rows: top border, input line, bottom border, status bar (3 rows on tiny terminals). */
19
+ get bottomHeight() {
20
+ return this.rows >= 14 ? 4 : 3;
21
+ }
22
+ // Scroll region occupies rows 1 … scrollEnd
23
+ get scrollEnd() { return Math.max(this.rows - this.bottomHeight, 4); }
24
+ get topBorderRow() { return this.rows - this.bottomHeight + 1; }
25
+ get inputRow() { return this.rows - this.bottomHeight + 2; }
26
+ get botBorderRow() { return this.bottomHeight >= 4 ? this.rows - 1 : 0; }
27
+ get statusRow() { return this.rows; }
28
+ /** Compatibility getters */
29
+ get divRow() { return this.topBorderRow; }
30
+ get hintRow() { return this.statusRow; }
31
+ get boxOuterW() {
32
+ return Math.max(this.cols - 4, 24);
33
+ }
34
+ /** Inner editable width (between " │ › " and " │") */
35
+ get innerTextWidth() {
36
+ return Math.max(this.boxOuterW - 8, 10);
37
+ }
38
+ /** Full-screen setup at app launch */
39
+ enterFullScreen() {
40
+ this.refreshSize();
41
+ process.stdout.write('\x1b[2J\x1b[3J');
42
+ process.stdout.write(`\x1b[1;${this.scrollEnd}r`);
43
+ process.stdout.write('\x1b[1;1H');
44
+ this.chatRow = 1;
45
+ }
46
+ /** Set DECSTBM scroll region and draw the bottom composer frame. */
47
+ init(opts) {
48
+ this.refreshSize();
49
+ this.drawComposer({ focused: false, focusCursor: false, ...opts });
50
+ }
51
+ /** Capture current terminal cursor row (when stdin is in raw mode and cursor is in scroll region). */
52
+ async captureChatRow() {
53
+ if (!process.stdin.isTTY || !process.stdin.isRaw)
54
+ return;
55
+ await new Promise((resolve) => {
56
+ let done = false;
57
+ const timer = setTimeout(() => {
58
+ if (!done) {
59
+ done = true;
60
+ process.stdin.removeListener('data', onDsr);
61
+ resolve();
62
+ }
63
+ }, 35);
64
+ const onDsr = (chunk) => {
65
+ const m = chunk.match(/\x1b\[(\d+);(\d+)R/);
66
+ if (m) {
67
+ const r = parseInt(m[1], 10);
68
+ if (r >= 1 && r <= this.scrollEnd) {
69
+ this.chatRow = r;
70
+ }
71
+ if (!done) {
72
+ done = true;
73
+ clearTimeout(timer);
74
+ process.stdin.removeListener('data', onDsr);
75
+ resolve();
76
+ }
77
+ }
78
+ };
79
+ process.stdin.on('data', onDsr);
80
+ process.stdout.write('\x1b[6n');
81
+ });
82
+ }
83
+ /** Move cursor back to the active chat line inside the scroll region. */
84
+ enterChat() {
85
+ const r = Math.max(1, Math.min(this.chatRow, this.scrollEnd));
86
+ process.stdout.write(`\x1b[${r};1H`);
87
+ }
88
+ /** Update scroll region without wiping chat, redraw composer. */
89
+ resize(opts) {
90
+ this.refreshSize();
91
+ process.stdout.write(`\x1b[1;${this.scrollEnd}r`);
92
+ if (opts?.focusCursor === false) {
93
+ const targetRow = Math.max(1, Math.min(this.chatRow, this.scrollEnd));
94
+ process.stdout.write(`\x1b[${targetRow};1H`);
95
+ }
96
+ this.drawComposer(opts);
97
+ }
98
+ /** Draw the framed composer box + status bar at the bottom rows. */
99
+ drawComposer(opts = {}) {
100
+ this.refreshSize();
101
+ const focused = opts.focused ?? true;
102
+ const streaming = opts.streaming ?? false;
103
+ const focusCursor = opts.focusCursor ?? focused;
104
+ const boxW = this.boxOuterW;
105
+ const innerW = this.innerTextWidth;
106
+ const borderPaint = streaming
107
+ ? chalk.hex('#4c1d95')
108
+ : focused
109
+ ? colors.brand
110
+ : colors.dim;
111
+ const topLeftBadge = streaming
112
+ ? borderPaint('╭─ ') + colors.accent('● streaming') + borderPaint(' ')
113
+ : borderPaint('╭');
114
+ const topLeftVis = visWidth(topLeftBadge);
115
+ const topFill = Math.max(boxW - topLeftVis - 3, 1);
116
+ const topLine = ' ' + topLeftBadge + borderPaint('─'.repeat(topFill) + '╮');
117
+ const promptSym = streaming
118
+ ? colors.muted('›')
119
+ : focused
120
+ ? colors.primary.bold('›')
121
+ : colors.muted('›');
122
+ const leftMark = opts.leftOverflow ? colors.primary('‹') : ' ';
123
+ const rightMark = opts.rightOverflow ? colors.primary('›') : ' ';
124
+ const rawText = opts.displayText ?? '';
125
+ let bodyContent;
126
+ if (rawText.length > 0) {
127
+ bodyContent = padVis(rawText, innerW);
128
+ }
129
+ else if (opts.placeholder) {
130
+ bodyContent = padVis(colors.muted(clipVis(opts.placeholder, innerW)), innerW);
131
+ }
132
+ else {
133
+ bodyContent = ' '.repeat(innerW);
134
+ }
135
+ const inputLine = ' ' + borderPaint('│') + ' ' + promptSym + leftMark + bodyContent + rightMark + borderPaint('│');
136
+ const botLine = ' ' + borderPaint('╰' + '─'.repeat(Math.max(boxW - 4, 1)) + '╯');
137
+ // Status / hints bar on the bottom row
138
+ let statusLine = '';
139
+ if (opts.notice) {
140
+ statusLine = ' ' + colors.warn(clipVis(opts.notice, Math.max(this.cols - 6, 16)));
141
+ }
142
+ else {
143
+ const leftParts = [];
144
+ if (opts.cwd) {
145
+ leftParts.push(colors.subtext(basename(opts.cwd) || opts.cwd));
146
+ }
147
+ if (opts.meta?.plan) {
148
+ leftParts.push(opts.meta.plan === 'Plus'
149
+ ? colors.accent('Plus')
150
+ : colors.muted('Free'));
151
+ }
152
+ if (opts.meta?.usage) {
153
+ const u = opts.meta.usage;
154
+ leftParts.push(colors.muted(`${fmtNum(u.tokens_used)}/${fmtNum(u.limit)}`));
155
+ }
156
+ const leftStr = leftParts.join(colors.dim(' · '));
157
+ const rightStr = streaming
158
+ ? colors.muted('Ctrl+C') + colors.dim(' cancel')
159
+ : colors.muted('@') + colors.dim(' file ') +
160
+ colors.muted('/') + colors.dim(' cmd ') +
161
+ colors.muted('Tab') + colors.dim(' path ') +
162
+ colors.muted('↑↓') + colors.dim(' history');
163
+ const avail = Math.max(this.cols - 8, 20);
164
+ const lw = visWidth(leftStr);
165
+ const rw = visWidth(rightStr);
166
+ if (lw + rw + 4 <= avail) {
167
+ const gap = ' '.repeat(avail - lw - rw);
168
+ statusLine = ' ' + leftStr + gap + rightStr;
169
+ }
170
+ else if (rw <= avail) {
171
+ statusLine = ' ' + rightStr;
172
+ }
173
+ else {
174
+ statusLine = ' ' + colors.dim('@ file · / cmd · Tab path');
175
+ }
176
+ }
177
+ if (!focusCursor) {
178
+ process.stdout.write('\x1b7');
179
+ }
180
+ process.stdout.write(`\x1b[${this.topBorderRow};1H\x1b[2K${topLine}`);
181
+ process.stdout.write(`\x1b[${this.inputRow};1H\x1b[2K${inputLine}`);
182
+ if (this.botBorderRow > 0) {
183
+ process.stdout.write(`\x1b[${this.botBorderRow};1H\x1b[2K${botLine}`);
184
+ }
185
+ process.stdout.write(`\x1b[${this.statusRow};1H\x1b[2K${statusLine}`);
186
+ if (focusCursor) {
187
+ // " │ › " = 6 columns (1-indexed col 7 is text start)
188
+ const colOffset = Math.max(0, Math.min(opts.cursorOffset ?? 0, innerW));
189
+ process.stdout.write(`\x1b[${this.inputRow};${7 + colOffset}H`);
190
+ }
191
+ else {
192
+ process.stdout.write('\x1b8');
193
+ }
194
+ }
195
+ /** Clear input & status rows (e.g., when preparing to exit). */
196
+ clearBottom() {
197
+ this.refreshSize();
198
+ for (let r = this.topBorderRow; r <= this.rows; r++) {
199
+ process.stdout.write(`\x1b[${r};1H\x1b[2K`);
200
+ }
201
+ }
202
+ /** Clear only chat rows (1 .. scrollEnd), keeping the bottom composer intact. */
203
+ clearChat(opts) {
204
+ this.refreshSize();
205
+ process.stdout.write(`\x1b[1;${this.scrollEnd}r`);
206
+ for (let r = 1; r <= this.scrollEnd; r++) {
207
+ process.stdout.write(`\x1b[${r};1H\x1b[2K`);
208
+ }
209
+ this.chatRow = 1;
210
+ this.drawComposer({ focused: false, focusCursor: false, ...opts });
211
+ process.stdout.write('\x1b[1;1H');
212
+ }
213
+ /** Reset scroll region and leave terminal clean on exit while preserving chat history. */
214
+ cleanup(preserveChat = true, atChatCursor = false) {
215
+ if (this.didCleanup)
216
+ return;
217
+ this.didCleanup = true;
218
+ this.refreshSize();
219
+ if (preserveChat) {
220
+ if (atChatCursor)
221
+ process.stdout.write('\x1b7');
222
+ process.stdout.write('\x1b[r');
223
+ this.clearBottom();
224
+ if (atChatCursor) {
225
+ process.stdout.write('\x1b8');
226
+ }
227
+ else {
228
+ this.enterChat();
229
+ }
230
+ }
231
+ else {
232
+ process.stdout.write('\x1b[r');
233
+ process.stdout.write('\x1b[2J\x1b[1;1H');
234
+ }
235
+ }
236
+ }
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.1",
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.