tokenrace 0.1.10 → 0.1.11

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/bin/cli.js +76 -2
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -2,8 +2,10 @@
2
2
  import { startServer } from '../src/server.js'
3
3
  import { ensureEnvVars } from '../src/ensure-env-vars.js'
4
4
  import open from 'open'
5
+ import { spawn } from 'node:child_process'
5
6
 
6
7
  const PORT = process.env.TOKENRACE_PORT ? Number(process.env.TOKENRACE_PORT) : 1337
8
+ const CWD = process.cwd()
7
9
 
8
10
  const { added, rcPath } = ensureEnvVars(PORT)
9
11
 
@@ -25,5 +27,77 @@ ${envStatus}
25
27
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
26
28
  `)
27
29
 
28
- // Abrir el browser (no bloqueante si falla, el servidor sigue corriendo)
29
- open(`http://localhost:${PORT}`).catch(() => {})
30
+ // Abrir el dashboard como ventana independiente (modo app sin barra de navegación)
31
+ openDashboard(PORT)
32
+
33
+ // Abrir una nueva ventana de terminal en el directorio donde se ejecutó npx
34
+ openTerminalHere(CWD)
35
+
36
+ // ─── helpers ────────────────────────────────────────────────────────────────
37
+
38
+ /**
39
+ * Abre el dashboard en modo app (sin barra de navegación ni pestañas).
40
+ * Intenta Chrome en macOS; si no está disponible usa el navegador por defecto.
41
+ */
42
+ function openDashboard(port) {
43
+ const url = `http://localhost:${port}`
44
+
45
+ if (process.platform === 'darwin') {
46
+ // macOS: intentar Chrome en modo app (ventana sin chrome de navegador)
47
+ const chrome = spawn(
48
+ 'open', ['-na', 'Google Chrome', '--args', `--app=${url}`, '--new-window'],
49
+ { detached: true, stdio: 'ignore' }
50
+ )
51
+ let fallbackDone = false
52
+ const fallback = () => {
53
+ if (fallbackDone) return
54
+ fallbackDone = true
55
+ // Chrome no disponible — abrir en nueva ventana del navegador por defecto
56
+ open(url, { newInstance: true }).catch(() => open(url).catch(() => {}))
57
+ }
58
+ chrome.on('close', (code) => { if (code !== 0) fallback() })
59
+ chrome.on('error', fallback)
60
+ chrome.unref()
61
+ } else {
62
+ open(url, { newInstance: true }).catch(() => open(url).catch(() => {}))
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Abre una nueva ventana de terminal en el directorio indicado.
68
+ * Compatible con macOS, Linux (varios emuladores) y Windows.
69
+ */
70
+ function openTerminalHere(dir) {
71
+ try {
72
+ if (process.platform === 'darwin') {
73
+ // macOS: abrir Terminal.app con cd al directorio de trabajo
74
+ // "quoted form of theDir" maneja espacios y caracteres especiales en el path
75
+ spawn('osascript', [
76
+ '-e', `set theDir to "${dir.replace(/\\/g, '/').replace(/"/g, '\\"')}"`,
77
+ '-e', `tell application "Terminal" to do script "cd " & quoted form of theDir`,
78
+ ], { detached: true, stdio: 'ignore' }).unref()
79
+
80
+ } else if (process.platform === 'linux') {
81
+ tryLinuxTerminal(dir, [
82
+ ['gnome-terminal', [`--working-directory=${dir}`]],
83
+ ['konsole', ['--workdir', dir]],
84
+ ['xfce4-terminal', [`--working-directory=${dir}`]],
85
+ ['xterm', ['-e', `bash -c "cd '${dir.replace(/'/g, "'\\''")}'; exec bash"`]],
86
+ ])
87
+
88
+ } else if (process.platform === 'win32') {
89
+ spawn('cmd', ['/c', 'start', 'cmd', '/K', `cd /d "${dir}"`],
90
+ { detached: true, stdio: 'ignore', shell: true }).unref()
91
+ }
92
+ } catch {
93
+ // silencioso — no bloquear el arranque si no se puede abrir la terminal
94
+ }
95
+ }
96
+
97
+ function tryLinuxTerminal(dir, emulators, i = 0) {
98
+ if (i >= emulators.length) return
99
+ const [cmd, args] = emulators[i]
100
+ const p = spawn(cmd, args, { detached: true, stdio: 'ignore' })
101
+ p.on('error', () => tryLinuxTerminal(dir, emulators, i + 1))
102
+ p.unref()
103
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenrace",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Monitor en tiempo real para Claude Code",
5
5
  "bin": {
6
6
  "tokenrace": "bin/cli.js"