feat(ui): memory and department tabs in the Brain panel

This commit is contained in:
newbie 2026-11-25 10:41:24 +08:00
parent 891b19f809
commit 0b655385af
8 changed files with 1368 additions and 332 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,8 @@
// Brain total panel: the shell-rendered centre page of the dsh-brain bundle.
import * as React from 'react'
import { Overview } from './Overview'
import { MemoryTab } from './MemoryTab'
import { DepartmentTab } from './DepartmentTab'
import { SettingsCard } from '../SettingsCard'
import styles from './BrainPanel.module.css'
@ -30,8 +32,8 @@ export function BrainPanel(props: { ctx?: any; panelId?: string; usePanelInfo?:
let content: any
if (tab === 'overview') content = h(Overview, { active })
else if (tab === 'connection') content = h(SettingsCard, null)
else if (tab === 'memory') content = h(Placeholder, { title: '记忆' })
else if (tab === 'departments') content = h(Placeholder, { title: '部门' })
else if (tab === 'memory') content = h(MemoryTab, { ctx: props.ctx, active })
else if (tab === 'departments') content = h(DepartmentTab, { ctx: props.ctx, active })
else if (tab === 'skills') content = h(Placeholder, { title: '技能' })
else content = h(Placeholder, { title: 'MCP' })
return h('div', { className: styles.nativeWorkspace, 'data-dsh-plugin': 'dsh-brain', 'data-dsh-part': 'brain-panel' },

View File

@ -0,0 +1,199 @@
// Department tab: list, create, detail (update/disable/checkpoint), recall.
import * as React from 'react'
import { request, postJson, bodyError, messageOf } from '../api'
import { formatIso } from '../format'
import { styles } from '../styles'
import { Banner, Btn, Field, Pill, Section } from '../components'
import { useApi } from './useApi'
import { resolveWorkspace, workspaceQuery } from './workspace'
const h = React.createElement
const EMPTY_CREATE = { name: '', role: '', scope: 'project', skills: '', allowedTools: '', readGlobal: true, readProject: true }
const ENDPOINTS = {
list: '/dsh-brain/departments/list',
create: '/dsh-brain/departments/create',
update: '/dsh-brain/departments/update',
disable: '/dsh-brain/departments/disable',
checkpoint: '/dsh-brain/departments/checkpoint',
recall: '/dsh-brain/departments/recall',
} as const
export function DepartmentTab(props: { ctx?: any; active?: boolean }): any {
const active = props.active !== false
const workspace = resolveWorkspace(props.ctx)
const [notice, setNotice] = React.useState<any>(null)
const [busy, setBusy] = React.useState('')
const [form, setForm] = React.useState<any>({ ...EMPTY_CREATE })
const [selectedId, setSelectedId] = React.useState('')
const [detail, setDetail] = React.useState<any>({ role: '', currentTask: '', handoff: '' })
const [recallId, setRecallId] = React.useState('')
const [recallQuery, setRecallQuery] = React.useState('')
const [recallK, setRecallK] = React.useState('5')
const [recallHits, setRecallHits] = React.useState<any[]>([])
const [recallBusy, setRecallBusy] = React.useState(false)
const list = useApi(async () => {
const result = await request(ENDPOINTS.list + workspaceQuery(workspace))
if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(bodyError(result, '读取部门列表失败'))
return result.body
}, { visible: active, pollMs: 15000 })
const departments: any[] = Array.isArray(list.data?.departments) ? list.data!.departments : []
const selected = departments.filter((item) => item.id === selectedId)[0]
React.useEffect(() => {
if (selected !== undefined) {
setDetail({ role: selected.role ?? '', currentTask: selected.currentTask ?? '', handoff: selected.handoff ?? '' })
}
}, [selectedId, list.data])
const handleFailure = (result: any, fallback: string): boolean => {
if (result.status === 409) {
setNotice({ tone: 'warn', text: '数据已变化,请刷新' })
list.reload()
return false
}
setNotice({ tone: 'bad', text: bodyError(result, fallback) })
return false
}
const create = async (): Promise<void> => {
if (String(form.name).trim() === '') { setNotice({ tone: 'warn', text: '请填写部门名称。' }); return }
setBusy('create')
try {
const result = await postJson(ENDPOINTS.create, {
name: String(form.name).trim(),
role: String(form.role).trim() || undefined,
scope: form.scope,
skills: String(form.skills).split(/[,,\s]+/).filter((value) => value !== ''),
allowedTools: String(form.allowedTools).split(/[,,\s]+/).filter((value) => value !== ''),
readGlobal: form.readGlobal === true,
readProject: form.readProject === true,
workspace,
})
if (result.status !== 200 || result.body === null || result.body.ok !== true) { handleFailure(result, '创建部门失败'); return }
setNotice({ tone: 'ok', text: result.body.created === false ? '同名部门已存在,已复用。' : '部门已创建。' })
setForm({ ...EMPTY_CREATE })
list.reload()
} catch (failure) {
setNotice({ tone: 'bad', text: messageOf(failure) })
} finally {
setBusy('')
}
}
const mutate = async (action: 'update' | 'disable' | 'checkpoint'): Promise<void> => {
if (selected === undefined) return
setBusy(action)
const payload: any = { id: selected.id, expectedRevision: selected.revision, workspace }
if (action === 'update') { payload.role = detail.role; payload.name = selected.name }
if (action === 'checkpoint') { payload.currentTask = detail.currentTask; payload.handoff = detail.handoff }
try {
const result = await postJson(action === 'update' ? ENDPOINTS.update : action === 'disable' ? ENDPOINTS.disable : ENDPOINTS.checkpoint, payload)
if (result.status !== 200 || result.body === null || result.body.ok !== true) { handleFailure(result, '操作失败'); return }
setNotice({ tone: 'ok', text: action === 'update' ? '部门已更新。' : action === 'checkpoint' ? '检查点已保存。' : '部门已停用。' })
list.reload()
} catch (failure) {
setNotice({ tone: 'bad', text: messageOf(failure) })
} finally {
setBusy('')
}
}
const recall = async (): Promise<void> => {
if (recallId === '') { setNotice({ tone: 'warn', text: '请选择要召回的部门。' }); return }
setRecallBusy(true)
setRecallHits([])
try {
const query = ENDPOINTS.recall + '?id=' + encodeURIComponent(recallId) + '&query=' + encodeURIComponent(recallQuery) + '&k=' + encodeURIComponent(recallK) + (workspace === undefined ? '' : '&workspace=' + encodeURIComponent(workspace))
const result = await request(query)
if (result.status !== 200 || result.body === null || result.body.ok !== true) { handleFailure(result, '召回失败'); return }
setRecallHits(Array.isArray(result.body.hits) ? result.body.hits : [])
} catch (failure) {
setNotice({ tone: 'bad', text: messageOf(failure) })
} finally {
setRecallBusy(false)
}
}
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
notice === null ? null : h(Banner, { tone: notice.tone }, notice.text),
list.error === null ? null : h(Banner, { tone: 'bad' }, list.error),
h(Section, { title: '部门列表', hint: '部门是本机可复用的工作身份;列表显示 scope、状态、当前任务与 revision。', aside: h(Btn, { label: '刷新', variant: 'small', onClick: () => list.reload() }) },
departments.length === 0 ? h('p', { style: styles.hint }, '还没有部门。可在下方创建。') : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
departments.map((item) => h('div', { key: item.id, style: styles.row },
h('div', { style: styles.rowHead },
h('span', { style: styles.rowTitle }, String(item.name) + '(' + String(item.scope) + ')'),
h('div', { style: styles.pills },
h(Pill, { label: '状态', value: item.active === true ? '启用' : '停用', tone: item.active === true ? 'ok' : 'bad' }),
h(Pill, { label: 'rev', value: item.revision ?? '—', tone: 'muted' }),
),
),
h('p', { style: styles.hint }, '当前任务:' + String(item.currentTask ?? '—') + (item.handoff === undefined ? '' : ' · 交接:' + String(item.handoff))),
h('div', { style: styles.actions },
h(Btn, { label: selectedId === item.id ? '收起详情' : '详情 / 编辑', variant: 'small', onClick: () => setSelectedId(selectedId === item.id ? '' : item.id) }),
h(Btn, { label: '设为召回对象', variant: 'small', onClick: () => setRecallId(item.id) }),
),
selectedId === item.id ? h('div', { style: styles.nested },
h('div', { style: styles.grid },
h(Field, { label: '角色', value: detail.role, onChange: (value) => setDetail({ ...detail, role: value }) }),
h(Field, { label: '当前任务', value: detail.currentTask, onChange: (value) => setDetail({ ...detail, currentTask: value }) }),
h(Field, { label: '交接说明', value: detail.handoff, onChange: (value) => setDetail({ ...detail, handoff: value }) }),
),
h('div', { style: styles.actions },
h(Btn, { variant: 'primary', label: busy === 'update' ? '保存中…' : '保存角色', disabled: busy !== '', onClick: () => { void mutate('update') } }),
h(Btn, { label: busy === 'checkpoint' ? '保存中…' : '保存检查点', disabled: busy !== '', onClick: () => { void mutate('checkpoint') } }),
h(Btn, { variant: 'danger', label: busy === 'disable' ? '停用中…' : '停用部门', disabled: busy !== '' || item.active !== true, onClick: () => { void mutate('disable') } }),
),
h('p', { style: styles.hint }, '创建于 ' + formatIso(item.createdAt) + ' · 更新于 ' + formatIso(item.updatedAt)),
) : null,
)),
),
),
h(Section, { title: '创建部门', hint: '同名部门会幂等复用,不会覆盖原角色。' },
h('div', { style: styles.grid },
h(Field, { label: '名称', value: form.name, onChange: (value) => setForm({ ...form, name: value }) }),
h(Field, { label: '角色', value: form.role, onChange: (value) => setForm({ ...form, role: value }) }),
h('div', { style: styles.field },
h('span', { style: styles.label }, '范围'),
h('select', { value: form.scope, style: styles.input, onChange: (event) => setForm({ ...form, scope: event.target.value }) },
h('option', { value: 'project' }, '项目'),
h('option', { value: 'global' }, '全局'),
),
),
h(Field, { label: '技能(逗号分隔)', value: form.skills, onChange: (value) => setForm({ ...form, skills: value }) }),
h(Field, { label: '允许工具(逗号分隔)', value: form.allowedTools, onChange: (value) => setForm({ ...form, allowedTools: value }) }),
),
h('div', { style: styles.checkboxRow },
h('label', null, h('input', { type: 'checkbox', checked: form.readGlobal === true, onChange: (event) => setForm({ ...form, readGlobal: event.target.checked }) }), ' 可读全局记忆'),
h('label', null, h('input', { type: 'checkbox', checked: form.readProject === true, onChange: (event) => setForm({ ...form, readProject: event.target.checked }) }), ' 可读项目记忆'),
),
h('div', { style: styles.actions }, h(Btn, { variant: 'primary', label: busy === 'create' ? '创建中…' : '创建部门', disabled: busy !== '', onClick: () => { void create() } })),
),
h(Section, { title: '部门召回', hint: '召回结果只展示服务端截断后的 contentSnippet(≤600 字符),并标注来源。' },
h('div', { style: styles.grid },
h('div', { style: styles.field },
h('span', { style: styles.label }, '部门'),
h('select', { value: recallId, style: styles.input, onChange: (event) => setRecallId(event.target.value) },
h('option', { value: '' }, '选择部门…'),
departments.map((item) => h('option', { key: item.id, value: item.id }, String(item.name))),
),
),
h(Field, { label: '查询', value: recallQuery, onChange: setRecallQuery }),
h(Field, { label: '数量(1-5)', type: 'number', value: recallK, onChange: setRecallK }),
),
h('div', { style: styles.actions }, h(Btn, { label: recallBusy ? '召回中…' : '查询召回', disabled: recallBusy, onClick: () => { void recall() } })),
recallHits.length === 0 ? h('p', { style: styles.hint }, '暂无召回结果。') : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
recallHits.map((hit: any, index: number) => h('div', { key: String(index), style: styles.row },
h('div', { style: styles.rowHead }, h('div', { style: styles.pills },
h(Pill, { label: '来源', value: hit.origin ?? '—', tone: 'muted' }),
hit.record?.category === undefined ? null : h(Pill, { label: '分类', value: hit.record.category, tone: 'muted' }),
)),
h('div', { style: styles.clamp2 }, String(hit.contentSnippet ?? hit.content ?? '')),
)),
),
),
)
}

View File

@ -0,0 +1,137 @@
// Memory tab: local-memory spaces, paged memory list, read-only documents, forget.
import * as React from 'react'
import { API, request, postJson, bodyError, messageOf } from '../api'
import { formatIso, formatTime } from '../format'
import { styles } from '../styles'
import { Banner, Btn, Field, Pill, Section } from '../components'
import { useApi } from './useApi'
const h = React.createElement
const PAGE_SIZE = 50
function workspaceSuffix(workspace: string | undefined): string {
return workspace === undefined ? '' : '&workspace=' + encodeURIComponent(workspace)
}
export function MemoryTab(props: { ctx?: any; active?: boolean }): any {
const active = props.active !== false
const [offset, setOffset] = React.useState(0)
const [search, setSearch] = React.useState('')
const [notice, setNotice] = React.useState<any>(null)
const [pendingForget, setPendingForget] = React.useState<any>(null)
const [busy, setBusy] = React.useState('')
const status = useApi(async () => {
const result = await request('/dsh-brain/local-memory/status')
if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(bodyError(result, '读取本地记忆状态失败'))
return result.body
}, { visible: active, pollMs: 15000 })
const memories = useApi(async () => {
const result = await request('/dsh-brain/local-memory/memories?limit=' + String(PAGE_SIZE) + '&offset=' + String(offset))
if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(bodyError(result, '读取记忆列表失败'))
return result.body
}, { visible: active, deps: [offset] })
const documents = useApi(async () => {
const result = await request('/dsh-brain/local-memory/documents')
if (result.status !== 200 || result.body === null || result.body.ok !== true) throw new Error(bodyError(result, '读取文档列表失败'))
return result.body
}, { visible: active })
const items: any[] = Array.isArray(memories.data?.items) ? memories.data!.items : []
const needle = String(search).trim().toLowerCase()
const filtered = needle === '' ? items : items.filter((item) => {
const hay = [item.content, item.category, item.scope, ...(Array.isArray(item.tags) ? item.tags : [])].join(' ').toLowerCase()
return hay.indexOf(needle) >= 0
})
const total = memories.data?.total ?? 0
const forget = async (item: any): Promise<void> => {
setBusy(item.id)
try {
const result = await postJson('/dsh-brain/local-memory/forget', { id: item.id, expectedRevision: item.revision })
if (result.status !== 200 || result.body === null || result.body.ok !== true) {
setNotice({ tone: 'bad', text: bodyError(result, '删除失败') })
} else {
setNotice({ tone: 'ok', text: '已删除记忆条目。' })
setPendingForget(null)
memories.reload()
}
} catch (failure) {
setNotice({ tone: 'bad', text: messageOf(failure) })
} finally {
setBusy('')
}
}
const spaces = status.data?.spaces ?? {}
const globalSpace = spaces.global
const projectSpace = spaces.project
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px' } },
status.error === null ? null : h(Banner, { tone: 'bad' }, status.error),
h(Section, { title: '本地记忆空间', hint: '全局空间与当前项目空间都由本机文件保存;云同步只影响上报,不改变本地存储。', aside: h(Btn, { label: '刷新', variant: 'small', onClick: () => { status.reload(); memories.reload(); documents.reload() } }) },
h('div', { style: styles.pills },
h(Pill, { label: 'provider', value: status.data?.provider ?? '—', tone: 'muted' }),
h(Pill, { label: '全局空间', value: globalSpace === null || globalSpace === undefined ? '未创建' : (globalSpace.name ?? globalSpace.id ?? '就绪'), tone: globalSpace === null || globalSpace === undefined ? 'muted' : 'ok' }),
h(Pill, { label: '项目空间', value: projectSpace === null || projectSpace === undefined ? '未创建' : (projectSpace.name ?? projectSpace.id ?? '就绪'), tone: projectSpace === null || projectSpace === undefined ? 'muted' : 'ok' }),
h(Pill, { label: '本地记忆', value: status.data?.localMemoryEnabled === false ? '关' : '开', tone: status.data?.localMemoryEnabled === false ? 'bad' : 'ok' }),
h(Pill, { label: '云同步', value: status.data?.cloudSyncEnabled === true ? '开' : '关', tone: status.data?.cloudSyncEnabled === true ? 'ok' : 'muted' }),
),
status.data?.globalRoot === undefined ? null : h('p', { style: styles.hint }, '全局:' + String(status.data.globalRoot) + (status.data?.projectRoot === undefined ? '' : ' · 项目:' + String(status.data.projectRoot))),
),
h(Section, { title: '记忆条目(' + String(total) + ')', hint: '只显示当前页;搜索只在当前页内过滤。删除需要二次确认并带 revision 校验。', aside: h('div', { style: styles.actions },
h(Field, { label: '搜索当前页', value: search, onChange: setSearch }),
h(Btn, { label: '刷新', variant: 'small', onClick: () => memories.reload() }),
) },
notice === null ? null : h(Banner, { tone: notice.tone }, notice.text),
memories.error === null ? null : h(Banner, { tone: 'bad' }, memories.error),
memories.status === 'loading' && items.length === 0 ? h('p', { style: styles.hint }, '正在读取记忆…') : null,
filtered.length === 0 ? h('p', { style: styles.hint }, '当前页没有匹配的记忆条目。') : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
filtered.map((item) => h('div', { key: item.id, style: styles.row },
h('div', { style: styles.rowHead },
h('div', { style: styles.pills },
h(Pill, { label: 'scope', value: item.scope ?? '—', tone: 'muted' }),
item.category === undefined ? null : h(Pill, { label: '分类', value: item.category, tone: 'muted' }),
h(Pill, { label: 'rev', value: item.revision ?? '—', tone: 'muted' }),
h(Pill, { label: '更新', value: formatIso(item.updatedAt), tone: 'muted' }),
),
h('div', { style: styles.actions },
pendingForget === item.id ? null : h(Btn, { label: '删除…', variant: 'small', onClick: () => { setPendingForget(item.id); setNotice(null) } }),
),
),
h('div', { style: styles.clamp2 }, String(item.content ?? '')),
Array.isArray(item.tags) && item.tags.length > 0 ? h('p', { style: styles.hint }, '标签:' + item.tags.join('、')) : null,
pendingForget === item.id ? h('div', { style: styles.nested },
h('p', { style: styles.hint }, '确认删除这条记忆?此操作不可撤销。'),
h('div', { style: styles.actions },
h(Btn, { variant: 'danger', label: busy === item.id ? '删除中…' : '确认删除', disabled: busy !== '', onClick: () => { void forget(item) } }),
h(Btn, { variant: 'small', label: '取消', disabled: busy !== '', onClick: () => setPendingForget(null) }),
),
) : null,
)),
),
h('div', { style: styles.actions },
h(Btn, { label: '上一页', variant: 'small', disabled: offset === 0 || memories.status === 'loading', onClick: () => setOffset(Math.max(0, offset - PAGE_SIZE)) }),
h('span', { style: styles.hint }, '第 ' + String(Math.floor(offset / PAGE_SIZE) + 1) + ' 页 · 共 ' + String(total) + ' 条'),
h(Btn, { label: '下一页', variant: 'small', disabled: offset + PAGE_SIZE >= total || memories.status === 'loading', onClick: () => setOffset(offset + PAGE_SIZE) }),
),
),
h(Section, { title: '文档(只读)', hint: '项目文档由本地记忆库维护;这里只展示标题与摘要。' },
documents.error === null ? null : h(Banner, { tone: 'bad' }, documents.error),
(documents.data?.documents ?? []).length === 0 ? h('p', { style: styles.hint }, '当前项目还没有文档。') : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '8px' } },
(documents.data?.documents ?? []).map((doc: any) => h('div', { key: doc.id, style: styles.row },
h('div', { style: styles.rowHead },
h('span', { style: styles.rowTitle }, String(doc.title ?? doc.id)),
h('div', { style: styles.pills },
h(Pill, { label: 'rev', value: doc.revision ?? '—', tone: 'muted' }),
h(Pill, { label: '更新', value: formatIso(doc.updatedAt), tone: 'muted' }),
),
),
h('div', { style: styles.clamp2 }, String(doc.content ?? '')),
)),
),
),
)
}

View File

@ -96,8 +96,8 @@ export function Overview(props: { active?: boolean }): any {
h(Card, { title: '本地记忆' },
h('div', { className: styles.pills },
h(Pill, { label: '状态', value: memory === null ? '不可用' : '已启用', tone: memory === null ? 'warn' : 'ok' }),
h(Pill, { label: '全局空间', value: memorySpaces.global === undefined ? '—' : (memorySpaces.global.exists === false ? '未创建' : '就绪'), tone: memorySpaces.global?.exists === false ? 'muted' : 'ok' }),
h(Pill, { label: '项目空间', value: memorySpaces.project === undefined ? '—' : (memorySpaces.project.exists === false ? '未创建' : '就绪'), tone: memorySpaces.project?.exists === false ? 'muted' : 'ok' }),
h(Pill, { label: '全局空间', value: memorySpaces.global === null || memorySpaces.global === undefined ? '未创建' : '就绪', tone: memorySpaces.global === null || memorySpaces.global === undefined ? 'muted' : 'ok' }),
h(Pill, { label: '项目空间', value: memorySpaces.project === null || memorySpaces.project === undefined ? '未创建' : '就绪', tone: memorySpaces.project === null || memorySpaces.project === undefined ? 'muted' : 'ok' }),
h(Pill, { label: '云同步', value: memory?.cloudSyncEnabled === true ? '开' : '关', tone: memory?.cloudSyncEnabled === true ? 'ok' : 'muted' }),
),
memory === null ? h('p', { className: styles.hint }, '本地记忆状态路由不可用;启用「本地记忆」后此处会显示空间状态。') : null,

View File

@ -0,0 +1,52 @@
// Small data-loading state machine shared by the Brain panel tabs.
import * as React from 'react'
import { messageOf } from '../api'
export type ApiStatus = 'idle' | 'loading' | 'ready' | 'error'
export interface ApiState<T> {
status: ApiStatus
data: T | null
error: string | null
}
export interface UseApiOptions {
/** false pauses all loading and polling (used by better-sidebar visible=false). */
visible?: boolean
/** Optional polling interval in milliseconds. */
pollMs?: number
/** Extra dependencies that should trigger a reload. */
deps?: unknown[]
}
export function useApi<T>(loader: () => Promise<T>, options: UseApiOptions = {}): ApiState<T> & { reload: () => void; mutate: (data: T | null) => void } {
const visible = options.visible !== false
const loaderRef = React.useRef(loader)
loaderRef.current = loader
const [state, setState] = React.useState<ApiState<T>>({ status: 'idle', data: null, error: null })
const reload = React.useCallback((): void => {
if (!visible) return
setState((previous) => ({ status: previous.data === null ? 'loading' : 'ready', data: previous.data, error: null }))
loaderRef.current().then(
(data) => setState({ status: 'ready', data, error: null }),
(failure) => setState((previous) => ({ status: 'error', data: previous.data, error: messageOf(failure) })),
)
}, [visible])
const dependencies = options.deps ?? []
React.useEffect(() => {
if (!visible) return
reload()
if (options.pollMs === undefined) return
const timer = setInterval(reload, options.pollMs)
return () => clearInterval(timer)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [visible, options.pollMs, reload, ...dependencies])
return {
...state,
reload,
mutate: (data: T | null) => setState({ status: data === null ? 'idle' : 'ready', data, error: null }),
}
}

View File

@ -0,0 +1,26 @@
// Resolve the active session workspace from the optional host sessions face.
// The probe is deliberately defensive: the panel must work without the service.
export function resolveWorkspace(ctx: any): string | undefined {
try {
const sessions = ctx !== undefined && ctx !== null && typeof ctx.get === 'function' ? ctx.get('sessions') : undefined
if (sessions === undefined || sessions === null) return undefined
const current = typeof sessions.current === 'function' ? sessions.current() : sessions.current
const candidates = [
current?.cwd,
current?.header?.cwd,
current?.session?.cwd,
current?.session?.header?.cwd,
typeof sessions.cwd === 'function' ? sessions.cwd() : undefined,
]
for (const candidate of candidates) {
if (typeof candidate === 'string' && candidate.trim() !== '') return candidate
}
} catch {
/* no sessions face -> omit the workspace argument */
}
return undefined
}
export function workspaceQuery(workspace: string | undefined): string {
return workspace === undefined ? '' : '?workspace=' + encodeURIComponent(workspace)
}

View File

@ -26,6 +26,12 @@ 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'))
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))
}
for (const label of ['记忆条目', '部门列表', '部门召回', '数据已变化,请刷新']) {
check('client bundle keeps U2 surface ' + label, bundle.includes(label))
}
check('client bundle is a single file with only react externals', (() => {
const requires = [...bundle.matchAll(/require\(\s*['"]([^'"]+)['"]\s*\)/g)].map((match) => match[1])
return requires.every((name) => name === 'react' || name === 'react/jsx-runtime')