@taj-special/dravix-code 1.1.2 → 1.1.4

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/index.js CHANGED
@@ -3,7 +3,7 @@ import * as path from 'path';
3
3
  import { randomBytes } from 'crypto';
4
4
  import { execSync } from 'child_process';
5
5
  import chalk from 'chalk';
6
- import { banner, printHelp, printError, colors, VERSION, PKG_VERSION } from '../utils/display.js';
6
+ import { banner, printHelp, printError, colors, VERSION } from '../utils/display.js';
7
7
  import { startRepl } from './repl.js';
8
8
  import { isLoggedIn, logout, getSavedUser, saveConfig, checkPlan, AUTH_URL } from '../services/auth.js';
9
9
  import { checkUsage, usageBar, fmtNum, formatResetTime } from '../services/usage.js';
@@ -184,23 +184,82 @@ async function browserAuth() {
184
184
  }, 300_000);
185
185
  });
186
186
  }
187
- async function checkVersion() {
187
+ async function checkForUpdate() {
188
188
  try {
189
189
  const res = await fetch('https://registry.npmjs.org/@taj-special/dravix-code/latest', {
190
190
  signal: AbortSignal.timeout(5000),
191
191
  });
192
192
  const data = await res.json();
193
193
  const latest = data.version ?? '';
194
- const current = PKG_VERSION;
195
- if (latest && latest !== current) {
196
- const DIM = chalk.hex('#4b5563');
197
- const W = chalk.hex('#e2e8f0');
198
- const Y = chalk.hex('#fcd34d');
199
- console.log('\n ' + Y('⚠') + ' ' + W.bold('New version available: ' + latest));
200
- console.log(' ' + DIM(' Run: npm install -g @taj-special/dravix-code') + '\n');
194
+ return (latest && latest !== VERSION) ? latest : '';
195
+ }
196
+ catch {
197
+ return '';
198
+ }
199
+ }
200
+ async function promptUpdate(latest) {
201
+ const Y = chalk.hex('#fcd34d');
202
+ const W = chalk.hex('#e2e8f0');
203
+ const DIM = chalk.hex('#4b5563');
204
+ const P = chalk.hex('#818cf8');
205
+ console.log('\n ' + Y('⬆') + ' ' + W.bold('Update available') + ' ' + DIM(`v${VERSION}`) + DIM(' → ') + P.bold(`v${latest}`));
206
+ console.log(' ' + DIM('─'.repeat(45)));
207
+ const enterKey = chalk.bgHex('#312e81').hex('#c7d2fe').bold(' Enter ');
208
+ const escKey = chalk.hex('#374151').bold(' Esc ');
209
+ console.log('\n ' + enterKey + W(' Update now and restart'));
210
+ console.log(' ' + escKey + colors.muted(' Skip for now') + '\n');
211
+ return new Promise((resolve) => {
212
+ process.stdin.setRawMode(true);
213
+ process.stdin.resume();
214
+ process.stdin.setEncoding('utf8');
215
+ function onKey(data) {
216
+ if (data === '\r' || data === '\n' || data === 'y' || data === 'Y') {
217
+ cleanup();
218
+ resolve(true);
219
+ }
220
+ else if (data === '\x1b' || data === '\x03' || data === 'n' || data === 'N') {
221
+ cleanup();
222
+ resolve(false);
223
+ }
201
224
  }
225
+ function cleanup() {
226
+ process.stdin.removeListener('data', onKey);
227
+ process.stdin.setRawMode(false);
228
+ process.stdin.pause();
229
+ }
230
+ process.stdin.on('data', onKey);
231
+ });
232
+ }
233
+ async function runUpdate() {
234
+ const W = chalk.hex('#e2e8f0');
235
+ const DIM = chalk.hex('#4b5563');
236
+ const G = chalk.hex('#34d399');
237
+ let frameIdx = 0;
238
+ let done = false;
239
+ const spinner = setInterval(() => {
240
+ if (done)
241
+ return;
242
+ process.stdout.write(`\r ${colors.muted(SPINNER[frameIdx % SPINNER.length])} ${colors.muted('Installing update...')}`);
243
+ frameIdx++;
244
+ }, 80);
245
+ try {
246
+ execSync('npm install -g @taj-special/dravix-code', { stdio: 'pipe' });
247
+ done = true;
248
+ clearInterval(spinner);
249
+ process.stdout.write('\r\x1b[K');
250
+ console.log(' ' + G('✓') + ' ' + W.bold('Updated successfully!'));
251
+ console.log(' ' + DIM('Run dravix again to start with the new version.') + '\n');
252
+ return true;
253
+ }
254
+ catch (e) {
255
+ done = true;
256
+ clearInterval(spinner);
257
+ process.stdout.write('\r\x1b[K');
258
+ const msg = e instanceof Error ? e.message.split('\n')[0] : String(e);
259
+ console.log(' ' + colors.error('✗') + ' ' + W('Update failed: ') + colors.muted(msg));
260
+ console.log(' ' + DIM('Run manually: npm install -g @taj-special/dravix-code') + '\n');
261
+ return false;
202
262
  }
203
- catch { /* ignore network errors */ }
204
263
  }
205
264
  async function main() {
206
265
  // Ensure UTF-8 output on Windows
@@ -211,8 +270,8 @@ async function main() {
211
270
  catch { }
212
271
  }
213
272
  const arg = process.argv[2];
214
- // Check for updates in background
215
- checkVersion().catch(() => { });
273
+ // Start version check in background immediately — result awaited after banner
274
+ const updatePromise = checkForUpdate();
216
275
  if (arg === '--help' || arg === '-h') {
217
276
  banner();
218
277
  printHelp();
@@ -238,6 +297,16 @@ async function main() {
238
297
  else {
239
298
  banner();
240
299
  }
300
+ // Check update result (network already in flight — usually instant by now)
301
+ const latestVersion = await updatePromise.catch(() => '');
302
+ if (latestVersion) {
303
+ const shouldUpdate = await promptUpdate(latestVersion);
304
+ if (shouldUpdate) {
305
+ const ok = await runUpdate();
306
+ if (ok)
307
+ process.exit(0);
308
+ }
309
+ }
241
310
  const { name, email } = getSavedUser();
242
311
  const cwd = (arg && !arg.startsWith('--')) ? path.resolve(arg) : process.cwd();
243
312
  // Fetch plan + usage in parallel
@@ -60,7 +60,7 @@ async function doSingleRequest(messages, token, abort, onChunk) {
60
60
  headers: {
61
61
  'Content-Type': 'application/json',
62
62
  'X-CLI-Token': token,
63
- 'X-CLI-Version': '1.1.0',
63
+ 'X-CLI-Version': '1.1.4',
64
64
  },
65
65
  body: JSON.stringify({
66
66
  provider: 'openrouter',
@@ -4,8 +4,7 @@ import { fileURLToPath } from 'url';
4
4
  import { dirname, join } from 'path';
5
5
  const _dir = dirname(fileURLToPath(import.meta.url));
6
6
  const _pkg = JSON.parse(readFileSync(join(_dir, '../../package.json'), 'utf-8'));
7
- export const VERSION = '1.0.0'; // user-facing version
8
- export const PKG_VERSION = _pkg.version; // internal npm version
7
+ export const VERSION = _pkg.version;
9
8
  export const colors = {
10
9
  primary: chalk.hex('#6366f1'),
11
10
  success: chalk.hex('#34d399'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taj-special/dravix-code",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "AI-powered coding assistant CLI — Dravix Code",
5
5
  "type": "module",
6
6
  "bin": {