@tostudy-ai/cli 0.18.22 → 0.18.23

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.
package/dist/main.js CHANGED
@@ -1325,11 +1325,27 @@ import path2 from "node:path";
1325
1325
  import { chmod, readFile, rm, writeFile } from "node:fs/promises";
1326
1326
  import { execFile } from "node:child_process";
1327
1327
  import { promisify } from "node:util";
1328
- function fileBelongsTo(secrets, owner) {
1328
+ function identityOf(secrets) {
1329
+ if (secrets.userId) return { userId: secrets.userId, sessionId: secrets.sessionId };
1330
+ try {
1331
+ const claims = JSON.parse(
1332
+ Buffer.from(secrets.accessToken.split(".")[1] ?? "", "base64url").toString("utf-8")
1333
+ );
1334
+ if (typeof claims.userId !== "string") return null;
1335
+ return {
1336
+ userId: claims.userId,
1337
+ ...typeof claims.sid === "string" ? { sessionId: claims.sid } : {}
1338
+ };
1339
+ } catch {
1340
+ return null;
1341
+ }
1342
+ }
1343
+ function belongsTo(secrets, owner) {
1329
1344
  if (!owner) return true;
1330
- if (!secrets.userId) return false;
1331
- if (secrets.userId !== owner.userId) return false;
1332
- if (secrets.sessionId && owner.sessionId && secrets.sessionId !== owner.sessionId) return false;
1345
+ const identity = identityOf(secrets);
1346
+ if (!identity) return null;
1347
+ if (identity.userId !== owner.userId) return false;
1348
+ if (identity.sessionId && owner.sessionId && identity.sessionId !== owner.sessionId) return false;
1333
1349
  return true;
1334
1350
  }
1335
1351
  function getStoreKey(configDir) {
@@ -1413,10 +1429,9 @@ async function loadStoredSessionSecrets(configDir, owner) {
1413
1429
  let legacyFile = null;
1414
1430
  try {
1415
1431
  const fromFile = await loadFallback(configDir);
1416
- if (fromFile && fileBelongsTo(fromFile, owner)) {
1417
- return fromFile;
1418
- }
1419
- if (fromFile && !fromFile.userId) legacyFile = fromFile;
1432
+ const verdict = fromFile && belongsTo(fromFile, owner);
1433
+ if (fromFile && verdict === true) return fromFile;
1434
+ if (fromFile && verdict === null) legacyFile = fromFile;
1420
1435
  } catch {
1421
1436
  }
1422
1437
  try {
@@ -1428,7 +1443,8 @@ async function loadStoredSessionSecrets(configDir, owner) {
1428
1443
  account,
1429
1444
  "-w"
1430
1445
  ]);
1431
- return JSON.parse(stdout2.trim());
1446
+ const fromKeychain = JSON.parse(stdout2.trim());
1447
+ return belongsTo(fromKeychain, owner) === false ? legacyFile : fromKeychain;
1432
1448
  } catch {
1433
1449
  return legacyFile;
1434
1450
  }
@@ -3790,7 +3806,7 @@ import { spawn } from "node:child_process";
3790
3806
  import { hostname } from "node:os";
3791
3807
 
3792
3808
  // src/version.ts
3793
- var CLI_VERSION = true ? "0.18.22" : "0.7.1";
3809
+ var CLI_VERSION = true ? "0.18.23" : "0.7.1";
3794
3810
 
3795
3811
  // src/installer/mcp-setup.ts
3796
3812
  function safeServerError(text2) {