You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(session): per-channel "current session" so Telegram and WhatsApp don't stomp each other
Until now `settings.json` had a single `currentSession` field that both
channels read and wrote. Switching sessions in Telegram silently moved
the WhatsApp cursor too (and vice versa), which made the two channels
fight over context whenever they were used in parallel.
This commit splits the cursor by channel:
- `Settings.currentSessionByChannel: { telegram?, whatsapp? }`
is the new persisted shape. Each channel keeps its own active
session; the OpenCode sessions themselves remain global, so
`/sessions` in either channel still lists every session.
- `Settings.currentSession` is kept as a deprecated, read-only field
for migration. On the first `loadSettings()` after upgrade, any
legacy value is moved to `currentSessionByChannel.telegram`
(Telegram has been the only channel until V1.x, so the assumption
is safe). The legacy field is dropped from disk on the next write.
- `setCurrentSession(channel, info)` now takes the channel as a
required first arg — TypeScript forces every call site to declare
who owns the session, so no future call accidentally reads/writes
the wrong slot.
- `getCurrentSession(channel?)` defaults to "telegram" so the dozens
of read-only call sites in `src/bot/`, `src/attach/`,
`src/pinned/`, `src/cron/` keep working unchanged.
- `clearSession(channel?)` clears only that channel; with no argument
it clears both, used by global resets like `switchToProject`,
`/start`, and the session/project mismatch recovery path.
Call sites updated:
- src/whatsapp/commands/{new,sessions,abort,status}.ts and
src/whatsapp/handlers/prompt.ts now pass "whatsapp"
- src/bot/commands/{new,sessions,rename,commands}.ts and
src/bot/handlers/prompt.ts now pass "telegram"
Tests: tests/session/per-channel-session.test.ts covers the new
read/write semantics, the migration from legacy single-slot config,
and the clearSession variants. 8 new tests; full suite green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments