taskboard-workbench 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/web/app.js CHANGED
@@ -683,6 +683,12 @@
683
683
  const hostNotice = mk("div", "banner warn");
684
684
  hostNotice.hidden = true;
685
685
  hostNotice.setAttribute("role", "status");
686
+ // 卡 `-222`(需求 `R163` ①):**可降级步骤**失败时的常驻条 —— 「面板能用,但这几项没读到」。
687
+ // 与一次性 `banner` 分开:条里要**留住原因**并带「重试」按钮;banner 到时会自动消失。
688
+ // 复用 `.empty-guide` 既有排版(只在 tokens.css 补一条宽度收敛,不新增取数通道)。
689
+ const bootStrip = mk("div", "empty-guide tb-boot-strip");
690
+ bootStrip.hidden = true;
691
+ bootStrip.setAttribute("role", "status");
686
692
  const boardScroll = mk("main", "board-scroll");
687
693
  const board = mk("div", "board");
688
694
  board.setAttribute("aria-label", "任务看板(按状态分列)");
@@ -709,6 +715,8 @@
709
715
  const advanceRoot = mk("div", "advance-view");
710
716
  advanceScroll.appendChild(advanceRoot);
711
717
  shell.append(header, toolbar, banner, connNotice, hostNotice, boardScroll, reqScroll, teamScroll, configScroll, gateScroll, advanceScroll);
718
+ // 卡 `-222`:常驻条挂在「能力提示」与各视图之间(单独插,不改上面那条已被 FR-20 守卫钉住的挂载行)。
719
+ try { shell.insertBefore(bootStrip, boardScroll); } catch { /* ignore */ }
712
720
 
713
721
  // 任务详情抽屉(含"归属团队 / 执行会话"关联)
714
722
  const drawerBackdrop = mk("div", "tb-drawer-backdrop");
@@ -722,7 +730,7 @@
722
730
  const drawerStage = mk("span", "tb-stage-badge", "");
723
731
  drawerStage.hidden = true;
724
732
  drawerHeadMain.append(drawerId, drawerStage, drawerTitle);
725
- const drawerClose = mk("button", "ghost", "✕");
733
+ const drawerClose = mk("button", "ghost icon", "✕");
726
734
  drawerClose.type = "button";
727
735
  drawerClose.title = "关闭";
728
736
  // FR-87 修订(2026-10-19):抽屉头加「全部收起 / 全部展开」与「全屏 / 还原」两个动作。
@@ -734,8 +742,16 @@
734
742
  drawerFull.title = "抽屉铺满窗口(再点一下还原为按视口分级的默认宽度)";
735
743
  // 2026-10-23(用户真机批注):整卡动作区上移到标题栏 —— 与「全部收起 / 还原 / ✕」同一排;
736
744
  // 卡片级操作(编辑 / 移动列 / 启动执行 / 拆解…)不再沉在正文最底部的「操作」区块里。
745
+ // 卡 `-224`(需求 `R164`):标题栏拆**两段** —— `.tb-drawer-actions` 只放卡片级动作
746
+ // (编辑 / 上一列 / 下一列 / 处置指针),`.tb-drawer-utils` 只放工具(全部收起 / 全屏 / ✕)。
747
+ // 原先这七个按钮一起 append,位置由**插入顺序**决定:动作一多就把工具挤向左边,高频与低频混在一排
748
+ // (真机批注「常用按钮位置和按钮样式不统一」)。现在顺序写死:动作区 → 分隔线 → 工具组,
749
+ // 工具组内部永远是 收起 → 全屏 → 关闭;两块之间由 CSS 画一条发丝线,不再靠"谁先 append"表达分区。
737
750
  const drawerActions = mk("div", "tb-drawer-actions");
738
- drawerHead.append(drawerHeadMain, mk("div", "spacer"), drawerActions, drawerExpandAll, drawerFull, drawerClose);
751
+ const drawerUtils = mk("div", "tb-drawer-utils");
752
+ const drawerSep = mk("div", "tb-drawer-sep");
753
+ drawerUtils.append(drawerExpandAll, drawerFull, drawerClose);
754
+ drawerHead.append(drawerHeadMain, mk("div", "spacer"), drawerActions, drawerSep, drawerUtils);
739
755
  const drawerResize = mk("div", "tb-drawer-resize");
740
756
  drawerResize.title = "拖动调整抽屉宽度(双击还原)";
741
757
  const drawerBody = mk("div", "tb-drawer-body");
@@ -830,6 +846,32 @@
830
846
  const allCollapsed = sections.length > 0 && sections.every((section) => section.classList.contains("collapsed"));
831
847
  drawerExpandAll.textContent = allCollapsed ? "全部展开" : "全部收起";
832
848
  };
849
+ /**
850
+ * 卡 `-224`(需求 `R164`):**全抽屉至多一个 primary**。
851
+ *
852
+ * 真机批注:「常用按钮位置和按钮样式不统一」。实证:未归因卡的抽屉里同时出现 3 个蓝按钮
853
+ * (头部「去归因」/「下一步」区「去归因」/「归因」区「关联需求条目」),各处置区又各配一个
854
+ * primary ⇒ 一屏 5–7 个同权重蓝块,人无法一眼看出"现在该点哪个"。
855
+ *
856
+ * 口径(只做**呈现**,不删按钮、不改回调、不改服务端 `next-step` 的 kind):
857
+ * · 「下一步」区的 primary 优先保留 —— 它是唯一回答"该干嘛"的地方;
858
+ * · 其它区块的 primary 降为 `secondary`(照样可点,只是不再抢主色);
859
+ * · 只换 class 与补 title,不动 disabled / onclick。
860
+ * 幂等:没有多余 primary 时什么都不做(重复渲染/手动展开区块都安全)。
861
+ */
862
+ const normalizeActionTiers = () => {
863
+ const primaries = Array.from(drawerBody.querySelectorAll("button.primary"));
864
+ if (primaries.length <= 1) return;
865
+ const sectionOf = (b) => (typeof b.closest === "function" ? b.closest(".drawer-section") : null);
866
+ const keep = primaries.find((b) => sectionOf(b)?.classList.contains("next-step")) ?? primaries[0];
867
+ for (const b of primaries) {
868
+ if (b === keep) continue;
869
+ b.classList.remove("primary");
870
+ b.classList.add("secondary");
871
+ const why = "全抽屉只保留一个主按钮(在「下一步」区)";
872
+ b.title = b.title ? `${b.title}(${why})` : why;
873
+ }
874
+ };
833
875
  const setSectionCollapsed = (section, collapsed) => {
834
876
  const key = String(section.querySelector(":scope > h3")?.textContent ?? "");
835
877
  section.classList.toggle("collapsed", collapsed);
@@ -969,16 +1011,39 @@
969
1011
  if (r.titleApplied === true) return r.sessionName ? ` · 会话名《${r.sessionName}》` : "";
970
1012
  return ` · ⚠ 会话名未生效(${r.titleReason ?? "原因未知"})`;
971
1013
  };
972
- const showBanner = (message, kind = "info") => {
1014
+ /**
1015
+ * 卡 `-222`(需求 `R163` ③):`sticky` —— **初始化失败态横幅不自动消失**。
1016
+ *
1017
+ * 取证(2026-11-04):`bootstrap()` 末尾**无条件** `hideBanner()`,而 error 横幅本身也只活 10s
1018
+ * ⇒ 一次 `Failed to fetch` 之后,那条唯一的失败理由被抹掉,人回来看到的是「全空且没有任何理由」。
1019
+ * 除初始化失败外,其余调用点都是「一次性操作提示」,故缺省 `sticky: false`,既有行为不变。
1020
+ */
1021
+ const showBanner = (message, kind = "info", { sticky = false } = {}) => {
973
1022
  banner.textContent = message;
974
- banner.className = `banner ${kind}`;
1023
+ banner.className = `banner ${kind}${sticky ? " tb-banner-sticky" : ""}`;
975
1024
  banner.hidden = false;
976
1025
  try { banner.scrollIntoView({ block: "nearest" }); } catch { /* ignore */ }
977
1026
  clearTimeout(bannerTimer);
978
- bannerTimer = setTimeout(() => { banner.hidden = true; }, kind === "error" ? 10000 : 5000);
1027
+ bannerTimer = sticky ? null : setTimeout(() => { banner.hidden = true; }, kind === "error" ? 10000 : 5000);
1028
+ };
1029
+ /**
1030
+ * 卡 `-222`(需求 `R163` ③):**初始化失败态横幅不许被清掉**。
1031
+ *
1032
+ * 原缺陷两层:① `bootstrap()` 末尾无条件 `hideBanner()`;② error 横幅本身只活 10s。
1033
+ * 于是「一次 `Failed to fetch`」的结果是:全空 + 没有任何理由,人只能去刷新整页。
1034
+ *
1035
+ * 现在两道锁:横幅 `sticky`(不挂定时器)+ 失败未解除时 `hideBanner()` 直接不生效。
1036
+ * 失败被解除的唯一入口是 `bootstrap()` 成功(那里先把 `bootFailureSticky` 置回 false 再收起)。
1037
+ * 这里用 `bootFailureSticky` 这个**先行声明的标志**而不是 `bootState`:`hideBanner` 定义在
1038
+ * `bootState` 之前,直接引用 `const` 会在 TDZ 里抛 ReferenceError。
1039
+ */
1040
+ const hideBanner = () => {
1041
+ if (bootFailureSticky) return; // 初始化失败未解除 ⇒ 理由必须留得住(否则又回到"全空且没有理由")
1042
+ banner.hidden = true;
1043
+ clearTimeout(bannerTimer);
979
1044
  };
980
- const hideBanner = () => { banner.hidden = true; clearTimeout(bannerTimer); };
981
1045
  let bannerTimer = null;
1046
+ let bootFailureSticky = false;
982
1047
 
983
1048
  /**
984
1049
  * 能力边界(真机 2026-10-29 · `:47830`「未能投递:host-unavailable」+「无法自动打开…」连撞两次)。
@@ -1572,6 +1637,10 @@
1572
1637
  }
1573
1638
 
1574
1639
  async function loadTasks() {
1640
+ // 卡 `-222`:必要步失败期间,**任何**刷新路径(SSE 回流 / 60s 看护轮询 / 重新同步)都不许把
1641
+ // 失败面板顶成一块空看板 —— 那正是「一次 Failed to fetch ⇒ 永久空白」的第二条复发路径
1642
+ // (面板画出来只是第一条;不拦住定时刷新,人过一分钟回来还是空白)。
1643
+ if (bootEssentialFailure()) { showBootPanel(); return; }
1575
1644
  const params = new URLSearchParams();
1576
1645
  if (state.projectId) params.set("project", state.projectId);
1577
1646
  if (state.priority) params.set("priority", state.priority);
@@ -1710,28 +1779,159 @@
1710
1779
  }
1711
1780
  }
1712
1781
 
1782
+ /**
1783
+ * 卡 `-222`(需求 `R163` ①–③):`bootstrap()` **分步容错** —— 一次 `Failed to fetch` 不再永久空白。
1784
+ *
1785
+ * 现场(2026-11-04 · `/integrations/taskboard-workbench`):服务端与压测全绿,问题在浏览器侧 ——
1786
+ * 同一毫秒内 10 条 `TypeError: Failed to fetch`(`api()` ← `loadTasks()`),是连接被同时掐断,
1787
+ * 不是某个接口 5xx。而当时的 `bootstrap()` 是**全有或全无**:`/api/meta`、`/api/projects` 两处裸
1788
+ * `await`,任一网络层失败 ⇒ `renderCurrentView()` 永不执行 ⇒ `.board` 0 子元素、8 个下拉 0 option;
1789
+ * `bootstrap().catch` 只弹一次 banner,**且末尾无条件 `hideBanner()` 把它抹掉**,还没有重试入口
1790
+ * ⇒ 用户看到的就是「全空且没有任何理由」,唯一自救是刷新整页。
1791
+ *
1792
+ * 处置(只在前端;**不改 `/api/*` 契约**):
1793
+ * ① 每步独立 `runBootStep`,一步失败**不中断**后续步骤;
1794
+ * ② 失败步**留占位 + 原因**(`bootState.failures`):
1795
+ * · **必要步**(`meta` / `projects`)→ 整块面板(`.tb-boot-panel`):画不出看板时如实说「哪一步、为什么」;
1796
+ * · **可降级步**(`health` / `context` / `settings` / `binding`)→ 常驻条(`.tb-boot-strip`):
1797
+ * 面板照常可用,但**缺哪几项、为什么**必须看得见(不再静默降级);
1798
+ * ③ 两处都带**显式「重试」**(只重跑 `bootstrap()`,**不刷新整页**);
1799
+ * ④ 有失败时**绝不 `hideBanner()`**,且失败横幅 `sticky`(不自动消失)—— 失败理由必须留得住。
1800
+ */
1801
+ const bootState = { running: false, at: null, failures: [] };
1802
+ const noteBootFailure = (id, label, essential, error) => {
1803
+ bootState.failures.push({
1804
+ id, label, essential,
1805
+ message: error?.message ?? String(error ?? "未知错误"),
1806
+ code: error?.code ?? null,
1807
+ });
1808
+ };
1809
+ /** 跑一步:成功返回 `{ ok:true, value }`,失败**记账后**返回 `{ ok:false, value:null }`(不抛)。 */
1810
+ async function runBootStep(id, label, essential, run) {
1811
+ try { return { ok: true, value: await run() }; }
1812
+ catch (error) { noteBootFailure(id, label, essential, error); return { ok: false, value: null }; }
1813
+ }
1814
+ const bootEssentialFailure = () => bootState.failures.some((f) => f.essential);
1815
+ const bootFailureLine = (f) => `✕ ${f.label} 读取失败:${f.message}${f.code ? `(${f.code})` : ""}`;
1816
+ /** 必要步失败的面板:**必须**能看出「哪一步、为什么、怎么再来一次」。 */
1817
+ function bootPanel() {
1818
+ const box = mk("div", "empty-guide tb-boot-panel");
1819
+ box.id = "tb-boot-panel";
1820
+ box.setAttribute("role", "alert");
1821
+ box.appendChild(mk("div", "empty-guide-title", "面板初始化没完成:看板暂时没能画出来"));
1822
+ box.appendChild(mk("div", "empty-guide-hint", "这不是「没有任务」—— 是初始化取数失败。下面逐步列出「哪一步」失败、失败原因;点「重试」只重跑初始化,不必刷新整页(刷新整页不是唯一出路)。"));
1823
+ for (const f of bootState.failures) {
1824
+ const row = mk("div", "empty-guide-hint tb-boot-failure");
1825
+ row.dataset.bootStep = f.id;
1826
+ row.dataset.bootEssential = f.essential ? "1" : "0";
1827
+ row.textContent = bootFailureLine(f);
1828
+ box.appendChild(row);
1829
+ }
1830
+ const bar = mk("div", "empty-guide-actions");
1831
+ bar.appendChild(bootRetryButton("primary"));
1832
+ box.appendChild(bar);
1833
+ return box;
1834
+ }
1835
+ /** 可降级步骤失败时的常驻条:面板照常可用,但缺项与原因不静默。 */
1836
+ function renderBootStrip() {
1837
+ const degraded = bootState.failures.filter((f) => !f.essential);
1838
+ bootStrip.replaceChildren();
1839
+ if (!degraded.length) { bootStrip.hidden = true; return; }
1840
+ bootStrip.appendChild(mk("div", "empty-guide-title", `面板已加载,但有 ${degraded.length} 项数据没读到(不是空白,只是缺这几项)`));
1841
+ for (const f of degraded) {
1842
+ const row = mk("div", "empty-guide-hint tb-boot-failure");
1843
+ row.dataset.bootStep = f.id;
1844
+ row.dataset.bootEssential = "0";
1845
+ row.textContent = bootFailureLine(f);
1846
+ bootStrip.appendChild(row);
1847
+ }
1848
+ const bar = mk("div", "empty-guide-actions");
1849
+ bar.appendChild(bootRetryButton("ghost"));
1850
+ bootStrip.appendChild(bar);
1851
+ bootStrip.hidden = false;
1852
+ }
1853
+ /** 显式重试入口(面板与常驻条共用同一份实现;`id` 供守卫读数)。 */
1854
+ function bootRetryButton(cls) {
1855
+ const retry = btn("重试(只重跑初始化)", () => { void retryBootstrap(); }, cls);
1856
+ retry.id = "tb-boot-retry";
1857
+ return retry;
1858
+ }
1859
+ /** 只重跑初始化 —— **不刷新整页**(需求 `R163` ②)。 */
1860
+ async function retryBootstrap() {
1861
+ if (bootState.running) return; // 连点不叠加:一次只跑一轮
1862
+ showBanner("正在重跑面板初始化…", "info");
1863
+ try { await bootstrap(); }
1864
+ catch (error) {
1865
+ bootFailureSticky = true;
1866
+ showBanner(`重试失败:${error?.message ?? error} —— 可再点「重试」,不必刷新整页。`, "error", { sticky: true });
1867
+ }
1868
+ }
1869
+ /** 必要步失败 ⇒ 只画面板(不画空看板、不画空下拉);其余视图一律让位给它。 */
1870
+ function showBootPanel() {
1871
+ boardScroll.hidden = false;
1872
+ reqScroll.hidden = true; teamScroll.hidden = true; configScroll.hidden = true;
1873
+ gateScroll.hidden = true; advanceScroll.hidden = true;
1874
+ bootStrip.hidden = true;
1875
+ board.replaceChildren(bootPanel());
1876
+ }
1877
+ /** 失败横幅:**sticky**(不自动消失),内容只列失败步 —— 成功的步不占位。 */
1878
+ function syncBootBanner() {
1879
+ if (!bootState.failures.length) {
1880
+ bootFailureSticky = false;
1881
+ hideBanner();
1882
+ return;
1883
+ }
1884
+ const head = bootEssentialFailure() ? "面板初始化未完成" : "面板已加载,但有数据没读到";
1885
+ bootFailureSticky = true; // 锁住 hideBanner:失败未解除前,任何后续收起都不许抹掉这条理由
1886
+ showBanner(`${head}:${bootState.failures.map((f) => `${f.label}(${f.message})`).join(";")} —— 点面板内「重试」只重跑初始化,不必刷新整页。`, "error", { sticky: true });
1887
+ }
1888
+
1713
1889
  async function bootstrap() {
1714
- // 先读能力位再渲染:否则首屏会先画出"能点"的按钮、几百毫秒后再置灰(闪一下更困惑)。
1715
- try { const h = await api("GET", "/api/health"); state.host = h?.host ?? null; } catch { state.host = null; }
1716
- renderHostNotice();
1717
- const meta = await api("GET", "/api/meta");
1718
- state.statuses = meta.statuses;
1719
- state.priorities = meta.priorities;
1720
- // FR-60:会话/工作区 → 项目(并把项目绑定到"初始会话")
1721
- const ctxParams = new URLSearchParams();
1722
- if (cwd) ctxParams.set("cwd", cwd);
1723
- if (sessionId) ctxParams.set("session", sessionId);
1724
- const ctx = await api("GET", `/api/context${ctxParams.toString() ? `?${ctxParams}` : ""}`).catch(() => null);
1725
- const projects = await api("GET", "/api/projects");
1726
- if (destroyed) return;
1727
- state.projects = projects.projects;
1728
- state.projectId = ctx?.project?.id ?? projects.projects[0]?.id ?? "";
1729
- state.context = ctx;
1730
- try { const st = await api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/settings`); state.loop = st.loop ?? {}; } catch { state.loop = {}; }
1731
- // FR-63(扩展到所有视图):解析"本会话×本项目"绑定态,未绑定则全视图显示关联门
1732
- await resolveBinding(state.projectId);
1733
- renderCurrentView();
1734
- hideBanner();
1890
+ if (bootState.running) return;
1891
+ bootState.running = true;
1892
+ bootState.failures = [];
1893
+ bootState.at = new Date().toISOString();
1894
+ try {
1895
+ // ① 能力位(**可降级**:读不到 = 能力未知,交给服务端如实拒绝,不擅自禁用)
1896
+ // 先读能力位再渲染:否则首屏会先画出"能点"的按钮、几百毫秒后再置灰(闪一下更困惑)。
1897
+ const health = await runBootStep("health", "宿主能力位(/api/health)", false, () => api("GET", "/api/health"));
1898
+ state.host = health.value?.host ?? null;
1899
+ renderHostNotice();
1900
+ // ② 状态 / 优先级元数据(**必要**:看板列与优先级下拉全靠它,缺了画不出列)
1901
+ const meta = await runBootStep("meta", "状态与优先级元数据(/api/meta)", true, () => api("GET", "/api/meta"));
1902
+ state.statuses = meta.value?.statuses ?? [];
1903
+ state.priorities = meta.value?.priorities ?? [];
1904
+ // ③ FR-60:会话/工作区 → 项目(**可降级**:拿不到就按项目列表第一项)
1905
+ const ctxParams = new URLSearchParams();
1906
+ if (cwd) ctxParams.set("cwd", cwd);
1907
+ if (sessionId) ctxParams.set("session", sessionId);
1908
+ const ctx = await runBootStep("context", "会话上下文(/api/context)", false,
1909
+ () => api("GET", `/api/context${ctxParams.toString() ? `?${ctxParams}` : ""}`));
1910
+ // ④ 项目列表(**必要**:没有项目就没有取数范围)
1911
+ const projects = await runBootStep("projects", "项目列表(/api/projects)", true, () => api("GET", "/api/projects"));
1912
+ const projectList = projects.value?.projects ?? [];
1913
+ if (destroyed) return;
1914
+ state.projects = projectList;
1915
+ state.projectId = ctx.value?.project?.id ?? projectList[0]?.id ?? "";
1916
+ state.context = ctx.value ?? null;
1917
+ // ⑤ 项目配置(**可降级**:读不到就按默认,不挡看板)
1918
+ if (state.projectId) {
1919
+ const settings = await runBootStep("settings", "项目设置(/api/projects/:id/settings)", false,
1920
+ () => api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/settings`));
1921
+ state.loop = settings.value?.loop ?? {};
1922
+ }
1923
+ // ⑥ FR-63(扩展到所有视图):解析"本会话×本项目"绑定态,未绑定则全视图显示关联门(**可降级**)
1924
+ await resolveBinding(state.projectId);
1925
+ if (destroyed) return;
1926
+ // 必要步失败 ⇒ 画「哪一步、为什么」的面板 + 重试;**不画空看板**
1927
+ if (bootEssentialFailure()) { showBootPanel(); syncBootBanner(); return; }
1928
+ renderCurrentView();
1929
+ // 卡 `-222` ③:失败态横幅**不被清** —— 只有全部成功才 hideBanner(原实现无条件 hide ⇒ 唯一理由被抹掉)
1930
+ if (bootState.failures.length) { renderBootStrip(); syncBootBanner(); }
1931
+ else { bootStrip.hidden = true; bootStrip.replaceChildren(); bootFailureSticky = false; hideBanner(); }
1932
+ } finally {
1933
+ bootState.running = false;
1934
+ }
1735
1935
  }
1736
1936
  // 会话×项目 绑定态解析(FR-63 → 全视图生效)
1737
1937
  async function resolveBinding(projectId) {
@@ -1739,7 +1939,11 @@
1739
1939
  try {
1740
1940
  const c = await api("GET", `/api/context?session=${encodeURIComponent(sessionId)}&project=${encodeURIComponent(projectId)}`);
1741
1941
  state.binding = { projectId, bound: c.sessionBound !== false, mainSessionId: c.mainSessionId ?? null, association: c.association ?? null, sessionOrigin: c.sessionOrigin ?? null };
1742
- } catch { state.binding = { projectId, bound: true, mainSessionId: null, association: null }; }
1942
+ } catch (error) {
1943
+ state.binding = { projectId, bound: true, mainSessionId: null, association: null };
1944
+ // 卡 `-222` ①:绑定态也是 bootstrap 的一步 —— 失败要留原因(项目内切换时不算 boot 步骤,不记账)
1945
+ if (bootState.running) noteBootFailure("binding", "会话绑定态(/api/context?project=…)", false, error);
1946
+ }
1743
1947
  }
1744
1948
  const isBlocked = () => Boolean(sessionId) && state.binding.projectId === state.projectId && state.binding.bound === false;
1745
1949
  function hideGate() { gateScroll.hidden = true; }
@@ -1946,6 +2150,9 @@
1946
2150
  }
1947
2151
 
1948
2152
  function renderCurrentView() {
2153
+ // 卡 `-222`(需求 `R163` ①):必要步失败 ⇒ 任何视图切换都只画「哪一步失败、为什么」的面板,
2154
+ // 不画空看板、不画只剩占位项的下拉(旧实现这里照样渲染 ⇒ 人看到的是「全空且没有理由」)。
2155
+ if (bootEssentialFailure()) { showBootPanel(); return; }
1949
2156
  if (isBlocked()) { void showBlockedGate(); return; }
1950
2157
  hideGate();
1951
2158
  if (view === "req") void renderRequirements();
@@ -2243,7 +2450,8 @@
2243
2450
  // 能力门是**渲染后**才知道要不要置灰的(区块/抽屉随时新建)⇒ 观察 DOM 变化,把新出现的宿主依赖按钮一并置灰。
2244
2451
  // 只观察 childList(不观察 attributes),故 `disabled/title` 的写入不会再触发自己。
2245
2452
  try { new MutationObserver(() => { try { applyHostGate(); } catch { /* ignore */ } }).observe(doc.body, { childList: true, subtree: true }); } catch { /* ignore */ }
2246
- bootstrap().catch((error) => showBanner(`初始化失败:${error.message}`, "error"));
2453
+ // 卡 `-222`:这一步只是**兜底**(每步已各自容错)—— 真抛出时也留住理由并指到「重试」,不给人「只剩刷新整页」。
2454
+ bootstrap().catch((error) => showBanner(`初始化失败:${error?.message ?? error} —— 点面板内「重试」可重跑初始化(不必刷新整页)。`, "error", { sticky: true }));
2247
2455
 
2248
2456
  // FR-41:进度可见(SSE 失效信号 → 重取)
2249
2457
  let boardEvents = null;
@@ -2346,8 +2554,10 @@
2346
2554
  if (!value) return "—";
2347
2555
  return String(value).replace("T", " ").replace(/\.\d+Z?$/, "").replace(/Z$/, "");
2348
2556
  }
2349
- function pill(text, cls = "") {
2350
- return mk("span", `chip ${cls}`.trim(), text);
2557
+ function pill(text, cls = "", title = "") {
2558
+ const node = mk("span", `chip ${cls}`.trim(), text);
2559
+ if (title) node.title = title;
2560
+ return node;
2351
2561
  }
2352
2562
  function statusPill(status) {
2353
2563
  return mk("span", `chip dot status-chip status-${status}`, STATUS_LABELS[status] ?? status);
@@ -2356,6 +2566,19 @@
2356
2566
  function reqStatusLabel(status) {
2357
2567
  return status === "draft" ? "待确认" : status === "open" ? "在办" : status === "done" ? "已完成" : status === "closed" ? "已关闭" : String(status ?? "");
2358
2568
  }
2569
+ /**
2570
+ * 卡 `-218`(R159 D-1=`c`):条目**完整性**三态的唯一文案表(列表胶囊与详情字段共用,避免两处走样)。
2571
+ * 口径来自服务端派生字段 `detailState`(`src/core/requirements.mjs` `deriveDetailState`)。
2572
+ */
2573
+ const DETAIL_STATE_LABELS = {
2574
+ truncated: { text: "残片", tone: "warn", title: "描述被截断(早期导入上限 2000 字符)—— 完整原文见来源文档,别当完整描述引用" },
2575
+ mirror: { text: "镜像", tone: "", title: "文档镜像条目:正文是某份文档的片段,不是可执行需求" },
2576
+ };
2577
+ function detailStateText(state) {
2578
+ return state === "truncated" ? "已截断 · 残片(仅存前 2000 字符;完整原文见「来源」所指文档)"
2579
+ : state === "mirror" ? "文档镜像(原文片段,非需求正文)"
2580
+ : "完整";
2581
+ }
2359
2582
  function btn(label, onClick, cls = "ghost") {
2360
2583
  const node = mk("button", cls, label);
2361
2584
  node.type = "button";
@@ -2476,6 +2699,41 @@
2476
2699
  return box;
2477
2700
  }
2478
2701
 
2702
+ /**
2703
+ * 卡 `-227`(需求 `R168`):从「会话关联」**直接跳到那条会话**。
2704
+ *
2705
+ * 真机批注(2026-11-05):「增加会话关联对应主会话以及相关会话的直接跳转能力」。
2706
+ * 此前这两行列的只有截断标识(`session-70a0bcda…`)与存活胶囊 —— 想看一眼那条会话在聊什么,
2707
+ * 只能记住/复制标识回侧栏翻。**面板里没有任何入口能把人送到那条会话**。
2708
+ *
2709
+ * 口径(与 `-211` 同一教训:**能跳才叫跳转**):
2710
+ * ① 优先**客户端导航**(`options.openSession`;实机里它走 `uiWorkspace.openSession` / 路由);
2711
+ * ② 成功后再把该会话的视图偏好改写成「对话」页 —— 否则嵌套宿主按上次偏好把标签页弹回看板,
2712
+ * "跳过去了但看到的还是看板"(真机取证见 `bringConversationToFront` 注释);
2713
+ * ③ 没有通道 / 宿主拒绝 ⇒ **复制标识 + 如实说明**,绝不说"已打开"(那是 `-211` 之前的老毛病)。
2714
+ * 能力门:按钮文案固定「打开会话」,`HOST_BUTTON_LABELS` 里已有该条 ⇒ `applyHostGate` 按
2715
+ * `openSession` 能力位统一置灰并补 title,不需要这里再判一次。
2716
+ */
2717
+ const openSessionJump = (sid) => {
2718
+ const target = String(sid ?? "").trim();
2719
+ if (!target) { showBanner("没有可打开的会话标识", "error"); return; }
2720
+ const short = target.length > 18 ? `${target.slice(0, 18)}…` : target;
2721
+ if (!openHostSession) {
2722
+ void copyText(target);
2723
+ showBanner(`本实例没有宿主会话通道,无法直接跳转 —— 已复制会话标识 ${short},可在侧栏搜索`, "error");
2724
+ return;
2725
+ }
2726
+ let result = null;
2727
+ try { result = openHostSession(target); } catch (error) { result = { ok: false, reason: error?.message ?? String(error) }; }
2728
+ if (result?.ok) {
2729
+ bringConversationToFront(doc, target);
2730
+ showBanner(`已打开会话 ${short}(若仍停在「任务工作台」页,点上方「对话」即可看历史)`, "info");
2731
+ return;
2732
+ }
2733
+ void copyText(target);
2734
+ showBanner(`打开会话失败:${result?.reason ?? "宿主未接受该会话"} —— 已复制会话标识 ${short}`, "error");
2735
+ };
2736
+
2479
2737
  async function renderConfig() {
2480
2738
  configRoot.replaceChildren(mk("p", "hint", "加载配置…"));
2481
2739
  try {
@@ -2490,11 +2748,18 @@
2490
2748
  box.appendChild(mk("h2", null, `任务工作台 · 配置`));
2491
2749
  box.appendChild(mk("p", "hint", `配置对象:${state.projectId}(${projName})${sessionId ? " · 会话内" : " · 全局入口"} — 用上方“项目”下拉切换;下方所有保存都作用于该项目。`));
2492
2750
  // 开局向导(团队先行七步 + 复制指令)
2493
- const [gSettings, gDocs, gItems, gTasks] = await Promise.all([
2751
+ const [gSettings, gDocs, gItems, gTasks, gNorms, gSpec, gTeams] = await Promise.all([
2494
2752
  api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/settings`).catch(() => ({})),
2495
2753
  api("GET", `/api/requirements/docs?project=${encodeURIComponent(state.projectId)}`).catch(() => ({ docs: [] })),
2496
2754
  api("GET", `/api/requirements/items?project=${encodeURIComponent(state.projectId)}`).catch(() => ({ items: [] })),
2497
2755
  api("GET", `/api/tasks?project=${encodeURIComponent(state.projectId)}`).catch(() => ({ tasks: [] })),
2756
+ // 卡 `-216`(R160):规范来源(旧服务端没有这条路由 ⇒ null,卡片显示"不可用"而不是崩)
2757
+ api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/norms`).catch(() => null),
2758
+ // 卡 `-220`(R161):随包人读文档的位置(包内默认 / 项目存放 / 生效来源)
2759
+ api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/docs`).catch(() => null),
2760
+ // 卡 `-228`(R169):第 4 步「创建执行团队」的真实判据 —— 工作区 `.agent-teams/` 里的第三方团队。
2761
+ // 官方团队是常量(永远在)⇒ 不能拿 `teams.length>0` 当「已创建」,否则这一步恒绿=假绿。
2762
+ api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/agent-teams`).catch(() => null),
2498
2763
  ]);
2499
2764
  const gDoc = (gDocs.docs || [])[0] || null;
2500
2765
  const gItemsAll = gItems.items || [];
@@ -2503,28 +2768,64 @@
2503
2768
  const gEnv = Object.keys(gSettings.envConfig || {}).length > 0;
2504
2769
  const gRoster = (gSettings.teamTemplate?.roles || []).length > 0;
2505
2770
  const gIntake = gDoc ? /##\s*资料清单/.test(gDoc.body || "") : false;
2506
- const gOpen = gItemsAll.filter((i) => i.status === "open").length;
2771
+ // 卡 `-228`(R169):**「已确认」= 非 draft**。原来只数 `open` ⇒ 已交付(done/closed)的条目
2772
+ // 一律不算 ⇒ 本项目 164 条全确认却显示「已确认 3」(真机读数,2026-11-05)。
2507
2773
  const gDraft = gItemsAll.filter((i) => i.status === "draft").length;
2774
+ const gConfirmed = gItemsAll.filter((i) => i.status !== "draft").length;
2775
+ const gThirdPartyTeams = (gTeams?.teams || []).filter((t) => t.source !== "official").length;
2508
2776
  const gProg = gTasksAll.filter((t) => ["in_progress", "in_review", "blocked"].includes(t.status)).length;
2509
2777
  const guide = mk("section", "config-card");
2510
- guide.appendChild(mk("h3", null, "开局向导(团队先行)"));
2778
+ guide.appendChild(mk("h3", null, "开局向导(团队先行 · 7 步)"));
2511
2779
  const engine = gSettings.teamTemplate?.engine ?? "instruction";
2512
2780
  const gcopy = (label, text) => btn(label, () => { void copyText(text).then((ok) => showBanner(ok ? `已复制:${label}` : `复制失败:浏览器拒绝了剪贴板写入 —— 请手动选择复制(${label})`, ok ? "info" : "error")); });
2513
- const srow = (ok, n, title, ...actions) => { const r = mk("div", "config-row"); r.appendChild(pill(`${ok ? "✅" : "○"} 第 ${n} 步`, ok ? "ok" : "warn")); r.appendChild(mk("span", null, title)); const right = mk("span", "config-actions"); right.append(...actions); r.appendChild(right); return r; };
2781
+ /**
2782
+ * 卡 `-228`(R169)· 三态步骤条:`true` ✅ / `false` ○(**确知**未做)/ `null` ◐ 待核验。
2783
+ *
2784
+ * 原来只有布尔,于是两件「非布尔事实」被硬塞成 `false`:① 第 4 步「创建执行团队」本机没有
2785
+ * 可核验产物;② 「开局提示词」根本不是步骤。结果两行永久 ○ —— 既像「一直没做」,又让人以为
2786
+ * 还有两件事没做完(真机批注:「为什么开局提示词在第八步」)。
2787
+ * 口径:**没有信号时如实说「待核验」,不谎报成未做,也不谎报成已完成**(同 FR-84 存活胶囊三态)。
2788
+ */
2789
+ const srow = (state, n, title, ...actions) => {
2790
+ const r = mk("div", "config-row");
2791
+ const badge = state === true
2792
+ ? pill(`✅ 第 ${n} 步`, "ok")
2793
+ : state === false
2794
+ ? pill(`○ 第 ${n} 步`, "warn")
2795
+ : pill(`◐ 第 ${n} 步`, "", "本机没有可核验信号 —— 不等于没做,需要人工确认");
2796
+ r.appendChild(badge);
2797
+ r.appendChild(mk("span", null, title));
2798
+ const right = mk("span", "config-actions"); right.append(...actions); r.appendChild(right);
2799
+ return r;
2800
+ };
2801
+ // 开工语 —— **不是第 8 步**:它是新会话发给队长的**第一条消息**(`KICKOFF_PROMPT` 的 ①–⑧ 就是
2802
+ // 下面这 7 步的完整流程),复制即用,没有「做完」这个状态,因此不编号、不参与 ✅/○。
2803
+ const kickoffRow = mk("div", "config-row");
2804
+ kickoffRow.appendChild(pill("开工语", "warn", "新会话首条 —— 不是步骤,不编号也没有完成态"));
2805
+ kickoffRow.appendChild(mk("span", null, "新会话首条:把这句发给队长(它驱动下面 1–7 步)"));
2806
+ const kickoffRight = mk("span", "config-actions");
2807
+ kickoffRight.appendChild(gcopy("复制开局提示词", KICKOFF_PROMPT));
2808
+ kickoffRow.appendChild(kickoffRight);
2809
+ guide.appendChild(kickoffRow);
2810
+ guide.appendChild(mk("p", "hint", "「开工语」不是步骤:它没有 ✅,复制进新会话即可;下面的 1–7 步才是可核验的进度。"));
2514
2811
  guide.append(
2515
2812
  srow(gBound, 1, "绑定项目 / 会话", mk("span", "hint", info.project ? `${info.project.id}${sessionId ? (info.sessionBound === false ? "(未绑定)" : " · 已绑定会话") : " · 全局入口"}` : "(未解析)")),
2516
2813
  srow(gEnv, 2, "项目环境与约束", mk("span", "hint", gEnv ? "已配置" : "未配置(见下方卡片)")),
2814
+ // 第 3 步保留**唯一**的复制入口(第 4 步原来又发一个同样的按钮,属重复动作)。
2517
2815
  srow(gRoster, 3, `执行团队模板 · 引擎=${engine}`, mk("span", "hint", gRoster ? `${(gSettings.teamTemplate?.roles || []).length} 个角色` : "未配置"), gcopy("复制团队创建指令", teamPrompt(engine))),
2518
- srow(false, 4, "创建执行团队(对应引擎)", gcopy(`复制创建指令(${engine})`, teamPrompt(engine))),
2816
+ // 第 4 步口径:真发现第三方团队 ⇒ ✅;读不到或没有产物 ⇒ ◐ 待核验(官方团队是常量,不能当「已创建」)。
2817
+ srow(gThirdPartyTeams > 0 ? true : null, 4, "创建执行团队(对应引擎)",
2818
+ mk("span", "hint", gTeams === null ? "本机读不到团队清单(服务端较旧)" : gThirdPartyTeams > 0 ? `已发现 ${gThirdPartyTeams} 个第三方团队(.agent-teams/)` : "本机无产物:团队由队长在新会话里按第 3 步指令创建")),
2519
2819
  srow(gIntake, 5, "引入项目资料", mk("span", "hint", gIntake ? `已引入(条目 ${gItemsAll.length})` : "未引入(见下方卡片)")),
2520
- srow(gOpen > 0, 6, "确认需求条目", mk("span", "hint", `待确认 ${gDraft} · 已确认 ${gOpen}`), btn("去需求页", () => setView("req"))),
2820
+ srow(gConfirmed > 0, 6, "确认需求条目", mk("span", "hint", `待确认 ${gDraft} · 已确认 ${gConfirmed}`), btn("去需求页", () => setView("req"))),
2521
2821
  srow(gTasksAll.length > 0, 7, "生成看板任务", mk("span", "hint", `任务 ${gTasksAll.length}(进行中/待验 ${gProg})`), btn("去看板", () => setView("board"))),
2522
- srow(false, 8, "开局提示词(新会话首条)", gcopy("复制开局提示词", KICKOFF_PROMPT)),
2523
2822
  );
2524
2823
  box.appendChild(guide);
2525
2824
  if (stale) box.appendChild(mk("p", "hint", "当前服务端为旧版(无 /api/context):请重启 web profile 后重试。"));
2526
2825
  const card = (title, hint) => { const c = mk("section", "config-card"); c.appendChild(mk("h3", null, title)); if (hint) c.appendChild(mk("p", "hint", hint)); return c; };
2527
- const row = (label, ...nodes) => { const r = mk("div", "config-row"); r.appendChild(mk("span", null, label)); const right = mk("span", "config-actions"); right.append(...nodes); r.appendChild(right); return r; };
2826
+ // 卡 `-227`:label 允许直接传节点 —— 会话行需要给标签挂 `title`(完整会话标识),
2827
+ // 而纯字符串会被 `mk` 重新包一层,改不动它。传字符串时行为一字不变。
2828
+ const row = (label, ...nodes) => { const r = mk("div", "config-row"); r.appendChild(label && label.nodeType ? label : mk("span", null, label)); const right = mk("span", "config-actions"); right.append(...nodes); r.appendChild(right); return r; };
2528
2829
 
2529
2830
  const bind = card("当前绑定", "工作区 → 项目 → 需求文档(初始绑定)");
2530
2831
  bind.appendChild(kvList([
@@ -2537,6 +2838,142 @@
2537
2838
  // 新建走这里的按钮 —— 此前配置页只有「前往需求视图」,正常使用路径下无法新建项目。
2538
2839
  bind.appendChild(mk("p", "hint", "切换项目用顶部「项目」下拉;要新建项目点上面的「新建项目」(建完即切换为本会话的项目)。"));
2539
2840
 
2841
+ // ── 卡 `-216`(R160 · D-A/D-B/D-C 已拍):规范来源 ───────────────────────────
2842
+ // 真机缺口的原貌:`web/app.js` 里 `contract` / `norms` **一次都没出现** ⇒ 规范在包内、
2843
+ // 契约在变、`NORM_STALE` 会拦写,而界面上**一个字都没有**。人只能靠报错反推规则在哪。
2844
+ const normsCard = card("规范来源(机器规范)", "看板读写用的规则来自哪里;可以直接改副本 —— 改正文必须 bump version");
2845
+ const normsBody = mk("div", "config-body");
2846
+ normsCard.appendChild(normsBody);
2847
+ const drawNorms = (v) => {
2848
+ normsBody.replaceChildren();
2849
+ if (!v) { normsBody.appendChild(mk("p", "hint", "当前服务端没有 /norms 路由(旧版)—— 请重启 web profile 后再看。")); return; }
2850
+ const fallback = v.fallbackIds || [];
2851
+ const changed = (v.norms || []).filter((n) => n.modified).length;
2852
+ normsBody.appendChild(kvList([
2853
+ ["来源", v.source === "project" ? "项目副本(本工作区优先)" : "随包默认(安装包内)"],
2854
+ ["目录", v.dir || v.packagedDir || "—"],
2855
+ ["份数", `${(v.norms || []).length} 份${fallback.length ? `(缺 ${fallback.length} 份已回落包内:${fallback.join(" / ")})` : ""}`],
2856
+ ["与内置不同", `${changed} 份`],
2857
+ ]));
2858
+ const list = mk("ul", "req-list");
2859
+ for (const n of (v.norms || [])) {
2860
+ const li = mk("li", "req-item");
2861
+ li.append(mk("span", "req-title", `${n.id}@v${n.version}`));
2862
+ li.appendChild(pill(n.origin === "project" ? "副本" : "包内", n.origin === "project" ? "accent" : ""));
2863
+ if (n.modified) li.appendChild(pill("已改", "warn"));
2864
+ list.appendChild(li);
2865
+ }
2866
+ normsBody.appendChild(list);
2867
+ if ((v.ignoredFiles || []).length) {
2868
+ normsBody.appendChild(mk("p", "hint", `已忽略 ${v.ignoredFiles.length} 个非规范文件:${v.ignoredFiles.map((x) => `${x.file}(${x.reason})`).join(" · ")}`));
2869
+ }
2870
+ const actions = mk("div", "config-row");
2871
+ actions.appendChild(btn("生成默认副本", () => void normsAction("materialize"), "primary"));
2872
+ actions.appendChild(btn("恢复默认(覆盖副本)", () => void normsAction("reset")));
2873
+ normsBody.appendChild(actions);
2874
+ normsBody.appendChild(mk("p", "hint", "改法:直接编辑副本里的 .md(frontmatter 的 norm_id 别动);**改正文必须把 version 加 1**,否则会被判「规范被偷偷改了」而拦写。改完在「契约」里重算一次基线。要不要把 .taskboard/ 入库由你定。"));
2875
+ };
2876
+ const refreshNorms = async () => {
2877
+ const v = await api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/norms`).catch(() => null);
2878
+ drawNorms(v);
2879
+ };
2880
+ const normsAction = async (action) => {
2881
+ if (action === "reset" && !window.confirm("用安装包里的默认规范覆盖本项目副本?已做的修改会丢。")) return;
2882
+ try {
2883
+ const r = await api("POST", `/api/projects/${encodeURIComponent(state.projectId)}/norms`, { action, actor: "human" });
2884
+ // 只弹一条:规范变了 ⇒ 契约基线一定变。**不自动重算**(那是写库,让人自己点)。
2885
+ const head = action === "materialize"
2886
+ ? `已生成规范副本(写 ${r.written?.length ?? 0} 份 / 保留 ${r.kept?.length ?? 0} 份)`
2887
+ : `已恢复默认(写 ${r.written?.length ?? 0} 份)`;
2888
+ showBanner(`${head};规范已变 ⇒ 请重算契约基线,否则写操作会按旧契约被拦`, "warn");
2889
+ } catch (err) { showBanner(`${action === "reset" ? "恢复" : "生成"}失败:${err.message}`, "error"); }
2890
+ await refreshNorms();
2891
+ };
2892
+ box.appendChild(normsCard);
2893
+ drawNorms(gNorms);
2894
+
2895
+ // ── 卡 `-220`(R161):文档与规范位置 ────────────────────────────────────
2896
+ // 用户要求:**落地真实启动包的相关配套文档**,其「默认解压位置 / 后续存放位置」要能查、能看、能改。
2897
+ // 与上面「规范来源」分卡的理:这份改了**不影响契约**(契约只吃 spec/norms 的机器规范)。
2898
+ const specCard = card("文档与规范位置(随包人读文档)", "开局 / 流程 / 条目文档放在哪:包内默认 → 项目存放 → 生效来源;存放位置可改");
2899
+ const specBody = mk("div", "config-body");
2900
+ specCard.appendChild(specBody);
2901
+ const drawSpec = (v) => {
2902
+ specBody.replaceChildren();
2903
+ if (!v) { specBody.appendChild(mk("p", "hint", "当前服务端没有 /docs 路由(旧版)—— 重启 web profile 后再看。")); return; }
2904
+ const proj = v.project || {};
2905
+ const pack = v.packaged || {};
2906
+ specBody.appendChild(kvList([
2907
+ ["包内默认(解压后)", pack.dir || "—"],
2908
+ ["项目存放位置", `${proj.dir || "—"}${proj.dirIsOverride ? "(已改)" : "(默认)"}`],
2909
+ ["生效来源", (v.effective || {}).source === "project" ? "项目副本(本工作区优先)" : "包内默认(安装包内)"],
2910
+ ["文件数", `${(proj.files || []).length} 份 / 包内 ${(pack.files || []).length} 份`],
2911
+ ]));
2912
+ const list = mk("ul", "req-list");
2913
+ for (const f of (pack.files || [])) {
2914
+ const li = mk("li", "req-item");
2915
+ li.append(mk("span", "req-title", f));
2916
+ li.appendChild(pill((proj.files || []).includes(f) ? "副本" : "包内", (proj.files || []).includes(f) ? "accent" : ""));
2917
+ li.addEventListener("click", () => void openSpecDoc(f));
2918
+ list.appendChild(li);
2919
+ }
2920
+ specBody.appendChild(list);
2921
+ if ((v.missingInProject || []).length) {
2922
+ specBody.appendChild(mk("p", "hint", `副本里缺 ${v.missingInProject.length} 份(回落包内):${v.missingInProject.join(" · ")}`));
2923
+ }
2924
+ // 存放位置:可改、可恢复默认
2925
+ const dirInput = mk("input");
2926
+ dirInput.placeholder = "留空=默认 <工作区>/.taskboard/docs;也可填相对工作区的路径";
2927
+ dirInput.value = proj.dirIsOverride ? proj.dir : "";
2928
+ const dirRow = mk("div", "config-row");
2929
+ dirRow.appendChild(mk("span", null, "存放位置"));
2930
+ const dirRight = mk("span", "config-actions");
2931
+ dirRight.appendChild(dirInput);
2932
+ dirRight.appendChild(btn("保存路径", async () => {
2933
+ const val = dirInput.value.trim();
2934
+ try { const out = await api("PUT", `/api/projects/${encodeURIComponent(state.projectId)}/docs`, { dir: val, actor: "human" }); showBanner(val ? `存放位置已改为:${out.project.dir}` : "已恢复默认存放位置", "info"); drawSpec(out); }
2935
+ catch (e) { showBanner(`保存失败:${e.message}`, "error"); }
2936
+ }, "primary"));
2937
+ dirRight.appendChild(btn("恢复默认路径", async () => {
2938
+ try { const out = await api("PUT", `/api/projects/${encodeURIComponent(state.projectId)}/docs`, { dir: null, actor: "human" }); showBanner(`已恢复默认存放位置:${out.project.dir}`, "info"); drawSpec(out); }
2939
+ catch (e) { showBanner(`恢复失败:${e.message}`, "error"); }
2940
+ }));
2941
+ dirRow.appendChild(dirRight);
2942
+ specBody.appendChild(dirRow);
2943
+ const actions = mk("div", "config-row");
2944
+ actions.appendChild(btn("生成默认副本", () => void specAction("materialize"), "primary"));
2945
+ actions.appendChild(btn("恢复默认(覆盖副本)", () => void specAction("reset")));
2946
+ specBody.appendChild(actions);
2947
+ specBody.appendChild(mk("p", "hint", "改这些人读文档**不影响契约与门禁**(那只看 spec/norms 的机器规范);要不要把副本入库由你定。"));
2948
+ };
2949
+ const openSpecDoc = async (file) => {
2950
+ try {
2951
+ const d = await api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/docs?file=${encodeURIComponent(file)}`);
2952
+ const c = mk("section", "config-card");
2953
+ c.appendChild(mk("h3", null, `${d.file} · ${d.source === "project" ? "项目副本" : "包内默认"}`));
2954
+ c.appendChild(mk("p", "hint", d.dir));
2955
+ const pre = mk("pre", "doc-preview"); pre.textContent = d.text;
2956
+ c.appendChild(pre);
2957
+ specBody.replaceChildren(c, btn("← 返回位置视图", () => void refreshSpec(), "ghost"));
2958
+ } catch (e) { showBanner(`打开失败:${e.message}`, "error"); }
2959
+ };
2960
+ const refreshSpec = async () => {
2961
+ const v = await api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/docs`).catch(() => null);
2962
+ drawSpec(v);
2963
+ };
2964
+ const specAction = async (action) => {
2965
+ if (action === "reset" && !window.confirm("用安装包里的默认文档覆盖本项目副本?已做的修改会丢。")) return;
2966
+ try {
2967
+ const r = await api("POST", `/api/projects/${encodeURIComponent(state.projectId)}/docs`, { action, actor: "human" });
2968
+ showBanner(action === "materialize"
2969
+ ? `已生成文档副本(写 ${r.written?.length ?? 0} 份 / 保留 ${r.kept?.length ?? 0} 份)⇒ ${r.dir}`
2970
+ : `已恢复默认(写 ${r.written?.length ?? 0} 份)`, "info");
2971
+ drawSpec(r.view);
2972
+ } catch (e) { showBanner(`${action === "reset" ? "恢复" : "生成"}失败:${e.message}`, "error"); }
2973
+ };
2974
+ box.appendChild(specCard);
2975
+ drawSpec(gSpec);
2976
+
2540
2977
  const req = card("需求", "需求文档与条目的管理入口");
2541
2978
  req.appendChild(row("需求视图", btn("打开", () => setView("req"), "primary")));
2542
2979
  req.appendChild(row("新建需求条目", btn("新建", async () => {
@@ -2630,6 +3067,7 @@
2630
3067
  try {
2631
3068
  const k = await api("GET", `/api/projects/${encodeURIComponent(state.projectId)}/kickoff`);
2632
3069
  lastKickoff = k;
3070
+ alignGapState(k);
2633
3071
  const wrap = mk("div", "kickoff-steps");
2634
3072
  wrap.appendChild(mk("div", `kickoff-verdict ${k.ready ? "ok" : "warn"}`, `${k.ready ? "✔ " : "⚠ "}${k.verdict}`));
2635
3073
  if (!k.readable) wrap.appendChild(mk("p", "hint", "项目未配置工作区目录(workspacePath)⇒ 文件类判据无法自检(设置里填上工作区即可)。"));
@@ -2652,11 +3090,51 @@
2652
3090
  src.appendChild(link);
2653
3091
  wrap.appendChild(src);
2654
3092
  alignBody.replaceChildren(wrap);
2655
- } catch (e) { alignBody.replaceChildren(mk("div", "empty-note", `自检失败:${e.message}(服务端旧版本需重载插件才有该端点)`)); }
3093
+ } catch (e) { alignBody.replaceChildren(mk("div", "empty-note", `自检失败:${e.message}(服务端旧版本需重载插件才有该端点)`)); alignGapState(null); }
3094
+ };
3095
+ // 卡 `-229`(需求 R170):把**当前实时缺口**引入主对话(不是复制到剪贴板就结束)。
3096
+ // 零缺口 = 自检 `ready`(六步全 done ⇒ 没有任何未通过判据)⇒ 置灰 + 明说「开局已对齐」。
3097
+ // 不挂 `data-needs-host`:无宿主会话通道时服务端会回带正文,本按钮仍要有用(降级为复制 + 如实说明未投递)。
3098
+ const alignGapCount = (k) => (k?.missing ?? []).reduce((n, s) => n + (s.todo?.length ?? 0), 0);
3099
+ const gapHint = mk("span", "hint", "自检完成后可点");
3100
+ const gapBtn = btn("引入主对话", () => void announceGaps(), "primary");
3101
+ gapBtn.disabled = true;
3102
+ const alignGapState = (k) => {
3103
+ const n = alignGapCount(k);
3104
+ const aligned = Boolean(k?.ready) || (k ? n === 0 : false);
3105
+ gapBtn.disabled = !k || aligned;
3106
+ gapBtn.title = !k ? "自检完成后可点" : aligned ? "开局已对齐:没有缺口可引入" : `把当前 ${n} 项缺口引入项目主会话`;
3107
+ gapHint.textContent = !k ? "自检完成后可点" : aligned ? "开局已对齐" : `缺口 ${n} 项(按依赖顺序引入)`;
3108
+ };
3109
+ const announceGaps = async () => {
3110
+ if (!lastKickoff) { showBanner("请先「重新自检」拿到当前缺口", "error"); return; }
3111
+ if (lastKickoff.ready) { showBanner("开局已对齐:没有缺口可引入", "info"); return; }
3112
+ gapBtn.disabled = true;
3113
+ try {
3114
+ const r = await api("POST", `/api/projects/${encodeURIComponent(state.projectId)}/kickoff/announce`, {});
3115
+ if (r?.delivered) {
3116
+ showBanner(`已把 ${r?.gaps?.count ?? "?"} 项缺口引入主会话 ${String(r.sessionId ?? "").slice(0, 12)}…(按依赖顺序推进;每完成一项回本页点「重新自检」)`, "info");
3117
+ } else if (r?.prompt) {
3118
+ const copied = await copyText(r.prompt);
3119
+ showBanner(`未投递(${r?.reason === "host-unavailable" ? "本实例没有宿主会话通道" : (r?.reason ?? "原因未知")}):缺口清单${copied ? "已复制到剪贴板" : "复制失败,请点「复制对齐清单」手动投递"} —— 这不是「已引入」;下一步:${r?.nextAction ?? "到 DSH 内的任务工作台重试"}`, "error");
3120
+ } else {
3121
+ showBanner(`未投递:${r?.reason ?? "未知原因"};请点「复制对齐清单」手工投递`, "error");
3122
+ }
3123
+ } catch (e) {
3124
+ const fallback = e?.details?.prompt ?? null;
3125
+ const copied = fallback ? await copyText(fallback) : false;
3126
+ const why = e?.code === "NO_MAIN_SESSION"
3127
+ ? "该项目还没有主会话:先在本卡「会话关联」重建/绑定主会话,再点「引入主对话」"
3128
+ : `投递失败:${e?.message ?? e}${e?.code ? `(${e.code})` : ""}`;
3129
+ showBanner(`${why}${fallback ? `;缺口清单${copied ? "已复制到剪贴板" : "复制失败,请点「复制对齐清单」手动投递"}(未投递)` : ""}`, "error");
3130
+ } finally { alignGapState(lastKickoff); }
2656
3131
  };
3132
+
2657
3133
  const alignBar = mk("div", "btn-row");
2658
3134
  alignBar.append(
2659
- btn("重新自检", () => void refreshAlign(), "primary"),
3135
+ btn("重新自检", () => void refreshAlign()),
3136
+ gapBtn,
3137
+ gapHint,
2660
3138
  btn("复制对齐清单", () => {
2661
3139
  const k = lastKickoff;
2662
3140
  if (!k) { showBanner("请先「重新自检」拿到清单", "error"); return; }
@@ -2729,7 +3207,15 @@
2729
3207
  };
2730
3208
  const mainRow = sessList.main ?? (state.context?.mainSessionId ? { sessionId: state.context.mainSessionId, liveness: null } : null);
2731
3209
  if (mainRow) {
2732
- links.appendChild(row(`主会话 · ${String(mainRow.sessionId).slice(0, 14)}…`, livenessPill(mainRow.liveness), sessList.staleMain ? btn("重建并绑定主会话", rebindMain, "primary") : mk("span", "hint", "")));
3210
+ // 卡 `-227`:主会话行加「打开会话」;标签挂 `title`(截断文本不再丢完整标识)。
3211
+ const mainLabel = mk("span", null, `主会话 · ${String(mainRow.sessionId).slice(0, 14)}…`);
3212
+ mainLabel.title = String(mainRow.sessionId);
3213
+ links.appendChild(row(
3214
+ mainLabel,
3215
+ livenessPill(mainRow.liveness),
3216
+ hostBtn("打开会话", () => openSessionJump(mainRow.sessionId)),
3217
+ sessList.staleMain ? btn("重建并绑定主会话", rebindMain, "primary") : mk("span", "hint", ""),
3218
+ ));
2733
3219
  }
2734
3220
  // FR-84 补口(2026-10-22):**不新建会话**的接续出口(宿主建会话不可用时的保底路径)。
2735
3221
  const bindBar = mk("div", "tb-bind-bar");
@@ -2763,9 +3249,13 @@
2763
3249
  links.appendChild(probeLine);
2764
3250
  if ((sessList.sessions ?? []).length) {
2765
3251
  for (const s of sessList.sessions) {
3252
+ // 卡 `-227`:每条相关会话都能直接跳过去(待批准的也允许 —— 存在不代表不能用来看历史)。
3253
+ const sessLabel = mk("span", null, `${s.status === "approved" ? "✅ 已批准" : "⏳ 待批准"} · ${String(s.sessionId).slice(0, 14)}…`);
3254
+ sessLabel.title = String(s.sessionId);
2766
3255
  links.appendChild(row(
2767
- `${s.status === "approved" ? "✅ 已批准" : "⏳ 待批准"} · ${String(s.sessionId).slice(0, 14)}…`,
3256
+ sessLabel,
2768
3257
  livenessPill(s.liveness),
3258
+ hostBtn("打开会话", () => openSessionJump(s.sessionId)),
2769
3259
  s.status === "pending" ? btn("批准", async () => {
2770
3260
  try { await api("POST", `/api/projects/${encodeURIComponent(state.projectId)}/sessions/approve`, { sessionId: s.sessionId }); showBanner("已批准关联", "info"); await renderConfig(); }
2771
3261
  catch (e) { showBanner(`批准失败:${e.message}`, "error"); }
@@ -2987,7 +3477,32 @@
2987
3477
  return { folders: merged, files, folderCount, fileTotal, byteTotal };
2988
3478
  }
2989
3479
 
2990
- /** FR-96:渲染文件夹树 —— 叶子是文件;节点可展开/收起,**默认展开**(不隐藏任何文件)。 */
3480
+ /**
3481
+ * 卡 `-226`(需求 `R167`):**文件类型徽标**的 kind —— 纯呈现,只决定图标的底色与字母。
3482
+ *
3483
+ * 真机批注(2026-11-05):「引入文件的样式我希望引用 dsh 侧边栏的文件列表样式」。
3484
+ * DSH 侧栏的每个文件前有一个按类型着色的小图标(`.mjs` 琥珀 / `.md` 绿 / `.json` 橙),
3485
+ * 扫一眼就能分辨「这是代码还是文档」。这里**不引入图标字体、不引外链资源**,只用 14×14 的
3486
+ * 圆角色块 + 8px 字母(纯 CSS 绘制),所以离线、随包、零请求。
3487
+ * ⚠️ 它**不参与** FR-96 的树结构 / 排序 / 计数 —— 那部分(`buildFileFolderTree`)一字未改。
3488
+ */
3489
+ function fileKind(name) {
3490
+ const n = String(name ?? "").toLowerCase();
3491
+ if (/\.(mjs|cjs|js|jsx)$/.test(n)) return "js";
3492
+ if (/\.(ts|tsx|mts|cts)$/.test(n)) return "ts";
3493
+ if (/\.(md|markdown|mdx)$/.test(n)) return "md";
3494
+ if (/\.json$/.test(n)) return "json";
3495
+ if (/\.ya?ml$/.test(n)) return "yaml";
3496
+ if (/\.(png|jpe?g|gif|svg|webp|ico)$/.test(n)) return "img";
3497
+ if (/\.(css|scss|less)$/.test(n)) return "css";
3498
+ if (/\.(sh|bash|zsh)$/.test(n)) return "sh";
3499
+ return "file";
3500
+ }
3501
+ const FILE_KIND_LABEL = { js: "JS", ts: "TS", md: "MD", json: "{}", yaml: "YML", img: "IMG", css: "CSS", sh: "SH", file: "·" };
3502
+
3503
+ /** FR-96:渲染文件夹树 —— 叶子是文件;节点可展开/收起,**默认展开**(不隐藏任何文件)。
3504
+ * 卡 `-226`:叶子行由「名字 + spacer + 体积胶囊」改为「类型图标 + 名字 + 定宽体积列」,
3505
+ * 与 DSH 侧栏文件列表同一套语言;`ul`/`li`/`details`/`summary` 的**结构不变**(既有 11 项守卫照旧)。 */
2991
3506
  function renderFileTree(tree) {
2992
3507
  const wrap = mk("div", "req-tree");
2993
3508
  const walk = (node, container) => {
@@ -3007,7 +3522,11 @@
3007
3522
  for (const f of node.files) {
3008
3523
  const li = mk("li", "req-file");
3009
3524
  li.title = f.path;
3010
- li.append(mk("span", "req-file-name", f.name), mk("span", "spacer"), pill(`${f.bytes} B`));
3525
+ const kind = fileKind(f.name);
3526
+ const icon = mk("span", "req-file-icon", FILE_KIND_LABEL[kind] ?? "·");
3527
+ icon.dataset.kind = kind;
3528
+ icon.setAttribute("aria-hidden", "true");
3529
+ li.append(icon, mk("span", "req-file-name", f.name), mk("span", "req-file-size", `${f.bytes} B`));
3011
3530
  ul.appendChild(li);
3012
3531
  }
3013
3532
  container.appendChild(ul);
@@ -3251,7 +3770,9 @@
3251
3770
  mk("span", "hint", `${tree.folderCount} 个文件夹 · 根级文件 ${tree.files.length} · 合计 ${(tree.byteTotal / 1024).toFixed(1)} KB`),
3252
3771
  );
3253
3772
  fs.appendChild(head);
3254
- const bar = mk("div", "field-inline");
3773
+ // 卡 `-226`:工具条不再用 `.field-inline`(那个是表单行,`align-items: flex-end` 会贴底),
3774
+ // 改为树自己的紧凑工具栏(左侧起头、与树的左内边距对齐)。
3775
+ const bar = mk("div", "req-tree-tools");
3255
3776
  bar.append(btn("全部展开", () => setAllFolders(fs, true)), btn("全部收起", () => setAllFolders(fs, false)));
3256
3777
  fs.appendChild(bar);
3257
3778
  fs.appendChild(renderFileTree(tree));
@@ -3302,7 +3823,10 @@
3302
3823
  const newTitle = mk("input");
3303
3824
  newTitle.type = "text";
3304
3825
  newTitle.placeholder = "新条目标题";
3305
- const createRow = mk("div", "field-inline");
3826
+ // 卡 `-225`(需求 `R166`):真机批注「同类输入框&按钮都挤在左侧」。三段(新建 / 筛选 / 批量)
3827
+ // 现在各自成行并挂在 `.req-toolbar` 里 —— 行内左右分组、控件同高,行距由容器统一给。
3828
+ // 不再套 `.field-inline`(全局表单类,`align-items: flex-end` 会把同排控件压得基线不齐)。
3829
+ const createRow = mk("div", "req-toolbar-row req-toolbar-create");
3306
3830
  // 真机批注 2026-10-28「新建条目点击无效」:此前标题为空时**静默 return** —— 点了没反应、
3307
3831
  // 也没有任何提示,被读成按钮坏了。口径:空标题必须**当场说话**并把焦点送回输入框;
3308
3832
  // 另外支持回车提交(填完标题顺手敲回车是常态)。
@@ -3323,7 +3847,8 @@
3323
3847
  event.preventDefault();
3324
3848
  void createItem();
3325
3849
  });
3326
- itemBody.appendChild(createRow);
3850
+ const reqToolbar = mk("div", "req-toolbar");
3851
+ reqToolbar.appendChild(createRow);
3327
3852
  const filt = mk("select");
3328
3853
  // FR-91:新增「已完成 / 已关闭」——需求层此前没有"做完了没有"的落点
3329
3854
  for (const [v, l] of [["all", "全部状态"], ["draft", "待确认"], ["open", "在办"], ["done", "已完成"], ["closed", "已关闭"]]) { const o = mk("option"); o.value = v; o.textContent = l; filt.appendChild(o); }
@@ -3334,11 +3859,13 @@
3334
3859
  search.placeholder = "搜索编号 / 标题";
3335
3860
  search.value = reqState.q ?? "";
3336
3861
  search.addEventListener("change", () => { reqState.q = search.value.trim(); void renderRequirements(); });
3337
- const fr = mk("div", "field-inline");
3338
- fr.append(filt, search);
3339
- itemBody.appendChild(fr);
3340
- // U-1:下一步引导(团队先行后的收敛路径)——单行,避免拥挤
3341
- itemBody.appendChild(mk("p", "hint", `下一步:确认条目 → 生成看板任务 → 授权开工 → 派发执行 (待确认 ${draftCount} · 已确认 ${openCount})`));
3862
+ const fr = mk("div", "req-toolbar-row req-toolbar-filter");
3863
+ // U-1:下一步引导(团队先行后的收敛路径)。卡 `-225`:从独占一行改为**并到筛选行右侧**
3864
+ // (宽视口右对齐、窄视口自动换行),不再让左侧控件与右侧长提示之间空出一大片。
3865
+ const nextHint = mk("p", "hint req-toolbar-hint", `下一步:确认条目 → 生成看板任务 → 授权开工 → 派发执行 (待确认 ${draftCount} · 已确认 ${openCount})`);
3866
+ fr.append(filt, search, nextHint);
3867
+ reqToolbar.appendChild(fr);
3868
+ itemBody.appendChild(reqToolbar);
3342
3869
  if (reqState.candidates.length) {
3343
3870
  const cs = mk("div", "drawer-section");
3344
3871
  cs.appendChild(mk("h3", null, `待确认候选(${reqState.candidates.length})`));
@@ -3385,9 +3912,12 @@
3385
3912
  : "逐行从既有 GET /api/requirements/items/:ref/completion 取数:关联任务全部收口的需求会显示「可收口」";
3386
3913
  };
3387
3914
  // 批量工具条(默认多选 → 批量生成任务)
3388
- const bulkBar = mk("div", "field-inline");
3915
+ // 卡 `-225`:批量条拆成「左=已选 N」+「右=动作组」。此前六个元素从左往右平铺,
3916
+ // 蓝色主按钮夹在中间、删除紧挨生成 —— 既难扫也危险(误点批量删除)。
3917
+ const bulkBar = mk("div", "req-bulk-bar");
3918
+ const bulkActions = mk("div", "req-bulk-actions");
3389
3919
  bulkBar.append(
3390
- mk("span", "hint", `已选 ${reqState.selected.size}`),
3920
+ mk("span", "hint req-bulk-count", `已选 ${reqState.selected.size}`),
3391
3921
  btn("全选可见", () => { for (const it of visible) reqState.selected.add(it.identifier); void renderRequirements(); }),
3392
3922
  btn("清除选择", () => { reqState.selected.clear(); void renderRequirements(); }),
3393
3923
  btn("批量确认", async () => {
@@ -3417,8 +3947,11 @@
3417
3947
  reqState.selected.clear();
3418
3948
  showBanner(failed.length ? `已删除 ${ok} 条,失败 ${failed.length} 条(首条:${failed[0]})` : `已删除 ${ok} 条`, failed.length ? "error" : "info");
3419
3949
  await renderRequirements();
3420
- }),
3950
+ }, "danger"),
3421
3951
  );
3952
+ // 五个动作整体挪到右侧动作组(顺序保持:全选 → 清除 → 批量确认 → 批量生成 → 批量删除)
3953
+ bulkActions.append(...Array.from(bulkBar.querySelectorAll(":scope > button")));
3954
+ bulkBar.appendChild(bulkActions);
3422
3955
  itemBody.appendChild(bulkBar);
3423
3956
  const ul = mk("ul", "req-list");
3424
3957
  for (const it of visible) {
@@ -3442,6 +3975,9 @@
3442
3975
  const completionChip = reqCompletionChip(it, reqState.completion.get(it.identifier)?.payload ?? null);
3443
3976
  const meta = mk("div", "req-item-meta");
3444
3977
  meta.append(pill(srcLabel, it.source === "intake" ? "" : "accent"));
3978
+ // 卡 `-218`(R159 D-1=`c`):**行上**就要看出这条是不是残片/镜像 —— 不点进详情才发现的等于没标。
3979
+ const integrity = DETAIL_STATE_LABELS[it.detailState];
3980
+ if (integrity) meta.append(pill(integrity.text, integrity.tone, integrity.title));
3445
3981
  if (it.feasibility === "infeasible") meta.append(pill("不可行", "danger"));
3446
3982
  li.append(main, statusChip, completionChip, meta);
3447
3983
  const acts = mk("div", "req-item-actions");
@@ -3589,6 +4125,7 @@
3589
4125
  const addF = (k, v, cls) => { dl.appendChild(mk("dt", null, k)); const dd = mk("dd", null, v); if (cls) dd.className = cls; dl.appendChild(dd); };
3590
4126
  addF("状态", statusTxt);
3591
4127
  addF("来源", srcLabel);
4128
+ addF("完整性", detailStateText(item.detailState), item.detailState === "truncated" ? "warn" : "");
3592
4129
  addF("优先级", PRIORITY_LABELS[item.priority] ?? item.priority);
3593
4130
  addF("可行性", item.feasibility ?? "未评估", item.feasibility === "infeasible" ? "danger" : item.feasibility === "feasible" ? "ok" : "");
3594
4131
  if (item.acceptance) addF("验收要点", item.acceptance);
@@ -3884,6 +4421,10 @@
3884
4421
  } catch (error) {
3885
4422
  host.replaceChildren(head, mk("p", "hint", `加载失败:${error.message}`));
3886
4423
  }
4424
+ // 卡 `-224`:本区块是**异步后补**的(`void fillTaskTeam(...)`,晚于 openTaskDetail 的收尾归一),
4425
+ // 且它在未归因时会追加一个 primary「去归因」—— 这里补一次归一,否则「一屏一个主按钮」会被
4426
+ // 后到的按钮破坏(验证台实测:primary=2,两条都在团队区块与「下一步」区)。
4427
+ normalizeActionTiers();
3887
4428
  }
3888
4429
  /** FR-42/47:从任务详情发起一次团队派发(单任务;引擎经 /api/teams 决定,默认 P2 指令降级)。 */
3889
4430
  async function dispatchTeam(identifier, onDone) {
@@ -4313,13 +4854,20 @@
4313
4854
  }
4314
4855
  // 入口口径与卡片、下一步面板同一份(executionEntry):未归因的可开工卡在抽屉里也给「去归因」。
4315
4856
  const drawerEntry = executionEntry(t);
4316
- if (drawerEntry === "attribute") ops.appendChild(btn("去归因(关联需求条目)", () => { void openAttributionEntry(t); }, "primary"));
4857
+ // 卡 `-224`:标题栏**不承担主按钮**。归因是「下一步」区的主动作(服务端 `goto-attribution`),
4858
+ // 标题栏只保留一条 `link` 指针(与 FR-89「下一列 → 处置见『下一步』」同一先例:
4859
+ // 同一动作不摆两个同等权重的平行入口)。
4860
+ if (drawerEntry === "attribute") {
4861
+ const gotoAttr = btn("去归因(见「归因」区)", () => { void openAttributionEntry(t); }, "link");
4862
+ gotoAttr.title = "等同于「下一步」区的「去归因(关联需求条目)」:展开并滚到下方「归因」区块";
4863
+ ops.appendChild(gotoAttr);
4864
+ }
4317
4865
  // 第九报:待办池卡在抽屉里也要有显式入口(此前只有「下一列」按钮,得靠人自己推断那是授权)。
4318
4866
  if (drawerEntry === "authorize") ops.appendChild(btn("授权开工(移出待办池)", async () => {
4319
4867
  if (!window.confirm(`把 ${t.identifier} 移出「待办池」→「可开工」?授权只是放行,仍需人点「启动执行」或由团队/执行循环认领。`)) return;
4320
4868
  const ok = await moveTask(t, "todo");
4321
4869
  if (ok) showBanner(`${t.identifier} 已授权开工(待办池 → 可开工)。下一步:点「启动执行」,或让它被团队/执行循环认领。`, "info");
4322
- }, "primary"));
4870
+ }, "secondary"));
4323
4871
  if (drawerEntry === "start") ops.appendChild(btn("启动执行", async () => {
4324
4872
  if (!window.confirm(`启动执行会尝试新建/切换会话(可能切换主视图)。${execRunning ? "\n\n⚠ 该任务已有执行会话正在执行且未返回结论,继续会被拒绝(EXECUTION_ALREADY_RUNNING)。" : ""}确认继续?`)) return;
4325
4873
  try { await api("POST", `/api/tasks/${ref}/execute`, undefined); closeDrawer(); await loadTasks(); }
@@ -4327,11 +4875,11 @@
4327
4875
  // 与卡片入口同一份处置(含「打开并高亮归因入口」),不再各写一套措辞。
4328
4876
  await handleExecutionFailure(e, ref, t);
4329
4877
  }
4330
- }, "primary"));
4878
+ }, "secondary"));
4331
4879
  if (t.status === "in_progress") {
4332
4880
  const r2 = mk("div", "btn-row");
4333
4881
  r2.append(
4334
- btn("提交待验收", async () => { try { await api("POST", `/api/tasks/${ref}/execution/review`, {}); closeDrawer(); await loadTasks(); } catch (e) { showBanner(e.message, "error"); } }, "primary"),
4882
+ btn("提交待验收", async () => { try { await api("POST", `/api/tasks/${ref}/execution/review`, {}); closeDrawer(); await loadTasks(); } catch (e) { showBanner(e.message, "error"); } }, "secondary"),
4335
4883
  btn("标记失败", async () => { try { await api("POST", `/api/tasks/${ref}/execution/fail`, { evidence: "手动标记失败" }); closeDrawer(); await loadTasks(); } catch (e) { showBanner(e.message, "error"); } }),
4336
4884
  btn("退回待办(重新派发)", async () => {
4337
4885
  const extra = execRunning ? "\n\n⚠ 该任务已有执行会话正在执行中;退回后会释放任务级锁,但再次下发仍会被拒(需等会话结束)。" : "";
@@ -4343,7 +4891,7 @@
4343
4891
  );
4344
4892
  ops.appendChild(r2);
4345
4893
  }
4346
- if (t.status === "blocked") ops.appendChild(btn("重试", async () => { try { await api("POST", `/api/tasks/${ref}/execution/retry`, {}); closeDrawer(); await loadTasks(); } catch (e) { showBanner(e.message, "error"); } }, "primary"));
4894
+ if (t.status === "blocked") ops.appendChild(btn("重试", async () => { try { await api("POST", `/api/tasks/${ref}/execution/retry`, {}); closeDrawer(); await loadTasks(); } catch (e) { showBanner(e.message, "error"); } }, "secondary"));
4347
4895
  ops.appendChild(btn("拆解为子任务", async () => {
4348
4896
  if (!window.confirm("按任务描述自动拆解为关联子任务?(无编号行则生成 实现/验证 两条)")) return;
4349
4897
  try { const r = await api("POST", `/api/tasks/${ref}/decompose`, {}); showBanner(`已生成子任务:${(r.children || []).map((c) => c.identifier).join("、")}(待办池)`, "info"); closeDrawer(); await loadTasks(); }
@@ -5140,6 +5688,8 @@
5140
5688
  for (const staleNextStep of Array.from(drawerBody.querySelectorAll(".drawer-section.next-step"))) staleNextStep.remove();
5141
5689
  drawerBody.insertBefore(sec, drawerBody.firstChild); // 放最前:先回答"该干嘛",再看明细
5142
5690
  }
5691
+ // 卡 `-224`:所有区块(含刚插到最前面的「下一步」)都渲染完后,统一收敛主按钮层级。
5692
+ normalizeActionTiers();
5143
5693
  } catch (error) {
5144
5694
  if (renderSeq !== detailRenderSeq) return; // 已被更新的一代取代 ⇒ 不要把失败占位压到新一代的成品上
5145
5695
  drawerActions.replaceChildren();