Commit Graph

531 Commits

Author SHA1 Message Date
Brian Krabach d955c90c0b feat: add openLoginPopup function and delegated click handler for auth tile login buttons
- Add openLoginPopup(remoteUrl) function after buildOfflineTileHTML that strips
  trailing slashes from remoteUrl before appending /login and opens a popup
  window with width=500,height=600
- Wire up delegated click handler for .source-tile__login-btn buttons inside
  bindStaticEventListeners, right after the existing delegated kill-session handler
- Export openLoginPopup from module.exports

Tests: 4 new tests covering openLoginPopup export, window.open call
with correct URL and dimensions, trailing slash handling (with and without)
2026-03-31 03:20:21 -07:00
Brian Krabach ebec7c3625 fix: fit view — defer layout measurement to rAF, stretch pre to fill tile
Bug 1: applyFitLayout measured parentElement.clientHeight before the
browser reflowed the DOM — returned 0 on first render. Fix: wrap in
requestAnimationFrame so measurement happens after layout pass.
Applies to all three call sites: renderGrid(), applyDisplaySettings(),
and the window resize handler.

Bug 2: .tile-body pre had position:absolute bottom:0 but no top:0.
In fit mode (taller tiles), content sat at the bottom with a gap above.
Fix: .session-grid--fit .tile-body pre { top: 0; overflow-y: auto }
2026-03-31 03:19:37 -07:00
Brian Krabach 2862f494f5 feat: integrate source status tiles into renderGrid
- Append auth tiles for auth_required sources after session tiles
- Append offline tiles for unreachable sources after session tiles
- _setSources test helper was already defined and exported (verified)
- All 197 tests pass (195 pre-existing + 2 new)
2026-03-31 03:11:47 -07:00
Brian Krabach bf87f05d82 test: add formatLastSeen branch coverage for seconds, hours, and days 2026-03-31 03:06:29 -07:00
Brian Krabach fe5337840d refactor: remove Compact view mode — keep Auto + Fit only 2026-03-31 03:05:18 -07:00
Brian Krabach e07cf196c6 feat: add formatLastSeen and buildOfflineTileHTML functions
- Add formatLastSeen(ms) to format millisecond timestamps into relative
  strings (Xs ago, Xm ago, Xh ago, Xd ago, Never for null)
- Add buildOfflineTileHTML(source) to render unreachable device tiles
  with Offline badge and last-seen timestamp
- Both functions added after buildAuthTileHTML in app.js
- Both exported via module.exports
- 7 new tests covering export, CSS class, device name, badge, last-seen,
  HTML escaping, and null handling
2026-03-31 02:45:36 -07:00
Brian Krabach 83e5318ba1 feat: add buildAuthTileHTML for auth-required federation tiles
- Add buildAuthTileHTML(source) function to frontend/app.js after buildSidebarHTML
- Function renders an <article class='source-tile source-tile--auth'> with device name,
  login button (with data-url), and hint text
- HTML-escapes both name and url to prevent XSS
- Export buildAuthTileHTML under '// Federation tiles' comment in module.exports
- Add 5 tests covering: export, article class, device name, login button data-url, HTML escaping

Task: task-2-build-auth-tile-html
2026-03-31 02:37:05 -07:00
Brian Krabach 55c80b4c9b refactor: move intra-function imports to module level in test_frontend_css 2026-03-31 02:31:54 -07:00
Brian Krabach 38a032b2d5 feat: add CSS for source-tile offline and auth-required states
Add Phase 3 source tile component CSS rules to style.css, inserted
before the @media (prefers-reduced-motion) block as specified.

Rules added:
- .source-tile: base flex column layout (centered, 12px gap, 24px padding)
- .source-tile--offline: opacity 0.45, dashed border
- .source-tile--offline .source-tile__name: var(--text-dim) color
- .source-tile--offline .source-tile__badge: var(--err) bg, bold, uppercase
- .source-tile--offline .source-tile__last-seen: 11px font, dim color
- .source-tile--auth: var(--warn) border-color, dashed border
- .source-tile__name: 15px/600 font, var(--text) color
- .source-tile__login-btn: accent bg, 8px 20px padding, opacity transition
- .source-tile__login-btn:hover: opacity 0.85
- .source-tile__login-btn:focus-visible: 2px solid accent outline
- .source-tile__hint: 11px font, var(--text-muted) color

grep -c 'source-tile' style.css returns 11 lines (all required selectors present).

Tests: 15 new tests added to test_frontend_css.py covering all selectors,
properties, positioning before reduced-motion block, and brace balance.
All 150 CSS tests pass.
2026-03-31 02:23:24 -07:00
Brian Krabach 7100fd881e style: apply ruff formatting to test_frontend_css.py (wrap long assertion) 2026-03-31 02:13:10 -07:00
Brian Krabach 918d92386f test: add Phase 2 integration tests — export verification and e2e pipeline (task-19) 2026-03-31 01:56:05 -07:00
Brian Krabach a9e1206ac6 style: restore ES6 syntax in detectBellTransitions and update JSDoc 2026-03-31 01:49:56 -07:00
Brian Krabach c7c92ee0da feat: use sessionKey for cross-device dedup in detectBellTransitions (task-18)
Replace s.name with s.sessionKey || s.name as the map key in
detectBellTransitions so two sessions with the same name on
different devices are tracked independently.

- prevMap construction uses s.sessionKey || s.name as key
- next filter lookup uses the same s.sessionKey || s.name key
- Falls back to s.name when no sessionKey is present (backward compatible)

Co-authored-by: Amplifier <amplifier@example.com>
2026-03-31 01:37:49 -07:00
Brian Krabach 2b5b6e3003 feat: skip connect and terminal mount for remote sessions in openSession
When opts.sourceUrl is non-empty (remote session), skip the POST
/api/sessions/{name}/connect call and skip window._openTerminal(name).
Remote terminal connections are deferred to Phase 3.
Local sessions (empty sourceUrl) continue to work as before.

Co-authored-by: Amplifier <amplifier@amplified.dev>
2026-03-31 01:31:09 -07:00
Brian Krabach 70b8df1458 feat: sidebar device grouping when multiple sources configured (task-16)
- Replace renderSidebar to group sessions by deviceName when _sources.length > 1
- Render sidebar-device-header h4 elements before each device's sessions
- When single source configured, render flat list with no headers
- Click handlers now pass sourceUrl to openSession
- Add tests: groups with header when multiple sources, flat when single source

🤖 Generated with Amplifier

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
2026-03-31 01:16:21 -07:00
Brian Krabach 88102751c8 style: fix code quality issues from review for task-15 remote instances UI
- Deduplicate CSS: merge shared properties of .settings-remote-url and
  .settings-remote-name into a combined selector, keeping only flex
  values in individual rules. Reduces 18 lines to 10.

- Fix remove button hover color: .settings-remote-remove:hover now uses
  #ef4444 (red) and rgba(239, 68, 68, 0.1) background, consistent with
  .tile-delete:hover and .sidebar-delete:hover for destructive actions.

- Add aria-label attributes to urlInput and nameInput in
  _buildRemoteInstanceRow for screen-reader accessibility:
  'Remote instance URL' and 'Remote instance display name'.

- Add 2 tests to verify aria-label attributes are set on both inputs
  (test_build_remote_instance_row_url_input_aria_label,
  test_build_remote_instance_row_name_input_aria_label).

All 615 tests pass.

Co-authored-by: Amplifier <amplifier@sourcegraph.com>
2026-03-31 01:09:27 -07:00
Brian Krabach c8a963f28e feat: add Remote Instances management UI to Settings (task-15) 2026-03-31 00:55:26 -07:00
Brian Krabach 200137a995 feat: add view mode and scope selectors to Display settings tab
Task: task-14 Settings dialog — view mode selector and scope toggle
2026-03-31 00:40:51 -07:00
Brian Krabach b2ff3613de feat: add loadGridViewMode and saveGridViewMode with local/server scope
- Add loadGridViewMode() that reads grid view mode preference based on
  viewPreferenceScope in display settings: returns gridViewMode from
  localStorage display settings when scope is 'local' (default), or
  grid_view_mode from _serverSettings when scope is 'server'. Returns
  'flat' as default when no preference is set.
- Add saveGridViewMode(mode) that saves to appropriate scope (localStorage
  via saveDisplaySettings when local, patchServerSetting when server)
  and updates _gridViewMode module variable.
- Wire loadGridViewMode() into DOMContentLoaded startup after applyDisplaySettings
  so _gridViewMode is initialized from stored preference on page load.
- Export both functions from module.exports for testing.

Closes task-13
2026-03-31 00:33:34 -07:00
Brian Krabach 393891173f fix: improve test assertion precision and add null guard in renderFilterBar
- Fixed imprecise pill count assertion in test_app.mjs by changing /filter-pill/g regex to /<button/g to accurately count button elements without double-counting when active pill has both classes
- Removed redundant OR fallback in active pill test, now relying only on specific regex for Laptop pill
- Added defensive null guard 'allSessions = allSessions || []' at entry of renderFilterBar in app.js to prevent TypeError

🤖 Generated with Amplifier

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
2026-03-31 00:26:12 -07:00
Brian Krabach 5738c39f7f feat: add filtered view mode with device pill bar (task-12)
- Add <div id="filter-bar" class="filter-bar"> to index.html before session-grid div
- Implement renderFilterBar(container, allSessions) that renders pill buttons
  for each unique device name plus an 'All' button
- Active device pill gets filter-pill--active class
- Add _setActiveFilterDevice(device) test helper
- Bind delegated click handler on filter-bar in bindStaticEventListeners
  that sets _activeFilterDevice and re-renders grid
- Export renderFilterBar and _setActiveFilterDevice

Co-authored-by: Amplifier <amplifier@amplified.dev>
2026-03-31 00:16:15 -07:00
Brian Krabach 2e8cf6ddee feat: add grouped view mode to renderGrid with device-group-header sections
- Add renderGroupedGrid(sessions, mobile) that groups sessions by deviceName
  and creates <h3 class="device-group-header"> headers for each group
- Rewrite renderGrid to: apply device filter in 'filtered' mode, apply sort
  order, call renderGroupedGrid when _gridViewMode === 'grouped', render
  filter bar in 'filtered' mode, bind click handlers with sourceUrl
- Add _setGridViewMode(mode) test-only helper
- Export renderGroupedGrid and _setGridViewMode from module.exports
2026-03-31 00:00:34 -07:00
Brian Krabach 300919c7d7 feat: device badge on sidebar items in buildSidebarHTML (task-10) 2026-03-30 23:49:31 -07:00
Brian Krabach 4084544530 refactor(task-9): extract badgeHtml const and tighten device badge tests
- Extract inline ternary for device badge into `const badgeHtml` variable
  above the return block, consistent with how `bellHtml` is handled
- Tighten data-session-key/data-source-url test assertions to check exact
  attribute values rather than just attribute presence
- Add XSS test: verifies deviceName containing HTML is escaped in the badge

All 159 tests pass.
2026-03-30 23:41:50 -07:00
Brian Krabach 5980a6c080 feat: add device badge and data attributes to buildTileHTML (task-9)
- Show <span class="device-badge"> after tile name when _sources.length > 1
  and session.deviceName is present (multi-source federation context)
- Add data-session-key and data-source-url attributes to tile article
  element for unique session identification across sources
- Tests: 3 new tests covering badge visibility, badge omission for single
  source, and presence of new data attributes
2026-03-30 23:34:22 -07:00
Brian Krabach d897c05c61 feat: add device-badge, group-header, filter-bar, and sidebar-device-header CSS classes 2026-03-30 23:29:30 -07:00
Brian Krabach 4ed8303b6e feat: update getVisibleSessions to only hide local sessions by name
- Replace getVisibleSessions filter logic: only hide sessions where
  sourceUrl is empty/absent AND name matches hidden_sessions list
- Remote sessions with the same name as a hidden local session now
  remain visible (task-7 spec requirement)
- Export getVisibleSessions in module.exports so tests can access it

Tests added:
- 'getVisibleSessions exported and filters hidden sessions': verifies
  export and that local hidden sessions are filtered
- 'getVisibleSessions hides local sessions by name but not remote
  sessions with same name': verifies remote sessions survive

All 155 tests pass.
2026-03-30 23:22:55 -07:00
Brian Krabach 48e87af3f8 feat: wire buildSources into loadServerSettings startup
After fetching /api/settings and caching in _serverSettings,
call _sources = buildSources(_serverSettings) so the polling
layer immediately knows which sources to query.

Implements task-6 of multi-device federation phase 1.
2026-03-30 23:14:48 -07:00
Brian Krabach e95a8d4282 refactor: improve pollSessions error handling and test coverage 2026-03-30 23:09:08 -07:00
Brian Krabach e7ed300b37 feat: rewrite pollSessions for multi-source parallel polling (task-5) 2026-03-30 22:59:08 -07:00
Brian Krabach 593f1639db style: align tagSessions and mergeSources with ES6 file conventions 2026-03-30 22:52:36 -07:00
Brian Krabach 55f9597e1a feat: add tagSessions and mergeSources for multi-source parallel polling
These two functions enable multi-source session federation:
- tagSessions(sessions, deviceName, sourceUrl): tags each session with
  deviceName, sourceUrl, and sessionKey (format: sourceUrl::name),
  returns new objects without mutating originals
- mergeSources(results): takes [{source, sessions}] objects, tags each
  source's sessions and concatenates into a single flat array

Both functions are exported in module.exports.
6 new tests added covering all specified behaviors.
2026-03-30 22:42:55 -07:00
Brian Krabach 07c61a0baf style: expand test-only helper bodies to match section formatting 2026-03-30 22:37:08 -07:00
Brian Krabach 844311b475 feat: add federation state globals and test-only helpers to app.js
Add new module-level globals:
- let _gridViewMode = 'flat'
- let _activeFilterDevice = 'all'

Add test-only helper functions:
- _setSources(sources): sets internal _sources array
- _setServerSettings(settings): sets internal _serverSettings
- _getGridViewMode(): returns current _gridViewMode value
- _getSources(): returns current _sources array

All 4 helpers exported in module.exports.

Tests added (all passing, 143/143):
- '_setSources sets internal _sources array'
- '_setServerSettings sets internal _serverSettings'
- '_getGridViewMode returns current _gridViewMode value'
- '_getSources returns current _sources array'

Task: task-3 (federation state helpers)
2026-03-30 22:29:30 -07:00
Brian Krabach 8c0675157a feat: three dashboard view modes — Auto, Fit, Compact
Auto: current behavior (auto-fill grid, fixed tile height, scrollable).
Fit: calculates cols × rows to fill viewport exactly, zero scroll.
Compact: 80px tiles, high density, auto-fill with 200px min-width.

Toggle button (▦) in overview header cycles modes. Fit recalculates
on window resize. View mode persisted in localStorage alongside other
display settings (viewMode: 'auto' default in DISPLAY_DEFAULTS).

- CSS: .session-grid--fit and .session-grid--compact modifiers
- JS: VIEW_MODES, cycleViewMode(), applyFitLayout() functions
- HTML: #view-mode-btn between + and ⚙ in overview header
- Tests: 8 new JS tests, 3 CSS tests, 1 HTML test all passing
2026-03-30 22:22:59 -07:00
Brian Krabach ecf57441cf feat: add buildSources to construct session source list from settings
🤖 Generated with Amplifier

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
2026-03-30 22:21:45 -07:00
Brian Krabach 93c5170581 feat: refactor api() to accept optional baseUrl for cross-origin requests
Add 4th parameter `baseUrl` to `api()`. When provided, strips trailing
slash and prepends to path, and sets `credentials: 'include'` for
cross-origin cookie sending. Behavior is unchanged when no baseUrl is
given (backward compatible). Export `api` in module.exports.

All 135 tests pass.

🤖 Generated with Amplifier <https://github.com/microsoft/amplifier>

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
2026-03-30 22:12:57 -07:00
Brian Krabach 3a102ba9d8 fix: add 18px font option, click-outside-dialog to dismiss settings
Added 18px to font size select. Dialog click handler checks
e.target === settingsDialog (click landed on ::backdrop area,
not dialog content) and closes settings.
2026-03-30 22:07:38 -07:00
Brian Krabach d0eb91dca7 refactor: replace fixed sleeps with deterministic polling in ws proxy tests; document CORS permissiveness 2026-03-30 21:56:05 -07:00
Brian Krabach b1cbeeb02c test: expand WebSocket proxy test suite 2026-03-30 21:47:17 -07:00
Brian Krabach 0e02181477 feat: add CORS middleware for cross-origin federation 2026-03-30 21:47:17 -07:00
Brian Krabach ca0eb44b88 feat: add GET /api/instance-info endpoint
Implement new public endpoint that returns device name and version without authentication required. The auth exemption was already in place from task 4.
2026-03-30 21:47:17 -07:00
Brian Krabach e61efd141c feat: exempt /api/instance-info from auth 2026-03-30 20:54:21 -07:00
Brian Krabach 395278818f feat: add remote_instances and device_name to settings
- Add 'remote_instances': [] to DEFAULT_SETTINGS for peer instance configs
- Add 'device_name': '' to DEFAULT_SETTINGS (empty for clean JSON serialization)
- Add import socket to settings.py
- In load_settings(), fill empty device_name with socket.gethostname() so the
  hostname is always current even if the machine is renamed
- Add 7 new tests covering defaults, hostname fallback, round-trips, and
  mutation isolation
- Update 2 existing tests that compared result == DEFAULT_SETTINGS to account
  for the hostname fill-in behavior

Co-authored-by: Amplifier <amplifier@amplified.dev>
2026-03-30 20:48:38 -07:00
Brian Krabach e94a27d2f8 chore: remove stale requirements.txt 2026-03-30 20:42:57 -07:00
Brian Krabach c049ad5628 chore: remove dead Caddyfile 2026-03-30 20:39:34 -07:00
Brian Krabach a5b02b74d2 Add multi-device federation design document
Covers:
- Backend settings & remote instance registry
- Frontend multi-origin API layer with parallel polling
- View modes (flat/grouped/filtered) & device tagging
- Remote auth flow (per-instance browser auth)
- Terminal connection for remote sessions (direct WebSocket)
- Unreachable instance handling with exponential backoff
- Cleanup: remove Caddyfile, requirements.txt, expand WS proxy tests
2026-03-30 20:04:13 -07:00
Brian Krabach 70da8dad38 fix: don't clear bells when browser tab is hidden
sendHeartbeat() always reported _viewingSession even when the user
switched to another browser tab. The server saw 'device is watching
session X' and cleared bells immediately. Fix: use Page Visibility API
(document.hidden) to send viewing_session=null when the tab is in the
background. Bells accumulate correctly, favicon badge shows activity,
and indicators appear in the dashboard/sidebar. When the user switches
back to the muxplex tab, the next heartbeat restores the real session.
2026-03-30 19:03:27 -07:00
Brian Krabach 79576bcbfe feat: customizable delete session command template
Symmetric with create template. Default: 'tmux kill-session -t {name}'.
Configurable in Settings → Commands tab (renamed from 'New Session').
DELETE /api/sessions/{name} reads template from settings, substitutes
{name}, runs synchronously via subprocess.run with 30s timeout.

Enables custom teardown workflows like:
  amplifier-dev ~/dev/{name} --destroy

Changes:
- settings.py: add delete_session_template to DEFAULT_SETTINGS
- main.py: DELETE endpoint uses subprocess.run + template instead of run_tmux
- index.html: add delete template textarea + reset btn; rename tab to Commands
- app.js: DELETE_SESSION_DEFAULT_TEMPLATE constant, openSettings loads it,
  bindStaticEventListeners wires input/reset; constant exported

Tests added:
- test_settings.py: 3 tests for default, load, and patch of delete_session_template
- test_api.py: 2 tests for custom/default template substitution via subprocess mock;
  update existing test_delete_session_calls_kill_session to match new implementation
- test_frontend_html.py: 5 tests for textarea, placeholder, rows, reset btn, tab label
- test_app.mjs: 5 tests for constant definition, value, and wiring in openSettings/bindStaticEventListeners
2026-03-30 17:17:34 -07:00
Brian Krabach 2a30e88feb fix: launchd plist includes PATH with Homebrew + user local bin
launchd agents run with minimal PATH (/usr/bin:/bin:/usr/sbin:/sbin).
Homebrew binaries (tmux, ttyd) in /opt/homebrew/bin and uv tool installs
in ~/.local/bin were not found, causing _check_dependencies() to exit(1).
Plist now includes EnvironmentVariables with a PATH that covers both
Apple Silicon and Intel Homebrew locations + ~/.local/bin.
2026-03-30 16:39:02 -07:00