tokens-metric 0.4.0 → 0.4.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.
Files changed (2) hide show
  1. package/dist/tui/index.js +30 -0
  2. package/package.json +1 -1
package/dist/tui/index.js CHANGED
@@ -2,6 +2,8 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from 'react';
4
4
  import { render, Box, Text, useApp, useInput } from 'ink';
5
+ import { createInterface } from 'node:readline';
6
+ import { spawnSync } from 'node:child_process';
5
7
  import { findActiveTranscript, listTranscripts } from '../core/parser.js';
6
8
  import { tailTranscript } from '../core/tailer.js';
7
9
  import { detectAuth } from '../core/detect.js';
@@ -380,4 +382,32 @@ function timeAgo(ms) {
380
382
  return `${h}h`;
381
383
  return `${Math.floor(h / 24)}d`;
382
384
  }
385
+ // ── Pre-start update prompt ───────────────────────────────────────────────────
386
+ async function promptForUpdate() {
387
+ const latest = await checkForUpdate(pkg.version);
388
+ if (!latest || !process.stdin.isTTY)
389
+ return;
390
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
391
+ const answer = await new Promise((resolve) => {
392
+ rl.question(`\n⚡ tokens-metric v${latest} available (you have v${pkg.version})\n` +
393
+ ` Install now? [Y/n] `, (ans) => { rl.close(); resolve(ans); });
394
+ });
395
+ process.stdout.write('\n');
396
+ if (answer.trim().toLowerCase() !== 'n') {
397
+ process.stdout.write('Installing tokens-metric@latest…\n');
398
+ const result = spawnSync('npm', ['install', '-g', 'tokens-metric'], {
399
+ stdio: 'inherit',
400
+ shell: true,
401
+ });
402
+ if (result.status === 0) {
403
+ process.stdout.write(`\n✓ Updated to v${latest} — restarting…\n\n`);
404
+ spawnSync(process.execPath, process.argv.slice(1), { stdio: 'inherit', shell: false });
405
+ process.exit(0);
406
+ }
407
+ else {
408
+ process.stdout.write('\n✗ Install failed — starting current version anyway.\n\n');
409
+ }
410
+ }
411
+ }
412
+ await promptForUpdate();
383
413
  render(_jsx(App, {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokens-metric",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Real-time token usage meter for Claude Code — statusline + Ink TUI.",
5
5
  "type": "module",
6
6
  "bin": {