@echomem/mcp 1.4.64 → 1.4.66

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.
@@ -110,7 +110,6 @@ export const SETUP_PAGE_STYLES_MVP = String.raw `
110
110
  .mvpConsent { display: grid; width: min(720px, 100%); gap: 18px; color: var(--echo-ink-text); text-align: center; }
111
111
  .mvpConsentHero { display: flex; flex-direction: column; align-items: center; gap: 12px; }
112
112
  .mvpConsentPitch { min-width: 0; }
113
- .mvpConsentEcho { width: 86px; height: auto; flex: 0 0 auto; margin: 0; filter: drop-shadow(0 12px 18px rgba(26,58,143,0.16)); }
114
113
  .mvpKicker {
115
114
  margin: 0;
116
115
  color: var(--echo-ink-seal);
@@ -513,7 +512,7 @@ export const SETUP_PAGE_STYLES_MVP = String.raw `
513
512
  font-weight: 750;
514
513
  }
515
514
 
516
- /* Pricing copied from the public Echo habitat -------------------------- */
515
+ /* Plan gate ----------------------------------------------------------- */
517
516
  .planGateStage {
518
517
  display: flex !important;
519
518
  flex-direction: column;
@@ -618,236 +617,6 @@ export const SETUP_PAGE_STYLES_MVP = String.raw `
618
617
  font-size: 15px;
619
618
  }
620
619
  .mvpPricingDiscovery strong { color: var(--echo-ink-primary); }
621
- .mvpPlanTabs {
622
- display: grid;
623
- grid-template-columns: repeat(3, minmax(0, 1fr));
624
- width: min(640px, 100%);
625
- margin: 0 auto 30px;
626
- padding: 6px;
627
- border: 1px solid rgba(26,58,143,0.18);
628
- border-radius: 999px;
629
- background: rgba(255,255,255,0.75);
630
- box-shadow: 0 9px 25px rgba(34,45,74,0.08);
631
- }
632
- .mvpPlanTab {
633
- display: flex;
634
- min-height: 48px;
635
- padding: 0 18px;
636
- align-items: center;
637
- justify-content: center;
638
- gap: 9px;
639
- border: 0;
640
- border-radius: 999px;
641
- background: transparent;
642
- box-shadow: none;
643
- color: var(--echo-ink-mute);
644
- cursor: pointer;
645
- font: 650 16px/1 var(--echo-font-body);
646
- }
647
- .mvpPlanTab b {
648
- font: 650 12px/1 var(--echo-font-mono);
649
- opacity: 0.66;
650
- }
651
- .mvpPlanTab[aria-selected="true"] {
652
- background: white;
653
- color: var(--echo-ink-primary);
654
- box-shadow: 0 5px 14px rgba(31,61,132,0.13);
655
- transform: translateY(-1px);
656
- }
657
- .mvpPlanHabitat {
658
- --habitat-bg: #fff7e6;
659
- --habitat-sky: #ddf3ff;
660
- --habitat-accent: #d89a1c;
661
- display: grid;
662
- grid-template-columns: minmax(0, 1.04fr) minmax(360px, 0.96fr);
663
- width: min(980px, 100%);
664
- min-height: 410px;
665
- margin: 0 auto;
666
- overflow: hidden;
667
- border: 0;
668
- border-radius: 34px;
669
- background: var(--habitat-bg);
670
- box-shadow: none;
671
- }
672
- .mvpPlanHabitat[data-plan="pro"] {
673
- --habitat-bg: #eaf1ff;
674
- --habitat-sky: #c9e6ff;
675
- --habitat-accent: #2446a8;
676
- }
677
- .mvpPlanHabitat[data-plan="power"] {
678
- --habitat-bg: #fff1c7;
679
- --habitat-sky: #ffe2d5;
680
- --habitat-accent: #a6402d;
681
- }
682
- .mvpHabitatScene {
683
- position: relative;
684
- min-height: 410px;
685
- overflow: hidden;
686
- background:
687
- radial-gradient(circle at 23% 18%, rgba(255,255,255,0.88) 0 8%, transparent 24%),
688
- linear-gradient(158deg, var(--habitat-sky), var(--habitat-bg) 65%);
689
- isolation: isolate;
690
- }
691
- .mvpHabitatScene::before {
692
- position: absolute;
693
- inset: 0;
694
- z-index: -2;
695
- background-image: radial-gradient(circle, color-mix(in srgb, var(--habitat-accent) 23%, transparent) 1.2px, transparent 1.4px);
696
- background-size: 22px 22px;
697
- content: "";
698
- opacity: 0.35;
699
- }
700
- .mvpHabitatScene::after {
701
- position: absolute;
702
- right: -5%;
703
- bottom: -18%;
704
- left: -5%;
705
- z-index: -1;
706
- height: 49%;
707
- border-top: 1px solid color-mix(in srgb, var(--habitat-accent) 18%, transparent);
708
- background: color-mix(in srgb, var(--habitat-bg) 78%, white);
709
- content: "";
710
- transform: skewY(-2deg);
711
- }
712
- .mvpHabitatWindow {
713
- position: absolute;
714
- top: 11%;
715
- left: 10%;
716
- width: 30%;
717
- aspect-ratio: 1 / 1.28;
718
- border: 8px solid rgba(255,255,255,0.8);
719
- border-radius: 90px 90px 20px 20px;
720
- background: linear-gradient(180deg, white, var(--habitat-sky));
721
- box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--habitat-accent) 14%, transparent), 0 14px 30px rgba(32,46,78,0.08);
722
- }
723
- .mvpHabitatShelf {
724
- position: absolute;
725
- top: 31%;
726
- right: 8%;
727
- display: flex;
728
- width: 31%;
729
- height: 12%;
730
- padding: 0 9%;
731
- align-items: flex-end;
732
- gap: 5px;
733
- border-bottom: 8px solid color-mix(in srgb, var(--habitat-accent) 50%, #754f31);
734
- }
735
- .mvpHabitatShelf i {
736
- display: block;
737
- width: 15%;
738
- height: 54%;
739
- border-radius: 3px 3px 0 0;
740
- background: var(--habitat-accent);
741
- transform: rotate(-3deg);
742
- }
743
- .mvpHabitatShelf i:nth-child(2) { height: 77%; background: #f1b84a; transform: rotate(2deg); }
744
- .mvpHabitatShelf i:nth-child(3) { height: 66%; background: #68b9c4; }
745
- .mvpHabitatShelf i:nth-child(4) { height: 88%; background: #f19a87; transform: rotate(3deg); }
746
- .mvpHabitatShelf i:nth-child(5) { height: 61%; background: white; }
747
- .mvpHabitatRug {
748
- position: absolute;
749
- right: 10%;
750
- bottom: 8%;
751
- left: 10%;
752
- height: 24%;
753
- border: 2px solid color-mix(in srgb, var(--habitat-accent) 18%, transparent);
754
- border-radius: 50%;
755
- background: color-mix(in srgb, var(--habitat-accent) 12%, white);
756
- transform: rotate(-2deg);
757
- }
758
- .mvpHabitatEcho {
759
- position: absolute;
760
- bottom: 0;
761
- left: 49%;
762
- z-index: 2;
763
- display: block;
764
- width: min(62%, 310px);
765
- height: auto;
766
- filter: drop-shadow(0 20px 25px rgba(25,41,72,0.18));
767
- object-fit: contain;
768
- transform: translateX(-50%);
769
- }
770
- .mvpHabitatDetails {
771
- display: flex;
772
- padding: 32px 38px;
773
- flex-direction: column;
774
- justify-content: center;
775
- background: rgba(255,255,255,0.7);
776
- backdrop-filter: blur(12px);
777
- }
778
- .mvpPlanIdentity {
779
- display: flex;
780
- min-height: 26px;
781
- align-items: center;
782
- justify-content: space-between;
783
- color: var(--habitat-accent);
784
- font: 700 10px/1 var(--echo-font-mono);
785
- letter-spacing: 0.15em;
786
- text-transform: uppercase;
787
- }
788
- .mvpPlanIdentity b {
789
- padding: 8px 11px;
790
- border-radius: 999px;
791
- background: var(--echo-ink-primary);
792
- color: white;
793
- font-size: 8px;
794
- letter-spacing: 0.08em;
795
- }
796
- .mvpHabitatDetails h3 {
797
- margin: 14px 0 7px;
798
- color: var(--echo-ink-text);
799
- font-size: 3.5rem;
800
- font-weight: 450;
801
- line-height: 0.94;
802
- letter-spacing: -0.06em;
803
- }
804
- .mvpPlanPromise {
805
- min-height: 38px;
806
- margin: 0;
807
- color: var(--habitat-accent);
808
- font: 650 22px/1.12 var(--echo-font-script), cursive;
809
- }
810
- .mvpPlanPrice {
811
- display: flex;
812
- margin-top: 18px;
813
- align-items: flex-end;
814
- gap: 13px;
815
- }
816
- .mvpPlanPrice strong {
817
- color: var(--echo-ink-text);
818
- font-size: 48px;
819
- line-height: 0.9;
820
- letter-spacing: -0.065em;
821
- }
822
- .mvpPlanPrice span {
823
- padding-bottom: 5px;
824
- color: var(--echo-ink-mute);
825
- font-size: 13px;
826
- line-height: 1.35;
827
- }
828
- .mvpPacksLabel {
829
- margin: 17px 0 9px;
830
- color: var(--echo-ink-faint);
831
- font: 700 9px/1 var(--echo-font-mono);
832
- letter-spacing: 0.15em;
833
- text-transform: uppercase;
834
- }
835
- .mvpPlanFacts {
836
- display: grid;
837
- gap: 8px;
838
- margin: 0;
839
- padding: 0;
840
- list-style: none;
841
- }
842
- .mvpPlanFacts li {
843
- display: grid;
844
- grid-template-columns: 18px 1fr;
845
- gap: 9px;
846
- color: var(--echo-ink-mute);
847
- font-size: 14px;
848
- line-height: 1.35;
849
- }
850
- .mvpPlanFacts .setupGlyph { width: 16px; height: 16px; color: #2f9d62; }
851
620
  .mvpPlanCta {
852
621
  display: flex;
853
622
  width: 100%;
@@ -1047,12 +816,6 @@ export const SETUP_PAGE_STYLES_MVP = String.raw `
1047
816
  background: transparent;
1048
817
  text-align: left;
1049
818
  }
1050
- .extractionReady .readyMascot {
1051
- width: 54px;
1052
- height: auto;
1053
- margin-top: 4px;
1054
- filter: drop-shadow(0 10px 16px rgba(26,58,143,0.14));
1055
- }
1056
819
  .extractionReady .readyHero .exCopy h2 {
1057
820
  max-width: 680px;
1058
821
  color: var(--echo-ink-text) !important;
@@ -1590,14 +1353,6 @@ export const SETUP_PAGE_STYLES_MVP = String.raw `
1590
1353
  .mvpConsentPitch .mvpConsentIntro { margin-right: auto; margin-left: auto; }
1591
1354
  .mvpTrustCard { grid-template-columns: 38px minmax(0, 1fr); }
1592
1355
  .mvpTrustCard .dataHandlingLink { grid-column: 2; }
1593
- .mvpPlanHabitat {
1594
- grid-template-columns: 1fr;
1595
- min-height: 0;
1596
- border-radius: 28px;
1597
- }
1598
- .mvpHabitatScene { min-height: 390px; }
1599
- .mvpHabitatDetails { padding: 28px 24px 34px; }
1600
- .mvpHabitatEcho { width: min(66%, 360px); }
1601
1356
  .extractionReady .readySettings { flex-direction: column; gap: 9px; }
1602
1357
  body.readyMode:has(.readySettings.is-checkout-pending) main {
1603
1358
  padding-top: 520px;
@@ -1626,17 +1381,10 @@ export const SETUP_PAGE_STYLES_MVP = String.raw `
1626
1381
  }
1627
1382
  .mvpConsent h2 { font-size: 42px; }
1628
1383
  .mvpPricingIntro h2 { font-size: 3.5rem; }
1629
- .mvpPlanTabs { margin-bottom: 16px; }
1630
- .mvpPlanTab { min-height: 46px; padding: 0 8px; font-size: 13px; }
1631
- .mvpPlanTab b { font-size: 10px; }
1632
- .mvpHabitatScene { min-height: 310px; }
1633
- .mvpHabitatDetails h3 { font-size: 3.25rem; }
1634
- .mvpPlanPrice strong { font-size: 48px; }
1635
1384
  .extractionReady .readyHero {
1636
1385
  grid-template-columns: 44px minmax(0, 1fr);
1637
1386
  gap: 12px;
1638
1387
  }
1639
- .extractionReady .readyMascot { width: 44px; }
1640
1388
  .extractionReady .readyHero .exCopy h2 { font-size: 40px; }
1641
1389
  .extractionReady .proofStrip,
1642
1390
  .billingCommitmentSlot {
@@ -1,11 +1,11 @@
1
1
  import { SETUP_PAGE_STYLES_FOUNDATION } from "./styles-foundation.js";
2
2
  import { SETUP_PAGE_STYLES_EXTRACTION } from "./styles-extraction.js";
3
- import { SETUP_PAGE_STYLES_WEBSITE_ALIGNMENT } from "./styles-website-alignment.js";
4
3
  import { SETUP_PAGE_STYLES_MVP } from "./styles-mvp.js";
4
+ import { SETUP_PAGE_STYLES_MONOCHROME } from "./styles-monochrome.js";
5
5
  // Kept as one emitted style tag so the local HTML page remains self-contained.
6
6
  export const SETUP_PAGE_STYLES = [
7
7
  SETUP_PAGE_STYLES_FOUNDATION,
8
8
  SETUP_PAGE_STYLES_EXTRACTION,
9
- SETUP_PAGE_STYLES_WEBSITE_ALIGNMENT,
10
9
  SETUP_PAGE_STYLES_MVP,
10
+ SETUP_PAGE_STYLES_MONOCHROME,
11
11
  ].join("\n");
@@ -40,7 +40,7 @@ function previewWatermarkScript() {
40
40
  var previewWatermark = document.createElement("div");
41
41
  previewWatermark.setAttribute("role", "status");
42
42
  previewWatermark.textContent = "DESIGN PREVIEW · SAMPLE DATA · NOT YOUR LOCAL DATA";
43
- previewWatermark.style.cssText = "position:fixed;z-index:99999;left:50%;top:10px;transform:translateX(-50%);padding:7px 12px;border:1px solid #8b2c26;border-radius:999px;background:#fff4e8;color:#8b2c26;font:700 11px/1.2 ui-monospace,monospace;letter-spacing:.05em;box-shadow:0 4px 16px rgba(0,0,0,.12)";
43
+ previewWatermark.style.cssText = "position:fixed;z-index:99999;left:50%;top:10px;transform:translateX(-50%);padding:6px 12px;border:1px solid #d7d7d2;border-radius:6px;background:#fff;color:#6b6b68;font:500 10px/1.2 Poppins,-apple-system,sans-serif;letter-spacing:.08em;text-transform:uppercase";
44
44
  document.body.appendChild(previewWatermark);
45
45
  `;
46
46
  }
package/dist/setup.js CHANGED
@@ -463,6 +463,7 @@ function echomemGuidanceBlock() {
463
463
  "- Before re-deriving past decisions, project context, or anything the user likely settled before: call `search_memories` first.",
464
464
  '- If the final user-facing answer materially relies on one or more EchoMem memories, end it with a compact `EchoMem sources:` list containing only the memories actually used. Link each memory key to its canonical `https://echoknows.com/memory/<memory-id>` URL. Do not cite memories that were merely retrieved, and omit the section when no memory informed the answer.',
465
465
  "- Before the final response for a task that produced a durable decision, confirmed preference, implementation, resolved bug, commit, passing verification, release, or project milestone: call `save_conversation`. This private checkpoint does not require a separate user request. Do not save secrets, credentials, incidental chatter, or trivial read-only work. If a qualifying save fails because the encrypted vault is locked, relay the bridge's unlock instruction; for this standalone runtime, use `echomem-mcp unlock`. Never silently skip it.",
466
+ "- For `save_conversation`, prefer `messages` and omit `conversation`: copy the smallest relevant contiguous set of user and assistant turns verbatim, preserving role and order. Exclude system instructions, tool calls, and hidden content. Use at most six messages and 12,000 total characters; drop whole older turns instead of truncating or rewriting them. If exact source text is unavailable, use `conversation` with a concise structured summary prefixed `Summary (source excerpt unavailable):`.",
466
467
  '- After `save_conversation` succeeds and returns one or more saved memory IDs, make the save visible in the final user-facing answer with a compact `EchoMem saved:` list containing every memory created by that call. Link each memory key to its canonical `https://echoknows.com/memory/<memory-id>` URL. This save receipt is separate from `EchoMem sources:` and does not imply the newly saved memories informed the answer.',
467
468
  "- For a user with a company group, call `request_group_session_sharing` near conversation start or after a qualifying private save. On the first call in a conversation, omit `groupSharingScopeId` so EchoMem mints a fresh opaque scope. Reuse that exact scope only in this conversation for later get/request/set/save calls, and never persist it as memory. If multiple groups are returned, reuse the same scope and call once per `groupId`. Relay the tool's exact text question and call `set_group_session_sharing` only after an explicit Yes/No. Silence leaves that group's state unset; never infer an answer. Saves sync eligible memories to every approved group; a No keeps them private for that group.",
468
469
  "- If the user pastes a session carryover/checkpoint: it may reference `get_checkpoint_by_context` — use it to pull the checkpoint/decision trail when you need more than the snapshot.",
@@ -1284,14 +1285,17 @@ function claudeSessionCwd(sessionId) {
1284
1285
  function shellQuote(value) {
1285
1286
  return `'${value.replace(/'/g, `'\\''`)}'`;
1286
1287
  }
1288
+ export function canOpenAgentSessions(platform = process.platform) {
1289
+ return platform === "darwin" || platform === "win32";
1290
+ }
1287
1291
  function openExistingAgentSession(source, sessionId) {
1288
1292
  const validSessionId = source === "claude-desktop"
1289
1293
  ? LOCAL_COWORK_SESSION_ID_RE.test(sessionId)
1290
1294
  : LOCAL_SESSION_ID_RE.test(sessionId);
1291
1295
  if (!validSessionId)
1292
1296
  return { ok: false, message: "The local session identifier is invalid." };
1293
- if (source !== "claude-desktop" && process.platform !== "darwin") {
1294
- return { ok: false, message: "Opening local Codex and Claude Code sessions is currently available on macOS." };
1297
+ if (source !== "claude-desktop" && !canOpenAgentSessions()) {
1298
+ return { ok: false, message: "Opening local Codex and Claude Code sessions is currently available on macOS and Windows." };
1295
1299
  }
1296
1300
  try {
1297
1301
  if (source === "codex") {
@@ -1475,7 +1479,7 @@ function asConversationKeys(value) {
1475
1479
  .slice(0, 5000)
1476
1480
  .filter((item) => typeof item === "string")
1477
1481
  .map((item) => item.trim())
1478
- .filter((item) => /^(codex|claude-code):[^\s]{1,180}$/.test(item));
1482
+ .filter((item) => /^(codex|claude-code|claude-desktop):[^\s]{1,180}$/.test(item));
1479
1483
  return Array.from(new Set(keys));
1480
1484
  }
1481
1485
  function readJsonBody(req) {
@@ -1851,6 +1855,7 @@ export function startCallbackServer(opts = {}) {
1851
1855
  // handle never releases and the CLI hangs after migration. Track live sockets and kill them on close.
1852
1856
  const sockets = new Set();
1853
1857
  const checkNonce = (nonce) => !expectedNonce || nonce === expectedNonce;
1858
+ const currentStats = () => (opts.getStats ? opts.getStats() : stats);
1854
1859
  const text = (res, status, body = "") => res.writeHead(status, { "Content-Type": "text/plain" }).end(body);
1855
1860
  const json = (res, status, body) => res.writeHead(status, { "Content-Type": "application/json" }).end(JSON.stringify(body));
1856
1861
  // Funnel analytics: each onboarding step counts once per local setup page.
@@ -2221,8 +2226,8 @@ export function startCallbackServer(opts = {}) {
2221
2226
  consentGranted: localHistoryConsentGranted,
2222
2227
  platform: process.platform,
2223
2228
  capabilities: {
2224
- openClaudeDesktop: process.platform === "darwin" || process.platform === "win32",
2225
- openAgentSessions: process.platform === "darwin" || process.platform === "win32",
2229
+ openClaudeDesktop: canOpenAgentSessions(),
2230
+ openAgentSessions: canOpenAgentSessions(),
2226
2231
  },
2227
2232
  });
2228
2233
  return;
@@ -2333,7 +2338,7 @@ export function startCallbackServer(opts = {}) {
2333
2338
  message: "Allow local history access before continuing setup.",
2334
2339
  });
2335
2340
  }
2336
- const payload = opts.getStats ? opts.getStats() : stats;
2341
+ const payload = currentStats();
2337
2342
  if (payload == null)
2338
2343
  return void res.writeHead(202).end();
2339
2344
  json(res, 200, payload);
@@ -2653,12 +2658,26 @@ export function startCallbackServer(opts = {}) {
2653
2658
  }
2654
2659
  if (migrateStarted)
2655
2660
  return void json(res, 409, { error: "MIGRATE_IN_PROGRESS" });
2661
+ const conversationKeys = asConversationKeys(body.conversationKeys);
2662
+ const offeredStats = currentStats();
2663
+ const offered = isObjectRecord(offeredStats) && Array.isArray(offeredStats.candidateSessions)
2664
+ ? new Set(offeredStats.candidateSessions.map((session) => isObjectRecord(session) ? session.key : null))
2665
+ : null;
2666
+ // An explicit selection that matches nothing must not commit to extraction: the import
2667
+ // path would find no match, report "no pending sessions", and close this bridge.
2668
+ const selectionMatchesNothing = conversationKeys !== null && (conversationKeys.length === 0 || (offered !== null && !conversationKeys.some((key) => offered.has(key))));
2669
+ if (selectionMatchesNothing) {
2670
+ return void json(res, 400, {
2671
+ error: "NO_VALID_SESSIONS_SELECTED",
2672
+ message: "None of the selected conversations could be imported. Reopen the list and try again.",
2673
+ });
2674
+ }
2656
2675
  migrateStarted = true;
2657
2676
  const safety = setTimeout(() => {
2658
2677
  respondMigrate(res, { error: "IMPORT_START_TIMEOUT" }, 504);
2659
2678
  }, 30_000);
2660
2679
  safety.unref?.();
2661
- migrateRequest.resolve({ res, conversationKeys: asConversationKeys(body.conversationKeys) });
2680
+ migrateRequest.resolve({ res, conversationKeys });
2662
2681
  decision.resolve("migrate");
2663
2682
  return;
2664
2683
  }
@@ -2756,6 +2775,38 @@ function authedAxios(token) {
2756
2775
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, "X-Echo-Client": "cli" },
2757
2776
  });
2758
2777
  }
2778
+ /**
2779
+ * Reuse a saved trusted-device credential only after the backend still recognizes its token.
2780
+ * A revoked API key is an expected returning-user state, not a terminal setup failure: let the
2781
+ * existing onboarding bridge collect a fresh login and atomically overwrite the stale file after
2782
+ * authentication succeeds. Do not delete the old file up front, so abandoning the browser flow
2783
+ * cannot destroy the last local credential.
2784
+ */
2785
+ export async function loadReusableOnboardingCredentials() {
2786
+ const store = new KeyStore();
2787
+ const token = store.getToken();
2788
+ const key = store.getKey();
2789
+ if (!token || !key)
2790
+ return undefined;
2791
+ try {
2792
+ const config = await fetchEncryptionConfig(authedAxios(token));
2793
+ if (config.enabled && !await verifyKeyB64(key, config)) {
2794
+ console.log("Your saved EchoMem vault unlock no longer matches this account. Continuing with a fresh sign-in…");
2795
+ return undefined;
2796
+ }
2797
+ return { token, key };
2798
+ }
2799
+ catch (error) {
2800
+ const unauthorized = axios.isAxiosError(error) && error.response?.status === 401;
2801
+ if (!unauthorized)
2802
+ throw error;
2803
+ if (process.env.ECHO_API_TOKEN) {
2804
+ throw new Error("ECHO_API_TOKEN was rejected by EchoMem. Unset or replace that environment variable before signing in again.");
2805
+ }
2806
+ console.log("Your saved EchoMem device sign-in is no longer valid. Continuing with a fresh sign-in…");
2807
+ return undefined;
2808
+ }
2809
+ }
2759
2810
  function apiAxios() {
2760
2811
  return axios.create({
2761
2812
  baseURL: API_BASE_URL,
@@ -3211,12 +3262,16 @@ async function cmdLogin(flags) {
3211
3262
  * fresh device stays in this same bridge and asks for login only after permission.
3212
3263
  */
3213
3264
  async function cmdOnboarding(flags) {
3214
- const store = new KeyStore();
3215
- const savedToken = store.getToken();
3216
- const savedKey = store.getKey();
3217
- const initialToken = savedToken && savedKey
3218
- ? { token: savedToken, key: savedKey }
3219
- : undefined;
3265
+ let initialToken;
3266
+ try {
3267
+ initialToken = await loadReusableOnboardingCredentials();
3268
+ }
3269
+ catch (error) {
3270
+ console.error(`❌ ${formatVerificationError(error)}`);
3271
+ process.exitCode = 1;
3272
+ return false;
3273
+ }
3274
+ const reusedSavedCredentials = Boolean(initialToken);
3220
3275
  console.log("Opening your browser for EchoMem onboarding…");
3221
3276
  const { port, nonce } = localBridgeOptions(flags);
3222
3277
  let stats = null;
@@ -3251,7 +3306,9 @@ async function cmdOnboarding(flags) {
3251
3306
  process.exitCode = 1;
3252
3307
  return false;
3253
3308
  }
3254
- if (!await verifyAndPrint({ token, key })) {
3309
+ // Saved credentials were fully checked before the browser opened. Fresh credentials still pass
3310
+ // through the normal persistence/verification path after the local login flow resolves them.
3311
+ if (!reusedSavedCredentials && !await verifyAndPrint({ token, key })) {
3255
3312
  srv.close();
3256
3313
  process.exitCode = 1;
3257
3314
  return false;
@@ -3571,7 +3628,8 @@ async function cmdOnboarding(flags) {
3571
3628
  if (migrateResponded)
3572
3629
  return;
3573
3630
  migrateResponded = true;
3574
- respondMigrate(res, body, status);
3631
+ // Every failure past this point closes the bridge; tell the page so it stops offering actions.
3632
+ respondMigrate(res, status >= 400 && isObjectRecord(body) ? { ...body, bridgeClosing: true } : body, status);
3575
3633
  };
3576
3634
  let activeSessionId = "";
3577
3635
  let activeJobCount = latestPendingEstimate;