Skip to content

feat: saved connections and the native connection switcher (#152) - #173

Merged
os-justin merged 4 commits into
mainfrom
claude/issue-152-saved-connections
Nov 2, 2026
Merged

os-justin merged 4 commits into
mainfrom
claude/issue-152-saved-connections

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #152

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么:App 能保存多个连接(Cloud 组织和公司私有服务器),在原生「切换组织」底部弹层里一键切换;左滑移除即退出该连接的登录;老用户原来保存的那一个服务器,升级后自动成为第一个连接。
  • 为什么改:同一个人常常同时在几个组织或公司服务器里办公,过去换服务器要重新输入地址、并覆盖掉原来那一个;现在各自保存、各自保持登录,切换不再丢失登录状态。
  • 风险与回滚:新增原生模块 @preeternal/react-native-cookie-manager 7.0.0,必须重新出商店包或开发包;移除时只清该主机自己的 Cookie,与其他主机共享的 Cookie 一律不动;回滚即 revert 本 PR 并重新出包,但升级时旧的单服务器键已删除,回滚到旧版本的用户需要重新输入一次地址。
  • 先看:lib/connections/cookies.ts(判定哪些 Cookie 属于本主机,风险最高);components/shell/ConsoleWebView.tsx 的 switch 分支(切换时在目标主机重建 WebView);lib/server-url.ts 的 loadConnections(升级迁移只跑一次)。
  • 两分钟验证:npx jest __tests__/components/ConsoleScreen.test.tsx,预期 7 条全过,其中有「切换后在目标主机的上次路由重建 WebView」与「移除当前连接:先请 Console 注销推送,再切走,最后清 Cookie」。
  • 需要你做的:用含新原生模块的开发包或商店包做一轮真机检查——添加两个连接并互相切换、移除其中一个并确认它已退出登录、从只保存了一个服务器的旧版本升级(iOS 与 Android 各一遍)。

What changes

  • Saved connections (lib/connections/model.ts). The single serverUrl becomes an ordered list in SecureStore (objectstack_connections, a versioned JSON document). Each record holds kind (cloud or server), label, host, brand colour and initial, lastRoute, addedAt, plus serverUrl: a host alone loses the scheme and a base path, which the WebView needs. One connection is current. Saving dedupes by host; removing the current one makes the first remaining one current. stores/server-store.ts publishes the list and keeps serverUrl as the current connection's, so the start screen and push routing read it as before.
  • Migration (lib/server-url.ts). The first launch that finds no document turns the old objectstack_server_url value into the first, current connection (labelled with its host; that build kept no branding), writes the document, then deletes the old key. Its value is read by exactly one migration. A failed write keeps the old key for the next launch. A fresh install writes nothing.
  • Switcher sheet (components/shell/ConnectionSwitcher.tsx, screen 8). The sheet lists each connection with its initial on the brand colour, the label, a kind badge (Cloud / Private) and the host, and checks the current one. Tapping a row switches to it. A left swipe reveals Remove, and screen readers get the same action on the row. "Add an organization or company server" goes back to the address step (/server-config?add=1, the address starting empty), so a connection is still saved only from the probe-and-confirm step, the same step connect links and the scanner use. "App settings" opens the system settings page for the app.
  • Switching. It goes through the load state machine. A new switch event in lib/shell/console-load.ts emits the existing recreate effect, so the WebView is re-created on the chosen host at that connection's lastRoute. The old host's held route and last route are dropped, and the held push token is kept. documentRef is still bumped only in that effect. app/console.tsx drops its key={serverUrl} remount, so there is one remount path. The bridge handler is built for the current connection's origin, so a page of the host left behind gets no answer. The Console's routeChanged is recorded as the current connection's lastRoute.
  • Removal signs out (lib/connections/sign-out.ts), in this order:
    1. For the current connection, with its Console ready, the shell dispatches the new shell event objectstack-native:connectionRemoved (cancelable, detail.waitUntil). The Console unregisters this install's push token under its own session, and the shell waits up to 10 s for the injected script's connectionRemovedDone answer.
    2. The connection leaves the list, and the WebView moves to the next connection, or to the picker.
    3. That host's own cookies are cleared.
      Any answer other than "handled and resolved" records the host in pushLeftRegistered, and a later save of that host clears the record. The shell calls no API.
  • Bridge. showConnectionSwitcher() is added as a method, the connectionRemoved shell event is added, and both are announced as capabilities. Adding them changes no protocol version. resetServer() now forgets the current connection, and the next saved one becomes current.
  • Offline page (screen 9). The secondary action becomes 切换组织 (Switch organization) and opens the sheet.
  • Ten locales. The new switcher.* strings, and common.close, are in all ten bundles; shell.changeServer is removed from all ten.
  • Native module. @preeternal/react-native-cookie-manager 7.0.0, pinned exactly. Its Expo config plugin is registered in app.config.ts. It is a New Architecture TurboModule, which Expo SDK 55 / React Native 0.83 requires. It is not in Expo's bundledNativeModules.json, which lists no cookie module at all. Its codegen spec uses CodegenTypes.EventEmitter, which RN 0.83 exports, and it pulls no extra npm dependencies: the lockfile adds only this package. On Android it compiles against androidx.webkit 1.16.0 (GET_COOKIE_INFO needs at least 1.6.0); react-native-webview asks for 1.14.0, and Gradle resolves the higher one.
  • docs/HYBRID-SHELL.md documents the connection model, switching, removal and cookie scoping, both bridge additions, the load state, the Console-side integration and the new known limits.

Tests

  • Unit:
    • __tests__/lib/connections/model.test.ts: add, dedupe by host, remove, current-connection rules, last route, storage form.
    • __tests__/lib/server-url.test.ts: upgrade with a saved URL, fresh install, interrupted migration, failed write, garbage value.
    • __tests__/lib/server-store.test.ts.
    • __tests__/lib/connections/cookies.test.ts: the plan, plus a stand-in cookie store that behaves like the module on iOS and on Android.
    • __tests__/lib/connections/sign-out.test.ts: the order of the steps.
    • console-load.test.ts: the switch event.
    • The bridge protocol, handler and scripts. The removal script is executed against a page with real DOM events.
  • Components:
    • ConnectionSwitcher.test.tsx: rows, badges, current check, select, swipe-revealed Remove, the screen-reader action, the lock while a removal runs, add, settings, backdrop, Arabic right-to-left. The swipe gesture itself is native and stubbed.
    • ConsoleScreen.test.tsx: wired end to end through the store. A switch remounts the WebView on the right host and route, the route is remembered, the offline action opens the sheet, add saves nothing, and the three removal cases run in their order.
    • ConsoleWebView.test.tsx: switching, the origin gate after a switch, the removal ask's answers, the timeout and a re-create.
  • New component suites use the beforeAll warm-up.

Acceptance notes

  • Landing point outside the claim's file surface: lib/shell/console-load.ts. The ruled remount path is the machine's recreate, but its recreate event starts the new WebView at the old host's held route or last route. The real producer of the remount is the machine, so the fix is there: a switch event that emits the same recreate effect. No second remount or readiness mechanism was added.
  • Cookie scoping, measured from the module's source at 7.0.0 and from react-native-webview 13.16. Not run on a device.
    • iOS. clearByName(url, name) deletes, one cookie at a time, every cookie of that name whose domain matches the host, including a parent-domain cookie (.objectos.ai), on every path. So the shell chooses the names itself. A name is cleared only when every cookie under it is the host's own: host-only, or a domain cookie for exactly this host that no other saved connection falls under. Shared cookies are left and counted.
    • iOS, both stores. With sharedCookiesEnabled, react-native-webview copies the WebKit store into HTTPCookieStorage on every change, and copies HTTPCookieStorage back into the WebKit store whenever a WebView is created. Both stores are cleared, or the cookie comes back.
    • Not used: WKWebsiteDataStore.removeData(ofTypes:for:). Its records are grouped by registrable domain, so it would sign out every *.objectos.ai environment at once.
    • Android. There is one app-wide CookieManager and no delete call. The module overwrites each cookie with an expired one, through GET_COOKIE_INFO. On a WebView provider without it, the shell clears nothing and records the outcome as unscoped. clearAll is never called.
  • Per-host isolation already holds for host-only cookies; nothing extra is needed. Both WebViews scope cookies by host, and the platform's session cookie is host-only by default. Cookies set with a parent Domain (OS_COOKIE_DOMAIN) are shared by design, and so are cookies that differ only by port. Separating those would need a data store per connection, and react-native-webview 13.16 does not expose one.
  • No session moves between hosts. Clearing cookies is sign-out only. The held push token survives a switch: it is the device's APNs/FCM token, not a session, and only the new Console registers it under its own sign-in.
  • resetServer(). Its meaning had to be chosen for a list: it now forgets the current connection and opens the picker, and it still clears no cookies, as before. This is in the report's open questions.
  • Design copy and layout not taken.
    • "App 设置(锁屏、通知、诊断信息)" is shortened to "App settings": there is no native settings screen, lock or diagnostics yet, so the link opens the system settings.
    • The design's 编辑 / Edit button is not in the card and was not built.
    • The offline page's context line still shows the server URL; the card asks only for the secondary action.
  • common.close. BottomSheet's backdrop label used common.close, a key no bundle had. The switcher is the sheet's first user, so the key is added to all ten bundles.
  • Size. About 3,850 changed lines, about half of them tests.
  • After acceptance, the seat files the Console consumer card in objectstack-ai/objectstack. It covers the header organization button calling showConnectionSwitcher() when has(...) is true, and a connectionRemoved listener that unregisters the push token through detail.waitUntil.
  • Push taps carry no connection. A notification is routed to the current connection's Console. With several saved servers, a tap on one from another server opens its route on the current host. This is listed under Known limits.
  • Removal clears cookies only. It leaves the removed origin's localStorage and IndexedDB, and it does not revoke the session on the server. Both are listed under Known limits.

Verification

Head 1996fb4. Every command was run in the worktree, through the shared verify lock.

Gates: exit codes
pnpm install --frozen-lockfile                          EXIT=0
npx tsc --noEmit                                        EXIT=0
npx eslint . --ext .ts,.tsx                             EXIT=0
npx jest --ci --coverage --maxWorkers=2                 EXIT=0
  Test Suites: 39 passed, 39 total
  Tests:       669 passed, 669 total
  lib/connections 95.34 % statements, 95 % branches, 100 % functions, 96.99 % lines
npx jest --ci --no-cache --maxWorkers=2 --coverage --coverageThreshold='{}' --verbose \
  __tests__/components/ConnectionSwitcher.test.tsx __tests__/components/ConsoleScreen.test.tsx
                                                        EXIT=0  17 passed, Time 18.081 s (cold)
Ablations: mutated, red, restored to the HEAD blob
1. lib/connections/cookies.ts: 'owned[i] && !sharedNames.has(c.name)' -> 'owned[i] /* ablated ... */'
   blob f7f1dad -> e57ec6b; cookies.test.ts: 2 failed, 13 passed
     planHostCookieClear > keeps a name that a shared cookie also carries
     clearHostCookies > on iOS > never clears a name a shared cookie also carries
   restored: blob == HEAD f7f1dad, git diff HEAD empty
   (A first attempt was refused before it ran: the replacement text already
    occurred in the anchor, so its on-disk count could not move. No reading.)
2. components/shell/ConsoleWebView.tsx: the layout effect's switch dispatch -> no-op
   blob 4a58b2b -> 60dc7c0; ConsoleWebView + ConsoleScreen: 8 failed, 52 passed
     every "switching" case plus the screen's switch, resume and remove-current cases
   restored: blob == HEAD 4a58b2b, git diff HEAD empty
  • Device checks: NOT MEASURED. These go to the maintainer, above.

Generated by Claude Code

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:mobile#1 · os-justin · session_01QSeKYnW1Xf6HDSWz1eGAqv

Seat verdict: ACCEPT with four questions for the maintainer. Head-sha: 1996fb455914c39584bc4e0b592154b0133a83e7

维护者速读

  • 改了什么:
    • 单个服务器地址变成可保存多条连接(SecureStore 版本化存储,旧的单地址首次启动时迁移一次)。
    • 新增原生「切换组织」底部面板,Console 可通过新桥接方法 showConnectionSwitcher() 打开,离线页的次要按钮也能打开。
    • 切换时经加载状态机重建 WebView,打开到该连接上次的路由。
    • 移除连接时:先请该连接已加载的 Console 注销推送令牌,再删记录,最后只清这一台主机自己的 cookie。新增原生模块 @preeternal/react-native-cookie-manager 7.0.0。
  • 为什么改: 设计稿第 8 屏,一个用户可以同时有多个组织或公司服务器。
  • 风险与回滚:
    • 新增原生模块,必须重新出包。
    • 从 1 个服务器升级的老用户会自动迁移。
    • 改动共 3854 行,超过 3000 行的人工合并线(测试约 1900 行),所以本 PR 不由席位落地,等你审批合并。
    • 回滚:revert 后重新出包。迁移是单向的,回滚后已保存的多条连接只认第一条。
  • 先看:
    • lib/connections/cookies.ts:判定哪些 cookie 属于该主机,从不清空全部。
    • lib/connections/sign-out.ts:移除流程。
    • lib/server-url.ts:迁移。
    • lib/shell/console-load.ts:新增的 switch 事件。
  • 两分钟验证: npx jest --ci __tests__/lib/connections __tests__/components/ConnectionSwitcher.test.tsx __tests__/components/ConsoleScreen.test.tsx
  • 需要你做的:
    • ① 裁下方 Q2–Q4。Q1 席位已按「不改变现有行为」定。
    • ② 真机:加两条连接、来回切换、移除一条后确认已登出、从只存 1 个服务器的旧版本升级。本 PR 未上真机。
    • ③ 审批并合并。

待你裁的问题(dev 的推荐在前,席位同意):

  • Q1 resetServer() 在多连接下的含义。 席位定为 A:忘掉当前连接、打开选择页、不清 cookie,和现有行为完全一致。若要「重置即登出」,属于会话处理,由你另行裁定,改动约两行。
  • Q2 父域共享 cookie。 部署设置了 OS_COOKIE_DOMAIN(例如 Cloud 的 *.objectos.ai 可能如此)时,会话 cookie 由同域下所有环境共享。
  • Q3 部分安卓 WebView 内核(不支持 GET_COOKIE_INFO)报不出 cookie 的域。推荐 A:清不了就不清,记一条日志,不猜着清。
  • Q4 设计披露。 这个 cookie 模块列 cookie 时会连值一起返回,所以移除连接的那一刻,被移除主机的会话 cookie 值会短暂经过壳的 JS 内存。它不存储、不记日志、不发送。这触及章程「壳不持凭据」的边界,请你知道并确认可接受。另外,iOS 上 sharedCookiesEnabled 本来就把 WebView cookie 镜像到 App 级 cookie 库,这在 main 上早已如此,本 PR 没有改变。

席位核对

  1. Shape: draft → main. The first line is Fixes #152. Clause-②: no and Metadata-protocol: none are present. The changeset is patch.
  2. Premise, measured: main at 0fd7113 held a single serverUrl, BRIDGE_METHODS had no showConnectionSwitcher, and there was no cookie-manager dependency.
  3. Gates: check-runs on head 1996fb4: Code Quality success, Lint & Type Check success. mergeable_state is clean. Local: jest --ci --coverage 39/39 suites, 669 tests. pnpm install --frozen-lockfile exits 0.
  4. Seat read of the risk surface:
    • cookies.ts never calls clearAll.
    • A name is cleared only when every visible cookie of that name is host-only for this host, or is a domain cookie for exactly this host.
    • A cookie with no domain makes the plan null, and then nothing is cleared.
    • Ablations:
      • Removing the shared-name guard turns 2 tests red.
      • No-op'ing the switch dispatch turns 8 red.
  5. Accepted deviation: lib/shell/console-load.ts gains a switch event. The remount is produced in the machine; the dev measured that recreate alone starts at the old host's route. documentRef is still bumped only on recreate.
  6. Out of scope:
    • A push tap from one saved server opens on the current host: hooks/usePushRouting.ts routes without checking the server. This PR makes it reachable, and the seat files it as its own card.
    • A removed host's localStorage and IndexedDB are not cleared, and its server-side session is not revoked. This is documented as a Known limit, and Q2/C covers the session half.
    • common.close was missing from every bundle; it is fixed here.
    • Skills-docs: n/a.
  7. Landing: the path surface is not governed, but the diff is 3854 changed lines, over 3000 (SKILL.md 路径分叉). The PR waits for the maintainer's approval and merge, and the seat does not enable auto-merge.

@objectstack-fleet objectstack-fleet Bot added the needs-user-decision Blocked on a maintainer decision — do not dispatch; decision cards only, never on a PR label Nov 2, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 2, 2026 15:26
@os-justin
os-justin added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit 678fbe9 Nov 2, 2026
2 checks passed
@objectstack-fleet objectstack-fleet Bot removed the needs-user-decision Blocked on a maintainer decision — do not dispatch; decision cards only, never on a PR label Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saved connections and the native "切换组织" switcher (organizations and company servers)

2 participants