drafted 1.14.3 → 1.14.5

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/mcp/server.mjs +15 -8
  2. package/package.json +1 -1
package/mcp/server.mjs CHANGED
@@ -1524,10 +1524,13 @@ async function launchDesktopSignin() {
1524
1524
  if (!bin) return false;
1525
1525
  try {
1526
1526
  const { spawn } = await import('child_process');
1527
- // If the app is already running (macOS KeepAlive normally guarantees it), the single-instance
1528
- // handler opens the sign-in window and DRAFTED_OPEN_LOGIN is ignored. If it isn't running,
1529
- // the fresh primary instance honors DRAFTED_OPEN_LOGIN=1 and opens sign-in on boot.
1530
- const child = spawn(bin, [], {
1527
+ // If the app isn't running, the fresh primary instance honors DRAFTED_OPEN_LOGIN=1 (env var)
1528
+ // and opens sign-in on boot. If it's already running (the common case — macOS KeepAlive
1529
+ // normally guarantees it), tauri-plugin-single-instance forwards this launch's ARGV to the
1530
+ // running instance but never its env, so the env var alone would be silently dropped and the
1531
+ // already-running instance would just refocus its window without opening sign-in — pass
1532
+ // --open-login as an actual arg so that path honors the request too.
1533
+ const child = spawn(bin, ['--open-login'], {
1531
1534
  detached: true,
1532
1535
  stdio: 'ignore',
1533
1536
  env: { ...process.env, DRAFTED_OPEN_LOGIN: '1' },
@@ -1538,11 +1541,14 @@ async function launchDesktopSignin() {
1538
1541
  }
1539
1542
 
1540
1543
  // Poll auth.json (written by the desktop app's cookie->auth.json bridge on in-app sign-in)
1541
- // until a valid session id lands or the deadline passes.
1542
- async function waitForBootstrapAuth(deadline) {
1544
+ // until a NEW session id lands or the deadline passes. `staleSid` is whatever was already in
1545
+ // auth.json before sign-in was triggered — an expired bootstrap session from a prior install
1546
+ // (e.g. past its 30-day server-side TTL) sits in that file until it's replaced, so returning
1547
+ // on ANY sid would hand back the same dead value instead of waiting for a real re-auth.
1548
+ async function waitForBootstrapAuth(deadline, staleSid) {
1543
1549
  while (Date.now() < deadline) {
1544
1550
  const sid = getBootstrapSessionId();
1545
- if (sid) return sid;
1551
+ if (sid && sid !== staleSid) return sid;
1546
1552
  await new Promise(r => setTimeout(r, 1500));
1547
1553
  }
1548
1554
  return null;
@@ -1565,11 +1571,12 @@ if (!isRemote) tool('auth', 'Sign in to Drafted. On a local install the DESKTOP
1565
1571
  }
1566
1572
  } catch { /* stale session — continue to sign-in */ }
1567
1573
  }
1574
+ const staleSid = getBootstrapSessionId();
1568
1575
  if (await launchDesktopSignin()) {
1569
1576
  if (action === 'get_link') {
1570
1577
  return ok('Opening the Drafted app to sign in — approve in the app window, then retry your request.');
1571
1578
  }
1572
- const sid = await waitForBootstrapAuth(Date.now() + 180000);
1579
+ const sid = await waitForBootstrapAuth(Date.now() + 180000, staleSid);
1573
1580
  if (!sid) throw new Error('Timed out waiting for sign-in. Complete sign-in in the Drafted app window, then retry.');
1574
1581
  getState().sessionId = null;
1575
1582
  // cloneSession() can fail transiently right after the app plants the bootstrap
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drafted",
3
- "version": "1.14.3",
3
+ "version": "1.14.5",
4
4
  "description": "Drafted — visual thinking surface for humans and AI agents. Renders HTML, markdown, images, and code as frames on a zoomable canvas, with MCP tools for AI agents and real-time sync for humans.",
5
5
  "type": "module",
6
6
  "files": [