Skip to content

feat(workspace): theme switch — light / dark / system at the top right of the central column (abilityai/trinity-enterprise#625) - #2841

Merged
vybe merged 5 commits into
devfrom
feature/625-workspace-theme-switch
Sep 16, 2026
Merged

vybe merged 5 commits into
devfrom
feature/625-workspace-theme-switch

Conversation

@dolho

@dolho dolho commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Fixes abilityai/trinity-enterprise#625

Summary

The Workspace is styled for both themes and follows the global useThemeStore, but its only control was the NavBar's appearance menu and the Workspace has no NavBar — a platform user could not change the theme from the Workspace, and an external client (no platform session, no stored preference) could not change it at all. This adds the switch, at the top right of the central column, driving the same store and key the platform UI uses.

  • PortalThemeSwitch.vue — trigger whose icon and label show the resolved theme ("System · dark", "Light", "Dark"; icon-only below sm) over a popover; Esc + click-outside close, focus returns to the trigger. Imports useThemeStore only — never auth / agents / clientPortal — so a client session gets it (pinned).
  • base/ThemeChoice.vue (+ ThemeIcon.vue) — the ONE light/dark/system picker: radiogroup of role="radio" buttons with aria-checked, roving tabindex, arrow keys. The NavBar's inline raw-palette picker is replaced by it, so the two cannot drift; NavBar's raw-colour entry shrinks 35 → 23 non-gray (re-frozen exactly, scoped to that entry and named in the baseline — the bug(subscriptions): a Workspace message on a rate-limited subscription fails instead of switching and completing — close the SUB-003 gaps on the turn path #2638 shape). The new files carry zero non-gray palette classes.
  • Placement — a #header-end slot at the tail of both column headers (PortalConversation.vue, PortalRoom.vue), filled by views/Portal.vue: new chat, thread, agent landing (one branch since ent#523) and room; the stage skeleton heads the branch chain and gets none. Terminal stage states (unavailable / error / unreachable) have no header and are left alone.
  • Stability — only the root dark class flips; the slot carries no :key, so scroll, composer draft and the active thread survive a switch. The popover is absolutely anchored to the header's right edge, so it widens nothing.
  • utils/themeSwitch.js — the decidable half (options, resolved theme, label, icon, aria label).

Test harness (own commit)

AC #8 asks for a test in which a click reaches setTheme. The suite is environment: 'node' with no mount harness, and a regex over the SFC cannot prove a click (#2829's rule) — so vitest.config.js gains @vitejs/plugin-vue and a spec may opt into jsdom per file (// @vitest-environment jsdom); the default stays node. Dev-only deps jsdom + @vue/test-utils; lock regenerated lock-only with the image's npm (node:26) so the diff is those two and their tree (57 entries, none with install scripts; npm audit unchanged at dev's one pre-existing low). npm 11 also drops a stale root dependencies line for @rollup/rollup-linux-arm64-musl (package.json declares it under optionalDependencies, where it stays). @vue/test-utils 2.5 pulls js-beautify→nopt, whose engines name node 22+ — a warning under npm ci on CI's node 20 (verified: the same path my local node 20 run took), not a failure.

tests/unit/portalThemeSwitch.spec.js is the suite's first mounted component test: renders "System · dark" from an empty store, opens to three checked/unchecked radios, a click calls setTheme('dark'), writes trinity-theme, flips the root class, closes and re-labels the trigger; a NavBar choice is reflected here; Esc and click-outside close; arrow keys and roving tabindex on ThemeChoice; plus source guards for the slot placement, the two fills, the no-session-dependency rule and the NavBar consuming the primitive.

Mutation: click never reaches the store → 1 red · label hides the resolved state → 2 red · Esc ignored → 1 red · aria-checked frozen → 2 red.

Verified in a browser (Chromium, worktree dev server against the local backend)

Light and dark, both with the popover open; system resolving honestly; 390px viewport → icon-only 32px trigger, no collision with the title band; Enter opens, Tab lands on the checked radio, ArrowLeft selects; focus returns to the trigger after a choice.

Acceptance criteria

AC Where
1 top-right of the central column, every stage state with a header Portal.vue two #header-end fills; slot in both headers
2 same three choices, same useThemeStore, no second store/key PortalThemeSwitch.vue → themeStore.setTheme; spec a choice made elsewhere … is reflected here
3 system default, resolved state shown honestly themeSwitch.js::themeSwitchLabel → "System · dark"; spec
4 works for an external client imports the theme store only; source guard
5 no scroll / draft / thread reset root-class flip only, slot without :key
6 both themes, tokens only, no baseline entry new files at 0 non-gray; ratchet green; NavBar entry shrinks
7 keyboard + accessible name + current choice announced aria-label="Theme: …", radiogroup/radio/aria-checked, roving tabindex, Esc
8 unit test: renders in header, three options, click → setTheme, current reflected portalThemeSwitch.spec.js (mounted)

Test plan

  • cd src/frontend && npm run test:unit → 137 files / 3083 passed
  • npm run check:tokens OK; raw-colour ratchet 14/14; vite build green
  • Browser pass above (both themes, narrow, keyboard)

Docs: requirements/core-agent.md §5.33 (WORKSPACE_THEME_SWITCH), feature-flows/dark-mode-theme.md (Workspace switch section + entry point), feature-flows.md index row, architecture/workspace.md (compact-header section).

Cross-tracker: Fixes cross-references the private issue but does not auto-close it — closed manually at release.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf

@dolho dolho added the ui PR touches the frontend UI — triggers Playwright e2e tests label Sep 16, 2026
@dolho

dolho commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

/review Report

Branch: feature/625-workspace-theme-switch → dev (merge-base 3360e8aee, head 1d74ad203)
Files Changed: 18 (+1338/−38; 776 of the additions are the lockfile)
Scope: CLEAN — one named drift (below)
Plan Completion: 8 ACs → 7 DONE, 1 CHANGED

AC Status Evidence
1 top-right of the central column, every stage state that renders it CHANGED Portal.vue fills #header-end on the conversation branch (new chat + thread + agent landing, one branch since ent#523) and the room; slots at PortalConversation.vue:172, PortalRoom.vue:81. The three terminal stage states (unavailable / error / unreachable agent, STAGE_WRAP divs) have no header and get no switch. Deliberate: the issue enumerates the four states with a header; a person on a dead-end card can still reach the switch from the sidebar's next click. Say if you want it there too — it is one <div class="absolute top-3 right-3"> per arm.
2 same three choices, same useThemeStore DONE PortalThemeSwitch.vue:60 themeStore.setTheme(value); spec a choice made elsewhere (the NavBar) is reflected here — no second store
3 honest default DONE themeSwitch.js::themeSwitchLabel → System · dark; spec renders it from an empty store
4 no session dependency DONE PortalThemeSwitch.vue imports @/stores/theme only; source guard `not.toMatch(/stores/(auth
5 no scroll/draft/thread reset DONE only document.documentElement.classList flips (stores/theme.js:41-45); the slot carries no :key (Portal.vue:271-274, :406-409)
6 both themes, tokens only, no baseline entry DONE new files at 0 raw non-gray; ratchet 14/14; NavBar 35→23 re-frozen exactly (raw-color-baseline.json _ent625_note)
7 keyboard + accessible name + announced choice DONE aria-label="Theme: …" (:16), radiogroup/radio/aria-checked (ThemeChoice.vue:11-19), roving tabindex, Esc + focus return (:63-77)
8 unit test renders / three options / click → setTheme / current reflected DONE portalThemeSwitch.spec.js mounted — clicking an option calls setTheme…

Critical Findings

None.

Informational Findings

[I1] Scope: NavBar copy changed "Auto" → "System" (Confidence: 9/10)
NavBar.vue:243 now renders ThemeChoice, whose third label is System (the issue's own word and the Workspace's). The user-menu button used to read Auto. Tiny, but it is a visible change on a surface the issue does not name — flagging so it is a decision, not a side effect.

[I2] Room header at narrow widths not screenshotted (Confidence: 6/10)
The browser pass covered the conversation header at 1280 and 390px. The room header carries star + "+ Add agent" + an optional budget notice (PortalRoom.vue:60-71, truncate) before the switch; at ~640–700px with a notice present the strip could tighten. Below sm the switch is icon-only (32px), so a collision is bounded, but I did not look. Worth one glance in the browser on a room with a budget notice.

[I3] Test harness now applies @vitejs/plugin-vue suite-wide (Confidence: 8/10)
vitest.config.js:19 registers the plugin for every spec, not only jsdom ones. Harmless for .js modules (3083 → 3084 passed, 4.1 s), and it is what lets a node-environment spec import an SFC for source guards later — but a future spec that imports an SFC in node will get a real component object, not a string, so the readFileSync guards should keep reading files, not importing them.

[I4] @vue/test-utils 2.5 pulls a node-22 engines transitive (Confidence: 9/10)
js-beautify@2 → nopt@10 / abbrev@5 declare node ^22.22.2 || ^24 || >=26. CI's frontend-build / frontend-e2e run npm ci on node 20 — a warning, not a failure (no engine-strict; my node 20 install and run took the same path). If it ever bites, pinning @vue/[email protected] (js-beautify ^1) is the fix; noted so the first EBADENGINE line in a CI log is not a mystery.

[I5] Pre-existing doc drift (Confidence: 8/10)
feature-flows/dark-mode-theme.md "Entry Points" cites NavBar.vue:81-98 / :135-168 — those line numbers predate this PR and were already wrong. I added the Workspace entry and left the stale numbers; a /sync-feature-flows pass owns the rest.

Clean Categories

  • SQL / concurrency / auth / credential exposure: no backend surface, no request, no secret; diff greps for keys/emails/IPs empty.
  • Conditional side effects: setTheme runs unconditionally on select; listeners are armed in onMounted (above any await) and removed in onBeforeUnmount.
  • Frontend: no v-html; no API call, so no loading/error state to own; the popover is absolute off the header's right edge, so opening it shifts nothing; hidden sm:inline label folds cleanly (measured 32px trigger at 390px).
  • Dead code: every export of themeSwitch.js has a consumer (THEME_IDS/normalizeTheme inside the module + spec, the rest in PortalThemeSwitch.vue).
  • Enum completeness: THEME_OPTIONS ids are exactly the store's accepted set (stores/theme.js:13); normalizeTheme folds anything else to system, matching getStoredTheme.
  • Supply chain: 57 new dev-only lock entries, none hasInstallScript; npm audit = dev's one pre-existing low; lock regenerated with the image's npm so the diff is only the two deps (+ npm 11 dropping a stale root line for an optionalDependencies entry, which stays declared).
  • Design contract: tokens only in the new files (action-primary-*, gray ladder, gray-750); dark meta text is gray-300/400, never 500 as ink; 4px grid; focus ring on both the trigger and every radio.

Coverage question (#2829)

Executed. The spec mounts the real components (@vue/test-utils, per-file jsdom) and drives them: click → setTheme('dark') → trinity-theme written → root dark class → menu closed → trigger re-labelled; NavBar-side setTheme('light') → Workspace trigger reads "Light"; Esc and outside click; arrow keys select and move focus (added in 1d74ad203 after a probe confirmed the function ref lands in the array — Vue auto-unwraps the top-level ref in the template); roving tabindex. Mutations: click never reaches the store → 1 red · label hides the resolved state → 2 red · Esc ignored → 1 red · aria-checked frozen → 2 red. The only source-text assertions are the placement/consumer guards (slot inside <header>, two fills, no-session-dependency import rule, NavBar consuming the primitive) — guards, not coverage, by design.

Learnings captured

docs/memory/learnings.md — regenerating the lock with a different npm major rewrites libc/optional fields the diff then blames on the PR; regenerate lock-only with the image's npm and read the removals.

Summary

  • Critical: 0
  • Informational: 5 — I1 is a copy decision for you; I2 is one browser glance; I3–I5 are awareness.
  • Scope: clean (I1 named).

Next: /validate-pr 2841 for the process/docs gate once the live frontend-e2e run lands (the report fail on the PR is the benign cancelled duplicate from creating the PR with the ui label).

dolho and others added 3 commits September 16, 2026 13:03
…s, opt-in per file

`vitest.config.js` stays `environment: 'node'` for the pure-rules suite and
gains `@vitejs/plugin-vue`, so a spec that must MOUNT an SFC opts into jsdom
with a leading `// @vitest-environment jsdom`. First consumer: the Workspace
theme switch (trinity-enterprise#625), whose AC asks for a click that reaches
`setTheme` — a regex over the SFC cannot prove a click (#2829). Dev-only
deps; the lock was regenerated lock-only with the image's npm (node:26) so
the diff is the two packages and their tree (57 entries, none with install
scripts, `npm audit` unchanged at dev's one pre-existing low). npm 11 also
drops a stale root `dependencies` line for `@rollup/rollup-linux-arm64-musl`,
which package.json declares under `optionalDependencies` (it stays there).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf
…t of the central column (trinity-enterprise#625)

The Workspace followed the global theme with no way to change it — its only
control was the NavBar's appearance menu, and the Workspace has no NavBar. A
platform user could not switch from the Workspace; an external client with no
stored preference could not switch at all.

- `components/portal/PortalThemeSwitch.vue`: trigger showing the RESOLVED
  theme (icon + "System · dark" / "Light" / "Dark"; icon-only below `sm`) over
  a popover; Esc + click-outside close, focus returns to the trigger. Reads
  and writes `useThemeStore` only — no auth/agents/clientPortal import — so a
  client session gets it. One store, one key: a choice here is what the
  platform UI shows next, and vice versa.
- `components/base/ThemeChoice.vue` (+ `ThemeIcon.vue`): the ONE
  light/dark/system picker — `radiogroup` of `role="radio"` buttons with
  `aria-checked`, roving tabindex, arrow keys. The NavBar's inline raw-palette
  picker is replaced by it (its raw-colour entry shrinks 35 → 23 non-gray,
  re-frozen exactly and named in the baseline); the new files stay at zero.
- `#header-end` slot at the tail of both column headers
  (`PortalConversation.vue`, `PortalRoom.vue`), filled by `views/Portal.vue`
  — new chat, thread, agent landing and room; the skeleton heads the branch
  chain and gets none. Only the root `dark` class flips and the slot carries
  no `:key`, so scroll, draft and thread survive a switch.
- `utils/themeSwitch.js`: the decidable half, executed.
- `tests/unit/portalThemeSwitch.spec.js`: the suite's first MOUNTED component
  test — renders "System · dark" from an empty store, three checked/unchecked
  radios, a click calls `setTheme('dark')`, writes `trinity-theme`, flips the
  root class, closes and re-labels; a NavBar choice is reflected. Mutations
  (click never reaches the store / label hides the resolved state / Esc
  ignored / aria-checked frozen) → red.

Verified live in Chromium on a dev server: light, dark, `system` resolving
honestly, icon-only at 390px with no collision, Enter opens, Tab lands on
the checked radio, ArrowLeft selects.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01VpvcfgWkmQPD7DrDLmATTf
@dolho
dolho force-pushed the feature/625-workspace-theme-switch branch from 1d74ad2 to f0d34a0 Compare September 16, 2026 10:03
@dolho
dolho requested a review from vybe September 16, 2026 10:08
sim and others added 2 commits September 16, 2026 15:08
…th entries kept (dev's first)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ityai/trinity-enterprise#625)

merge-train finding. The popover closed on Escape from a bubble-phase
`document` listener and never marked the event. The conversation's own
`document` listener cancels an in-flight turn, or ends a live voice call, on
any Escape nobody claimed, so closing the menu mid-turn also killed the turn.
That is the #2582/#2598 class in learnings.md.

The popover now follows the same protocol as PortalFilePreview and
PortalRailFiles. It listens in the capture phase, returns early on
`defaultPrevented`, and calls `preventDefault()` only while the menu is open.
With the menu closed it claims nothing, so Escape still cancels.

Tests:
- A mounted test runs the conversation's real `shouldCancelOnEscape` and
  `shouldEndCallOnEscape` against the same keystroke, with the menu open
  (both false) and closed (both true).
- A second test checks that an earlier owner's claim leaves the menu open.
- The "choose dark" test now clears the `dark` class first. `system` already
  resolved dark in beforeEach, so the assertion used to hold before the click.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@vybe

vybe commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

merge-train 2026-09-16: two commits pushed to this branch. Both are mechanical, and this PR stays on the train.

  1. d797d97a merges dev. The only conflict was the learnings.md append collision. Both entries are kept, dev's first.
  2. c0284654 makes the theme menu claim the Escape that closes it. Review found that the popover closed on Escape from a bubble-phase document listener without marking the event. PortalConversation.vue:1837 cancels an in-flight turn, or ends a live call, on any unclaimed Escape. So dismissing the menu mid-turn also killed the turn. That is the bug(workspace): uploads reach the Files tab only after the agent replies; own uploads not downloadable; image download opens inline #2582/bug(workspace): Escape during a voice call ends the call even when an overlay already claimed it #2598 class in learnings.md.
    • Fix. PortalThemeSwitch.vue now uses the protocol PortalFilePreview and PortalRailFiles already use. It listens in the capture phase, returns on defaultPrevented, and calls preventDefault() only while the menu is open.
    • Tests. A mounted test runs the conversation's real shouldCancelOnEscape and shouldEndCallOnEscape on the same keystroke. With the menu open both return false, and with it closed both return true. A second test checks that an earlier owner's claim leaves the menu open.
    • Also fixed. The "choose dark" test now clears the dark class before the click. system already resolved dark in beforeEach, so that assertion held before the click too.

Docker was down locally, so the new spec is proven by this branch's frontend-build run rather than a local vitest run.

Still open for after merge: status-in-dev on ent#625 has to be set by hand, because a cross-tracker keyword does not relabel. Not from this PR, but worth knowing: stores/theme.js reads and writes localStorage without try/catch.

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train 2026-09-16: validated at lane B (/validate-pr, /review). The one critical finding, Escape on the theme menu also cancelling a running turn or ending a call, is fixed in c028465 with mounted tests that run the conversation's real cancel rules. frontend-build passed 3090 tests, including this spec's 19. e2e is green. The raw-color ratchet passes after the dev merge. The pytest matrix stalled on base and head alike, and this diff has no Python, so it merges on the required checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants