rechrome 1.9.2 → 1.10.1

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/rech.js +20 -8
  3. package/rech.ts +20 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rechrome",
3
- "version": "1.9.2",
3
+ "version": "1.10.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/snomiao/rechrome.git"
package/rech.js CHANGED
@@ -11,8 +11,8 @@ export const DEFAULT_PORT = 13775;
11
11
  export const RECH_DIR = join(import.meta.dir, ".rech");
12
12
  export const LOG_DIR = join(RECH_DIR, "logs");
13
13
 
14
- const RECH_HOME_DIR = join(process.env.HOME!, ".rech");
15
- const TOKENS_FILE = join(RECH_HOME_DIR, "tokens.json");
14
+ const RECH_HOME_DIR = join(process.env.HOME!, ".rechrome");
15
+ const TOKENS_FILE = join(RECH_HOME_DIR, "profiles.json");
16
16
 
17
17
  type TokenEntry = { extensionId: string; token: string; profileDir: string; userDataDir?: string };
18
18
 
@@ -557,7 +557,6 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
557
557
  }).catch(() => null) : null;
558
558
  if (anonPing && authPing?.ok) {
559
559
  console.log(` Already running at ${protocol}://${host}:${port} — skipping reinstall`);
560
- await runOxmgr(["service", "install"]);
561
560
  } else if (anonPing && !authPing?.ok) {
562
561
  console.log(` Server running but key mismatch — reinstalling with new key`);
563
562
  await daemonInstall(url);
@@ -608,7 +607,7 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
608
607
  return available[idx];
609
608
  }
610
609
 
611
- async function getExtAndToken(profileDir: string, profileDisplay: string): Promise<{ extId: string; token: string } | null> {
610
+ async function getExtAndToken(profileDir: string, profileDisplay: string, profileKey: string): Promise<{ extId: string; token: string } | null> {
612
611
  // Extension check
613
612
  let extId: string | undefined;
614
613
  while (true) {
@@ -625,6 +624,19 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
625
624
  }
626
625
  console.log(` Extension found: ${extId}`);
627
626
 
627
+ // Check for existing token in registry
628
+ const registry = await readTokenRegistry();
629
+ const existing = registry[profileKey];
630
+ if (existing && existing.extensionId === extId && existing.token) {
631
+ console.log(` Existing token found: ${existing.token.slice(0, 6)}…`);
632
+ if (!isTTY) console.log(` [agent] Provide y to keep existing token, n to refresh on next stdin line`);
633
+ const keep = (await ask(" Keep existing token? [Y/n]: ")).trim().toLowerCase();
634
+ if (keep !== "n") {
635
+ console.log(" Keeping existing token");
636
+ return { extId, token: existing.token };
637
+ }
638
+ }
639
+
628
640
  // Token
629
641
  const statusUrl = `chrome-extension://${extId}/status.html`;
630
642
  console.log(`\n Get auth token from the extension:`);
@@ -658,10 +670,10 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
658
670
 
659
671
  // [3+4/4] Extension + token for primary profile
660
672
  console.log("\n[3/4] Checking extension...");
661
- const primary = await getExtAndToken(profileDir, profileDisplay);
673
+ const profileEmail = profileInfoSel.user_name || profileDir;
674
+ const primary = await getExtAndToken(profileDir, profileDisplay, profileEmail);
662
675
  if (!primary) { rl?.close(); process.exit(1); }
663
676
  const { extId, token } = primary;
664
- const profileEmail = profileInfoSel.user_name || profileDir;
665
677
 
666
678
  // Build RECHROME_URL and show it before asking where to save
667
679
  const rechUrl = new URL(url);
@@ -708,10 +720,10 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
708
720
  if (!extra) { console.log(" Skipped."); continue; }
709
721
  const [extraDir, extraInfo] = extra;
710
722
  const extraDisplay = extraInfo.user_name || extraInfo.name || extraDir;
723
+ const extraEmail = extraInfo.user_name || extraDir;
711
724
  console.log(`\n Setting up: ${extraDisplay}`);
712
- const result = await getExtAndToken(extraDir, extraDisplay);
725
+ const result = await getExtAndToken(extraDir, extraDisplay, extraEmail);
713
726
  if (!result) { console.log(" Skipped."); continue; }
714
- const extraEmail = extraInfo.user_name || extraDir;
715
727
  await saveTokenEntry(extraEmail, { extensionId: result.extId, token: result.token, profileDir: extraDir, userDataDir: userDataDir ?? undefined });
716
728
  configured.add(extraDir);
717
729
  console.log(` Saved token for ${extraDisplay}`);
package/rech.ts CHANGED
@@ -11,8 +11,8 @@ export const DEFAULT_PORT = 13775;
11
11
  export const RECH_DIR = join(import.meta.dir, ".rech");
12
12
  export const LOG_DIR = join(RECH_DIR, "logs");
13
13
 
14
- const RECH_HOME_DIR = join(process.env.HOME!, ".rech");
15
- const TOKENS_FILE = join(RECH_HOME_DIR, "tokens.json");
14
+ const RECH_HOME_DIR = join(process.env.HOME!, ".rechrome");
15
+ const TOKENS_FILE = join(RECH_HOME_DIR, "profiles.json");
16
16
 
17
17
  type TokenEntry = { extensionId: string; token: string; profileDir: string; userDataDir?: string };
18
18
 
@@ -557,7 +557,6 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
557
557
  }).catch(() => null) : null;
558
558
  if (anonPing && authPing?.ok) {
559
559
  console.log(` Already running at ${protocol}://${host}:${port} — skipping reinstall`);
560
- await runOxmgr(["service", "install"]);
561
560
  } else if (anonPing && !authPing?.ok) {
562
561
  console.log(` Server running but key mismatch — reinstalling with new key`);
563
562
  await daemonInstall(url);
@@ -608,7 +607,7 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
608
607
  return available[idx];
609
608
  }
610
609
 
611
- async function getExtAndToken(profileDir: string, profileDisplay: string): Promise<{ extId: string; token: string } | null> {
610
+ async function getExtAndToken(profileDir: string, profileDisplay: string, profileKey: string): Promise<{ extId: string; token: string } | null> {
612
611
  // Extension check
613
612
  let extId: string | undefined;
614
613
  while (true) {
@@ -625,6 +624,19 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
625
624
  }
626
625
  console.log(` Extension found: ${extId}`);
627
626
 
627
+ // Check for existing token in registry
628
+ const registry = await readTokenRegistry();
629
+ const existing = registry[profileKey];
630
+ if (existing && existing.extensionId === extId && existing.token) {
631
+ console.log(` Existing token found: ${existing.token.slice(0, 6)}…`);
632
+ if (!isTTY) console.log(` [agent] Provide y to keep existing token, n to refresh on next stdin line`);
633
+ const keep = (await ask(" Keep existing token? [Y/n]: ")).trim().toLowerCase();
634
+ if (keep !== "n") {
635
+ console.log(" Keeping existing token");
636
+ return { extId, token: existing.token };
637
+ }
638
+ }
639
+
628
640
  // Token
629
641
  const statusUrl = `chrome-extension://${extId}/status.html`;
630
642
  console.log(`\n Get auth token from the extension:`);
@@ -658,10 +670,10 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
658
670
 
659
671
  // [3+4/4] Extension + token for primary profile
660
672
  console.log("\n[3/4] Checking extension...");
661
- const primary = await getExtAndToken(profileDir, profileDisplay);
673
+ const profileEmail = profileInfoSel.user_name || profileDir;
674
+ const primary = await getExtAndToken(profileDir, profileDisplay, profileEmail);
662
675
  if (!primary) { rl?.close(); process.exit(1); }
663
676
  const { extId, token } = primary;
664
- const profileEmail = profileInfoSel.user_name || profileDir;
665
677
 
666
678
  // Build RECHROME_URL and show it before asking where to save
667
679
  const rechUrl = new URL(url);
@@ -708,10 +720,10 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
708
720
  if (!extra) { console.log(" Skipped."); continue; }
709
721
  const [extraDir, extraInfo] = extra;
710
722
  const extraDisplay = extraInfo.user_name || extraInfo.name || extraDir;
723
+ const extraEmail = extraInfo.user_name || extraDir;
711
724
  console.log(`\n Setting up: ${extraDisplay}`);
712
- const result = await getExtAndToken(extraDir, extraDisplay);
725
+ const result = await getExtAndToken(extraDir, extraDisplay, extraEmail);
713
726
  if (!result) { console.log(" Skipped."); continue; }
714
- const extraEmail = extraInfo.user_name || extraDir;
715
727
  await saveTokenEntry(extraEmail, { extensionId: result.extId, token: result.token, profileDir: extraDir, userDataDir: userDataDir ?? undefined });
716
728
  configured.add(extraDir);
717
729
  console.log(` Saved token for ${extraDisplay}`);