diff --git a/README.md b/README.md index bd8bc7c..c1094be 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 三省六部(dsh-sansheng)· v1.0.0 +# 三省六部(dsh-sansheng)· v1.1.0 在 DSH 里为每个项目提供固定的十席角色(丞相、中书、门下、尚书、吏部、户部、礼部、兵部、刑部、工部), 每席绑定一个独立的原生 root Session,模型与补充说明按项目独立保存。中间复用宿主原生会话,不替换聊天引擎。 @@ -14,9 +14,16 @@ - 派工工具随席位绑定即时注册:新建、恢复、重建后同一次 DSH 启动内即可派工;重新绑定后旧会话失去该席位工具权限。 - 派工失败明确区分「本席派工工具未就绪」「目标部门未开启」「任务投递失败」,以项目真实席位绑定和会话 ID 为准。 - 尚书可按需汇总项目真实任务与结果,明确区分「已派工/已收到」和「已完成」,不拦截丞相直接派工。 +- 丞相需求澄清(Grill Me):仅在存在关键歧义、冲突或缺失时自动加载 `grilling` skill 追问;代码解释、状态查询、普通讨论和已足够明确的需求不触发。追问结果回写原 `R-xxx` 并递增 revision,保留 `missingInfo`;不创建任务、不派工、不生成批准凭证。 **本包尚未安装到用户的日常 DSH profile,也未改动日常 DSH 配置。** +## Grill Me 技能依赖 + +- 丞相自动追问使用 `grilling` skill;`grill-me` 是用户手动入口,正文只转调 `grilling`。 +- 上游 `grill-me` 带 `disable-model-invocation: true`,DSH 会把它从模型目录和 `skill` 工具中排除,所以模型侧自动加载的是 `grilling`,不是 `grill-me`。 +- 本仓库根目录 `.dsh/skills/` 保留两份技能副本(MIT,来源:mattpocock/skills);用户级 `~/.dsh/skills/` 已安装扁平文件 `grilling.md` 与 `grill-me.md`,供所有项目加载。技能缺失时丞相必须明确报告,不得伪造调用。 + ## 目录 - `index.js` — 宿主插件入口(`name` / `inject` / `apply`)。 @@ -24,4 +31,4 @@ - `src/host/` — 项目状态存储、严格会话创建/恢复、模型配置(不写 profile)、提示词 section、HTTP `api/sansheng`。 - `src/client/` — Web 工作台(纯视图模型 + React 接线 + 传输层)。 - `src/native/` — dsh-go 原生面板(纯视图树构造 + bridge 接线)。 -- `test/` — fake ctx 单元/集成测试。 +- `test/` — fake ctx 单元/集成测试。 \ No newline at end of file diff --git a/client.js b/client.js index 310a3a4..ee16124 100644 --- a/client.js +++ b/client.js @@ -369,138 +369,2118 @@ async function request(endpoint, payload, signal) { } var transport_default = request; -// src/client/styles.js -var CSS = ` -.ssw-scope{--ssw-bg:#ffffff;--ssw-side:#f8f9fa;--ssw-rail:#f8fafc;--ssw-card:#ffffff;--ssw-line:#e3e8ef;--ssw-strong:#c7d8f5;--ssw-ink:#0f172a;--ssw-muted:#667085;--ssw-faint:#98a2b3;--ssw-blue:#4263eb;--ssw-wash:#eef2ff;--ssw-frame:#3b82f6;--ssw-wire:#c9d6ea;--ssw-danger:#dc2626;--ssw-ok:#16a34a;box-sizing:border-box;color:var(--ssw-ink);font-family:Inter,"Segoe UI","Microsoft YaHei",sans-serif;font-size:13px;line-height:1.5} -.ssw-scope *,.ssw-scope *::before,.ssw-scope *::after{box-sizing:border-box} -.ssw-scope :where(button){font:inherit;color:inherit;background:transparent;border:0;cursor:pointer} -.ssw-scope button:disabled{cursor:default;opacity:.55} -.ssw-scope :focus-visible{outline:2px solid var(--ssw-blue);outline-offset:2px} -body[data-ds-dark-theme] .ssw-scope,html[data-theme=dark] .ssw-scope,.ssw-scope[data-ssw-theme=dark]{--ssw-bg:#14171c;--ssw-side:#171b21;--ssw-rail:#161a20;--ssw-card:#1e232b;--ssw-line:#2c333d;--ssw-strong:#3b4a63;--ssw-frame:#6ea8ff;--ssw-ink:#e6ebf2;--ssw-muted:#a9b4c2;--ssw-faint:#7b8797;--ssw-blue:#6ea8ff;--ssw-wash:#1d2b40;--ssw-wire:#3a4350;--ssw-danger:#f87171;--ssw-ok:#4ade80} -.ssw-float{position:fixed;right:14px;bottom:70px;z-index:2147483000;width:min(374px,calc(100vw - 28px));max-height:calc(100vh - 96px);display:flex;flex-direction:column;background:#ffffff;border:1px solid #e3e8ef;border-radius:12px;box-shadow:0 18px 50px -12px rgba(16,24,40,.28),0 4px 12px -2px rgba(16,24,40,.12);overflow:hidden} -body[data-ds-dark-theme] .ssw-float,html[data-theme=dark] .ssw-float{background:#161a20;border-color:#2c333d} -.ssw-root{container-type:inline-size;display:flex;flex-direction:column;min-height:0;height:100%;overflow:auto;background:var(--ssw-rail);color:var(--ssw-ink)} -.ssw-head{flex:none;height:52px;display:flex;align-items:center;gap:8px;padding:0 16px;border-bottom:1px solid var(--ssw-line);background:var(--ssw-card)} -.ssw-head svg{width:18px;height:18px;color:var(--ssw-muted)} -.ssw-head-title{font-size:13px;font-weight:600} -.ssw-icon-btn{margin-left:auto;display:inline-flex;align-items:center;justify-content:center;width:30px;height:30px;border-radius:6px;color:var(--ssw-muted)} -.ssw-icon-btn:hover{background:var(--ssw-wash);color:var(--ssw-blue)} -.ssw-project{padding:22px 20px 0} -.ssw-project-line{display:flex;align-items:center;justify-content:space-between;margin-bottom:5px} -.ssw-eyebrow{display:inline-flex;align-items:center;gap:6px;font-size:11px;color:var(--ssw-muted)} -.ssw-eyebrow svg{width:14px;height:14px} -.ssw-count{font-size:10px;color:var(--ssw-faint)} -.ssw-project-title{font-size:21px;font-weight:650;letter-spacing:.5px;margin:4px 0 16px} -.ssw-enable{margin:0 16px 4px;padding:12px;border:1px solid var(--ssw-strong);background:var(--ssw-wash);border-radius:10px} -.ssw-enable-note{margin:0 0 10px;font-size:12px;color:var(--ssw-muted);line-height:1.7} -.ssw-primary{min-height:36px;background:var(--ssw-blue);color:#ffffff;border-radius:7px;padding:8px 13px;font-size:12px;font-weight:500} -.ssw-primary:hover{filter:brightness(1.05)} -.ssw-tree{padding:24px 20px 4px;position:relative} -.ssw-lead{width:168px;margin:0 auto;position:relative} -.ssw-lead::after{content:none} -.ssw-sansheng{position:relative;margin-top:24px} -.ssw-trio{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:9px} -.ssw-seat{position:relative;width:100%;display:flex;flex-direction:column;gap:6px;padding:14px 12px 12px;border:1px solid var(--ssw-line);border-radius:12px;background:var(--ssw-card);text-align:left;min-height:80px;box-shadow:0 1px 2px rgba(16,24,40,.04);transition:border-color .15s,box-shadow .15s,transform .15s} -.ssw-seat:hover{border-color:var(--ssw-blue);transform:translateY(-1px);box-shadow:0 3px 8px rgba(16,24,40,.06)} -.ssw-seat[aria-pressed=true]{border-color:var(--ssw-blue);background:var(--ssw-wash);box-shadow:0 0 0 2px rgba(59,130,246,.12)} -.ssw-lead .ssw-seat{min-height:84px} -.ssw-role-top{display:flex;align-items:center;justify-content:space-between;gap:6px} -.ssw-role-name{font-size:14px;font-weight:600;letter-spacing:2px} -.ssw-role-duty{font-size:11px;color:var(--ssw-muted);line-height:1.5} -.ssw-dot{flex:none;width:6px;height:6px;border-radius:50%;border:1px solid var(--ssw-faint);background:transparent} -.ssw-dot[data-status=bound]{background:var(--ssw-ok);border-color:var(--ssw-ok)} -.ssw-dot[data-status=failed],.ssw-dot[data-status=missing]{background:var(--ssw-danger);border-color:var(--ssw-danger)} -.ssw-dot[data-status=creating]{background:var(--ssw-blue);border-color:var(--ssw-blue)} -.ssw-ministries{position:relative;margin-top:18px} -.ssw-group-label{display:flex;align-items:center;gap:10px;margin:0 2px 8px;font-size:11px;font-weight:600;letter-spacing:.5px;color:var(--ssw-muted)} -.ssw-six{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px} -.ssw-six .ssw-seat{min-height:76px;padding:12px} -.ssw-report{padding:0 20px;margin-top:4px} -.ssw-report-toggle{font-size:12px;color:var(--ssw-blue);padding:7px 2px;font-weight:500} -.ssw-report-list{display:flex;flex-direction:column;gap:8px;margin-top:4px} -.ssw-report-item{border:1px solid var(--ssw-line);border-radius:9px;padding:9px 11px;background:var(--ssw-card)} -.ssw-report-head{display:flex;gap:8px;align-items:baseline} -.ssw-report-head strong{font-size:13px;letter-spacing:1px} -.ssw-report-head span{font-size:10px;color:var(--ssw-muted)} -.ssw-report-model{margin:4px 0 0;font-size:11px;color:var(--ssw-blue);letter-spacing:.2px} -.ssw-report-text{margin:4px 0 0;font-size:12px;line-height:1.7;color:var(--ssw-muted)} -.ssw-current{margin:14px 20px 0;padding:16px;border:1px solid var(--ssw-line);border-radius:11px;background:var(--ssw-card)} -.ssw-current-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:9px} -.ssw-current-name{font-size:13px;font-weight:600} -.ssw-current-label{font-size:10px;color:var(--ssw-faint)} -.ssw-current-text{margin:0;font-size:12px;line-height:1.8;color:var(--ssw-muted)} -.ssw-config{margin:10px 20px 20px;border:1px solid var(--ssw-line);border-radius:10px;background:var(--ssw-card);overflow:hidden} -.ssw-config-toggle{display:flex;align-items:center;gap:8px;width:100%;padding:12px 13px;font-size:12px;color:var(--ssw-ink)} -.ssw-config-toggle svg{width:15px;height:15px;color:var(--ssw-muted)} -.ssw-chevron{margin-left:auto;transition:transform .2s} -.ssw-config-toggle[aria-expanded=true] .ssw-chevron{transform:rotate(180deg)} -.ssw-config-body{padding:0 13px 14px} -.ssw-label{display:block;font-size:11px;color:var(--ssw-muted);margin:12px 0 6px} -.ssw-field{width:100%;border:1px solid var(--ssw-line);background:var(--ssw-bg);color:var(--ssw-ink);border-radius:6px;padding:8px;font-size:12px;line-height:1.5} -.ssw-textarea{resize:vertical;min-height:84px;font-family:inherit} -.ssw-scope-note{margin:10px 0;font-size:10px;line-height:1.6;color:var(--ssw-faint)} -.ssw-save-row{display:flex;align-items:center;gap:10px} -.ssw-save-status{font-size:10px;color:var(--ssw-muted)} -.ssw-notice{margin:12px 16px 16px;font-size:11px;color:var(--ssw-muted)} -.ssw-error{margin:12px 16px 16px;font-size:11px;color:var(--ssw-danger)} -.ssw-loading,.ssw-empty{padding:36px 20px;text-align:center;font-size:12px;color:var(--ssw-muted)} -.ssw-empty .ssw-primary{margin-top:12px} -/* 导航行图标:尺寸/颜色全部跟随宿主导航行,不自己画背景,避免比同类导航项突兀。 */ -.ssw-nav-hit{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;color:inherit;cursor:pointer} -.ssw-nav-hit svg{width:16px;height:16px;flex:none;display:block} -.ssw-hint{margin:6px 0 0;font-size:11px;color:var(--ssw-faint)} -.ssw-current-actions{margin-top:10px;display:flex;gap:8px} -.ssw-inline-bar{flex:none;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 12px;border-bottom:1px solid var(--ssw-line);background:var(--ssw-card);font-size:12px;color:var(--ssw-muted)} -.ssw-link{color:var(--ssw-blue);font-size:12px;padding:2px 4px} -@media (prefers-reduced-motion:reduce){.ssw-scope *{transition:none!important}} -.ssw-tabs{display:flex;gap:6px;margin:0 20px;padding:4px;border:1px solid var(--ssw-line);border-radius:12px;background:var(--ssw-side)} -.ssw-tab{flex:1;display:flex;align-items:center;justify-content:center;gap:6px;padding:7px 6px;border-radius:6px;font-size:12px;color:var(--ssw-muted)} -.ssw-tab.is-active{background:var(--ssw-card);color:var(--ssw-blue);font-weight:600;box-shadow:0 1px 2px rgba(16,24,40,.06)} -.ssw-tab-count{font-size:10px;color:var(--ssw-faint)} -.ssw-page{padding:12px 16px 0} -.ssw-page-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:10px} -.ssw-page-head strong{font-size:13px} -.ssw-list{display:flex;flex-direction:column;gap:8px} -.ssw-row{border:1px solid var(--ssw-line);border-radius:9px;padding:9px 11px;background:var(--ssw-card)} -.ssw-row-top{display:flex;align-items:center;justify-content:space-between;gap:8px} -.ssw-row-title{font-size:13px} -.ssw-row-meta{margin:4px 0 0;font-size:11px;color:var(--ssw-muted)} -.ssw-row-note{margin:4px 0 0;font-size:10px;color:var(--ssw-faint)} -.ssw-row-result{margin:4px 0 0;font-size:11px;color:var(--ssw-ok);word-break:break-word} -.ssw-row-actions{display:flex;gap:10px;margin-top:6px} -.ssw-link{color:var(--ssw-blue);font-size:12px;padding:2px 2px} -.ssw-link-muted{color:var(--ssw-muted)} -.ssw-badge{font-size:10px;padding:2px 6px;border-radius:999px;background:var(--ssw-wash);color:var(--ssw-blue)} -.ssw-badge[data-status=running]{background:rgba(37,99,235,.12);color:var(--ssw-blue)} -.ssw-badge[data-status=done]{background:rgba(22,163,74,.12);color:var(--ssw-ok)} -.ssw-badge[data-status=cancelled]{background:rgba(107,114,128,.14);color:var(--ssw-muted)} -.ssw-badge[data-status=failed]{background:rgba(220,38,38,.12);color:var(--ssw-danger)} -.ssw-form{margin-bottom:12px;padding:10px;border:1px solid var(--ssw-line);border-radius:9px;background:var(--ssw-side)} -.ssw-empty-line{margin:10px 0;font-size:12px;color:var(--ssw-faint)} -.ssw-project-line{align-items:baseline;margin-bottom:10px} -.ssw-project-title{margin:0} -.ssw-tab-body{height:100%;min-height:0;display:flex;flex-direction:column} -.ssw-tab-body .ssw-root{flex:1;min-height:0} -.ssw-tab-title{font-size:13px} -.ssw-group-label::after{content:"";height:1px;background:var(--ssw-line);flex:1} -.ssw-role-top{width:100%} -.ssw-tab-count{padding:1px 5px;border-radius:5px;background:var(--ssw-rail)} -.ssw-current-name{font-size:15px;letter-spacing:1px} -.ssw-current-label{padding:3px 7px;border-radius:5px;background:var(--ssw-side)} -.ssw-config-toggle:hover{background:var(--ssw-side)} -/* 按工作台本身的宽度适配:宽屏居中,右侧窄栏保持紧凑。 */ -.ssw-root > :is(.ssw-project,.ssw-tree,.ssw-report,.ssw-page){width:100%;max-width:720px;align-self:center;flex-shrink:0} -.ssw-root > :is(.ssw-tabs,.ssw-current,.ssw-config,.ssw-enable,.ssw-notice,.ssw-error){width:calc(100% - 40px);max-width:680px;margin-left:auto;margin-right:auto;flex-shrink:0} -.ssw-enable{margin-top:12px} -@container(max-width:380px){.ssw-root > :is(.ssw-tabs,.ssw-current,.ssw-config,.ssw-enable,.ssw-notice,.ssw-error){width:calc(100% - 24px);margin-left:auto;margin-right:auto} -.ssw-project{padding:16px 12px 0}.ssw-tabs{margin:0 12px}.ssw-tree{padding:20px 12px 4px}.ssw-current{margin:12px 12px 0}.ssw-config{margin:10px 12px 16px}.ssw-report{padding:0 12px}.ssw-trio,.ssw-six{gap:6px}.ssw-seat,.ssw-six .ssw-seat{padding:10px 8px}.ssw-role-duty{font-size:10px}} -/* 窄栏隐藏职责小字,避免被卡片宽度截断 */ -@container (max-width:420px){ - .ssw-role-duty{display:none} - .ssw-seat{min-height:52px;padding:10px 9px;gap:0} - .ssw-six{grid-template-columns:repeat(2,minmax(0,1fr))} - .ssw-six .ssw-seat{min-height:50px;padding:10px 9px} +// src/client/workbench-v2.js +var import_react = require("react"); +var TODAY = () => { + const d = /* @__PURE__ */ new Date(); + d.setHours(0, 0, 0, 0); + return d.getTime(); +}; +var TASK_LABELS = { + draft: "待派发", + dispatched: "已派发", + running: "进行中", + prepared: "待复核", + done: "已完成", + cancelled: "已取消", + failed: "失败", + waiting_user: "待用户批准", + returned: "已退回", + reconfirm: "待重新确认" +}; +var TASK_TONES = { + draft: "idle", + dispatched: "review", + running: "run", + prepared: "review", + done: "done", + cancelled: "idle", + failed: "fail", + waiting_user: "review", + returned: "fail", + reconfirm: "fail" +}; +var OPEN_STATUS = /* @__PURE__ */ new Set(["dispatched", "running", "prepared"]); +var REQ_STATUS_LABELS = { + discussing: "商讨中", + ready: "待发布", + published: "已发布", + returned: "已退回", + cancelled: "已取消" +}; +var REQ_JUDGEMENT_LABELS = { + can_do: "可立项", + needs_discussion: "需商讨", + not_now: "暂不可做" +}; +var WORKFLOW_STAGE_LABELS = { + zhongshu_draft: "中书拟案", + menxia_review: "门下审核", + awaiting_execution_approval: "待用户批准", + shangshu_dispatch: "尚书调度", + department_exec: "六部执行", + menxia_acceptance: "门下验收", + lead_delivery: "丞相交付", + delivered: "已交付", + reconfirm: "待重新确认" +}; +function toneOfSeat(seat) { + if (!seat) return "idle"; + if (seat.status === "bound" || seat.status === "creating") return "run"; + if (seat.status === "failed" || seat.status === "missing") return "fail"; + return "idle"; } +function seatStateText(seat) { + if (!seat) return "待命"; + if (seat.status === "bound") return "运行中"; + if (seat.status === "creating") return "开启中"; + if (seat.status === "missing") return "会话缺失"; + if (seat.status === "failed") return "创建失败"; + return "待命"; +} +function taskTone(status) { + return TASK_TONES[status] || "idle"; +} +function taskLabel(status) { + return TASK_LABELS[status] || status || "未知"; +} +function pad2(n) { + return String(n).padStart(2, "0"); +} +function clockText(ts) { + const n = Number(ts); + if (!Number.isFinite(n) || n <= 0) return "—"; + const d = new Date(n); + return pad2(d.getHours()) + ":" + pad2(d.getMinutes()); +} +function dateText(ts) { + const n = Number(ts); + if (!Number.isFinite(n) || n <= 0) return "—"; + const d = new Date(n); + return d.getMonth() + 1 + "-" + pad2(d.getDate()) + " " + clockText(n); +} +function durationText(ms) { + const n = Number(ms); + if (!Number.isFinite(n) || n <= 0) return "—"; + const total = Math.round(n / 1e3); + const sec = total % 60; + const min = Math.floor(total / 60) % 60; + const hour = Math.floor(total / 3600); + if (hour > 0) return hour + "h " + min + "m"; + if (min > 0) return min + "m " + pad2(sec) + "s"; + return sec + "s"; +} +function dateLabel() { + try { + return new Intl.DateTimeFormat("zh-CN", { weekday: "long", year: "numeric", month: "long", day: "numeric" }).format(/* @__PURE__ */ new Date()); + } catch { + return ""; + } +} +function taskDurationMs(task) { + if (!task) return 0; + const start = Number(task.dispatchedAt || task.createdAt || 0); + const end = task.resultAt ? Number(task.resultAt) : Date.now(); + if (!Number.isFinite(start) || !Number.isFinite(end) || start <= 0 || end <= start) return 0; + return end - start; +} +function shortText(text, max) { + const value = String(text || "").replace(/\s+/g, " ").trim(); + if (!value) return ""; + return value.length > max ? value.slice(0, max - 1) + "…" : value; +} +function splitResultText(text) { + const clean = String(text || "").replace(/\r/g, "").trim(); + if (!clean) return { summary: "", points: [], hasMore: false }; + const lines = clean.split("\n").map((line) => line.trim()).filter(Boolean); + const first = lines[0] || ""; + let summary = first.replace(/^#{1,6}\s*/, ""); + let rest = lines.slice(1); + if (/[。!?!?]/.test(first)) { + const sentences = first.split(/(?<=[。!?!?])/).map((item) => item.trim()).filter(Boolean); + if (sentences.length > 0) { + summary = sentences[0]; + rest = [...sentences.slice(1), ...lines.slice(1)]; + } + } + if (summary.length > 120) summary = summary.slice(0, 119) + "…"; + const bullets = rest.filter((line) => /^([-*•]\s+|\d+[.)、]\s+|[一二三四五六七八九十]+、)/.test(line)).map((line) => line.replace(/^([-*•]\s+|\d+[.)、]\s+|[一二三四五六七八九十]+、)/, "").trim()).filter(Boolean); + const source = bullets.length > 0 ? bullets : rest.flatMap((line) => line.split(/(?<=[。!?!?])/).map((item) => item.trim()).filter(Boolean)); + const points = source.slice(0, 3).map((item) => shortText(item, 90)); + const covered = summary.length + points.join("").length; + return { summary, points, hasMore: clean.length > covered + 12 }; +} +function renderRichText(text) { + const lines = String(text || "").replace(/\r/g, "").split("\n"); + const blocks = []; + let list = []; + let code = null; + const flushList = () => { + if (list.length === 0) return; + blocks.push((0, import_react.createElement)("ul", { className: "rs-list", key: "list-" + blocks.length }, list.map((item, index) => (0, import_react.createElement)("li", { key: index }, item)))); + list = []; + }; + lines.forEach((line) => { + const value = line.trim(); + if (value.startsWith("```")) { + flushList(); + if (code === null) code = []; + else { + blocks.push((0, import_react.createElement)("pre", { className: "rs-code", key: "code-" + blocks.length }, (0, import_react.createElement)("code", null, code.join("\n")))); + code = null; + } + return; + } + if (code !== null) { + code.push(line); + return; + } + if (!value) { + flushList(); + return; + } + if (/^#{1,6}\s+/.test(value)) { + flushList(); + blocks.push((0, import_react.createElement)("h4", { className: "rs-heading", key: "h-" + blocks.length }, value.replace(/^#{1,6}\s+/, ""))); + return; + } + if (/^([-*•]\s+|\d+[.)、]\s+|[一二三四五六七八九十]+、)/.test(value)) { + list.push(value.replace(/^([-*•]\s+|\d+[.)、]\s+|[一二三四五六七八九十]+、)/, "")); + return; + } + flushList(); + if (/^(?:[A-Za-z]:[\\/]|\/|\.{0,2}\/|[\w.-]+[\\/])/.test(value) && !/\s{2,}/.test(value) && value.length <= 260) { + blocks.push((0, import_react.createElement)("code", { className: "rs-path", key: "p-" + blocks.length }, value)); + } else { + blocks.push((0, import_react.createElement)("p", { className: "rs-para", key: "p-" + blocks.length }, value)); + } + }); + flushList(); + if (code !== null) blocks.push((0, import_react.createElement)("pre", { className: "rs-code", key: "code-" + blocks.length }, (0, import_react.createElement)("code", null, code.join("\n")))); + return blocks; +} +function SummaryBlock(props) { + const text = String(props && props.text ? props.text : "").trim(); + const label = props && props.label ? props.label : "摘要"; + const empty = props && props.empty ? props.empty : "(暂无内容)"; + const max = props && props.max ? props.max : 120; + return (0, import_react.createElement)( + "div", + { className: "card-summary" + (text ? "" : " is-empty") }, + label ? (0, import_react.createElement)("span", { className: "t-label" }, label) : null, + (0, import_react.createElement)("p", { className: "card-summary-text" }, text ? shortText(text, max) : empty) + ); +} +function fileIcon(paths, size) { + return (0, import_react.createElement)( + "svg", + { viewBox: "0 0 24 24", width: size || 16, height: size || 16, fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true" }, + paths.map((d, i) => (0, import_react.createElement)("path", { key: i, d })) + ); +} +var RefreshIcon = () => fileIcon(["M21 12a9 9 0 1 1-2.64-6.36", "M21 3v6h-6"]); +var ChatIcon = () => fileIcon(["M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"]); +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 "方案"; + if (id === "menxia") return "审核"; + if (id === "shangshu") return "调度"; + return "工作"; +} +function seatRecordOf(view, id) { + const seats = view && view.project ? view.project.seats : null; + if (Array.isArray(seats)) return seats.find((seat) => seat && seat.id === id) || null; + if (seats && typeof seats === "object") return seats[id] || null; + return null; +} +function fmtModel(rec, options) { + const described = describeModel(rec && rec.model ? rec.model : null, options); + return described.modelLabel; +} +function WorkbenchV2(props) { + const { + onClose, + resolveWorkspace, + navigateToSession, + openRightTab, + selectionCache, + getLastSeatId, + setLastSeatId + } = props || {}; + const [phase, setPhase] = (0, import_react.useState)("loading"); + const [error, setError] = (0, import_react.useState)(null); + const [errorRetryable, setErrorRetryable] = (0, import_react.useState)(true); + const [notice, setNotice] = (0, import_react.useState)(null); + const [view, setView] = (0, import_react.useState)(null); + const [models, setModels] = (0, import_react.useState)(null); + const [selectedSeatId, setSelectedSeatId] = (0, import_react.useState)(() => { + const saved = typeof getLastSeatId === "function" ? getLastSeatId() : null; + return SEAT_IDS.includes(saved) ? saved : SEAT_IDS[0]; + }); + const [tab, setTab] = (0, import_react.useState)("overview"); + const [queueSearch, setQueueSearch] = (0, import_react.useState)(""); + const [selectedTask, setSelectedTask] = (0, import_react.useState)(null); + const [reviewPanelOpen, setReviewPanelOpen] = (0, import_react.useState)(false); + const [durationPanelOpen, setDurationPanelOpen] = (0, import_react.useState)(false); + const [tokenPanelOpen, setTokenPanelOpen] = (0, import_react.useState)(false); + const [queuePanelOpen, setQueuePanelOpen] = (0, import_react.useState)(false); + const [draft, setDraft] = (0, import_react.useState)({}); + const [busy, setBusy] = (0, import_react.useState)(false); + const [summaryBusy, setSummaryBusy] = (0, import_react.useState)(false); + const [memory, setMemory] = (0, import_react.useState)(null); + const [memoryDraft, setMemoryDraft] = (0, import_react.useState)({ goal: "", constraints: "", acceptance: "", decisions: "" }); + const [tasks, setTasks] = (0, import_react.useState)([]); + const [requirements, setRequirements] = (0, import_react.useState)([]); + const [approvals, setApprovals] = (0, import_react.useState)([]); + const [reqView, setReqView] = (0, import_react.useState)("requirements"); + const [artifacts, setArtifacts] = (0, import_react.useState)([]); + const [artifactDraft, setArtifactDraft] = (0, import_react.useState)({ title: "", path: "", summary: "" }); + const [artifactFormOpen, setArtifactFormOpen] = (0, import_react.useState)(false); + const [orgCols, setOrgCols] = (0, import_react.useState)(6); + const alive = (0, import_react.useRef)(true); + const orgRef = (0, import_react.useRef)(null); + (0, import_react.useEffect)(() => { + alive.current = true; + return () => { + alive.current = false; + }; + }, []); + const loadProject = (0, import_react.useCallback)(async () => { + setPhase("loading"); + setError(null); + setErrorRetryable(true); + setNotice(null); + if (typeof resolveWorkspace !== "function") { + setPhase("no-workspace"); + return; + } + const workspace = resolveWorkspace(); + if (!workspace) { + setPhase("no-workspace"); + return; + } + try { + const projectView = await request("open", { workspaceId: workspace.workspaceId, name: workspace.name, path: workspace.path }); + let modelCatalog = null; + try { + modelCatalog = await request("models"); + } catch (modelError) { + console.warn("[sansheng] 模型目录加载失败:", modelError && modelError.message ? modelError.message : modelError); + } + let memoryData = null; + try { + memoryData = (await request("memory", { projectId: projectView.project.id })).memory; + } catch { + } + let taskList = []; + let artifactList = []; + let requirementData = { requirements: [], approvals: [] }; + try { + taskList = (await request("tasks", { projectId: projectView.project.id })).tasks ?? []; + } catch (taskError) { + console.warn("[sansheng] 任务加载失败:", taskError && taskError.message ? taskError.message : taskError); + } + try { + requirementData = await request("requirements", { projectId: projectView.project.id }); + } catch { + } + try { + artifactList = (await request("artifacts", { projectId: projectView.project.id })).artifacts ?? []; + } catch { + } + if (!alive.current) return; + setView(projectView); + setModels(modelCatalog); + setMemory(memoryData); + setMemoryDraft({ goal: memoryData?.goal ?? "", constraints: (memoryData?.constraints ?? []).join("\n"), acceptance: (memoryData?.acceptance ?? []).join("\n"), decisions: "" }); + setTasks(taskList); + setArtifacts(artifactList); + setRequirements(Array.isArray(requirementData.requirements) ? requirementData.requirements : []); + setApprovals(Array.isArray(requirementData.approvals) ? requirementData.approvals : []); + setPhase("ready"); + } catch (loadError) { + if (!alive.current) return; + setError(loadError && loadError.message ? loadError.message : "加载失败"); + setErrorRetryable(!(loadError && loadError.retryable === false)); + setPhase("error"); + } + }, [resolveWorkspace]); + (0, import_react.useEffect)(() => { + 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, requirementData] = await Promise.all([ + request("project", { projectId }), + request("tasks", { projectId }), + request("artifacts", { projectId }), + request("requirements", { projectId }).catch(() => ({ requirements: [], approvals: [] })) + ]); + 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 : []); + setRequirements(Array.isArray(requirementData?.requirements) ? requirementData.requirements : []); + setApprovals(Array.isArray(requirementData?.approvals) ? requirementData.approvals : []); + 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); + if (saved && SEAT_IDS.includes(saved)) setSelectedSeatId(saved); + }, [projectId, selectionCache]); + const wb = buildWorkbenchView(view, { selectedSeatId, models, draft }); + const seatById = (0, import_react.useMemo)(() => { + const map = {}; + for (const seat of wb.seats) map[seat.id] = seat; + return map; + }, [wb.seats]); + (0, import_react.useEffect)(() => { + const node = orgRef.current; + if (!node || typeof ResizeObserver === "undefined") return void 0; + const sync = () => { + const w = node.clientWidth || 0; + setOrgCols(w <= 700 ? 2 : w <= 1180 ? 3 : 6); + }; + sync(); + const observer = new ResizeObserver(sync); + observer.observe(node); + return () => observer.disconnect(); + }, [phase, tab]); + function setSeat(id) { + if (!id || id === selectedSeatId) return; + setSelectedSeatId(id); + if (typeof setLastSeatId === "function") setLastSeatId(id); + if (projectId && selectionCache) selectionCache.set(projectId, id); + } + function setModelValue(value) { + setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value })); + void rememberModel(value, selectedSeatId); + } + function setInstructions(value) { + setDraft((prev) => updateDraft(prev, selectedSeatId, { instructions: value })); + } + function modelFromValue(value) { + const option = findModelOption(wb.selected.modelOptions, value); + if (option) { + return option.reasoningEffort ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } : { provider: option.provider, model: option.model }; + } + const parts = String(value || "").split("::"); + if (parts.length >= 2 && parts[0] && parts[1]) { + return parts[2] ? { provider: parts[0], model: parts[1], reasoningEffort: parts[2] } : { provider: parts[0], model: parts[1] }; + } + return null; + } + async function rememberModel(value, seatId) { + if (!projectId || !value || !seatId) return; + const model = modelFromValue(value); + if (!model) return; + try { + const saved = await request("configure", { projectId, seatId, model }); + if (!alive.current) return; + setView((prev) => { + if (!prev || !prev.project) return prev; + const seats = Array.isArray(prev.project.seats) ? prev.project.seats.map((seat) => seat && seat.id === seatId ? { ...seat, ...saved && saved.seat ? saved.seat : { model } } : seat) : prev.project.seats; + return { ...prev, revision: (prev.revision ?? 0) + 1, project: { ...prev.project, seats } }; + }); + setNotice("已记住「" + (SEATS[seatId]?.label ?? seatId) + "」的模型"); + } catch (error2) { + if (alive.current) setNotice(error2 && error2.message ? error2.message : "模型记忆失败"); + } + } + async function openSeat(seatId) { + const seat = seatById[seatId]; + if (!projectId || !seat) return; + if (seat.status === "missing") { + setNotice("「" + seat.name + "」的会话已不存在,点「重建会话」可重新建立"); + return; + } + if (seat.status !== "bound") { + setNotice("「" + seat.name + "」还没开启,先点「开启『" + seat.name + "』」"); + return; + } + setBusy(true); + setError(null); + try { + const result = await request("openSeat", { projectId, seatId }); + if (!alive.current) return; + if (!result || !result.sessionId) throw new Error("宿主没有返回会话"); + navigateToSession(result.sessionId); + setNotice("已切换到「" + seat.name + "」会话"); + } catch (openError) { + if (alive.current) setError(openError && openError.message ? openError.message : "打开会话失败"); + if (openError && openError.code === "sansheng/session-missing") { + try { + const next = await request("project", { projectId }); + if (alive.current) setView(next); + } catch { + } + } + } finally { + if (alive.current) setBusy(false); + } + } + async function rebuildSeat(seatId) { + const seat = seatById[seatId]; + if (!projectId || !seat) return; + const rec = seatRecordOf(view, seatId); + setBusy(true); + setError(null); + setNotice("正在重建「" + seat.name + "」的会话…"); + try { + const next = await request("rebuildSeat", { projectId, seatId, expectedSessionId: rec && rec.sessionId ? rec.sessionId : void 0 }); + if (!alive.current) return; + setView(next); + setNotice("已重建「" + seat.name + "」的会话;旧会话历史仍保留"); + } catch (rebuildError) { + if (alive.current) setError(rebuildError && rebuildError.message ? rebuildError.message : "重建会话失败"); + if (rebuildError && rebuildError.code === "sansheng/session-conflict") { + try { + const next = await request("project", { projectId }); + if (alive.current) setView(next); + } catch { + } + } + } finally { + if (alive.current) setBusy(false); + } + } + async function enableSeat(seatId) { + if (!projectId) return; + const seat = seatById[seatId]; + setBusy(true); + setError(null); + setNotice("正在开启「" + (seat ? seat.name : seatId) + "」…"); + try { + const next = await request("enableSeat", { projectId, seatId }); + if (!alive.current) return; + setView(next); + setNotice("已开启「" + (seat ? seat.name : seatId) + "」的独立会话"); + try { + if (typeof openRightTab === "function") openRightTab(); + } catch { + } + } catch (enableError) { + if (alive.current) setError(enableError && enableError.message ? enableError.message : "开启失败"); + } finally { + if (alive.current) setBusy(false); + } + } + async function saveConfig() { + if (!projectId) return; + const seatId = wb.selected.id; + const value = wb.selected.modelValue; + if (!value) { + setNotice("请先为当前角色选择模型"); + return; + } + const model = modelFromValue(value); + setBusy(true); + setError(null); + setNotice("保存中…"); + try { + await request("configure", { projectId, seatId, model, instructions: wb.selected.instructions }); + const next = await request("project", { projectId }); + if (!alive.current) return; + setView(next); + setDraft((prev) => clearDraft(prev, seatId)); + setNotice("已保存"); + } catch (saveError) { + if (alive.current) setError(saveError && saveError.message ? saveError.message : "保存失败"); + } finally { + if (alive.current) setBusy(false); + } + } + async function saveMemory() { + if (!projectId) return; + setBusy(true); + setError(null); + setNotice("保存项目共识…"); + try { + const result = await request("memoryUpdate", { + projectId, + expectedRevision: memory?.revision ?? 0, + goal: memoryDraft.goal, + constraints: memoryDraft.constraints.split("\n").map((x) => x.trim()).filter(Boolean), + acceptance: memoryDraft.acceptance.split("\n").map((x) => x.trim()).filter(Boolean), + decisions: memoryDraft.decisions.split("\n").map((x) => x.trim()).filter(Boolean).map((text) => ({ type: "user", status: "active", text, sourceRefs: [] })), + sources: [] + }); + if (!alive.current) return; + setMemory(result.memory); + setMemoryDraft((prev) => ({ ...prev, decisions: "" })); + setNotice("项目共识已保存(v" + result.memory.revision + ")"); + } catch (memoryError) { + if (alive.current) setError(memoryError && memoryError.message ? memoryError.message : "保存项目共识失败"); + } finally { + if (alive.current) setBusy(false); + } + } + async function reloadTasks() { + if (!projectId) return; + try { + const result = await request("tasks", { projectId }); + if (alive.current) setTasks(result.tasks ?? []); + } catch (error2) { + if (alive.current) setNotice(error2 && error2.message ? error2.message : "任务列表刷新失败"); + } + } + async function summarizeByShangshu() { + if (!projectId) return; + setSummaryBusy(true); + setError(null); + try { + const result = await request("shangshuSummary", { projectId }); + if (!alive.current) return; + if (!result || !result.sessionId) throw new Error("宿主没有返回尚书会话"); + setNotice("已请尚书汇总当前任务,正在打开尚书会话…"); + navigateToSession(result.sessionId); + } catch (summaryError) { + if (alive.current) setError(summaryError && summaryError.message ? summaryError.message : "尚书汇总请求失败"); + } finally { + if (alive.current) setSummaryBusy(false); + } + } + async function addArtifact() { + if (!projectId) return; + const title = artifactDraft.title.trim(); + if (!title) { + setNotice("成果名称不能为空"); + return; + } + setBusy(true); + setError(null); + try { + const result = await request("artifactAdd", { projectId, title, path: artifactDraft.path, summary: artifactDraft.summary }); + setArtifacts((list) => [...list, result.artifact]); + setArtifactDraft({ title: "", path: "", summary: "" }); + setArtifactFormOpen(false); + setNotice("成果已登记。"); + } catch (error2) { + if (alive.current) setError(error2 && error2.message ? error2.message : "登记成果失败"); + } finally { + if (alive.current) setBusy(false); + } + } + const todayStart = TODAY(); + const todayTasks = tasks.filter((task) => Number(task.createdAt) >= todayStart); + const todayDone = todayTasks.filter((task) => task.status === "done"); + const reviewTasks = tasks.filter((task) => task.ownerSeatId === "menxia" && OPEN_STATUS.has(task.status)); + const anomalyTasks = tasks.filter((task) => task.status === "failed" || task.deliveryState === "failed"); + const projectDurationMs = tasks.reduce((sum, task) => sum + taskDurationMs(task), 0); + function latestTaskOf(seatId) { + return tasks.filter((task) => task.ownerSeatId === seatId).sort((a, b) => Number(b.updatedAt || b.createdAt || 0) - Number(a.updatedAt || a.createdAt || 0))[0] || null; + } + function tasksOf(seatId) { + return tasks.filter((task) => task.ownerSeatId === seatId).sort((a, b) => Number(b.updatedAt || b.createdAt || 0) - Number(a.updatedAt || a.createdAt || 0)); + } + function selectedSeatRecord(id) { + return seatRecordOf(view, id); + } + function modelLabelOf(id) { + return fmtModel(selectedSeatRecord(id), wb.selected.modelOptions); + } + 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)( + "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 || [] + ); + } + function renderSeatNode(seat) { + const tone = toneOfSeat(seat); + const latest = latestTaskOf(seat.id); + return (0, import_react.createElement)( + "div", + { key: seat.id, className: "node" + (seat.id === selectedSeatId ? " selected" : ""), "data-seat": seat.id }, + (0, import_react.createElement)( + "button", + { type: "button", className: "node-main", onClick: () => setSeat(seat.id), "aria-pressed": seat.id === selectedSeatId ? "true" : "false" }, + (0, import_react.createElement)("span", { className: "node-top" }, (0, import_react.createElement)("span", { className: "node-name" }, seat.name), (0, import_react.createElement)("span", { className: "status " + tone }, (0, import_react.createElement)("i"), seatStateText(seat))), + (0, import_react.createElement)("span", { className: "node-role" }, seat.duty), + (0, import_react.createElement)("span", { className: "node-task" }, (0, import_react.createElement)("span", { className: "t-label" }, "当前任务"), (0, import_react.createElement)("span", { className: "task-text" }, latest ? latest.title : "—")), + (0, import_react.createElement)("span", { className: "node-model" }, "主任模型 ", (0, import_react.createElement)("span", { className: "num" }, modelLabelOf(seat.id))) + ), + (0, import_react.createElement)("div", { className: "node-foot" }, (0, import_react.createElement)("span", { className: "elapsed" }, latest ? taskLabel(latest.status) : seat.status === "bound" ? "在线 · 待命" : "未运行 · 待命")) + ); + } + function reqTone(status) { + if (status === "ready" || status === "published") return "review"; + if (status === "returned") return "fail"; + if (status === "cancelled") return "idle"; + return "run"; + } + function copyRequirementText(text) { + try { + if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") { + void navigator.clipboard.writeText(text).then(() => setNotice("已复制:" + text)).catch(() => { + }); + } + } catch { + } + } + function renderRequirementGate(selected) { + const views = [ + { id: "requirements", label: "需求清单" }, + { id: "flow", label: "流转任务" }, + { id: "delivery", label: "交付结果" } + ]; + const workflowTasks = tasks.filter((task) => task.kind === "workflow" || task.kind === "execution"); + const deliveryTasks = tasks.filter((task) => task.kind === "workflow" && (task.stage === "delivered" || task.status === "done")); + let body; + if (reqView === "flow") { + body = workflowTasks.length ? (0, import_react.createElement)("div", { className: "review-list req-list" }, workflowTasks.map((task) => (0, import_react.createElement)( + "article", + { className: "review-card req-card", key: task.id }, + (0, import_react.createElement)( + "div", + { className: "rc-head" }, + (0, import_react.createElement)("div", { className: "rc-title" }, task.title), + (0, import_react.createElement)("span", { className: "rc-status " + taskTone(task.status) }, (0, import_react.createElement)("i"), taskLabel(task.status)) + ), + (0, import_react.createElement)( + "div", + { className: "req-meta" }, + (0, import_react.createElement)("span", null, task.id), + (0, import_react.createElement)("span", null, SEATS[task.ownerSeatId] && SEATS[task.ownerSeatId].label || task.ownerSeatId || "—"), + (0, import_react.createElement)("span", null, WORKFLOW_STAGE_LABELS[task.stage] || task.stage || "—"), + task.requirementId ? (0, import_react.createElement)("span", null, task.requirementId + " v" + task.requirementRevision) : null, + task.approvalId ? (0, import_react.createElement)("span", null, task.approvalId) : null + ), + (0, import_react.createElement)(SummaryBlock, { text: task.goal || task.requirement || "", label: "任务说明", empty: "(无任务说明)", max: 110 }), + (0, import_react.createElement)(SummaryBlock, { text: task.result || task.note || task.blockedReason || "", label: "当前结果 / 阻塞", empty: "(尚未回报)", max: 110 }), + (0, import_react.createElement)("div", { className: "rc-actions" }, (0, import_react.createElement)("span", { className: "spacer" }), (0, import_react.createElement)("button", { type: "button", className: "r-open", onClick: () => setSelectedTask(task) }, "查看详情 →")) + ))) : (0, import_react.createElement)("p", { className: "empty-note" }, "还没有流转任务。需求发布后会出现在这里。"); + } else if (reqView === "delivery") { + body = deliveryTasks.length ? (0, import_react.createElement)("div", { className: "review-list req-list" }, deliveryTasks.map((task) => { + const children = tasks.filter((item) => item.parentTaskId === task.id && item.kind === "execution"); + return (0, import_react.createElement)( + "article", + { className: "review-card req-card", key: task.id }, + (0, import_react.createElement)("div", { className: "rc-head" }, (0, import_react.createElement)("div", { className: "rc-title" }, task.title), (0, import_react.createElement)("span", { className: "rc-status done" }, (0, import_react.createElement)("i"), "已交付")), + (0, import_react.createElement)("div", { className: "req-meta" }, (0, import_react.createElement)("span", null, task.requirementId || "—"), (0, import_react.createElement)("span", null, "v" + (task.requirementRevision || "—")), (0, import_react.createElement)("span", null, task.id)), + (0, import_react.createElement)(SummaryBlock, { text: task.deliveryNote || task.summary || "", label: "交付说明", empty: "(暂无交付说明)", max: 110 }), + children.length ? (0, import_react.createElement)("div", { className: "req-children" }, children.map((child) => (0, import_react.createElement)( + "div", + { className: "req-child", key: child.id }, + (0, import_react.createElement)("span", { className: "req-child-owner" }, SEATS[child.ownerSeatId] && SEATS[child.ownerSeatId].label || child.ownerSeatId), + (0, import_react.createElement)("span", { className: "rc-status " + taskTone(child.status) }, (0, import_react.createElement)("i"), taskLabel(child.status)), + (0, import_react.createElement)("span", { className: "req-child-result" }, child.result || child.note || "(暂无结果)"), + (0, import_react.createElement)("span", { className: "req-child-session" }, child.resultSessionId ? "结果会话 " + child.resultSessionId : "尚无结果会话") + ))) : null + ); + })) : (0, import_react.createElement)("p", { className: "empty-note" }, "还没有已交付结果。"); + } else { + body = requirements.length ? (0, import_react.createElement)("div", { className: "review-list req-list" }, requirements.map((req) => (0, import_react.createElement)( + "article", + { className: "review-card req-card", key: req.id }, + (0, import_react.createElement)( + "div", + { className: "rc-head" }, + (0, import_react.createElement)("div", { className: "rc-title" }, req.id + " · " + req.title), + (0, import_react.createElement)("span", { className: "rc-status " + reqTone(req.status) }, (0, import_react.createElement)("i"), REQ_STATUS_LABELS[req.status] || req.status) + ), + (0, import_react.createElement)( + "div", + { className: "req-meta" }, + (0, import_react.createElement)("span", null, "v" + req.revision), + (0, import_react.createElement)("span", null, "丞相判断:" + (REQ_JUDGEMENT_LABELS[req.judgement] || req.judgement || "—")), + (0, import_react.createElement)("span", null, "当前阻塞:" + (req.blockedReason || "—")) + ), + (0, import_react.createElement)(SummaryBlock, { text: req.summary || req.originalText || "", label: "摘要", empty: "(暂无摘要)", max: 110 }), + (0, import_react.createElement)(SummaryBlock, { text: req.judgementReason || "", label: "判断理由", empty: "(暂无判断理由)", max: 110 }), + (0, import_react.createElement)( + "details", + { className: "req-details" }, + (0, import_react.createElement)("summary", null, "范围、验收与待补信息"), + (0, import_react.createElement)( + "dl", + { className: "kv" }, + (0, import_react.createElement)("dt", null, "用户原话"), + (0, import_react.createElement)("dd", null, req.originalText || "—"), + (0, import_react.createElement)("dt", null, "范围"), + (0, import_react.createElement)("dd", null, req.scope || "—"), + (0, import_react.createElement)("dt", null, "非目标"), + (0, import_react.createElement)("dd", null, req.nonGoals || "—"), + (0, import_react.createElement)("dt", null, "验收标准"), + (0, import_react.createElement)("dd", null, req.acceptanceCriteria || "—"), + (0, import_react.createElement)("dt", null, "风险"), + (0, import_react.createElement)("dd", null, req.risks || "—"), + (0, import_react.createElement)("dt", null, "依赖"), + (0, import_react.createElement)("dd", null, req.dependencies || "—"), + (0, import_react.createElement)("dt", null, "待补信息"), + (0, import_react.createElement)("dd", null, req.missingInfo || "—") + ) + ), + (0, import_react.createElement)( + "div", + { className: "rc-actions" }, + (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => copyRequirementText(req.id) }, "复制条目编号"), + req.status === "ready" ? (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => copyRequirementText("发布 " + req.id + " 给中书") }, "复制发布命令") : null, + (0, import_react.createElement)("span", { className: "spacer" }) + ) + ))) : (0, import_react.createElement)("p", { className: "empty-note" }, "还没有需求条目。可以先与丞相讨论,尚未发布的内容不会进入执行流程。"); + } + return (0, import_react.createElement)( + "section", + { className: "card req-gate", "aria-label": "丞相需求门控" }, + (0, import_react.createElement)("h3", null, "需求门控 ", (0, import_react.createElement)("span", { className: "seat-tag" }, selected.name)), + (0, import_react.createElement)("p", { className: "foot-note ws-hint" }, "与丞相商讨后,需求会整理到这里。清单条目不会自动执行;在聊天中发送“发布 R-001 给中书”才会立项。"), + (0, import_react.createElement)("div", { className: "req-tabs", role: "tablist" }, views.map((view2) => (0, import_react.createElement)("button", { + key: view2.id, + type: "button", + role: "tab", + "aria-selected": reqView === view2.id, + className: "req-tab" + (reqView === view2.id ? " is-active" : ""), + onClick: () => setReqView(view2.id) + }, view2.label))), + body + ); + } + function renderOverview() { + const stats = [ + (0, import_react.createElement)( + "button", + { type: "button", className: "stat stat-link", key: "cost", onClick: () => setTokenPanelOpen(true) }, + (0, import_react.createElement)("div", { className: "label" }, "消耗金额"), + (0, import_react.createElement)("div", { className: "big" }, (0, import_react.createElement)("em", null, "—"), (0, import_react.createElement)("span", { className: "unit" }, "元")), + (0, import_react.createElement)("div", { className: "foot" }, "Token 统计待接入") + ), + (0, import_react.createElement)( + "button", + { type: "button", className: "stat stat-link", key: "duration", onClick: () => setDurationPanelOpen(true) }, + (0, import_react.createElement)("div", { className: "label" }, "消耗时间"), + (0, import_react.createElement)("div", { className: "big" }, projectDurationMs > 0 ? durationText(projectDurationMs) : "—"), + (0, import_react.createElement)("div", { className: "foot" }, "按任务单程累计") + ), + (0, import_react.createElement)( + "button", + { type: "button", className: "stat stat-link", key: "review", onClick: () => setReviewPanelOpen(true) }, + (0, import_react.createElement)("div", { className: "label" }, "待审核"), + (0, import_react.createElement)("div", { className: "big" }, (0, import_react.createElement)("em", null, String(reviewTasks.length)), " ", (0, import_react.createElement)("span", { className: "unit" }, "件")), + (0, import_react.createElement)("div", { className: "foot" }, "待门下复核") + ), + (0, import_react.createElement)( + "button", + { type: "button", className: "stat stat-link", key: "anomaly", onClick: () => { + setQueueSearch("失败"); + setQueuePanelOpen(true); + } }, + (0, import_react.createElement)("div", { className: "label" }, "异常 / 失败"), + (0, import_react.createElement)("div", { className: "big" }, (0, import_react.createElement)("em", null, String(anomalyTasks.length)), " ", (0, import_react.createElement)("span", { className: "unit" }, "条")), + (0, import_react.createElement)("div", { className: "foot" }, "失败或投递失败") + ) + ]; + const selected = wb.selected; + const selectedLatest = latestTaskOf(selected.id); + const selectedTasks = tasksOf(selected.id); + const selectedToday = todayTasks.filter((task) => task.ownerSeatId === selected.id); + const selectedDone = selectedToday.filter((task) => task.status === "done"); + const excerpt = selectedLatest && (selectedLatest.result || selectedLatest.note) || selected.responsibility; + const actionLabel = selected.status === "bound" ? "开始对话" : selected.status === "missing" ? "重建会话" : "开启「" + selected.name + "」"; + const action = selected.status === "bound" ? () => openSeat(selected.id) : selected.status === "missing" ? () => rebuildSeat(selected.id) : () => enableSeat(selected.id); + const detail = (0, import_react.createElement)( + "section", + { className: "card", "aria-label": "席位详情" }, + (0, import_react.createElement)("div", { className: "detail-head" }, (0, import_react.createElement)("h3", null, "席位详情"), (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy || selected.status === "creating", onClick: action }, (0, import_react.createElement)(ChatIcon), actionLabel)), + (0, import_react.createElement)("div", { className: "detail-name" }, selected.name), + (0, import_react.createElement)("div", { className: "detail-role" }, selected.duty + " · " + selected.statusLabel), + (0, import_react.createElement)( + "dl", + { className: "kv" }, + (0, import_react.createElement)("dt", null, "主任模型"), + (0, import_react.createElement)("dd", null, selected.modelLabel), + (0, import_react.createElement)("dt", null, "当前任务"), + (0, import_react.createElement)("dd", null, selectedLatest ? selectedLatest.title : "—"), + (0, import_react.createElement)("dt", null, "本日派工"), + (0, import_react.createElement)("dd", null, selectedToday.length + " 条 · 完成 " + selectedDone.length), + (0, import_react.createElement)("dt", null, "最近会话"), + (0, import_react.createElement)("dd", null, selected.sessionId ? "已绑定 · " + selected.sessionId.slice(0, 8) : "尚未建立") + ), + (0, import_react.createElement)("div", { className: "excerpt" }, (0, import_react.createElement)(SummaryBlock, { text: excerpt, label: "最近产出", empty: "(暂无产出)", max: 110 })) + ); + const workspace = selected.id === "lead" ? renderRequirementGate(selected) : (0, import_react.createElement)( + "section", + { className: "card", "aria-label": "席位工作区" }, + (0, import_react.createElement)("h3", null, "席位工作区 ", (0, import_react.createElement)("span", { className: "seat-tag" }, selected.name), " ", (0, import_react.createElement)("span", { className: "w-kind" }, seatKind(selected.id))), + selected.id === "shangshu" ? (0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: summaryBusy || busy, onClick: summarizeByShangshu }, summaryBusy ? "汇总中…" : "尚书汇总当前任务")) : null, + (0, import_react.createElement)("p", { className: "foot-note ws-hint" }, "需求请先在聊天中与丞相商讨;明确发布并经用户批准后,由尚书向六部派工;工作台只查看任务与结果。"), + selectedTasks.length === 0 ? (0, import_react.createElement)("p", { className: "empty-note" }, "该席位还没有任务记录。") : (0, import_react.createElement)("div", { className: "review-list" }, selectedTasks.slice(0, 3).map((task) => (0, import_react.createElement)( + "article", + { className: "review-card", key: task.id }, + (0, import_react.createElement)("div", { className: "rc-head" }, (0, import_react.createElement)("div", { className: "rc-title" }, task.title), (0, import_react.createElement)("span", { className: "rc-status " + taskTone(task.status) }, (0, import_react.createElement)("i"), taskLabel(task.status))), + (0, import_react.createElement)(SummaryBlock, { text: task.goal || task.requirement || "", label: "任务说明", empty: "(无任务说明)", max: 110 }), + (0, import_react.createElement)(SummaryBlock, { text: task.result || taskLabel(task.status), label: "任务完成情况", empty: "(暂无结果)", max: 110 }), + (0, import_react.createElement)( + "div", + { className: "rc-actions" }, + (0, import_react.createElement)("span", { className: "spacer" }), + (0, import_react.createElement)("button", { type: "button", className: "r-open", onClick: () => setSelectedTask(task) }, "查看详情 →") + ) + ))) + ); + const modelChoices = []; + const seenModels = /* @__PURE__ */ new Set(); + for (const option of selected.modelOptions) { + const key = option.provider + "::" + option.model; + if (seenModels.has(key)) continue; + seenModels.add(key); + modelChoices.push({ value: key, label: option.model, provider: option.provider, model: option.model }); + } + const valueParts = String(selected.modelValue || "").split("::"); + const currentProvider = valueParts[0] || ""; + const currentModel = valueParts[1] || ""; + const currentModelValue = currentProvider && currentModel ? currentProvider + "::" + currentModel : ""; + if (currentModelValue && !seenModels.has(currentModelValue)) { + modelChoices.unshift({ value: currentModelValue, label: currentModel, provider: currentProvider, model: currentModel }); + } + const effortChoices = []; + for (const option of selected.modelOptions) { + if (option.provider !== currentProvider || option.model !== currentModel || !option.reasoningEffort) continue; + if (!effortChoices.includes(option.reasoningEffort)) effortChoices.push(option.reasoningEffort); + } + const currentEffort = valueParts[2] || ""; + if (currentEffort && !effortChoices.includes(currentEffort)) effortChoices.unshift(currentEffort); + const configCard = (0, import_react.createElement)( + "details", + { className: "card dept-config-card", "aria-label": "部门配置" }, + (0, import_react.createElement)("summary", null, (0, import_react.createElement)("span", null, "部门配置"), (0, import_react.createElement)("span", { className: "seat-tag" }, selected.name)), + (0, import_react.createElement)( + "div", + { className: "dept-config-body" }, + (0, import_react.createElement)( + "div", + { className: "cfg-grid" }, + (0, import_react.createElement)("label", { className: "cfg-row" }, "主任模型", (0, import_react.createElement)( + "select", + { value: currentModelValue, onChange: (event) => setModelValue(event.target.value) }, + (0, import_react.createElement)("option", { value: "" }, "请选择模型"), + modelChoices.map((option) => (0, import_react.createElement)("option", { key: option.value, value: option.value }, option.label)) + )), + (0, import_react.createElement)("label", { className: "cfg-row" }, "推理等级", (0, import_react.createElement)( + "select", + { + value: currentEffort, + disabled: effortChoices.length === 0, + title: effortChoices.length === 0 ? "当前模型目录未提供可调推理等级" : void 0, + onChange: (event) => setModelValue(event.target.value ? currentProvider + "::" + currentModel + "::" + event.target.value : currentModelValue) + }, + effortChoices.length === 0 ? (0, import_react.createElement)("option", { value: "" }, "默认(模型固定)") : [(0, import_react.createElement)("option", { key: "default", value: "" }, "默认"), ...effortChoices.map((effort) => (0, import_react.createElement)("option", { key: effort, value: effort }, effort))] + )), + (0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "角色补充说明", (0, import_react.createElement)("textarea", { + rows: 3, + className: "ssv-textarea", + value: selected.instructions, + placeholder: "仅对该席位追加的补充说明", + onChange: (event) => setInstructions(event.target.value) + })) + ), + (0, import_react.createElement)( + "div", + { className: "cfg-skills" }, + (0, import_react.createElement)("span", { className: "t-label" }, "技能绑定"), + (0, import_react.createElement)( + "ul", + { className: "skill-list" }, + (0, import_react.createElement)("li", null, (0, import_react.createElement)("span", { className: "skill-name" }, "真实会话绑定"), (0, import_react.createElement)("span", { className: "skill-state" + (selected.status === "bound" ? " bound" : "") }, (0, import_react.createElement)("i"), selected.status === "bound" ? "已绑定" : "未绑定")), + (0, import_react.createElement)("li", null, (0, import_react.createElement)("span", { className: "skill-name" }, "工作台派工工具"), (0, import_react.createElement)("span", { className: "skill-state" + (selected.status === "bound" ? " bound" : "") }, (0, import_react.createElement)("i"), selected.status === "bound" ? "可用" : "待开启")), + (0, import_react.createElement)("li", null, (0, import_react.createElement)("span", { className: "skill-name" }, "职责"), (0, import_react.createElement)("span", { className: "skill-state bound" }, (0, import_react.createElement)("i"), selected.duty)) + ) + ), + (0, import_react.createElement)( + "div", + { className: "ws-actions" }, + (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: saveConfig }, busy ? "保存中…" : "保存配置"), + selected.status !== "bound" ? (0, import_react.createElement)("button", { type: "button", className: "btn", disabled: busy, onClick: action }, actionLabel) : null + ) + ) + ); + return (0, import_react.createElement)( + "div", + { className: "page" }, + renderTopbar("总览", [ + (0, import_react.createElement)( + "button", + { type: "button", className: "btn primary btn-cx", onClick: () => { + setSeat("lead"); + if (seatById.lead.status === "bound") void openSeat("lead"); + else setTab("settings"); + } }, + (0, import_react.createElement)("span", { className: "cx-name" }, "丞相"), + (0, import_react.createElement)("span", { className: "cx-dot", "aria-hidden": "true" }), + (0, import_react.createElement)("span", { className: "cx-state" }, seatStateText(seatById.lead)) + ) + ]), + (0, import_react.createElement)("section", { className: "stats", "aria-label": "关键指标" }, stats), + (0, import_react.createElement)( + "section", + { "aria-label": "席位谱系", style: { marginTop: "22px" } }, + (0, import_react.createElement)("div", { className: "panel-head" }, (0, import_react.createElement)("h2", null, "席位谱系")), + (0, import_react.createElement)("div", { id: "orgTree", ref: orgRef }, (0, import_react.createElement)( + "div", + { className: "org-rows", "data-cols": String(orgCols) }, + (0, import_react.createElement)("div", { className: "org-row org-row-3" }, wb.groups.sansheng.map((id) => (0, import_react.createElement)("div", { className: "org-cell", key: id, "data-slot": id }, renderSeatNode(seatById[id])))), + (0, import_react.createElement)( + "div", + { className: "org-wires org-wires-2", "aria-hidden": "true" }, + (0, import_react.createElement)("span", { className: "wire-v", style: { left: "50%", top: 0, height: 11 } }), + (0, import_react.createElement)("span", { className: "wire-h", style: { left: "8.3333%", right: "8.3333%", top: 11 } }), + ...[8.3333, 25, 41.6667, 58.3333, 75, 91.6667].map((left, i) => (0, import_react.createElement)("span", { key: i, className: "wire-v w2-b" + (i + 1), style: { left: left + "%", top: 11, height: 11 } })) + ), + (0, import_react.createElement)("div", { className: "org-row org-row-6" }, wb.groups.liubu.map((id) => (0, import_react.createElement)("div", { className: "org-cell", key: id, "data-slot": id }, renderSeatNode(seatById[id])))) + )) + ), + (0, import_react.createElement)("div", { className: "grid" }, (0, import_react.createElement)("div", { className: "detail-col" }, detail, workspace), (0, import_react.createElement)("div", { className: "rail" }, configCard)), + (0, import_react.createElement)("p", { className: "foot-note" }, "数据来自当前项目真实会话 · " + (wb.project.boundCount + " / " + wb.project.seatCount + " 席已启用")) + ); + } + function renderQueuePanel() { + if (!queuePanelOpen) return null; + const query = queueSearch.trim().toLowerCase(); + const filtered = tasks.filter((task) => { + if (!query) return true; + const seatName = SEATS[task.ownerSeatId]?.label || task.ownerSeatId || ""; + const haystack = [task.title, seatName, task.id, task.goal, task.requirement, task.result, taskLabel(task.status), task.deliveryState === "failed" ? "投递失败" : ""].filter(Boolean).join(" ").toLowerCase(); + return haystack.includes(query); + }); + const openTask = (task) => { + setQueuePanelOpen(false); + setSelectedTask(task); + }; + return (0, import_react.createElement)( + "div", + { className: "modal-backdrop", onClick: (event) => { + if (event.target === event.currentTarget) setQueuePanelOpen(false); + } }, + (0, import_react.createElement)( + "div", + { className: "modal wide", role: "dialog", "aria-modal": "true", "aria-labelledby": "ssv-queue-title" }, + (0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", { id: "ssv-queue-title" }, "派工队列"), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setQueuePanelOpen(false) }, "✕")), + (0, import_react.createElement)( + "div", + { className: "modal-toolbar" }, + (0, import_react.createElement)("label", { className: "search" }, (0, import_react.createElement)(SearchIcon), (0, import_react.createElement)("input", { type: "search", value: queueSearch, placeholder: "搜索派工记录…", "aria-label": "搜索派工队列", onChange: (event) => setQueueSearch(event.target.value) })), + (0, import_react.createElement)("button", { type: "button", className: "btn", disabled: summaryBusy || busy, onClick: summarizeByShangshu }, summaryBusy ? "汇总中…" : "尚书汇总"), + (0, import_react.createElement)("button", { type: "button", className: "btn", disabled: busy, onClick: reloadTasks }, (0, import_react.createElement)(RefreshIcon), "刷新") + ), + (0, import_react.createElement)( + "div", + { className: "queue-table-wrap" }, + (0, import_react.createElement)("div", { className: "table-scroll" }, (0, import_react.createElement)( + "table", + null, + (0, import_react.createElement)("thead", null, (0, import_react.createElement)("tr", null, ["任务", "承办席位", "状态", "结果", "耗时", "派发时间"].map((label) => (0, import_react.createElement)("th", { key: label, scope: "col" }, label)))), + (0, import_react.createElement)("tbody", null, filtered.map((task) => (0, import_react.createElement)( + "tr", + { key: task.id, className: "clickable", tabIndex: 0, onClick: () => openTask(task), onKeyDown: (event) => { + if (event.key === "Enter") openTask(task); + } }, + (0, import_react.createElement)("td", null, (0, import_react.createElement)("span", { className: "task-name" }, task.title), (0, import_react.createElement)("br"), (0, import_react.createElement)("span", { className: "task-id" }, task.id)), + (0, import_react.createElement)("td", null, SEATS[task.ownerSeatId]?.label || task.ownerSeatId || "—"), + (0, import_react.createElement)("td", null, (0, import_react.createElement)("span", { className: "pill " + taskTone(task.status) }, (0, import_react.createElement)("i"), taskLabel(task.status)), task.deliveryState === "failed" ? (0, import_react.createElement)("span", { className: "pill fail", style: { marginLeft: "4px" } }, (0, import_react.createElement)("i"), "投递失败") : null), + (0, import_react.createElement)("td", { className: "result-cell" }, task.result ? shortText(task.result, 42) : "—"), + (0, import_react.createElement)("td", { className: "dur" }, taskDurationMs(task) > 0 ? durationText(taskDurationMs(task)) : "—"), + (0, import_react.createElement)("td", { className: "time" }, task.dispatchedAt ? dateText(task.dispatchedAt) : "—") + ))) + )), + (0, import_react.createElement)("p", { className: "foot-note" }, filtered.length === 0 ? "没有匹配的派工记录,换个关键词试试。" : "共 " + filtered.length + " 条派工记录。") + ) + ) + ); + } + function renderMemory() { + const constraints = Array.isArray(memory?.constraints) ? memory.constraints : []; + const acceptance = Array.isArray(memory?.acceptance) ? memory.acceptance : []; + const decisions = Array.isArray(memory?.decisions) ? memory.decisions : []; + const item = (title, meta, body, tone) => (0, import_react.createElement)( + "article", + { className: "review-card", key: title }, + (0, import_react.createElement)("div", { className: "rc-head" }, (0, import_react.createElement)("div", { className: "rc-title" }, title), (0, import_react.createElement)("span", { className: "rc-status " + (tone || "pass") }, (0, import_react.createElement)("i"), "现行")), + (0, import_react.createElement)("div", { className: "rc-meta-row" }, (0, import_react.createElement)("span", { className: "rc-from" }, "项目共识"), (0, import_react.createElement)("span", { className: "rc-meta" }, meta)), + (0, import_react.createElement)("div", { className: "rc-excerpt" }, body || "(暂无)") + ); + return (0, import_react.createElement)( + "div", + { className: "page" }, + renderTopbar("记忆", [ + (0, import_react.createElement)("span", { className: "date" }, (wb.project.name || "项目") + " · 项目共识 v" + (memory?.revision ?? 0)) + ]), + (0, import_react.createElement)( + "div", + { className: "settings-stack" }, + (0, import_react.createElement)( + "section", + { className: "card", "aria-label": "项目共识" }, + (0, import_react.createElement)("h3", null, "项目共识 ", (0, import_react.createElement)("span", { className: "seat-tag" }, "v" + (memory?.revision ?? 0))), + (0, import_react.createElement)( + "div", + { className: "review-list" }, + item("项目目标", "goal", memory?.goal || "尚未填写项目目标", "pass"), + item("硬约束", (constraints.length || 0) + " 条", constraints.join(";"), constraints.length ? "pass" : "idle"), + item("验收标准", (acceptance.length || 0) + " 条", acceptance.join(";"), acceptance.length ? "pass" : "idle"), + ...decisions.slice(-5).map((decision, index) => item(decision.text || "决定 " + (index + 1), decision.recordedAt ? dateText(decision.recordedAt) : "项目记录", decision.status === "active" ? "现行决定" : "已归档", "pass")) + ) + ), + (0, import_react.createElement)( + "details", + { className: "card memory-editor", "aria-label": "编辑项目共识" }, + (0, import_react.createElement)("summary", null, (0, import_react.createElement)("span", null, "编辑项目共识"), (0, import_react.createElement)("span", { className: "seat-tag" }, "可折叠")), + (0, import_react.createElement)( + "div", + { className: "cfg-grid" }, + (0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "项目目标", (0, import_react.createElement)("textarea", { rows: 3, className: "ssv-textarea", value: memoryDraft.goal, placeholder: "这个项目最终要达成什么", onChange: (event) => setMemoryDraft({ ...memoryDraft, goal: event.target.value }) })), + (0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "硬约束(每行一条)", (0, import_react.createElement)("textarea", { rows: 3, className: "ssv-textarea", value: memoryDraft.constraints, placeholder: "例如:不能改动线上数据", onChange: (event) => setMemoryDraft({ ...memoryDraft, constraints: event.target.value }) })), + (0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "验收标准(每行一条)", (0, import_react.createElement)("textarea", { rows: 3, className: "ssv-textarea", value: memoryDraft.acceptance, placeholder: "例如:交付前必须跑完回归测试", onChange: (event) => setMemoryDraft({ ...memoryDraft, acceptance: event.target.value }) })), + (0, import_react.createElement)("label", { className: "cfg-row", style: { gridColumn: "1 / -1" } }, "新增决定(每行一条)", (0, import_react.createElement)("textarea", { rows: 2, className: "ssv-textarea", value: memoryDraft.decisions, placeholder: "例如:先保证稳定性,再考虑样式", onChange: (event) => setMemoryDraft({ ...memoryDraft, decisions: event.target.value }) })) + ), + (0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: saveMemory }, busy ? "保存中…" : "保存共识")) + ), + (0, import_react.createElement)( + "section", + { className: "card", "aria-label": "成果" }, + (0, import_react.createElement)("h3", null, "成果登记 ", (0, import_react.createElement)("span", { className: "seat-tag" }, String(artifacts.length))), + (0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setArtifactFormOpen(true) }, (0, import_react.createElement)(PlusIcon), "登记成果")), + artifacts.length === 0 ? (0, import_react.createElement)("p", { className: "empty-note" }, "还没有登记成果。") : (0, import_react.createElement)("ul", { className: "skill-list" }, artifacts.slice(0, 8).map((artifact) => (0, import_react.createElement)("li", { key: artifact.id }, (0, import_react.createElement)("span", { className: "skill-name" }, artifact.title), (0, import_react.createElement)("span", { className: "skill-state bound" }, (0, import_react.createElement)("i"), artifact.path || "已登记")))) + ) + ) + ); + } + function renderSettings() { + return (0, import_react.createElement)( + "div", + { className: "page" }, + renderTopbar("设置"), + (0, import_react.createElement)( + "div", + { className: "settings-stack" }, + (0, import_react.createElement)( + "section", + { className: "card", "aria-label": "项目绑定" }, + (0, import_react.createElement)("h3", null, "项目绑定"), + (0, import_react.createElement)( + "dl", + { className: "kv" }, + (0, import_react.createElement)("dt", null, "当前项目"), + (0, import_react.createElement)("dd", null, wb.project.name || "未命名项目"), + (0, import_react.createElement)("dt", null, "类型"), + (0, import_react.createElement)("dd", null, "主项目"), + (0, import_react.createElement)("dt", null, "席位"), + (0, import_react.createElement)("dd", null, wb.project.seatCount + " 席"), + (0, import_react.createElement)("dt", null, "工作区"), + (0, import_react.createElement)("dd", null, wb.project.workspaceId || "—") + ) + ), + (0, import_react.createElement)( + "section", + { className: "card", "aria-label": "席位开关" }, + (0, import_react.createElement)("h3", null, "席位开关"), + (0, import_react.createElement)("ul", { className: "skill-list" }, SEAT_IDS.map((id) => { + const seat = seatById[id]; + const online = seat.status === "bound"; + return (0, import_react.createElement)( + "li", + { key: id }, + (0, import_react.createElement)("span", { className: "skill-name" }, seat.name + " · " + seat.duty), + (0, import_react.createElement)("span", { className: "skill-state" + (online ? " bound" : "") }, (0, import_react.createElement)("i"), online ? "已上线" : seat.status === "missing" ? "会话缺失" : "未上线"), + (0, import_react.createElement)("button", { type: "button", className: "skill-toggle", disabled: busy, onClick: () => { + if (seat.status === "missing") void rebuildSeat(id); + else if (online) void openSeat(id); + else void enableSeat(id); + } }, seat.status === "missing" ? "重建" : online ? "打开" : "上线") + ); + })) + ), + (0, import_react.createElement)( + "section", + { className: "card", "aria-label": "角色职责" }, + (0, import_react.createElement)("h3", null, "角色职责"), + (0, import_react.createElement)("ul", { className: "skill-list" }, SEAT_IDS.map((id) => (0, import_react.createElement)( + "li", + { key: id }, + (0, import_react.createElement)("span", { className: "skill-name" }, (0, import_react.createElement)("b", null, SEATS[id].label)), + (0, import_react.createElement)("span", { className: "skill-state bound" }, (0, import_react.createElement)("i"), SEATS[id].duty), + (0, import_react.createElement)("span", { className: "rc-meta" }, modelLabelOf(id)) + ))) + ) + ) + ); + } + function renderReviewPanel() { + if (!reviewPanelOpen) return null; + return (0, import_react.createElement)( + "div", + { className: "modal-backdrop", onClick: (event) => { + if (event.target === event.currentTarget) setReviewPanelOpen(false); + } }, + (0, import_react.createElement)( + "div", + { className: "modal wide", role: "dialog", "aria-modal": "true", "aria-labelledby": "ssv-review-title" }, + (0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", { id: "ssv-review-title" }, "待审核 · 门下复核"), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setReviewPanelOpen(false) }, "✕")), + (0, import_react.createElement)("p", { className: "foot-note" }, "只读展示当前待门下复核的任务。"), + reviewTasks.length === 0 ? (0, import_react.createElement)("p", { className: "empty-note" }, "当前没有待审核任务。") : (0, import_react.createElement)("div", { className: "review-list" }, reviewTasks.map((task) => (0, import_react.createElement)( + "article", + { className: "review-card", key: task.id }, + (0, import_react.createElement)("div", { className: "rc-head" }, (0, import_react.createElement)("div", { className: "rc-title" }, task.title), (0, import_react.createElement)("span", { className: "rc-status " + taskTone(task.status) }, (0, import_react.createElement)("i"), taskLabel(task.status))), + (0, import_react.createElement)("div", { className: "rc-meta-row" }, (0, import_react.createElement)("span", { className: "rc-from" }, task.id || "—"), (0, import_react.createElement)("span", { className: "rc-meta" }, task.dispatchedAt ? "派发 " + dateText(task.dispatchedAt) : "尚未派发")), + (0, import_react.createElement)(SummaryBlock, { text: task.result || task.goal || task.requirement || "", label: "审核材料", empty: "(暂无内容)", max: 110 }), + (0, import_react.createElement)("div", { className: "rc-actions" }, (0, import_react.createElement)("span", { className: "spacer" }), (0, import_react.createElement)("button", { type: "button", className: "r-open", onClick: () => { + setReviewPanelOpen(false); + setSelectedTask(task); + } }, "查看任务 →")) + ))) + ) + ); + } + function renderDurationPanel() { + if (!durationPanelOpen) return null; + const rows = tasks.map((task) => ({ task, ms: taskDurationMs(task) })).filter((row) => row.ms > 0).sort((a, b) => b.ms - a.ms); + return (0, import_react.createElement)( + "div", + { className: "modal-backdrop", onClick: (event) => { + if (event.target === event.currentTarget) setDurationPanelOpen(false); + } }, + (0, import_react.createElement)( + "div", + { className: "modal wide", role: "dialog", "aria-modal": "true", "aria-labelledby": "ssv-duration-title" }, + (0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", { id: "ssv-duration-title" }, "单任务耗时"), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setDurationPanelOpen(false) }, "✕")), + (0, import_react.createElement)("p", { className: "foot-note" }, "按任务从派发到完成的时间累计;进行中任务算到当前时刻。"), + rows.length === 0 ? (0, import_react.createElement)("p", { className: "empty-note" }, "还没有可统计的任务耗时。") : (0, import_react.createElement)("div", { className: "table-card" }, (0, import_react.createElement)("div", { className: "table-scroll" }, (0, import_react.createElement)( + "table", + null, + (0, import_react.createElement)("thead", null, (0, import_react.createElement)("tr", null, ["任务", "承办", "状态", "耗时"].map((label) => (0, import_react.createElement)("th", { key: label, scope: "col" }, label)))), + (0, import_react.createElement)("tbody", null, rows.map((row) => (0, import_react.createElement)( + "tr", + { key: row.task.id }, + (0, import_react.createElement)("td", null, (0, import_react.createElement)("span", { className: "task-name" }, row.task.title)), + (0, import_react.createElement)("td", null, SEATS[row.task.ownerSeatId]?.label || row.task.ownerSeatId || "—"), + (0, import_react.createElement)("td", null, (0, import_react.createElement)("span", { className: "pill " + taskTone(row.task.status) }, (0, import_react.createElement)("i"), taskLabel(row.task.status))), + (0, import_react.createElement)("td", { className: "dur" }, durationText(row.ms)) + ))) + ))) + ) + ); + } + function renderTokenPanel() { + if (!tokenPanelOpen) return null; + return (0, import_react.createElement)( + "div", + { className: "modal-backdrop", onClick: (event) => { + if (event.target === event.currentTarget) setTokenPanelOpen(false); + } }, + (0, import_react.createElement)( + "div", + { className: "modal wide", role: "dialog", "aria-modal": "true", "aria-labelledby": "ssv-token-title" }, + (0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", { id: "ssv-token-title" }, "Token 用量"), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setTokenPanelOpen(false) }, "✕")), + (0, import_react.createElement)( + "section", + { className: "stats", style: { marginTop: "16px" }, "aria-label": "Token 统计" }, + (0, import_react.createElement)("div", { className: "stat" }, (0, import_react.createElement)("div", { className: "label" }, "Token 消耗"), (0, import_react.createElement)("div", { className: "big" }, (0, import_react.createElement)("em", null, "—")), (0, import_react.createElement)("div", { className: "foot" }, "待接入宿主 usage 数据")), + (0, import_react.createElement)("div", { className: "stat" }, (0, import_react.createElement)("div", { className: "label" }, "上下文占用"), (0, import_react.createElement)("div", { className: "big" }, (0, import_react.createElement)("em", null, "—")), (0, import_react.createElement)("div", { className: "foot" }, "统计粒度待定:项目 / 会话 / 席位")) + ), + (0, import_react.createElement)( + "section", + { className: "card", style: { marginTop: "18px" }, "aria-label": "Token 接入说明" }, + (0, import_react.createElement)("h3", null, "接入说明"), + (0, import_react.createElement)("p", { className: "foot-note", style: { marginTop: "8px" } }, "当前宿主尚未提供稳定的 usage 数据源,这里先占位,不展示估算值,避免假精确。接入真实用量后会展示 Token 消耗、上下文占用和消耗金额。") + ) + ) + ); + } + function renderArtifactModal() { + if (!artifactFormOpen) return null; + return (0, import_react.createElement)( + "div", + { className: "modal-backdrop", onClick: (event) => { + if (event.target === event.currentTarget) setArtifactFormOpen(false); + } }, + (0, import_react.createElement)( + "div", + { className: "modal", role: "dialog", "aria-modal": "true", "aria-labelledby": "ssv-artifact-title" }, + (0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", { id: "ssv-artifact-title" }, "登记成果"), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setArtifactFormOpen(false) }, "✕")), + (0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "成果名称"), (0, import_react.createElement)("input", { type: "text", value: artifactDraft.title, placeholder: "例如:竞品分析报告 v1", onChange: (event) => setArtifactDraft({ ...artifactDraft, title: event.target.value }) })), + (0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "文件路径"), (0, import_react.createElement)("input", { type: "text", value: artifactDraft.path, placeholder: "例如:docs/竞品分析.md", onChange: (event) => setArtifactDraft({ ...artifactDraft, path: event.target.value }) })), + (0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "摘要"), (0, import_react.createElement)("textarea", { rows: 3, value: artifactDraft.summary, placeholder: "这份成果解决了什么、在哪里", onChange: (event) => setArtifactDraft({ ...artifactDraft, summary: event.target.value }) })), + (0, import_react.createElement)("div", { className: "modal-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", disabled: busy, onClick: addArtifact }, busy ? "提交中…" : "登记"), (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setArtifactFormOpen(false) }, "取消")) + ) + ); + } + function renderTaskDetail() { + if (!selectedTask) return null; + const task = selectedTask; + const seat = SEATS[task.ownerSeatId]; + return (0, import_react.createElement)( + "div", + { className: "modal-backdrop", onClick: (event) => { + if (event.target === event.currentTarget) setSelectedTask(null); + } }, + (0, import_react.createElement)( + "div", + { className: "modal wide", role: "dialog", "aria-modal": "true" }, + (0, import_react.createElement)("div", { className: "modal-head" }, (0, import_react.createElement)("h3", null, task.title), (0, import_react.createElement)("button", { type: "button", className: "modal-close", "aria-label": "关闭", onClick: () => setSelectedTask(null) }, "✕")), + (0, import_react.createElement)("div", { className: "m-from" }, "派工编号:" + (task.id || "—") + " · " + (task.dispatchedAt ? "派发时间 " + dateText(task.dispatchedAt) : "尚未派发")), + (0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "任务说明"), (0, import_react.createElement)("div", { className: "m-rich" }, task.goal || task.requirement ? renderRichText(task.goal || task.requirement) : (0, import_react.createElement)("p", { className: "empty-note" }, "(无任务说明)"))), + (0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "承办与状态"), (0, import_react.createElement)("p", null, "承办席位:" + (seat ? seat.label : task.ownerSeatId) + " · 模型:" + modelLabelOf(task.ownerSeatId) + " · 状态:" + taskLabel(task.status) + (task.deliveryState === "failed" ? " · 投递失败" : ""))), + (0, import_react.createElement)("div", { className: "m-sec" }, (0, import_react.createElement)("span", { className: "t-label" }, "任务完成情况"), (0, import_react.createElement)("div", { className: "m-rich" }, task.result ? renderRichText(task.result) : (0, import_react.createElement)("p", { className: "empty-note" }, "(暂无结果)"))), + (0, import_react.createElement)("div", { className: "modal-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn", onClick: () => setSelectedTask(null) }, "关闭")) + ) + ); + } + function renderPage() { + if (phase === "loading") return (0, import_react.createElement)("div", { className: "page" }, (0, import_react.createElement)("p", { className: "empty-note" }, "正在载入工作台…")); + if (phase === "no-workspace") return (0, import_react.createElement)("div", { className: "page" }, (0, import_react.createElement)("p", { className: "empty-note" }, "请先在宿主中选择或建立一个项目工作区,再打开三省六部工作台。")); + if (phase === "error" && !view) return (0, import_react.createElement)("div", { className: "page" }, (0, import_react.createElement)("p", { className: "ssv-banner is-error", role: "alert" }, error || "工作台加载失败"), errorRetryable ? (0, import_react.createElement)("div", { className: "ws-actions" }, (0, import_react.createElement)("button", { type: "button", className: "btn primary", onClick: loadProject }, "重试")) : null); + if (tab === "memory") return renderMemory(); + if (tab === "settings") return renderSettings(); + return renderOverview(); + } + return (0, import_react.createElement)( + "div", + { className: "ssv2 ssw-tab-body" }, + (0, import_react.createElement)( + "div", + { className: "main" }, + (0, import_react.createElement)( + "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" }, "⌄") + ) + ) + ), + renderArtifactModal(), + renderTaskDetail(), + renderReviewPanel(), + renderDurationPanel(), + renderQueuePanel(), + renderTokenPanel() + ); +} + +// src/client/workspace.js +function samePath(a, b) { + if (typeof a !== "string" || typeof b !== "string") return false; + const norm = (value) => value.replace(/\//g, "\\").replace(/\\+$/g, "").toLowerCase(); + return norm(a) === norm(b); +} +function baseName(path) { + if (typeof path !== "string") return void 0; + const parts = path.replace(/\/+$/g, "").split(/[\\/]/).filter(Boolean); + return parts.length ? parts[parts.length - 1] : void 0; +} +function normalizeWorkspaceItem(item) { + if (!item || typeof item !== "object") return null; + const workspaceId = item.workspaceId ?? item.id ?? null; + if (typeof workspaceId !== "string" || !workspaceId) return null; + return { + workspaceId, + name: typeof item.name === "string" ? item.name : typeof item.title === "string" ? item.title : void 0, + path: typeof item.path === "string" ? item.path : void 0, + sessionIds: Array.isArray(item.sessionIds) ? item.sessionIds : void 0 + }; +} +function workspaceItemsFromSnapshot(snapshot) { + const items = Array.isArray(snapshot) ? snapshot : snapshot && typeof snapshot === "object" && Array.isArray(snapshot.items) ? snapshot.items : []; + return items.map(normalizeWorkspaceItem).filter(Boolean); +} +function sessionSummaryFromSnapshot(snapshot, sessionId) { + if (!snapshot || typeof snapshot !== "object" || typeof sessionId !== "string" || !sessionId) return null; + const byId = snapshot.byId; + if (!byId || typeof byId !== "object") return null; + const summary = byId[sessionId]; + return summary && typeof summary === "object" ? summary : null; +} +function workspaceForSession(items, sessionId, sessionSummary) { + const list = (Array.isArray(items) ? items : []).map(normalizeWorkspaceItem).filter(Boolean); + if (typeof sessionId !== "string" || !sessionId) return null; + const bySession = list.find((item) => Array.isArray(item.sessionIds) && item.sessionIds.includes(sessionId)); + if (bySession) return bySession; + const cwd = sessionSummary && typeof sessionSummary.cwd === "string" ? sessionSummary.cwd : ""; + if (!cwd) return null; + const byPath = list.find((item) => item.path && samePath(item.path, cwd)); + if (byPath) return byPath; + return { workspaceId: null, name: baseName(cwd), path: cwd, sessionIds: [sessionId] }; +} + +// src/client/styles.js +var CSS = `.ssv2{ + /* ============ shadcn 式干净后台:平整、利落、高对比 ============ + 侧边栏 + 统计卡 + 表格的标准后台骨架,全页统一平整处理: + 白/浅灰底、1px 细边框、小圆角、无凸凹阴影、无拟物。 + 钴蓝只给选中态、主按钮与关键数字,其余用中性灰阶分层。 */ + + & { + color-scheme: light dark; + --bg: #ffffff; + --sidebar-bg: #fafafa; + --panel: #ffffff; + --panel-line: #e4e4e7; + --muted-bg: #f4f4f5; + --ink: #09090b; + --ink-2: #3f3f46; + --muted: #71717a; + --cobalt: #1e40d8; + --cobalt-ink: #17319f; + --cobalt-soft: rgba(30, 64, 216, .08); + --on-accent: #ffffff; + --ok: #2e7d4f; + --warn: #b06a12; + --bad: #b3372c; + --radius-panel: 8px; + --radius-control: 8px; + --font-ui: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; + --font-seat: "Noto Serif SC", "Songti SC", serif; + --font-num: "IBM Plex Mono", ui-monospace, "SF Mono", monospace; + } + @media (prefers-color-scheme: dark) { + & { + --bg: #09090b; + --sidebar-bg: #0c0c0e; + --panel: #18181b; + --panel-line: #27272a; + --muted-bg: #27272a; + --ink: #fafafa; + --ink-2: #d4d4d8; + --muted: #a1a1aa; + --cobalt: #829cff; + --cobalt-ink: #a9bcff; + --cobalt-soft: rgba(130, 156, 255, .13); + --on-accent: #141a38; + --ok: #5cb582; + --warn: #d99a45; + --bad: #e0705f; + } + } + + * { box-sizing: border-box; } +& { height: 100%; } +& { + margin: 0; + background: var(--bg); + color: var(--ink); + font-family: var(--font-ui); + font-size: 14px; + line-height: 1.55; + -webkit-font-smoothing: antialiased; + } + button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; } + button, [role="button"], select, summary, input:not([type="checkbox"], [type="radio"]) { min-height: 2.25rem; } + :focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; } + .num { font-family: var(--font-num); font-variant-numeric: tabular-nums; } + + /* ================= 布局:工作台占满整页(无文件树栏) ================= */ + .shell { display: block; min-height: 100vh; } + + /* ---------- 面板头部与横向标签页(都在内容区同一平面上) ---------- */ + .panel-top { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; } + .brand { display: flex; align-items: baseline; gap: 9px; } + .brand .seal { + font-family: var(--font-seat); font-weight: 900; font-size: 21px; letter-spacing: .06em; + } + .brand .sub { font-size: 11px; color: var(--muted); letter-spacing: .14em; } + .proj { + margin-left: auto; text-align: left; + display: flex; align-items: center; gap: 10px; + padding: 8px 12px; border-radius: var(--radius-control); + background: var(--panel); border: 1px solid var(--panel-line); + } + .proj:hover { background: var(--muted-bg); } + .proj .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: 0 0 auto; } + .proj .name { font-weight: 700; font-size: 13.5px; } + .proj .meta { font-size: 11.5px; color: var(--muted); } + .proj svg { margin-left: 4px; color: var(--muted); flex: 0 0 auto; } + + /* 横向标签页:灰槽轨道 + 白色选中块,与分段控件同一语言 */ + .tabs { + margin-top: 18px; display: flex; flex-wrap: wrap; gap: 2px; padding: 3px; + border-radius: var(--radius-control); background: var(--muted-bg); + width: fit-content; max-width: 100%; + } + .tabs a { + display: inline-flex; align-items: center; gap: 8px; + padding: 6px 15px; border-radius: 6px; + color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 13.5px; + min-height: 36px; white-space: nowrap; + } + .tabs a svg { flex: 0 0 auto; opacity: .75; } + .tabs a:hover { color: var(--ink); } + .tabs a.on { + color: var(--cobalt-ink); font-weight: 700; + background: var(--panel); border: 1px solid var(--panel-line); padding: 5px 14px; + } + .tabs a.on svg { opacity: 1; color: var(--cobalt); } + /* ---------- 主区 ---------- */ + .main { min-width: 0; padding: 24px 28px 40px; width: 100%; } + /* ---------- 页签页面:一次只显示一页 ---------- */ + .page[hidden] { display: none; } + .page > .topbar { margin-top: 20px; } + tbody tr.clickable { cursor: pointer; } + .settings-stack { display: flex; flex-direction: column; gap: 20px; margin-top: 20px; } + .topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; } + .topbar h1 { font-size: 22px; margin: 0; font-weight: 700; letter-spacing: .01em; } + .topbar .date { color: var(--muted); font-size: 13px; } + .topbar .spacer { flex: 1; } + .search { + display: flex; align-items: center; gap: 8px; + border-radius: var(--radius-control); border: 1px solid var(--panel-line); background: var(--panel); + padding: 0 12px; flex: 0 1 250px; min-width: 0; + } + .search:focus-within { border-color: var(--cobalt); } + .search svg { color: var(--muted); flex: 0 0 auto; } + .search input { border: 0; background: none; outline: none; width: 100%; color: var(--ink); font: inherit; font-size: 13.5px; } + .search input::placeholder { color: var(--muted); } + .btn { + display: inline-flex; align-items: center; gap: 7px; + padding: 8px 16px; border-radius: var(--radius-control); font-weight: 500; + background: var(--panel); border: 1px solid var(--panel-line); + white-space: nowrap; + } + .btn:hover { background: var(--muted-bg); } + .btn.primary { background: var(--cobalt); border-color: var(--cobalt); color: var(--on-accent); font-weight: 700; } + .btn.primary:hover { background: var(--cobalt-ink); border-color: var(--cobalt-ink); } + /* 页头主按钮位:丞相(派工经丞相下达,点开即向丞相交代任务) */ + .btn-cx { gap: 9px; } + .btn-cx .cx-name { font-family: var(--font-seat); font-weight: 900; font-size: 16px; letter-spacing: .05em; line-height: 1; } + .btn-cx .cx-dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(255,255,255,.22); flex: 0 0 auto; } + .btn-cx .cx-dot.idle { background: #d4d4d8; box-shadow: none; } + .btn-cx .cx-state { font-size: 12px; font-weight: 500; opacity: .88; } + .btn-cx.selected { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--cobalt); } + .ws-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; } + .ws-actions .btn { padding: 7px 16px; } + .modal input[type="text"] { + width: 100%; border: 1px solid var(--panel-line); border-radius: var(--radius-control); + background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px; + padding: 8px 10px; + } + .modal input[type="text"]:focus { border-color: var(--cobalt); outline: none; } + + /* ---------- 统计卡(骨架:平、脆、白) ---------- */ + .stats { + display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; + margin-top: 22px; + } + .stat { + background: var(--panel); border: 1px solid var(--panel-line); + border-radius: var(--radius-panel); padding: 16px 18px 14px; + } + .stat-link { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; } + .stat-link:hover { border-color: var(--cobalt); background: var(--cobalt-soft); } + .stat-link:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; } + .stat .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 7px; } + .stat .big { font-family: var(--font-num); font-size: 30px; font-weight: 600; line-height: 1.25; margin-top: 2px; } + .stat .big .unit { font-size: 14px; color: var(--muted); font-weight: 400; } + .stat .big em { font-style: normal; color: var(--cobalt); } + .stat .foot { font-size: 12px; color: var(--muted); margin-top: 2px; } + .stat .foot b { color: var(--ink-2); font-weight: 500; } + .spark { display: block; margin-top: 6px; } + + /* ---------- 内容网格 ---------- */ + .grid { + display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 368px); gap: 20px; + margin-top: 20px; align-items: start; + } + .panel-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; } + .panel-head h2 { font-size: 16px; margin: 0; font-weight: 700; } + .panel-head .hint { font-size: 12.5px; color: var(--muted); } + + /* 分段控件:平底灰槽 + 白色选中块 */ + .seg { + margin-left: auto; display: inline-flex; gap: 2px; padding: 3px; + border-radius: var(--radius-control); background: var(--muted-bg); + } + .seg button { padding: 5px 14px; border-radius: 6px; font-size: 13px; color: var(--ink-2); min-height: 32px; } + .seg button:hover { color: var(--ink); } + .seg button.on { background: var(--panel); border: 1px solid var(--panel-line); color: var(--ink); font-weight: 700; padding: 4px 13px; } + + /* ---------- 席位谱系:紧凑对齐 · 宽3排 / 中4排 / 窄5排 ---------- + 三省与六部共用一个整宽块:不再居中定宽 760px(宽屏下两边大片留白), + 改为撑满内容区、与上方统计卡和下方表格左右齐平,两排总宽仍相等、上下对齐成块。 + 所有列宽一律 minmax(0, 1fr):可随容器一路流式收缩。 + 三省恒为一排:尚书居中,中书、门下贴其两侧;六部宽屏 6 列、中屏 3×2、窄屏 2×3。 */ + .org-rows { + --tree-line: #c6c6cd; padding-top: 2px; + --ss-gap: 14px; + --lb-gap: 10px; + max-width: none; margin: 0; width: 100%; min-width: 0; + /* 谱系块自身成为容器:六部排数按本块的实际宽度决定(容器查询), + 不再只看视口——外壳/分栏让呈现宽度与视口不一致时,视口断点永远等不到。 */ + container-type: inline-size; + container-name: orgtree; + } + @media (prefers-color-scheme: dark) { .org-rows { --tree-line: #3d3d44; } } + .org-row { display: grid; gap: var(--lb-gap); min-width: 0; } + .org-row-1 { grid-template-columns: minmax(0, 1fr); } + .org-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--ss-gap); } + .org-row-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); } + .org-cell { display: flex; justify-content: center; min-width: 0; } + .org-row-1 .node { width: min(248px, 100%); } + .org-row-3 .node { width: 100%; max-width: none; padding: 15px 18px 13px; } + .org-row-3 .node-name { font-size: 24px; } + .org-row-3 .node-role { font-size: 12.5px; } + .org-row-3 .node-task { font-size: 13px; } + .org-row-3 .node-model { font-size: 12.5px; } + .org-row-6 .node { width: 100%; max-width: none; } + /* 六部节点:撑满整宽后每席约 200px+,字号回到正常档,文字不再截断 */ + .org-row-6 .node { padding: 12px 14px 11px; } + .org-row-6 .node-top { gap: 4px 6px; flex-wrap: wrap; } + .org-row-6 .node-name { font-size: 20px; } + .org-row-6 .status { font-size: 12px; gap: 5px; } + .org-row-6 .node-role { font-size: 12px; margin-top: 3px; } + .org-row-6 .node-task { font-size: 12.5px; margin-top: 6px; } + .org-row-6 .node-model { font-size: 12px; margin-top: 6px; } + .org-row-6 .node-foot { margin-top: 8px; } + /* 排间连线层:竖线对准每列中心,横线贯通,全部横平竖直;高度收紧到 22px */ + .org-wires { position: relative; height: 22px; } + .org-wires .wire-v { position: absolute; width: 1px; background: var(--tree-line); } + .org-wires .wire-h { position: absolute; height: 1px; background: var(--tree-line); } + /* ===== 六部换行:触发依据是谱系块自身的宽度,不是视口 ===== + 根因(旧版):排数只由 @media (max-width:1080px/640px) 两条视口断点控制。 + 在应用外壳里,页面呈现宽度(分栏/嵌入)与视口宽并不总是一致,窗口缩到 + 视口断点之前就停住时,两条断点永远等不到,六张卡只能一味变小、挤在一排。 + 根治:三路同阈值(按谱系块宽:>1180 一排 6 张;≤1180 → 3×2;≤700 → 2×3)—— + ① JS ResizeObserver 实测 .org-rows 宽度写入 data-cols(主路,见脚本); + ② @container 容器查询(CSS 原生同义路);③ @media 视口断点(兜底,数值已 + 按主区左右内边距 56px 换算对齐)。三省在任何档位恒为一排。 */ + /* 中档:六部 3 列 × 2 排,每排总宽仍与三省排同宽对齐 */ + .org-rows[data-cols="3"] { --ss-gap: 10px; --lb-gap: 10px; } + .org-rows[data-cols="3"] .org-row-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } + .org-rows[data-cols="3"] .org-wires-2 .wire-h { left: 16.6667% !important; right: 16.6667% !important; } + .org-rows[data-cols="3"] .org-wires-2 .w2-b1 { left: 16.6667% !important; } + .org-rows[data-cols="3"] .org-wires-2 .w2-b2 { left: 50% !important; } + .org-rows[data-cols="3"] .org-wires-2 .w2-b3 { left: 83.3333% !important; } + .org-rows[data-cols="3"] .org-wires-2 .w2-b4, + .org-rows[data-cols="3"] .org-wires-2 .w2-b5, + .org-rows[data-cols="3"] .org-wires-2 .w2-b6 { display: none; } + @container orgtree (max-width: 1180px) { + .org-row-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } + .org-wires-2 .wire-h { left: 16.6667% !important; right: 16.6667% !important; } + .org-wires-2 .w2-b1 { left: 16.6667% !important; } + .org-wires-2 .w2-b2 { left: 50% !important; } + .org-wires-2 .w2-b3 { left: 83.3333% !important; } + .org-wires-2 .w2-b4, .org-wires-2 .w2-b5, .org-wires-2 .w2-b6 { display: none; } + } + @media (max-width: 1240px) { + .org-row-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } + .org-wires-2 .wire-h { left: 16.6667% !important; right: 16.6667% !important; } + .org-wires-2 .w2-b1 { left: 16.6667% !important; } + .org-wires-2 .w2-b2 { left: 50% !important; } + .org-wires-2 .w2-b3 { left: 83.3333% !important; } + .org-wires-2 .w2-b4, .org-wires-2 .w2-b5, .org-wires-2 .w2-b6 { display: none; } + } + /* 窄档:六部 2 列 × 3 排;三省仍一排;卡片上的「主任模型」行隐藏(配置面板不受影响) */ + .org-rows[data-cols="2"] { --ss-gap: 8px; --lb-gap: 8px; } + .org-rows[data-cols="2"] .org-row-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } + .org-rows[data-cols="2"] .node-model { display: none; } + .org-rows[data-cols="2"] .org-wires-2 .wire-h { left: 25% !important; right: 25% !important; } + .org-rows[data-cols="2"] .org-wires-2 .w2-b1 { left: 25% !important; } + .org-rows[data-cols="2"] .org-wires-2 .w2-b2 { left: 75% !important; } + .org-rows[data-cols="2"] .org-wires-2 .w2-b3, + .org-rows[data-cols="2"] .org-wires-2 .w2-b4, + .org-rows[data-cols="2"] .org-wires-2 .w2-b5, + .org-rows[data-cols="2"] .org-wires-2 .w2-b6 { display: none; } + .org-rows[data-cols="2"] .org-row .node { padding: 9px 9px 8px; } + .org-rows[data-cols="2"] .org-row-3 .node-name { font-size: 18px; } + .org-rows[data-cols="2"] .org-row-6 .node-name { font-size: 17px; } + .org-rows[data-cols="2"] .org-row .status { font-size: 11px; gap: 4px; } + .org-rows[data-cols="2"] .org-row .node-top { gap: 5px; flex-wrap: wrap; } + @container orgtree (max-width: 700px) { + .org-row-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } + .node-model { display: none; } + .org-wires-2 .wire-h { left: 25% !important; right: 25% !important; } + .org-wires-2 .w2-b1 { left: 25% !important; } + .org-wires-2 .w2-b2 { left: 75% !important; } + .org-wires-2 .w2-b3, .org-wires-2 .w2-b4, .org-wires-2 .w2-b5, .org-wires-2 .w2-b6 { display: none; } + .org-row .node { padding: 9px 9px 8px; } + .org-row-3 .node-name { font-size: 18px; } + .org-row-6 .node-name { font-size: 17px; } + .org-row .status { font-size: 11px; gap: 4px; } + } + @media (max-width: 760px) { + .node-model { display: none !important; } + .org-row-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } + .org-wires-2 .wire-h { left: 25% !important; right: 25% !important; } + .org-wires-2 .w2-b1 { left: 25% !important; } + .org-wires-2 .w2-b2 { left: 75% !important; } + .org-wires-2 .w2-b3, .org-wires-2 .w2-b4, .org-wires-2 .w2-b5, .org-wires-2 .w2-b6 { display: none; } + .org-row .node { padding: 9px 9px 8px; } + .org-row-3 .node-name { font-size: 18px; } + .org-row-6 .node-name { font-size: 17px; } + .org-row .status { font-size: 11px; gap: 4px; } + .org-row .node-top { gap: 5px; flex-wrap: wrap; } + } + + .node { + width: 158px; min-width: 0; + border-radius: var(--radius-panel); background: var(--panel); + border: 1px solid var(--panel-line); padding: 11px 13px 10px; + position: relative; z-index: 1; + } + .node-main { min-width: 0; } + .node-role, .node-task { overflow-wrap: break-word; } + .node-model .num { overflow-wrap: anywhere; } + .node:hover { border-color: var(--muted); } + .node.selected { border-color: var(--cobalt); background: var(--cobalt-soft); } + .node.dim { opacity: .28; } + .node-main { display: block; width: 100%; text-align: left; padding: 0; min-height: 0; } + .node-role, .node-task, .node-model { display: block; } + .node-top { display: flex; align-items: center; gap: 8px; } + .node-name { font-family: var(--font-seat); font-weight: 900; font-size: 21px; line-height: 1.1; letter-spacing: .04em; } + .node.selected .node-name { color: var(--cobalt); } + .node.root { width: min(248px, 100%); } + .node.root .node-name { font-size: 25px; } + @media (max-width: 1400px) { + .node { width: 136px; } + .node.root { width: min(248px, 100%); } + } + .node-role { font-size: 11.5px; color: var(--muted); margin-top: 3px; } + .node-task { margin-top: 7px; font-size: 12px; color: var(--ink-2); } + .node-task .t-label { color: var(--muted); font-size: 11px; display: block; } + .node-model { margin-top: 6px; font-size: 11.5px; color: var(--muted); } + .node-model .num { font-size: 11px; } + .node-foot { margin-top: 9px; display: flex; align-items: center; gap: 8px; } + .status { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; } + .status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; } + .status.run i { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,125,79,.16); } + .status.review i { background: var(--warn); box-shadow: 0 0 0 3px rgba(176,106,18,.16); } + .status.idle i { background: var(--muted); } + .elapsed { font-size: 12px; color: var(--muted); } + + /* ---------- 节点纵向骨架:内容区撑满,已耗时一行钉在卡底 ---------- */ + .node { display: flex; flex-direction: column; } + .node-main { flex: 1 1 auto; display: flex; flex-direction: column; } + .node-foot { margin-top: auto; } + .node-task .task-text { display: block; } + + /* ---------- 席位详情头:标题 + 开始对话主按钮 ---------- */ + .detail-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 4px; flex-wrap: wrap; } + .detail-head h3 { flex: 1 1 auto; min-width: 140px; margin: 0; overflow-wrap: anywhere; } + .detail-head .btn { flex: 0 0 auto; padding: 7px 16px; } + /* ---------- 会话弹窗:与该席对话 ---------- */ + .chat-log { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; } + .chat-msg { + max-width: 88%; padding: 9px 12px; border-radius: 8px; + font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere; + } + .chat-msg.seat { background: var(--muted-bg); color: var(--ink-2); align-self: flex-start; } + .chat-msg.me { background: var(--cobalt); color: var(--on-accent); align-self: flex-end; } + .chat-compose { display: flex; gap: 10px; margin-top: 16px; align-items: flex-end; } + .chat-compose textarea { + flex: 1; min-height: 44px; resize: vertical; + border: 1px solid var(--panel-line); border-radius: var(--radius-control); + background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px; + padding: 8px 10px; + } + .chat-compose textarea:focus { border-color: var(--cobalt); outline: none; } + .chat-compose .btn { flex: 0 0 auto; padding: 8px 18px; } + .chat-card { margin-top: 20px; } + .chat-card .chat-log { margin-top: 0; min-height: 260px; } + .chat-card .m-decided { margin: 12px 0 0; font-size: 13px; color: var(--muted); } + + /* ---------- 六部:六张等高卡,每段单行固定高,卡底已耗时齐平 ---------- */ + .org-row-6 .node { height: 100%; padding: 12px 14px; } + .org-row-6 .node-top { flex-wrap: nowrap; height: 30px; overflow: hidden; } + .org-row-6 .node-name { flex: 0 0 auto; } + .org-row-6 .status { flex: 0 0 auto; } + .org-row-6 .node-role { + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + height: 20px; line-height: 20px; margin-top: 4px; + } + .org-row-6 .node-task { margin-top: 8px; } + .org-row-6 .node-task .t-label { height: 16px; line-height: 16px; } + .org-row-6 .node-task .task-text { + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + height: 20px; line-height: 20px; + } + .org-row-6 .node-model { + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + height: 20px; line-height: 20px; margin-top: 6px; + } + .org-row-6 .node-foot { margin-top: auto; padding-top: 9px; } + .org-row-6 .elapsed { + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + height: 20px; line-height: 20px; display: block; + } + + /* ---------- 右列:详情 + 复核(骨架面板) ---------- */ + .rail { display: flex; flex-direction: column; gap: 20px; } + .detail-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; } + .card { + background: var(--panel); border: 1px solid var(--panel-line); + border-radius: var(--radius-panel); padding: 18px; + } + .card h3 { margin: 0 0 4px; font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; } + .card h3 .count { + font-family: var(--font-num); font-size: 11.5px; background: var(--cobalt); color: var(--on-accent); + border-radius: 999px; padding: 0 8px; line-height: 19px; + } + .detail-name { font-family: var(--font-seat); font-weight: 900; font-size: 30px; color: var(--cobalt); line-height: 1.15; } + .detail-role { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; } + .kv { display: grid; grid-template-columns: 74px 1fr; row-gap: 8px; font-size: 13px; } + .kv dt { color: var(--muted); } + .kv dd { margin: 0; color: var(--ink); } + .kv dd .sub { color: var(--muted); font-size: 12px; } + .excerpt { + margin-top: 14px; border-top: 1px dashed var(--panel-line); padding-top: 12px; + font-size: 13px; color: var(--ink-2); + } + .excerpt .t-label { color: var(--muted); font-size: 11.5px; display: block; margin-bottom: 4px; } + + /* ---------- 部门配置面板:平表单 + 圆点文字标状态 ---------- */ + .card h3 .seat-tag { color: var(--cobalt); font-family: var(--font-seat); font-weight: 900; font-size: 16px; } + .cfg-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px 16px; margin-top: 10px; } + .cfg-row { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); } + .cfg-row select { + border: 1px solid var(--panel-line); border-radius: var(--radius-control); + background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px; + padding: 7px 10px; width: 100%; + } + .cfg-row select:focus { border-color: var(--cobalt); outline: none; } + .cfg-skills { margin-top: 16px; border-top: 1px dashed var(--panel-line); padding-top: 12px; } + .cfg-skills .t-label { color: var(--muted); font-size: 11.5px; display: block; } + .skill-list { list-style: none; margin: 4px 0 0; padding: 0; } + .skill-list li { + display: flex; align-items: center; gap: 10px; + padding: 8px 0; border-top: 1px solid var(--panel-line); font-size: 13px; + } + .skill-list li:first-child { border-top: 0; padding-top: 4px; } + .skill-list .skill-name { flex: 1; min-width: 0; } + .skill-list .skill-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; } + .skill-list .skill-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; } + .skill-list .skill-state.bound { color: var(--ink); } + .skill-list .skill-state.bound i { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,125,79,.16); } + .skill-toggle { + border: 1px solid var(--panel-line); border-radius: var(--radius-control); + background: var(--panel); padding: 4px 13px; font-size: 12.5px; min-height: 32px; white-space: nowrap; + } + .skill-toggle:hover { background: var(--muted-bg); } + @media (max-width: 640px) { .cfg-grid { grid-template-columns: 1fr; } } + + /* ---------- 工作区条目:一条一卡(门下审核 / 中书方案 / 尚书调度共用同一套) ---------- */ + .review-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; } + .review-card { + background: var(--panel); border: 1px solid var(--panel-line); + border-radius: var(--radius-panel); padding: 14px 16px 12px; + } + .review-card.decided { opacity: .55; } + .rc-head { display: flex; align-items: center; gap: 10px; } + .rc-title { + flex: 1; min-width: 0; font-weight: 700; font-size: 14.5px; color: var(--ink); + white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + } + .rc-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); white-space: nowrap; flex: 0 0 auto; } + .rc-status i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 3px rgba(176,106,18,.16); flex: 0 0 auto; } + .rc-status.pass i { background: var(--ok); box-shadow: 0 0 0 3px rgba(46,125,79,.16); } + .rc-status.reject i { background: var(--bad); box-shadow: 0 0 0 3px rgba(179,55,44,.14); } + .rc-status.run i { background: var(--cobalt); box-shadow: 0 0 0 3px var(--cobalt-soft); } + .rc-status.idle i { background: var(--muted); box-shadow: none; } + .rc-meta-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; } + .rc-from { + font-size: 11.5px; font-weight: 500; color: var(--ink-2); + background: var(--muted-bg); border-radius: 999px; padding: 1px 9px; line-height: 19px; + white-space: nowrap; + } + .rc-meta { font-size: 12px; color: var(--muted); } + .rc-excerpt { + margin-top: 10px; background: var(--muted-bg); border-radius: 6px; + padding: 9px 11px; font-size: 12.5px; color: var(--ink-2); line-height: 1.6; + display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; + } + .rc-excerpt.expanded { display: block; -webkit-line-clamp: unset; } + /* 定夺后记在卡上的批复理由 / 批语(回传提交席位照此修改) */ + .rc-reason { + margin-top: 10px; background: var(--muted-bg); border-radius: 6px; + padding: 8px 11px; font-size: 12.5px; color: var(--ink-2); line-height: 1.6; + overflow-wrap: anywhere; + } + .rc-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; } + .rc-actions .spacer { flex: 1; } + .rc-actions .btn { padding: 5px 14px; font-size: 13px; min-height: 34px; } + .rc-actions .btn.pass { color: var(--cobalt-ink); font-weight: 700; } + .rc-actions .btn:disabled { opacity: .5; cursor: default; } + .rc-actions .btn:disabled:hover { background: var(--panel); } + .r-open { + display: inline-flex; align-items: center; gap: 4px; + font-size: 13px; font-weight: 500; color: var(--cobalt); padding: 5px 6px; min-height: 34px; + } + .r-open:hover { color: var(--cobalt-ink); text-decoration: underline; } + .empty-note { font-size: 13px; color: var(--muted); padding: 10px 0 2px; } + + /* ---------- 席位工作区:随选中席位切换内容 ---------- */ + .w-kind { + font-size: 11.5px; font-weight: 500; color: var(--cobalt-ink); + background: var(--cobalt-soft); border-radius: 999px; padding: 1px 9px; line-height: 19px; + } + .ws-sec { margin-top: 14px; } + .ws-sec:first-child { margin-top: 6px; } + .ws-sec .t-label { color: var(--muted); font-size: 11.5px; display: block; margin-bottom: 4px; } + .ws-sec p { margin: 0; font-size: 13.5px; color: var(--ink-2); } + /* 方案 / 调度 / 审核条目样式见上方「工作区条目:一条一卡」 */ + + /* ---------- 右列里的配置面板:字段上下排 ---------- */ + .rail .cfg-grid { grid-template-columns: minmax(0, 1fr); } + + /* ---------- 复核弹窗:看清待准奏内容再定夺 ---------- */ + .modal-backdrop { + position: fixed; inset: 0; z-index: 60; + background: rgba(9, 9, 11, .48); + display: flex; align-items: center; justify-content: center; + padding: 18px; + } + .modal-backdrop[hidden] { display: none; } + .modal { + background: var(--panel); color: var(--ink); + border: 1px solid var(--panel-line); border-radius: 12px; + width: min(580px, 100%); max-height: calc(100vh - 36px); overflow-y: auto; + padding: 20px 22px 18px; + } + .modal.wide { width: min(760px, 100%); } + .modal-head { display: flex; align-items: flex-start; gap: 12px; } + .modal-head h3 { margin: 0; font-size: 17px; font-weight: 700; flex: 1; min-width: 0; } + .modal-close { + flex: 0 0 auto; width: 32px; height: 32px; min-height: 32px; + border: 1px solid var(--panel-line); border-radius: var(--radius-control); + display: inline-flex; align-items: center; justify-content: center; font-size: 15px; + } + .modal-close:hover { background: var(--muted-bg); } + .modal .m-from { font-size: 12.5px; color: var(--muted); margin-top: 3px; } + .modal .m-sec { margin-top: 15px; } + .modal .m-sec .t-label { color: var(--muted); font-size: 11.5px; display: block; margin-bottom: 4px; } + .modal .m-sec p { margin: 0; font-size: 13.5px; color: var(--ink-2); } + .modal .m-doubts { list-style: none; margin: 0; padding: 0; } + .modal .m-doubts li { padding: 6px 0 6px 16px; border-top: 1px solid var(--panel-line); font-size: 13.5px; color: var(--ink-2); position: relative; } + .modal .m-doubts li:first-child { border-top: 0; } + .modal .m-doubts li::before { content: ""; position: absolute; left: 2px; top: 14px; width: 5px; height: 5px; border-radius: 50%; background: var(--warn); } + .modal .m-source { + background: var(--muted-bg); border-radius: var(--radius-panel); + padding: 10px 12px; font-size: 13px; color: var(--ink-2); + } + .modal-actions { display: flex; gap: 10px; margin-top: 18px; } + .modal-actions .btn { padding: 7px 18px; } + .modal-actions .btn.pass { color: var(--cobalt-ink); font-weight: 700; } + .modal .m-decided { margin-top: 16px; font-size: 13px; color: var(--muted); } + .modal textarea { + width: 100%; border: 1px solid var(--panel-line); border-radius: var(--radius-control); + background: var(--panel); color: var(--ink); font: inherit; font-size: 13.5px; + padding: 8px 10px; resize: vertical; min-height: 64px; + } + .modal textarea:focus { border-color: var(--cobalt); outline: none; } + .modal .m-err { color: var(--bad); font-size: 12.5px; margin: 6px 0 0; } + .modal .m-err[hidden] { display: none; } + + /* ---------- 表格(骨架:干脆、高对比、无拟物) ---------- */ + .table-card { + margin-top: 20px; background: var(--panel); border: 1px solid var(--panel-line); + border-radius: var(--radius-panel); padding: 18px 18px 8px; + } + .table-scroll { overflow-x: auto; } + table { width: 100%; border-collapse: collapse; font-size: 13.5px; } + thead th { + text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; + padding: 8px 12px; border-bottom: 1px solid var(--panel-line); white-space: nowrap; + } + tbody td { padding: 11px 12px; border-bottom: 1px solid var(--panel-line); vertical-align: middle; } + tbody tr:last-child td { border-bottom: 0; } + tbody tr:hover td { background: var(--cobalt-soft); } + td .task-name { font-weight: 500; } + td .task-id { font-family: var(--font-num); font-size: 11.5px; color: var(--muted); } + .pill { + display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; + border: 1px solid var(--panel-line); border-radius: 999px; padding: 2px 10px; white-space: nowrap; + background: var(--panel); + } + .pill i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); } + .pill.done i { background: var(--ok); } + .pill.run i { background: var(--cobalt); } + .pill.review i { background: var(--warn); } + .pill.fail i { background: var(--bad); } + td.time, td.dur { font-family: var(--font-num); font-size: 12.5px; color: var(--ink-2); white-space: nowrap; } + td.result-cell { max-width: 260px; min-width: 160px; color: var(--ink-2); font-size: 12.5px; line-height: 1.5; overflow-wrap: anywhere; } + .foot-note { margin-top: 16px; font-size: 12px; color: var(--muted); } + + /* ---------- 窄屏回落:按工作台自身宽度判断,避免右栏 600px 仍套宽屏网格 ---------- */ + @container ssv2 (max-width: 1180px) { + .grid { grid-template-columns: 1fr; } + .rail { flex-direction: row; align-items: stretch; } + .rail .card { flex: 1; } + .stats { grid-template-columns: repeat(2, 1fr); } + } + @container ssv2 (max-width: 860px) { + .proj { margin-left: 0; } + .tabs { width: 100%; } + .tabs a { flex: 1 1 auto; justify-content: center; } + .rail { flex-direction: column; } + .search { width: 100%; order: 5; } + .stats { grid-template-columns: 1fr 1fr; gap: 10px; } + } + @container ssv2 (max-width: 640px) { + /* 窄栏表格收成四列:藏「耗时」「派发时间」两列,单元格允许换行,不横滚 */ + thead th:nth-child(5), tbody td:nth-child(5), + thead th:nth-child(6), tbody td:nth-child(6) { display: none; } + thead th, tbody td { padding-left: 8px; padding-right: 8px; } + thead th { white-space: normal; } + td .task-name, td .task-id { overflow-wrap: anywhere; } + .pill { padding: 2px 7px; font-size: 11.5px; white-space: normal; } + td.time { white-space: normal; } + } + @media (prefers-reduced-motion: reduce) { + * { transition: none !important; } + } + } + +body[data-ds-dark-theme] .ssv2,html[data-theme=dark] .ssv2,.ssv2[data-ssv-theme=dark]{--bg:#09090b;--sidebar-bg:#0c0c0e;--panel:#18181b;--panel-line:#27272a;--muted-bg:#27272a;--ink:#fafafa;--ink-2:#d4d4d8;--muted:#a1a1aa;--cobalt:#829cff;--cobalt-ink:#a9bcff;--cobalt-soft:rgba(130,156,255,.13);--on-accent:#141a38;--ok:#5cb582;--warn:#d99a45;--bad:#e0705f} + +/* ---------- 宿主接线:右栏 / 浮动面板 / 内嵌条 ---------- */ +.ssw-tab-body{height:100%;min-height:0;display:flex;flex-direction:column;overflow:hidden} +.ssw-tab-title{font-size:12px;font-weight:600} +.ssw-inline-bar{flex:none;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 14px;background:var(--muted-bg);border-bottom:1px solid var(--panel-line);font-size:12px;color:var(--muted)} +.ssw-link{color:var(--cobalt-ink);font-size:12px;font-weight:500;padding:4px 6px;border-radius:6px} +.ssw-link:hover{background:var(--cobalt-soft)} +.ssw-nav-hit{display:inline-flex;align-items:center;justify-content:center;color:inherit;width:100%;height:100%} +.ssw-float{position:fixed;right:14px;bottom:70px;z-index:2147483000;width:min(760px,calc(100vw - 28px));max-height:calc(100vh - 96px);display:flex;flex-direction:column;background:var(--panel,#fff);border:1px solid var(--panel-line,#e4e4e7);border-radius:12px;box-shadow:0 18px 50px -12px rgba(16,24,40,.28),0 4px 12px -2px rgba(16,24,40,.12);overflow:hidden} +.ssw-float>.ssv2{height:100%;min-height:0;overflow:auto} + +/* ---------- 工作台 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;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))} +.ssv-textarea{width:100%;box-sizing:border-box;border:1px solid var(--panel-line);border-radius:var(--radius-control);background:var(--panel);color:var(--ink);font:inherit;font-size:13px;line-height:1.55;padding:7px 10px;resize:vertical} +.ssv-textarea:focus{border-color:var(--cobalt);outline:none} +.ssv-select{width:100%;border:1px solid var(--panel-line);border-radius:var(--radius-control);background:var(--panel);color:var(--ink);font:inherit;font-size:13.5px;padding:7px 10px} +.ssv-select:focus{border-color:var(--cobalt);outline:none} +.ssv-check{display:flex;align-items:center;gap:8px;margin-top:12px;font-size:13px;color:var(--ink-2);cursor:pointer} +.ssv-check input{accent-color:var(--cobalt);width:15px;height:15px} +.ssv-proj-caret{font-size:15px;color:var(--muted);margin-left:2px} +.ssv2 .ws-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:12px} +.ssv2 .ws-actions .btn{min-height:34px;padding:5px 12px;font-size:13px} +.ssv2 .skill-list li{gap:8px} +.ssv2 .skill-list .skill-toggle{flex:none} +.ssv2 .card h3 .count{font-family:var(--font-num)} + +/* ---------- 结果摘要 / 展开详情 ---------- */ +.ssv2 .result-summary{margin-top:10px;min-width:0;max-width:100%} +.ssv2 .rs-line{display:flex;flex-direction:column;gap:3px;min-width:0} +.ssv2 .rs-summary{font-size:13px;color:var(--ink);line-height:1.6;overflow-wrap:anywhere;word-break:break-word} +.ssv2 .rs-points{margin:6px 0 0;padding-left:18px;font-size:12.5px;color:var(--ink-2);line-height:1.65} +.ssv2 .rs-points li{margin:2px 0;overflow-wrap:anywhere} +.ssv2 .rs-toggle{margin-top:5px;padding:0;color:var(--cobalt);font-size:12.5px;font-weight:500;min-height:24px;text-align:left} +.ssv2 .rs-detail{margin-top:10px;border-top:1px dashed var(--panel-line);padding-top:10px;font-size:13px;color:var(--ink-2);max-width:100%;overflow:hidden} +.ssv2 .rs-detail p,.ssv2 .rs-detail li,.ssv2 .rs-detail code,.ssv2 .rs-detail pre{overflow-wrap:anywhere;word-break:break-word;white-space:pre-wrap;max-width:100%} +.ssv2 .rs-heading{margin:10px 0 4px;font-size:13px;color:var(--ink);font-weight:700} +.ssv2 .rs-list{margin:4px 0 8px;padding-left:18px} +.ssv2 .rs-code{margin:6px 0;padding:8px 10px;border-radius:6px;background:var(--muted-bg);border:1px solid var(--panel-line);white-space:pre-wrap;overflow-wrap:anywhere} +.ssv2 .rs-path{display:inline-block;padding:1px 4px;border-radius:4px;background:var(--muted-bg);font-family:var(--font-num);font-size:12px} +.ssv2 .result-summary.is-empty{color:var(--muted);font-size:12.5px} +.ssv2 .rs-empty{margin-left:6px;color:var(--muted)} +.ssv2 .ws-hint{margin-top:8px} +/* ---------- 可折叠卡片(部门配置 / 记忆编辑) ---------- */ +.ssv2 details.card>summary{display:flex;align-items:center;gap:8px;cursor:pointer;font-weight:700;font-size:14.5px;list-style:none;min-height:28px} +.ssv2 details.card>summary::-webkit-details-marker{display:none} +.ssv2 details.card>summary::after{content:'⌄';margin-left:auto;color:var(--muted);transition:transform .15s} +.ssv2 details.card[open]>summary::after{transform:rotate(180deg)} +.ssv2 details.card[open]>summary{margin-bottom:8px} +.ssv2 .dept-config-body{padding-top:2px} + +/* ---------- 工作台 v2:顶栏小导航 / 队列与 Token 弹窗 / 卡片摘要 ---------- */ +.ssv2 .panel-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap} +.ssv2 .panel-actions .btn{min-height:32px;padding:5px 11px;font-size:12.5px} +.ssv2 .modal-toolbar{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:16px} +.ssv2 .modal-toolbar .search{flex:1 1 220px} +.ssv2 .queue-table-wrap{margin-top:14px;border-top:1px solid var(--panel-line)} +.ssv2 .queue-table-wrap table{margin-top:4px} +.ssv2 .card-summary{margin-top:8px;min-width:0} +.ssv2 .card-summary .t-label{display:block;color:var(--muted);font-size:11.5px;margin-bottom:3px} +.ssv2 .card-summary-text{margin:0;font-size:12.5px;line-height:1.6;color:var(--ink-2);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere;word-break:break-word} +.ssv2 .card-summary.is-empty .card-summary-text{color:var(--muted)} +.ssv2 .m-rich{margin-top:2px;font-size:13.5px;color:var(--ink-2);max-width:100%;overflow:hidden} +.ssv2 .m-rich p{margin:0 0 6px} +.ssv2 .m-rich p:last-child{margin-bottom:0} +/* ---------- 需求门控工作区 ---------- */ +.ssv2 .req-gate{padding:18px} +.ssv2 .req-gate h3{margin-bottom:6px} +.ssv2 .req-tabs{display:flex;gap:6px;margin:12px 0 14px;border-bottom:1px solid var(--panel-line);padding-bottom:2px} +.ssv2 .req-tab{border:0;background:transparent;color:var(--muted);font-family:var(--font-ui);font-size:13px;padding:7px 10px;border-radius:6px 6px 0 0;cursor:pointer} +.ssv2 .req-tab:hover{background:var(--muted-bg);color:var(--ink)} +.ssv2 .req-tab.is-active{color:var(--cobalt);font-weight:700;box-shadow:inset 0 -2px 0 var(--cobalt)} +.ssv2 .req-list{gap:10px} +.ssv2 .req-card{padding:13px 14px} +.ssv2 .req-meta{display:flex;flex-wrap:wrap;gap:8px 14px;margin:6px 0 8px;color:var(--muted);font-family:var(--font-num);font-size:11px} +.ssv2 .req-details{margin:8px 0;border-top:1px dashed var(--panel-line);padding-top:8px} +.ssv2 .req-details>summary{cursor:pointer;color:var(--ink-2);font-size:12px} +.ssv2 .req-details .kv{margin-top:8px} +.ssv2 .req-children{display:flex;flex-direction:column;gap:6px;margin-top:10px;border-top:1px dashed var(--panel-line);padding-top:8px} +.ssv2 .req-child{display:grid;grid-template-columns:74px auto 1fr;gap:6px 10px;align-items:start;font-size:12px;color:var(--ink-2)} +.ssv2 .req-child-owner{font-family:var(--font-seat);font-weight:700;color:var(--ink)} +.ssv2 .req-child-result{grid-column:1/-1;color:var(--muted);overflow-wrap:anywhere} +.ssv2 .req-child-session{grid-column:1/-1;color:var(--muted);font-family:var(--font-num);font-size:10px;overflow-wrap:anywhere} `; // src/native/panel.js @@ -858,12 +2838,28 @@ function install(ctx) { var native_default = { install }; // src/client/index.js -var import_react = require("react"); +var import_react2 = require("react"); var import_react_dom = require("react-dom"); -var inject = ["sessions", "uiWorkspace", "uiConversation", "slots", "theme", "layout"]; +var inject = ["sessions", "workspaces", "uiWorkspace", "uiConversation", "slots", "theme", "layout", "sidebarRightTabs", "sidebarRight"]; var PLUGIN_ID = "dsh-sansheng"; var TAB_KIND = "sansheng-workbench"; var TAB_TYPE_ID = "dsh-sansheng:workbench"; +var RIGHT_PIN_KEY = "sansheng.right-workbench.pinned"; +function readRightWorkbenchPinned() { + try { + return typeof localStorage !== "undefined" && localStorage.getItem(RIGHT_PIN_KEY) === "1"; + } catch { + return false; + } +} +function writeRightWorkbenchPinned(value) { + try { + if (typeof localStorage === "undefined") return; + if (value) localStorage.setItem(RIGHT_PIN_KEY, "1"); + else localStorage.removeItem(RIGHT_PIN_KEY); + } catch { + } +} function installStyles(doc, tag, text) { if (!doc || !doc.head) return null; const style = doc.createElement("style"); @@ -874,7 +2870,7 @@ function installStyles(doc, tag, text) { return style; } function svgWrap(children, props) { - return (0, import_react.createElement)("svg", { + return (0, import_react2.createElement)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, @@ -888,20 +2884,20 @@ function svgWrap(children, props) { }, children); } var TreeIcon = (props) => svgWrap([ - (0, import_react.createElement)("rect", { key: "a", x: 9, y: 2, width: 6, height: 5, rx: 1 }), - (0, import_react.createElement)("path", { key: "b", d: "M12 7v5M5 16v-4h14v4" }), - (0, import_react.createElement)("rect", { key: "c", x: 2, y: 16, width: 6, height: 5, rx: 1 }), - (0, import_react.createElement)("rect", { key: "d", x: 16, y: 16, width: 6, height: 5, rx: 1 }) + (0, import_react2.createElement)("rect", { key: "a", x: 9, y: 2, width: 6, height: 5, rx: 1 }), + (0, import_react2.createElement)("path", { key: "b", d: "M12 7v5M5 16v-4h14v4" }), + (0, import_react2.createElement)("rect", { key: "c", x: 2, y: 16, width: 6, height: 5, rx: 1 }), + (0, import_react2.createElement)("rect", { key: "d", x: 16, y: 16, width: 6, height: 5, rx: 1 }) ], props); -var CloseIcon = (props) => svgWrap([(0, import_react.createElement)("path", { key: "p", d: "m6 6 12 12M6 18 18 6" })], props); -var FolderIcon = (props) => svgWrap([(0, import_react.createElement)("path", { key: "p", d: "M3 7V5a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v11H3Z" })], props); +var CloseIcon = (props) => svgWrap([(0, import_react2.createElement)("path", { key: "p", d: "m6 6 12 12M6 18 18 6" })], props); +var FolderIcon = (props) => svgWrap([(0, import_react2.createElement)("path", { key: "p", d: "M3 7V5a2 2 0 0 1 2-2h5l2 3h7a2 2 0 0 1 2 2v11H3Z" })], props); var GearIcon = (props) => svgWrap([ - (0, import_react.createElement)("path", { key: "a", d: "M4 6h16M4 12h16M4 18h16" }), - (0, import_react.createElement)("circle", { key: "b", cx: 9, cy: 6, r: 2 }), - (0, import_react.createElement)("circle", { key: "c", cx: 16, cy: 12, r: 2 }), - (0, import_react.createElement)("circle", { key: "d", cx: 8, cy: 18, r: 2 }) + (0, import_react2.createElement)("path", { key: "a", d: "M4 6h16M4 12h16M4 18h16" }), + (0, import_react2.createElement)("circle", { key: "b", cx: 9, cy: 6, r: 2 }), + (0, import_react2.createElement)("circle", { key: "c", cx: 16, cy: 12, r: 2 }), + (0, import_react2.createElement)("circle", { key: "d", cx: 8, cy: 18, r: 2 }) ], props); -var ChevronIcon = (props) => (0, import_react.createElement)("svg", { +var ChevronIcon = (props) => (0, import_react2.createElement)("svg", { viewBox: "0 0 24 24", width: 14, height: 14, @@ -912,7 +2908,7 @@ var ChevronIcon = (props) => (0, import_react.createElement)("svg", { strokeLinejoin: "round", className: "ssw-chevron", "aria-hidden": "true" -}, (0, import_react.createElement)("path", { d: "m6 9 6 6 6-6" })); +}, (0, import_react2.createElement)("path", { d: "m6 9 6 6 6-6" })); var SEAT_ICON_PATHS = { lead: ["M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8Z", "M4.5 20c0-3.2 3.4-5 7.5-5s7.5 1.8 7.5 5"], zhongshu: ["M7 3h7l4 4v14H7z", "M14 3v4h4", "M9.5 12h5", "M9.5 16h5"], @@ -927,7 +2923,7 @@ var SEAT_ICON_PATHS = { }; function SeatIcon(props) { const paths = SEAT_ICON_PATHS[props && props.id] ?? SEAT_ICON_PATHS.lead; - return (0, import_react.createElement)("svg", { + return (0, import_react2.createElement)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, @@ -938,7 +2934,7 @@ function SeatIcon(props) { strokeLinejoin: "round", "aria-hidden": "true", className: "ssw-seat-icon" - }, paths.map((d, index) => (0, import_react.createElement)("path", { key: index, d }))); + }, paths.map((d, index) => (0, import_react2.createElement)("path", { key: index, d }))); } function isFn(value) { return typeof value === "function"; @@ -971,22 +2967,23 @@ function apply(ctx) { return void 0; } }; + function sessionsSnapshot() { + return snapshotOf(get("sessions")?.list) ?? snapshotOf(get("sessions")); + } function workspaceItems() { - const fromWorkspaces = snapshotOf(get("workspaces")?.list)?.items; - if (Array.isArray(fromWorkspaces)) return fromWorkspaces; - const fromUi = snapshotOf(get("uiWorkspace")?.workspaces)?.items; - if (Array.isArray(fromUi)) return fromUi; + const sources = [ + get("workspaces")?.list, + get("uiWorkspace")?.workspaces, + get("workspaces") + ]; + for (const source of sources) { + const items = workspaceItemsFromSnapshot(snapshotOf(source)); + if (items.length) return items; + } return []; } - function normalizeWorkspace(item) { - if (!item || typeof item !== "object") return null; - const workspaceId = item.workspaceId ?? item.id ?? null; - if (typeof workspaceId !== "string" || !workspaceId) return null; - return { - workspaceId, - name: typeof item.name === "string" ? item.name : typeof item.title === "string" ? item.title : void 0, - path: typeof item.path === "string" ? item.path : void 0 - }; + function sessionSummary(sessionId) { + return sessionSummaryFromSnapshot(sessionsSnapshot(), sessionId); } function currentSessionId() { const snap = snapshotOf(get("sessions")?.list) ?? snapshotOf(get("sessions")); @@ -1018,12 +3015,20 @@ function apply(ctx) { const sessionId = currentSessionId(); if (sessionId) { const owner = workspaceItems().find((item) => Array.isArray(item.sessionIds) && item.sessionIds.includes(sessionId)); - if (owner) candidates.push(owner.workspaceId ?? owner.id); + if (owner) candidates.push(owner.workspaceId); } return candidates.find((id) => typeof id === "string" && id) ?? null; } + function workspaceForSessionId(sessionId) { + const explicitId = typeof sessionId === "string" && sessionId ? sessionId : null; + const targetId = explicitId || currentSessionId(); + const fromSession = workspaceForSession(workspaceItems(), targetId, sessionSummary(targetId)); + if (fromSession) return fromSession; + if (explicitId && explicitId !== currentSessionId()) return null; + return currentWorkspace(); + } function currentWorkspace() { - const items = workspaceItems().map(normalizeWorkspace).filter(Boolean); + const items = workspaceItems(); const id = currentWorkspaceId(); if (id) { const hit = items.find((item) => item.workspaceId === id); @@ -1032,7 +3037,7 @@ function apply(ctx) { if (items.length === 1) return items[0]; return null; } - function seatRecordOf(view, id) { + function seatRecordOf2(view, id) { const seats = view && view.project ? view.project.seats : null; if (Array.isArray(seats)) return seats.find((seat) => seat && seat.id === id) || null; if (seats && typeof seats === "object") return seats[id] || null; @@ -1086,27 +3091,118 @@ function apply(ctx) { return false; } } - function revealRightTab() { + function rightMountedSessionId() { const right = get("sidebarRight"); - if (!right) return; try { - const rows = isFn(right.openTabs?.getSnapshot) ? right.openTabs.getSnapshot() : []; - const row = Array.isArray(rows) ? rows.find((item) => item && item.kind === TAB_KIND) : null; - if (row && isFn(right.focus)) right.focus(row.tabId); - if (isFn(right.isExpanded) && !right.isExpanded() && isFn(right.toggleExpanded)) right.toggleExpanded(); - } catch (error) { - console.warn("[sansheng] 展开右侧栏失败:", error && error.message ? error.message : error); + if (right && isFn(right.mounted?.getSnapshot)) { + const mounted = right.mounted.getSnapshot(); + if (typeof mounted === "string" && mounted) return mounted; + } + } catch { + } + return currentSessionId(); + } + function activeRightTabId() { + const right = get("sidebarRight"); + if (!right || !isFn(right.active)) return null; + try { + const record = right.active(); + if (!record) return null; + if (typeof record === "string") return record; + return record.id || record.tabId || null; + } catch { + return null; } } - function tryOpenRightTab() { + function findRightWorkbenchTab(sessionId) { + const right = get("sidebarRight"); + if (!right || !isFn(right.openTabs?.getSnapshot)) return null; + try { + const rows = right.openTabs.getSnapshot(); + const targetSessionId = typeof sessionId === "string" && sessionId ? sessionId : rightMountedSessionId(); + if (!targetSessionId) return null; + const matches = (Array.isArray(rows) ? rows : []).filter((item) => item && item.kind === TAB_KIND && item.sessionId === targetSessionId); + if (matches.length === 0) return null; + const activeId = activeRightTabId(); + return matches.find((item) => item.tabId === activeId) || matches[0]; + } catch { + return null; + } + } + function revealRightTab(sessionId) { + const right = get("sidebarRight"); + if (!right) return false; + try { + const row = findRightWorkbenchTab(sessionId); + if (!row) return false; + 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); + return false; + } + } + function scheduleRevealRightTab(sessionId) { + 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) return revealRightTab(targetSessionId); const bs = get("betterSidebar"); if (bs && isFn(bs.openTab)) { try { - const snap = isFn(bs.getSnapshot) ? bs.getSnapshot() : null; - const sessionId = snap && typeof snap === "object" ? snap.sessionId : void 0; - if (!sessionId) return false; - bs.openTab({ type: TAB_KIND, title: "三省六部" }); - for (const delay of [200, 600, 1200]) setTimeout(revealRightTab, delay); + if (!targetSessionId) return false; + const summary = sessionSummary(targetSessionId); + const scope = { sessionId: targetSessionId }; + if (summary && typeof summary.cwd === "string" && summary.cwd) scope.cwd = summary.cwd; + bs.openTab({ type: TAB_KIND, title: "三省六部" }, scope); + scheduleRevealRightTab(targetSessionId); return true; } catch (error) { console.warn("[sansheng] better-sidebar 打开失败,改用宿主接口:", error && error.message ? error.message : error); @@ -1116,20 +3212,23 @@ function apply(ctx) { if (!right || !isFn(right.openTab)) return false; if (!ensureRightTab()) return false; try { - right.openTab(TAB_KIND); + const mountedId = rightMountedSessionId(); + if (targetSessionId && targetSessionId !== mountedId && isFn(right.openTabIn)) right.openTabIn(targetSessionId, TAB_KIND); + else right.openTab(TAB_KIND); } catch (error) { console.warn("[sansheng] 打开右侧标签失败,改用浮动面板:", error && error.message ? error.message : error); return false; } - revealRightTab(); - for (const delay of [150, 500, 1200]) setTimeout(revealRightTab, delay); + revealRightTab(targetSessionId); + scheduleRevealRightTab(targetSessionId); return true; } - function SanshengTabBody() { - return (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {})); + function SanshengTabBody(props) { + 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_react.createElement)("span", { className: "ssw-tab-title" }, "三省六部"); + return (0, import_react2.createElement)("span", { className: "ssw-tab-title" }, "三省六部"); } function registerRightTabType() { try { @@ -1139,10 +3238,14 @@ function apply(ctx) { id: TAB_KIND, title: "三省六部", description: "十席角色与独立会话的当前项目工作台", - icon: (size) => (0, import_react.createElement)(TreeIcon, { width: size, height: size }), + icon: (size) => (0, import_react2.createElement)(TreeIcon, { width: size, height: size }), order: 32, single: true, - component: () => (0, import_react.createElement)("div", { className: "ssw-tab-body" }, (0, import_react.createElement)(SanshengWorkbench, {})) + component: (tabProps) => { + const scope = tabProps && tabProps.scope ? tabProps.scope : null; + 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 () => { try { @@ -1161,7 +3264,20 @@ function apply(ctx) { if (!tabs || !isFn(tabs.register)) return; let disposeType = null, disposeBody = null, disposeTitle = null; try { - disposeType = tabs.register({ id: TAB_TYPE_ID, kind: TAB_KIND, keepMounted: true, priority: "extension", title: () => "三省六部" }); + disposeType = tabs.register({ + id: TAB_TYPE_ID, + kind: TAB_KIND, + keepMounted: true, + priority: "extension", + title: () => "三省六部", + guide: [{ + id: `${TAB_TYPE_ID}:guide`, + order: 32, + title: () => "三省六部", + description: () => "十席角色与独立会话的当前项目工作台", + icon: TreeIcon + }] + }); disposeBody = ctx.slots.inject("sidebar.right.pane.tab", () => ctx.slots.register({ name: "sidebar.right.pane.tab", key: TAB_TYPE_ID, @@ -1209,752 +3325,45 @@ function apply(ctx) { } const selectedSeatCache = /* @__PURE__ */ new Map(); let lastSelectedSeatId = SEAT_IDS[0]; + let rightWorkbenchPinned = readRightWorkbenchPinned(); function SanshengWorkbench(props) { - const onClose = props && props.onClose ? props.onClose : null; - const [phase, setPhase] = (0, import_react.useState)("loading"); - const [error, setError] = (0, import_react.useState)(null); - const [errorRetryable, setErrorRetryable] = (0, import_react.useState)(true); - const [notice, setNotice] = (0, import_react.useState)(null); - const [view, setView] = (0, import_react.useState)(null); - const [models, setModels] = (0, import_react.useState)(null); - const [selectedSeatId, setSelectedSeatId] = (0, import_react.useState)(lastSelectedSeatId); - const [draft, setDraft] = (0, import_react.useState)({}); - const [busy, setBusy] = (0, import_react.useState)(false); - const [configOpen, setConfigOpen] = (0, import_react.useState)(false); - const [reportOpen, setReportOpen] = (0, import_react.useState)(false); - const [memory, setMemory] = (0, import_react.useState)(null); - const [memoryOpen, setMemoryOpen] = (0, import_react.useState)(false); - const [memoryDraft, setMemoryDraft] = (0, import_react.useState)({ goal: "", constraints: "", acceptance: "", decisions: "" }); - const [tab, setTab] = (0, import_react.useState)("court"); - const [tasks, setTasks] = (0, import_react.useState)([]); - const [artifacts, setArtifacts] = (0, import_react.useState)([]); - const [taskFormOpen, setTaskFormOpen] = (0, import_react.useState)(false); - const [taskDraft, setTaskDraft] = (0, import_react.useState)({ title: "", goal: "", ownerSeatId: SEAT_IDS[0] }); - const [summaryBusy, setSummaryBusy] = (0, import_react.useState)(false); - const [artifactFormOpen, setArtifactFormOpen] = (0, import_react.useState)(false); - const [artifactDraft, setArtifactDraft] = (0, import_react.useState)({ title: "", path: "", summary: "" }); - const alive = (0, import_react.useRef)(true); - (0, import_react.useEffect)(() => () => { - alive.current = false; - }, []); - const loadProject = (0, import_react.useCallback)(async () => { - setPhase("loading"); - setError(null); - setErrorRetryable(true); - setNotice(null); - const workspace = currentWorkspace(); - if (!workspace) { - setPhase("no-workspace"); - return; + const sessionId = props && props.sessionId; + const resolveWorkspace = (0, import_react2.useCallback)(() => workspaceForSessionId(sessionId), [sessionId]); + return (0, import_react2.createElement)(WorkbenchV2, { + sessionId, + onClose: props && props.onClose, + resolveWorkspace, + navigateToSession, + openRightTab: tryOpenRightTab, + selectionCache: selectedSeatCache, + getLastSeatId: () => lastSelectedSeatId, + setLastSeatId: (id) => { + lastSelectedSeatId = id; } - try { - const projectView = await request("open", { - workspaceId: workspace.workspaceId, - name: workspace.name, - path: workspace.path - }); - let modelCatalog = null; - try { - modelCatalog = await request("models"); - } catch (modelError) { - console.warn("[sansheng] 模型目录加载失败:", modelError && modelError.message ? modelError.message : modelError); - } - let memoryData = null; - try { - memoryData = (await request("memory", { projectId: projectView.project.id })).memory; - } catch (memoryError) { - console.warn("[sansheng] 项目共识加载失败:", memoryError && memoryError.message ? memoryError.message : memoryError); - } - let taskList = []; - let artifactList = []; - try { - taskList = (await request("tasks", { projectId: projectView.project.id })).tasks ?? []; - } catch (taskError) { - console.warn("[sansheng] 任务加载失败:", taskError && taskError.message ? taskError.message : taskError); - } - try { - artifactList = (await request("artifacts", { projectId: projectView.project.id })).artifacts ?? []; - } catch (artifactError) { - console.warn("[sansheng] 成果加载失败:", artifactError && artifactError.message ? artifactError.message : artifactError); - } - if (!alive.current) return; - setView(projectView); - setModels(modelCatalog); - setMemory(memoryData); - setMemoryDraft({ - goal: memoryData?.goal ?? "", - constraints: (memoryData?.constraints ?? []).join("\n"), - acceptance: (memoryData?.acceptance ?? []).join("\n"), - decisions: "" - }); - setTasks(taskList); - setArtifacts(artifactList); - setPhase("ready"); - } catch (loadError) { - if (!alive.current) return; - setError(loadError && loadError.message ? loadError.message : "加载失败"); - setErrorRetryable(!(loadError && loadError.retryable === false)); - setPhase("error"); - } - }, []); - (0, import_react.useEffect)(() => { - void loadProject(); - }, [loadProject]); - const projectIdForSeat = view && view.project ? view.project.id : null; - (0, import_react.useEffect)(() => { - if (!projectIdForSeat) return; - const saved = selectedSeatCache.get(projectIdForSeat); - if (saved && SEAT_IDS.includes(saved)) { - lastSelectedSeatId = saved; - setSelectedSeatId(saved); - } - }, [projectIdForSeat]); - const wb = buildWorkbenchView(view, { selectedSeatId, models, draft }); - const seatById = (0, import_react.useMemo)(() => { - const map = {}; - for (const seat of wb.seats) map[seat.id] = seat; - return map; - }, [wb.seats]); - function pickSeat(id) { - if (!id) return; - if (id !== selectedSeatId) { - setSelectedSeatId(id); - setConfigOpen(false); - } - lastSelectedSeatId = id; - const pid = view && view.project ? view.project.id : null; - if (pid) selectedSeatCache.set(pid, id); - const seat = seatById[id]; - if (seat && seat.status === "missing") setNotice("「" + seat.name + "」的会话已不存在,点下面的「重建会话」可重新建立"); - else if (seat && seat.status !== "bound" && seat.status !== "creating") setNotice("「" + seat.name + "」还没开启,点下面的按钮开启这个部门"); - } - async function openSelectedSeat() { - const projectId = view && view.project ? view.project.id : null; - const seat = seatById[wb.selected.id]; - if (!projectId || !seat) return; - if (seat.status === "missing") { - setNotice("「" + seat.name + "」的会话已不存在,点下面的「重建会话」可重新建立"); - return; - } - if (seat.status !== "bound") { - setNotice("「" + seat.name + "」还没开启,先点「开启『" + seat.name + "』」"); - return; - } - setBusy(true); - setError(null); - try { - const result = await request("openSeat", { projectId, seatId: seat.id }); - if (!alive.current) return; - if (!result || !result.sessionId) throw new Error("宿主没有返回会话"); - navigateToSession(result.sessionId); - setNotice("已切换到" + seat.name + "会话"); - } catch (openError) { - if (!alive.current) return; - setError(openError && openError.message ? openError.message : "打开会话失败"); - if (openError && openError.code === "sansheng/session-missing") { - try { - const next = await request("project", { projectId }); - if (alive.current) setView(next); - } catch { - } - } - } finally { - if (alive.current) setBusy(false); - } - } - async function rebuildSelectedSeat() { - const projectId = view && view.project ? view.project.id : null; - const seat = seatById[wb.selected.id]; - if (!projectId || !seat) return; - const rec = seatRecordOf(view, seat.id); - const expectedSessionId = rec && rec.sessionId ? rec.sessionId : void 0; - setBusy(true); - setError(null); - setNotice("正在重建「" + seat.name + "」的会话…"); - try { - const next = await request("rebuildSeat", { projectId, seatId: seat.id, expectedSessionId }); - if (!alive.current) return; - setView(next); - setNotice("已重建「" + seat.name + "」的会话;旧会话历史仍保留"); - } catch (rebuildError) { - if (!alive.current) return; - setError(rebuildError && rebuildError.message ? rebuildError.message : "重建会话失败"); - if (rebuildError && rebuildError.code === "sansheng/session-conflict") { - try { - const next = await request("project", { projectId }); - if (alive.current) setView(next); - } catch { - } - } - } finally { - if (alive.current) setBusy(false); - } - } - function modelFromValue(value) { - const option = findModelOption(wb.selected.modelOptions, value); - if (!option) return null; - return option.reasoningEffort ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } : { provider: option.provider, model: option.model }; - } - async function rememberModel(value) { - const projectId = view && view.project ? view.project.id : null; - if (!projectId || !value) return; - const seatId = selectedSeatId; - const model = modelFromValue(value); - if (!model) return; - try { - const saved = await request("configure", { projectId, seatId, model }); - if (!alive.current) return; - setView((prev) => { - if (!prev || !prev.project) return prev; - const seats = Array.isArray(prev.project.seats) ? prev.project.seats.map((seat) => seat && seat.id === seatId ? { ...seat, ...saved && saved.seat ? saved.seat : { model } } : seat) : prev.project.seats; - return { ...prev, revision: (prev.revision ?? 0) + 1, project: { ...prev.project, seats } }; - }); - setDraft((prev) => clearDraft(prev, seatId)); - setNotice("已记住「" + wb.selected.name + "」的模型,下次打开继续使用"); - } catch (error2) { - if (alive.current) setNotice(error2 && error2.message ? error2.message : "模型记忆失败"); - } - } - function setModelValue(value) { - setDraft((prev) => updateDraft(prev, selectedSeatId, { modelValue: value })); - void rememberModel(value); - } - function setInstructions(value) { - setDraft((prev) => updateDraft(prev, selectedSeatId, { instructions: value })); - } - async function enableSelectedSeat() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - const seatId = wb.selected.id; - setBusy(true); - setError(null); - setNotice("正在开启「" + wb.selected.name + "」…"); - try { - const next = await request("enableSeat", { projectId, seatId }); - if (!alive.current) return; - setView(next); - setNotice("已开启「" + wb.selected.name + "」的独立会话"); - try { - tryOpenRightTab(); - } catch { - } - } catch (enableError) { - if (alive.current) setError(enableError && enableError.message ? enableError.message : "开启失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function enableSeats() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - setBusy(true); - setError(null); - setNotice("正在启用十席…"); - try { - const next = await request("enable", { projectId }); - if (!alive.current) return; - setView(next); - setNotice("十席已启用(建立独立会话,不自动运行模型)"); - } catch (enableError) { - if (alive.current) setError(enableError && enableError.message ? enableError.message : "启用失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function saveConfig() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - const seatId = wb.selected.id; - const value = wb.selected.modelValue; - if (!value) { - setNotice("请先为当前角色选择模型"); - return; - } - const option = findModelOption(wb.selected.modelOptions, value); - const model = option ? option.reasoningEffort ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } : { provider: option.provider, model: option.model } : null; - setBusy(true); - setError(null); - setNotice("保存中…"); - try { - await request("configure", { projectId, seatId, model, instructions: wb.selected.instructions }); - const next = await request("project", { projectId }); - if (!alive.current) return; - setView(next); - setDraft((prev) => clearDraft(prev, seatId)); - setNotice("已保存"); - } catch (saveError) { - if (alive.current) setError(saveError && saveError.message ? saveError.message : "保存失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function saveMemory() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - setBusy(true); - setError(null); - setNotice("保存项目共识…"); - try { - const result = await request("memoryUpdate", { - projectId, - expectedRevision: memory?.revision ?? 0, - goal: memoryDraft.goal, - constraints: memoryDraft.constraints.split("\n").map((line) => line.trim()).filter(Boolean), - acceptance: memoryDraft.acceptance.split("\n").map((line) => line.trim()).filter(Boolean), - decisions: memoryDraft.decisions.split("\n").map((line) => line.trim()).filter(Boolean).map((text) => ({ - type: "user", - status: "active", - text, - sourceRefs: wb.selected.sessionId ? [{ sessionId: wb.selected.sessionId, excerpt: "工作台记录", recordedAt: Date.now() }] : [] - })), - sources: wb.selected.sessionId ? [{ id: "ui-" + Date.now(), sessionId: wb.selected.sessionId, excerpt: "工作台记录", recordedAt: Date.now() }] : [] - }); - if (!alive.current) return; - setMemory(result.memory); - setMemoryDraft((prev) => ({ ...prev, decisions: "" })); - setNotice("项目共识已保存(v" + result.memory.revision + ")"); - } catch (memoryError) { - if (alive.current) setError(memoryError && memoryError.message ? memoryError.message : "保存项目共识失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function reloadTasks(projectId) { - try { - const result = await request("tasks", { projectId }); - if (alive.current) setTasks(result.tasks ?? []); - } catch (error2) { - if (alive.current) setNotice(error2 && error2.message ? error2.message : "任务列表刷新失败"); - } - } - async function createTask() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - const title = taskDraft.title.trim(); - if (!title) { - setNotice("任务标题不能为空"); - return; - } - setBusy(true); - setError(null); - try { - await request("taskCreate", { projectId, title, goal: taskDraft.goal, ownerSeatId: taskDraft.ownerSeatId }); - setTaskDraft({ title: "", goal: "", ownerSeatId: taskDraft.ownerSeatId }); - setTaskFormOpen(false); - await reloadTasks(projectId); - setNotice("已存为草稿;点「派工」才会交给部门。"); - } catch (error2) { - if (alive.current) setError(error2 && error2.message ? error2.message : "新建任务失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function dispatchTask(taskId) { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - setBusy(true); - setError(null); - try { - const result = await request("taskDispatch", { projectId, taskId }); - await reloadTasks(projectId); - setNotice(result.delivered ? "已派工到该部门会话。" : "已记录为待执行(当前宿主暂不支持直接发送)。"); - } catch (error2) { - if (alive.current) setError(error2 && error2.message ? error2.message : "派工失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function summarizeByShangshu() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - setSummaryBusy(true); - setError(null); - try { - const result = await request("shangshuSummary", { projectId }); - if (!alive.current) return; - if (!result || !result.sessionId) throw new Error("宿主没有返回尚书会话"); - setNotice("已请尚书汇总当前任务,正在打开尚书会话…"); - navigateToSession(result.sessionId); - } catch (summaryError) { - if (alive.current) setError(summaryError && summaryError.message ? summaryError.message : "尚书汇总请求失败"); - } finally { - if (alive.current) setSummaryBusy(false); - } - } - async function cancelTask(taskId) { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - setBusy(true); - setError(null); - try { - await request("taskCancel", { projectId, taskId }); - await reloadTasks(projectId); - setNotice("任务已取消。"); - } catch (error2) { - if (alive.current) setError(error2 && error2.message ? error2.message : "取消失败"); - } finally { - if (alive.current) setBusy(false); - } - } - async function addArtifact() { - const projectId = view && view.project ? view.project.id : null; - if (!projectId) return; - const title = artifactDraft.title.trim(); - if (!title) { - setNotice("成果名称不能为空"); - return; - } - setBusy(true); - setError(null); - try { - const result = await request("artifactAdd", { projectId, title, path: artifactDraft.path, summary: artifactDraft.summary }); - setArtifactDraft({ title: "", path: "", summary: "" }); - setArtifactFormOpen(false); - setArtifacts((list) => [...list, result.artifact]); - setNotice("成果已登记。"); - } catch (error2) { - if (alive.current) setError(error2 && error2.message ? error2.message : "登记成果失败"); - } finally { - if (alive.current) setBusy(false); - } - } - const seatCard = (seat) => (0, import_react.createElement)( - "button", - { - key: seat.id, - type: "button", - className: "ssw-seat", - "aria-pressed": seat.selected ? "true" : "false", - title: seat.name + " · " + seat.duty + "(" + seat.statusLabel + ")", - onClick: () => pickSeat(seat.id) - }, - (0, import_react.createElement)( - "span", - { className: "ssw-role-top" }, - (0, import_react.createElement)("span", { className: "ssw-role-name" }, seat.name), - (0, import_react.createElement)("span", { className: "ssw-dot", "data-status": seat.status, "aria-hidden": "true" }) - ), - (0, import_react.createElement)("span", { className: "ssw-role-duty" }, seat.duty) - ); - const pickList = (ids) => ids.map((id) => seatById[id]).filter(Boolean); - const tree = (0, import_react.createElement)( - "section", - { className: "ssw-tree", "aria-label": "切换角色" }, - (0, import_react.createElement)("div", { className: "ssw-lead" }, pickList(wb.groups.lead).map(seatCard)), - (0, import_react.createElement)( - "div", - { className: "ssw-sansheng" }, - (0, import_react.createElement)("span", { className: "ssw-group-label" }, "三省"), - (0, import_react.createElement)("div", { className: "ssw-trio" }, pickList(wb.groups.sansheng).map(seatCard)) - ), - (0, import_react.createElement)( - "div", - { className: "ssw-ministries" }, - (0, import_react.createElement)("span", { className: "ssw-group-label" }, "六部 · 尚书统筹"), - (0, import_react.createElement)("div", { className: "ssw-six" }, pickList(wb.groups.liubu).map(seatCard)) - ) - ); - const head = (0, import_react.createElement)( - "header", - { className: "ssw-head" }, - (0, import_react.createElement)(TreeIcon), - (0, import_react.createElement)("strong", { className: "ssw-head-title" }, "工作台"), - onClose ? (0, import_react.createElement)("button", { type: "button", className: "ssw-icon-btn", onClick: onClose, "aria-label": "收起工作台" }, (0, import_react.createElement)(CloseIcon)) : null - ); - const projectInfo = (0, import_react.createElement)( - "div", - { className: "ssw-project" }, - (0, import_react.createElement)( - "div", - { className: "ssw-project-line", style: { justifyContent: "flex-end" } }, - (0, import_react.createElement)("span", { className: "ssw-count" }, wb.project.seatCount + " 个角色 · " + wb.project.sessionCount + " 个会话") - ), - (0, import_react.createElement)("div", { className: "ssw-project-title" }, wb.projectTitle || "未命名项目") - ); - const selectedStatus = wb.selected.status; - const detailActions = (0, import_react.createElement)( - "div", - { className: "ssw-current-actions" }, - selectedStatus === "bound" ? (0, import_react.createElement)("button", { - type: "button", - className: "ssw-primary", - disabled: busy, - onClick: openSelectedSeat - }, "开始对话") : selectedStatus === "missing" ? (0, import_react.createElement)("button", { - type: "button", - className: "ssw-primary", - disabled: busy, - onClick: rebuildSelectedSeat - }, "重建会话") : (0, import_react.createElement)("button", { - type: "button", - className: "ssw-primary", - disabled: busy || selectedStatus === "creating", - onClick: enableSelectedSeat - }, selectedStatus === "creating" ? "正在开启…" : "开启「" + wb.selected.name + "」") - ); - const optionEls = wb.selected.modelOptions.map((option) => (0, import_react.createElement)("option", { key: option.value, value: option.value }, option.label)); - if (wb.selected.modelValue && !wb.selected.modelOptions.some((option) => option.value === wb.selected.modelValue)) { - optionEls.push((0, import_react.createElement)("option", { key: "__current__", value: wb.selected.modelValue }, wb.selected.modelLabel)); - } - const config = (0, import_react.createElement)( - "section", - { className: "ssw-config" }, - (0, import_react.createElement)( - "button", - { - type: "button", - className: "ssw-config-toggle", - "aria-expanded": configOpen ? "true" : "false", - onClick: () => setConfigOpen((value) => !value) - }, - (0, import_react.createElement)(GearIcon), - (0, import_react.createElement)("span", null, "配置" + wb.selected.name + (wb.selected.dirty ? " · 未保存" : "")), - (0, import_react.createElement)(ChevronIcon) - ), - configOpen ? (0, import_react.createElement)( - "div", - { className: "ssw-config-body" }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "默认模型(开启该部门时应用)"), - (0, import_react.createElement)( - "select", - { - className: "ssw-field", - value: wb.selected.modelValue, - disabled: busy, - onChange: (event) => setModelValue(event.target.value) - }, - (0, import_react.createElement)("option", { value: "", disabled: true }, UNCHOSEN_MODEL_LABEL), - ...optionEls - ), - (0, import_react.createElement)("label", { className: "ssw-label" }, "角色补充说明"), - (0, import_react.createElement)("textarea", { - className: "ssw-field ssw-textarea", - rows: 4, - value: wb.selected.instructions, - disabled: busy, - placeholder: "补充该角色在当前项目中的工作要求", - onChange: (event) => setInstructions(event.target.value) - }), - (0, import_react.createElement)("p", { className: "ssw-scope-note" }, "这里预配置的模型会在开启该部门或按需派工时应用;丞相派工不选择模型。只影响当前项目当前角色。"), - (0, import_react.createElement)( - "div", - { className: "ssw-save-row" }, - (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", disabled: busy, onClick: saveConfig }, busy ? "保存中…" : "保存配置"), - wb.selected.dirty ? (0, import_react.createElement)("span", { className: "ssw-save-status" }, "有未保存修改") : null - ) - ) : null - ); - const memorySection = (0, import_react.createElement)( - "section", - { className: "ssw-config" }, - (0, import_react.createElement)( - "button", - { - type: "button", - className: "ssw-config-toggle", - "aria-expanded": memoryOpen ? "true" : "false", - onClick: () => setMemoryOpen((value) => !value) - }, - (0, import_react.createElement)(GearIcon), - (0, import_react.createElement)("span", null, "项目共识 v" + (memory?.revision ?? 0) + (memory?.updatedAt ? " · 最近更新" : " · 尚未建立")), - (0, import_react.createElement)(ChevronIcon) - ), - memoryOpen ? (0, import_react.createElement)( - "div", - { className: "ssw-config-body" }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "项目目标"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: memoryDraft.goal, placeholder: "这个项目最终要达成什么", onChange: (event) => setMemoryDraft({ ...memoryDraft, goal: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "硬约束(每行一条,部门必须遵守)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: memoryDraft.constraints, placeholder: "例如:不能改动线上数据", onChange: (event) => setMemoryDraft({ ...memoryDraft, constraints: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "验收标准(每行一条)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: memoryDraft.acceptance, placeholder: "例如:交付前必须跑完回归测试", onChange: (event) => setMemoryDraft({ ...memoryDraft, acceptance: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "新增决定(每行一条,按用户明确要求记录)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 2, value: memoryDraft.decisions, placeholder: "例如:先保证稳定性,再考虑样式", onChange: (event) => setMemoryDraft({ ...memoryDraft, decisions: event.target.value }) }), - (0, import_react.createElement)("p", { className: "ssw-scope-note" }, "保存后版本号会增加;每个部门在下一次模型请求前都会收到这份共识。当前为本地临时存储,后续迁移到 Mnemon Documents。"), - (0, import_react.createElement)("div", { className: "ssw-save-row" }, (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", disabled: busy, onClick: saveMemory }, busy ? "保存中…" : "保存共识")) - ) : null - ); - const report = (0, import_react.createElement)( - "section", - { className: "ssw-report" }, - (0, import_react.createElement)("button", { - type: "button", - className: "ssw-report-toggle", - "aria-expanded": reportOpen ? "true" : "false", - onClick: () => setReportOpen((value) => !value) - }, reportOpen ? "收起角色职责" : "全部角色职责"), - reportOpen ? (0, import_react.createElement)( - "div", - { className: "ssw-report-list" }, - SEAT_IDS.map((id) => { - const rec = seatRecordOf(view, id); - const m = rec && rec.model; - const modelLabel = m && m.model ? m.model + (m.reasoningEffort ? " · " + m.reasoningEffort : "") : "未选择模型"; - return (0, import_react.createElement)( - "div", - { key: id, className: "ssw-report-item", "data-seat": id }, - (0, import_react.createElement)( - "div", - { className: "ssw-report-head" }, - (0, import_react.createElement)("strong", null, SEATS[id].label), - (0, import_react.createElement)("span", null, SEATS[id].duty) - ), - (0, import_react.createElement)("p", { className: "ssw-report-model" }, "模型:" + modelLabel), - (0, import_react.createElement)("p", { className: "ssw-report-text" }, SEATS[id].responsibility) - ); - }) - ) : null - ); - const statusEl = error ? (0, import_react.createElement)("p", { className: "ssw-error", role: "alert" }, error) : notice ? (0, import_react.createElement)("p", { className: "ssw-notice", role: "status" }, notice) : null; - const tabCounts = { court: wb.project.seatCount, tasks: tasks.length, artifacts: artifacts.length }; - const tabBar = (0, import_react.createElement)( - "div", - { className: "ssw-tabs", role: "tablist" }, - [["court", "朝堂"], ["tasks", "任务"], ["artifacts", "成果"]].map(([id, label]) => (0, import_react.createElement)("button", { - key: id, - type: "button", - role: "tab", - "aria-selected": tab === id ? "true" : "false", - className: "ssw-tab" + (tab === id ? " is-active" : ""), - onClick: () => setTab(id) - }, (0, import_react.createElement)("span", null, label), (0, import_react.createElement)("span", { className: "ssw-tab-count" }, String(tabCounts[id] ?? 0)))) - ); - const TASK_STATUS_LABEL = { draft: "草稿", prepared: "待执行", dispatched: "已派工", running: "执行中", done: "已完成", cancelled: "已取消", failed: "失败" }; - const taskRows = tasks.length === 0 ? (0, import_react.createElement)("p", { className: "ssw-empty-line" }, "这个项目还没有任务。点「新建任务」先存一张草稿。") : tasks.map((task) => { - const stale = (memory?.revision ?? 0) > (task.contextRevision ?? 0) && (task.status === "dispatched" || task.status === "prepared" || task.status === "running"); - return (0, import_react.createElement)( - "article", - { key: task.id, className: "ssw-row", "data-task": task.id }, - (0, import_react.createElement)( - "div", - { className: "ssw-row-top" }, - (0, import_react.createElement)("strong", { className: "ssw-row-title" }, task.title), - (0, import_react.createElement)("span", { className: "ssw-badge", "data-status": task.status }, TASK_STATUS_LABEL[task.status] ?? task.status), - stale ? (0, import_react.createElement)("span", { className: "ssw-badge", "data-status": "stale" }, "要求有更新") : null - ), - (0, import_react.createElement)("p", { className: "ssw-row-meta" }, (SEATS[task.ownerSeatId]?.label ?? task.ownerSeatId) + (task.goal ? " · " + task.goal : "") + (task.contextRevision !== void 0 ? " · 共识 v" + task.contextRevision : "")), - task.note ? (0, import_react.createElement)("p", { className: "ssw-row-note" }, task.note) : null, - task.result ? (0, import_react.createElement)("p", { className: "ssw-row-result" }, "结果:" + task.result) : null, - (0, import_react.createElement)( - "div", - { className: "ssw-row-actions" }, - task.status === "draft" || task.status === "prepared" || task.status === "failed" ? (0, import_react.createElement)("button", { type: "button", className: "ssw-link", disabled: busy, onClick: () => dispatchTask(task.id) }, task.status === "prepared" ? "重试派工" : "派工") : null, - task.status !== "done" && task.status !== "cancelled" ? (0, import_react.createElement)("button", { type: "button", className: "ssw-link ssw-link-muted", disabled: busy, onClick: () => cancelTask(task.id) }, "取消") : null - ) - ); }); - const taskView = (0, import_react.createElement)( - "section", - { className: "ssw-page" }, - (0, import_react.createElement)( - "div", - { className: "ssw-page-head" }, - (0, import_react.createElement)("strong", null, "任务 · " + tasks.length), - (0, import_react.createElement)( - "div", - { style: { display: "flex", alignItems: "center", gap: "10px" } }, - (0, import_react.createElement)("button", { type: "button", className: "ssw-link", disabled: busy || summaryBusy || tasks.length === 0, onClick: () => { - void summarizeByShangshu(); - } }, summaryBusy ? "汇总中…" : "尚书汇总"), - (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: () => setTaskFormOpen((value) => !value) }, taskFormOpen ? "收起" : "新建任务") - ) - ), - taskFormOpen ? (0, import_react.createElement)( - "form", - { className: "ssw-form", onSubmit: (event) => { - event.preventDefault(); - void createTask(); - } }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "标题"), - (0, import_react.createElement)("input", { className: "ssw-field", value: taskDraft.title, placeholder: "交给部门做什么", onChange: (event) => setTaskDraft({ ...taskDraft, title: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "目标(可选)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: taskDraft.goal, onChange: (event) => setTaskDraft({ ...taskDraft, goal: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "主责部门"), - (0, import_react.createElement)( - "select", - { className: "ssw-field", value: taskDraft.ownerSeatId, onChange: (event) => setTaskDraft({ ...taskDraft, ownerSeatId: event.target.value }) }, - SEAT_IDS.map((id) => (0, import_react.createElement)("option", { key: id, value: id }, SEATS[id].label)) - ), - (0, import_react.createElement)("div", { className: "ssw-save-row" }, (0, import_react.createElement)("button", { type: "submit", className: "ssw-primary", disabled: busy }, busy ? "保存中…" : "保存草稿")) - ) : null, - (0, import_react.createElement)("div", { className: "ssw-list" }, taskRows) - ); - const artifactRows = artifacts.length === 0 ? (0, import_react.createElement)("p", { className: "ssw-empty-line" }, "这个项目还没有登记成果。") : artifacts.map((item) => (0, import_react.createElement)( - "article", - { key: item.id, className: "ssw-row", "data-artifact": item.id }, - (0, import_react.createElement)("div", { className: "ssw-row-top" }, (0, import_react.createElement)("strong", { className: "ssw-row-title" }, item.title)), - item.summary ? (0, import_react.createElement)("p", { className: "ssw-row-meta" }, item.summary) : null, - item.path ? (0, import_react.createElement)("p", { className: "ssw-row-note" }, item.path) : null - )); - const artifactView = (0, import_react.createElement)( - "section", - { className: "ssw-page" }, - (0, import_react.createElement)( - "div", - { className: "ssw-page-head" }, - (0, import_react.createElement)("strong", null, "成果 · " + artifacts.length), - (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: () => setArtifactFormOpen((value) => !value) }, artifactFormOpen ? "收起" : "登记成果") - ), - artifactFormOpen ? (0, import_react.createElement)( - "form", - { className: "ssw-form", onSubmit: (event) => { - event.preventDefault(); - void addArtifact(); - } }, - (0, import_react.createElement)("label", { className: "ssw-label" }, "成果名称"), - (0, import_react.createElement)("input", { className: "ssw-field", value: artifactDraft.title, onChange: (event) => setArtifactDraft({ ...artifactDraft, title: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "文件路径(可选)"), - (0, import_react.createElement)("input", { className: "ssw-field", value: artifactDraft.path, onChange: (event) => setArtifactDraft({ ...artifactDraft, path: event.target.value }) }), - (0, import_react.createElement)("label", { className: "ssw-label" }, "说明(可选)"), - (0, import_react.createElement)("textarea", { className: "ssw-field ssw-textarea", rows: 3, value: artifactDraft.summary, onChange: (event) => setArtifactDraft({ ...artifactDraft, summary: event.target.value }) }), - (0, import_react.createElement)("div", { className: "ssw-save-row" }, (0, import_react.createElement)("button", { type: "submit", className: "ssw-primary", disabled: busy }, busy ? "保存中…" : "保存")) - ) : null, - (0, import_react.createElement)("div", { className: "ssw-list" }, artifactRows) - ); - const detail = (0, import_react.createElement)( - "section", - { className: "ssw-current" }, - (0, import_react.createElement)( - "div", - { className: "ssw-current-top" }, - (0, import_react.createElement)("strong", { className: "ssw-current-name" }, wb.selected.name), - (0, import_react.createElement)("span", { className: "ssw-current-label" }, "角色职责 · " + wb.selected.statusLabel) - ), - (0, import_react.createElement)("p", { className: "ssw-current-text" }, wb.selected.responsibility), - detailActions - ); - const courtView = (0, import_react.createElement)(import_react.Fragment, null, tree, detail, config, memorySection); - let body; - if (phase === "loading") body = (0, import_react.createElement)("div", { className: "ssw-loading" }, "正在加载工作台…"); - else if (phase === "no-workspace") body = (0, import_react.createElement)( - "div", - { className: "ssw-empty" }, - (0, import_react.createElement)("p", null, "请先选择项目"), - (0, import_react.createElement)("p", { className: "ssw-hint" }, "在左侧工作区里选中一个项目后再打开三省六部。"), - (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: loadProject }, "重新检查") - ); - else if (phase === "error" && !view) body = (0, import_react.createElement)( - "div", - { className: "ssw-empty" }, - (0, import_react.createElement)("p", { className: "ssw-error" }, error || "加载失败"), - errorRetryable ? (0, import_react.createElement)("button", { type: "button", className: "ssw-primary", onClick: loadProject }, "重试") : null - ); - else body = (0, import_react.createElement)( - import_react.Fragment, - null, - projectInfo, - tabBar, - tab === "tasks" ? taskView : tab === "artifacts" ? artifactView : courtView, - statusEl - ); - return (0, import_react.createElement)("div", { className: "ssw-root ssw-scope" }, head, body); } const NAV_PANEL_ID = "sansheng-workbench"; const NAV_ORDER = 32; - function openRightWorkbench() { - return tryOpenRightTab(); + function openRightWorkbench(sessionId) { + const opened = tryOpenRightTab(sessionId); + if (opened) { + rightWorkbenchPinned = true; + writeRightWorkbenchPinned(true); + } + return opened; } function closeRightWorkbench() { + rightWorkbenchPinned = false; + writeRightWorkbenchPinned(false); + const right = get("sidebarRight"); + const row = findRightWorkbenchTab(); + if (row && right && isFn(right.close)) { + try { + right.close(row.tabId); + return; + } catch { + } + } const layout = get("layout"); if (layout && isFn(layout.selectPanel)) { try { @@ -1963,7 +3372,6 @@ function apply(ctx) { } catch { } } - const right = get("sidebarRight"); if (right && isFn(right.closeTab)) { try { right.closeTab(TAB_KIND); @@ -1972,16 +3380,84 @@ function apply(ctx) { } } } + function installRightDockPinning() { + const right = get("sidebarRight"); + if (!right || !isFn(right.mounted?.subscribe)) return; + const delays = [60, 140, 280, 560, 1e3, 1800, 3e3]; + let timer = null; + let attempt = 0; + const clear = () => { + if (timer !== null) { + clearTimeout(timer); + timer = null; + } + }; + const ensure = () => { + timer = null; + if (!rightWorkbenchPinned) { + attempt = 0; + return; + } + try { + const sessionId = rightMountedSessionId(); + if (findRightWorkbenchTab(sessionId)) { + if (revealRightTab(sessionId)) { + attempt = 0; + return; + } + } + if (openRightWorkbench(sessionId)) { + attempt = 0; + return; + } + } catch { + } + if (attempt < delays.length - 1) { + attempt += 1; + timer = setTimeout(ensure, delays[attempt]); + } + }; + const kick = () => { + if (!rightWorkbenchPinned) return; + clear(); + attempt = 0; + 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) { const size = props && typeof props.size === "number" ? props.size : 16; - const [floating, setFloating] = (0, import_react.useState)(false); + const [floating, setFloating] = (0, import_react2.useState)(false); const stop = (event) => { if (event && isFn(event.stopPropagation)) event.stopPropagation(); }; const onClick = (event) => { if (event && isFn(event.stopPropagation)) event.stopPropagation(); if (event && isFn(event.preventDefault)) event.preventDefault(); - if (openRightWorkbench()) { + if (openRightWorkbench(currentSessionId())) { setFloating(false); return; } @@ -1989,18 +3465,18 @@ function apply(ctx) { }; let panel = null; if (floating) { - const card = (0, import_react.createElement)( + const card = (0, import_react2.createElement)( "div", { className: "ssw-float", role: "dialog", "aria-label": "三省六部工作台" }, - (0, import_react.createElement)(SanshengWorkbench, { onClose: () => setFloating(false) }) + (0, import_react2.createElement)(SanshengWorkbench, { sessionId: currentSessionId(), onClose: () => setFloating(false) }) ); const canPortal = typeof document !== "undefined" && document.body && isFn(import_react_dom.createPortal); panel = canPortal ? (0, import_react_dom.createPortal)(card, document.body) : card; } - return (0, import_react.createElement)( - import_react.Fragment, + return (0, import_react2.createElement)( + import_react2.Fragment, null, - (0, import_react.createElement)("span", { + (0, import_react2.createElement)("span", { className: "ssw-nav-hit", role: "presentation", title: "三省六部", @@ -2008,7 +3484,7 @@ function apply(ctx) { onPointerDown: stop, onMouseDown: stop, "aria-expanded": floating ? "true" : "false" - }, (0, import_react.createElement)(TreeIcon, { width: size, height: size })), + }, (0, import_react2.createElement)(TreeIcon, { width: size, height: size })), panel ); } @@ -2023,11 +3499,11 @@ function apply(ctx) { } function SanshengNavFallback() { const hasBetterSidebar = !!get("betterSidebar"); - const [mode, setMode] = (0, import_react.useState)("pending"); - (0, import_react.useEffect)(() => { + const [mode, setMode] = (0, import_react2.useState)("pending"); + (0, import_react2.useEffect)(() => { let opened = false; try { - opened = openRightWorkbench(); + opened = openRightWorkbench(currentSessionId()); } catch { opened = false; } @@ -2045,7 +3521,7 @@ function apply(ctx) { for (const delay of [200, 600, 1200, 2e3]) { setTimeout(() => { try { - if (!openedLater && openRightWorkbench()) { + if (!openedLater && openRightWorkbench(currentSessionId())) { openedLater = true; backToChat(); } @@ -2058,7 +3534,7 @@ function apply(ctx) { }, 2600); return void 0; }, []); - (0, import_react.useEffect)(() => { + (0, import_react2.useEffect)(() => { if (mode !== "docked") return; backToChat(); const timer = setTimeout(backToChat, 700); @@ -2066,16 +3542,16 @@ function apply(ctx) { }, [mode]); if (mode === "pending") return null; if (mode === "docked") return null; - return (0, import_react.createElement)( + return (0, import_react2.createElement)( "div", { className: "ssw-tab-body" }, - (0, import_react.createElement)( + (0, import_react2.createElement)( "div", { className: "ssw-inline-bar" }, - (0, import_react.createElement)("span", null, "工作台 · 内嵌模式"), - (0, import_react.createElement)("button", { type: "button", className: "ssw-link", onClick: backToChat }, "返回对话") + (0, import_react2.createElement)("span", null, "工作台 · 内嵌模式"), + (0, import_react2.createElement)("button", { type: "button", className: "ssw-link", onClick: backToChat }, "返回对话") ), - (0, import_react.createElement)(SanshengWorkbench, {}) + (0, import_react2.createElement)(SanshengWorkbench, { sessionId: currentSessionId() }) ); } function registerNavEntry() { @@ -2110,6 +3586,7 @@ function apply(ctx) { } registerNavEntry(); registerRightTabType(); + installRightDockPinning(); try { install(ctx); } catch (error) { diff --git a/package.json b/package.json index 53880c1..cda05b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-sansheng-liubu", - "version": "1.0.0", + "version": "1.1.0", "description": "三省六部:每个项目固定十席角色与独立会话的 DSH 插件(第一版)。", "keywords": [ "dsh-plugin", diff --git a/src/client/index.js b/src/client/index.js index c693fd6..2aacb7d 100644 --- a/src/client/index.js +++ b/src/client/index.js @@ -4,22 +4,30 @@ import { createElement as h, Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react' import { createPortal } from 'react-dom' import { SEAT_IDS, SEATS } from '../shared/roles.js' -import { - buildWorkbenchView, - findModelOption, - updateDraft, - clearDraft, - UNCHOSEN_MODEL_LABEL, -} from './workbench.js' +import { WorkbenchV2 } from './workbench-v2.js' +import { workspaceForSession, workspaceItemsFromSnapshot, sessionSummaryFromSnapshot } from './workspace.js' import { request } from './transport.js' import { CSS as WORKBENCH_CSS } from './styles.js' import { install as installNativePanel } from '../native/index.js' -export const inject = ['sessions', 'uiWorkspace', 'uiConversation', 'slots', 'theme', 'layout'] +export const inject = ['sessions', 'workspaces', 'uiWorkspace', 'uiConversation', 'slots', 'theme', 'layout', 'sidebarRightTabs', 'sidebarRight'] const PLUGIN_ID = 'dsh-sansheng' const TAB_KIND = 'sansheng-workbench' const TAB_TYPE_ID = 'dsh-sansheng:workbench' +const RIGHT_PIN_KEY = 'sansheng.right-workbench.pinned' + +function readRightWorkbenchPinned() { + try { return typeof localStorage !== 'undefined' && localStorage.getItem(RIGHT_PIN_KEY) === '1' } catch { return false } +} + +function writeRightWorkbenchPinned(value) { + try { + if (typeof localStorage === 'undefined') return + if (value) localStorage.setItem(RIGHT_PIN_KEY, '1') + else localStorage.removeItem(RIGHT_PIN_KEY) + } catch { /* 忽略 */ } +} function installStyles(doc, tag, text) { if (!doc || !doc.head) return null @@ -103,23 +111,25 @@ export function apply(ctx) { const get = (name) => { try { return ctx.get(name) } catch { return undefined } } // ---------- 当前项目 / 工作区(特性探测,拿不到就提示用户先选项目) ---------- + function sessionsSnapshot() { + return snapshotOf(get('sessions')?.list) ?? snapshotOf(get('sessions')) + } + function workspaceItems() { - const fromWorkspaces = snapshotOf(get('workspaces')?.list)?.items - if (Array.isArray(fromWorkspaces)) return fromWorkspaces - const fromUi = snapshotOf(get('uiWorkspace')?.workspaces)?.items - if (Array.isArray(fromUi)) return fromUi + const sources = [ + get('workspaces')?.list, + get('uiWorkspace')?.workspaces, + get('workspaces'), + ] + for (const source of sources) { + const items = workspaceItemsFromSnapshot(snapshotOf(source)) + if (items.length) return items + } return [] } - function normalizeWorkspace(item) { - if (!item || typeof item !== 'object') return null - const workspaceId = item.workspaceId ?? item.id ?? null - if (typeof workspaceId !== 'string' || !workspaceId) return null - return { - workspaceId, - name: typeof item.name === 'string' ? item.name : (typeof item.title === 'string' ? item.title : undefined), - path: typeof item.path === 'string' ? item.path : undefined, - } + function sessionSummary(sessionId) { + return sessionSummaryFromSnapshot(sessionsSnapshot(), sessionId) } function currentSessionId() { @@ -153,13 +163,25 @@ export function apply(ctx) { const sessionId = currentSessionId() if (sessionId) { const owner = workspaceItems().find(item => Array.isArray(item.sessionIds) && item.sessionIds.includes(sessionId)) - if (owner) candidates.push(owner.workspaceId ?? owner.id) + if (owner) candidates.push(owner.workspaceId) } return candidates.find(id => typeof id === 'string' && id) ?? null } + // 某个会话所属的工作区。右侧标签、浮动面板和主区内嵌都把自己的 sessionId 传进来, + // 因此多工作区下不会再把「当前全局会话」误当成标签页里的会话。 + function workspaceForSessionId(sessionId) { + const explicitId = typeof sessionId === 'string' && sessionId ? sessionId : null + const targetId = explicitId || currentSessionId() + const fromSession = workspaceForSession(workspaceItems(), targetId, sessionSummary(targetId)) + if (fromSession) return fromSession + // 明确指定了别的会话时,不能退回「当前全局会话」的工作区,否则又会串项目。 + if (explicitId && explicitId !== currentSessionId()) return null + return currentWorkspace() + } + function currentWorkspace() { - const items = workspaceItems().map(normalizeWorkspace).filter(Boolean) + const items = workspaceItems() const id = currentWorkspaceId() if (id) { const hit = items.find(item => item.workspaceId === id) @@ -221,29 +243,133 @@ export function apply(ctx) { try { return !!(tabs.get(TAB_KIND) || tabs.get(TAB_TYPE_ID)) } catch { return false } } // 桌面版右栏常是收起状态:只 openTab 不展开,用户会以为“点了没反应”。 - function revealRightTab() { + function rightMountedSessionId() { const right = get('sidebarRight') - if (!right) return try { - const rows = isFn(right.openTabs?.getSnapshot) ? right.openTabs.getSnapshot() : [] - const row = Array.isArray(rows) ? rows.find(item => item && item.kind === TAB_KIND) : null - if (row && isFn(right.focus)) right.focus(row.tabId) + if (right && isFn(right.mounted?.getSnapshot)) { + const mounted = right.mounted.getSnapshot() + if (typeof mounted === 'string' && mounted) return mounted + } + } catch { /* 忽略 */ } + return currentSessionId() + } + + function activeRightTabId() { + const right = get('sidebarRight') + if (!right || !isFn(right.active)) return null + try { + const record = right.active() + if (!record) return null + if (typeof record === 'string') return record + return record.id || record.tabId || null + } catch { return null } + } + + function findRightWorkbenchTab(sessionId) { + const right = get('sidebarRight') + if (!right || !isFn(right.openTabs?.getSnapshot)) return null + try { + const rows = right.openTabs.getSnapshot() + const targetSessionId = typeof sessionId === 'string' && sessionId ? sessionId : rightMountedSessionId() + // 关键:没有明确会话时不能匹配「所有会话」的工作台标签,否则新工作区会误抓旧会话的标签。 + if (!targetSessionId) return null + const matches = (Array.isArray(rows) ? rows : []).filter(item => item && item.kind === TAB_KIND && item.sessionId === targetSessionId) + if (matches.length === 0) return null + const activeId = activeRightTabId() + return matches.find(item => item.tabId === activeId) || matches[0] + } catch { return null } + } + + // 只在“还没有这个会话的工作台标签”时打开;已有标签只做必要的聚焦/展开, + // 已处于目标状态时一律不动作,避免切换会话时重复 openTab/focus 造成整块刷新。 + function revealRightTab(sessionId) { + const right = get('sidebarRight') + if (!right) return false + try { + const row = findRightWorkbenchTab(sessionId) + if (!row) return false + 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) + return false } } - function tryOpenRightTab() { + + // 单次补聚焦只用于“标签异步落位”的短窗口;每次先确认标签真的存在,绝不在已有标签时重复 openTab。 + function scheduleRevealRightTab(sessionId) { + for (const delay of [120, 420, 900, 1600]) { + setTimeout(() => { + if (!rightWorkbenchPinned) return + revealRightTab(sessionId) + }, delay) + } + } + + // 右侧栏是宿主的独立布局列:新会话切换后,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) return revealRightTab(targetSessionId) // 桌面版右栏由 dsh-better-sidebar 接管:它自己的 openTab 会排队等待会话面板挂载, // 主区正被切走时也不会丢;直接调宿主 sidebarRight 反而会因“没有挂载的会话面板”失败。 + // 显式传 scope:新会话刚建立时 bs 的 active snapshot 可能还停在旧会话,不能靠猜。 const bs = get('betterSidebar') if (bs && isFn(bs.openTab)) { try { - const snap = isFn(bs.getSnapshot) ? bs.getSnapshot() : null - const sessionId = snap && typeof snap === 'object' ? snap.sessionId : undefined - if (!sessionId) return false - bs.openTab({ type: TAB_KIND, title: '三省六部' }) - for (const delay of [200, 600, 1200]) setTimeout(revealRightTab, delay) + if (!targetSessionId) return false + const summary = sessionSummary(targetSessionId) + const scope = { sessionId: targetSessionId } + if (summary && typeof summary.cwd === 'string' && summary.cwd) scope.cwd = summary.cwd + bs.openTab({ type: TAB_KIND, title: '三省六部' }, scope) + scheduleRevealRightTab(targetSessionId) return true } catch (error) { console.warn('[sansheng] better-sidebar 打开失败,改用宿主接口:', error && error.message ? error.message : error) @@ -252,18 +378,23 @@ export function apply(ctx) { const right = get('sidebarRight') if (!right || !isFn(right.openTab)) return false if (!ensureRightTab()) return false - try { right.openTab(TAB_KIND) } catch (error) { + try { + // 原生接口的 openTab 只能作用于 on-screen 会话;目标会话尚未 adopt 时, + // 如果宿主暴露了 openTabIn(跨会话目标通道)就用它,否则退回 openTab 并靠退避重试。 + const mountedId = rightMountedSessionId() + if (targetSessionId && targetSessionId !== mountedId && isFn(right.openTabIn)) right.openTabIn(targetSessionId, TAB_KIND) + else right.openTab(TAB_KIND) + } catch (error) { console.warn('[sansheng] 打开右侧标签失败,改用浮动面板:', error && error.message ? error.message : error) return false } - // 右栏(尤其 better-sidebar 的原生面)是异步落位的,不能同步看不到就当失败, - // 否则会误退成主区渲染、把中间聊天顶掉。这里先乐观返回,再多次补一次聚焦/展开。 - revealRightTab() - for (const delay of [150, 500, 1200]) setTimeout(revealRightTab, delay) + revealRightTab(targetSessionId) + scheduleRevealRightTab(targetSessionId) return true } - function SanshengTabBody() { - return h('div', { className: 'ssw-tab-body' }, h(SanshengWorkbench, {})) + function SanshengTabBody(props) { + 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' }, '三省六部') @@ -281,7 +412,11 @@ export function apply(ctx) { icon: (size) => h(TreeIcon, { width: size, height: size }), order: 32, single: true, - component: () => h('div', { className: 'ssw-tab-body' }, h(SanshengWorkbench, {})), + component: (tabProps) => { + const scope = tabProps && tabProps.scope ? tabProps.scope : null + 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 { /* 忽略 */ } } } @@ -295,7 +430,13 @@ export function apply(ctx) { if (!tabs || !isFn(tabs.register)) return let disposeType = null, disposeBody = null, disposeTitle = null try { - disposeType = tabs.register({ id: TAB_TYPE_ID, kind: TAB_KIND, keepMounted: true, priority: 'extension', title: () => '三省六部' }) + disposeType = tabs.register({ + id: TAB_TYPE_ID, kind: TAB_KIND, keepMounted: true, priority: 'extension', title: () => '三省六部', + guide: [{ + id: `${TAB_TYPE_ID}:guide`, order: 32, title: () => '三省六部', + description: () => '十席角色与独立会话的当前项目工作台', icon: TreeIcon, + }], + }) disposeBody = ctx.slots.inject('sidebar.right.pane.tab', () => ctx.slots.register({ name: 'sidebar.right.pane.tab', key: TAB_TYPE_ID, inject: (sessionId) => ({ sessionId }), }, SanshengTabBody)) @@ -323,643 +464,23 @@ export function apply(ctx) { // 工作台会随宿主会话切换而重挂载;按项目记住选中的部门,避免又跳回丞相。 const selectedSeatCache = new Map() let lastSelectedSeatId = SEAT_IDS[0] + let rightWorkbenchPinned = readRightWorkbenchPinned() // ---------- 工作台组件 ---------- + // 工作台 v2:视觉与交互按用户提供的设计稿实现,数据全部走真实 host API。 function SanshengWorkbench(props) { - const onClose = props && props.onClose ? props.onClose : null - const [phase, setPhase] = useState('loading') - const [error, setError] = useState(null) - const [errorRetryable, setErrorRetryable] = useState(true) - const [notice, setNotice] = useState(null) - const [view, setView] = useState(null) - const [models, setModels] = useState(null) - const [selectedSeatId, setSelectedSeatId] = useState(lastSelectedSeatId) - const [draft, setDraft] = useState({}) - const [busy, setBusy] = useState(false) - const [configOpen, setConfigOpen] = useState(false) - const [reportOpen, setReportOpen] = useState(false) - const [memory, setMemory] = useState(null) - const [memoryOpen, setMemoryOpen] = useState(false) - const [memoryDraft, setMemoryDraft] = useState({ goal: '', constraints: '', acceptance: '', decisions: '' }) - const [tab, setTab] = useState('court') - const [tasks, setTasks] = useState([]) - const [artifacts, setArtifacts] = useState([]) - const [taskFormOpen, setTaskFormOpen] = useState(false) - const [taskDraft, setTaskDraft] = useState({ title: '', goal: '', ownerSeatId: SEAT_IDS[0] }) - const [summaryBusy, setSummaryBusy] = useState(false) - const [artifactFormOpen, setArtifactFormOpen] = useState(false) - const [artifactDraft, setArtifactDraft] = useState({ title: '', path: '', summary: '' }) - const alive = useRef(true) - - useEffect(() => () => { alive.current = false }, []) - - const loadProject = useCallback(async () => { - setPhase('loading'); setError(null); setErrorRetryable(true); setNotice(null) - const workspace = currentWorkspace() - if (!workspace) { setPhase('no-workspace'); return } - try { - const projectView = await request('open', { - workspaceId: workspace.workspaceId, - name: workspace.name, - path: workspace.path, - }) - let modelCatalog = null - try { modelCatalog = await request('models') } catch (modelError) { - console.warn('[sansheng] 模型目录加载失败:', modelError && modelError.message ? modelError.message : modelError) - } - let memoryData = null - try { memoryData = (await request('memory', { projectId: projectView.project.id })).memory } catch (memoryError) { - console.warn('[sansheng] 项目共识加载失败:', memoryError && memoryError.message ? memoryError.message : memoryError) - } - let taskList = [] - let artifactList = [] - try { taskList = (await request('tasks', { projectId: projectView.project.id })).tasks ?? [] } catch (taskError) { - console.warn('[sansheng] 任务加载失败:', taskError && taskError.message ? taskError.message : taskError) - } - try { artifactList = (await request('artifacts', { projectId: projectView.project.id })).artifacts ?? [] } catch (artifactError) { - console.warn('[sansheng] 成果加载失败:', artifactError && artifactError.message ? artifactError.message : artifactError) - } - if (!alive.current) return - setView(projectView) - setModels(modelCatalog) - setMemory(memoryData) - setMemoryDraft({ - goal: memoryData?.goal ?? '', - constraints: (memoryData?.constraints ?? []).join('\n'), - acceptance: (memoryData?.acceptance ?? []).join('\n'), - decisions: '', - }) - setTasks(taskList) - setArtifacts(artifactList) - setPhase('ready') - } catch (loadError) { - if (!alive.current) return - setError(loadError && loadError.message ? loadError.message : '加载失败') - setErrorRetryable(!(loadError && loadError.retryable === false)) - setPhase('error') - } - }, []) - - useEffect(() => { void loadProject() }, [loadProject]) - const projectIdForSeat = view && view.project ? view.project.id : null - useEffect(() => { - if (!projectIdForSeat) return - const saved = selectedSeatCache.get(projectIdForSeat) - if (saved && SEAT_IDS.includes(saved)) { - lastSelectedSeatId = saved - setSelectedSeatId(saved) - } - }, [projectIdForSeat]) - - const wb = buildWorkbenchView(view, { selectedSeatId, models, draft }) - const seatById = useMemo(() => { - const map = {} - for (const seat of wb.seats) map[seat.id] = seat - return map - }, [wb.seats]) - - // 单击只负责“选中部门”,不切换宿主会话;切换会话会让工作台重挂载、选中项回到丞相。 - function pickSeat(id) { - if (!id) return - if (id !== selectedSeatId) { - setSelectedSeatId(id) - setConfigOpen(false) - } - lastSelectedSeatId = id - const pid = view && view.project ? view.project.id : null - if (pid) selectedSeatCache.set(pid, id) - const seat = seatById[id] - if (seat && seat.status === 'missing') setNotice('「' + seat.name + '」的会话已不存在,点下面的「重建会话」可重新建立') - else if (seat && seat.status !== 'bound' && seat.status !== 'creating') setNotice('「' + seat.name + '」还没开启,点下面的按钮开启这个部门') - } - - // 只有明确点“开始对话”时才进入该部门的宿主会话;先用后端核实原会话存在,绝不新建。 - async function openSelectedSeat() { - const projectId = view && view.project ? view.project.id : null - const seat = seatById[wb.selected.id] - if (!projectId || !seat) return - if (seat.status === 'missing') { - setNotice('「' + seat.name + '」的会话已不存在,点下面的「重建会话」可重新建立') - return - } - if (seat.status !== 'bound') { - setNotice('「' + seat.name + '」还没开启,先点「开启『' + seat.name + '』」') - return - } - setBusy(true); setError(null) - try { - const result = await request('openSeat', { projectId, seatId: seat.id }) - if (!alive.current) return - if (!result || !result.sessionId) throw new Error('宿主没有返回会话') - navigateToSession(result.sessionId) - setNotice('已切换到' + seat.name + '会话') - } catch (openError) { - if (!alive.current) return - setError(openError && openError.message ? openError.message : '打开会话失败') - if (openError && openError.code === 'sansheng/session-missing') { - try { - const next = await request('project', { projectId }) - if (alive.current) setView(next) - } catch { /* 刷新失败保留当前视图 */ } - } - } finally { - if (alive.current) setBusy(false) - } - } - - // 只有后端确认旧会话不存在(missing)时,用户才能点这个按钮重建一次。 - async function rebuildSelectedSeat() { - const projectId = view && view.project ? view.project.id : null - const seat = seatById[wb.selected.id] - if (!projectId || !seat) return - const rec = seatRecordOf(view, seat.id) - const expectedSessionId = rec && rec.sessionId ? rec.sessionId : undefined - setBusy(true); setError(null); setNotice('正在重建「' + seat.name + '」的会话…') - try { - const next = await request('rebuildSeat', { projectId, seatId: seat.id, expectedSessionId }) - if (!alive.current) return - setView(next) - setNotice('已重建「' + seat.name + '」的会话;旧会话历史仍保留') - } catch (rebuildError) { - if (!alive.current) return - setError(rebuildError && rebuildError.message ? rebuildError.message : '重建会话失败') - if (rebuildError && rebuildError.code === 'sansheng/session-conflict') { - try { - const next = await request('project', { projectId }) - if (alive.current) setView(next) - } catch { /* 刷新失败保留当前视图 */ } - } - } finally { - if (alive.current) setBusy(false) - } - } - - function modelFromValue(value) { - const option = findModelOption(wb.selected.modelOptions, value) - if (!option) return null - return option.reasoningEffort - ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } - : { provider: option.provider, model: option.model } - } - - // 选模型就记住,不需要再点保存;下次打开或开启该部门时继续使用。 - async function rememberModel(value) { - const projectId = view && view.project ? view.project.id : null - if (!projectId || !value) return - const seatId = selectedSeatId - const model = modelFromValue(value) - if (!model) return - try { - const saved = await request('configure', { projectId, seatId, model }) - if (!alive.current) return - // 保存成功后同步本地项目视图:否则受控 select 仍读旧 view 的 model=null, - // 会显示回「请选择模型」,用户以为选择没生效。 - setView(prev => { - if (!prev || !prev.project) return prev - const seats = Array.isArray(prev.project.seats) - ? prev.project.seats.map(seat => (seat && seat.id === seatId - ? { ...seat, ...(saved && saved.seat ? saved.seat : { model }) } - : seat)) - : prev.project.seats - return { ...prev, revision: (prev.revision ?? 0) + 1, project: { ...prev.project, seats } } - }) - setDraft(prev => clearDraft(prev, seatId)) - setNotice('已记住「' + wb.selected.name + '」的模型,下次打开继续使用') - } catch (error) { - if (alive.current) setNotice(error && error.message ? error.message : '模型记忆失败') - } - } - - function setModelValue(value) { - setDraft(prev => updateDraft(prev, selectedSeatId, { modelValue: value })) - void rememberModel(value) - } - function setInstructions(value) { - setDraft(prev => updateDraft(prev, selectedSeatId, { instructions: value })) - } - - async function enableSelectedSeat() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - const seatId = wb.selected.id - setBusy(true); setError(null); setNotice('正在开启「' + wb.selected.name + '」…') - try { - const next = await request('enableSeat', { projectId, seatId }) - if (!alive.current) return - setView(next) - setNotice('已开启「' + wb.selected.name + '」的独立会话') - // 开新部门时自动把三省六部工作台面板打开/置前,避免用户以为没反应。 - try { tryOpenRightTab() } catch { /* 打开失败不影响开启结果 */ } - } catch (enableError) { - if (alive.current) setError(enableError && enableError.message ? enableError.message : '开启失败') - } finally { - if (alive.current) setBusy(false) - } - } - - async function enableSeats() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - setBusy(true); setError(null); setNotice('正在启用十席…') - try { - const next = await request('enable', { projectId }) - if (!alive.current) return - setView(next) - setNotice('十席已启用(建立独立会话,不自动运行模型)') - } catch (enableError) { - if (alive.current) setError(enableError && enableError.message ? enableError.message : '启用失败') - } finally { - if (alive.current) setBusy(false) - } - } - - async function saveConfig() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - const seatId = wb.selected.id - const value = wb.selected.modelValue - if (!value) { setNotice('请先为当前角色选择模型'); return } - const option = findModelOption(wb.selected.modelOptions, value) - const model = option - ? (option.reasoningEffort - ? { provider: option.provider, model: option.model, reasoningEffort: option.reasoningEffort } - : { provider: option.provider, model: option.model }) - : null - setBusy(true); setError(null); setNotice('保存中…') - try { - await request('configure', { projectId, seatId, model, instructions: wb.selected.instructions }) - const next = await request('project', { projectId }) - if (!alive.current) return - setView(next) - setDraft(prev => clearDraft(prev, seatId)) - setNotice('已保存') - } catch (saveError) { - if (alive.current) setError(saveError && saveError.message ? saveError.message : '保存失败') - } finally { - if (alive.current) setBusy(false) - } - } - - async function saveMemory() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - setBusy(true); setError(null); setNotice('保存项目共识…') - try { - const result = await request('memoryUpdate', { - projectId, - expectedRevision: memory?.revision ?? 0, - goal: memoryDraft.goal, - constraints: memoryDraft.constraints.split('\n').map(line => line.trim()).filter(Boolean), - acceptance: memoryDraft.acceptance.split('\n').map(line => line.trim()).filter(Boolean), - decisions: memoryDraft.decisions.split('\n').map(line => line.trim()).filter(Boolean).map(text => ({ - type: 'user', status: 'active', text, - sourceRefs: wb.selected.sessionId ? [{ sessionId: wb.selected.sessionId, excerpt: '工作台记录', recordedAt: Date.now() }] : [], - })), - sources: wb.selected.sessionId ? [{ id: 'ui-' + Date.now(), sessionId: wb.selected.sessionId, excerpt: '工作台记录', recordedAt: Date.now() }] : [], - }) - if (!alive.current) return - setMemory(result.memory) - setMemoryDraft(prev => ({ ...prev, decisions: '' })) - setNotice('项目共识已保存(v' + result.memory.revision + ')') - } catch (memoryError) { - if (alive.current) setError(memoryError && memoryError.message ? memoryError.message : '保存项目共识失败') - } finally { - if (alive.current) setBusy(false) - } - } - - async function reloadTasks(projectId) { - try { - const result = await request('tasks', { projectId }) - if (alive.current) setTasks(result.tasks ?? []) - } catch (error) { - if (alive.current) setNotice(error && error.message ? error.message : '任务列表刷新失败') - } - } - - async function createTask() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - const title = taskDraft.title.trim() - if (!title) { setNotice('任务标题不能为空'); return } - setBusy(true); setError(null) - try { - await request('taskCreate', { projectId, title, goal: taskDraft.goal, ownerSeatId: taskDraft.ownerSeatId }) - setTaskDraft({ title: '', goal: '', ownerSeatId: taskDraft.ownerSeatId }) - setTaskFormOpen(false) - await reloadTasks(projectId) - setNotice('已存为草稿;点「派工」才会交给部门。') - } catch (error) { - if (alive.current) setError(error && error.message ? error.message : '新建任务失败') - } finally { if (alive.current) setBusy(false) } - } - - async function dispatchTask(taskId) { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - setBusy(true); setError(null) - try { - const result = await request('taskDispatch', { projectId, taskId }) - await reloadTasks(projectId) - setNotice(result.delivered ? '已派工到该部门会话。' : '已记录为待执行(当前宿主暂不支持直接发送)。') - } catch (error) { - if (alive.current) setError(error && error.message ? error.message : '派工失败') - } finally { if (alive.current) setBusy(false) } - } - - async function summarizeByShangshu() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - setSummaryBusy(true); setError(null) - try { - const result = await request('shangshuSummary', { projectId }) - if (!alive.current) return - if (!result || !result.sessionId) throw new Error('宿主没有返回尚书会话') - setNotice('已请尚书汇总当前任务,正在打开尚书会话…') - navigateToSession(result.sessionId) - } catch (summaryError) { - if (alive.current) setError(summaryError && summaryError.message ? summaryError.message : '尚书汇总请求失败') - } finally { - if (alive.current) setSummaryBusy(false) - } - } - - async function cancelTask(taskId) { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - setBusy(true); setError(null) - try { - await request('taskCancel', { projectId, taskId }) - await reloadTasks(projectId) - setNotice('任务已取消。') - } catch (error) { - if (alive.current) setError(error && error.message ? error.message : '取消失败') - } finally { if (alive.current) setBusy(false) } - } - - async function addArtifact() { - const projectId = view && view.project ? view.project.id : null - if (!projectId) return - const title = artifactDraft.title.trim() - if (!title) { setNotice('成果名称不能为空'); return } - setBusy(true); setError(null) - try { - const result = await request('artifactAdd', { projectId, title, path: artifactDraft.path, summary: artifactDraft.summary }) - setArtifactDraft({ title: '', path: '', summary: '' }) - setArtifactFormOpen(false) - setArtifacts(list => [...list, result.artifact]) - setNotice('成果已登记。') - } catch (error) { - if (alive.current) setError(error && error.message ? error.message : '登记成果失败') - } finally { if (alive.current) setBusy(false) } - } - - const seatCard = (seat) => h('button', { - key: seat.id, type: 'button', className: 'ssw-seat', - 'aria-pressed': seat.selected ? 'true' : 'false', - title: seat.name + ' · ' + seat.duty + '(' + seat.statusLabel + ')', - onClick: () => pickSeat(seat.id), - }, - h('span', { className: 'ssw-role-top' }, - h('span', { className: 'ssw-role-name' }, seat.name), - h('span', { className: 'ssw-dot', 'data-status': seat.status, 'aria-hidden': 'true' }), - ), - h('span', { className: 'ssw-role-duty' }, seat.duty), - ) - - const pickList = (ids) => ids.map(id => seatById[id]).filter(Boolean) - const tree = h('section', { className: 'ssw-tree', 'aria-label': '切换角色' }, - h('div', { className: 'ssw-lead' }, pickList(wb.groups.lead).map(seatCard)), - h('div', { className: 'ssw-sansheng' }, - h('span', { className: 'ssw-group-label' }, '三省'), - h('div', { className: 'ssw-trio' }, pickList(wb.groups.sansheng).map(seatCard)), - ), - h('div', { className: 'ssw-ministries' }, - h('span', { className: 'ssw-group-label' }, '六部 · 尚书统筹'), - h('div', { className: 'ssw-six' }, pickList(wb.groups.liubu).map(seatCard)), - ), - ) - - const head = h('header', { className: 'ssw-head' }, - h(TreeIcon), - h('strong', { className: 'ssw-head-title' }, '工作台'), - onClose - ? h('button', { type: 'button', className: 'ssw-icon-btn', onClick: onClose, 'aria-label': '收起工作台' }, h(CloseIcon)) - : null, - ) - - const projectInfo = h('div', { className: 'ssw-project' }, - h('div', { className: 'ssw-project-line', style: { justifyContent: 'flex-end' } }, - h('span', { className: 'ssw-count' }, wb.project.seatCount + ' 个角色 · ' + wb.project.sessionCount + ' 个会话'), - ), - h('div', { className: 'ssw-project-title' }, wb.projectTitle || '未命名项目'), - ) - - const selectedStatus = wb.selected.status - const detailActions = h('div', { className: 'ssw-current-actions' }, - selectedStatus === 'bound' - ? h('button', { - type: 'button', className: 'ssw-primary', disabled: busy, - onClick: openSelectedSeat, - }, '开始对话') - : selectedStatus === 'missing' - ? h('button', { - type: 'button', className: 'ssw-primary', disabled: busy, - onClick: rebuildSelectedSeat, - }, '重建会话') - : h('button', { - type: 'button', className: 'ssw-primary', disabled: busy || selectedStatus === 'creating', - onClick: enableSelectedSeat, - }, selectedStatus === 'creating' ? '正在开启…' : '开启「' + wb.selected.name + '」'), - ) - - const optionEls = wb.selected.modelOptions.map(option => h('option', { key: option.value, value: option.value }, option.label)) - if (wb.selected.modelValue && !wb.selected.modelOptions.some(option => option.value === wb.selected.modelValue)) { - optionEls.push(h('option', { key: '__current__', value: wb.selected.modelValue }, wb.selected.modelLabel)) - } - const config = h('section', { className: 'ssw-config' }, - h('button', { - type: 'button', className: 'ssw-config-toggle', 'aria-expanded': configOpen ? 'true' : 'false', - onClick: () => setConfigOpen(value => !value), - }, - h(GearIcon), - h('span', null, '配置' + wb.selected.name + (wb.selected.dirty ? ' · 未保存' : '')), - h(ChevronIcon), - ), - configOpen - ? h('div', { className: 'ssw-config-body' }, - h('label', { className: 'ssw-label' }, '默认模型(开启该部门时应用)'), - h('select', { - className: 'ssw-field', value: wb.selected.modelValue, disabled: busy, - onChange: event => setModelValue(event.target.value), - }, - h('option', { value: '', disabled: true }, UNCHOSEN_MODEL_LABEL), - ...optionEls, - ), - h('label', { className: 'ssw-label' }, '角色补充说明'), - h('textarea', { - className: 'ssw-field ssw-textarea', rows: 4, value: wb.selected.instructions, disabled: busy, - placeholder: '补充该角色在当前项目中的工作要求', - onChange: event => setInstructions(event.target.value), - }), - h('p', { className: 'ssw-scope-note' }, '这里预配置的模型会在开启该部门或按需派工时应用;丞相派工不选择模型。只影响当前项目当前角色。'), - h('div', { className: 'ssw-save-row' }, - h('button', { type: 'button', className: 'ssw-primary', disabled: busy, onClick: saveConfig }, busy ? '保存中…' : '保存配置'), - wb.selected.dirty ? h('span', { className: 'ssw-save-status' }, '有未保存修改') : null, - ), - ) - : null, - ) - - const memorySection = h('section', { className: 'ssw-config' }, - h('button', { - type: 'button', className: 'ssw-config-toggle', 'aria-expanded': memoryOpen ? 'true' : 'false', - onClick: () => setMemoryOpen(value => !value), - }, - h(GearIcon), - h('span', null, '项目共识 v' + (memory?.revision ?? 0) + (memory?.updatedAt ? ' · 最近更新' : ' · 尚未建立')), - h(ChevronIcon), - ), - memoryOpen - ? h('div', { className: 'ssw-config-body' }, - h('label', { className: 'ssw-label' }, '项目目标'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: memoryDraft.goal, placeholder: '这个项目最终要达成什么', onChange: event => setMemoryDraft({ ...memoryDraft, goal: event.target.value }) }), - h('label', { className: 'ssw-label' }, '硬约束(每行一条,部门必须遵守)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: memoryDraft.constraints, placeholder: '例如:不能改动线上数据', onChange: event => setMemoryDraft({ ...memoryDraft, constraints: event.target.value }) }), - h('label', { className: 'ssw-label' }, '验收标准(每行一条)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: memoryDraft.acceptance, placeholder: '例如:交付前必须跑完回归测试', onChange: event => setMemoryDraft({ ...memoryDraft, acceptance: event.target.value }) }), - h('label', { className: 'ssw-label' }, '新增决定(每行一条,按用户明确要求记录)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 2, value: memoryDraft.decisions, placeholder: '例如:先保证稳定性,再考虑样式', onChange: event => setMemoryDraft({ ...memoryDraft, decisions: event.target.value }) }), - h('p', { className: 'ssw-scope-note' }, '保存后版本号会增加;每个部门在下一次模型请求前都会收到这份共识。当前为本地临时存储,后续迁移到 Mnemon Documents。'), - h('div', { className: 'ssw-save-row' }, h('button', { type: 'button', className: 'ssw-primary', disabled: busy, onClick: saveMemory }, busy ? '保存中…' : '保存共识')), - ) - : null, - ) - - const report = h('section', { className: 'ssw-report' }, - h('button', { - type: 'button', className: 'ssw-report-toggle', 'aria-expanded': reportOpen ? 'true' : 'false', - onClick: () => setReportOpen(value => !value), - }, reportOpen ? '收起角色职责' : '全部角色职责'), - reportOpen - ? h('div', { className: 'ssw-report-list' }, - SEAT_IDS.map(id => { - const rec = seatRecordOf(view, id) - const m = rec && rec.model - const modelLabel = m && m.model ? (m.model + (m.reasoningEffort ? ' · ' + m.reasoningEffort : '')) : '未选择模型' - return h('div', { key: id, className: 'ssw-report-item', 'data-seat': id }, - h('div', { className: 'ssw-report-head' }, - h('strong', null, SEATS[id].label), - h('span', null, SEATS[id].duty), - ), - h('p', { className: 'ssw-report-model' }, '模型:' + modelLabel), - h('p', { className: 'ssw-report-text' }, SEATS[id].responsibility), - ) - }), - ) - : null, - ) - - const statusEl = error - ? h('p', { className: 'ssw-error', role: 'alert' }, error) - : (notice ? h('p', { className: 'ssw-notice', role: 'status' }, notice) : null) - - const tabCounts = { court: wb.project.seatCount, tasks: tasks.length, artifacts: artifacts.length } - const tabBar = h('div', { className: 'ssw-tabs', role: 'tablist' }, - [['court', '朝堂'], ['tasks', '任务'], ['artifacts', '成果']].map(([id, label]) => h('button', { - key: id, type: 'button', role: 'tab', 'aria-selected': tab === id ? 'true' : 'false', - className: 'ssw-tab' + (tab === id ? ' is-active' : ''), onClick: () => setTab(id), - }, h('span', null, label), h('span', { className: 'ssw-tab-count' }, String(tabCounts[id] ?? 0))))) - - const TASK_STATUS_LABEL = { draft: '草稿', prepared: '待执行', dispatched: '已派工', running: '执行中', done: '已完成', cancelled: '已取消', failed: '失败' } - const taskRows = tasks.length === 0 - ? h('p', { className: 'ssw-empty-line' }, '这个项目还没有任务。点「新建任务」先存一张草稿。') - : tasks.map(task => { - const stale = (memory?.revision ?? 0) > (task.contextRevision ?? 0) && (task.status === 'dispatched' || task.status === 'prepared' || task.status === 'running') - return h('article', { key: task.id, className: 'ssw-row', 'data-task': task.id }, - h('div', { className: 'ssw-row-top' }, - h('strong', { className: 'ssw-row-title' }, task.title), - h('span', { className: 'ssw-badge', 'data-status': task.status }, TASK_STATUS_LABEL[task.status] ?? task.status), - stale ? h('span', { className: 'ssw-badge', 'data-status': 'stale' }, '要求有更新') : null), - h('p', { className: 'ssw-row-meta' }, (SEATS[task.ownerSeatId]?.label ?? task.ownerSeatId) + (task.goal ? ' · ' + task.goal : '') + (task.contextRevision !== undefined ? ' · 共识 v' + task.contextRevision : '')), - task.note ? h('p', { className: 'ssw-row-note' }, task.note) : null, - task.result ? h('p', { className: 'ssw-row-result' }, '结果:' + task.result) : null, - h('div', { className: 'ssw-row-actions' }, - (task.status === 'draft' || task.status === 'prepared' || task.status === 'failed') - ? h('button', { type: 'button', className: 'ssw-link', disabled: busy, onClick: () => dispatchTask(task.id) }, task.status === 'prepared' ? '重试派工' : '派工') - : null, - (task.status !== 'done' && task.status !== 'cancelled') - ? h('button', { type: 'button', className: 'ssw-link ssw-link-muted', disabled: busy, onClick: () => cancelTask(task.id) }, '取消') - : null)) - }) - - const taskView = h('section', { className: 'ssw-page' }, - h('div', { className: 'ssw-page-head' }, - h('strong', null, '任务 · ' + tasks.length), - h('div', { style: { display: 'flex', alignItems: 'center', gap: '10px' } }, - h('button', { type: 'button', className: 'ssw-link', disabled: busy || summaryBusy || tasks.length === 0, onClick: () => { void summarizeByShangshu() } }, summaryBusy ? '汇总中…' : '尚书汇总'), - h('button', { type: 'button', className: 'ssw-primary', onClick: () => setTaskFormOpen(value => !value) }, taskFormOpen ? '收起' : '新建任务'))), - taskFormOpen ? h('form', { className: 'ssw-form', onSubmit: event => { event.preventDefault(); void createTask() } }, - h('label', { className: 'ssw-label' }, '标题'), - h('input', { className: 'ssw-field', value: taskDraft.title, placeholder: '交给部门做什么', onChange: event => setTaskDraft({ ...taskDraft, title: event.target.value }) }), - h('label', { className: 'ssw-label' }, '目标(可选)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: taskDraft.goal, onChange: event => setTaskDraft({ ...taskDraft, goal: event.target.value }) }), - h('label', { className: 'ssw-label' }, '主责部门'), - h('select', { className: 'ssw-field', value: taskDraft.ownerSeatId, onChange: event => setTaskDraft({ ...taskDraft, ownerSeatId: event.target.value }) }, - SEAT_IDS.map(id => h('option', { key: id, value: id }, SEATS[id].label))), - h('div', { className: 'ssw-save-row' }, h('button', { type: 'submit', className: 'ssw-primary', disabled: busy }, busy ? '保存中…' : '保存草稿')), - ) : null, - h('div', { className: 'ssw-list' }, taskRows)) - - const artifactRows = artifacts.length === 0 - ? h('p', { className: 'ssw-empty-line' }, '这个项目还没有登记成果。') - : artifacts.map(item => h('article', { key: item.id, className: 'ssw-row', 'data-artifact': item.id }, - h('div', { className: 'ssw-row-top' }, h('strong', { className: 'ssw-row-title' }, item.title)), - item.summary ? h('p', { className: 'ssw-row-meta' }, item.summary) : null, - item.path ? h('p', { className: 'ssw-row-note' }, item.path) : null)) - - const artifactView = h('section', { className: 'ssw-page' }, - h('div', { className: 'ssw-page-head' }, - h('strong', null, '成果 · ' + artifacts.length), - h('button', { type: 'button', className: 'ssw-primary', onClick: () => setArtifactFormOpen(value => !value) }, artifactFormOpen ? '收起' : '登记成果')), - artifactFormOpen ? h('form', { className: 'ssw-form', onSubmit: event => { event.preventDefault(); void addArtifact() } }, - h('label', { className: 'ssw-label' }, '成果名称'), - h('input', { className: 'ssw-field', value: artifactDraft.title, onChange: event => setArtifactDraft({ ...artifactDraft, title: event.target.value }) }), - h('label', { className: 'ssw-label' }, '文件路径(可选)'), - h('input', { className: 'ssw-field', value: artifactDraft.path, onChange: event => setArtifactDraft({ ...artifactDraft, path: event.target.value }) }), - h('label', { className: 'ssw-label' }, '说明(可选)'), - h('textarea', { className: 'ssw-field ssw-textarea', rows: 3, value: artifactDraft.summary, onChange: event => setArtifactDraft({ ...artifactDraft, summary: event.target.value }) }), - h('div', { className: 'ssw-save-row' }, h('button', { type: 'submit', className: 'ssw-primary', disabled: busy }, busy ? '保存中…' : '保存')), - ) : null, - h('div', { className: 'ssw-list' }, artifactRows)) - - const detail = h('section', { className: 'ssw-current' }, - h('div', { className: 'ssw-current-top' }, - h('strong', { className: 'ssw-current-name' }, wb.selected.name), - h('span', { className: 'ssw-current-label' }, '角色职责 · ' + wb.selected.statusLabel), - ), - h('p', { className: 'ssw-current-text' }, wb.selected.responsibility), - detailActions, - ) - const courtView = h(Fragment, null, tree, detail, config, memorySection) - - let body - if (phase === 'loading') body = h('div', { className: 'ssw-loading' }, '正在加载工作台…') - else if (phase === 'no-workspace') body = h('div', { className: 'ssw-empty' }, - h('p', null, '请先选择项目'), - h('p', { className: 'ssw-hint' }, '在左侧工作区里选中一个项目后再打开三省六部。'), - h('button', { type: 'button', className: 'ssw-primary', onClick: loadProject }, '重新检查'), - ) - else if (phase === 'error' && !view) body = h('div', { className: 'ssw-empty' }, - h('p', { className: 'ssw-error' }, error || '加载失败'), - errorRetryable - ? h('button', { type: 'button', className: 'ssw-primary', onClick: loadProject }, '重试') - : null, - ) - else body = h(Fragment, null, projectInfo, tabBar, - tab === 'tasks' ? taskView : tab === 'artifacts' ? artifactView : courtView, statusEl) - - return h('div', { className: 'ssw-root ssw-scope' }, head, body) + const sessionId = props && props.sessionId + const resolveWorkspace = useCallback(() => workspaceForSessionId(sessionId), [sessionId]) + return h(WorkbenchV2, { + sessionId, + onClose: props && props.onClose, + resolveWorkspace, + navigateToSession, + openRightTab: tryOpenRightTab, + selectionCache: selectedSeatCache, + getLastSeatId: () => lastSelectedSeatId, + setLastSeatId: id => { lastSelectedSeatId = id }, + }) } // ---------- 左侧导航入口 ---------- @@ -968,21 +489,89 @@ export function apply(ctx) { const NAV_PANEL_ID = 'sansheng-workbench' const NAV_ORDER = 32 - function openRightWorkbench() { - return tryOpenRightTab() + function openRightWorkbench(sessionId) { + const opened = tryOpenRightTab(sessionId) + if (opened) { rightWorkbenchPinned = true; writeRightWorkbenchPinned(true) } + return opened } function closeRightWorkbench() { + rightWorkbenchPinned = false + writeRightWorkbenchPinned(false) + const right = get('sidebarRight') + const row = findRightWorkbenchTab() + if (row && right && isFn(right.close)) { + try { right.close(row.tabId); return } catch { /* 忽略 */ } + } const layout = get('layout') if (layout && isFn(layout.selectPanel)) { try { layout.selectPanel(null); return } catch { /* 换下一个候选 */ } } - const right = get('sidebarRight') if (right && isFn(right.closeTab)) { try { right.closeTab(TAB_KIND); return } catch { /* 忽略 */ } } } + // 右侧栏按会话保存布局;切换部门打开新会话后,把固定工作台重新挂到新会话。 + // 新建会话的 store 是异步 mint 的:mounted 先变,sidebarRight 还会短暂报 + // “no session surface is mounted”。这里只重试“缺标签”的那一次打开; + // 已有标签只做必要的聚焦/展开,绝不对同一会话重复 openTab。 + function installRightDockPinning() { + const right = get('sidebarRight') + if (!right || !isFn(right.mounted?.subscribe)) return + const delays = [60, 140, 280, 560, 1000, 1800, 3000] + let timer = null + let attempt = 0 + const clear = () => { + if (timer !== null) { clearTimeout(timer); timer = null } + } + const ensure = () => { + timer = null + if (!rightWorkbenchPinned) { attempt = 0; return } + try { + const sessionId = rightMountedSessionId() + if (findRightWorkbenchTab(sessionId)) { + // 标签存在不代表已经展开:新会话的右栏 surface 可能尚未 mint, + // reveal 会短暂失败。失败时继续退避重试,不能把“找到标签”当成成功。 + if (revealRightTab(sessionId)) { attempt = 0; return } + } + if (openRightWorkbench(sessionId)) { + attempt = 0 + return + } + } catch { /* 会话尚未挂载时,继续按退避重试 */ } + if (attempt < delays.length - 1) { + attempt += 1 + timer = setTimeout(ensure, delays[attempt]) + } + } + const kick = () => { + if (!rightWorkbenchPinned) return + clear() + attempt = 0 + 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 { /* 忽略 */ } + }) + } + // 导航行内容(宿主只把这里当图标渲染,标签由宿主按 label() 画)。 // 点击只开右侧工作台,并阻止冒泡,避免宿主把主区切成面板页——中央原生聊天因此保持原样。 function SanshengNavButton(props) { @@ -994,13 +583,13 @@ export function apply(ctx) { const onClick = (event) => { if (event && isFn(event.stopPropagation)) event.stopPropagation() if (event && isFn(event.preventDefault)) event.preventDefault() - if (openRightWorkbench()) { setFloating(false); return } + if (openRightWorkbench(currentSessionId())) { setFloating(false); return } setFloating(value => !value) } let panel = null if (floating) { const card = h('div', { className: 'ssw-float', role: 'dialog', 'aria-label': '三省六部工作台' }, - h(SanshengWorkbench, { onClose: () => setFloating(false) })) + h(SanshengWorkbench, { sessionId: currentSessionId(), onClose: () => setFloating(false) })) const canPortal = typeof document !== 'undefined' && document.body && isFn(createPortal) panel = canPortal ? createPortal(card, document.body) : card } @@ -1028,7 +617,7 @@ export function apply(ctx) { const [mode, setMode] = useState('pending') useEffect(() => { let opened = false - try { opened = openRightWorkbench() } catch { opened = false } + try { opened = openRightWorkbench(currentSessionId()) } catch { opened = false } if (opened) { setMode('docked') backToChat() @@ -1044,7 +633,7 @@ export function apply(ctx) { let openedLater = false for (const delay of [200, 600, 1200, 2000]) { setTimeout(() => { - try { if (!openedLater && openRightWorkbench()) { openedLater = true; backToChat() } } catch { /* 忽略 */ } + try { if (!openedLater && openRightWorkbench(currentSessionId())) { openedLater = true; backToChat() } } catch { /* 忽略 */ } }, delay) } setTimeout(() => { if (!openedLater) setMode('inline') }, 2600) @@ -1063,7 +652,7 @@ export function apply(ctx) { h('span', null, '工作台 · 内嵌模式'), h('button', { type: 'button', className: 'ssw-link', onClick: backToChat }, '返回对话'), ), - h(SanshengWorkbench, {}), + h(SanshengWorkbench, { sessionId: currentSessionId() }), ) } @@ -1098,6 +687,7 @@ export function apply(ctx) { // 右侧工作台标签类型:需在 apply 时就注册(宿主按类型 id 选正文 slot)。 registerRightTabType() + installRightDockPinning() // dsh-go 原生面板:浏览器(无 dshGo 服务)或桥未就绪时,install 内部安静退出。 try { diff --git a/src/client/styles.js b/src/client/styles.js index 87c277a..27a9a16 100644 --- a/src/client/styles.js +++ b/src/client/styles.js @@ -1,136 +1,723 @@ -// 三省六部工作台样式:白蓝主题,自带深色适配。 -// 所有选择器以 .ssw- 前缀隔离,避免污染宿主样式;变量参考 preview/index.html。 -// 不依赖任何构建工具,作为普通字符串导出,由入口注入