Skip to content

Add multiple sessions: one tab per connection, each with its own settings - #422

Merged
gbmhunter merged 3 commits into
mainfrom
feature/sessions
Sep 6, 2026
Merged

gbmhunter merged 3 commits into
mainfrom
feature/sessions

Conversation

@gbmhunter

@gbmhunter gbmhunter commented Sep 5, 2026 •

Copy link
Copy Markdown
Owner

Multiple sessions in one window: one tab per connection, each with its own settings, terminals, macros, filters, rules, logging and graphing. RTT from one board in one tab, serial from another in the next. Steps 1–4 of the plan discussed: extract Session, persist sessions[], tabs UI, session-aware MCP.

The model

A session is a connection plus everything configured around it — which is exactly what ProfileConfig already held. The persisted seam existed; the runtime didn't: App was a Session and an app shell welded together.

Session (new) takes the per-connection half: settings, connController, terminals, TX line, graphing, logging, fake ports, preset controller, byte counts and rates, parseRxData/writeBytesToSerialPort, keyboard/clipboard/find handling, and the config-reload registry that used to live on AppDataManager.

App keeps what exists once per window — app data and presets, snackbar, sound player, performance monitor, updater, MCP, main pane, CPU monitor — plus sessions: Session[] and activeSessionId. It exposes the active session's members through delegating getters (app.settings, app.connController, app.terminals, …), so the views and e2e tests read them exactly as before and a tab switch re-renders everything through MobX. No view outside the tab strip and settings header knows sessions exist.

Every session-owned class takes its Session, not the App — the six settings classes, ConnController and the transports, BluetoothLEController, FakePortsController, Logging, Graphing, PresetController, MacroController, RightDrawer, Terminals, FilterController, RulesSettings. That is the part that matters: session B's connection reads session B's baud rate while session A is on screen. SettingsBranch attaches to a small ConfigHost interface (config, registerOnConfigReload, saveAppData) that Session implements.

Per session App-wide
connection + its settings, the live connection presets, NinjaTerm defaults
RX/TX/display settings, the three terminal panes, filters, find app-level general settings (auto-update, MCP)
macros, right drawer, highlight rules MCP server, snackbar, updater, window
logging, graphing, byte counts, rates main-pane selection, CPU monitor

Persisted

appData.currentAppConfig → appData.sessions[] (id, name, config) + activeSessionId. Folded into the still-unreleased v24→v25 migration, which wraps the one config as "Session 1". The v25 snapshot is regenerated; the spec normalises the random session ids before comparing to a fresh AppData. Order, names and the active session survive a restart. New rows go in as plain objects (makeSessionData) so their settings are observable — the same trap AppDataManager guards against for the whole tree.

UI

Tab strip above the main pane, one tab per session with a connection-state dot. + opens a session with default settings; drag a tab onto another to take its slot; right-click a tab for Rename / Duplicate / Move left / Move right / Close; double-click to rename; Ctrl+Tab / Ctrl+Shift+Tab cycle. The main pane is keyed by session id so a switch remounts against the new session's terminals. The settings pane says which session it is editing. Closing a session disconnects it, flushes any active log, releases its timers and listeners, and activates its neighbour; the last one can't be closed. Keys pressed inside the tab strip don't reach the terminal.

MCP

  • list_sessions is new.
  • get_terminal_output, send_data, get_connection_status take an optional session (id or case-insensitive name), defaulting to the active one.
  • send_data goes through the renderer session instead of writing to the serial port from the main process — so it works for sockets, RTT and Bluetooth, and is echoed to the TX terminal and logged like typed data. getActivePortPath is no longer used by MCP.
  • Per-session RX stream: ninjaterm://sessions/{id}/rxstream (a resource template, listable), one bounded buffer per NinjaTerm session per MCP session. ninjaterm://terminal/rxstream still reads the active session's stream.

Not in this PR

Split view (two sessions side by side), cross-session triggers ("this RTT line sends that serial command"), and pruning MCP stream buffers for closed sessions. Noted in TODO.md §7. Per-profile generalSettings (two clipboard preferences) stay per session; the genuinely app-wide general settings were already at the appData root.

Verification

  • Session.spec.ts (13): independent settings and data paths, delegation + tab-switch observability, duplicate, close (neighbour activation, last-session guard), rename/reorder persistence, move-to-slot, restart, preset scoped to the active session, Ctrl+Tab cycling, MCP session resolution
  • Sessions.spec.ts e2e (3): tab strip new/switch/close with per-session baud rate; drag-to-reorder; RX data lands in the owning session, not the active one
  • AppDataManager.spec: v24→v25 asserts the session wrap; all snapshot upgrades compare with normalised ids
  • Existing specs that built settings classes against a second AppDataManager now build against app.activeSession; spies target the session
  • npx tsc clean · npm run lint 0 errors · 506/506 unit · 92/92 e2e · snapshot preflight OK

A session is a connection plus everything configured around it -- the
connection settings, the terminal panes and their RX/TX/display settings,
macros, filters, highlight rules, logging and graphing. That is exactly
what ProfileConfig already held, so the persisted seam existed; the runtime
did not. App was a Session and an app shell welded together.

Session (new) takes the per-connection half of App: settings, connController,
terminals, txLineController, graphing, logging, fakePortController,
presetController, byte counts and rates, parseRxData / writeBytesToSerialPort
and the keyboard, clipboard and find handling, plus the config-reload
registry that lived on AppDataManager. App keeps the app-wide services --
app data and presets, snackbar, sound player, performance monitor, updater,
MCP, main-pane selection, CPU monitor -- and a list of sessions with an
active one. It exposes the active session's members through delegating
getters (app.settings, app.connController, app.terminals, ...), so the views
and the e2e tests read them exactly as before and a tab switch re-renders
everything through MobX.

Every session-owned class (Settings and the six settings classes,
ConnController, the transports, BluetoothLEController, FakePortsController,
Logging, Graphing, PresetController, MacroController, RightDrawer, Terminals,
FilterController, RulesSettings) now takes its Session rather than the App.
That is the part that matters: session B's connection reads session B's
baud rate while session A is on screen. SettingsBranch attaches to a small
ConfigHost interface (config, registerOnConfigReload, saveAppData) that
Session implements. MainPanes and isTypingInField moved to their own modules
so Session can import them without a cycle.

Persisted: appData.currentAppConfig becomes appData.sessions[] (id, name,
config) plus activeSessionId. Folded into the unreleased v24->v25 migration,
which wraps the one config as "Session 1"; the v25 snapshot is regenerated
and the spec normalises the random session ids before comparing. Sessions,
their order, names and the active one survive a restart. A blob with no
sessions gets a default one. New rows are pushed as plain objects (see
makeSessionData) so their settings are observable.

UI: a tab strip above the main pane, one tab per session with a
connection-state dot. "+" opens a session with default settings; right-click
a tab for rename, duplicate, move left/right and close; double-click to
rename; Ctrl+Tab / Ctrl+Shift+Tab cycle. The main pane is keyed by session
id so a switch remounts against the new session's terminals. The settings
pane names the session it edits. Closing a session disconnects it, flushes
any active log, releases its timers and listeners, and activates its
neighbour; the last one cannot be closed. Keys pressed inside the tab strip
do not reach the terminal.

MCP: list_sessions is new. get_terminal_output, send_data and
get_connection_status take an optional `session` (id or case-insensitive
name) and default to the active one. send_data now goes through the
renderer session rather than writing to the serial port from the main
process, so it works for every connection type and is echoed to the TX
terminal and logged like typed data; getActivePortPath is no longer used by
MCP. The rxstream resource is a template, ninjaterm://sessions/{id}/rxstream,
with one bounded buffer per NinjaTerm session per MCP session; the old
ninjaterm://terminal/rxstream URI still reads the active session's stream.
pushRxData carries the session id across IPC.

Tests: Session.spec (12) covers independence of settings and data paths,
delegation and tab-switch observability, duplicate, close (neighbour
activation, last-session guard), rename and reorder persistence, restart,
preset scoping to the active session, Ctrl+Tab cycling and MCP session
resolution. Two e2e tests drive the tab strip and check that data lands in
the owning session. Existing specs that built settings classes against a
second AppDataManager now build them against app.activeSession; the ones
that spy on parseRxData / writeBytesToSerialPort spy on the session, and
those remain prototype methods (not arrow fields) so they can be spied on.
Comment thread src/renderer/src/model/App.tsx Fixed
Comment thread src/renderer/src/model/App.tsx Fixed
Comment thread src/renderer/src/model/App.tsx Fixed
Comment thread src/renderer/src/model/App.tsx Fixed
CodeQL flagged the Math.random() fallback in newSessionId as insecure
randomness flowing into an identifier. The ids carry no security weight, but
the fallback was only there for runtimes without crypto.randomUUID, and every
one of those has crypto.getRandomValues, so build a v4 UUID from that instead.
Dropping a tab on another moves the dragged session into that tab's slot,
shifting the rest along; the target tab is outlined while hovered and the
dragged one dimmed. HTML5 drag events on the MUI Tab, no library.
App.moveSessionTo(id, index) does the work and the context menu's
Move left/right now go through it. Unit test for the slot semantics and
clamping; e2e drags the third tab onto the first.
@gbmhunter gbmhunter self-assigned this Sep 6, 2026
@gbmhunter
gbmhunter merged commit cb7e340 into main Sep 6, 2026
8 checks passed
@gbmhunter
gbmhunter deleted the feature/sessions branch September 6, 2026 04:48
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.

2 participants