From 5e6b6a471aaa003e8b1f7990788a61a6930d454f Mon Sep 17 00:00:00 2001 From: AlexZ005 Date: Fri, 27 Nov 2026 01:04:03 +0200 Subject: [PATCH 1/2] 107 107-panels: the panel registry (panelsCore + panels.js) and show panel on it Every real panel by its own name (Animation, UV / Shader / HUD editor, Statistics, Profiler read-only and allowed); an unknown name errors with the valid names and the block list by reason; whole-word block matching (Profiler is not profile); show {action: panels} reads the registry with state; focus reports visible/front truthfully and brings a hidden panel forward; Dock / Left / Right sidebar targets; move, maximize, restore, collapse/expand a panel's own sidebars; named layouts apply/save. Co-Authored-By: Claude Opus 5.5 --- src/components/shared/WindowShell.svelte | 29 ++ src/lib/ai/panels.js | 402 +++++++++++++++++++++++ src/lib/ai/panelsCore.js | 173 ++++++++++ src/lib/ai/personToolNames.js | 2 + src/lib/ai/personTools.js | 28 +- src/lib/ai/showCore.js | 108 +----- src/lib/ai/showTool.js | 296 ++++++++++++----- src/lib/dockMenu.js | 13 + src/lib/windowPanes.js | 28 ++ tests/e2e/connector-show-panels.test.cjs | 145 ++++++++ tests/unit/panels107.test.js | 95 ++++++ tests/unit/showScene.test.js | 20 +- 12 files changed, 1152 insertions(+), 187 deletions(-) create mode 100644 src/lib/ai/panels.js create mode 100644 src/lib/ai/panelsCore.js create mode 100644 src/lib/windowPanes.js create mode 100644 tests/e2e/connector-show-panels.test.cjs create mode 100644 tests/unit/panels107.test.js diff --git a/src/components/shared/WindowShell.svelte b/src/components/shared/WindowShell.svelte index 443046fdb..250b2f3f6 100644 --- a/src/components/shared/WindowShell.svelte +++ b/src/components/shared/WindowShell.svelte @@ -9,6 +9,7 @@ import Icon from '../ui/Icon.svelte' import { paneLocks, togglePaneLock } from '$lib/ui/paneLocks.js' import { edgeFade } from '$lib/ui/edgeFade.js' + import { registerPanes } from '$lib/windowPanes.js' // 197: reusable window CHROME. A MAIN area flanked by a collapsible PRIMARY // sidebar and a SECONDARY panel that can show one of several MODES (e.g. @@ -183,6 +184,34 @@ persistSecondary() if (narrow && narrowMode) narrowPane = 'main' } + // 107-panels: the assistant's show {state: collapse | expand, pane} works these same panes ($lib/windowPanes) + $effect(() => + registerPanes(key, { + status: () => ({ + primary: { available: !hidePrimary && !!primary, open: narrow ? pane === 'primary' : primaryOpen }, + secondary: { available: secondaryModes.length > 0 && !!secondary, open: narrow ? !!narrowMode : secondaryOpen, mode: secondaryMode }, + locked, + narrow + }), + setPrimary: (open: boolean) => { + if (narrow) { + narrowPane = open ? 'primary' : 'main' + return + } + primaryOpen = open + writePanelOpen(`ws:${key}:primaryOpen`, primaryOpen) + }, + setSecondary: (open: boolean) => { + if (narrow) { + narrowPane = open ? secondaryMode : 'main' + return + } + secondaryOpen = open + if (open) secondaryPinned = true + persistSecondary() + } + }) + ) export function secondaryStatus() { if (narrow) return { open: !!narrowMode, mode: narrowMode ?? secondaryMode, pinned: secondaryPinned, narrow: true } return { open: secondaryOpen, mode: secondaryMode, pinned: secondaryPinned } diff --git a/src/lib/ai/panels.js b/src/lib/ai/panels.js new file mode 100644 index 000000000..b1b89b7bf --- /dev/null +++ b/src/lib/ai/panels.js @@ -0,0 +1,402 @@ +// Roadmap 107 (107-panels) — THE PANEL REGISTRY, the live half (a lazy chunk: showTool.js and the UI-state read +// load it on first use). panelsCore.js is the list; this module asks the app where each panel is and whether the +// person can see it, and opens, closes, brings forward, moves and maximizes through the app's OWN seams +// (panelToggles, dockMenu, dockHost, sidebars, focusMode, the WindowShell panes) so a panel lands where the +// person keeps it and every gesture is one the person could have made. +// +// THE STATE WORDS (owner 2026-11-27: "show panel focus answers changed:false while the panel is not in front"): +// open it is open somewhere: a dock tab, a sidebar tab, a floating window or a pop-out window +// where 'dock' | 'left' | 'right' | 'floating' | 'window' | null (closed) +// visible the person can see it now: its dock tab is the one showing and the dock is not minimized, its +// sidebar tab is in front and the column is on screen, its floating window is its group's tab; +// never while focus mode hides it or Play mode hides the editor +// front visible AND nothing covers it: a floating window is the top window; a dock / sidebar tab in +// front is front + +import { get } from 'svelte/store'; +import { PANELS, PANEL_BY_ID, TARGETS, blockedList, paneOf } from './panelsCore.js'; +import { inspectorClose, inspectorKind, chatHidden, chatTab, showSidebar, closeSelectionInspector } from '../../stores/appStore'; +import { isLocked } from '../../stores/sceneStore'; + +/** @typedef {import('./panelsCore.js').PanelDef} PanelDef */ +/** @typedef {'dock'|'left'|'right'|'floating'|'window'|null} Where */ + +/** @param {number} frames */ +export const waitFrames = (frames) => + new Promise((resolve) => { + let n = 0; + const step = () => (++n >= frames || typeof requestAnimationFrame === 'undefined' ? resolve(undefined) : requestAnimationFrame(step)); + if (typeof requestAnimationFrame === 'undefined') setTimeout(resolve, frames * 16); + else requestAnimationFrame(step); + }); + +/** the app's modules, loaded once (all already in the editor's chunks) */ +async function mods() { + const [dockMenu, bottomDock, sidebars, focusMode, windowTabs, windowFocus, phone] = await Promise.all([ + import('../dockMenu'), + import('../bottomDock'), + import('../sidebars'), + import('../focusMode'), + import('../windowTabs'), + import('../windowFocus'), + import('../ui/phoneShell.js') + ]); + return { dockMenu, bottomDock, sidebars, focusMode, windowTabs, windowFocus, phone }; +} + +/** @typedef {Awaited>} Mods */ + +/** where one panel is open @param {PanelDef} p @param {Mods} m @returns {Promise} */ +async function whereOf(p, m) { + if (p.via === 'debugger') { + const { debugOpen } = await import('../flowDebug'); + if (!get(debugOpen)) return null; + const w = m.dockMenu.windowWhere('debugger'); + return w ?? 'floating'; + } + if (p.via === 'inspector' || p.via === 'scene') { + const tab = p.via === 'scene' ? 'scene' : 'inspector'; + const tabs = get(m.sidebars.sidebarTabs); + if (tabs.left.includes(tab)) return 'left'; + if (tabs.right.includes(tab)) return 'right'; + const kind = get(inspectorKind); + const showing = !get(inspectorClose) && (p.via === 'scene' ? kind === 'scene' : kind !== 'scene'); + if (!showing) return null; + return get(m.phone.phoneShell) ? 'dock' : 'floating'; + } + return m.dockMenu.windowWhere(p.key); +} + +/** + * One panel's state, read now. + * @param {PanelDef} p @param {Mods} m + * @returns {Promise<{open: boolean, where: Where, visible: boolean, front: boolean, tab?: string}>} + */ +async function stateOf(p, m) { + const where = await whereOf(p, m); + if (!where) return { open: false, where: null, visible: false, front: false }; + const playing = get(isLocked) === true; + const focus = get(m.focusMode.focusMode); + const key = p.via === 'scene' ? 'scene' : p.key; + let visible = false; + let front = false; + if (where === 'window') { + visible = true; + front = true; + } else if (where === 'dock') { + visible = !get(m.bottomDock.dockMinimized) && get(m.bottomDock.dockShownKeys).includes(key) && focus !== 'viewport'; + if (get(m.phone.phoneShell) && (p.via === 'inspector' || p.via === 'scene')) visible = true; + front = visible; + } else if (where === 'left' || where === 'right') { + visible = !!get(m.sidebars.sidebarVisible)[where] && !m.sidebars.sidebarTabCovered(key) && !focus; + front = visible; + } else { + const group = m.windowTabs.groupOfKey(key); + visible = (!group || group.active === key) && !focus; + front = visible && (m.windowFocus.isTopVisibleWindow(key) || p.via === 'inspector' || p.via === 'scene'); + } + if (playing) visible = front = false; + // the Chat window holds two panels: the one on its other tab is open but not showing + if (p.via === 'chat') { + const tab = get(chatTab); + const mine = p.id === 'assistant' ? 'assistant' : 'session'; + if (tab !== mine) visible = front = false; + return { open: true, where, visible, front, tab }; + } + return { open: true, where, visible, front }; +} + +/** the dock and the two sidebar columns, read now @param {Mods} m */ +function targetsState(m) { + const b = m.bottomDock; + const showing = get(b.visibleDockKey); + const minimized = get(b.dockMinimized); + const vis = get(m.sidebars.sidebarVisible); + const tabs = get(m.sidebars.sidebarTabs); + const shown = get(m.sidebars.sidebarShown); + const title = (/** @type {string} */ k) => PANELS.find((p) => p.key === k || (p.via === 'scene' && k === 'scene'))?.title ?? b.DOCK_TITLES[k] ?? k; + return { + dock: { + open: (!!showing && !minimized) || get(b.dockEmptyShown), + minimized: !!showing && minimized, + front: showing ? title(showing) : null, + tabs: get(b.dockTabs).map((t) => title(t.key)) + }, + left: { open: !!vis.left, front: shown.left ? title(shown.left) : null, tabs: tabs.left.map(title) }, + right: { open: !!vis.right, front: shown.right ? title(shown.right) : null, tabs: tabs.right.map(title) } + }; +} + +/** a panel's own sidebars (panes), when it has any and they are mounted @param {PanelDef} p */ +async function panesState(p) { + if (!p.panes) return undefined; + const out = /** @type {Record} */ ({}); + const names = Object.keys(p.panes); + if (p.id === 'code') { + const { codeLeftOpen, codeRightOpen } = await import('../codeSidebars'); + out[names[0]] = !!get(codeLeftOpen); + out[names[1]] = !!get(codeRightOpen); + return out; + } + const { panesOf } = await import('../windowPanes.js'); + const api = panesOf(p.key); + if (!api) return undefined; + const s = api.status(); + out[names[0]] = s.primary.available ? s.primary.open : null; + if (names[1]) out[names[1]] = s.secondary.available ? s.secondary.open : null; + return out; +} + +/** one panel's read @param {string} id */ +export async function readPanel(id) { + const p = PANEL_BY_ID[id]; + if (!p) return null; + const m = await mods(); + const s = await stateOf(p, m); + const panes = s.open ? await panesState(p) : undefined; + return { id: p.id, title: p.title, ...s, ...(panes ? { panes } : {}) }; +} + +/** + * THE READ every surface shares (show {action: "panels"}, the connector's UI-state panels field): every + * panel with what it contains and its state now, the refused surfaces by reason, the dock and sidebars, + * focus mode, and the named layouts. + */ +export async function readPanels() { + const m = await mods(); + const panels = []; + for (const p of PANELS) { + const s = await stateOf(p, m); + const panes = s.open ? await panesState(p) : undefined; + panels.push({ + id: p.id, + title: p.title, + description: p.description, + readOnly: !!p.readOnly, + ...s, + ...(p.panes ? { paneNames: Object.keys(p.panes) } : {}), + ...(panes ? { panes } : {}) + }); + } + const { uiLayouts, activeLayoutId } = await import('../uiLayouts'); + const layouts = /** @type {any[]} */ (get(uiLayouts)).map((l) => l.name); + const activeId = get(activeLayoutId); + const active = /** @type {any[]} */ (get(uiLayouts)).find((l) => l.id === activeId)?.name ?? null; + return { + panels, + blocked: blockedList(), + ...targetsState(m), + focusMode: get(m.focusMode.focusMode), + playing: get(isLocked) === true, + phone: !!get(m.phone.phoneShell), + layouts: { names: layouts, active }, + targets: Object.values(TARGETS).map((t) => ({ id: t.id, title: t.title, description: t.description })) + }; +} + +// ---------------------------------------------------------------- acting + +/** open a panel where it lives (or brings it forward when it is open) @param {PanelDef} p */ +export async function openPanel(p) { + if (p.via === 'inspector') return showSidebar('properties', { focus: true }); + const { focusWindow } = await import('../dockMenu'); + if (p.via === 'scene') { + if (focusWindow('scene')) return; + if (!get(inspectorClose) && get(inspectorKind) === 'scene') return; + return showSidebar('scene', { focus: true }); + } + if (p.via === 'chat') { + const { openChatTab } = await import('../chat/chatWindow.js'); + return openChatTab(p.id === 'assistant' ? 'assistant' : 'session'); + } + if (p.via === 'debugger') { + const { setDebugOpen } = await import('../flowDebug'); + if (focusWindow('debugger')) return; + setDebugOpen(true); + const { raiseWindow } = await import('../windowFocus'); + await waitFrames(2); + raiseWindow('debugger'); + return; + } + if (focusWindow(p.key)) return; + if (p.via === 'toggle') { + const { togglePanel } = await import('../panelToggles'); + return togglePanel(p.key); + } + const { HOSTED } = await import('../dockHost'); + HOSTED[p.key]?.open(); +} + +/** close a panel @param {PanelDef} p */ +export async function closePanel(p) { + if (p.via === 'inspector') { + const { closeInspectorTab, inspectorTabs } = await import('../sidebars'); + if (get(inspectorTabs).inspector) return closeInspectorTab('inspector'); + return closeSelectionInspector(); + } + if (p.via === 'scene') { + const { closeInspectorTab, inspectorTabs } = await import('../sidebars'); + if (get(inspectorTabs).scene) return closeInspectorTab('scene'); + if (get(inspectorKind) === 'scene') inspectorClose.set(true); + return; + } + if (p.via === 'chat') return chatHidden.set('hidden'); + if (p.via === 'debugger') { + const { setDebugOpen } = await import('../flowDebug'); + return setDebugOpen(false); + } + if (p.via === 'hosted') { + const { HOSTED } = await import('../dockHost'); + return HOSTED[p.key]?.close(); + } + const { closeDockView } = await import('../dockMenu'); + closeDockView(p.key); +} + +/** + * Bring an open panel to the front where it is: its dock tab (un-minimizing the dock), its sidebar tab (showing + * a hidden column), its floating window (its group's tab, raised and pulled back on screen). Leaves focus mode + * when focus mode hides it. Returns what it had to undo for Back. + * @param {PanelDef} p + * @returns {Promise<{exitedFocus: string | null}>} + */ +export async function bringForward(p) { + const m = await mods(); + const focus = get(m.focusMode.focusMode); + const where = await whereOf(p, m); + const maximized = focus === 'dock' && where === 'dock' && get(m.bottomDock.visibleDockKey) === p.key; + let exitedFocus = null; + if (focus && !maximized) { + m.focusMode.exitFocus(); + exitedFocus = focus; + } + await openPanel(p); + if (where === 'floating' && p.via !== 'inspector' && p.via !== 'scene') { + // a floating window: raise it whatever the open path did (focusWindow raises only one it can find) + if (!m.windowFocus.raiseWindow(p.key)) m.windowFocus.raiseWindowNode(m.windowTabs.nodeOf(p.key)); + } + return { exitedFocus }; +} + +/** + * Move an open panel to the dock, a sidebar or a floating window — the "+" menus' and the tab menus' own moves. + * @param {PanelDef} p @param {'dock'|'left'|'right'|'floating'} to + * @returns {Promise<{ok: true, from: Where} | {error: string}>} + */ +export async function movePanel(p, to) { + const m = await mods(); + const from = await whereOf(p, m); + if (!from) return { error: p.title + ' is not open: open it first (state: "open"), then move it' }; + if (from === to) return { ok: true, from }; + if (from === 'window') return { error: p.title + ' is in its own pop-out window: the person brings it back with its window\'s Dock button' }; + if (p.via === 'inspector' || p.via === 'scene') { + if (to !== 'left' && to !== 'right') return { error: p.title + ' lives only in a sidebar: to: "left" or "right"' }; + const ok = m.sidebars.moveSidebarTab(p.via === 'scene' ? 'scene' : 'inspector', to); + return ok ? { ok: true, from } : { error: p.title + ' cannot move there on this screen' }; + } + if (get(m.phone.phoneShell)) return { error: 'on a phone the panels live in the bottom sheet: moving them is for a wider screen' }; + const key = p.key; + if (to === 'floating') { + if (from === 'dock') { + if (!m.dockMenu.canUndockTab(key)) return { error: p.title + ' has no floating window' }; + m.bottomDock.armDockMode(key, false); + return { ok: true, from }; + } + const { floatSidebarTab } = await import('../sidebarMenu'); + return floatSidebarTab(key) ? { ok: true, from } : { error: p.title + ' cannot float' }; + } + if (to === 'dock' && !m.dockMenu.canDockHere(key)) return { error: p.title + ' cannot be docked' }; + return m.dockMenu.moveWindowTo(key, to) ? { ok: true, from } : { error: p.title + ' cannot move to the ' + (to === 'dock' ? 'dock' : to + ' sidebar') + ' on this screen' }; +} + +/** + * Maximize a DOCKED panel (the dock tab menu's "Maximize (focus mode)": it fills the window, everything else + * hidden, nothing closed) or restore. + * @param {PanelDef} p @param {boolean} on + * @returns {Promise<{ok: true, was: string | null} | {error: string}>} + */ +export async function maximizePanel(p, on) { + const m = await mods(); + const was = get(m.focusMode.focusMode); + if (!on) { + m.focusMode.exitFocus(); + return { ok: true, was }; + } + if (get(isLocked) === true) return { error: 'the person is playing: maximize is for the editor' }; + const where = await whereOf(p, m); + if (where !== 'dock') return { error: 'maximize fills the window with a DOCKED panel; ' + p.title + ' is ' + (where ? (where === 'floating' ? 'floating' : where === 'window' ? 'in a pop-out window' : 'in the ' + where + ' sidebar') : 'closed') + ': move it first (to: "dock")' }; + m.focusMode.maximizeDockTab(p.key); + return { ok: true, was }; +} + +/** + * Open or close one of a panel's OWN sidebars (panes): the Explorer's folder tree, the Code workspace's files / + * tools sidebars, the UV / HUD / Timeline / Profiler side panes. + * @param {PanelDef} p @param {string} paneName @param {boolean} open + * @returns {Promise<{ok: true, pane: string, was: boolean} | {error: string}>} + */ +export async function setPane(p, paneName, open) { + if (!p.panes) return { error: p.title + ' has no sidebars of its own to collapse' }; + const pane = paneOf(p, paneName); + if (!pane) return { error: p.title + '\'s sidebars are ' + Object.entries(p.panes).map(([k, v]) => k + ' (' + v + ')').join(', ') }; + const index = Object.keys(p.panes).indexOf(pane); + if (p.id === 'code') { + const { codeLeftOpen, codeRightOpen } = await import('../codeSidebars'); + const store = index === 0 ? codeLeftOpen : codeRightOpen; + const was = !!get(store); + store.set(open); + return { ok: true, pane, was }; + } + const { panesOf } = await import('../windowPanes.js'); + const api = panesOf(p.key); + if (!api) return { error: p.title + ' is not on screen: open it first' }; + const s = api.status(); + const side = index === 0 ? s.primary : s.secondary; + if (!side.available) return { error: p.title + ' shows no ' + pane + ' sidebar here' }; + if (s.locked) return { error: 'the person locked ' + p.title + '\'s sidebars (its handle menu): they unlock it' }; + const was = !!side.open; + if (index === 0) api.setPrimary(open); + else api.setSecondary(open); + return { ok: true, pane, was }; +} + +/** + * The dock / a sidebar column as a named target: open, close or toggle. Closing hides; every tab stays open. + * @param {'dock'|'left'|'right'} id @param {'open'|'close'|'toggle'} state + * @returns {Promise<{changed: boolean, open: boolean, undo: () => void} | {error: string}>} + */ +export async function setTarget(id, state) { + const m = await mods(); + if (id === 'dock') { + const b = m.bottomDock; + const isOpen = () => (!!get(b.visibleDockKey) && !get(b.dockMinimized)) || get(b.dockEmptyShown); + const was = isOpen(); + const want = state === 'toggle' ? !was : state === 'open'; + if (want === was) return { changed: false, open: was, undo: () => {} }; + const minBefore = get(b.dockMinimized); + const emptyBefore = get(b.dockEmptyOpen); + if (get(m.phone.phoneShell)) { + const { toggleDock } = await import('../panelToggles'); + toggleDock(); + } else if (get(b.visibleDockKey)) b.dockMinimized.set(!want); + else b.setDockEmptyOpen(want); + await waitFrames(1); + return { + changed: isOpen() !== was, + open: isOpen(), + undo: () => { + b.dockMinimized.set(minBefore); + b.dockEmptyOpen.set(emptyBefore); + } + }; + } + if (get(m.phone.phoneShell)) return { error: 'a phone has no sidebar columns: its panels live in the bottom sheet (the dock)' }; + const s = m.sidebars; + const was = !!get(s.sidebarVisible)[id]; + const want = state === 'toggle' ? !was : state === 'open'; + if (want === was) return { changed: false, open: was, undo: () => {} }; + s.toggleSidebar(id, want); + await waitFrames(1); + const now = !!get(s.sidebarVisible)[id]; + return { changed: now !== was, open: now, undo: () => s.toggleSidebar(id, was) }; +} diff --git a/src/lib/ai/panelsCore.js b/src/lib/ai/panelsCore.js new file mode 100644 index 000000000..9a2289870 --- /dev/null +++ b/src/lib/ai/panelsCore.js @@ -0,0 +1,173 @@ +// Roadmap 107 (connector round 3, 107-panels) — THE PANEL REGISTRY, the pure half (a LEAF: imports nothing). +// Every real editor panel / window / dock tab the assistant may name, in one list: its id, the title the +// person sees on its tab, one line on what is inside it, whether it is read-only, and how the app opens it. +// `show` (showTool.js) acts on it and `readPanels` (panels.js) reports it; the connector's UI-state read +// (107-ui-state) takes its panels field from the same read, so the three never disagree. +// +// THE NAME RULE (owner 2026-11-27, "show panel Animation silently opens the Timeline"): a name is a panel's +// id, its title, or one of its aliases — the words people use for THAT panel. Nothing is guessed: an unknown +// name is an error that lists every valid name and every refused surface with its reason. +// +// THE BLOCK RULE (rule 2 of show, unchanged): sign-in, account, consent, publishing, connected apps, payment +// and settings stay the person's own to open. It is matched on WHOLE WORDS, so "Profiler" is not "profile" +// and "Statistics" is not refused — the read-only views (Profiler, Statistics) are not settings. + +/** + * @typedef {'toggle' | 'hosted' | 'inspector' | 'scene' | 'chat' | 'debugger'} PanelVia + * toggle panelToggles.togglePanel / dockMenu.focusWindow / closeDockView (the dockable editors) + * hosted dockHost.HOSTED[key] (floating windows the dock can host) + * inspector the selection's Properties (showSidebar 'properties') + * scene Configure Scene, the Inspector's other tab (showSidebar 'scene') + * chat the Chat window on its Session or Assistant tab + * debugger the flow Debugger (flowDebug.setDebugOpen) + * @typedef {{ + * id: string, + * key: string, + * title: string, + * description: string, + * via: PanelVia, + * readOnly?: boolean, + * aliases?: string[], + * panes?: Record + * }} PanelDef + */ + +/** + * Every panel, in the order the person meets them. `key` is the app's own window key (dockMenu.windowWhere, + * the dock, the sidebars); `panes` names a panel's own sidebars that show {state: collapse | expand, pane} + * opens and closes (the WindowShell primary / secondary panes, the Code workspace's two sidebars). + * @type {PanelDef[]} + */ +export const PANELS = [ + { id: 'explorer', key: 'explorer', title: 'Explorer', via: 'toggle', description: 'The Library: the person\'s files and folders as a folder tree and a file list', aliases: ['library', 'files', 'file explorer', 'file browser'], panes: { tree: 'the folder tree (left)', details: 'the file details and settings sidebar (right)' } }, + { id: 'objects', key: 'objects', title: 'Objects', via: 'toggle', description: 'Every object in the scene as a tree (the outliner)', aliases: ['outliner', 'object list', 'hierarchy', 'scene tree'] }, + { id: 'inspector', key: 'inspector', title: 'Inspector', via: 'inspector', description: 'The selected object\'s properties (the Properties tab: transform, look, physics, lights, cameras)', aliases: ['properties', 'properties panel', 'object properties'] }, + { id: 'scene', key: 'scene', title: 'Configure Scene', via: 'scene', description: 'The scene\'s own setup: sky, light, fog, physics, grid (the Inspector\'s other tab)', aliases: ['configure scene', 'scene setup', 'environment', 'sky'] }, + { id: 'flow', key: 'flow', title: 'Flow editor', via: 'toggle', description: 'The node editor: an object\'s or the scene\'s behaviour as a node graph', aliases: ['node editor', 'flow', 'nodes', 'flow graph', 'behaviours', 'graph editor'] }, + { id: 'animation', key: 'animation', title: 'Animation', via: 'toggle', description: 'The Animation editor: keyframes and clips for the selected object (its own moves, not the Timeline\'s shots)', aliases: ['animation editor', 'animator', 'keyframes', 'dope sheet'] }, + { id: 'timeline', key: 'timeline', title: 'Timeline', via: 'toggle', description: 'The Timeline: cutscene sequences of camera shots, clips, audio and events', aliases: ['sequencer', 'sequences', 'cutscenes'], panes: { sequences: 'the sequences list (left)', details: 'the selected track\'s details (right)' } }, + { id: 'uv', key: 'uv', title: 'UV editor', via: 'toggle', description: 'The selected mesh\'s UV map over its texture, with paint and UV tools', aliases: ['uv', 'uvs', 'uv map', 'texture editor'], panes: { materials: 'the materials list (left)', tools: 'the Tool and Settings sidebar (right)' } }, + { id: 'shader', key: 'shader', title: 'Shader editor', via: 'toggle', description: 'A material\'s shader as a node graph', aliases: ['shader', 'shader graph', 'shaders', 'material graph'] }, + { id: 'hud', key: 'hud', title: 'HUD editor', via: 'toggle', description: 'The on-screen HUD (buttons, text, bars) the scene shows while it plays, screen by screen', aliases: ['hud', 'ui editor', 'hud screens'], panes: { screens: 'the screens list (left)', properties: 'the selected element\'s properties (right)' } }, + { id: 'code', key: 'code', title: 'Code', via: 'toggle', description: 'The Code workspace: scripts, behaviours, flow code and graph JSON in tabs', aliases: ['code editor', 'code workspace', 'scripts', 'script editor'], panes: { files: 'Open editors and Project (left)', tools: 'Outline, Problems, Bound nodes, Find in files (right)' } }, + { id: 'profiler', key: 'profiler', title: 'Profiler', via: 'toggle', readOnly: true, description: 'Read-only: frame time and draw calls over time, recordings, and what draws most', aliases: ['performance', 'frame profiler', 'live profiler'], panes: { recordings: 'the recordings list (left)', details: 'the selected frame\'s details (right)' } }, + { id: 'stats', key: 'stats', title: 'Statistics', via: 'hosted', readOnly: true, description: 'Read-only: the scene budget (draw calls, triangles, textures, memory) against the device profile', aliases: ['stats', 'scene budget', 'scene statistics', 'budget'] }, + { id: 'assets', key: 'assets', title: 'Free assets', via: 'hosted', description: 'The free CC0 asset browser (Poly Haven, ambientCG): models, skies and materials to add', aliases: ['assets', 'asset browser', 'cc0 assets', 'free models'] }, + { id: 'preview', key: 'preview', title: 'Preview', via: 'hosted', description: 'A preview of the file selected in the Explorer (an image, model, sound or video); empty until a file is selected', aliases: ['file preview', 'image preview', 'model preview'] }, + { id: 'debugger', key: 'debugger', title: 'Debugger', via: 'debugger', description: 'The flow Debugger: breakpoints and the values flowing through nodes while the scene plays', aliases: ['flow debugger', 'debug'] }, + { id: 'chat', key: 'chat', title: 'Chat', via: 'chat', description: 'The session Chat: messages with the people in this session', aliases: ['session chat', 'messages'] }, + { id: 'assistant', key: 'chat', title: 'Assistant', via: 'chat', description: 'The in-app AI assistant (the Chat window\'s Assistant tab)', aliases: ['ai assistant', 'ai'] } +]; + +/** id -> definition */ +export const PANEL_BY_ID = /** @type {Record} */ (Object.fromEntries(PANELS.map((p) => [p.id, p]))); + +/** + * The layout TARGETS show {action: "panel"} also takes by name: the bottom dock and the two sidebar columns. + * @type {Record} + */ +export const TARGETS = { + dock: { id: 'dock', title: 'Dock', description: 'The bottom dock: a strip of tabs under the 3D view (close = minimize, every tab stays open)', aliases: ['bottom dock', 'bottom panel', 'the dock'] }, + left: { id: 'left', title: 'Left sidebar', description: 'The left sidebar column and its tabs (close = hide it, every tab stays open)', aliases: ['left sidebar', 'left panel', 'left column'] }, + right: { id: 'right', title: 'Right sidebar', description: 'The right sidebar column and its tabs (close = hide it, every tab stays open)', aliases: ['right sidebar', 'right panel', 'right column'] } +}; + +/** + * Surfaces show never opens (rule 2), grouped by the reason it gives. `words` are matched as whole words. + * @type {{reason: string, names: string[], words: string[]}[]} + */ +export const BLOCKED = [ + { reason: 'sign-in and account', names: ['Sign in', 'Account', 'Profile'], words: ['sign in', 'signin', 'log in', 'login', 'log out', 'logout', 'sign out', 'account', 'profile', 'password'] }, + { reason: 'consent and privacy', names: ['Consent', 'Privacy'], words: ['consent', 'privacy', 'cookies'] }, + { reason: 'publishing and export', names: ['Publish', 'Export', 'Share'], words: ['publish', 'publishing', 'export', 'share'] }, + { reason: 'connected apps', names: ['Connected apps', 'Connect Claude', 'Generate 3D'], words: ['connected apps', 'connected app', 'connect claude', 'connector', 'generate 3d', 'mesh generator', 'meshy'] }, + { reason: 'payment', names: ['Payment', 'Billing', 'Subscription'], words: ['payment', 'payments', 'billing', 'subscription', 'credits'] }, + { reason: 'settings', names: ['Settings', 'Preferences'], words: ['settings', 'preferences', 'options'] }, + { reason: 'session access', names: ['Roles', 'Permissions', 'Invite'], words: ['roles', 'permissions', 'invite', 'approve'] } +]; + +/** @param {string} name @returns {string} lower-case, single-spaced, no "panel"/"window"/"tab"/"view"/"the"/"editor" noise */ +export function normalName(name) { + return String(name ?? '') + .toLowerCase() + .replace(/[_\-./]+/g, ' ') + .replace(/\b(panel|window|tab|view|pane|the|open|show)\b/g, ' ') + .replace(/\s+/g, ' ') + .trim(); +} + +/** every spelling a panel answers to, normalised @param {PanelDef | {id: string, title: string, aliases?: string[]}} p */ +const spellings = (p) => [p.id, p.title, ...(p.aliases ?? [])].map(normalName); + +/** normalised spelling -> panel id (built once; a unit test keeps it free of collisions) */ +const NAME_TO_ID = /** @type {Map} */ (new Map()); +for (const p of PANELS) for (const s of spellings(p)) if (!NAME_TO_ID.has(s)) NAME_TO_ID.set(s, p.id); +const NAME_TO_TARGET = /** @type {Map} */ (new Map()); +for (const t of Object.values(TARGETS)) for (const s of spellings(t)) if (!NAME_TO_TARGET.has(s)) NAME_TO_TARGET.set(s, t.id); + +/** the panel a name means — exactly, never a near guess — or null @param {string} name */ +export function panelOf(name) { + const n = normalName(name); + if (!n) return null; + return NAME_TO_ID.get(n) ?? NAME_TO_ID.get(n.replace(/ editor$/, '')) ?? null; +} + +/** the layout target ('dock' | 'left' | 'right') a name means, or null @param {string} name */ +export function targetOf(name) { + const n = normalName(name); + if (!n) return null; + return NAME_TO_TARGET.get(n) ?? null; +} + +/** @param {string} hay @param {string} word */ +const hasWord = (hay, word) => (' ' + hay + ' ').includes(' ' + word + ' '); + +/** the reason a name is refused (rule 2), or null. A real panel's own name is never refused. @param {string} name */ +export function blockedReason(name) { + if (panelOf(name) || targetOf(name)) return null; + const n = normalName(name); + if (!n) return null; + for (const b of BLOCKED) if (b.words.some((w) => hasWord(n, normalName(w)))) return b.reason; + return null; +} + +/** is this a surface rule 2 keeps closed @param {string} name */ +export function deniedPanel(name) { + return blockedReason(name) !== null; +} + +/** the valid names, for an error: every panel title, then the targets */ +export function validNames() { + return [...PANELS.map((p) => p.title), ...Object.values(TARGETS).map((t) => t.title)]; +} + +/** the refused surfaces, by reason, for an error and the panels list */ +export function blockedList() { + return BLOCKED.map((b) => ({ reason: b.reason, names: b.names })); +} + +/** one line naming the refused surfaces by reason */ +export function blockedLine() { + return BLOCKED.map((b) => b.reason + ' (' + b.names.join(', ') + ')').join('; '); +} + +/** the error for a name that is neither a panel, a target nor a refused surface @param {string} asked */ +export function unknownPanelError(asked) { + return { + error: 'no panel "' + String(asked).slice(0, 60) + '": nothing was opened. The panels are ' + validNames().join(', ') + '. Never opened (the person\'s own): ' + blockedLine() + '. show {action: "panels"} lists each one with what it contains and whether it is open.', + valid: validNames(), + blocked: blockedList() + }; +} + +/** the pane a panel's own sidebar name means, or null @param {PanelDef} p @param {string} pane */ +export function paneOf(p, pane) { + if (!p.panes) return null; + const n = normalName(pane); + if (Object.hasOwn(p.panes, n)) return n; + const keys = Object.keys(p.panes); + // left / right / sidebar words: the first pane is the left one, the second the right one + if (/^(left|primary|first)( sidebar)?$/.test(n)) return keys[0] ?? null; + if (/^(right|secondary|second)( sidebar)?$/.test(n) && keys[1]) return keys[1]; + return null; +} diff --git a/src/lib/ai/personToolNames.js b/src/lib/ai/personToolNames.js index b7f9991c1..1ad200e86 100644 --- a/src/lib/ai/personToolNames.js +++ b/src/lib/ai/personToolNames.js @@ -8,5 +8,7 @@ export function personToolReads(name, args) { const action = String(args?.action ?? ''); if (name === 'files') return action === 'list' || action === 'read'; if (name === 'scene') return action === 'list'; + // 107-panels: the panel registry with each panel's state + if (name === 'show') return action === 'panels'; return false; } diff --git a/src/lib/ai/personTools.js b/src/lib/ai/personTools.js index 33cab1efb..419ff942c 100644 --- a/src/lib/ai/personTools.js +++ b/src/lib/ai/personTools.js @@ -24,9 +24,15 @@ const FILES_DESCRIPTION = 'Not for scenes (scene opens them) or for the scene\'s objects (list_scene).'; const SHOW_DESCRIPTION = - "Show the person something on THEIR OWN screen (never anyone else's): panel = open, close or bring forward one of their panels " + - '(Explorer, Objects, Inspector, Flow editor, Code, Timeline, Assets, Preview, Chat, Assistant); camera = move their editor view to frame objects ' + - '(frame: [uuids], select: true also selects them), to a position + target, or let them look through a scene camera (through: uuid); ' + + "Show the person something on THEIR OWN screen (never anyone else's). " + + 'panels = the list of every real panel (id, title, what it contains, read-only or not) with its state now: open, where (dock, left, right, floating, window), visible and front; ' + + 'also the dock and the two sidebars, focus mode, the saved layouts, and the refused surfaces by reason. It only reads and never asks. ' + + 'panel = open, close, focus (bring to the front where it is), toggle, move (to: dock, left, right, floating), maximize / restore (a docked panel fills the window), ' + + 'collapse / expand one of its own sidebars (pane) for one panel by its name: Explorer, Objects, Inspector, Configure Scene, Flow editor, Animation, Timeline, UV editor, Shader editor, HUD editor, Code, ' + + 'Profiler and Statistics (read-only views), Free assets, Preview (the selected Explorer file), Debugger, Chat, Assistant; or name "Dock", "Left sidebar", "Right sidebar" to open, close or toggle them (close hides, tabs stay open). ' + + 'An unknown name opens nothing and the error lists the valid names: never guess another panel. The answer says visible and front truthfully. ' + + 'layout = apply a saved layout by name, or save the current one under a new name. ' + + 'camera = move their editor view to frame objects (frame: [uuids], select: true also selects them), to a position + target, or let them look through a scene camera (through: uuid); ' + 'code = open a file or a Script / Behaviour node\'s code in their Code tab at a line, selecting lines [line, to], a range, or the first match of find; ' + 'back = undo what the last show changed. The first time for each of panel / camera / code the person is asked on their screen (Always / This time / No): ' + 'call again with the confirmId; after No, do not ask again, tell them where to look instead. ' + @@ -81,9 +87,18 @@ export const PERSON_AI_TOOLS = [ parameters: { type: 'object', properties: { - action: { type: 'string', enum: ['panel', 'camera', 'code', 'back'], description: 'what to show' }, - name: { type: 'string', description: 'panel: Explorer, Objects, Inspector, Flow editor, Code, Timeline, Assets, Preview, Chat or Assistant' }, - state: { type: 'string', enum: ['open', 'close', 'focus'], description: 'panel: default open (focus brings an open one forward)' }, + action: { type: 'string', enum: ['panels', 'panel', 'layout', 'camera', 'code', 'back'], description: 'what to show (panels = the list, reads only)' }, + name: { type: 'string', description: 'panel: a panel title from panels (Animation, UV editor, Profiler, ...) or Dock / Left sidebar / Right sidebar; layout: the layout name' }, + state: { + type: 'string', + enum: ['open', 'close', 'focus', 'toggle', 'move', 'maximize', 'restore', 'collapse', 'expand', 'apply', 'save'], + description: 'panel: default open (focus brings an open one to the front; move needs to; collapse / expand need pane); layout: apply (default) or save' + }, + to: { + description: 'panel: where to move it — dock, left, right or floating. code: with line, the last line to select', + anyOf: [{ type: 'string', enum: ['dock', 'left', 'right', 'floating'] }, { type: 'number' }] + }, + pane: { type: 'string', description: 'panel collapse / expand: one of the panel\'s own sidebars (panels lists paneNames: tree, files, tools, ...)' }, frame: { type: 'array', items: { type: 'string' }, description: 'camera: object uuids to frame together' }, select: { description: 'camera: true = also select the framed objects. code: a range to select, {from: [line, col], to: [line, col]} (lines from 1, columns from 0)', @@ -100,7 +115,6 @@ export const PERSON_AI_TOOLS = [ node: { type: 'string', description: 'code: a Script or Behaviour node id' }, object: { type: 'string', description: 'code: an object uuid: its first Script or Behaviour node' }, line: { type: 'number', description: 'code: the line to go to (from 1)' }, - to: { type: 'number', description: 'code: with line, select lines line..to' }, find: { type: 'string', description: 'code: select the first match of this text (from line, when given)' }, confirmId: { type: 'string', description: 'the answer to the first-use question (from a needsConfirm answer)' }, wait: { type: 'number', description: 'with confirmId: seconds to wait for the person\'s answer (at most 60)' } diff --git a/src/lib/ai/showCore.js b/src/lib/ai/showCore.js index 9de4d3eae..6866eae73 100644 --- a/src/lib/ai/showCore.js +++ b/src/lib/ai/showCore.js @@ -1,9 +1,9 @@ -// Roadmap 104 C2 — `show`, the pure half (a LEAF: imports nothing). showTool.js drives the interface. +// Roadmap 104 C2 — `show`, the pure half (a LEAF: imports only the panelsCore leaf). showTool.js drives the interface. // // `show` acts on the screen of the person the assistant acts for, and nobody else's: it has no peer // argument at all. Its eight safety rules (scout report row 7c) and where each one lives: // 1 own tab only; headless agent pages do not get the tool (personTools.js / tpAgent) -// 2 a deny-list: never sign-in, consent, Publish, Connected apps, account, payment surfaces DENIED / deniedPanel() +// 2 a deny-list: never sign-in, consent, Publish, Connected apps, account, payment surfaces panelsCore BLOCKED / blockedReason() // 3 the first use of each kind asks once (Always / This time / No), stored per device showTool.js + SHOW_KINDS // 4 every action leaves a line the person can act on: "Claude moved your view · Back" showTool.js // 5 no camera move in a headset (this release) showTool.js @@ -11,6 +11,8 @@ // 7 6 calls a minute, one camera move per 2 s, refused while the person drags or types SHOW_PER_MINUTE / CAMERA_GAP_MS // 8 editing text stays files {write}: show {code} only opens, goes to a line and selects (no text argument) +import { PANELS, panelOf, deniedPanel, normalName, blockedReason, BLOCKED } from './panelsCore.js'; + /** the kinds the person is asked about, once each */ export const SHOW_KINDS = /** @type {const} */ (['panel', 'camera', 'code']); export const SHOW_PER_MINUTE = 6; @@ -24,101 +26,19 @@ export const KIND_WORDS = /** @type {Record} */ ({ code: 'open code for you' }); +// 107-panels: the panels, their names and the refused surfaces live in ONE registry (panelsCore.js, also a +// leaf); these are the names show always exported, kept so every reader keeps working. +export { panelOf, deniedPanel, normalName, blockedReason }; + /** - * The panels `show` may open, close or bring forward — the allow-list. `key` is the app's own key - * (panelToggles / dockHost), `via` how it opens. - * @type {Record} + * The panels `show` may open, close or bring forward, by id: `key` is the app's own key (panelToggles / + * dockHost), `via` how it opens, `label` its title. + * @type {Record} */ -export const SHOW_PANELS = { - explorer: { key: 'explorer', label: 'Explorer', via: 'toggle' }, - objects: { key: 'objects', label: 'Objects', via: 'toggle' }, - inspector: { key: 'inspector', label: 'Inspector', via: 'inspector' }, - flow: { key: 'flow', label: 'Flow editor', via: 'toggle' }, - code: { key: 'code', label: 'Code', via: 'toggle' }, - timeline: { key: 'timeline', label: 'Timeline', via: 'toggle' }, - assets: { key: 'assets', label: 'Assets', via: 'hosted' }, - preview: { key: 'preview', label: 'Preview', via: 'hosted' }, - chat: { key: 'chat', label: 'Chat', via: 'chat' }, - assistant: { key: 'chat', label: 'Assistant', via: 'chat' } -}; - -/** other words people use for them */ -const ALIASES = /** @type {Record} */ ({ - library: 'explorer', - files: 'explorer', - 'file explorer': 'explorer', - outliner: 'objects', - 'object list': 'objects', - hierarchy: 'objects', - properties: 'inspector', - 'properties panel': 'inspector', - 'node editor': 'flow', - nodes: 'flow', - 'flow graph': 'flow', - 'flow editor': 'flow', - behaviours: 'flow', - 'code editor': 'code', - 'code workspace': 'code', - scripts: 'code', - animation: 'timeline', - sequencer: 'timeline', - 'asset browser': 'assets', - 'free assets': 'assets', - 'file preview': 'preview', - 'session chat': 'chat', - 'ai assistant': 'assistant', - ai: 'assistant' -}); - -/** surfaces `show` never opens or presses (rule 2): named so the refusal can say what was asked */ -export const DENIED = [ - 'sign in', - 'sign-in', - 'signin', - 'log in', - 'login', - 'account', - 'profile', - 'consent', - 'privacy', - 'publish', - 'export', - 'connected apps', - 'connect claude', - 'connector', - 'payment', - 'billing', - 'subscription', - 'settings', - 'roles', - 'permissions', - 'invite', - 'approve' -]; +export const SHOW_PANELS = Object.fromEntries(PANELS.map((p) => [p.id, { key: p.key, label: p.title, via: p.via, ...(p.readOnly ? { readOnly: true } : {}) }])); -/** @param {string} name @returns {string} lower-case, single-spaced, no "panel"/"window" */ -export function normalName(name) { - return String(name ?? '') - .toLowerCase() - .replace(/[_-]+/g, ' ') - .replace(/\b(panel|window|tab|view)\b/g, ' ') - .replace(/\s+/g, ' ') - .trim(); -} - -/** the allow-listed panel a name means, or null @param {string} name */ -export function panelOf(name) { - const n = normalName(name); - if (SHOW_PANELS[n]) return n; - if (ALIASES[n]) return ALIASES[n]; - return null; -} - -/** is this a surface rule 2 keeps closed @param {string} name */ -export function deniedPanel(name) { - const n = normalName(name); - return DENIED.some((d) => n === d || n.includes(d)); -} +/** surfaces `show` never opens or presses (rule 2), every word of every reason */ +export const DENIED = BLOCKED.flatMap((b) => b.words); /** * Where the camera goes to frame a box, keeping the view direction (objectActions.focusObject's diff --git a/src/lib/ai/showTool.js b/src/lib/ai/showTool.js index 72277b419..7a40d911e 100644 --- a/src/lib/ai/showTool.js +++ b/src/lib/ai/showTool.js @@ -1,9 +1,12 @@ // Roadmap 104 C2 — `show`: the assistant drives the person's OWN interface, in their own tab. A lazy // chunk (personTools.js loads it on the first call). The rules are listed in showCore.js. // -// panel {name, state: open | close | focus} the allow-list in showCore.SHOW_PANELS, through the app's -// own toggles (panelToggles / dockHost / showSidebar / openChatTab), so a panel opens where -// the person keeps it (dock, sidebar, floating) +// panel {name, state: open | close | focus | toggle | move (to) | maximize | restore | collapse | expand (pane)} +// 107-panels: the registry in panelsCore.js (every real panel, the dock and the two sidebars as named +// targets), through the app's own seams (panels.js), so a panel opens where the person keeps it. An +// unknown name never substitutes: it errors with the valid names and the refused surfaces by reason. +// panels the whole registry with each panel's state (open / where / visible / front): reads, never asks +// layout {name, state: apply | save} the Windows ▸ Layouts named layouts // camera {frame: [uuids]} | {position, target} | {through: cameraUuid}, select: true selects what was // framed. objectActions.flyTo (0.6 s, an instant cut under reduced motion) / startCameraPreview // code {path | id | node | object, line, to, select: {from, to}, find}: codeWorkspace.openCode, then @@ -17,21 +20,11 @@ import { get } from 'svelte/store'; import { safeStorage } from '../safeStorage'; -import { showToastById, inspectorClose, inspectorKind, chatHidden, chatTab, showSidebar, closeSelectionInspector, specatorMode } from '../../stores/appStore'; +import { showToastById, specatorMode } from '../../stores/appStore'; import { globalCamera, orbitControls, globalRenderer, objectsGroup, TControls, isLocked, selectedObjects, marqueeRect, isVRMode } from '../../stores/sceneStore'; import { askPerson } from './personAsk.js'; -import { - SHOW_PANELS, - SHOW_PER_MINUTE, - CAMERA_GAP_MS, - FLY_MS, - KIND_WORDS, - panelOf, - deniedPanel, - frameBox, - isVec3, - findRange -} from './showCore.js'; +import { SHOW_PANELS, SHOW_PER_MINUTE, CAMERA_GAP_MS, FLY_MS, KIND_WORDS, panelOf, deniedPanel, frameBox, isVec3, findRange } from './showCore.js'; +import { targetOf } from './panelsCore.js'; import { createRateLimit, resolveRef, isTextName, extOf } from './filesCore.js'; import { isDirty } from '../codeTabs'; @@ -141,81 +134,223 @@ const waitFrames = (frames) => }); // ---------------------------------------------------------------- panel +// 107-panels: the registry (panelsCore.js) says WHICH panels exist and what each is called; panels.js says where +// each one is and works the app's own seams. This section is the show rules around them: an unknown name never +// substitutes, the answer reports visible + front truthfully, and every change has a Back. + +/** the snapshot of what bringing something forward can change, so Back puts it back @returns {Promise} */ +async function chromeSnapshot() { + const [b, sb, fm] = await Promise.all([import('../bottomDock'), import('../sidebars'), import('../focusMode')]); + return { active: get(b.bottomDockActive), min: get(b.dockMinimized), vis: { ...get(sb.sidebarVisible) }, shown: { ...get(sb.sidebarShown) }, focus: get(fm.focusMode) }; +} -/** @param {string} key */ -async function panelOpenNow(key) { - const { windowWhere } = await import('../dockMenu'); - return windowWhere(key) !== null; +/** @param {any} snap */ +async function restoreChrome(snap) { + const [b, sb, fm] = await Promise.all([import('../bottomDock'), import('../sidebars'), import('../focusMode')]); + b.bottomDockActive.set(snap.active); + b.dockMinimized.set(snap.min); + for (const side of /** @type {const} */ (['left', 'right'])) { + if (snap.shown[side] && get(sb.sidebarShown)[side] !== snap.shown[side]) sb.activateSidebarTab(snap.shown[side]); + if (!snap.vis[side] && get(sb.sidebarVisible)[side]) sb.toggleSidebar(side, false); + } + if (snap.focus && !get(fm.focusMode)) fm.enterFocus(snap.focus); } -/** @param {string} id the SHOW_PANELS id */ -async function isOpen(id) { - const p = SHOW_PANELS[id]; - if (p.via === 'inspector') return !get(inspectorClose) && get(inspectorKind) === 'selection'; - if (p.via === 'chat') return get(chatHidden) === '' && get(chatTab) === (id === 'assistant' ? 'assistant' : 'session'); - return panelOpenNow(p.key); +/** the answer's state fields @param {string} id @returns {Promise<{where?: string | null, visible?: boolean, front?: boolean, panes?: any}>} */ +async function panelState(id) { + const P = await import('./panels.js'); + await P.waitFrames(2); + const r = await P.readPanel(id); + return r ? { where: r.where, visible: r.visible, front: r.front, ...(r.panes ? { panes: r.panes } : {}) } : {}; } -/** @param {string} id */ -async function openPanel(id) { - const p = SHOW_PANELS[id]; - if (p.via === 'inspector') return showSidebar('properties', { focus: true }); - if (p.via === 'chat') { - const { openChatTab } = await import('../chat/chatWindow.js'); - return openChatTab(id === 'assistant' ? 'assistant' : 'session'); - } - const { focusWindow } = await import('../dockMenu'); - if (focusWindow(p.key)) return; - if (p.via === 'toggle') { - const { togglePanel } = await import('../panelToggles'); - return togglePanel(p.key); - } - const { HOSTED } = await import('../dockHost'); - HOSTED[p.key]?.open(); +/** why a panel that is open is still not visible, for the note @param {any} st */ +function hiddenWhy(st) { + if (get(isLocked) === true) return 'The person is playing (Play mode hides the editor): it shows when they press Esc.'; + if (st.where && !st.visible) return 'It is open but not showing on this screen (a narrow screen or a phone can fold it away).'; + return ''; } /** @param {string} id */ -async function closePanel(id) { - const p = SHOW_PANELS[id]; - if (p.via === 'inspector') return closeSelectionInspector(); - if (p.via === 'chat') return chatHidden.set('hidden'); - if (p.via === 'hosted') { - const { HOSTED } = await import('../dockHost'); - return HOSTED[p.key]?.close(); +const readOnlyNote = (id) => (SHOW_PANELS[id]?.readOnly ? { readOnly: true, note: 'A read-only panel: it shows figures; it changes nothing in the scene.' } : {}); + +/** the dock / a sidebar as a target @param {'dock'|'left'|'right'} tid @param {string} state @param {string} by */ +async function targetAction(tid, state, by) { + const T = (await import('./panelsCore.js')).TARGETS[tid]; + const want = state === 'focus' ? 'open' : state; + if (!['open', 'close', 'toggle'].includes(want)) return fail(T.title + ': state open, close or toggle'); + const P = await import('./panels.js'); + const r = await P.setTarget(tid, /** @type {any} */ (want)); + if ('error' in r) return fail(r.error); + const all = await P.readPanels(); + const now = /** @type {any} */ (all)[tid]; + if (r.changed) { + push((r.open ? 'opened ' : 'closed ') + T.title, () => { + r.undo(); + return (r.open ? 'closed ' : 'reopened ') + T.title; + }); + line(by + (r.open ? ' opened ' : ' closed ') + 'the ' + T.title.toLowerCase()); } - const { closeDockView } = await import('../dockMenu'); - closeDockView(p.key); + return { target: T.title, ...now, state: now.open ? 'open' : 'closed', changed: r.changed, ...(r.changed && !r.open ? { note: 'Hidden, not closed: every tab in it stays open.' } : {}) }; } /** @param {any} args @param {string} by */ async function panelAction(args, by) { + const core = await import('./panelsCore.js'); const asked = String(args.name ?? args.panel ?? ''); - if (!asked) return fail('name: the panel to show — ' + Object.values(SHOW_PANELS).map((p) => p.label).join(', ')); - if (deniedPanel(asked)) return fail('"' + asked + '" is not something show opens: sign-in, account, consent, publishing, connected apps, payment and settings stay the person\'s own to open', { refused: true }); - const id = panelOf(asked); - if (!id) return fail('no panel "' + asked + '": show opens ' + Object.values(SHOW_PANELS).map((p) => p.label).join(', ')); - const state = String(args.state ?? 'open'); - if (!['open', 'close', 'focus'].includes(state)) return fail('state: open, close or focus'); - const label = SHOW_PANELS[id].label; - const was = await isOpen(id); + if (!asked) return fail('name: the panel to show. ' + core.unknownPanelError('').error.replace(/^no panel "": nothing was opened\. /, ''), { valid: core.validNames(), blocked: core.blockedList() }); + const reason = core.blockedReason(asked); + if (reason) return fail('"' + asked + '" is not something show opens (' + reason + '): sign-in, account, consent, publishing, connected apps, payment and settings stay the person\'s own to open. Read-only views (Profiler, Statistics) do open.', { refused: true, reason, blocked: core.blockedList() }); + const state = String(args.state ?? (args.to ? 'move' : 'open')); + const tid = core.targetOf(asked); + if (tid) return targetAction(/** @type {any} */ (tid), state, by); + const id = core.panelOf(asked); + if (!id) { + const e = core.unknownPanelError(asked); + return fail(e.error, { valid: e.valid, blocked: e.blocked }); + } + const p = core.PANEL_BY_ID[id]; + const label = p.title; + const P = await import('./panels.js'); + const STATES = ['open', 'close', 'focus', 'toggle', 'move', 'maximize', 'restore', 'collapse', 'expand']; + if (!STATES.includes(state)) return fail('state: ' + STATES.join(', ')); + const before = await P.readPanel(id); + const was = !!before?.open; + const sameAs = { id, ...(asked.trim().toLowerCase() !== label.toLowerCase() ? { asked } : {}) }; + + if (state === 'toggle') return panelAction({ ...args, state: was && before?.front ? 'close' : 'open' }, by); + if (state === 'close') { - if (!was) return { panel: label, state: 'closed', changed: false }; - await closePanel(id); + if (!was) return { panel: label, ...sameAs, state: 'closed', changed: false }; + const snap = await chromeSnapshot(); + await P.closePanel(p); push('closed ' + label, async () => { - await openPanel(id); + await P.openPanel(p); + await restoreChrome(snap); return 'reopened ' + label; }); line(by + ' closed ' + label); - return { panel: label, state: 'closed', changed: true }; + return { panel: label, ...sameAs, state: 'closed', changed: true }; + } + + if (state === 'collapse' || state === 'expand') { + if (!args.pane) return fail('pane: which of ' + label + '\'s own sidebars — ' + (p.panes ? Object.keys(p.panes).join(', ') : 'it has none')); + if (!was) return fail(label + ' is not open: open it first'); + const r = await P.setPane(p, String(args.pane), state === 'expand'); + if ('error' in r) return fail(r.error); + const changed = r.was !== (state === 'expand'); + if (changed) { + push((state === 'expand' ? 'opened ' : 'closed ') + label + '\'s ' + r.pane, async () => { + await P.setPane(p, r.pane, r.was); + return 'put ' + label + '\'s ' + r.pane + ' back'; + }); + line(by + (state === 'expand' ? ' opened ' : ' closed ') + label + '\'s ' + r.pane + ' sidebar'); + } + return { panel: label, ...sameAs, pane: r.pane, paneState: state === 'expand' ? 'open' : 'closed', changed, ...(await panelState(id)) }; + } + + if (state === 'maximize' || state === 'restore') { + const r = await P.maximizePanel(p, state === 'maximize'); + if ('error' in r) return fail(r.error); + const fm = await import('../focusMode'); + const now = get(fm.focusMode); + const changed = now !== r.was; + if (changed) { + push(state === 'maximize' ? 'maximized ' + label : 'restored the layout', async () => { + if (r.was) fm.enterFocus(/** @type {any} */ (r.was)); + else fm.exitFocus(); + return state === 'maximize' ? 'restored the layout' : 'maximized it again'; + }); + line(by + (state === 'maximize' ? ' maximized ' + label + ' (Esc restores)' : ' restored your layout')); + } + return { panel: label, ...sameAs, maximized: now === 'dock', changed, ...(await panelState(id)) }; } - await openPanel(id); - if (!was) - push('opened ' + label, async () => { - await closePanel(id); - return 'closed ' + label; + + if (state === 'move') { + const to = String(args.to ?? ''); + if (!['dock', 'left', 'right', 'floating'].includes(to)) return fail('to: dock, left, right or floating'); + const r = await P.movePanel(p, /** @type {any} */ (to)); + if ('error' in r) return fail(r.error); + const st = await panelState(id); + const changed = r.from !== st.where; + if (changed && r.from) { + const from = r.from; + push('moved ' + label, async () => { + await P.movePanel(p, /** @type {any} */ (from)); + return 'moved ' + label + ' back'; + }); + line(by + ' moved ' + label + ' to the ' + (to === 'dock' ? 'dock' : to === 'floating' ? 'a floating window' : to + ' sidebar')); + } + return { panel: label, ...sameAs, state: 'open', changed, ...st }; + } + + // open / focus: open it where it lives, or bring it to the front where it is + const snap = await chromeSnapshot(); + const { exitedFocus } = was ? await P.bringForward(p) : (await P.openPanel(p), { exitedFocus: null }); + let st = await panelState(id); + // a move asked together with the open + if (args.to && ['dock', 'left', 'right', 'floating'].includes(String(args.to)) && st.where !== args.to) { + const r = await P.movePanel(p, /** @type {any} */ (String(args.to))); + if ('error' in r) return fail(r.error, { opened: !was, panel: label }); + st = await panelState(id); + } + const changed = !was || !before?.front || before?.where !== st.where || !!exitedFocus; + if (changed) + push((was ? 'brought ' + label + ' forward' : 'opened ' + label), async () => { + if (!was) await P.closePanel(p); + await restoreChrome(snap); + return was ? 'put the panels back as they were' : 'closed ' + label; }); - line(by + (was ? ' brought ' + label + ' forward' : ' opened ' + label)); - return { panel: label, state: 'open', changed: !was, ...(inVR() ? { note: 'The person is in a headset: panels show when they take it off.' } : {}) }; + if (changed) line(by + (was ? ' brought ' + label + ' forward' : ' opened ' + label)); + const why = st.visible ? '' : hiddenWhy(st); + const ro = readOnlyNote(id); + const notes = [ro.note, why, exitedFocus ? 'Focus mode was hiding it: the person\'s layout is back (back re-enters focus mode).' : '', inVR() ? 'The person is in a headset: panels show when they take it off.' : ''].filter(Boolean); + return { + panel: label, + ...sameAs, + state: 'open', + changed, + ...st, + ...(ro.readOnly ? { readOnly: true } : {}), + ...(notes.length ? { note: notes.join(' ') } : {}) + }; +} + +// ---------------------------------------------------------------- layout (the Layouts menu's named layouts) + +/** @param {any} args @param {string} by */ +async function layoutAction(args, by) { + const L = await import('../uiLayouts'); + const list = /** @type {any[]} */ (get(L.uiLayouts)); + const state = String(args.state ?? 'apply'); + const name = String(args.name ?? '').trim(); + if (!name) return fail('name: the layout\'s name. Saved layouts: ' + (list.map((l) => l.name).join(', ') || 'none yet'), { layouts: list.map((l) => l.name) }); + const hit = list.find((l) => String(l.name).toLowerCase() === name.toLowerCase()); + if (state === 'save') { + if (hit) return fail('a layout named "' + hit.name + '" exists: show never overwrites one (the person replaces it in Windows ▸ Layouts), pick a new name', { layouts: list.map((l) => l.name) }); + const r = L.saveLayout(name); + if (!r.ok) return fail(r.reason); + const id = r.layout.id; + push('saved the layout "' + r.layout.name + '"', () => { + L.deleteLayout(id); + return 'removed the layout "' + r.layout.name + '"'; + }); + line(by + ' saved your layout as "' + r.layout.name + '"'); + return { layout: r.layout.name, saved: true, layouts: get(L.uiLayouts).map((/** @type {any} */ l) => l.name) }; + } + if (state !== 'apply') return fail('layout state: apply (default) or save'); + if (!hit) return fail('no layout "' + name + '": nothing changed. Saved layouts: ' + (list.map((l) => l.name).join(', ') || 'none yet'), { layouts: list.map((l) => l.name) }); + const beforeRec = L.captureLayout('before'); + const beforeActive = get(L.activeLayoutId); + const ok = await L.applyLayout(hit.id); + if (!ok) return fail('the layout could not be applied right now (another one is applying): try again in a moment'); + push('applied the layout "' + hit.name + '"', async () => { + await L.applyLayoutRecord(beforeRec); + L.activeLayoutId.set(beforeActive); + return 'put the layout from before back'; + }); + line(by + ' applied your layout "' + hit.name + '"'); + return { layout: hit.name, applied: true }; } // ---------------------------------------------------------------- camera @@ -410,20 +545,26 @@ async function codeAction(args, by) { */ export async function showTool(args, ctx = {}) { const a = args && typeof args === 'object' ? args : {}; - const action = String(a.action ?? ''); + const raw = String(a.action ?? ''); const by = String(ctx.by || 'The assistant'); - if (action === 'back') { + if (raw === 'back') { if (!stack.length) return { back: false, note: 'nothing to put back: show has not changed anything yet (or it was all put back)' }; const said = await back(); return { back: true, did: said, left: stack.length }; } - if (!['panel', 'camera', 'code'].includes(action)) return fail('action: panel, camera, code or back'); + // 107-panels: the panel list only reads — no question, no pacing + if (raw === 'panels') { + const { readPanels } = await import('./panels.js'); + return readPanels(); + } + if (!['panel', 'camera', 'code', 'layout'].includes(raw)) return fail('action: panel, panels, layout, camera, code or back'); // rule 2 first: a denied or unknown panel is refused without asking and without spending the minute's calls - if (action === 'panel') { + if (raw === 'panel') { const asked = String(a.name ?? a.panel ?? ''); - if (asked && deniedPanel(asked)) return panelAction(a, by); - if (asked && !panelOf(asked)) return panelAction(a, by); + if (!asked || deniedPanel(asked) || (!panelOf(asked) && !targetOf(asked))) return panelAction(a, by); } + // 107-panels: a layout asks as a panel change (the same first-use kind: "open and close your panels") + const action = raw === 'layout' ? 'panel' : raw; const busy = busyReason(); if (busy) return fail(busy + ': show waits until they stop (try again in a moment)', { busy: true, retryAfter: 3 }); // the camera's own pacing first (it is synchronous): the checks below await @@ -440,7 +581,8 @@ export async function showTool(args, ctx = {}) { const run = async () => { calls.note(); debug.done++; - debug.last = { action, at: Date.now() }; + debug.last = { action: raw, at: Date.now() }; + if (raw === 'layout') return layoutAction(a, by); if (action === 'panel') return panelAction(a, by); if (action === 'camera') return cameraAction(a, by); return codeAction(a, by); diff --git a/src/lib/dockMenu.js b/src/lib/dockMenu.js index abfe391c7..6e35b50da 100644 --- a/src/lib/dockMenu.js +++ b/src/lib/dockMenu.js @@ -406,6 +406,19 @@ function moveHere(key, where, target) { return true; } +/** + * 107-panels — the assistant's show {panel, to}: MOVE an OPEN window to the bottom dock or a sidebar column, the + * "+" menus' own move (`moveHere`), so nothing is opened twice. False when it is closed, in a pop-out window, or + * cannot live there. + * @param {string} key @param {'dock'|'left'|'right'} target + */ +export function moveWindowTo(key, target) { + const where = windowWhere(key); + if (!where || where === 'window') return false; + if (where === target) return true; + return moveHere(key, where, target); +} + /** * 41 G22 + 44 M5/M7 — THE "+" MENU, every one of them: the dock strip's, a sidebar's, the * floating Node editor's header. One row per registry window (`DOCK_WINDOWS` + the hosted ones), diff --git a/src/lib/windowPanes.js b/src/lib/windowPanes.js new file mode 100644 index 000000000..b1f74f4e4 --- /dev/null +++ b/src/lib/windowPanes.js @@ -0,0 +1,28 @@ +// 107-panels — a WINDOW'S OWN SIDEBARS, reachable from outside the window (a LEAF: imports nothing). Every +// WindowShell (the Explorer, the UV / HUD / Timeline / Profiler editors, the Image editor) keeps its primary and +// secondary pane state inside the component; each one registers here while it is mounted, so the assistant's +// show {state: "collapse" | "expand", pane} works the window's own handles, never a copy of their state. + +/** + * @typedef {{ + * status: () => {primary: {available: boolean, open: boolean}, secondary: {available: boolean, open: boolean, mode: string}, locked: boolean, narrow: boolean}, + * setPrimary: (open: boolean) => void, + * setSecondary: (open: boolean) => void + * }} PanesApi + */ + +/** window key -> the newest mounted shell's panes @type {Map} */ +const shells = new Map(); + +/** a mounted WindowShell registers its panes @param {string} key @param {PanesApi} api @returns {() => void} unregister */ +export function registerPanes(key, api) { + shells.set(key, api); + return () => { + if (shells.get(key) === api) shells.delete(key); + }; +} + +/** the panes of the window with this key, or null while it is not mounted @param {string} key */ +export function panesOf(key) { + return shells.get(key) ?? null; +} diff --git a/tests/e2e/connector-show-panels.test.cjs b/tests/e2e/connector-show-panels.test.cjs new file mode 100644 index 000000000..77b66d353 --- /dev/null +++ b/tests/e2e/connector-show-panels.test.cjs @@ -0,0 +1,145 @@ +// 107-panels (roadmap 107, owner report 27 Nov) — the PANEL REGISTRY and `show` panel through a real connector tab, +// against the fake relay. +// 1. show {action: "panels"} reads with no question: every panel, the dock + sidebars, the refused surfaces +// 2. Animation opens the Animation editor and NOT the Timeline; UV / Shader / HUD editor, Statistics and Profiler open +// (Profiler + Statistics are read-only and allowed) +// 3. an unknown name opens nothing and lists the valid names + the block list by reason (counterfactual: the same +// call with the real name opens it); Settings / Profile are refused with their reason +// 4. focus is truthful: a covered dock tab answers changed:true front:true; again changed:false; a minimized dock +// reads visible:false and focus brings it back +// 5. Dock / Left sidebar as targets: close hides (tabs stay open), Back reopens +// 6. move to the right sidebar and Back; maximize a docked panel and restore; collapse / expand the Explorer tree +// 7. layouts: save under a new name (an existing name is refused), apply, Back +// Run: APP_URL='https://theprototype.app:7240/' npm run e2e -- connector-show-panels +const h = require('./helpers.cjs'); +const { installProvider, fakeRelay, connectorPhase } = require('./connectorFake.cjs'); + +h.run(async () => { + const browser = await h.launch(); + const A = await h.setupPage(browser, 'A'); + const page = A.page; + const relay = await fakeRelay(page); + await installProvider(page); + await page.locator('#connect-claude-button').click(); + await h.eventually(() => connectorPhase(A), (p) => p === 'connected', 'connected', 15000); + let seq = 0; + const call = async (tool, args = {}, scope = 'edit', timeout = 60000) => { + const id = 'p' + ++seq; + relay.call(id, tool, args, scope); + return relay.answer(id, timeout); + }; + const short = (x) => JSON.stringify(x).slice(0, 300); + const reset = () => page.evaluate(() => window.__tp.test.v1.showTool.showToolResetForTest()); + const show = (args) => call('show', args); + const panels = async () => (await show({ action: 'panels' }))?.result; + const P = async (id) => (await panels())?.panels?.find((p) => p.id === id); + const where = (key) => page.evaluate((k) => window.__tp.test.v1.dockMenu.windowWhere(k), key); + const errOf = (r) => (r?.type === 'error' ? r.error?.message ?? '' : ''); + + // ---- 1 ---------------------------------------------------------------------------------------------------- + await page.evaluate(() => window.__tp.test.v1.safeStorage.removeItem('show:allow:panel')); + const list = await panels(); + h.check(!list?.needsConfirm && Array.isArray(list?.panels), `panels reads with no question (${short(list)})`); + const ids = (list?.panels ?? []).map((p) => p.id); + for (const id of ['explorer', 'animation', 'timeline', 'uv', 'shader', 'hud', 'profiler', 'stats', 'preview']) h.check(ids.includes(id), `panels lists ${id}`); + h.check((list?.panels ?? []).every((p) => typeof p.description === 'string' && 'open' in p && 'visible' in p && 'front' in p && 'where' in p), 'each panel has a description, open, where, visible, front'); + h.check((list?.panels ?? []).filter((p) => p.readOnly).map((p) => p.id).join() === 'profiler,stats', 'Profiler and Statistics are the read-only ones'); + h.check(list?.dock && list?.left && list?.right && Array.isArray(list?.blocked) && list.blocked.some((b) => b.reason === 'settings'), `the dock, both sidebars and the block list by reason (${short(list?.blocked)})`); + h.check(list?.layouts && Array.isArray(list.layouts.names), 'the saved layouts are listed'); + await page.evaluate(() => window.__tp.test.v1.safeStorage.setItem('show:allow:panel', 'always')); + + // ---- 2 ---------------------------------------------------------------------------------------------------- + await page.evaluate(() => { const s = window.__tp.test.v1; s.animationClose?.set?.(true); s.timelineClose?.set?.(true); }); + await h.eventually(() => where('timeline'), (w) => w === null, 'the Timeline is closed to start', 5000); + await reset(); + const anim = await show({ action: 'panel', name: 'Animation' }); + h.check(anim?.result?.panel === 'Animation' && anim.result.changed === true, `"Animation" opens the Animation editor (${short(anim)})`); + await h.eventually(() => where('animation'), (w) => w !== null, 'the Animation editor is open', 5000); + h.check((await where('timeline')) === null, 'and the Timeline stays closed (the substitution is gone)'); + h.check(anim?.result?.visible === true && anim.result.front === true, `the answer says visible + front (${short(anim?.result)})`); + for (const [name, id] of [['UV Editor', 'uv'], ['Shader Editor', 'shader'], ['HUD Editor', 'hud'], ['Statistics', 'stats'], ['Profiler', 'profiler']]) { + await reset(); + const r = await show({ action: 'panel', name }); + h.check(r?.result?.id === id && r.result.state === 'open', `"${name}" opens (${short(r)})`); + if (id === 'profiler' || id === 'stats') h.check(r?.result?.readOnly === true, `${name} answers readOnly: true`); + } + + // ---- 3 ---------------------------------------------------------------------------------------------------- + await reset(); + const openBefore = (await panels()).panels.filter((p) => p.open).map((p) => p.id).join(); + const unk = await show({ action: 'panel', name: 'Animations timeline' }); + h.check(/no panel "Animations timeline": nothing was opened/.test(errOf(unk)) && /Animation, Timeline/.test(errOf(unk)) && /settings \(Settings/.test(errOf(unk)), `an unknown name errors with the valid names and the block list (${errOf(unk).slice(0, 200)})`); + h.check((await panels()).panels.filter((p) => p.open).map((p) => p.id).join() === openBefore, 'and nothing opened'); + for (const [name, reason] of [['Settings', 'settings'], ['Profile', 'sign-in and account'], ['Publish', 'publishing and export'], ['Generate 3D', 'connected apps']]) { + const r = await show({ action: 'panel', name }); + h.check(new RegExp('not something show opens \\(' + reason + '\\)').test(errOf(r)), `"${name}" is refused: ${reason} (${errOf(r).slice(0, 120)})`); + } + + // ---- 4 ---------------------------------------------------------------------------------------------------- + await reset(); + await show({ action: 'panel', name: 'Explorer', to: 'dock' }); + await show({ action: 'panel', name: 'Timeline', to: 'dock' }); + await reset(); + const tl = await show({ action: 'panel', name: 'Timeline', state: 'focus' }); + h.check(tl?.result?.front === true && tl.result.where === 'dock', `the Timeline is the dock's front tab (${short(tl?.result)})`); + const exBefore = await P('explorer'); + h.check(exBefore?.open === true && exBefore.where === 'dock' && exBefore.front === false, `the Explorer is open in the dock but covered (${short(exBefore)})`); + const f1 = await show({ action: 'panel', name: 'Explorer', state: 'focus' }); + h.check(f1?.result?.changed === true && f1.result.front === true && f1.result.visible === true, `focus on a covered tab: changed:true, front:true (${short(f1?.result)})`); + const f2 = await show({ action: 'panel', name: 'Explorer', state: 'focus' }); + h.check(f2?.result?.changed === false && f2.result.front === true, `focus again: changed:false, still front (${short(f2?.result)})`); + await reset(); + const dc = await show({ action: 'panel', name: 'Dock', state: 'close' }); + h.check(dc?.result?.target === 'Dock' && dc.result.state === 'closed' && dc.result.changed === true, `Dock close hides the dock (${short(dc?.result)})`); + const exMin = await P('explorer'); + h.check(exMin?.open === true && exMin.visible === false, `a minimized dock: the Explorer is open but not visible (${short(exMin)})`); + const f3 = await show({ action: 'panel', name: 'Explorer', state: 'focus' }); + h.check(f3?.result?.changed === true && f3.result.visible === true, `focus brings the minimized dock back (${short(f3?.result)})`); + + // ---- 5 ---------------------------------------------------------------------------------------------------- + await reset(); + const d2 = await show({ action: 'panel', name: 'bottom dock', state: 'close' }); + h.check(d2?.result?.changed === true && d2.result.tabs?.includes('Explorer'), `close again: hidden, its tabs listed (${short(d2?.result)})`); + const bk = await show({ action: 'back' }); + h.check(bk?.result?.back === true, `back (${short(bk)})`); + h.check((await panels()).dock.open === true, 'Back reopens the dock'); + const ls = await show({ action: 'panel', name: 'Left sidebar', state: 'toggle' }); + h.check(ls?.result?.target === 'Left sidebar' && typeof ls.result.open === 'boolean', `Left sidebar toggles (${short(ls?.result)})`); + await show({ action: 'back' }); + + // ---- 6 ---------------------------------------------------------------------------------------------------- + await reset(); + const mv = await show({ action: 'panel', name: 'Explorer', state: 'move', to: 'right' }); + h.check(mv?.result?.where === 'right' && mv.result.changed === true, `move to the right sidebar (${short(mv?.result)})`); + await h.eventually(() => where('explorer'), (w) => w === 'right', 'the Explorer is in the right sidebar', 5000); + await show({ action: 'back' }); + await h.eventually(() => where('explorer'), (w) => w === 'dock', 'Back puts it in the dock again', 5000); + const mx = await show({ action: 'panel', name: 'Explorer', state: 'maximize' }); + h.check(mx?.result?.maximized === true, `maximize a docked panel (${short(mx?.result)})`); + h.check((await panels()).focusMode === 'dock', 'focus mode is the dock'); + const rs = await show({ action: 'panel', name: 'Explorer', state: 'restore' }); + h.check(rs?.result?.maximized === false && (await panels()).focusMode === null, `restore (${short(rs?.result)})`); + await reset(); + const mxf = await show({ action: 'panel', name: 'Statistics', state: 'maximize' }); + h.check(/DOCKED panel/.test(errOf(mxf)) || mxf?.result?.maximized === true, `maximize on a non-docked panel says to dock it first (${errOf(mxf).slice(0, 120) || short(mxf?.result)})`); + const col = await show({ action: 'panel', name: 'Explorer', state: 'collapse', pane: 'tree' }); + h.check(col?.result?.pane === 'tree' && col.result.paneState === 'closed', `collapse the Explorer's folder tree (${short(col?.result)})`); + h.check((await P('explorer'))?.panes?.tree === false, 'panels reads the tree closed'); + const exp = await show({ action: 'panel', name: 'Explorer', state: 'expand', pane: 'left' }); + h.check(exp?.result?.paneState === 'open' && (await P('explorer'))?.panes?.tree === true, `expand it again by side (${short(exp?.result)})`); + + // ---- 7 ---------------------------------------------------------------------------------------------------- + await reset(); + const sv = await show({ action: 'layout', name: 'E2E panels', state: 'save' }); + h.check(sv?.result?.saved === true && sv.result.layouts.includes('E2E panels'), `save a layout (${short(sv)})`); + const dup = await show({ action: 'layout', name: 'e2e panels', state: 'save' }); + h.check(/show never overwrites one/.test(errOf(dup)), `an existing name is refused (${errOf(dup).slice(0, 100)})`); + await show({ action: 'panel', name: 'Explorer', state: 'close' }); + const ap = await show({ action: 'layout', name: 'E2E panels' }); + h.check(ap?.result?.applied === true, `apply it (${short(ap)})`); + await h.eventually(() => where('explorer'), (w) => w !== null, 'the layout brought the Explorer back', 8000); + const nl = await show({ action: 'layout', name: 'No such layout' }); + h.check(/no layout "No such layout": nothing changed/.test(errOf(nl)), 'an unknown layout changes nothing'); + + await h.finish(browser); +}); diff --git a/tests/unit/panels107.test.js b/tests/unit/panels107.test.js new file mode 100644 index 000000000..92ec69728 --- /dev/null +++ b/tests/unit/panels107.test.js @@ -0,0 +1,95 @@ +import { describe, it, expect } from 'vitest'; +import { PANELS, PANEL_BY_ID, TARGETS, BLOCKED, normalName, panelOf, targetOf, blockedReason, unknownPanelError, validNames, blockedList, paneOf } from '../../src/lib/ai/panelsCore.js'; +import { DOCK_FAMILY, HOSTED_DOCK_TABS, DOCK_TITLES } from '../../src/lib/bottomDock.js'; + +// 107-panels (roadmap 107, owner report 27 Nov): THE PANEL REGISTRY. Every real panel by its own name, +// an unknown name never substitutes, the block list is narrow and matched on whole words. + +describe('107 panel registry: names', () => { + it('the panels the owner asked for open by their own names, never another one', () => { + expect(panelOf('Animation')).toBe('animation'); + expect(panelOf('Animation editor')).toBe('animation'); + expect(panelOf('UV Editor')).toBe('uv'); + expect(panelOf('Shader Editor')).toBe('shader'); + expect(panelOf('HUD Editor')).toBe('hud'); + expect(panelOf('Statistics')).toBe('stats'); + expect(panelOf('Profiler')).toBe('profiler'); + expect(panelOf('Timeline')).toBe('timeline'); + expect(panelOf('Sequencer')).toBe('timeline'); + expect(panelOf('Preview')).toBe('preview'); + expect(panelOf('Configure Scene')).toBe('scene'); + }); + it('an unknown name is null: no near guess (the "Animation opened the Timeline" bug)', () => { + for (const n of ['Animations timeline', 'Anim', 'Material editor', 'Sculpt', 'Terrain', 'Particles', '', ' ']) expect(panelOf(n)).toBe(null); + }); + it('every spelling names ONE panel (no alias collides with another panel or a target)', () => { + /** @type {Map} */ + const seen = new Map(); + for (const p of PANELS) + for (const s of [p.id, p.title, ...(p.aliases ?? [])].map(normalName)) { + expect(seen.get(s) ?? p.id, `"${s}" names ${seen.get(s)} and ${p.id}`).toBe(p.id); + seen.set(s, p.id); + expect(targetOf(s), `"${s}" is also a target`).toBe(null); + } + }); + it('the registry covers every dock view and hosted window the app has', () => { + const keys = new Set(PANELS.map((p) => p.key)); + // flowcode is the Node editor's JSON face (Code workspace covers it); meshGen is Generate 3D (connected apps: refused) + for (const k of [...DOCK_FAMILY, ...HOSTED_DOCK_TABS].filter((k) => !['flowcode', 'meshGen'].includes(k))) expect(keys.has(k), k).toBe(true); + expect(blockedReason(DOCK_TITLES.meshGen)).toBe('connected apps'); + }); + it('each panel has a one-line description; Profiler and Statistics are read-only', () => { + for (const p of PANELS) { + expect(p.description.length, p.id).toBeGreaterThan(20); + expect(p.description.length, p.id).toBeLessThan(200); + } + expect(PANELS.filter((p) => p.readOnly).map((p) => p.id)).toEqual(['profiler', 'stats']); + expect(PANEL_BY_ID.preview.description).toMatch(/selected in the Explorer/); + }); + it('the dock and the two sidebars are named targets', () => { + expect(targetOf('Dock')).toBe('dock'); + expect(targetOf('bottom dock')).toBe('dock'); + expect(targetOf('Left sidebar')).toBe('left'); + expect(targetOf('right sidebar')).toBe('right'); + expect(targetOf('Explorer')).toBe(null); + expect(Object.keys(TARGETS)).toEqual(['dock', 'left', 'right']); + }); +}); + +describe('107 panel registry: the block list', () => { + it('whole words: Profiler is not "profile", Statistics is not refused', () => { + expect(blockedReason('Profiler')).toBe(null); + expect(blockedReason('Statistics')).toBe(null); + expect(blockedReason('Profile')).toBe('sign-in and account'); + expect(blockedReason('Settings')).toBe('settings'); + expect(blockedReason('Explorer settings')).toBe('settings'); + expect(blockedReason('Sign in')).toBe('sign-in and account'); + expect(blockedReason('Publish')).toBe('publishing and export'); + expect(blockedReason('Connected apps')).toBe('connected apps'); + expect(blockedReason('Billing')).toBe('payment'); + expect(blockedReason('Privacy')).toBe('consent and privacy'); + }); + it('no real panel name is ever refused', () => { + for (const p of PANELS) for (const s of [p.title, ...(p.aliases ?? [])]) expect(blockedReason(s), s).toBe(null); + }); + it('the unknown-name error lists every valid name and the refused surfaces by reason', () => { + const e = unknownPanelError('Animations'); + expect(e.error).toMatch(/^no panel "Animations": nothing was opened/); + for (const t of ['Animation', 'UV editor', 'Shader editor', 'HUD editor', 'Statistics', 'Profiler', 'Dock', 'Left sidebar']) expect(e.valid).toContain(t); + expect(e.blocked.map((b) => b.reason)).toEqual(BLOCKED.map((b) => b.reason)); + expect(e.error).toMatch(/settings \(Settings, Preferences\)/); + expect(validNames().length).toBe(PANELS.length + 3); + expect(blockedList()[0]).toEqual({ reason: 'sign-in and account', names: ['Sign in', 'Account', 'Profile'] }); + }); +}); + +describe('107 panel registry: panes', () => { + it('a panel\'s own sidebars by name or by side', () => { + expect(paneOf(PANEL_BY_ID.explorer, 'tree')).toBe('tree'); + expect(paneOf(PANEL_BY_ID.explorer, 'left sidebar')).toBe('tree'); + expect(paneOf(PANEL_BY_ID.code, 'right')).toBe('tools'); + expect(paneOf(PANEL_BY_ID.code, 'files')).toBe('files'); + expect(paneOf(PANEL_BY_ID.objects, 'tree')).toBe(null); + expect(paneOf(PANEL_BY_ID.explorer, 'nope')).toBe(null); + }); +}); diff --git a/tests/unit/showScene.test.js b/tests/unit/showScene.test.js index eb402fffd..b449e3476 100644 --- a/tests/unit/showScene.test.js +++ b/tests/unit/showScene.test.js @@ -9,10 +9,10 @@ import { PERSON_AI_TOOLS, PERSON_TOOL_NAMES, personToolReads } from '../../src/l const tool = (name) => PERSON_AI_TOOLS.find((t) => t.function.name === name)?.function; describe('show: panels', () => { - it('the allow-list is the nine panels (+ the Assistant tab), by their names and the words people use', () => { - expect(Object.values(SHOW_PANELS).map((p) => p.label)).toEqual(['Explorer', 'Objects', 'Inspector', 'Flow editor', 'Code', 'Timeline', 'Assets', 'Preview', 'Chat', 'Assistant']); + it('the allow-list is the registry (107-panels), by their names and the words people use', () => { + expect(Object.values(SHOW_PANELS).map((p) => p.label)).toEqual(['Explorer', 'Objects', 'Inspector', 'Configure Scene', 'Flow editor', 'Animation', 'Timeline', 'UV editor', 'Shader editor', 'HUD editor', 'Code', 'Profiler', 'Statistics', 'Free assets', 'Preview', 'Debugger', 'Chat', 'Assistant']); expect(panelOf('Explorer')).toBe('explorer'); - expect(panelOf('the Library')).toBe(null); + expect(panelOf('the Library')).toBe('explorer'); expect(panelOf('library')).toBe('explorer'); expect(panelOf('Flow editor')).toBe('flow'); expect(panelOf('node editor')).toBe('flow'); @@ -20,11 +20,12 @@ describe('show: panels', () => { expect(panelOf('code window')).toBe('code'); expect(panelOf('Timeline')).toBe('timeline'); expect(panelOf('AI assistant')).toBe('assistant'); - expect(panelOf('UV editor')).toBe(null); + expect(panelOf('UV editor')).toBe('uv'); + expect(panelOf('Animation')).toBe('animation'); }); it('rule 2: sign-in, account, consent, publish, connected apps, payment and settings are denied', () => { for (const n of ['Sign in', 'login', 'Account', 'Consent', 'Publish', 'Connected apps', 'Connect Claude', 'payment', 'Billing', 'Settings', 'Roles', 'Privacy settings', 'Export']) expect(deniedPanel(n)).toBe(true); - for (const n of ['Explorer', 'Objects', 'Inspector', 'Flow editor', 'Code', 'Timeline', 'Assets', 'Preview', 'Chat']) expect(deniedPanel(n)).toBe(false); + for (const n of ['Explorer', 'Objects', 'Inspector', 'Flow editor', 'Code', 'Timeline', 'Assets', 'Preview', 'Chat', 'Profiler', 'Statistics']) expect(deniedPanel(n)).toBe(false); }); it('rule 7: 6 a minute, one camera move per 2 s', () => { expect(SHOW_PER_MINUTE).toBe(6); @@ -63,9 +64,9 @@ describe('show + scene: schemas', () => { expect(PERSON_TOOL_NAMES).toEqual(['files', 'show', 'scene']); expect(PERSON_AI_TOOLS.map((t) => t.function.name)).toEqual(['files', 'show', 'scene']); }); - it('show: panel | camera | code | back, and no text to write (rule 8)', () => { + it('show: panels | panel | layout | camera | code | back, and no text to write (rule 8)', () => { const s = tool('show'); - expect(s.parameters.properties.action.enum).toEqual(['panel', 'camera', 'code', 'back']); + expect(s.parameters.properties.action.enum).toEqual(['panels', 'panel', 'layout', 'camera', 'code', 'back']); expect(s.parameters.properties.text).toBeUndefined(); expect(s.description).toMatch(/THEIR OWN screen/); expect(s.description).toMatch(/Always \/ This time \/ No/); @@ -82,10 +83,11 @@ describe('show + scene: schemas', () => { expect(s.description).toMatch(/only the host/); expect(s.description).toMatch(/call list_scene again/); }); - it('read scope: scene list reads; show never counts as a read', () => { + it('read scope: scene list reads; of show only the panels list reads (107-panels)', () => { expect(personToolReads('scene', { action: 'list' })).toBe(true); expect(personToolReads('scene', { action: 'open' })).toBe(false); expect(personToolReads('scene', { action: 'new' })).toBe(false); - for (const a of ['panel', 'camera', 'code', 'back']) expect(personToolReads('show', { action: a })).toBe(false); + for (const a of ['panel', 'layout', 'camera', 'code', 'back']) expect(personToolReads('show', { action: a })).toBe(false); + expect(personToolReads('show', { action: 'panels' })).toBe(true); }); }); From c55605c9f1454b1c85dbb9fe0ea72c8f7212d841 Mon Sep 17 00:00:00 2001 From: AlexZ005 Date: Fri, 27 Nov 2026 01:24:43 +0200 Subject: [PATCH 2/2] =?UTF-8?q?107=20107-panels:=20rulings=20=E2=80=94=20r?= =?UTF-8?q?efuse=20by=20exact=20surface=20with=20its=20reason,=20Scene=20s?= =?UTF-8?q?ettings=20opens,=20panels=20belong=20to=20Edit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ruling 2026-11-27 (claude:9 via theprototype-41): the block list is by exact surface name with a reason (BLOCKED entries), never a substring; Scene settings is Configure Scene; publishing / export stays refused and the error says so. In Play, a panel / dock / layout call is an error (panels belong to Edit), never a success; also refused while a dialog is open or while spectating; moves and layouts respect Windows > Lock layout. A closed panel with to: opens and moves. connector-show-panels in the battery. Co-Authored-By: Claude Opus 5.5 --- src/lib/ai/panelsCore.js | 91 +++++++++++++++++------- src/lib/ai/personTools.js | 5 +- src/lib/ai/showCore.js | 4 +- src/lib/ai/showTool.js | 50 +++++++++++-- tests/e2e/battery.json | 1 + tests/e2e/connector-show-panels.test.cjs | 17 ++++- tests/unit/panels107.test.js | 46 ++++++++---- 7 files changed, 166 insertions(+), 48 deletions(-) diff --git a/src/lib/ai/panelsCore.js b/src/lib/ai/panelsCore.js index 9a2289870..5ecebf65c 100644 --- a/src/lib/ai/panelsCore.js +++ b/src/lib/ai/panelsCore.js @@ -8,9 +8,10 @@ // id, its title, or one of its aliases — the words people use for THAT panel. Nothing is guessed: an unknown // name is an error that lists every valid name and every refused surface with its reason. // -// THE BLOCK RULE (rule 2 of show, unchanged): sign-in, account, consent, publishing, connected apps, payment -// and settings stay the person's own to open. It is matched on WHOLE WORDS, so "Profiler" is not "profile" -// and "Statistics" is not refused — the read-only views (Profiler, Statistics) are not settings. +// THE BLOCK RULE (rule 2 of show): sign-in, account, consent, publishing, connected apps, payment and settings +// stay the person's own to open. Ruling 2026-11-27: each refused surface is listed BY ITS OWN NAME with its reason, +// never matched by substring, so "Profiler" is not "profile", "Statistics" opens and "Scene settings" is +// Configure Scene (scene content, not app settings). /** * @typedef {'toggle' | 'hosted' | 'inspector' | 'scene' | 'chat' | 'debugger'} PanelVia @@ -42,7 +43,7 @@ export const PANELS = [ { id: 'explorer', key: 'explorer', title: 'Explorer', via: 'toggle', description: 'The Library: the person\'s files and folders as a folder tree and a file list', aliases: ['library', 'files', 'file explorer', 'file browser'], panes: { tree: 'the folder tree (left)', details: 'the file details and settings sidebar (right)' } }, { id: 'objects', key: 'objects', title: 'Objects', via: 'toggle', description: 'Every object in the scene as a tree (the outliner)', aliases: ['outliner', 'object list', 'hierarchy', 'scene tree'] }, { id: 'inspector', key: 'inspector', title: 'Inspector', via: 'inspector', description: 'The selected object\'s properties (the Properties tab: transform, look, physics, lights, cameras)', aliases: ['properties', 'properties panel', 'object properties'] }, - { id: 'scene', key: 'scene', title: 'Configure Scene', via: 'scene', description: 'The scene\'s own setup: sky, light, fog, physics, grid (the Inspector\'s other tab)', aliases: ['configure scene', 'scene setup', 'environment', 'sky'] }, + { id: 'scene', key: 'scene', title: 'Configure Scene', via: 'scene', description: 'The scene\'s own setup: sky, light, fog, physics, grid (the Inspector\'s other tab)', aliases: ['configure scene', 'scene settings', 'scene setup', 'scene config', 'scene configuration', 'environment', 'sky'] }, { id: 'flow', key: 'flow', title: 'Flow editor', via: 'toggle', description: 'The node editor: an object\'s or the scene\'s behaviour as a node graph', aliases: ['node editor', 'flow', 'nodes', 'flow graph', 'behaviours', 'graph editor'] }, { id: 'animation', key: 'animation', title: 'Animation', via: 'toggle', description: 'The Animation editor: keyframes and clips for the selected object (its own moves, not the Timeline\'s shots)', aliases: ['animation editor', 'animator', 'keyframes', 'dope sheet'] }, { id: 'timeline', key: 'timeline', title: 'Timeline', via: 'toggle', description: 'The Timeline: cutscene sequences of camera shots, clips, audio and events', aliases: ['sequencer', 'sequences', 'cutscenes'], panes: { sequences: 'the sequences list (left)', details: 'the selected track\'s details (right)' } }, @@ -73,19 +74,42 @@ export const TARGETS = { }; /** - * Surfaces show never opens (rule 2), grouped by the reason it gives. `words` are matched as whole words. - * @type {{reason: string, names: string[], words: string[]}[]} + * Surfaces show never opens (rule 2), EACH BY ITS OWN NAME with the reason it gives (ruling 2026-11-27: the refuse + * list is by exact surface, never by substring — "Profiler" is not "profile", "Scene settings" is Configure Scene). + * A name that is neither a panel nor one of these is simply unknown, and the unknown-name error lists both. + * @type {{id: string, title: string, reason: string, aliases?: string[]}[]} */ export const BLOCKED = [ - { reason: 'sign-in and account', names: ['Sign in', 'Account', 'Profile'], words: ['sign in', 'signin', 'log in', 'login', 'log out', 'logout', 'sign out', 'account', 'profile', 'password'] }, - { reason: 'consent and privacy', names: ['Consent', 'Privacy'], words: ['consent', 'privacy', 'cookies'] }, - { reason: 'publishing and export', names: ['Publish', 'Export', 'Share'], words: ['publish', 'publishing', 'export', 'share'] }, - { reason: 'connected apps', names: ['Connected apps', 'Connect Claude', 'Generate 3D'], words: ['connected apps', 'connected app', 'connect claude', 'connector', 'generate 3d', 'mesh generator', 'meshy'] }, - { reason: 'payment', names: ['Payment', 'Billing', 'Subscription'], words: ['payment', 'payments', 'billing', 'subscription', 'credits'] }, - { reason: 'settings', names: ['Settings', 'Preferences'], words: ['settings', 'preferences', 'options'] }, - { reason: 'session access', names: ['Roles', 'Permissions', 'Invite'], words: ['roles', 'permissions', 'invite', 'approve'] } + { id: 'signin', title: 'Sign in', reason: 'sign-in and account', aliases: ['sign-in', 'signin', 'log in', 'login', 'log out', 'logout', 'sign out', 'sign up'] }, + { id: 'account', title: 'Account', reason: 'sign-in and account', aliases: ['profile', 'edit profile', 'my account', 'profile menu', 'avatar menu', 'password'] }, + { id: 'consent', title: 'Consent', reason: 'consent and privacy', aliases: ['cookies', 'cookie consent', 'consent dialog'] }, + { id: 'privacy', title: 'Privacy', reason: 'consent and privacy', aliases: ['privacy settings', 'data and privacy'] }, + { id: 'publish', title: 'Publish / Export', reason: 'publishing', aliases: ['publish', 'publishing', 'export', 'publish export', 'export for 3d printing', 'export for ar', 'export 3d', 'publish your game'] }, + { id: 'moment', title: 'Share a moment', reason: 'publishing', aliases: ['share', 'share moment', 'moment', 'share as video'] }, + { id: 'connectedApps', title: 'Connected apps', reason: 'connected apps', aliases: ['connected app'] }, + { id: 'connectClaude', title: 'Connect Claude', reason: 'connected apps', aliases: ['connector', 'claude connector', 'connect ai'] }, + { id: 'meshGen', title: 'Generate 3D', reason: 'connected apps', aliases: ['generate 3d model', 'mesh generator', 'meshy'] }, + { id: 'payment', title: 'Payment', reason: 'payment', aliases: ['payments', 'billing', 'subscription', 'credits', 'buy credits'] }, + { id: 'settings', title: 'Settings', reason: 'settings', aliases: ['app settings', 'preferences', 'options', 'settings dialog'] }, + { id: 'roles', title: 'Roles', reason: 'session access', aliases: ['permissions', 'connected peers', 'peers', 'people'] }, + { id: 'invite', title: 'Invite', reason: 'session access', aliases: ['invite to this session', 'invites', 'invite link'] }, + { id: 'joinRequests', title: 'Join requests', reason: 'session access', aliases: ['approve', 'approvals', 'connection requests'] }, + { id: 'connect', title: 'Connect', reason: 'session access', aliases: ['connect bar', 'connect drawer', 'session connect'] }, + { id: 'reportBug', title: 'Report a bug', reason: 'sends data out', aliases: ['bug report', 'problem report', 'feedback'] } ]; +/** what each reason means, for the refusal */ +export const BLOCK_REASONS = /** @type {Record} */ ({ + 'sign-in and account': 'signing in and the person\'s account stay theirs to open', + 'consent and privacy': 'consent and privacy choices are the person\'s own', + publishing: 'publishing and export stay refused: they send the person\'s work out of the app, so the person opens them', + 'connected apps': 'connected apps (the connector itself, Generate 3D) are the person\'s own to open', + payment: 'payment is the person\'s own', + settings: 'the app\'s Settings stay the person\'s own (scene setup is Configure Scene, which opens)', + 'session access': 'who may join or edit the session is the person\'s own to decide', + 'sends data out': 'a bug report sends data out of the app: the person opens it' +}); + /** @param {string} name @returns {string} lower-case, single-spaced, no "panel"/"window"/"tab"/"view"/"the"/"editor" noise */ export function normalName(name) { return String(name ?? '') @@ -119,16 +143,19 @@ export function targetOf(name) { return NAME_TO_TARGET.get(n) ?? null; } -/** @param {string} hay @param {string} word */ -const hasWord = (hay, word) => (' ' + hay + ' ').includes(' ' + word + ' '); +const NAME_TO_BLOCKED = /** @type {Map} */ (new Map()); +for (const b of BLOCKED) for (const sp of spellings(b)) if (!NAME_TO_BLOCKED.has(sp)) NAME_TO_BLOCKED.set(sp, b); -/** the reason a name is refused (rule 2), or null. A real panel's own name is never refused. @param {string} name */ -export function blockedReason(name) { - if (panelOf(name) || targetOf(name)) return null; +/** the refused surface a name means, exactly, or null @param {string} name */ +export function blockedOf(name) { const n = normalName(name); - if (!n) return null; - for (const b of BLOCKED) if (b.words.some((w) => hasWord(n, normalName(w)))) return b.reason; - return null; + if (!n || panelOf(name) || targetOf(name)) return null; + return NAME_TO_BLOCKED.get(n) ?? null; +} + +/** the reason a name is refused (rule 2), or null @param {string} name */ +export function blockedReason(name) { + return blockedOf(name)?.reason ?? null; } /** is this a surface rule 2 keeps closed @param {string} name */ @@ -141,14 +168,30 @@ export function validNames() { return [...PANELS.map((p) => p.title), ...Object.values(TARGETS).map((t) => t.title)]; } -/** the refused surfaces, by reason, for an error and the panels list */ +/** the refused surfaces, by reason, for an error and the panels list @returns {{reason: string, names: string[]}[]} */ export function blockedList() { - return BLOCKED.map((b) => ({ reason: b.reason, names: b.names })); + /** @type {Map} */ + const by = new Map(); + for (const b of BLOCKED) by.set(b.reason, [...(by.get(b.reason) ?? []), b.title]); + return [...by].map(([reason, names]) => ({ reason, names })); } /** one line naming the refused surfaces by reason */ export function blockedLine() { - return BLOCKED.map((b) => b.reason + ' (' + b.names.join(', ') + ')').join('; '); + return blockedList().map((b) => b.reason + ' (' + b.names.join(', ') + ')').join('; '); +} + +/** the refusal for a blocked surface @param {string} asked */ +export function blockedError(asked) { + const b = blockedOf(asked); + if (!b) return null; + return { + error: '"' + String(asked).slice(0, 60) + '" is not something show opens (' + b.reason + '): ' + (BLOCK_REASONS[b.reason] ?? 'it stays the person\'s own') + '. Nothing was opened. Read-only views (Profiler, Statistics) and Configure Scene do open.', + refused: true, + reason: b.reason, + surface: b.title, + blocked: blockedList() + }; } /** the error for a name that is neither a panel, a target nor a refused surface @param {string} asked */ diff --git a/src/lib/ai/personTools.js b/src/lib/ai/personTools.js index 419ff942c..05acce516 100644 --- a/src/lib/ai/personTools.js +++ b/src/lib/ai/personTools.js @@ -31,13 +31,14 @@ const SHOW_DESCRIPTION = 'collapse / expand one of its own sidebars (pane) for one panel by its name: Explorer, Objects, Inspector, Configure Scene, Flow editor, Animation, Timeline, UV editor, Shader editor, HUD editor, Code, ' + 'Profiler and Statistics (read-only views), Free assets, Preview (the selected Explorer file), Debugger, Chat, Assistant; or name "Dock", "Left sidebar", "Right sidebar" to open, close or toggle them (close hides, tabs stay open). ' + 'An unknown name opens nothing and the error lists the valid names: never guess another panel. The answer says visible and front truthfully. ' + + 'Panels belong to Edit: while the person plays, panel and layout calls are refused (panels still reads). ' + 'layout = apply a saved layout by name, or save the current one under a new name. ' + 'camera = move their editor view to frame objects (frame: [uuids], select: true also selects them), to a position + target, or let them look through a scene camera (through: uuid); ' + 'code = open a file or a Script / Behaviour node\'s code in their Code tab at a line, selecting lines [line, to], a range, or the first match of find; ' + 'back = undo what the last show changed. The first time for each of panel / camera / code the person is asked on their screen (Always / This time / No): ' + 'call again with the confirmId; after No, do not ask again, tell them where to look instead. ' + 'Each action leaves a line with a Back button for the person. Not in a VR headset (camera moves are refused there), not while they play, drag or type; ' + - '6 calls a minute, one camera move per 2 s. Never opens sign-in, account, settings, consent, publishing, connected apps or payment. ' + + '6 calls a minute, one camera move per 2 s. Never opens sign-in, account, settings, consent, publishing or export, connected apps or payment (each refused by name, with its reason); Configure Scene (scene settings) is scene content and opens. ' + 'screenshot never moves anyone (use it to look yourself); show moves the person\'s own view. show only opens and selects code: change text with files {action: "write"}, running code with edit_behaviour. ' + 'Opening another scene is scene, not show.'; @@ -92,7 +93,7 @@ export const PERSON_AI_TOOLS = [ state: { type: 'string', enum: ['open', 'close', 'focus', 'toggle', 'move', 'maximize', 'restore', 'collapse', 'expand', 'apply', 'save'], - description: 'panel: default open (focus brings an open one to the front; move needs to; collapse / expand need pane); layout: apply (default) or save' + description: 'panel: default open (with to: opens it there); focus brings an open one to the front; move needs to; collapse / expand need pane. layout: apply (default) or save' }, to: { description: 'panel: where to move it — dock, left, right or floating. code: with line, the last line to select', diff --git a/src/lib/ai/showCore.js b/src/lib/ai/showCore.js index 6866eae73..2dd671a82 100644 --- a/src/lib/ai/showCore.js +++ b/src/lib/ai/showCore.js @@ -37,8 +37,8 @@ export { panelOf, deniedPanel, normalName, blockedReason }; */ export const SHOW_PANELS = Object.fromEntries(PANELS.map((p) => [p.id, { key: p.key, label: p.title, via: p.via, ...(p.readOnly ? { readOnly: true } : {}) }])); -/** surfaces `show` never opens or presses (rule 2), every word of every reason */ -export const DENIED = BLOCKED.flatMap((b) => b.words); +/** surfaces `show` never opens or presses (rule 2), by their names */ +export const DENIED = BLOCKED.flatMap((b) => [b.title, ...(b.aliases ?? [])].map(normalName)); /** * Where the camera goes to frame a box, keeping the view direction (objectActions.focusObject's diff --git a/src/lib/ai/showTool.js b/src/lib/ai/showTool.js index 7a40d911e..78cec3052 100644 --- a/src/lib/ai/showTool.js +++ b/src/lib/ai/showTool.js @@ -194,21 +194,44 @@ async function targetAction(tid, state, by) { return { target: T.title, ...now, state: now.open ? 'open' : 'closed', changed: r.changed, ...(r.changed && !r.open ? { note: 'Hidden, not closed: every tab in it stays open.' } : {}) }; } +/** + * 107-panels (ruling 2026-11-27): when no panel change can be true. Play mode hides the editor, so show never answers + * success for a panel that is not there; an open dialog (Settings, Sessions, ...) puts the panels back as they were + * when it closes, and watching someone else's view holds the same snapshot. + * @returns {Promise<{error: string, extra: any} | null>} + */ +async function panelsNotNow() { + if (get(isLocked) === true) return { error: 'the person is playing: panels belong to Edit, and Play hides them. Nothing was opened. Ask them to press Esc to go back to Edit, then call again', extra: { refused: true, playing: true } }; + const { anyModalOpen } = await import('../../stores/appStore'); + if (get(anyModalOpen)) return { error: 'a dialog is open on the person\'s screen (Settings, Sessions, Modules, ...): it puts the panels back as they were when it closes. Ask them to close it first', extra: { busy: true, retryAfter: 5 } }; + if (get(specatorMode)) return { error: 'the person is watching someone else\'s view: their panels come back when they press Exit', extra: { refused: true } }; + return null; +} + +/** the person's Windows ▸ Lock layout: moves and layouts wait for them @returns {Promise} */ +async function layoutLockedWhy() { + const { layoutLocked } = await import('../windowPrefs'); + return get(layoutLocked) ? 'the person locked the layout (Windows ▸ Lock layout): moving panels and applying a layout wait until they unlock it' : ''; +} + /** @param {any} args @param {string} by */ async function panelAction(args, by) { const core = await import('./panelsCore.js'); const asked = String(args.name ?? args.panel ?? ''); if (!asked) return fail('name: the panel to show. ' + core.unknownPanelError('').error.replace(/^no panel "": nothing was opened\. /, ''), { valid: core.validNames(), blocked: core.blockedList() }); - const reason = core.blockedReason(asked); - if (reason) return fail('"' + asked + '" is not something show opens (' + reason + '): sign-in, account, consent, publishing, connected apps, payment and settings stay the person\'s own to open. Read-only views (Profiler, Statistics) do open.', { refused: true, reason, blocked: core.blockedList() }); - const state = String(args.state ?? (args.to ? 'move' : 'open')); - const tid = core.targetOf(asked); - if (tid) return targetAction(/** @type {any} */ (tid), state, by); - const id = core.panelOf(asked); - if (!id) { + const blocked = core.blockedError(asked); + if (blocked) return fail(blocked.error, { refused: true, reason: blocked.reason, surface: blocked.surface, blocked: blocked.blocked }); + if (!core.panelOf(asked) && !core.targetOf(asked)) { const e = core.unknownPanelError(asked); return fail(e.error, { valid: e.valid, blocked: e.blocked }); } + const notNow = await panelsNotNow(); + if (notNow) return fail(notNow.error, notNow.extra); + // a `to` without a state opens it (when closed) and puts it there: the open path below moves it too + const state = String(args.state ?? 'open'); + const tid = core.targetOf(asked); + if (tid) return targetAction(/** @type {any} */ (tid), state, by); + const id = /** @type {string} */ (core.panelOf(asked)); const p = core.PANEL_BY_ID[id]; const label = p.title; const P = await import('./panels.js'); @@ -266,6 +289,10 @@ async function panelAction(args, by) { return { panel: label, ...sameAs, maximized: now === 'dock', changed, ...(await panelState(id)) }; } + if (state === 'move' || (args.to && state === 'open')) { + const locked = await layoutLockedWhy(); + if (locked) return fail(locked, { refused: true, locked: true }); + } if (state === 'move') { const to = String(args.to ?? ''); if (!['dock', 'left', 'right', 'floating'].includes(to)) return fail('to: dock, left, right or floating'); @@ -320,6 +347,8 @@ async function panelAction(args, by) { /** @param {any} args @param {string} by */ async function layoutAction(args, by) { + const notNow = await panelsNotNow(); + if (notNow) return fail(notNow.error, notNow.extra); const L = await import('../uiLayouts'); const list = /** @type {any[]} */ (get(L.uiLayouts)); const state = String(args.state ?? 'apply'); @@ -339,6 +368,8 @@ async function layoutAction(args, by) { return { layout: r.layout.name, saved: true, layouts: get(L.uiLayouts).map((/** @type {any} */ l) => l.name) }; } if (state !== 'apply') return fail('layout state: apply (default) or save'); + const locked = await layoutLockedWhy(); + if (locked) return fail(locked, { refused: true, locked: true }); if (!hit) return fail('no layout "' + name + '": nothing changed. Saved layouts: ' + (list.map((l) => l.name).join(', ') || 'none yet'), { layouts: list.map((l) => l.name) }); const beforeRec = L.captureLayout('before'); const beforeActive = get(L.activeLayoutId); @@ -563,6 +594,11 @@ export async function showTool(args, ctx = {}) { const asked = String(a.name ?? a.panel ?? ''); if (!asked || deniedPanel(asked) || (!panelOf(asked) && !targetOf(asked))) return panelAction(a, by); } + // 107-panels: nobody is asked about a panel change that cannot happen now (Play, a dialog, spectating) + if (raw === 'panel' || raw === 'layout') { + const notNow = await panelsNotNow(); + if (notNow) return fail(notNow.error, notNow.extra); + } // 107-panels: a layout asks as a panel change (the same first-use kind: "open and close your panels") const action = raw === 'layout' ? 'panel' : raw; const busy = busyReason(); diff --git a/tests/e2e/battery.json b/tests/e2e/battery.json index 0aa69046c..47654717a 100644 --- a/tests/e2e/battery.json +++ b/tests/e2e/battery.json @@ -544,6 +544,7 @@ "connector-join": 120, "connector-physics": 41, "connector-relay": 240, + "connector-show-panels": 200, "connector-show-scene": 180, "connector-through": 150, "connector-voice": 7, diff --git a/tests/e2e/connector-show-panels.test.cjs b/tests/e2e/connector-show-panels.test.cjs index 77b66d353..65ffbcd11 100644 --- a/tests/e2e/connector-show-panels.test.cjs +++ b/tests/e2e/connector-show-panels.test.cjs @@ -18,6 +18,7 @@ h.run(async () => { const browser = await h.launch(); const A = await h.setupPage(browser, 'A'); const page = A.page; + await page.evaluate(() => window.__tp.test.v1.aiAssistantHidden.set('')); const relay = await fakeRelay(page); await installProvider(page); await page.locator('#connect-claude-button').click(); @@ -70,10 +71,24 @@ h.run(async () => { const unk = await show({ action: 'panel', name: 'Animations timeline' }); h.check(/no panel "Animations timeline": nothing was opened/.test(errOf(unk)) && /Animation, Timeline/.test(errOf(unk)) && /settings \(Settings/.test(errOf(unk)), `an unknown name errors with the valid names and the block list (${errOf(unk).slice(0, 200)})`); h.check((await panels()).panels.filter((p) => p.open).map((p) => p.id).join() === openBefore, 'and nothing opened'); - for (const [name, reason] of [['Settings', 'settings'], ['Profile', 'sign-in and account'], ['Publish', 'publishing and export'], ['Generate 3D', 'connected apps']]) { + for (const [name, reason] of [['Settings', 'settings'], ['Profile', 'sign-in and account'], ['Publish', 'publishing'], ['Export', 'publishing'], ['Generate 3D', 'connected apps']]) { const r = await show({ action: 'panel', name }); h.check(new RegExp('not something show opens \\(' + reason + '\\)').test(errOf(r)), `"${name}" is refused: ${reason} (${errOf(r).slice(0, 120)})`); } + h.check(/publishing and export stay refused/.test(errOf(await show({ action: 'panel', name: 'Export' }))), 'the publishing refusal says it stays refused'); + const notSub = await show({ action: 'panel', name: 'Explorer settings' }); + h.check(/^no panel "Explorer settings"/.test(errOf(notSub)), `no substring block: "Explorer settings" is unknown, not refused (${errOf(notSub).slice(0, 80)})`); + await reset(); + const sceneSet = await show({ action: 'panel', name: 'Scene settings' }); + h.check(sceneSet?.result?.id === 'scene' && sceneSet.result.state === 'open', `"Scene settings" opens Configure Scene (scene content, not app settings) (${short(sceneSet)})`); + await page.evaluate(() => window.__tp.test.v1.isLocked.set(true)); + const inPlay = await show({ action: 'panel', name: 'Timeline' }); + const inPlayDock = await show({ action: 'panel', name: 'Dock', state: 'open' }); + const readInPlay = await panels(); + await page.evaluate(() => window.__tp.test.v1.isLocked.set(false)); + h.check(/panels belong to Edit/.test(errOf(inPlay)) && inPlay?.error?.data?.playing !== false, `in Play a panel call is an error, never a success (${errOf(inPlay).slice(0, 100)})`); + h.check(/panels belong to Edit/.test(errOf(inPlayDock)), 'and so is a dock call'); + h.check(readInPlay?.playing === true && readInPlay.panels.every((p) => !p.visible), 'panels still reads in Play: playing true, nothing visible'); // ---- 4 ---------------------------------------------------------------------------------------------------- await reset(); diff --git a/tests/unit/panels107.test.js b/tests/unit/panels107.test.js index 92ec69728..42262faa7 100644 --- a/tests/unit/panels107.test.js +++ b/tests/unit/panels107.test.js @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { PANELS, PANEL_BY_ID, TARGETS, BLOCKED, normalName, panelOf, targetOf, blockedReason, unknownPanelError, validNames, blockedList, paneOf } from '../../src/lib/ai/panelsCore.js'; +import { PANELS, PANEL_BY_ID, TARGETS, BLOCKED, normalName, panelOf, targetOf, blockedReason, blockedError, unknownPanelError, validNames, blockedList, paneOf } from '../../src/lib/ai/panelsCore.js'; import { DOCK_FAMILY, HOSTED_DOCK_TABS, DOCK_TITLES } from '../../src/lib/bottomDock.js'; // 107-panels (roadmap 107, owner report 27 Nov): THE PANEL REGISTRY. Every real panel by its own name, @@ -56,30 +56,52 @@ describe('107 panel registry: names', () => { }); }); -describe('107 panel registry: the block list', () => { - it('whole words: Profiler is not "profile", Statistics is not refused', () => { - expect(blockedReason('Profiler')).toBe(null); - expect(blockedReason('Statistics')).toBe(null); +describe('107 panel registry: the block list (exact surfaces, never substrings)', () => { + it('each refused surface by its own name, with its reason', () => { expect(blockedReason('Profile')).toBe('sign-in and account'); expect(blockedReason('Settings')).toBe('settings'); - expect(blockedReason('Explorer settings')).toBe('settings'); expect(blockedReason('Sign in')).toBe('sign-in and account'); - expect(blockedReason('Publish')).toBe('publishing and export'); + expect(blockedReason('Publish')).toBe('publishing'); + expect(blockedReason('Export')).toBe('publishing'); + expect(blockedReason('Publish / Export')).toBe('publishing'); expect(blockedReason('Connected apps')).toBe('connected apps'); + expect(blockedReason('Generate 3D')).toBe('connected apps'); expect(blockedReason('Billing')).toBe('payment'); - expect(blockedReason('Privacy')).toBe('consent and privacy'); + expect(blockedReason('Privacy settings')).toBe('consent and privacy'); + expect(blockedReason('Invite')).toBe('session access'); }); - it('no real panel name is ever refused', () => { + it('no substring: Profiler, Statistics, Scene settings and "Explorer settings" are not refused', () => { + expect(blockedReason('Profiler')).toBe(null); + expect(blockedReason('Statistics')).toBe(null); + expect(blockedReason('Scene settings')).toBe(null); + expect(panelOf('Scene settings')).toBe('scene'); + // not a panel and not a refused surface: simply unknown (the unknown error lists both) + expect(blockedReason('Explorer settings')).toBe(null); + expect(panelOf('Explorer settings')).toBe(null); + expect(blockedReason('Account settings page')).toBe(null); + }); + it('no real panel name is ever refused, and no refused name is also a panel', () => { for (const p of PANELS) for (const s of [p.title, ...(p.aliases ?? [])]) expect(blockedReason(s), s).toBe(null); + for (const b of BLOCKED) for (const s of [b.title, ...(b.aliases ?? [])]) { + expect(panelOf(s), s).toBe(null); + expect(blockedReason(s), s).toBe(b.reason); + } + }); + it('the publishing refusal says publishing stays refused', () => { + const e = blockedError('Export'); + expect(e?.reason).toBe('publishing'); + expect(e?.surface).toBe('Publish / Export'); + expect(e?.error).toMatch(/not something show opens \(publishing\): publishing and export stay refused/); + expect(blockedError('Profiler')).toBe(null); }); it('the unknown-name error lists every valid name and the refused surfaces by reason', () => { const e = unknownPanelError('Animations'); expect(e.error).toMatch(/^no panel "Animations": nothing was opened/); for (const t of ['Animation', 'UV editor', 'Shader editor', 'HUD editor', 'Statistics', 'Profiler', 'Dock', 'Left sidebar']) expect(e.valid).toContain(t); - expect(e.blocked.map((b) => b.reason)).toEqual(BLOCKED.map((b) => b.reason)); - expect(e.error).toMatch(/settings \(Settings, Preferences\)/); + expect(e.blocked.map((b) => b.reason)).toEqual(['sign-in and account', 'consent and privacy', 'publishing', 'connected apps', 'payment', 'settings', 'session access', 'sends data out']); + expect(e.error).toMatch(/settings \(Settings\)/); expect(validNames().length).toBe(PANELS.length + 3); - expect(blockedList()[0]).toEqual({ reason: 'sign-in and account', names: ['Sign in', 'Account', 'Profile'] }); + expect(blockedList()[0]).toEqual({ reason: 'sign-in and account', names: ['Sign in', 'Account'] }); }); });