Repository navigation
Add multiple sessions: one tab per connection, each with its own settings - #422
Merged
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, persistsessions[], tabs UI, session-aware MCP.The model
A session is a connection plus everything configured around it — which is exactly what
ProfileConfigalready held. The persisted seam existed; the runtime didn't:Appwas aSessionand 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 onAppDataManager.Appkeeps what exists once per window — app data and presets, snackbar, sound player, performance monitor, updater, MCP, main pane, CPU monitor — plussessions: Session[]andactiveSessionId. 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 theApp— the six settings classes,ConnControllerand 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.SettingsBranchattaches to a smallConfigHostinterface (config,registerOnConfigReload,saveAppData) thatSessionimplements.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 freshAppData. Order, names and the active session survive a restart. New rows go in as plain objects (makeSessionData) so their settings are observable — the same trapAppDataManagerguards 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_sessionsis new.get_terminal_output,send_data,get_connection_statustake an optionalsession(id or case-insensitive name), defaulting to the active one.send_datagoes 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.getActivePortPathis no longer used by MCP.ninjaterm://sessions/{id}/rxstream(a resource template, listable), one bounded buffer per NinjaTerm session per MCP session.ninjaterm://terminal/rxstreamstill 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-profilegeneralSettings(two clipboard preferences) stay per session; the genuinely app-wide general settings were already at theappDataroot.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 resolutionSessions.spec.tse2e (3): tab strip new/switch/close with per-session baud rate; drag-to-reorder; RX data lands in the owning session, not the active oneAppDataManager.spec: v24→v25 asserts the session wrap; all snapshot upgrades compare with normalised idsAppDataManagernow build againstapp.activeSession; spies target the sessionnpx tscclean ·npm run lint0 errors · 506/506 unit · 92/92 e2e · snapshot preflight OK