diff --git a/.changeset/adr-0057-p3c-maximized-dock.md b/.changeset/adr-0057-p3c-maximized-dock.md
new file mode 100644
index 0000000000..b380a31b16
--- /dev/null
+++ b/.changeset/adr-0057-p3c-maximized-dock.md
@@ -0,0 +1,24 @@
+---
+"@object-ui/app-shell": patch
+---
+
+feat(console-ai): /ai = the ChatDock maximized + Studio right-dock reflow (ADR-0057 P3c)
+
+The final P3 slice, all behind the default-off `features.chatDock` flag:
+
+- **/ai ⇄ rail continuity**: the dock header gains a maximize button that opens
+ the full-page `/ai` surface, and the `/ai` page gains a collapse-to-dock button
+ that returns to the console with the rail expanded — same thread both ways
+ (the P1 `(user, app, product)` conversation key). Deep links
+ (`/ai/:agent/:conversationId`, ADR-0013) are untouched and keep working.
+- **Studio reflow** (the ADR's decided grid `[left: nav/tree] [center: canvas +
+ properties] [right: chat]`): the AI copilot leaves the left `w-96` panel and
+ renders as the shared right dock (`ChatDockPanel` + `ChatDockLauncher`), same
+ package-scoped build thread; the Interfaces pillar's right inspector folds
+ into center `[Canvas | Properties]` tabs with select-a-block auto-switch. An
+ injected `aiSlot` (cloud seam, ADR-0080) keeps the legacy left panel.
+- **Live Canvas** (ADR-0037): in the rail, the dock auto-maximizes while the
+ canvas is open and tucks back on close (manual resize wins); maximized (`/ai`)
+ keeps the existing beside-the-chat split.
+
+With the flag OFF, `/ai` and Studio are pixel-identical to before.
diff --git a/docs/adr/0057-console-ai-chat-one-conversation-docked.md b/docs/adr/0057-console-ai-chat-one-conversation-docked.md
index 53142897a2..fa7e87aba3 100644
--- a/docs/adr/0057-console-ai-chat-one-conversation-docked.md
+++ b/docs/adr/0057-console-ai-chat-one-conversation-docked.md
@@ -2,7 +2,9 @@
**Status**: Accepted (2026-07-13) — P1+P2 shipped (#2414), P4 shipped
(#2439 / #2444 + cloud#818/#819; reliability follow-ups #2449 + cloud#820);
-P3 planned (implementation plan on epic #2409). Console-layer realization of the two-agent,
+P3 shipped behind the default-off `features.chatDock` rollout flag (P3a #2464,
+P3b #2465, P3c #2467 — epic #2409; flag default-on + overlay retirement are the
+remaining cleanup, tracked on the epic). Console-layer realization of the two-agent,
surface-bound model (cloud ADR-0063). **No agent, boundary, or commercial-model
change** — this ADR only rearranges how the objectui console *renders and wires*
chat surfaces.
@@ -242,7 +244,10 @@ inert; AI is reached only via MCP.
Studio copilot moves to the shared right dock (properties reflow); `/ai` =
maximized dock, same thread; runtime SDUI unchanged (bubble). *Proof: chat
location is identical across console pages; expand/collapse preserves the
- thread.*
+ thread.* **Shipped behind `features.chatDock` (default OFF): P3a #2464 (rail),
+ P3b #2465 (FAB → launcher), P3c #2467 (maximized `/ai` ⇄ rail + Studio reflow
+ + canvas auto-maximize). Flag default-on + floating-overlay retirement are the
+ remaining cleanup (epic #2409).**
- **P4 — ask→build handoff (explicit).** In `ask`, a build-shaped request
surfaces an explicit **"Open in Builder →"** that carries the conversation
context through the generalized `assistantBus` — ADR-0063's *decline-and-
@@ -339,7 +344,9 @@ product-scoped threads; a deleted bound package needs a terminal chip state
1. **Dock side under Studio (P3).** ~~Chat right vs properties right.~~
**DECIDED (2026-07-13): chat right**; properties fold into a center tab —
- `[left: nav/tree] [center: canvas + properties] [right: chat]`.
+ `[left: nav/tree] [center: canvas + properties] [right: chat]`. **Shipped in
+ P3c** (Interfaces pillar `[Canvas | Properties]` center tabs; Data/Automations
+ keep their in-center inspectors).
2. **FAB retirement path (P3).** ~~Hard-retire, or keep the FAB as the collapsed
affordance?~~ **DECIDED (2026-07-13): the FAB becomes the dock's collapsed
affordance** — the bottom-right button stays and expands the right rail
@@ -352,9 +359,11 @@ product-scoped threads; a deleted bound package needs a terminal chip state
4. **`app.defaultAgent` post-ADR-0063.** Now bounded to `ask` / `build` (tenant
custom agents withdrawn). Confirm the resolver **rejects** anything else rather
than silently falling through.
-5. **Focus-mode routing.** Does `/ai/build/:conversationId` stay a deep-linkable,
- shareable URL (ADR-0013) once the dock is canonical? Proposed: **yes** — the
- URL opens the dock maximized on that thread.
+5. **Focus-mode routing.** ~~Does `/ai/build/:conversationId` stay a deep-linkable,
+ shareable URL (ADR-0013) once the dock is canonical?~~ **DECIDED & SHIPPED
+ (P3c): yes** — the routes are untouched; the full page IS the dock maximized
+ (same P1 thread), with a maximize button on the rail and a collapse-to-dock
+ button on the page bridging the two presentations.
## Alternatives considered
diff --git a/packages/app-shell/src/console/ai/AiChatPage.tsx b/packages/app-shell/src/console/ai/AiChatPage.tsx
index fef1b7945c..0c913032f1 100644
--- a/packages/app-shell/src/console/ai/AiChatPage.tsx
+++ b/packages/app-shell/src/console/ai/AiChatPage.tsx
@@ -44,7 +44,7 @@ import {
EmptyDescription,
cn,
} from '@object-ui/components';
-import { Bug, PanelLeft, PanelLeftClose, PanelLeftOpen, Share2 } from 'lucide-react';
+import { Bug, PanelLeft, PanelLeftClose, PanelLeftOpen, PanelRightOpen, Share2 } from 'lucide-react';
import {
ChatbotEnhanced,
useAgents,
@@ -69,6 +69,7 @@ import {
} from '@object-ui/plugin-chatbot';
import { AppHeader } from '../../layout/AppHeader';
+import { armChatDockExpanded } from '../../layout/chatDockState';
import { fetchPendingDraftCount } from '../../preview/draftStatus';
import { emitMetadataRefresh } from '../../assistant/assistantBus';
import { getRuntimeConfig } from '../../runtime-config';
@@ -509,6 +510,19 @@ export function matchAiChatShortcut(e: {
}
}
+/**
+ * ADR-0057 P3c — where the "collapse to dock" affordance navigates: back
+ * through history when react-router has an in-app entry to return to
+ * (`window.history.state.idx > 0` — the router stamps a monotonically
+ * increasing `idx` on entries it creates), else `/home` (the page was the
+ * entry point: a deep link, a fresh tab). The dock itself is armed to open
+ * expanded separately ({@link armChatDockExpanded}); this only picks the
+ * landing. Pure + exported for tests.
+ */
+export function resolveCollapseToDockTarget(historyIdx: unknown): -1 | '/home' {
+ return typeof historyIdx === 'number' && historyIdx > 0 ? -1 : '/home';
+}
+
/** A composer submission held until the conversation id that will carry it exists. */
/** Stable empty array for the stale-scope window (#2450) — a fresh `[]` per
* render would churn the pane's `initialMessages` identity for no reason. */
@@ -994,6 +1008,34 @@ export function AiChatPage({ apiBase: apiBaseProp, defaultAgent: defaultAgentPro
+ {/* ADR-0057 P3c — "/ai = the ChatDock maximized": tuck this full-page
+ surface back into the console's right rail. Arms the dock to mount
+ expanded, then returns to the page the user came from (or /home on
+ a cold deep link) — the rail resolves the same (user, product)
+ conversation scope, so it shows THE SAME THREAD. Desktop-only
+ (the dock itself is `hidden md:flex`) and flag-gated: with
+ `features.chatDock` off this button does not exist and the page is
+ pixel-identical to pre-P3c. */}
+ {!noAgents && getRuntimeConfig().features.chatDock === true && (
+
+ )}
{noAgents ? (
{
+ it('goes back when react-router stamped a positive history index', () => {
+ expect(resolveCollapseToDockTarget(1)).toBe(-1);
+ expect(resolveCollapseToDockTarget(7)).toBe(-1);
+ });
+
+ it('lands on /home when this page is the entry point (idx 0)', () => {
+ expect(resolveCollapseToDockTarget(0)).toBe('/home');
+ });
+
+ it('lands on /home when the index is missing or not a number', () => {
+ expect(resolveCollapseToDockTarget(undefined)).toBe('/home');
+ expect(resolveCollapseToDockTarget(null)).toBe('/home');
+ expect(resolveCollapseToDockTarget('2')).toBe('/home');
+ expect(resolveCollapseToDockTarget(NaN)).toBe('/home');
+ });
+});
diff --git a/packages/app-shell/src/layout/ChatDock.tsx b/packages/app-shell/src/layout/ChatDock.tsx
index 182f974eae..3d70623ac7 100644
--- a/packages/app-shell/src/layout/ChatDock.tsx
+++ b/packages/app-shell/src/layout/ChatDock.tsx
@@ -10,12 +10,15 @@
*
* It reuses the shared {@link ChatPane} engine over the P1 `(user, app, product)`
* conversation — the same thread the full-page `/ai` surface shows — so the dock
- * is a VIEW, not a new conversation. P3b later retires the FAB into this dock's
- * launcher; P3c makes `/ai` the dock maximized.
+ * is a VIEW, not a new conversation. P3b retired the FAB into this dock's
+ * launcher. P3c makes `/ai` the dock maximized (the header's maximize button ⇄
+ * the page's collapse-to-dock button, same thread both ways), reuses the panel
+ * under Studio (right dock, `children` body override), and auto-maximizes the
+ * rail while the ADR-0037 Live Canvas is open.
*/
import * as React from 'react';
import { cn, Button } from '@object-ui/components';
-import { MessagesSquare, PanelRightClose } from 'lucide-react';
+import { Maximize2, MessagesSquare, PanelRightClose } from 'lucide-react';
import { useObjectTranslation } from '@object-ui/i18n';
import { useAgents } from '@object-ui/plugin-chatbot';
import { ChatPane, resolveApiBase, type PendingFirstMessage } from '../console/ai/AiChatPage';
@@ -25,6 +28,9 @@ import { resolveSurfaceAgent } from '../hooks/surfaceAgent';
import { getRuntimeConfig } from '../runtime-config';
import {
clampDockWidth,
+ maximizedDockWidth,
+ readStoredDockExpanded,
+ writeStoredDockExpanded,
DOCK_DEFAULT_WIDTH,
DOCK_WIDTH_STORAGE_KEY,
} from './chatDockState';
@@ -39,13 +45,39 @@ function readStoredWidth(): number {
}
}
+export interface ChatDockOptions {
+ /**
+ * Mount expanded when no stored preference exists. The console rail keeps
+ * P3a's default-collapsed posture; the Studio dock passes `true` because the
+ * copilot it replaces has always been visible by default.
+ */
+ defaultExpanded?: boolean;
+ /**
+ * sessionStorage key the expanded/collapsed state round-trips through (see
+ * {@link DOCK_EXPANDED_STORAGE_KEY}). Omitted → in-memory only, so each mount
+ * starts from `defaultExpanded` (the Studio dock's parity with today's
+ * non-persisted copilot collapse).
+ */
+ persistExpandedKey?: string;
+}
+
export interface ChatDockState {
expanded: boolean;
width: number;
dragging: boolean;
+ /** ADR-0037/P3c — true while the rail is canvas-maximized (see `maximize`). */
+ maximized: boolean;
toggle: () => void;
expand: () => void;
collapse: () => void;
+ /**
+ * Grow the rail to its widest legal width (Live Canvas needs room for the
+ * chat + preview split). Transient: the pre-maximize width is remembered and
+ * NEVER persisted over the user's chosen width.
+ */
+ maximize: () => void;
+ /** Undo `maximize` — a no-op unless currently maximized (see doc below). */
+ restore: () => void;
/** Pointer-down on the rail's left-edge resize handle. */
onResizePointerDown: (e: React.PointerEvent) => void;
}
@@ -55,15 +87,63 @@ export interface ChatDockState {
* layout cost until invoked (preserving the FAB's virtue of not reflowing dense
* data grids). Width persists to localStorage; the drag anchors the rail's LEFT
* edge (dragging left widens it). All DOM reads happen in handlers, never render.
+ *
+ * P3c adds two orthogonal behaviors, both opt-in and both preserving the bare
+ * `useChatDockState()` call unchanged:
+ * - `persistExpandedKey` round-trips expanded/collapsed through sessionStorage
+ * so the console rail survives in-tab navigation and the `/ai` page can arm
+ * it before navigating back ({@link armChatDockExpanded}).
+ * - `maximize`/`restore` implement the Live-Canvas "auto-maximize on canvas
+ * open, tuck on close" (ADR-0037 beside-the-chat preview needs width the
+ * rail doesn't have). `restore` is a NO-OP unless a maximize is actually
+ * latched: ChatPane reports `onCanvasOpenChange(false)` on mount (twice
+ * under StrictMode), and an unguarded restore would clobber the width on
+ * every dock open. A manual resize drag clears the latch — the user taking
+ * the handle wins over the automation, so the later canvas-close restore
+ * does nothing.
*/
-export function useChatDockState(): ChatDockState {
- const [expanded, setExpanded] = React.useState(false);
+export function useChatDockState(options?: ChatDockOptions): ChatDockState {
+ const { defaultExpanded = false, persistExpandedKey } = options ?? {};
+ const [expanded, setExpandedState] = React.useState(() =>
+ persistExpandedKey ? readStoredDockExpanded(persistExpandedKey, defaultExpanded) : defaultExpanded,
+ );
const [width, setWidth] = React.useState(() => readStoredWidth());
const [dragging, setDragging] = React.useState(false);
+ const [maximized, setMaximized] = React.useState(false);
+ // The latch and the width to return to when the canvas closes. Refs, not
+ // state: they are only read inside handlers (never rendered), and the latch
+ // must be checkable synchronously so a double-fired maximize/restore (React
+ // StrictMode re-runs effects) can bail before touching the width.
+ const maximizedRef = React.useRef(false);
+ const prevWidthRef = React.useRef(null);
+ // Latest width, readable from the IDENTITY-STABLE maximize below. If
+ // `maximize` closed over `width` (a [width] dep) its identity would change on
+ // every drag move — and consumers key their canvas-open effect on the handler
+ // identity, so each change would re-fire maximize mid-drag and snap the width
+ // back to max, fighting the user. Render-phase ref sync keeps it current.
+ const widthRef = React.useRef(width);
+ widthRef.current = width;
+
+ const setExpanded = React.useCallback(
+ (update: (prev: boolean) => boolean) => {
+ setExpandedState((prev) => {
+ const next = update(prev);
+ if (persistExpandedKey) writeStoredDockExpanded(persistExpandedKey, next);
+ return next;
+ });
+ },
+ [persistExpandedKey],
+ );
const onResizePointerDown = React.useCallback(
(e: React.PointerEvent) => {
e.preventDefault();
+ // Grabbing the handle is the user taking control of the width — drop the
+ // canvas-maximize latch so the eventual canvas-close restore won't fight
+ // them (their drag result stays, and gets persisted below as usual).
+ maximizedRef.current = false;
+ prevWidthRef.current = null;
+ setMaximized(false);
const startX = e.clientX;
const startWidth = width;
setDragging(true);
@@ -90,16 +170,48 @@ export function useChatDockState(): ChatDockState {
[width],
);
- const toggle = React.useCallback(() => setExpanded((v) => !v), []);
- const expand = React.useCallback(() => setExpanded(true), []);
- const collapse = React.useCallback(() => setExpanded(false), []);
+ const maximize = React.useCallback(() => {
+ if (maximizedRef.current) return; // already maximized — keep the original return width
+ maximizedRef.current = true;
+ prevWidthRef.current = widthRef.current;
+ setWidth(maximizedDockWidth(window.innerWidth));
+ setMaximized(true);
+ }, []);
- return { expanded, width, dragging, toggle, expand, collapse, onResizePointerDown };
+ const restore = React.useCallback(() => {
+ // Not latched → nothing to undo. This guard is what makes ChatPane's
+ // mount-time onCanvasOpenChange(false) (and StrictMode's double fire, and
+ // a restore after a manual drag took the width over) harmless.
+ if (!maximizedRef.current) return;
+ maximizedRef.current = false;
+ setWidth(prevWidthRef.current ?? readStoredWidth());
+ prevWidthRef.current = null;
+ setMaximized(false);
+ }, []);
+
+ const toggle = React.useCallback(() => setExpanded((v) => !v), [setExpanded]);
+ const expand = React.useCallback(() => setExpanded(() => true), [setExpanded]);
+ const collapse = React.useCallback(() => setExpanded(() => false), [setExpanded]);
+
+ return {
+ expanded,
+ width,
+ dragging,
+ maximized,
+ toggle,
+ expand,
+ collapse,
+ maximize,
+ restore,
+ onResizePointerDown,
+ };
}
interface ChatDockConversationProps {
userId: string | undefined;
apiBase: string;
+ /** ADR-0037/P3c — the Live Canvas open/close seam, forwarded to ChatPane. */
+ onCanvasOpenChange?: (open: boolean) => void;
}
/**
@@ -109,7 +221,7 @@ interface ChatDockConversationProps {
* the console's ambient assistant thread. Renders nothing when the AI catalog is
* empty (OSS / no seat).
*/
-function ChatDockConversation({ userId, apiBase }: ChatDockConversationProps) {
+function ChatDockConversation({ userId, apiBase, onCanvasOpenChange }: ChatDockConversationProps) {
const { agents, isLoading, error } = useAgents({ apiBase });
const activeAgent = React.useMemo(
() =>
@@ -152,14 +264,32 @@ function ChatDockConversation({ userId, apiBase }: ChatDockConversationProps) {
onSent={() => {}}
onShare={() => {}}
showDebug={false}
+ onCanvasOpenChange={onCanvasOpenChange}
/>
);
}
export interface ChatDockPanelProps {
dock: ChatDockState;
- userId: string | undefined;
+ /** Signed-in user id for the default (console ask) body. Unused with `children`. */
+ userId?: string;
apiBase?: string;
+ /** Header title override (the Studio dock says "AI copilot"); default "Assistant". */
+ title?: string;
+ /**
+ * ADR-0057 P3c — render a maximize header button that opens the full-page
+ * focus surface (`/ai…`) on the SAME thread. The caller supplies the
+ * navigation because the right target is per-surface (console → `/ai`,
+ * Studio → `/ai/build?package=…`).
+ */
+ onMaximize?: () => void;
+ /**
+ * Body override. Default mounts {@link ChatDockConversation} (the console's
+ * ambient ask thread). The Studio dock passes its own package-scoped build
+ * conversation instead — note the empty-catalog gate then lives in the
+ * caller, because the default body's self-gate is bypassed.
+ */
+ children?: React.ReactNode;
}
/**
@@ -167,9 +297,23 @@ export interface ChatDockPanelProps {
* main content. Only render this when `dock.expanded` (the caller decides), so a
* collapsed dock contributes no flex child.
*/
-export function ChatDockPanel({ dock, userId, apiBase: apiBaseProp }: ChatDockPanelProps) {
+export function ChatDockPanel({
+ dock,
+ userId,
+ apiBase: apiBaseProp,
+ title,
+ onMaximize,
+ children,
+}: ChatDockPanelProps) {
const { t } = useObjectTranslation();
const apiBase = React.useMemo(() => resolveApiBase(apiBaseProp), [apiBaseProp]);
+ // ADR-0037/P3c — the default body auto-maximizes the rail while the Live
+ // Canvas is open and tucks back when it closes (restore self-guards against
+ // the mount-time false, StrictMode, and user-drag takeover).
+ const handleCanvasOpenChange = React.useCallback(
+ (open: boolean) => (open ? dock.maximize() : dock.restore()),
+ [dock.maximize, dock.restore],
+ );
return (
);
@@ -216,8 +381,9 @@ export interface ChatDockLauncherProps {
/**
* The collapsed affordance — a fixed edge button that expands the dock. Rendered
- * only while collapsed, so it never overlaps the expanded rail. (P3b will fold
- * the FAB into this launcher; for P3a they coexist behind the flag.)
+ * only while collapsed, so it never overlaps the expanded rail. The console
+ * retired it in P3b (the FAB is that surface's launcher); the Studio dock (P3c)
+ * uses it as its collapsed state, since Studio has no FAB.
*/
export function ChatDockLauncher({ onExpand }: ChatDockLauncherProps) {
const { t } = useObjectTranslation();
diff --git a/packages/app-shell/src/layout/ConsoleLayout.tsx b/packages/app-shell/src/layout/ConsoleLayout.tsx
index c1b817fd8e..0fd08499a8 100644
--- a/packages/app-shell/src/layout/ConsoleLayout.tsx
+++ b/packages/app-shell/src/layout/ConsoleLayout.tsx
@@ -9,6 +9,7 @@
*/
import React, { useEffect } from 'react';
+import { useNavigate } from 'react-router-dom';
import { AppShell } from '@object-ui/layout';
// Lightweight FAB stub — the heavy chat chunk graph (plugin-chatbot,
@@ -16,7 +17,7 @@ import { AppShell } from '@object-ui/layout';
// hover/click. See ConsoleChatbotFab.tsx.
import { ConsoleChatbotFab } from './ConsoleChatbotFab';
import { useChatDockState, ChatDockPanel } from './ChatDock';
-import { matchChatDockShortcut } from './chatDockState';
+import { matchChatDockShortcut, DOCK_EXPANDED_STORAGE_KEY } from './chatDockState';
import { DraftPreviewBar } from '../preview/DraftPreviewBar';
import { UnpublishedAppBar } from '../preview/UnpublishedAppBar';
import { UnifiedSidebar } from './UnifiedSidebar';
@@ -82,9 +83,13 @@ export function ConsoleLayout({
// ADR-0057 P3a — the right-docked chat rail. DEFAULT OFF: gated on the
// `chatDock` rollout flag AND the same AI-surface gate as the FAB, so it is
- // strictly additive and renders nothing on OSS / opt-out runtimes.
- const dock = useChatDockState();
+ // strictly additive and renders nothing on OSS / opt-out runtimes. P3c: the
+ // expanded state round-trips through sessionStorage so the rail survives
+ // in-tab navigation, and so the `/ai` page's collapse-to-dock affordance can
+ // arm it before navigating back here (the maximize ⇄ tuck loop).
+ const dock = useChatDockState({ persistExpandedKey: DOCK_EXPANDED_STORAGE_KEY });
const dockEnabled = showChatbot && getRuntimeConfig().features.chatDock === true;
+ const navigate = useNavigate();
// Set navigation context to 'app' when this layout mounts
useEffect(() => {
@@ -128,7 +133,20 @@ export function ConsoleLayout({
}
className="!p-0 overflow-y-auto overflow-x-hidden bg-muted/5"
rightRail={
- dockEnabled && dock.expanded ? : undefined
+ dockEnabled && dock.expanded ? (
+ navigate('/ai')}
+ />
+ ) : undefined
}
branding={
activeApp?.branding
diff --git a/packages/app-shell/src/layout/__tests__/ChatDock.test.tsx b/packages/app-shell/src/layout/__tests__/ChatDock.test.tsx
new file mode 100644
index 0000000000..0cb6b27e06
--- /dev/null
+++ b/packages/app-shell/src/layout/__tests__/ChatDock.test.tsx
@@ -0,0 +1,89 @@
+/**
+ * ObjectUI
+ * Copyright (c) 2024-present ObjectStack Inc.
+ *
+ * ADR-0057 P3c — ChatDockPanel chrome contract: the `children` body override
+ * (the Studio dock's seam), the maximize button rendered only when a target is
+ * provided, and the collapse button still driving the dock state.
+ */
+import '@testing-library/jest-dom/vitest';
+import { describe, it, expect, vi } from 'vitest';
+import { render, screen, fireEvent } from '@testing-library/react';
+import { ChatDockPanel, type ChatDockState } from '../ChatDock';
+
+vi.mock('@object-ui/i18n', () => ({
+ useObjectTranslation: () => ({
+ t: (key: string, options?: Record) => String(options?.defaultValue ?? key),
+ }),
+}));
+
+// The default body (ChatDockConversation) drags in the whole chat graph
+// (plugin-chatbot, hooks, AiChatPage) — irrelevant to the chrome under test,
+// and every case here overrides the body via `children` anyway.
+vi.mock('../../console/ai/AiChatPage', () => ({
+ ChatPane: () => null,
+ resolveApiBase: (explicit?: string) => explicit ?? '/api/v1/ai',
+}));
+vi.mock('@object-ui/plugin-chatbot', () => ({
+ useAgents: () => ({ agents: [], isLoading: false, error: undefined }),
+}));
+vi.mock('../../hooks', () => ({
+ useChatConversation: () => ({ conversationId: undefined, initialMessages: [] }),
+}));
+
+function dockState(overrides: Partial = {}): ChatDockState {
+ return {
+ expanded: true,
+ width: 420,
+ dragging: false,
+ maximized: false,
+ toggle: vi.fn(),
+ expand: vi.fn(),
+ collapse: vi.fn(),
+ maximize: vi.fn(),
+ restore: vi.fn(),
+ onResizePointerDown: vi.fn(),
+ ...overrides,
+ };
+}
+
+describe('ChatDockPanel', () => {
+ it('renders the children body override instead of the default conversation', () => {
+ render(
+
+
+ ,
+ );
+ expect(screen.getByTestId('studio-dock-body')).toBeInTheDocument();
+ });
+
+ it('shows the maximize button only when onMaximize is provided, and fires it', () => {
+ const { rerender } = render(
+
+
+ ,
+ );
+ expect(screen.queryByTestId('chat-dock-maximize')).not.toBeInTheDocument();
+
+ const onMaximize = vi.fn();
+ rerender(
+
+
+ ,
+ );
+ fireEvent.click(screen.getByTestId('chat-dock-maximize'));
+ expect(onMaximize).toHaveBeenCalledTimes(1);
+ });
+
+ it('renders the title override and keeps collapse wired to the dock state', () => {
+ const dock = dockState();
+ render(
+
+
+ ,
+ );
+ expect(screen.getByText('AI copilot')).toBeInTheDocument();
+ fireEvent.click(screen.getByTestId('chat-dock-collapse'));
+ expect(dock.collapse).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/packages/app-shell/src/layout/__tests__/chatDockState.test.ts b/packages/app-shell/src/layout/__tests__/chatDockState.test.ts
index 3312cb4857..84228e61bb 100644
--- a/packages/app-shell/src/layout/__tests__/chatDockState.test.ts
+++ b/packages/app-shell/src/layout/__tests__/chatDockState.test.ts
@@ -4,10 +4,13 @@
*
* ADR-0057 P3a — ChatDock pure state: the width clamp keeps neither pane from
* collapsing, and the toggle shortcut is composer-safe (⌘/Ctrl+Shift+I).
+ * P3c adds the canvas-maximize width and the stored-expanded parse.
*/
import { describe, it, expect } from 'vitest';
import {
clampDockWidth,
+ maximizedDockWidth,
+ parseStoredDockExpanded,
matchChatDockShortcut,
DOCK_MIN_WIDTH,
DOCK_CONTENT_MIN_WIDTH,
@@ -31,6 +34,31 @@ describe('clampDockWidth', () => {
});
});
+describe('maximizedDockWidth', () => {
+ it('is the widest legal rail — main content keeps its minimum', () => {
+ expect(maximizedDockWidth(1600)).toBe(1600 - DOCK_CONTENT_MIN_WIDTH);
+ });
+
+ it('floors at the rail minimum on tiny containers', () => {
+ // container − CONTENT_MIN would be below the rail minimum → the min wins
+ // (clampDockWidth's lower bound takes precedence over its upper bound).
+ expect(maximizedDockWidth(700)).toBe(DOCK_MIN_WIDTH);
+ });
+});
+
+describe('parseStoredDockExpanded', () => {
+ it("only the exact '1' opts into mounting expanded", () => {
+ expect(parseStoredDockExpanded('1')).toBe(true);
+ });
+
+ it('null / other values keep the default-collapsed posture', () => {
+ expect(parseStoredDockExpanded(null)).toBe(false);
+ expect(parseStoredDockExpanded('0')).toBe(false);
+ expect(parseStoredDockExpanded('true')).toBe(false);
+ expect(parseStoredDockExpanded('')).toBe(false);
+ });
+});
+
describe('matchChatDockShortcut', () => {
const base = { key: 'i', metaKey: false, ctrlKey: false, shiftKey: false, altKey: false };
it('matches ⌘/Ctrl+Shift+I', () => {
diff --git a/packages/app-shell/src/layout/chatDockState.ts b/packages/app-shell/src/layout/chatDockState.ts
index 668a77dcd1..f2690a3399 100644
--- a/packages/app-shell/src/layout/chatDockState.ts
+++ b/packages/app-shell/src/layout/chatDockState.ts
@@ -2,12 +2,25 @@
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
- * ADR-0057 P3a — pure state helpers for the ChatDock (the right-docked console
- * AI rail). Kept dependency-free so the width math and the keyboard matcher are
- * unit-testable without React or the DOM.
+ * ADR-0057 P3a/P3c — state helpers for the ChatDock (the right-docked console
+ * AI rail). Kept React-free so the width math and the keyboard matcher are
+ * unit-testable without the component tree; the storage round-trip helpers
+ * guard every `sessionStorage` touch so they degrade to defaults in private
+ * mode (and no-op cleanly under a DOM-less test runner).
*/
export const DOCK_WIDTH_STORAGE_KEY = 'ai-chat-dock-width';
+/**
+ * ADR-0057 P3c — sessionStorage key holding `'1'` when the dock should mount
+ * EXPANDED. Armed by the `/ai` page's "collapse to dock" affordance (so landing
+ * back in the console shows the same thread in the rail, completing the
+ * maximize ⇄ tuck loop), and kept up to date by expand/collapse so the rail
+ * survives in-tab navigation between console pages. sessionStorage — not
+ * localStorage — on purpose: a fresh tab/session keeps P3a's default-collapsed
+ * virtue (zero layout cost until invoked), and the flag can never leak into a
+ * shared URL (ADR-0013 deep links stay clean).
+ */
+export const DOCK_EXPANDED_STORAGE_KEY = 'ai-chat-dock-expanded';
/** Default rail width (px). */
export const DOCK_DEFAULT_WIDTH = 420;
/** The rail never narrower than this. */
@@ -29,6 +42,57 @@ export function clampDockWidth(desired: number, containerWidth: number): number
return Math.min(Math.max(desired, DOCK_MIN_WIDTH), upper);
}
+/**
+ * ADR-0057 P3c / ADR-0037 — the widest legal rail for a container: the Live
+ * Canvas "maximize in place" width. Just {@link clampDockWidth} pinned to its
+ * own upper bound (main content keeps {@link DOCK_CONTENT_MIN_WIDTH}), named so
+ * call sites read as intent. Pure + exported for tests.
+ */
+export function maximizedDockWidth(containerWidth: number): number {
+ return clampDockWidth(containerWidth, containerWidth);
+}
+
+/**
+ * Parse the stored {@link DOCK_EXPANDED_STORAGE_KEY} value — only the exact
+ * `'1'` opts into mounting expanded; null/garbage keeps the default-collapsed
+ * posture. Pure + exported for tests.
+ */
+export function parseStoredDockExpanded(raw: string | null): boolean {
+ return raw === '1';
+}
+
+/** Read a stored expanded flag; storage failures (private mode) → `fallback`. */
+export function readStoredDockExpanded(key: string, fallback: boolean): boolean {
+ try {
+ const raw = window.sessionStorage.getItem(key);
+ return raw === null ? fallback : parseStoredDockExpanded(raw);
+ } catch {
+ return fallback;
+ }
+}
+
+/** Persist an expanded flag (`'1'` / removed); storage failures are swallowed. */
+export function writeStoredDockExpanded(key: string, expanded: boolean): void {
+ try {
+ if (expanded) window.sessionStorage.setItem(key, '1');
+ else window.sessionStorage.removeItem(key);
+ } catch {
+ /* private mode — the rail just won't survive navigation */
+ }
+}
+
+/**
+ * ADR-0057 P3c — arm the console dock to mount EXPANDED on the next page that
+ * hosts it. The `/ai` page's "collapse to dock" affordance calls this right
+ * before navigating back, completing the maximize ⇄ tuck loop with the same
+ * thread showing in the rail. Lives here (not ChatDock.tsx) so AiChatPage can
+ * import it without a module cycle — ChatDock.tsx imports ChatPane FROM
+ * AiChatPage.
+ */
+export function armChatDockExpanded(): void {
+ writeStoredDockExpanded(DOCK_EXPANDED_STORAGE_KEY, true);
+}
+
export type ChatDockShortcut = 'toggle';
/**
diff --git a/packages/app-shell/src/views/metadata-admin/i18n.ts b/packages/app-shell/src/views/metadata-admin/i18n.ts
index 6a326c25cc..f95058a58a 100644
--- a/packages/app-shell/src/views/metadata-admin/i18n.ts
+++ b/packages/app-shell/src/views/metadata-admin/i18n.ts
@@ -1154,6 +1154,7 @@ const ENGINE_STRINGS_EN: Record = {
'engine.studio.if.noApp': 'This package has no app yet.',
'engine.studio.if.noNavItems': 'No nav items yet — (click “Edit” above to add)',
'engine.studio.if.previewIsRuntime': 'Live preview',
+ 'engine.studio.if.tabCanvas': 'Canvas',
'engine.studio.if.noAppTitle': 'This package has no app yet',
'engine.studio.if.noAppHint': 'Create an app to design its navigation and interfaces.',
'engine.studio.if.readonlyPreview': '{type} shows a read-only preview for now; design support is in progress.',
@@ -2357,6 +2358,7 @@ const ENGINE_STRINGS_ZH: Record = {
'engine.studio.if.noApp': '这个软件包还没有应用。',
'engine.studio.if.noNavItems': '还没有导航项 —(点上方「编辑」添加)',
'engine.studio.if.previewIsRuntime': '实时预览',
+ 'engine.studio.if.tabCanvas': '画布',
'engine.studio.if.noAppTitle': '这个软件包还没有应用',
'engine.studio.if.noAppHint': '创建一个应用来设计它的导航与界面。',
'engine.studio.if.readonlyPreview': '{type} 暂用只读预览,设计能力建设中。',
diff --git a/packages/app-shell/src/views/studio-design/StudioAiCopilot.tsx b/packages/app-shell/src/views/studio-design/StudioAiCopilot.tsx
index 11082fce60..8578c64a1f 100644
--- a/packages/app-shell/src/views/studio-design/StudioAiCopilot.tsx
+++ b/packages/app-shell/src/views/studio-design/StudioAiCopilot.tsx
@@ -1,6 +1,7 @@
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import React from 'react';
+import { useNavigate } from 'react-router-dom';
import { useAuth } from '@object-ui/auth';
import { Button } from '@object-ui/components';
import { Sparkles, PanelLeftClose } from 'lucide-react';
@@ -9,6 +10,7 @@ import { useChatConversation } from '../../hooks/useChatConversation';
import { chatConversationScope, chatProductOfAgent } from '../../hooks/chatScope';
import { resolveSurfaceAgent } from '../../hooks/surfaceAgent';
import { ChatPane, resolveApiBase, type PendingFirstMessage } from '../../console/ai/AiChatPage';
+import { ChatDockPanel, ChatDockLauncher, useChatDockState } from '../../layout/ChatDock';
export interface StudioAiCopilotProps {
/** The package the Studio surface is editing — scopes the build agent to it. */
@@ -17,26 +19,28 @@ export interface StudioAiCopilotProps {
locale?: string;
}
+interface StudioCopilotConversationProps {
+ /** The package the Studio surface is editing — scopes the build agent to it. */
+ packageId: string;
+ /** ADR-0037/P3c — the Live Canvas open/close seam, forwarded to ChatPane. */
+ onCanvasOpenChange?: (open: boolean) => void;
+}
+
/**
- * The Studio design surface's left AI copilot (ADR-0080 `aiSlot`). It embeds the
- * SAME build-agent chat as the full-page `/ai/build` surface (ChatPane), but
- * scoped to the package the user is designing (`editPackageId`), so "add a field
- * / add a view / add an automation" acts on THIS app without leaving the design
- * surface — the iterate copilot ADR-0080 calls for.
- *
- * Open-core: the chat UI ships in OSS app-shell but is INERT without a served
- * agent. We gate on the live agent catalog (`useAgents`) — an env that serves a
- * `build` agent (the cloud AI Studio) lights the copilot up; a community env
- * with no agent renders nothing, leaving the plain three-zone surface. Same
- * "cloud fills it" contract as the floating chat FAB, with no injected prop
- * threaded through the console.
+ * The Studio copilot's chat body — the build agent scoped to the package being
+ * designed, over the ADR-0057 P1 `(user, app, product)` conversation. Extracted
+ * from {@link StudioAiCopilot} so the P3c right dock ({@link StudioChatDock})
+ * can host the SAME conversation in the shared dock chrome. Renders nothing
+ * when the AI catalog is empty (community edition / no seat) — callers that
+ * add chrome around it must apply the same gate so no empty shell renders.
*/
-export function StudioAiCopilot({ packageId, locale }: StudioAiCopilotProps): React.ReactElement | null {
- const zh = (locale ?? '').toLowerCase().startsWith('zh');
+export function StudioCopilotConversation({
+ packageId,
+ onCanvasOpenChange,
+}: StudioCopilotConversationProps): React.ReactElement | null {
const { user } = useAuth();
const userId = user?.id;
const apiBase = React.useMemo(() => resolveApiBase(), []);
- const [collapsed, setCollapsed] = React.useState(false);
const { agents, isLoading: agentsLoading, error: agentsError } = useAgents({ apiBase });
@@ -71,6 +75,56 @@ export function StudioAiCopilot({ packageId, locale }: StudioAiCopilotProps): Re
// No agent served (community edition / misconfigured) → no copilot, plain surface.
if (!agentsLoading && agents.length === 0) return null;
+ return (
+ {}}
+ onShare={() => {}}
+ showDebug={false}
+ onCanvasOpenChange={onCanvasOpenChange}
+ />
+ );
+}
+
+/**
+ * The Studio design surface's left AI copilot (ADR-0080 `aiSlot`). It embeds the
+ * SAME build-agent chat as the full-page `/ai/build` surface (ChatPane), but
+ * scoped to the package the user is designing (`editPackageId`), so "add a field
+ * / add a view / add an automation" acts on THIS app without leaving the design
+ * surface — the iterate copilot ADR-0080 calls for.
+ *
+ * Open-core: the chat UI ships in OSS app-shell but is INERT without a served
+ * agent. We gate on the live agent catalog (`useAgents`) — an env that serves a
+ * `build` agent (the cloud AI Studio) lights the copilot up; a community env
+ * with no agent renders nothing, leaving the plain three-zone surface. Same
+ * "cloud fills it" contract as the floating chat FAB, with no injected prop
+ * threaded through the console.
+ *
+ * ADR-0057 P3c: this LEFT panel is the flag-off rendering only — with
+ * `features.chatDock` on, StudioDesignSurface renders {@link StudioChatDock}
+ * (the shared right dock) instead.
+ */
+export function StudioAiCopilot({ packageId, locale }: StudioAiCopilotProps): React.ReactElement | null {
+ const zh = (locale ?? '').toLowerCase().startsWith('zh');
+ const apiBase = React.useMemo(() => resolveApiBase(), []);
+ const [collapsed, setCollapsed] = React.useState(false);
+
+ // Same catalog gate as the conversation body (useAgents caches, so this is
+ // one fetch): the CHROME must hide too, or an agent-less env would show an
+ // empty framed panel.
+ const { agents, isLoading: agentsLoading } = useAgents({ apiBase });
+ if (!agentsLoading && agents.length === 0) return null;
+
if (collapsed) {
return (
);
}
+
+export interface StudioChatDockProps {
+ /** The package the Studio surface is editing — scopes the build agent to it. */
+ packageId: string;
+ /** UI locale (from the Studio surface) for the dock chrome. */
+ locale?: string;
+}
+
+/**
+ * ADR-0057 P3c — the Studio copilot rendered as the shared RIGHT dock (the
+ * ADR's decided grid: `[left: nav/tree] [center: canvas + properties] [right:
+ * chat]`). Same conversation as the left copilot it replaces (the P1
+ * `(user, package, build)` scope), in the same {@link ChatDockPanel} chrome as
+ * the console rail.
+ *
+ * Differences from the console rail, on purpose:
+ * - Default EXPANDED (the copilot has always been visible by default) and
+ * NOT persisted (parity with the old panel's in-memory collapse).
+ * - Collapsed state = the {@link ChatDockLauncher} edge button — Studio has
+ * no FAB to double as the launcher.
+ * - Maximize opens `/ai/build?package=…`, which resumes THIS thread (the
+ * scope is keyed on the package, not the surface).
+ * - The Live Canvas auto-maximizes the rail on open, tucks on close
+ * (ADR-0037 — the preview needs more width than the rail has).
+ */
+export function StudioChatDock({ packageId, locale }: StudioChatDockProps): React.ReactElement | null {
+ const zh = (locale ?? '').toLowerCase().startsWith('zh');
+ const navigate = useNavigate();
+ const apiBase = React.useMemo(() => resolveApiBase(), []);
+ const dock = useChatDockState({ defaultExpanded: true });
+
+ // The catalog gate lives HERE (not in ChatDockPanel): the `children` body
+ // override below bypasses the panel's default self-gating conversation.
+ const { agents, isLoading: agentsLoading } = useAgents({ apiBase });
+
+ const handleCanvasOpenChange = React.useCallback(
+ (open: boolean) => (open ? dock.maximize() : dock.restore()),
+ [dock.maximize, dock.restore],
+ );
+
+ if (!agentsLoading && agents.length === 0) return null;
+
+ if (!dock.expanded) {
+ return ;
+ }
+
+ return (
+ navigate(`/ai/build?package=${encodeURIComponent(packageId)}`)}
+ >
+
+
+ );
+}
diff --git a/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx b/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx
index 44f7be5a1f..e053c140bb 100644
--- a/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx
+++ b/packages/app-shell/src/views/studio-design/StudioDesignSurface.tsx
@@ -17,7 +17,9 @@
import * as React from 'react';
import { useParams, useNavigate, useSearchParams, Link } from 'react-router-dom';
import { SchemaRenderer, useAdapter, SchemaRendererProvider } from '@object-ui/react';
-import { StudioAiCopilot } from './StudioAiCopilot';
+import { StudioAiCopilot, StudioChatDock } from './StudioAiCopilot';
+import { nextCenterTab, type StudioCenterTab } from './centerTab';
+import { getRuntimeConfig } from '../../runtime-config';
import {
GridFieldAuthoringProvider,
cn,
@@ -585,15 +587,26 @@ export function StudioDesignSurface({ aiSlot }: StudioDesignSurfaceProps): React
};
}, [shellClient, packageId, publishNonce]);
+ // ADR-0057 P3c — the decided Studio grid: `[left: nav/tree] [center: canvas +
+ // properties tabs] [right: chat]`. Gated on the rollout flag ALONE (not
+ // flag + agent catalog): the catalog resolves async, and keying the layout on
+ // it would flip the whole grid after load. On a flag-on-but-agent-less env
+ // the folded center tabs still work; the right dock simply self-gates away.
+ // An injected `aiSlot` (the cloud seam, ADR-0080) keeps the legacy left
+ // panel untouched in every flag state — the cloud edition migrates on its
+ // own schedule.
+ const chatDockMode = !aiSlot && getRuntimeConfig().features.chatDock === true;
+
return (
{/* Left AI copilot (ADR-0080). An explicit `aiSlot` overrides; otherwise the
* built-in Studio copilot self-gates on the live agent catalog — it embeds
* the build-agent chat scoped to THIS package, or renders nothing when no
- * agent is served (community edition). */}
+ * agent is served (community edition). With the ADR-0057 P3c dock flag on,
+ * the copilot renders as the RIGHT dock below instead of this left panel. */}
{aiSlot ? (
- ) : (
+ ) : chatDockMode ? null : (
)}
@@ -712,11 +725,17 @@ export function StudioDesignSurface({ aiSlot }: StudioDesignSurfaceProps): React
onDraftSaved={onDraftSaved}
onCreateApp={readOnly ? undefined : () => setAppCreating(true)}
readOnly={readOnly}
+ foldInspector={chatDockMode}
/>
)}
+ {/* ADR-0057 P3c — the copilot as the shared right dock (same package-
+ * scoped build thread as the left panel it replaces; self-gates on the
+ * agent catalog like the copilot always has). */}
+ {chatDockMode && }
+
void;
/** Courtesy gate: hide/disable nav-authoring affordances. */
readOnly?: boolean;
+ /** ADR-0057 P3c — the chat dock owns the right side, so the inspector folds
+ * into center `[canvas | properties]` tabs instead of its own right aside.
+ * Default false → the classic three-zone layout, pixel-identical. */
+ foldInspector?: boolean;
}): React.ReactElement {
const client = useMetadataClient();
const locale = useMetadataLocale();
@@ -1006,6 +1030,19 @@ function InterfacesPillar({
const [inspectorTab, setInspectorTab] = React.useState<'props' | 'source'>('source');
const [draft, setDraft] = React.useState>({});
const [selection, setSelection] = React.useState(null);
+ // ADR-0057 P3c — the folded-layout center tab (canvas | properties). The
+ // auto-switch below reacts to inspector-target EDGES (select a block → jump
+ // to Properties; deselect → back to Canvas) while preserving a manual choice
+ // in steady state — see nextCenterTab. Inert when `foldInspector` is off.
+ const [centerTab, setCenterTab] = React.useState('canvas');
+ const hasInspectorTarget = Boolean((editNav && navSel) || selection);
+ const prevInspectorTargetRef = React.useRef(hasInspectorTarget);
+ React.useEffect(() => {
+ if (!foldInspector) return;
+ const hadTarget = prevInspectorTargetRef.current;
+ prevInspectorTargetRef.current = hasInspectorTarget;
+ setCenterTab((cur) => nextCenterTab(cur, hadTarget, hasInspectorTarget));
+ }, [foldInspector, hasInspectorTarget]);
const [loading, setLoading] = React.useState(false);
const [saving, setSaving] = React.useState(false);
const [hasDraft, setHasDraft] = React.useState(false);
@@ -1227,6 +1264,189 @@ function InterfacesPillar({
}
}, [client, appName, appDraft, onDraftSaved]);
+ // ADR-0057 P3c — the canvas and the inspector are rendered by BOTH layouts
+ // below (the classic three-zone row, and the folded center-tabs grid that
+ // cedes the right side to the chat dock), so they are built once here. The
+ // extraction is presentation-neutral: the classic branch composes exactly
+ // the pre-P3c tree.
+ const canvasEl = (
+
+