Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs([issue-1973]): codify tabbed config-drawer UX convention + design record

[._.]/ Adam Eivy1f3930fcdb06
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 5c0d60ecc5..73479e0257 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -106,6 +106,7 @@
## Internal
+- **[issue-1973] Documented the tabbed config-drawer UX convention** — codified the epic #1966 drawer redesign so new config surfaces follow it instead of dumping another page-length flat scroll into a narrow panel. Added a "Config drawers → the shared tabbed `Drawer` convention" bullet to `CLAUDE.md` (near the Layout/deep-linking conventions) covering the `size` variants (sm/md/lg/xl, mobile stays full-screen), when to tab vs. use grouped sections, the per-tab-scroll + state-hoisting rule, the `TabPills` mobile `<select>` fallback ("reuse `TabPills`, never roll a new tab bar"), and deep-linkable active tab via `useDrawerTab` — pointing at `EditAppDrawer.jsx` / `ImageGenTab.jsx` as worked examples and `Drawer.jsx` as the primitive. Added the design record `docs/plans/2026-07-01-drawer-ux-redesign.md` (problem, size+tabs+deep-link approach, the #1968–#1972 per-surface migrations, and the scoped-out multi-open-instance id namespacing — deferred because drawers are modal/single-open). Docs only. (Closes #1973)
- **[issue-1964] Made `peerSync.test.js` full-sync coverage hermetic** — `getFullSyncCoverageForPeer` walks every subscribable record kind, but the test only mocked the universe/series/collection/artist/album/track/music-video list backends. The author, creative-director-project, mood-board, and writers-room (work/folder/exercise) list backends were left unmocked, so a developer running the full server suite against a populated local `portos` Postgres saw the coverage `total` count real rows instead of the fixture (`expected 3 to be 1`) — an order-dependent flake that repeatedly forced a "known flake or real break?" judgment during merge gating. Those six list functions are now partially mocked (the module's real merge/get/tombstone surface is preserved via `importOriginal`; only the DB-reading list function is overridden) and defaulted to empty in `beforeEach`, so coverage is driven purely by each test's fixture regardless of suite order or DB contents. Test-only. (#1964)
- **[issue-1947] Boot migrations no longer crash when a server is booted from inside a CoS agent worktree** — every path in the boot-migration chain derived its data root from where the executing file lives (`import.meta.url`), so a `node server/index.js` launched from inside a CoS agent's git worktree (`data/cos/worktrees/agent-*/`) resolved `data/`/`data.reference/` to the worktree's checkout, which has no gitignored runtime tree — boot migrations then crashed on ENOENT (observed: migration 005 writing `data/prompts/stages/pipeline-arc-overview.md`). Two fixes: (1) a durable `PORTOS_DATA_ROOT` env var (new `server/lib/dataRoot.js` `resolveInstallRoot`), pinned at real launch in `ecosystem.config.cjs`, that lets a process pin its install root explicitly instead of inferring it from the executing file — now preferred over the derived path in `PATHS` (`server/lib/fileUtils.js`), `server/index.js`'s migration call, and `scripts/run-migrations.js`; falls back to the derived path when unset (backward compatible). (2) a defensive backstop in `runMigrations` — `isWorktreeRoot()` detects a `data/cos/worktrees/`-rooted path and skips the migration pass with a single-line warning instead of crashing (keyed on the path segment only, so a fresh install's empty `data/` isn't a false positive). (Closes #1947)
- **[issue-1848] Strengthened weak truthiness test assertions** — replaced `toBeTruthy()` checks that would pass on wrong values with concrete value/shape assertions: `autobiography.test.js` now asserts the next-prompt object shape and round-trippable ISO-8601 timestamps for `createdAt`/`updatedAt`/`lastPromptAt`/`followUpsGeneratedAt` (with `updatedAt`/`lastPromptAt` proven strictly newer than the seeded old values); `storyBuilder.test.js` asserts `getSeries()` returns the matching `series.id` and `lockedAt` is a valid ISO timestamp; `commandSecurity.test.js` anchors the allowlist against known-safe membership (`git`/`gh`/`node`/`npm`/`pm2`/`ls`/`cat`/`echo`) and asserts dangerous commands stay absent, replacing the self-referential array-vs-Set check; and `fileUtils.test.js`'s visualTemplates resolution now asserts the returned path carries the `data/templates/` segment + unique basename. (#1848)
diff --git a/CLAUDE.md b/CLAUDE.md
index 7e74069454..02654ae6b7 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -221,6 +221,14 @@ When CoS agents or AI tools work on managed apps outside PortOS, all research, p
- **Alphabetical navigation** - sidebar nav items in `Layout.jsx` are alphabetically ordered after the Dashboard+CyberCity top section and separator; children within collapsible sections are also alphabetical
- **Every new page registers in the nav manifest** - when adding a `<Route>` + sidebar link, also add a `NAV_COMMANDS` entry in `server/lib/navManifest.js`. This makes the page reachable via `⌘K` and voice (`ui_navigate`) automatically. See the "Command Palette & Voice Nav" section above for the entry shape.
- **New page → pick the right Layout scroll mode.** `Layout.jsx` has an `isFullWidth` route list: matched routes get a bare `relative overflow-hidden` `<main>` (the PAGE must own an internal `overflow-y-auto`, like the editor's `<section>`); unmatched routes get the default `overflow-auto p-4 md:p-6` scrolling+padded main. A list/index page (e.g. `/universes`, `/pipeline`) should usually be a plain `<div>` and stay OUT of `isFullWidth` so the main scrolls it; only full-bleed editors that manage their own scroll belong in the list. Match `/route/` (trailing slash) to scope full-width to detail/editor sub-routes without catching the bare index. A full-width page with no internal scroll container silently clips below the fold.
+- **Config drawers → the shared tabbed `Drawer` convention.** Slide-in "settings over a feature page" surfaces use the shared `client/src/components/Drawer.jsx` primitive — never a hand-rolled `fixed inset-y-0 right-0` clone. Follow this convention instead of dumping another page-length flat scroll into a narrow panel (the epic #1966 redesign):
+ - **Size.** Pass `size` (`sm` 520px · `md` 640px · `lg` 720→880px · `xl` up to 1100px). Widen for genuinely large forms so they can lay out in columns on desktop; keep small dialogs at `sm`. Mobile is always `w-full` (full-screen sheet) regardless of `size` — mobile-responsive is non-negotiable. `widthClass` is a back-compat escape hatch that overrides `size`.
+ - **When to tab.** A large config surface (many fields / logical groups, e.g. Edit App's ~25 fields) should group its fields into `tabs={[{ id, label, icon?, count? }]}` + `activeTab` / `onTabChange` and render only the active tab's fields as `children` — not one page-length scroll. A *medium* form that should stay fully visible above the fold uses the child's own labeled sections instead (e.g. `ImageGenSettingsForm`'s `grouped` prop in the pipeline image-gen drawers), because tabs hide inactive fields behind a click.
+ - **Per-tab scroll.** The drawer gives each tab its own scroll region that resets on switch (`key={currentTab}` remounts the panel) — so no single tab is ever page-length. Because the body remounts per tab, **all mutable form state must live above the Drawer body** in the parent component, never in an uncontrolled input inside the form, or it resets on tab switch (see `EditAppDrawer.jsx`'s state-hoisting comment). Validate fields on tabs that may be unmounted at Save time explicitly, and `setActiveTab()` to the offending tab to surface the error.
+ - **Mobile `<select>` fallback + `TabPills`.** The tab bar is `client/src/components/ui/TabPills.jsx` (`mobileDropdown` collapses it to a `<select>` under `sm`) — **reuse it, never roll a new tab bar.** The `Drawer tabs` layout wires TabPills for you; a surface hosted in *both* a drawer and a page (like `ImageGenTab`) renders its own internal `<TabPills variant="pills" mobileDropdown>` instead so the same grouping works in either host.
+ - **Deep-linkable active tab.** Drive `activeTab` from a URL search param via `useDrawerTab(paramName, defaultTab, tabIds)` (`client/src/hooks/useDrawerTab.js`) so the open section is shareable/bookmarkable/reload-safe — the same "URL is the source of truth for what's open" rule as routed views. The caller owns the param name (`appTab`, `mediaTab`, …) so a page can host more than one drawer; pass the id list so a stale deep link degrades to `defaultTab` instead of a blank panel.
+ - **Long-lived forms** opt out of accidental dismissal with `closeOnEsc={false}` / `closeOnBackdrop={false}` so an Esc keystroke mid-edit doesn't discard the form.
+ - **Worked examples:** `client/src/components/apps/EditAppDrawer.jsx` (built-in `tabs` layout, `size="lg"`, `useDrawerTab('appTab', …)`) and `client/src/components/settings/ImageGenTab.jsx` (internal `TabPills variant="pills"` sub-tabs, `useDrawerTab('mediaTab', …)`). The primitive is `Drawer.jsx`; the design record is `docs/plans/2026-07-01-drawer-ux-redesign.md`.
- **Reactive UI updates** - after mutations (delete, create, update), update local state directly instead of refetching the entire list from the server. Use `setState(prev => prev.filter(...))` or similar patterns for immediate feedback
- **Single-line logging** - use emoji prefixes and string interpolation, never log full JSON blobs or arrays
```js
diff --git a/docs/plans/2026-07-01-drawer-ux-redesign.md b/docs/plans/2026-07-01-drawer-ux-redesign.md
new file mode 100644
index 0000000000..2296701c76
--- /dev/null
+++ b/docs/plans/2026-07-01-drawer-ux-redesign.md
@@ -0,0 +1,117 @@
+# Slide-in config drawer redesign — tabbed / responsive / deep-linkable (#1966)
+
+**Approved:** 2026-07-01 · **Epic:** #1966 · **Foundation:** #1967
+
+## Context
+
+PortOS's slide-in config drawers (Edit App, Media Generation Settings, CoS task
+config, pipeline image-gen settings, sync detail) were poor UX: each dumped a
+long, flat, single-column scroll into a narrow fixed-width panel with little
+organization. On desktop they wasted horizontal space; on mobile they were an
+endless scroll. The shared primitive `client/src/components/Drawer.jsx` was ~63
+lines — a right-side `fixed inset-y-0 right-0` panel, `w-full` on mobile and a
+single fixed `sm:w-[NNNpx]` bracket on desktop, with one flat `overflow-y-auto`
+body and no internal grouping. Every large form became one long scroll, and
+`SyncDetailDrawer` had even hand-rolled its own clone of the markup so it
+inherited none of the primitive's behavior.
+
+The goal: make large config surfaces **grouped/tabbed**, **responsive**, and able
+to use **more of the screen** on wide displays, while degrading gracefully to a
+full-screen sheet on mobile.
+
+## Key finding — the tab machinery already existed
+
+The redesign reused rather than invented:
+
+- `client/src/components/ui/TabPills.jsx` — a mature, a11y-complete tab primitive
+ with `underline`/`pills` variants, a `mobileDropdown` that collapses to a
+ `<select>` under `sm`, and icons/counts/spinners.
+- The URL-param-driven tabbed-settings pattern already used by `pages/Settings.jsx`
+ — the same "URL is the source of truth for what's open" convention the rest of
+ the app follows for routed views.
+
+So #1966 reduced to enhancing the shared `Drawer` primitive with size variants +
+an optional tabbed layout wired to `TabPills`, then migrating each large drawer
+onto it.
+
+## Decisions
+
+1. **Size variants, mobile stays full-screen.** `Drawer` gained a `size` prop
+ (`sm` 520px · `md` 640px · `lg` 720→880px · `xl` up to 1100px) that only
+ affects the desktop bracket; mobile remains `w-full`. `lg`/`xl` intentionally
+ use extra breakpoints so wide forms lay out in columns instead of a cramped
+ single column inside a wide panel. `widthClass` stays as a back-compat escape
+ hatch that overrides `size`. `bodyClassName` opts a tab into a multi-column
+ grid on wide sizes.
+2. **Optional tabbed layout, not mandatory.** Pass `tabs` + `activeTab` /
+ `onTabChange` and the drawer renders a sticky `TabPills` bar under the header
+ (collapsing to a `<select>` on mobile) and gives each tab its own scroll region
+ that **resets on switch** (`key={currentTab}` remounts the panel) — so no
+ single tab is ever page-length. Omit `tabs` and it stays the original
+ flat-scroll drawer. Both controlled (`activeTab` + `onTabChange`) and
+ uncontrolled tab state are supported, so a caller that doesn't care about
+ deep-linking still gets working tab switching.
+3. **Tabs vs. grouped sections.** Large surfaces (many logical groups) tab. A
+ *medium* form that should stay fully visible above the fold uses the child's
+ own labeled sections (`ImageGenSettingsForm`'s `grouped` prop) instead —
+ because tabs hide inactive fields behind a click.
+4. **Deep-linkable active tab.** New hook `client/src/hooks/useDrawerTab.js`
+ returns `[activeTab, setActiveTab]` backed by a caller-named URL search param
+ (`appTab`, `mediaTab`, …) so the open section is shareable, bookmarkable, and
+ reload-safe. The caller owns the param name (a page may host more than one
+ drawer) and passes the tab-id list so a stale/hand-edited deep link degrades to
+ `defaultTab` instead of a blank panel. Tabs live in a search param — not a
+ route `:tab` segment — because a drawer is an overlay on an already-routed page
+ and can't own a path segment.
+5. **Reuse `TabPills`, never roll a new tab bar.** A surface hosted in *both* a
+ drawer and a page (like `ImageGenTab`, rendered by the ImageGen / VideoGen /
+ StoryboardPanel drawers *and* the Settings page) renders its own internal
+ `<TabPills variant="pills" mobileDropdown>` instead of the Drawer's built-in
+ tabs, so the same grouping works in either host.
+6. **State hoisting is a hard requirement of per-tab remount.** Because the body
+ remounts per active tab, all mutable form state must live in the parent above
+ the Drawer body — never in an uncontrolled input inside the form — or it
+ silently resets on tab switch. Fields on a tab that may be unmounted at Save
+ time must be validated explicitly, surfacing the offending tab via
+ `setActiveTab()`.
+
+## Foundation + per-surface migrations
+
+- **#1967 (foundation, shipped)** — `Drawer` size variants + optional tabbed
+ layout + `useDrawerTab`. Worked into `EditAppDrawer` and `ImageGenTab` as the
+ reference call-sites; covered by `Drawer.test.jsx`.
+- **#1968 (shipped)** — Edit App drawer → built-in tabs (General / Ports & TLS /
+ Commands / Workflow / JIRA / DataDog), `size="lg"`, `useDrawerTab('appTab')`,
+ `closeOnEsc/closeOnBackdrop={false}` to protect a long-lived form.
+- **#1969 (shipped)** — Media Generation Settings (`ImageGenTab`) → internal
+ `TabPills` pills sub-tabs (Backend / External / Local / Codex / Tokens / Expose
+ / Test), `useDrawerTab('mediaTab')`; fixes the VideoGen / ImageGen /
+ StoryboardPanel drawers and the Settings page in one change.
+- **#1970 (shipped)** — Pipeline image-gen drawers (NounsStage, ComicScriptStage)
+ → grouped sections via the shared `ImageGenSettingsForm` `grouped` prop at
+ `size="md"` (medium form, no tabs).
+- **#1971 (open)** — CoS task config drawer → tabs (Stage config / Global
+ defaults / Per-app overrides).
+- **#1972 (open)** — Reconcile the hand-rolled `SyncDetailDrawer` clone onto the
+ shared `Drawer` primitive.
+- **#1973 (this record)** — Document the convention in `CLAUDE.md` + this design
+ record.
+
+## Scoped out
+
+- **Multi-open-instance id namespacing.** The tabbed body uses fixed element ids
+ (`drawer-tabpanel-<tab>`, `tab-<tab>`). This is safe because a drawer is modal
+ and single-open by contract — the backdrop + scroll-lock guarantee one drawer at
+ a time, and a closed drawer renders nothing (`if (!open) return null`). Two
+ drawers on one page use distinct URL params for their persisted tab state but
+ never share the DOM open simultaneously, so the ids can't collide. Per-instance
+ id namespacing was therefore deferred as unnecessary complexity; revisit only if
+ a genuinely stacked/simultaneous multi-drawer surface is ever introduced.
+
+## Verification
+
+- `client/src/components/Drawer.test.jsx` covers the `size`/`widthClass` brackets
+ and the tabbed layout.
+- The convention is documented in `CLAUDE.md` (Config drawers bullet) and
+ `useDrawerTab` carries its catalog row in `client/src/hooks/README.md` +
+ barrel export in `client/src/hooks/index.js`.