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({