ninja-terminals 2.1.1 → 2.1.2

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 (3) hide show
  1. package/package.json +1 -1
  2. package/public/app.js +2 -2
  3. package/server.js +23 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ninja-terminals",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "Multi-terminal Claude Code orchestrator with DAG task management, permission hooks, and resilience",
5
5
  "main": "server.js",
6
6
  "bin": {
package/public/app.js CHANGED
@@ -347,7 +347,7 @@ function createTerminalUI(termData) {
347
347
  closeBtn.addEventListener('mousedown', (e) => {
348
348
  e.preventDefault();
349
349
  e.stopPropagation();
350
- removeTerminal(id);
350
+ closeTerminal(id);
351
351
  });
352
352
 
353
353
  header.appendChild(labelEl);
@@ -1108,7 +1108,7 @@ async function clearAllTerminals() {
1108
1108
 
1109
1109
  const ids = Array.from(state.terminals.keys());
1110
1110
  for (const id of ids) {
1111
- await removeTerminal(id);
1111
+ await closeTerminal(id);
1112
1112
  }
1113
1113
  addFeedEntry('All terminals cleared');
1114
1114
  }
package/server.js CHANGED
@@ -346,14 +346,30 @@ app.get('/health', (_req, res) => {
346
346
 
347
347
  // ── Session Endpoints ───────────────────────────────────────
348
348
 
349
- // Create session — validates token and spawns terminals
349
+ // Create session — validates token and returns existing or spawns terminals
350
350
  app.post('/api/session', requireAuth, (req, res) => {
351
351
  try {
352
352
  const { tier, terminalsMax, features, token } = req.ninjaUser;
353
353
 
354
- // Clear any existing session
354
+ // If session already exists with same token, return existing terminals
355
+ if (activeSession && activeSession.token === token) {
356
+ const existingTerminals = activeSession.terminalIds
357
+ .map(id => terminals.get(id))
358
+ .filter(Boolean)
359
+ .map(t => ({ id: t.id, label: t.label, status: t.status, cwd: t.cwd }));
360
+
361
+ console.log(`[session] Returning existing session: tier=${tier}, terminals=${existingTerminals.length}`);
362
+
363
+ return res.json({
364
+ tier,
365
+ terminalsMax,
366
+ features,
367
+ terminals: existingTerminals,
368
+ });
369
+ }
370
+
371
+ // Clear any existing session with different token
355
372
  if (activeSession) {
356
- // Kill existing terminals
357
373
  for (const id of activeSession.terminalIds) {
358
374
  const terminal = terminals.get(id);
359
375
  if (terminal) {
@@ -364,7 +380,7 @@ app.post('/api/session', requireAuth, (req, res) => {
364
380
  }
365
381
  }
366
382
 
367
- // Create new session
383
+ // Create new session (but don't auto-spawn terminals - let user add them)
368
384
  activeSession = {
369
385
  token,
370
386
  tier,
@@ -374,28 +390,14 @@ app.post('/api/session', requireAuth, (req, res) => {
374
390
  createdAt: Date.now(),
375
391
  };
376
392
 
377
- // Spawn terminals up to the tier limit
378
- const cwd = req.body?.cwd || DEFAULT_CWD;
379
- const spawnedTerminals = [];
380
-
381
- for (let i = 0; i < terminalsMax; i++) {
382
- const terminal = spawnTerminal(`T${i + 1}`, [], cwd, tier);
383
- activeSession.terminalIds.push(terminal.id);
384
- spawnedTerminals.push({
385
- id: terminal.id,
386
- label: terminal.label,
387
- status: terminal.status,
388
- cwd: terminal.cwd,
389
- });
390
- }
391
-
392
- console.log(`[session] Created session: tier=${tier}, terminals=${terminalsMax}`);
393
+ console.log(`[session] Created new session: tier=${tier}, terminalsMax=${terminalsMax}`);
393
394
 
395
+ // Return empty terminals - user can add via + button
394
396
  res.json({
395
397
  tier,
396
398
  terminalsMax,
397
399
  features,
398
- terminals: spawnedTerminals,
400
+ terminals: [],
399
401
  });
400
402
  } catch (err) {
401
403
  res.status(500).json({ error: 'Failed to create session', detail: err.message });