From 66b89f74d4c40626da5c50d3de1ff73a0d1c52c8 Mon Sep 17 00:00:00 2001 From: engineer Date: Mon, 1 Jun 2026 23:49:19 -0700 Subject: [PATCH] fix(sessions): keep created-session scope through navigation and send (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit createSession now stamps the scope directory onto the returned session, and the create-session navigation passes that directory to the detail screen. Previously a freshly created home-scoped session was opened/addressed with the default (CWD) client because the route carried no directory param — the same scope mismatch class as #10, on the open/send path instead of the list path. Co-Authored-By: Claude Opus 4.8 --- app/(tabs)/index.tsx | 10 ++++++++-- src/stores/sessions.ts | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index 91e8e0f..1860250 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -188,7 +188,10 @@ export default function SessionsScreen() { const onCreateSession = async () => { const session = await createSession() if (session) { - router.push(`/session/${session.id}`) + router.push({ + pathname: `/session/[id]`, + params: { id: session.id, ...(session.directory ? { directory: session.directory } : {}) }, + }) } } @@ -227,7 +230,10 @@ export default function SessionsScreen() { setShowNewSession(false) setCustomDir("") if (session) { - router.push(`/session/${session.id}`) + router.push({ + pathname: `/session/[id]`, + params: { id: session.id, ...(session.directory ? { directory: session.directory } : {}) }, + }) } } diff --git a/src/stores/sessions.ts b/src/stores/sessions.ts index b9a2614..dc32557 100644 --- a/src/stores/sessions.ts +++ b/src/stores/sessions.ts @@ -197,7 +197,12 @@ export const useSessions = create((set, get) => ({ const client = scopeDir ? connState.clientForDirectory(scopeDir) || connState.client : connState.client try { - const session = await client.session.create({ title }) + const created = await client.session.create({ title }) + // Stamp the scope we created in onto the session so every downstream path + // (navigation params, selectSession, sendMessage's clientFor) addresses it + // in the SAME scope. Without this, opening/sending to a freshly created + // home-scoped session via the default client would hit the wrong scope (#10). + const session = scopeDir && !created.directory ? { ...created, directory: scopeDir } : created // Don't optimistically add to sessions list — let loadSessions() handle it // to avoid duplicate key errors from race conditions set({