fix(workbench): 修复右栏切换隐藏并完善自动刷新

This commit is contained in:
qyh15 2026-11-21 16:48:32 +08:00
parent ac98a40942
commit 16da0b1568
5 changed files with 293 additions and 54 deletions

View File

@ -554,6 +554,8 @@ var ChatIcon = () => fileIcon(["M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2
var PlusIcon = () => fileIcon(["M12 5v14", "M5 12h14"]);
var SearchIcon = () => (0, import_react.createElement)("svg", { viewBox: "0 0 24 24", width: 15, height: 15, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true" }, (0, import_react.createElement)("circle", { cx: 11, cy: 11, r: 8 }), (0, import_react.createElement)("path", { d: "m21 21-4.3-4.3" }));
var ArrowIcon = () => fileIcon(["m9 18 6-6-6-6"], 15);
var BookIcon = () => fileIcon(["M4 19.5A2.5 2.5 0 0 1 6.5 17H20", "M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"], 15);
var SlidersIcon = () => fileIcon(["M4 21v-7", "M4 10V3", "M12 21v-9", "M12 8V3", "M20 21v-5", "M20 12V3", "M2 14h4", "M10 8h4", "M18 16h4"], 15);
function seatKind(id) {
if (id === "lead") return "总协调";
if (id === "zhongshu") return "方案";
@ -673,6 +675,44 @@ function WorkbenchV2(props) {
void loadProject();
}, [loadProject]);
const projectId = view && view.project ? view.project.id : null;
(0, import_react.useEffect)(() => {
if (!projectId) return void 0;
let disposed = false;
let running = false;
let timer = null;
const tick = async () => {
if (disposed || running) return;
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
running = true;
try {
const [projectView, taskRes, artifactRes] = await Promise.all([
request("project", { projectId }),
request("tasks", { projectId }),
request("artifacts", { projectId })
]);
if (disposed || !alive.current) return;
setView(projectView);
const nextTasks = taskRes && Array.isArray(taskRes.tasks) ? taskRes.tasks : [];
setTasks(nextTasks);
setArtifacts(artifactRes && Array.isArray(artifactRes.artifacts) ? artifactRes.artifacts : []);
setSelectedTask((previous) => previous ? nextTasks.find((task) => task.id === previous.id) || previous : previous);
} catch {
} finally {
running = false;
}
};
timer = setInterval(tick, 4e3);
const onVisibility = () => {
if (document.visibilityState === "visible") void tick();
};
document.addEventListener("visibilitychange", onVisibility);
void tick();
return () => {
disposed = true;
if (timer !== null) clearInterval(timer);
document.removeEventListener("visibilitychange", onVisibility);
};
}, [projectId]);
(0, import_react.useEffect)(() => {
if (!projectId || !selectionCache) return;
const saved = selectionCache.get(projectId);
@ -931,11 +971,20 @@ function WorkbenchV2(props) {
}
const statusBanner = error ? (0, import_react.createElement)("p", { className: "ssv-banner is-error", role: "alert" }, error) : notice ? (0, import_react.createElement)("p", { className: "ssv-banner is-notice", role: "status" }, notice) : null;
function renderTopbar(title, extra) {
const shortcuts = tab === "overview" ? [
(0, import_react.createElement)("button", { type: "button", key: "memory", className: "icon-btn", title: "记忆", "aria-label": "记忆", onClick: () => setTab("memory") }, (0, import_react.createElement)(BookIcon)),
(0, import_react.createElement)("button", { type: "button", key: "settings", className: "icon-btn", title: "设置", "aria-label": "设置", onClick: () => setTab("settings") }, (0, import_react.createElement)(SlidersIcon))
] : [];
return (0, import_react.createElement)(
"header",
{ className: "topbar" },
(0, import_react.createElement)("h1", null, title),
tab === "overview" ? (0, import_react.createElement)("span", { className: "date" }, dateLabel()) : null,
(0, import_react.createElement)(
"div",
{ className: "topbar-title" },
(0, import_react.createElement)("h1", null, title),
tab === "overview" ? (0, import_react.createElement)("span", { className: "date" }, dateLabel()) : null,
(0, import_react.createElement)("div", { className: "topbar-icons" }, shortcuts)
),
(0, import_react.createElement)("span", { className: "spacer" }),
...extra || []
);
@ -1119,11 +1168,6 @@ function WorkbenchV2(props) {
"div",
{ className: "page" },
renderTopbar("总览", [
(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => {
setQueueSearch("");
setQueuePanelOpen(true);
} }, "派工队列"),
(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: loadProject, disabled: phase === "loading" }, (0, import_react.createElement)(RefreshIcon), "刷新状态"),
(0, import_react.createElement)(
"button",
{ type: "button", className: "btn primary btn-cx", onClick: () => {
@ -1228,7 +1272,6 @@ function WorkbenchV2(props) {
"div",
{ className: "page" },
renderTopbar("记忆", [
(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setTab("overview") }, "← 总览"),
(0, import_react.createElement)("span", { className: "date" }, (wb.project.name || "项目") + " · 项目共识 v" + (memory?.revision ?? 0))
]),
(0, import_react.createElement)(
@ -1275,7 +1318,7 @@ function WorkbenchV2(props) {
return (0, import_react.createElement)(
"div",
{ className: "page" },
renderTopbar("设置", [(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setTab("overview") }, "← 总览")]),
renderTopbar("设置"),
(0, import_react.createElement)(
"div",
{ className: "settings-stack" },
@ -1469,23 +1512,25 @@ function WorkbenchV2(props) {
"div",
{ className: "panel-top" },
(0, import_react.createElement)("div", { className: "brand" }, (0, import_react.createElement)("span", { className: "seal" }, "三省六部"), (0, import_react.createElement)("span", { className: "sub" }, "DSH 工作台")),
tab !== "overview" ? (0, import_react.createElement)(
"div",
{ className: "panel-actions" },
(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setTab("overview") }, "← 总览")
) : null
),
statusBanner,
renderPage(),
(0, import_react.createElement)(
"div",
{ className: "project-dock" },
(0, import_react.createElement)(
"button",
{ type: "button", className: "proj", "aria-label": "当前项目", onClick: () => setTab("settings") },
(0, import_react.createElement)("span", { className: "dot" }),
(0, import_react.createElement)("span", null, (0, import_react.createElement)("span", { className: "name" }, wb.project.name || wb.projectTitle || "当前项目"), (0, import_react.createElement)("br"), (0, import_react.createElement)("span", { className: "meta" }, "主项目 · " + wb.project.seatCount + " 席")),
(0, import_react.createElement)("span", { className: "ssv-proj-caret" }, "⌄")
),
(0, import_react.createElement)(
"div",
{ className: "panel-actions" },
tab !== "overview" ? (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setTab("overview") }, "← 总览") : null,
(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setTab("memory") }, "记忆"),
(0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setTab("settings") }, "设置")
)
),
statusBanner,
renderPage()
)
),
renderArtifactModal(),
renderTaskDetail(),
@ -2180,8 +2225,15 @@ body[data-ds-dark-theme] .ssv2,html[data-theme=dark] .ssv2,.ssv2[data-ssv-theme=
/* ---------- 工作台 v2 工具样式 ---------- */
.ssv2{height:100%;min-height:0;overflow:auto;background:var(--bg);color:var(--ink);font-family:var(--font-ui)}
.ssv2 .main{min-height:100%;min-width:600px;container-type:inline-size;container-name:ssv2}
.ssv2 .page{min-height:0}
.ssv2 .main{min-height:100%;min-width:600px;container-type:inline-size;container-name:ssv2;display:flex;flex-direction:column}
.ssv2 .page{min-height:0;flex:1 0 auto}
.ssv2 .topbar-title{display:flex;align-items:center;gap:12px;min-width:0;flex-wrap:wrap}
.ssv2 .topbar-icons{display:flex;align-items:center;gap:6px}
.ssv2 .icon-btn{width:32px;height:32px;display:inline-flex;align-items:center;justify-content:center;border:1px solid transparent;border-radius:var(--radius-control);background:transparent;color:var(--muted);cursor:pointer;padding:0}
.ssv2 .icon-btn:hover{background:var(--muted-bg);color:var(--ink);border-color:var(--panel-line)}
.ssv2 .icon-btn:focus-visible{outline:2px solid var(--cobalt);outline-offset:2px}
.ssv2 .project-dock{display:flex;justify-content:flex-end;margin-top:auto;padding-top:22px}
.ssv2 .project-dock .proj{margin-left:0}
.ssv-banner{margin:12px 0 0;padding:9px 12px;border-radius:8px;font-size:12.5px;line-height:1.5;border:1px solid var(--panel-line);background:var(--muted-bg);color:var(--ink-2)}
.ssv-banner.is-error{color:var(--bad);background:color-mix(in srgb, var(--bad) 8%, var(--panel));border-color:color-mix(in srgb, var(--bad) 24%, var(--panel-line))}
.ssv-banner.is-notice{color:var(--cobalt-ink);background:var(--cobalt-soft);border-color:color-mix(in srgb, var(--cobalt) 20%, var(--panel-line))}
@ -2893,6 +2945,10 @@ function apply(ctx) {
const activeId = activeRightTabId();
if (activeId !== row.tabId && isFn(right.focus)) right.focus(row.tabId);
if (isFn(right.isExpanded) && !right.isExpanded() && isFn(right.toggleExpanded)) right.toggleExpanded();
const activeNow = activeRightTabId();
if (activeNow !== row.tabId) return false;
if (isFn(right.isExpanded) && !right.isExpanded()) return false;
scheduleWorkbenchVisibility(sessionId);
return true;
} catch (error) {
console.warn("[sansheng] 展开右侧栏失败:", error && error.message ? error.message : error);
@ -2900,20 +2956,51 @@ function apply(ctx) {
}
}
function scheduleRevealRightTab(sessionId) {
for (const delay of [120, 420]) {
for (const delay of [120, 420, 900, 1600]) {
setTimeout(() => {
if (!rightWorkbenchPinned) return;
revealRightTab(sessionId);
}, delay);
}
}
function workbenchVisible(sessionId) {
if (typeof document === "undefined") return true;
try {
const hosts = Array.from(document.querySelectorAll(".ssw-tab-body[data-session-id]"));
const scoped = sessionId ? hosts.filter((el) => el.getAttribute("data-session-id") === sessionId) : hosts;
if (sessionId && scoped.length === 0) return false;
const candidates = scoped.length ? scoped : Array.from(document.querySelectorAll(".ssw-tab-body"));
return candidates.some((host) => {
const node = host.querySelector(".ssv2");
if (!node) return false;
const rect = node.getBoundingClientRect();
return rect.width > 0 && rect.height > 0;
});
} catch {
return true;
}
}
function scheduleWorkbenchVisibility(sessionId) {
for (const delay of [180, 600, 1200]) {
setTimeout(() => {
if (!rightWorkbenchPinned) return;
try {
if (workbenchVisible(sessionId)) return;
const right = get("sidebarRight");
const row = findRightWorkbenchTab(sessionId);
if (!right || !row || activeRightTabId() !== row.tabId) return;
const layout = get("layout");
if (layout && isFn(layout.openRightbar)) layout.openRightbar(true, false);
else if (isFn(right.toggleExpanded)) right.toggleExpanded();
} catch {
}
}, delay);
}
}
function tryOpenRightTab(sessionId) {
const targetSessionId = typeof sessionId === "string" && sessionId ? sessionId : rightMountedSessionId();
const existing = findRightWorkbenchTab(targetSessionId);
if (existing) {
revealRightTab(targetSessionId);
return true;
}
if (existing) return revealRightTab(targetSessionId);
const bs = get("betterSidebar");
if (bs && isFn(bs.openTab)) {
try {
@ -2944,7 +3031,8 @@ function apply(ctx) {
return true;
}
function SanshengTabBody(props) {
return (0, import_react2.createElement)("div", { className: "ssw-tab-body" }, (0, import_react2.createElement)(SanshengWorkbench, { sessionId: props && props.sessionId }));
const sessionId = props && props.sessionId;
return (0, import_react2.createElement)("div", { className: "ssw-tab-body", "data-session-id": sessionId || void 0 }, (0, import_react2.createElement)(SanshengWorkbench, { sessionId }));
}
function SanshengTabTitle() {
return (0, import_react2.createElement)("span", { className: "ssw-tab-title" }, "三省六部");
@ -2962,7 +3050,8 @@ function apply(ctx) {
single: true,
component: (tabProps) => {
const scope = tabProps && tabProps.scope ? tabProps.scope : null;
return (0, import_react2.createElement)("div", { className: "ssw-tab-body" }, (0, import_react2.createElement)(SanshengWorkbench, { sessionId: scope && scope.sessionId }));
const sessionId = scope && scope.sessionId;
return (0, import_react2.createElement)("div", { className: "ssw-tab-body", "data-session-id": sessionId || void 0 }, (0, import_react2.createElement)(SanshengWorkbench, { sessionId }));
}
});
return () => {
@ -3119,9 +3208,10 @@ function apply(ctx) {
try {
const sessionId = rightMountedSessionId();
if (findRightWorkbenchTab(sessionId)) {
revealRightTab(sessionId);
attempt = 0;
return;
if (revealRightTab(sessionId)) {
attempt = 0;
return;
}
}
if (openRightWorkbench(sessionId)) {
attempt = 0;
@ -3141,10 +3231,28 @@ function apply(ctx) {
timer = setTimeout(ensure, delays[0]);
};
const stop = right.mounted.subscribe(kick);
let stopTabs = null;
const discoverPinnedTab = () => {
try {
const sessionId = rightMountedSessionId();
if (!sessionId || !findRightWorkbenchTab(sessionId)) return;
if (!rightWorkbenchPinned) {
rightWorkbenchPinned = true;
writeRightWorkbenchPinned(true);
}
kick();
} catch {
}
};
if (isFn(right.openTabs?.subscribe)) stopTabs = right.openTabs.subscribe(discoverPinnedTab);
if (rightWorkbenchPinned) kick();
if (isFn(ctx.effect)) ctx.effect(() => {
clear();
stop();
try {
if (isFn(stopTabs)) stopTabs();
} catch {
}
});
}
function SanshengNavButton(props) {

View File

@ -291,6 +291,12 @@ export function apply(ctx) {
const activeId = activeRightTabId()
if (activeId !== row.tabId && isFn(right.focus)) right.focus(row.tabId)
if (isFn(right.isExpanded) && !right.isExpanded() && isFn(right.toggleExpanded)) right.toggleExpanded()
// focus/toggle 可能是宿主在会话 surface 尚未 mint 时的 silent no-op。
// 只有“目标标签真的 active 且右栏真的展开”才算成功,否则交给退避重试。
const activeNow = activeRightTabId()
if (activeNow !== row.tabId) return false
if (isFn(right.isExpanded) && !right.isExpanded()) return false
scheduleWorkbenchVisibility(sessionId)
return true
} catch (error) {
console.warn('[sansheng] 展开右侧栏失败:', error && error.message ? error.message : error)
@ -300,7 +306,7 @@ export function apply(ctx) {
// 单次补聚焦只用于“标签异步落位”的短窗口;每次先确认标签真的存在,绝不在已有标签时重复 openTab。
function scheduleRevealRightTab(sessionId) {
for (const delay of [120, 420]) {
for (const delay of [120, 420, 900, 1600]) {
setTimeout(() => {
if (!rightWorkbenchPinned) return
revealRightTab(sessionId)
@ -308,10 +314,50 @@ export function apply(ctx) {
}
}
// 右侧栏是宿主的独立布局列:新会话切换后,sidebarRight 可能先报“已展开”,
// 但这一列的 DOM 实际宽度仍是 0(旧会话 surface 的布局快照滞后)。
// 这种状态 focus/toggle 的服务层返回值不可靠,用工作台 DOM 宽度做最终判据,
// 并在短窗口内补一次 toggle,让新会话的右栏真正展开。
function workbenchVisible(sessionId) {
if (typeof document === 'undefined') return true
try {
// 每个会话在右栏各有自己的挂载节点;旧会话节点即使可见,也不代表当前会话可见。
const hosts = Array.from(document.querySelectorAll('.ssw-tab-body[data-session-id]'))
const scoped = sessionId ? hosts.filter(el => el.getAttribute('data-session-id') === sessionId) : hosts
if (sessionId && scoped.length === 0) return false
const candidates = scoped.length ? scoped : Array.from(document.querySelectorAll('.ssw-tab-body'))
return candidates.some(host => {
const node = host.querySelector('.ssv2')
if (!node) return false
const rect = node.getBoundingClientRect()
return rect.width > 0 && rect.height > 0
})
} catch { return true }
}
function scheduleWorkbenchVisibility(sessionId) {
for (const delay of [180, 600, 1200]) {
setTimeout(() => {
if (!rightWorkbenchPinned) return
try {
if (workbenchVisible(sessionId)) return
const right = get('sidebarRight')
const row = findRightWorkbenchTab(sessionId)
if (!right || !row || activeRightTabId() !== row.tabId) return
// 宿主布局列和 rightbar surface 是两层状态:surface 可能已 expanded,
// 但布局列仍为 0。直接报告一次可见 track,随后仍留给宿主自己收敛。
const layout = get('layout')
if (layout && isFn(layout.openRightbar)) layout.openRightbar(true, false)
else if (isFn(right.toggleExpanded)) right.toggleExpanded()
} catch { /* 忽略 */ }
}, delay)
}
}
function tryOpenRightTab(sessionId) {
const targetSessionId = (typeof sessionId === 'string' && sessionId) ? sessionId : rightMountedSessionId()
const existing = findRightWorkbenchTab(targetSessionId)
if (existing) { revealRightTab(targetSessionId); return true }
if (existing) return revealRightTab(targetSessionId)
// 桌面版右栏由 dsh-better-sidebar 接管:它自己的 openTab 会排队等待会话面板挂载,
// 主区正被切走时也不会丢;直接调宿主 sidebarRight 反而会因“没有挂载的会话面板”失败。
// 显式传 scope:新会话刚建立时 bs 的 active snapshot 可能还停在旧会话,不能靠猜。
@ -347,7 +393,8 @@ export function apply(ctx) {
return true
}
function SanshengTabBody(props) {
return h('div', { className: 'ssw-tab-body' }, h(SanshengWorkbench, { sessionId: props && props.sessionId }))
const sessionId = props && props.sessionId
return h('div', { className: 'ssw-tab-body', 'data-session-id': sessionId || undefined }, h(SanshengWorkbench, { sessionId }))
}
function SanshengTabTitle() {
return h('span', { className: 'ssw-tab-title' }, '三省六部')
@ -367,7 +414,8 @@ export function apply(ctx) {
single: true,
component: (tabProps) => {
const scope = tabProps && tabProps.scope ? tabProps.scope : null
return h('div', { className: 'ssw-tab-body' }, h(SanshengWorkbench, { sessionId: scope && scope.sessionId }))
const sessionId = scope && scope.sessionId
return h('div', { className: 'ssw-tab-body', 'data-session-id': sessionId || undefined }, h(SanshengWorkbench, { sessionId }))
},
})
return () => { try { if (isFn(dispose)) dispose() } catch { /* 忽略 */ } }
@ -483,9 +531,9 @@ export function apply(ctx) {
try {
const sessionId = rightMountedSessionId()
if (findRightWorkbenchTab(sessionId)) {
revealRightTab(sessionId)
attempt = 0
return
// 标签存在不代表已经展开:新会话的右栏 surface 可能尚未 mint,
// reveal 会短暂失败。失败时继续退避重试,不能把“找到标签”当成成功。
if (revealRightTab(sessionId)) { attempt = 0; return }
}
if (openRightWorkbench(sessionId)) {
attempt = 0
@ -504,10 +552,23 @@ export function apply(ctx) {
timer = setTimeout(ensure, delays[0])
}
const stop = right.mounted.subscribe(kick)
// 用户也可能从右侧栏 guide 入口直接打开工作台;此时没有经过 openRightWorkbench,
// 需要观察 openTabs 把“已经打开”记成固定状态,否则切一次会话就被宿主收起。
let stopTabs = null
const discoverPinnedTab = () => {
try {
const sessionId = rightMountedSessionId()
if (!sessionId || !findRightWorkbenchTab(sessionId)) return
if (!rightWorkbenchPinned) { rightWorkbenchPinned = true; writeRightWorkbenchPinned(true) }
kick()
} catch { /* 忽略 */ }
}
if (isFn(right.openTabs?.subscribe)) stopTabs = right.openTabs.subscribe(discoverPinnedTab)
if (rightWorkbenchPinned) kick()
if (isFn(ctx.effect)) ctx.effect(() => {
clear()
stop()
try { if (isFn(stopTabs)) stopTabs() } catch { /* 忽略 */ }
})
}

View File

@ -639,8 +639,15 @@ body[data-ds-dark-theme] .ssv2,html[data-theme=dark] .ssv2,.ssv2[data-ssv-theme=
/* ---------- 工作台 v2 工具样式 ---------- */
.ssv2{height:100%;min-height:0;overflow:auto;background:var(--bg);color:var(--ink);font-family:var(--font-ui)}
.ssv2 .main{min-height:100%;min-width:600px;container-type:inline-size;container-name:ssv2}
.ssv2 .page{min-height:0}
.ssv2 .main{min-height:100%;min-width:600px;container-type:inline-size;container-name:ssv2;display:flex;flex-direction:column}
.ssv2 .page{min-height:0;flex:1 0 auto}
.ssv2 .topbar-title{display:flex;align-items:center;gap:12px;min-width:0;flex-wrap:wrap}
.ssv2 .topbar-icons{display:flex;align-items:center;gap:6px}
.ssv2 .icon-btn{width:32px;height:32px;display:inline-flex;align-items:center;justify-content:center;border:1px solid transparent;border-radius:var(--radius-control);background:transparent;color:var(--muted);cursor:pointer;padding:0}
.ssv2 .icon-btn:hover{background:var(--muted-bg);color:var(--ink);border-color:var(--panel-line)}
.ssv2 .icon-btn:focus-visible{outline:2px solid var(--cobalt);outline-offset:2px}
.ssv2 .project-dock{display:flex;justify-content:flex-end;margin-top:auto;padding-top:22px}
.ssv2 .project-dock .proj{margin-left:0}
.ssv-banner{margin:12px 0 0;padding:9px 12px;border-radius:8px;font-size:12.5px;line-height:1.5;border:1px solid var(--panel-line);background:var(--muted-bg);color:var(--ink-2)}
.ssv-banner.is-error{color:var(--bad);background:color-mix(in srgb, var(--bad) 8%, var(--panel));border-color:color-mix(in srgb, var(--bad) 24%, var(--panel-line))}
.ssv-banner.is-notice{color:var(--cobalt-ink);background:var(--cobalt-soft);border-color:color-mix(in srgb, var(--cobalt) 20%, var(--panel-line))}

View File

@ -182,6 +182,8 @@ const ChatIcon = () => fileIcon(['M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14
const PlusIcon = () => fileIcon(['M12 5v14', 'M5 12h14'])
const SearchIcon = () => h('svg', { viewBox: '0 0 24 24', width: 15, height: 15, fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', 'aria-hidden': 'true' }, h('circle', { cx: 11, cy: 11, r: 8 }), h('path', { d: 'm21 21-4.3-4.3' }))
const ArrowIcon = () => fileIcon(['m9 18 6-6-6-6'], 15)
const BookIcon = () => fileIcon(['M4 19.5A2.5 2.5 0 0 1 6.5 17H20', 'M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z'], 15)
const SlidersIcon = () => fileIcon(['M4 21v-7', 'M4 10V3', 'M12 21v-9', 'M12 8V3', 'M20 21v-5', 'M20 12V3', 'M2 14h4', 'M10 8h4', 'M18 16h4'], 15)
function seatKind(id) {
if (id === 'lead') return '总协调'
@ -280,6 +282,45 @@ export function WorkbenchV2(props) {
useEffect(() => { void loadProject() }, [loadProject])
const projectId = view && view.project ? view.project.id : null
// 派工等操作在聊天里发生,工作台没有事件通道;轮询真实接口让队列/席位状态自动跟上。
// 页面隐藏时跳过;回到前台立即补一次。绝不把轮询结果写进草稿或配置。
useEffect(() => {
if (!projectId) return undefined
let disposed = false
let running = false
let timer = null
const tick = async () => {
if (disposed || running) return
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
running = true
try {
const [projectView, taskRes, artifactRes] = await Promise.all([
request('project', { projectId }),
request('tasks', { projectId }),
request('artifacts', { projectId }),
])
if (disposed || !alive.current) return
setView(projectView)
const nextTasks = taskRes && Array.isArray(taskRes.tasks) ? taskRes.tasks : []
setTasks(nextTasks)
setArtifacts(artifactRes && Array.isArray(artifactRes.artifacts) ? artifactRes.artifacts : [])
setSelectedTask(previous => previous ? (nextTasks.find(task => task.id === previous.id) || previous) : previous)
} catch { /* 轮询失败保留上一份真实数据,不弹错误打断编辑 */ } finally {
running = false
}
}
timer = setInterval(tick, 4000)
const onVisibility = () => { if (document.visibilityState === 'visible') void tick() }
document.addEventListener('visibilitychange', onVisibility)
void tick()
return () => {
disposed = true
if (timer !== null) clearInterval(timer)
document.removeEventListener('visibilitychange', onVisibility)
}
}, [projectId])
useEffect(() => {
if (!projectId || !selectionCache) return
const saved = selectionCache.get(projectId)
@ -505,9 +546,18 @@ export function WorkbenchV2(props) {
: (notice ? h('p', { className: 'ssv-banner is-notice', role: 'status' }, notice) : null)
function renderTopbar(title, extra) {
const shortcuts = tab === 'overview'
? [
h('button', { type: 'button', key: 'memory', className: 'icon-btn', title: '记忆', 'aria-label': '记忆', onClick: () => setTab('memory') }, h(BookIcon)),
h('button', { type: 'button', key: 'settings', className: 'icon-btn', title: '设置', 'aria-label': '设置', onClick: () => setTab('settings') }, h(SlidersIcon)),
]
: []
return h('header', { className: 'topbar' },
h('h1', null, title),
tab === 'overview' ? h('span', { className: 'date' }, dateLabel()) : null,
h('div', { className: 'topbar-title' },
h('h1', null, title),
tab === 'overview' ? h('span', { className: 'date' }, dateLabel()) : null,
h('div', { className: 'topbar-icons' }, shortcuts),
),
h('span', { className: 'spacer' }),
...(extra || []),
)
@ -651,8 +701,6 @@ export function WorkbenchV2(props) {
return h('div', { className: 'page' },
renderTopbar('总览', [
h('button', { type: 'button', className: 'btn', onClick: () => { setQueueSearch(''); setQueuePanelOpen(true) } }, '派工队列'),
h('button', { type: 'button', className: 'btn', onClick: loadProject, disabled: phase === 'loading' }, h(RefreshIcon), '刷新状态'),
h('button', { type: 'button', className: 'btn primary btn-cx', onClick: () => { setSeat('lead'); if (seatById.lead.status === 'bound') void openSeat('lead'); else setTab('settings') } },
h('span', { className: 'cx-name' }, '丞相'), h('span', { className: 'cx-dot', 'aria-hidden': 'true' }), h('span', { className: 'cx-state' }, seatStateText(seatById.lead))),
]),
@ -719,7 +767,6 @@ export function WorkbenchV2(props) {
)
return h('div', { className: 'page' },
renderTopbar('记忆', [
h('button', { type: 'button', className: 'btn', onClick: () => setTab('overview') }, '← 总览'),
h('span', { className: 'date' }, (wb.project.name || '项目') + ' · 项目共识 v' + (memory?.revision ?? 0)),
]),
h('div', { className: 'settings-stack' },
@ -753,7 +800,7 @@ export function WorkbenchV2(props) {
function renderSettings() {
return h('div', { className: 'page' },
renderTopbar('设置', [h('button', { type: 'button', className: 'btn', onClick: () => setTab('overview') }, '← 总览')]),
renderTopbar('设置'),
h('div', { className: 'settings-stack' },
h('section', { className: 'card', 'aria-label': '项目绑定' },
h('h3', null, '项目绑定'),
@ -886,18 +933,18 @@ export function WorkbenchV2(props) {
h('div', { className: 'main' },
h('div', { className: 'panel-top' },
h('div', { className: 'brand' }, h('span', { className: 'seal' }, '三省六部'), h('span', { className: 'sub' }, 'DSH 工作台')),
tab !== 'overview' ? h('div', { className: 'panel-actions' },
h('button', { type: 'button', className: 'btn', onClick: () => setTab('overview') }, '← 总览'),
) : null,
),
statusBanner,
renderPage(),
h('div', { className: 'project-dock' },
h('button', { type: 'button', className: 'proj', 'aria-label': '当前项目', onClick: () => setTab('settings') },
h('span', { className: 'dot' }),
h('span', null, h('span', { className: 'name' }, wb.project.name || wb.projectTitle || '当前项目'), h('br'), h('span', { className: 'meta' }, '主项目 · ' + wb.project.seatCount + ' 席')),
h('span', { className: 'ssv-proj-caret' }, '⌄')),
h('div', { className: 'panel-actions' },
tab !== 'overview' ? h('button', { type: 'button', className: 'btn', onClick: () => setTab('overview') }, '← 总览') : null,
h('button', { type: 'button', className: 'btn', onClick: () => setTab('memory') }, '记忆'),
h('button', { type: 'button', className: 'btn', onClick: () => setTab('settings') }, '设置'),
),
),
statusBanner,
renderPage(),
),
renderArtifactModal(),
renderTaskDetail(),

View File

@ -27,6 +27,22 @@ test('右侧工作台依赖宿主 sidebarRight,并在会话切换后重新固
test('右侧栏有可发现的 guide 入口,并把标签会话传给工作台', async () => {
const source = await readFile(join(root, 'src/client/index.js'), 'utf8')
assert.match(source, /guide: \[\{/)
assert.match(source, /sessionId: props && props\.sessionId/)
assert.match(source, /const sessionId = props && props\.sessionId/)
assert.match(source, /workspaceForSessionId\(sessionId\)/)
})
test('右栏展开失败会继续重试,guide 打开也会记为固定', async () => {
const source = await readFile(join(root, 'src/client/index.js'), 'utf8')
assert.match(source, /if \(revealRightTab\(sessionId\)\) \{ attempt = 0; return \}/)
assert.match(source, /right\.openTabs\.subscribe\(discoverPinnedTab\)/)
assert.match(source, /if \(existing\) return revealRightTab\(targetSessionId\)/)
assert.match(source, /if \(activeNow !== row\.tabId\) return false/)
})
test('右栏可见性按会话判断,布局列收起时主动展开', async () => {
const source = await readFile(join(root, 'src/client/index.js'), 'utf8')
assert.match(source, /'data-session-id': sessionId/)
assert.match(source, /function workbenchVisible\(sessionId\)/)
assert.match(source, /workbenchVisible\(sessionId\)/)
assert.match(source, /layout\.openRightbar\(true, false\)/)
})