Fix Brain panel rendering and keep Mnemon sidebar
This commit is contained in:
parent
7d306e77ad
commit
53e4423656
949
client/index.js
949
client/index.js
File diff suppressed because it is too large
Load Diff
|
|
@ -4,7 +4,6 @@ import { messageOf } from './api'
|
|||
import { CardBoundary } from './components'
|
||||
import { SettingsCard } from './SettingsCard'
|
||||
import { registerBrainPanel } from './panel/register'
|
||||
import { mountBrainSidebarTab } from './sidebar/register'
|
||||
|
||||
const h = React.createElement
|
||||
|
||||
|
|
@ -42,13 +41,6 @@ export function apply(ctx: any): void {
|
|||
} catch (failure) {
|
||||
if (typeof console !== 'undefined') console.warn('[dsh-brain] panel registration failed: ' + messageOf(failure))
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof ctx.effect === 'function') ctx.effect(() => mountBrainSidebarTab(ctx), 'dsh-brain: better-sidebar tab')
|
||||
else mountBrainSidebarTab(ctx)
|
||||
} catch (failure) {
|
||||
if (typeof console !== 'undefined') console.warn('[dsh-brain] better-sidebar tab registration failed: ' + messageOf(failure))
|
||||
}
|
||||
}
|
||||
|
||||
export const name = 'dsh-brain'
|
||||
|
|
|
|||
|
|
@ -13,15 +13,12 @@ const TABS = [
|
|||
{ id: 'departments', label: '部门' },
|
||||
] as const
|
||||
|
||||
export function BrainPanel(props: { panelId?: string; usePanelInfo?: any }): any {
|
||||
export function BrainPanel(): any {
|
||||
const [tab, setTab] = React.useState('overview')
|
||||
const panelId = props.panelId ?? 'dsh-brain'
|
||||
const usePanelInfo = props.usePanelInfo
|
||||
const active = usePanelInfo === undefined ? true : usePanelInfo((info: { activePanelId: string | null }) => info.activePanelId === panelId)
|
||||
let content: any
|
||||
if (tab === 'overview') content = h(Overview, { active })
|
||||
else if (tab === 'memory') content = h(MemoryTab, { scope: 'global', active })
|
||||
else content = h(DepartmentTab, { scope: 'global', active })
|
||||
if (tab === 'overview') content = h(Overview)
|
||||
else if (tab === 'memory') content = h(MemoryTab, { scope: 'global' })
|
||||
else content = h(DepartmentTab, { scope: 'global' })
|
||||
return h('div', { className: styles.nativeWorkspace, 'data-dsh-plugin': 'dsh-brain', 'data-dsh-part': 'brain-panel' },
|
||||
h('div', { className: styles.windowDragBand, 'data-window-drag': true, 'aria-hidden': 'true' }),
|
||||
h('div', { className: styles.panelInner },
|
||||
|
|
|
|||
|
|
@ -11,42 +11,14 @@ import { BrainPanel } from './BrainPanel'
|
|||
export const PANEL_ID = 'dsh-brain'
|
||||
export const PANEL_ORDER = 30
|
||||
|
||||
interface LayoutPanelInfo {
|
||||
getSnapshot(): { activePanelId: string | null }
|
||||
subscribe(listener: () => void): () => void
|
||||
}
|
||||
|
||||
export interface BrainPanelSeatFace {
|
||||
panelId: string
|
||||
ctx: any
|
||||
usePanelInfo?: <T>(selector: (info: { activePanelId: string | null }) => T) => T
|
||||
}
|
||||
|
||||
function makeUsePanelInfo(ctx: any, panelId: string): (<T>(selector: (info: { activePanelId: string | null }) => T) => T) {
|
||||
return function usePanelInfo<T>(selector: (info: { activePanelId: string | null }) => T): T {
|
||||
const panelInfo = ctx?.layout?.panelInfo as LayoutPanelInfo | undefined
|
||||
const read = (): T => selector(panelInfo === undefined ? { activePanelId: panelId } : panelInfo.getSnapshot())
|
||||
const [value, setValue] = React.useState<T>(read)
|
||||
React.useEffect(() => {
|
||||
if (panelInfo === undefined) return
|
||||
const update = (): void => setValue(read())
|
||||
update()
|
||||
return panelInfo.subscribe(update)
|
||||
}, [panelInfo, panelId])
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
export function registerBrainPanel(ctx: any): () => void {
|
||||
let stopNative: (() => void) | undefined
|
||||
let disposed = false
|
||||
try {
|
||||
stopNative = ctx.slots.inject('main', () =>
|
||||
ctx.slots.inject('sidebar.panellist', () => {
|
||||
const usePanelInfo = makeUsePanelInfo(ctx, PANEL_ID)
|
||||
const panel = (props: any) => React.createElement(BrainPanel, { ...props, panelId: PANEL_ID, usePanelInfo })
|
||||
const icon = (props: any) => React.createElement(BrainIcon, { size: props?.size ?? 18 })
|
||||
const stopMain = ctx.slots.register({ name: 'main', key: PANEL_ID, inject: () => ({ panelId: PANEL_ID }) }, panel as never)
|
||||
const stopMain = ctx.slots.register({ name: 'main', key: PANEL_ID }, BrainPanel as never)
|
||||
let stopIcon: (() => void) | undefined
|
||||
try {
|
||||
stopIcon = ctx.slots.register({
|
||||
|
|
|
|||
|
|
@ -353,6 +353,7 @@ const localStorageStub = {
|
|||
}
|
||||
|
||||
let registered = null
|
||||
let mainPanel = null
|
||||
globalThis.window = {
|
||||
localStorage: localStorageStub,
|
||||
addEventListener: () => {},
|
||||
|
|
@ -363,11 +364,13 @@ globalThis.window = {
|
|||
const exportsObject = spec.factory(requireShim)
|
||||
const captured = []
|
||||
exportsObject.apply({
|
||||
get layout() { throw new Error('cannot get property "layout" without inject') },
|
||||
slots: {
|
||||
inject(_seat, fn) {
|
||||
return fn()
|
||||
},
|
||||
register(_options, component) {
|
||||
register(options, component) {
|
||||
if (options.name === 'main' && options.key === 'dsh-brain') mainPanel = component
|
||||
captured.push(component)
|
||||
return () => {}
|
||||
},
|
||||
|
|
@ -417,6 +420,15 @@ function loadBundle() {
|
|||
return registered
|
||||
}
|
||||
|
||||
loadBundle()
|
||||
const panelText = render(React.createElement(mainPanel))
|
||||
check('the main slot renders the Brain overview without accessing the layout service',
|
||||
panelText.includes('概览') && panelText.includes('版本与构建') && panelText.includes('部门'))
|
||||
hooks = []
|
||||
cursor = 0
|
||||
pendingEffects = []
|
||||
|
||||
|
||||
async function drive(tab, bridgeAvailable, clickAfter, clickOccurrence) {
|
||||
activeTab = tab
|
||||
mcpAvailable = bridgeAvailable
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ check('client bundle uses the __ModuleLoader__ contract', bundle.includes('__Mod
|
|||
check('client bundle id stays dsh-brain', /id:\s*['"]dsh-brain['"]/.test(bundle))
|
||||
const cssModuleIds = [...bundle.matchAll(/^\s*\/\/ \S*?dsh-brain-css:(\S+)$/gm)].map((match) => match[1])
|
||||
check('client CSS module comments use portable repository paths',
|
||||
cssModuleIds.length === 2 && cssModuleIds.every((id) => /^src-client\/.*\.module\.css\.mjs$/.test(id)))
|
||||
cssModuleIds.length === 1 && cssModuleIds.every((id) => /^src-client\/.*\.module\.css\.mjs$/.test(id)))
|
||||
for (const seat of ['settings.section', 'plugins.bundle.config', 'sidebar.panellist']) {
|
||||
check('client bundle registers ' + seat, bundle.includes(seat))
|
||||
}
|
||||
|
|
@ -34,8 +34,7 @@ for (const label of ['连接与上报', '技能管理', 'MCP 管理', '概览',
|
|||
check('client bundle keeps tab label ' + label, bundle.includes(label))
|
||||
}
|
||||
check('client bundle keeps the panel semantic anchor', bundle.includes('data-dsh-panel-entry') && bundle.includes('data-dsh-plugin'))
|
||||
check('client bundle registers the better-sidebar tab surface', bundle.includes('dsh-brain:memory') && bundle.includes('registerTab') && bundle.includes('internal/service'))
|
||||
check('better-sidebar view keeps a visible pause branch', bundle.includes('visible') && bundle.includes('项目记忆'))
|
||||
check('Brain does not bundle a replacement for the Mnemon right tab', !bundle.includes('dsh-brain:memory'))
|
||||
for (const apiPath of ['/dsh-brain/local-memory/status', '/dsh-brain/local-memory/memories', '/dsh-brain/local-memory/documents', '/dsh-brain/local-memory/forget', '/dsh-brain/departments/list', '/dsh-brain/departments/create', '/dsh-brain/departments/update', '/dsh-brain/departments/disable', '/dsh-brain/departments/checkpoint', '/dsh-brain/departments/recall']) {
|
||||
check('client bundle consumes ' + apiPath, bundle.includes(apiPath))
|
||||
}
|
||||
|
|
@ -111,7 +110,7 @@ check('apply registers settings + panel seats', ['settings.section', 'plugins.bu
|
|||
const bySeat = Object.fromEntries(current.registrations.map((entry) => [entry.seat, entry]))
|
||||
check('settings.section keeps its id/order/label', JSON.stringify(shapeOf(bySeat['settings.section'])) === JSON.stringify({ seat: 'settings.section', name: 'settings.section', id: 'dsh-brain', key: undefined, order: 100, label: '云端记忆', inject: undefined }))
|
||||
check('plugins.bundle.config keeps its key', JSON.stringify(shapeOf(bySeat['plugins.bundle.config'])) === JSON.stringify({ seat: 'plugins.bundle.config', name: 'plugins.bundle.config', id: undefined, key: 'dsh-brain', order: undefined, label: undefined, inject: undefined }))
|
||||
check('main panel uses the dsh-brain panel key', bySeat['main'] !== undefined && bySeat['main'].options.key === 'dsh-brain' && typeof bySeat['main'].options.inject === 'function')
|
||||
check('main panel uses the dsh-brain panel key', bySeat['main'] !== undefined && bySeat['main'].options.key === 'dsh-brain')
|
||||
check('sidebar panellist row uses id dsh-brain at order 30 with Brain label', bySeat['sidebar.panellist'] !== undefined && bySeat['sidebar.panellist'].options.id === 'dsh-brain' && bySeat['sidebar.panellist'].options.order === 30 && bySeat['sidebar.panellist'].options.label() === 'Brain')
|
||||
check('module exports name dsh-brain', current.name === 'dsh-brain' && Array.isArray(current.inject) && current.inject.includes('slots'))
|
||||
|
||||
|
|
@ -136,27 +135,6 @@ try {
|
|||
} catch { rejectThrew = true }
|
||||
check('rejecting panel seats degrade without throwing', !rejectThrew)
|
||||
|
||||
let sidebarDescriptor = null
|
||||
let sidebarListener = null
|
||||
let currentService = undefined
|
||||
let sidebarThrew = false
|
||||
try {
|
||||
const mod = loadBundle('client/index.js')
|
||||
const service = { registerTab(descriptor) { sidebarDescriptor = descriptor; return () => {} } }
|
||||
mod.apply({
|
||||
slots: { inject(seat, callback) { callback() }, register() { return () => {} } },
|
||||
get(name) { return name === 'betterSidebar' ? currentService : undefined },
|
||||
on(name, listener) { if (name === 'internal/service') sidebarListener = listener; return () => {} },
|
||||
effect(setup) { if (typeof setup === 'function') setup() },
|
||||
})
|
||||
if (sidebarDescriptor !== null) throw new Error('tab must not register without a service')
|
||||
currentService = service
|
||||
sidebarListener('betterSidebar')
|
||||
} catch { sidebarThrew = true }
|
||||
check('better-sidebar tab is absent without the service', !sidebarThrew && sidebarDescriptor !== null)
|
||||
check('better-sidebar tab registers with the expected descriptor', sidebarDescriptor !== null && sidebarDescriptor.id === 'dsh-brain:memory' && sidebarDescriptor.order === 60 && sidebarDescriptor.single === true && typeof sidebarDescriptor.title === 'function' && sidebarDescriptor.title() === '项目记忆' && typeof sidebarDescriptor.description === 'string' && sidebarDescriptor.description.includes('项目'))
|
||||
check('better-sidebar tab hot-plugs through internal/service', sidebarListener !== null && typeof sidebarListener === 'function')
|
||||
|
||||
const legacyFile = new URL('./artifacts/analysis/client-legacy.js', import.meta.url)
|
||||
if (existsSync(legacyFile)) {
|
||||
const legacy = exercise(legacyFile)
|
||||
|
|
@ -166,15 +144,11 @@ if (existsSync(legacyFile)) {
|
|||
console.log('SKIP legacy comparison (artifacts/analysis/client-legacy.js missing)')
|
||||
}
|
||||
|
||||
// Each surface must pass an explicit scope to both management tabs.
|
||||
// The global panel must pass an explicit scope to both management tabs.
|
||||
const layout = readFileSync(new URL('./src-client/panel/BrainPanel.tsx', import.meta.url), 'utf8')
|
||||
const sidebar = readFileSync(new URL('./src-client/sidebar/ProjectMemoryView.tsx', import.meta.url), 'utf8')
|
||||
const patch = readFileSync(new URL('./cordis.patch.yml', import.meta.url), 'utf8')
|
||||
check('global panel binds both tabs to global data',
|
||||
layout.includes("h(MemoryTab, { scope: 'global', active })") && layout.includes("h(DepartmentTab, { scope: 'global', active })"))
|
||||
check('project tab waits for its workspace and scopes both tabs to it',
|
||||
sidebar.includes("postJson('/sidebar/api/session.cwd', { sessionId })") && sidebar.includes('value?.sessionId !== sessionId') &&
|
||||
sidebar.includes('workspace === undefined ?') && sidebar.includes("h(MemoryTab, { scope: 'project', workspace,") && sidebar.includes("h(DepartmentTab, { scope: 'project', workspace,"))
|
||||
layout.includes("h(MemoryTab, { scope: 'global' })") && layout.includes("h(DepartmentTab, { scope: 'global' })"))
|
||||
check('the UI loader row mounts at the package root for browser discovery',
|
||||
/id: dsh-brain-ui\r?\n(?: *#[^\r\n]*\r?\n)* *name: dsh-brain\r?\n *config:\r?\n *entry: ui(?:\r?\n|$)/.test(patch))
|
||||
check('settings section mounts the full plugin config form',
|
||||
|
|
|
|||
Loading…
Reference in New Issue