ninja-terminals 2.4.5 → 2.4.6

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/cli.js +11 -35
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -225,6 +225,14 @@ process.env.HTTP_PORT = String(port);
225
225
  process.env.DEFAULT_TERMINALS = String(terminals);
226
226
  process.env.DEFAULT_CWD = cwd;
227
227
 
228
+ // Single browser-open path: server.js opens the tab in its listen callback
229
+ // (knows the actual selected port, uses 127.0.0.1). Enable it by default for
230
+ // CLI launches; opt out with --no-open. This replaces cli.js's own opener,
231
+ // which previously fired a second, redundant tab.
232
+ if (!hasFlag('--no-open') && !process.env.NINJA_OPEN_BROWSER) {
233
+ process.env.NINJA_OPEN_BROWSER = '1';
234
+ }
235
+
228
236
  // Auth env vars
229
237
  if (token) {
230
238
  process.env.NINJA_AUTH_TOKEN = token;
@@ -233,41 +241,9 @@ if (offline) {
233
241
  process.env.NINJA_OFFLINE = '1';
234
242
  }
235
243
 
236
- // ── Auto-open browser ────────────────────────────────────────
237
-
238
- function openBrowser(url) {
239
- const { spawn } = require('child_process');
240
- const platform = process.platform;
241
- let cmd, cmdArgs;
242
-
243
- if (platform === 'darwin') {
244
- cmd = 'open';
245
- cmdArgs = [url];
246
- } else if (platform === 'win32') {
247
- cmd = 'cmd';
248
- cmdArgs = ['/c', 'start', url];
249
- } else {
250
- cmd = 'xdg-open';
251
- cmdArgs = [url];
252
- }
253
-
254
- spawn(cmd, cmdArgs, { stdio: 'ignore', detached: true }).unref();
255
- }
256
-
257
- // Delay browser open until after the server listen callback fires.
258
- // server.js calls server.listen() synchronously on require, so we
259
- // schedule the open after the current tick stack clears. Read the actual
260
- // selected port from the session file — the server may have rolled to a
261
- // different port if the preferred one was occupied (on either IP stack).
262
- setTimeout(() => {
263
- let openPort = port;
264
- try {
265
- const sessionPath = require('path').join(require('os').homedir(), '.ninja', 'session.json');
266
- const s = JSON.parse(require('fs').readFileSync(sessionPath, 'utf8'));
267
- if (s && s.port) openPort = s.port;
268
- } catch { /* fall back to requested port */ }
269
- openBrowser(`http://127.0.0.1:${openPort}`);
270
- }, 1500);
244
+ // Browser auto-open is handled by server.js's listen callback (single path,
245
+ // gated by NINJA_OPEN_BROWSER which we set above). cli.js no longer opens its
246
+ // own tab — that produced a duplicate.
271
247
 
272
248
  // ── Start the server ─────────────────────────────────────────
273
249
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ninja-terminals",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "description": "MCP server for multi-terminal Claude Code orchestration with DAG task management, parallel execution, and self-improvement",
5
5
  "main": "server.js",
6
6
  "bin": {