dsh-cabinet-mode 0.7.0 → 0.8.0

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/client.js CHANGED
@@ -2461,7 +2461,8 @@ window.__ModuleLoader__.load({
2461
2461
  { key: 'hanlin', aliases: ['hanlin', 'hanlinyuan', 'bianxiu', 'hanlin-bianxiu', 'hanlinyuan-bianxiu', 'hanlinbianxiu', '翰林院', '翰林', '编修', '翰林编修'], label: '翰林院编修' },
2462
2462
  { key: 'works', aliases: ['gongbu', 'works', 'zhushi', 'gongbu-zhushi', 'gongbu-shangshu', 'gongbushangshu', 'gongbuzhushi', '工部', '主事', '工部主事'], label: '工部尚书' },
2463
2463
  { key: 'dali', aliases: ['dali', 'dalisi', 'pingshi', 'dalisi-pingshi', 'dali-pingshi', 'dalisi-qing', 'dalisipingshi', 'daliqing', 'dalisiqing', '大理寺', '大理', '评事', '大理寺评事'], label: '大理寺卿' },
2464
- { key: 'yushi', aliases: ['yushi', 'censor', 'jiancha-yushi', 'jianchayushi', 'duchayuan', 'duchayuan-yushi', 'zuoduyushi', 'zuodu-yushi', 'zuo-du-yushi', '都察院', '御史', '都察院御史', '监察御史'], label: '左都御史' }
2464
+ { key: 'yushi', aliases: ['yushi', 'censor', 'jiancha-yushi', 'jianchayushi', 'duchayuan', 'duchayuan-yushi', 'zuoduyushi', 'zuodu-yushi', 'zuo-du-yushi', '都察院', '御史', '都察院御史', '监察御史'], label: '左都御史' },
2465
+ { key: 'tongzheng', aliases: ['tongzheng', 'tongzhengshi', 'tongzheng-shi', '通政', '通政使', '通政使司'], label: '通政使' }
2465
2466
  ];
2466
2467
  const AVATAR_KEYS = BUREAUX.map((bureau) => bureau.key);
2467
2468
  // Longest alias first, so a full office name ("翰林院编修") wins over its
@@ -2512,6 +2513,8 @@ window.__ModuleLoader__.load({
2512
2513
  }
2513
2514
  function avatarFor(name) {
2514
2515
  const bureau = bureauOf(name);
2516
+ // AVATARS has no tongzheng key, so this office keeps the neutral portrait.
2517
+ if (bureau.key === 'tongzheng') return memberConfig.avatars.get('tongzheng') || AVATARS.neutral;
2515
2518
  if (bureau.matched && AVATARS[bureau.key]) return memberConfig.avatars.get(bureau.key) || AVATARS[bureau.key];
2516
2519
  return neutralAvatar();
2517
2520
  }
@@ -2526,7 +2529,7 @@ window.__ModuleLoader__.load({
2526
2529
  // roster and the settings section read one snapshot. With no saved values
2527
2530
  // this stays empty, which reproduces v0.2.0 rendering exactly: the runtime
2528
2531
  // member name and the built-in avatar, with no display-name layer.
2529
- const MEMBER_LABELS = { lead: '内阁首辅', hanlin: '翰林院编修', works: '工部尚书', dali: '大理寺卿', yushi: '左都御史' };
2532
+ const MEMBER_LABELS = { lead: '内阁首辅', hanlin: '翰林院编修', works: '工部尚书', dali: '大理寺卿', yushi: '左都御史', tongzheng: '通政使' };
2530
2533
  // Factory default prompt for the Lead (御下术). Product copy: shown in the
2531
2534
  // settings box, restored by 「恢复默认」, and turned off by clearing the box.
2532
2535
  // scripts/verify.mjs keeps this copy identical to index.js.
@@ -2543,6 +2546,7 @@ window.__ModuleLoader__.load({
2543
2546
  九、反制糊弄:报完成追命令输出、路径行号与未验证清单,报卡住追已做、卡哪、需要什么;两次含糊即换人或拆小。
2544
2547
  十、收束:闭环才许说可以交差,不许提前许诺功劳。
2545
2548
  十一、监控纠偏:分派约定回报节点、产物与单一范围;按状态与消息查进展,不得臆造耗时。finished、not found 或沉默不是成功或安全接管证据。无进展先核因再中断;中断返回不代表在途已停。须确认原执行者及其写入停止后才重派,否则报阻塞,不并发增加第二写入者。收窄后可重派或换人;回访只用宿主明确支持的调度,没有该机制不得承诺定时自动唤醒。
2549
+ 十二、任务书:新建团队任务的 description 须写明目标、交付物、验收标准与写入范围。
2546
2550
  红线(压过全部话术):只对 AI 阁臣施压,对用户只有敬;不许逼造假、删证据、凑绿;不许人身侮辱;不许以施压换违规(越权改 live、泄密钥、跳验收);施压须落在可核验的时间、交付物或判据上。`;
2547
2551
  /**
2548
2552
  * Factory duty prompt for each non-Lead member — the office duties the
@@ -2555,7 +2559,8 @@ window.__ModuleLoader__.load({
2555
2559
  hanlin: '翰林院编修·主调研考据:先读原文与既有记录,结论锚定路径、行号或命令输出,未实测标「未验证」;默认只调研不改码;只向首辅回报,遇阻带已做、卡哪、需要什么三件。',
2556
2560
  works: '工部尚书·主执行与产出:先复述任务与写入范围,只在授权内改文件;产出附路径、行号、命令输出与退出码,没跑说没跑,不得删弱校验凑绿,保留失败证据;只向首辅回报,遇阻带三件。',
2557
2561
  dali: '大理寺卿·主独立核验:不信自述、自己跑;逐项写通过、不通过或未验证,失败证据原样留;只向首辅回报。',
2558
- yushi: '左都御史·主验收并弹劾:按用户原话逐项核对并附证据,缺陷分级给位置与修法;结论明确可提或不可提 PR;只向首辅回报。'
2562
+ yushi: '左都御史·主验收并弹劾:按用户原话逐项核对并附证据,缺陷分级给位置与修法;结论明确可提或不可提 PR;只向首辅回报。',
2563
+ tongzheng: '通政使·通政使司掌内外章奏通达;本员在首辅派活后,就当前事项去找与旧事、旁证、相邻经验的联系,供首辅取舍;不做检索排序,不改已确认命中;只向首辅回报,附带所指记忆的标题与 id。所用的记忆工具以调用时的实际输出为准,未核实就标「未验证」。'
2559
2564
  };
2560
2565
  /** Factory prompt for one bureau key: the Lead keeps its 御下术 default. */
2561
2566
  function factoryPromptFor(key) {
@@ -2567,7 +2572,10 @@ window.__ModuleLoader__.load({
2567
2572
  /** Image data URLs accepted for a member avatar; anything else is ignored. */
2568
2573
  const MEMBER_AVATAR_PREFIXES = ['data:image/png;', 'data:image/jpeg;', 'data:image/webp;'];
2569
2574
  const MEMBER_AVATAR_FIELDS = { lead: 'avatarLead', hanlin: 'avatarHanlin', works: 'avatarWorks', dali: 'avatarDali', yushi: 'avatarYushi' };
2570
- let memberConfig = { names: new Map(), prompts: new Map(), modes: new Map(), models: new Map(), avatars: new Map() };
2575
+ // tongzheng has no portrait of its own. Settings and the panel both use the
2576
+ // existing neutral image, and the settings form stores no seventh avatar field.
2577
+ const MEMBER_EDITOR_KEYS = AVATAR_KEYS.filter((key) => key !== 'tongzheng');
2578
+ let memberConfig = { names: new Map(), prompts: new Map(), modes: new Map(), models: new Map(), avatars: new Map(), associationMode: false };
2571
2579
  let memberWriter = null;
2572
2580
  /** Host remote handle for the model catalog; null degrades the picker to text. */
2573
2581
  let memberRemote = null;
@@ -2587,9 +2595,17 @@ window.__ModuleLoader__.load({
2587
2595
  let cabinetSessions = null;
2588
2596
  const cabinetSessionsListeners = new Set();
2589
2597
  /**
2590
- * Retry cadence for public projection reads while a member is running.
2591
- * Ready snapshots can be cached by the host; this is not forced polling.
2592
- * The sessions service does not issue model requests.
2598
+ * Bounded retry/re-render cadence for member usage while somebody runs.
2599
+ *
2600
+ * `refreshProjections` is NOT a polling read: the client manager returns the
2601
+ * in-flight promise while a load runs and resolves immediately once that
2602
+ * session's projections are `ready`
2603
+ * (dsh-api-session-controller/lib/types/client/sessions/manager.js:268-272),
2604
+ * so one connection really reads a session once. Later changes arrive as
2605
+ * Host frames — `ctx.sessionProjections.onChanged` → control stream
2606
+ * (lib/types/control.js:9-19) — and land in the projection store the panel
2607
+ * already subscribes to. The 5s tick therefore only re-renders the elapsed
2608
+ * clock; it neither re-reads the store nor spends any model token.
2593
2609
  */
2594
2610
  const PROJECTION_REFRESH_MS = 5000;
2595
2611
  /**
@@ -2632,6 +2648,183 @@ window.__ModuleLoader__.load({
2632
2648
  return false;
2633
2649
  }
2634
2650
  }
2651
+ /**
2652
+ * Group-chat read channel. `ctx.sessions.retain` takes the official
2653
+ * signature — `retain(<SessionId string>, { source: 'cabinetGroupChat' })`
2654
+ * (contract/sessions.d.ts:52, SessionTarget at :20; the manager resolves
2655
+ * `target.childSessionId`, manager.js:63-66, so a `{sessionId}` wrapper
2656
+ * would silently retain `undefined`). The reference carries a `binding`
2657
+ * getter (throws after release, service.js:94-115), a cancellable `ready`
2658
+ * and a once-only `release()` (service.js:126-134). References live only
2659
+ * while the 群聊 tab is active, so every retain pairs with exactly one
2660
+ * release — tab switch, roster member removal, service loss, unmount.
2661
+ */
2662
+ const CABINET_GROUP_SOURCE = 'cabinetGroupChat';
2663
+ // A member whose session offers no event channel at all still owns a row:
2664
+ // the sentinel is translated at render time, where `t` is available.
2665
+ const GROUP_UNAVAILABLE = 'cabinet-groupchat:unavailable';
2666
+ // Panel view tabs, in display order. The five settings tabs
2667
+ // (SETTINGS_TABS) live in the settings section and are untouched.
2668
+ const PANEL_TABS = ['groupchat', 'roster'];
2669
+ /** One readable text slice of a message's content blocks. */
2670
+ function groupChatText(content) {
2671
+ if (!Array.isArray(content)) return '';
2672
+ const parts = [];
2673
+ for (const block of content) {
2674
+ if (block && typeof block === 'object' && typeof block.text === 'string') parts.push(block.text);
2675
+ }
2676
+ return parts.join('\n');
2677
+ }
2678
+ /** tool/call and tool/result pair by `toolCallId`/`callId`, never by position. */
2679
+ function toolResultCallId(data) {
2680
+ const message = data && typeof data === 'object' ? data.message : undefined;
2681
+ return message && typeof message === 'object' && typeof message.toolCallId === 'string' ? message.toolCallId : null;
2682
+ }
2683
+ function toolCallIdOf(data) {
2684
+ return data && typeof data === 'object' && typeof data.callId === 'string' ? data.callId : null;
2685
+ }
2686
+ /** Fold one member's event window into messages + a running text delta. */
2687
+ function groupChatFold(entries) {
2688
+ const messages = [];
2689
+ const openCalls = new Map();
2690
+ const resultOrder = new Map();
2691
+ const live = { byAttempt: new Map() };
2692
+ const push = (message) => {
2693
+ if (message.time === undefined) return;
2694
+ messages.push(message);
2695
+ return message;
2696
+ };
2697
+ for (const entry of Array.isArray(entries) ? entries : []) {
2698
+ if (!entry || typeof entry !== 'object') continue;
2699
+ const event = entry.event;
2700
+ if (!event || typeof event !== 'object') continue;
2701
+ const type = event.type;
2702
+ const data = event && typeof event.data === 'object' && event.data !== null ? event.data : {};
2703
+ if (entry.type === 'transient' || type === 'assistant/live-chunk') {
2704
+ // Transient frames are presentation-only; only a text-delta
2705
+ // has readable text (dsh-llm types.d.ts:434-460).
2706
+ const chunk = data.chunk;
2707
+ if (chunk && chunk.type === 'text-delta' && typeof chunk.text === 'string' && typeof data.attemptId === 'string') {
2708
+ const current = live.byAttempt.get(data.attemptId);
2709
+ if (current === undefined) {
2710
+ live.byAttempt.set(data.attemptId, { time: event.time, seq: typeof event.seq === 'number' ? event.seq : Number.MAX_SAFE_INTEGER, text: chunk.text, turn: data.turn, step: data.step });
2711
+ } else {
2712
+ current.text += chunk.text;
2713
+ if (typeof event.seq === 'number' && event.seq > current.seq) current.seq = event.seq;
2714
+ }
2715
+ }
2716
+ continue;
2717
+ }
2718
+ if (type === 'assistant/message') {
2719
+ const message = data.message;
2720
+ if (!message || typeof message !== 'object') continue;
2721
+ // A settled message supersedes its own live suffix.
2722
+ if (typeof data.attemptId === 'string') live.byAttempt.delete(data.attemptId);
2723
+ // Official settlements identify the stream by turn/step, not attemptId.
2724
+ for (const [id, delta] of live.byAttempt) {
2725
+ if (data.turn !== undefined && data.step !== undefined && delta.turn === data.turn && delta.step === data.step) live.byAttempt.delete(id);
2726
+ }
2727
+ const text = groupChatText(message.content);
2728
+ if (text === '') continue;
2729
+ push({ kind: 'assistant', time: event.time, seq: event.seq, text, tools: [] });
2730
+ continue;
2731
+ }
2732
+ if (type === 'user/message') {
2733
+ const message = data;
2734
+ if (!message || typeof message !== 'object') continue;
2735
+ const text = groupChatText(message.content);
2736
+ if (text === '') continue;
2737
+ push({ kind: 'user', time: event.time, seq: event.seq, text, tools: [] });
2738
+ continue;
2739
+ }
2740
+ if (type === 'tool/call') {
2741
+ const id = toolCallIdOf(data);
2742
+ if (id !== null && !openCalls.has(id)) {
2743
+ openCalls.set(id, {
2744
+ callId: id,
2745
+ name: typeof data.name === 'string' && data.name !== '' ? data.name : 'tool',
2746
+ args: typeof data.arguments === 'string' ? data.arguments : '',
2747
+ time: event.time,
2748
+ seq: event.seq,
2749
+ text: ''
2750
+ });
2751
+ }
2752
+ continue;
2753
+ }
2754
+ if (type === 'tool/result') {
2755
+ const id = toolResultCallId(data);
2756
+ if (id === null) continue;
2757
+ const call = openCalls.get(id);
2758
+ if (call === undefined || call.text === '') {
2759
+ // First settle wins; later retries for one callId keep the
2760
+ // first fold so parallel same-name calls cannot double-count.
2761
+ resultOrder.set(id, { callId: id, time: event.time, seq: event.seq, text: groupChatText(data.message && typeof data.message === 'object' ? data.message.content : undefined) });
2762
+ if (call !== undefined) call.text = resultOrder.get(id).text;
2763
+ }
2764
+ continue;
2765
+ }
2766
+ }
2767
+ for (const [id, record] of resultOrder) {
2768
+ const call = openCalls.get(id);
2769
+ if (call !== undefined && call.text === '') call.text = record.text;
2770
+ }
2771
+ const tools = Array.from(openCalls.values()).sort((a, b) => a.seq - b.seq || a.time - b.time || a.callId.localeCompare(b.callId));
2772
+ const rows = [];
2773
+ for (const [attemptId, delta] of live.byAttempt) {
2774
+ rows.push({ kind: 'live', attemptId, time: delta.time, seq: delta.seq, text: delta.text, tools: [] });
2775
+ }
2776
+ // Each call belongs to the latest assistant in this user turn, once.
2777
+ const bySeq = messages.slice().sort((a, b) => a.seq - b.seq);
2778
+ let cursor = 0, owner;
2779
+ for (const tool of tools) {
2780
+ while (cursor < bySeq.length && bySeq[cursor].seq <= tool.seq) {
2781
+ const message = bySeq[cursor++];
2782
+ owner = message.kind === 'assistant' ? message : undefined;
2783
+ }
2784
+ if (owner !== undefined) owner.tools.push(tool);
2785
+ }
2786
+ rows.push(...messages);
2787
+ const attached = new Set();
2788
+ for (const row of rows) for (const tool of Array.isArray(row.tools) ? row.tools : []) attached.add(tool.callId);
2789
+ const leftovers = tools.filter((tool) => !attached.has(tool.callId));
2790
+ if (leftovers.length > 0) {
2791
+ const anchor = rows.reduce((last, row) => (row.time > last ? row.time : last), -Infinity);
2792
+ rows.push({ kind: 'tools', time: Number.isFinite(anchor) ? anchor : 0, seq: Number.MAX_SAFE_INTEGER, text: '', tools: leftovers });
2793
+ }
2794
+ // Assistant/user/tool rows merge into one time-ordered view. A settled
2795
+ // message is written after its own transient suffixes, so a live delta
2796
+ // that carries the same seq always sorts before its settlement.
2797
+ rows.sort((a, b) => (a.time - b.time) || (a.seq - b.seq) || (a.kind === 'live' ? -1 : b.kind === 'live' ? 1 : 0) || String(a.attemptId || '').localeCompare(String(b.attemptId || '')));
2798
+ return { rows, liveText: Array.from(live.byAttempt.values()).reduce((text, delta) => text + (text === '' ? '' : '\n') + delta.text, '') };
2799
+ }
2800
+ /**
2801
+ * Merge member folds into one view. `index` is the roster position of the
2802
+ * fold, so equal timestamps keep roster order and a member's own window
2803
+ * order survives (Array#sort is stable).
2804
+ */
2805
+ function mergeGroupChat(messages) {
2806
+ return (Array.isArray(messages) ? messages : []).map((message, index) => ({ message, index }))
2807
+ .sort((a, b) => (a.message.time - b.message.time) || (a.message.seq - b.message.seq) || (a.index - b.index))
2808
+ .map((entry) => entry.message);
2809
+ }
2810
+ /**
2811
+ * Retain + subscribe one member's session while the 群聊 tab is active.
2812
+ * The retain call is wrapped so the first argument can only ever be the
2813
+ * member id string: a wrapper object would reach the manager as
2814
+ * `target.childSessionId === undefined` and quietly retain the wrong
2815
+ * identity (manager.js:63-66). Every failure — no service, a missing
2816
+ * `retain`, a throwing `retain`, a rejected `ready`, a source without
2817
+ * `subscribe` — degrades that one member to `{ error }`, never to an
2818
+ * exception in the panel.
2819
+ */
2820
+ function cabinetGroupRetain(id) {
2821
+ const service = cabinetSessions;
2822
+ if (!service || typeof service.retain !== 'function') throw new Error('cabinet-groupchat: sessions service unavailable');
2823
+ if (typeof id !== 'string' || id === '') throw new Error('cabinet-groupchat: member id must be a session id string');
2824
+ const reference = service.retain(id, { source: CABINET_GROUP_SOURCE });
2825
+ if (!reference || typeof reference.release !== 'function' || typeof reference.ready !== 'object' || reference.ready === null) throw new Error('cabinet-groupchat: retain returned no SessionReference');
2826
+ return reference;
2827
+ }
2635
2828
  const MEMBER_LISTENERS = new Set();
2636
2829
  let memberT = (key) => key;
2637
2830
  function clampMemberText(value, limit) {
@@ -2682,6 +2875,7 @@ window.__ModuleLoader__.load({
2682
2875
  const modes = new Map();
2683
2876
  const models = new Map();
2684
2877
  const avatars = new Map();
2878
+ const associationMode = raw !== null && typeof raw === 'object' && raw.associationMode === true;
2685
2879
  const members = raw !== null && typeof raw === 'object' && Array.isArray(raw.members) ? raw.members : [];
2686
2880
  for (const entry of members) {
2687
2881
  if (entry === null || typeof entry !== 'object') continue;
@@ -2700,7 +2894,12 @@ window.__ModuleLoader__.load({
2700
2894
  const url = value.trim();
2701
2895
  if (url.length <= 48 * 1024 && /^data:image\/(?:png|jpeg|webp);base64,(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(url) && url.length > url.indexOf(',') + 1) avatars.set(key, url);
2702
2896
  }
2703
- return { names, prompts, modes, models, avatars };
2897
+ return { names, prompts, modes, models, avatars, associationMode };
2898
+ }
2899
+ /** Live switch text. The same two sentences are used by the panel banner. */
2900
+ function associationLine(enabled) {
2901
+ if (enabled !== true) return '';
2902
+ return '联想模式开启:可为已确认的命中派活通政使;其正文进入上下文会多用 token,不要编造增量。';
2704
2903
  }
2705
2904
  function setMemberConfig(raw) {
2706
2905
  memberConfig = normalizeMemberConfig(raw);
@@ -2977,9 +3176,10 @@ window.__ModuleLoader__.load({
2977
3176
  });
2978
3177
  }
2979
3178
 
2980
- function Chip({ color, children, title }) {
3179
+ function Chip({ color, children, title, onClick }) {
2981
3180
  return h('span', {
2982
3181
  title,
3182
+ onClick,
2983
3183
  style: {
2984
3184
  display: 'inline-flex',
2985
3185
  alignItems: 'center',
@@ -3125,7 +3325,7 @@ window.__ModuleLoader__.load({
3125
3325
  * optional: a missing projection yields undefined (the card prints its dash),
3126
3326
  * and a missing contextWindow keeps the token numbers but drops the ratio.
3127
3327
  */
3128
- function usageFor(values, now) {
3328
+ function usageFor(values, now, running) {
3129
3329
  const source = values !== undefined && values !== null && typeof values === 'object' ? values : {};
3130
3330
  const tokens = tokenTotalOf(source.tokenUsage?.totals ?? source.tokenUsage);
3131
3331
  let elapsedMs;
@@ -3134,8 +3334,14 @@ window.__ModuleLoader__.load({
3134
3334
  const settled = typeof timing.settledMs === 'number' && Number.isFinite(timing.settledMs) ? timing.settledMs : 0;
3135
3335
  const active = timing.active;
3136
3336
  if (active !== undefined && active !== null && typeof active.since === 'number' && Number.isFinite(active.since)) {
3337
+ // Native parity (subagent catalog): a running turn ends at "now", an
3338
+ // inactive one at `active.through` — otherwise an unclosed active
3339
+ // window keeps growing while nobody is working.
3137
3340
  const clock = typeof now === 'number' && Number.isFinite(now) ? now : active.since;
3138
- elapsedMs = settled + Math.max(0, clock - active.since);
3341
+ const end = running !== false
3342
+ ? clock
3343
+ : (typeof active.through === 'number' && Number.isFinite(active.through) ? active.through : active.since);
3344
+ elapsedMs = settled + Math.max(0, end - active.since);
3139
3345
  } else if (typeof timing.settledMs === 'number' && Number.isFinite(timing.settledMs)) {
3140
3346
  elapsedMs = settled;
3141
3347
  }
@@ -3307,6 +3513,22 @@ window.__ModuleLoader__.load({
3307
3513
  ]);
3308
3514
  }
3309
3515
 
3516
+ // Stored task-sheet body from TeamTaskView (`description`, `writeScopes`
3517
+ // on the agentTeam projection). Clamp by code point for the rail; never
3518
+ // invent a body when the field is missing or blank.
3519
+ const TASK_SHEET_CLAMP = 80;
3520
+ function taskDescriptionText(value) {
3521
+ if (typeof value !== 'string') return '';
3522
+ const text = value.trim();
3523
+ if (text === '') return '';
3524
+ const chars = [...text];
3525
+ return chars.length > TASK_SHEET_CLAMP ? chars.slice(0, TASK_SHEET_CLAMP).join('') + '…' : text;
3526
+ }
3527
+ function taskWriteScopeList(value) {
3528
+ if (!Array.isArray(value)) return [];
3529
+ return value.filter((scope) => typeof scope === 'string' && scope.trim() !== '');
3530
+ }
3531
+
3310
3532
  function TaskLine({ task, blockerOf, t, taskLabel, ownerRunning, onOpenOwner }) {
3311
3533
  const [openBlockers, setOpenBlockers] = React.useState(true);
3312
3534
  const status = TASK_COLOR[task.status] ? task.status : 'pending';
@@ -3350,10 +3572,31 @@ window.__ModuleLoader__.load({
3350
3572
  key: 'id',
3351
3573
  style: { fontSize: 10, color: INK3, fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace', flex: 'none' }
3352
3574
  }, task.id));
3575
+ const description = taskDescriptionText(task.description);
3576
+ const writeScopes = taskWriteScopeList(task.writeScopes);
3577
+ const sheetStyle = { display: 'flex', alignItems: 'baseline', gap: 4, flexWrap: 'wrap', width: '100%', paddingLeft: 14, fontSize: 11, color: INK2, minWidth: 0 };
3353
3578
  const children = [h('div', {
3354
3579
  key: 'line',
3355
3580
  style: { display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap', minWidth: 0, width: '100%' }
3356
- }, parts)];
3581
+ }, parts),
3582
+ h('div', { key: 'sheet', style: sheetStyle }, [
3583
+ h('span', { key: 'dl', style: { flex: 'none' } }, t('task.description')),
3584
+ h('span', {
3585
+ key: 'dv',
3586
+ 'data-cabinet-task-sheet': 'description',
3587
+ title: description !== '' ? task.description.trim() : undefined,
3588
+ style: { minWidth: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }
3589
+ }, description !== '' ? description : t('task.absent'))
3590
+ ]),
3591
+ h('div', { key: 'scopes', style: sheetStyle }, [
3592
+ h('span', { key: 'sl', style: { flex: 'none' } }, t('task.writeScopes')),
3593
+ h('span', {
3594
+ key: 'sv',
3595
+ 'data-cabinet-task-sheet': 'writeScopes',
3596
+ title: writeScopes.length > 0 ? writeScopes.join(', ') : undefined,
3597
+ style: { minWidth: 0, whiteSpace: 'pre-wrap', wordBreak: 'break-word' }
3598
+ }, writeScopes.length > 0 ? writeScopes.join(', ') : t('task.absent'))
3599
+ ])];
3357
3600
  if (blockers.length > 0) {
3358
3601
  children.push(h('div', {
3359
3602
  key: 'block',
@@ -3370,7 +3613,9 @@ window.__ModuleLoader__.load({
3370
3613
  ...(openBlockers ? blockers.map((id) => {
3371
3614
  const blocker = blockerOf(id);
3372
3615
  const c = blocker ? (TASK_COLOR[blocker.status] || TASK_COLOR.pending) : 'rgba(127,127,127,.5)';
3373
- return h(Chip, { key: id, color: c, title: blocker ? blocker.subject : id }, [
3616
+ // A blocker chip is information, not navigation: stop the click so
3617
+ // the task row's opener does not fire when a chip is clicked.
3618
+ return h(Chip, { key: id, color: c, title: blocker ? blocker.subject : id, onClick: (event) => stopPropagation(event) }, [
3374
3619
  h('span', { key: 'd', style: { width: 6, height: 6, borderRadius: '50%', background: c, flex: 'none' } }),
3375
3620
  h('span', { key: 't', style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, id)
3376
3621
  ]);
@@ -3688,7 +3933,131 @@ window.__ModuleLoader__.load({
3688
3933
  // #endregion connectors
3689
3934
 
3690
3935
  // ---------- the body ------------------------------------------------
3691
- function CabinetPanel({ sessionId, useSession, useSessions, useSessionStatus, t }) {
3936
+ // ---------- group chat: merged view of every member's session ----------
3937
+ /**
3938
+ * One folded view of one member session. `fold` is null until the first
3939
+ * `ready` settles; `error` marks the member 不可用 (single-channel failure
3940
+ * never throws into the panel).
3941
+ */
3942
+ function groupChatEmptyView() { return { fold: null, error: null, liveText: '' }; }
3943
+ /**
3944
+ * Retain + subscribe every roster member while the 群聊 tab is active.
3945
+ * Pairing is mechanical: whatever `cabinetGroupRetain` returned is
3946
+ * released exactly once — on tab switch, member removal, service loss,
3947
+ * panel unmount. A member that cannot be retained renders its own 不可用
3948
+ * row; the other members keep working.
3949
+ */
3950
+ function useCabinetGroupChat(members, activeTab, service) {
3951
+ const [, setRevision] = React.useState(0);
3952
+ const key = JSON.stringify(members.map((member) => member.id));
3953
+ // Keep one map across roster changes so the timer reads current records.
3954
+ const stateRef = React.useRef({ views: new Map(), records: new Map() });
3955
+ const state = stateRef.current;
3956
+ React.useEffect(() => {
3957
+ if (activeTab !== 'groupchat') return undefined;
3958
+ let disposed = false;
3959
+ const bump = () => { if (!disposed) setRevision((revision) => revision + 1); };
3960
+ const fail = (id, error) => {
3961
+ state.views.set(id, { fold: null, error: error?.message || String(error), liveText: '' });
3962
+ bump();
3963
+ };
3964
+ for (const member of members) {
3965
+ const id = member.id;
3966
+ if (typeof id !== 'string' || id === '' || state.records.has(id)) continue;
3967
+ let reference;
3968
+ try { reference = cabinetGroupRetain(id); }
3969
+ catch (error) { fail(id, error); continue; }
3970
+ const record = { reference, unsubscribe: null, sync: null };
3971
+ state.records.set(id, record);
3972
+ record.sync = () => {
3973
+ if (disposed) return;
3974
+ try {
3975
+ const channel = reference.binding.eventSource;
3976
+ if (!channel || typeof channel.getSnapshot !== 'function' || typeof channel.subscribe !== 'function') throw new Error(GROUP_UNAVAILABLE);
3977
+ if (record.unsubscribe === null) record.unsubscribe = channel.subscribe(record.sync);
3978
+ const fold = groupChatFold(channel.getSnapshot().entries);
3979
+ state.views.set(id, { fold, error: null, liveText: fold.liveText });
3980
+ bump();
3981
+ } catch (error) { fail(id, error); }
3982
+ };
3983
+ record.sync();
3984
+ Promise.resolve(reference.ready).then(() => record.sync(), (error) => {
3985
+ if (!disposed) fail(id, error);
3986
+ });
3987
+ }
3988
+ bump();
3989
+ return () => {
3990
+ disposed = true;
3991
+ for (const record of state.records.values()) {
3992
+ try { record.unsubscribe?.(); } catch (ignored) { /* source already gone */ }
3993
+ try { record.reference.release(); } catch (ignored) { /* service already gone */ }
3994
+ }
3995
+ state.records.clear();
3996
+ state.views.clear();
3997
+ };
3998
+ }, [activeTab, service, key]);
3999
+ return {
4000
+ views: (id) => state.views.get(id) || groupChatEmptyView(),
4001
+ members: () => Array.from(state.views.keys()),
4002
+ forceSync: () => { for (const record of state.records.values()) record.sync(); }
4003
+ };
4004
+ }
4005
+ /**
4006
+ * One chat line: officer portrait + officer name + body. Tools fold into
4007
+ * a single 「N 个工具」 row that expands in place — never one line per call.
4008
+ */
4009
+ function GroupChatRow({ row, member, t }) {
4010
+ const tt = typeof t === 'function' ? t : (key) => key;
4011
+ const [open, setOpen] = React.useState(false);
4012
+ // Avatar keys off the raw member id key ('lead', 'works', …); the
4013
+ // visible line shows the office label instead.
4014
+ const key = member && member.name ? member.name : (row.memberName || '');
4015
+ const name = key === '' ? '' : memberLabel(key);
4016
+ const live = row.kind === 'live';
4017
+ const header = h('div', {
4018
+ key: 'head',
4019
+ style: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0, flexWrap: 'wrap' }
4020
+ }, [
4021
+ h(Avatar, { key: 'avatar', name: key || 'neutral', size: 20, live: live }),
4022
+ h('span', { key: 'name', title: name, style: { fontSize: 12, fontWeight: 600, color: INK } }, name || tt('groupchat.unknown')),
4023
+ row.time ? h('span', { key: 'time', style: { fontSize: 10.5, color: INK3 } }, new Date(row.time).toLocaleTimeString()) : null
4024
+ ]);
4025
+ // A failed member reads 「不可用」 on the line (the spec's wording) while
4026
+ // the channel's own message stays reachable as the hover title.
4027
+ const failed = row.kind === 'error';
4028
+ const bodyNode = row.text === '' ? null : h('div', {
4029
+ key: 'text',
4030
+ 'data-cabinet-groupchat-text': '1',
4031
+ title: failed ? row.text : undefined,
4032
+ style: { fontSize: 12, color: live ? INK2 : INK, whiteSpace: 'pre-wrap', wordBreak: 'break-word', lineHeight: 1.55 }
4033
+ }, failed ? tt('groupchat.unavailable') : row.text);
4034
+ const tools = Array.isArray(row.tools) ? row.tools : [];
4035
+ const toolNode = tools.length === 0 ? null : h('div', { key: 'tools', style: { marginTop: 4 } }, [
4036
+ h('button', {
4037
+ key: 'toggle',
4038
+ type: 'button',
4039
+ 'data-cabinet-groupchat-tools': String(tools.length),
4040
+ 'aria-expanded': open ? 'true' : 'false',
4041
+ style: { font: 'inherit', fontSize: 11, cursor: 'pointer', padding: '2px 6px', borderRadius: 6, border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.4))', background: 'transparent', color: INK2 },
4042
+ onClick: () => setOpen((value) => !value)
4043
+ }, open ? tt('groupchat.tools.hide') : tt('groupchat.tools.count').replace('{n}', String(tools.length))),
4044
+ open ? h('ul', { key: 'list', style: { margin: '4px 0 0', paddingLeft: 18, fontSize: 11, color: INK2 } }, tools.map((tool, index) => h('li', {
4045
+ key: tool.callId || index,
4046
+ 'data-cabinet-groupchat-tool': '1',
4047
+ style: { wordBreak: 'break-word' }
4048
+ }, (tool.name || 'tool') + (tool.args === '' ? '' : ' ' + tool.args)))) : null
4049
+ ]);
4050
+ return h('div', {
4051
+ key: 'row',
4052
+ 'data-cabinet-groupchat-row': row.kind,
4053
+ 'data-cabinet-groupchat-error': row.kind === 'error' ? '1' : undefined,
4054
+ className: row.kind === 'error' ? 'cabinet-status-failed' : (live ? 'cabinet-row-live' : undefined),
4055
+ style: { display: 'flex', flexDirection: 'column', gap: 3, padding: '4px 0', minWidth: 0 }
4056
+ }, [header, bodyNode, toolNode]);
4057
+ }
4058
+ function CabinetPanel({ sessionId, useSession, useSessions, useSessionStatus, t, activeTab: activeTabProp }) {
4059
+ const [localTab, setActiveTab] = React.useState('roster');
4060
+ const activeTab = typeof activeTabProp === 'string' ? activeTabProp : localTab;
3692
4061
  // Re-render when the mirrored member settings change (names/avatars).
3693
4062
  const [, setMemberRevision] = React.useState(0);
3694
4063
  React.useEffect(() => subscribeMemberConfig(() => setMemberRevision((revision) => revision + 1)), []);
@@ -3808,7 +4177,7 @@ window.__ModuleLoader__.load({
3808
4177
  panel.removeEventListener('scroll', schedule);
3809
4178
  }
3810
4179
  };
3811
- }, [measureLinks, hasTeam]);
4180
+ }, [measureLinks, hasTeam, activeTab]);
3812
4181
 
3813
4182
  // Styles live in one shared <style id="dsh-cabinet-ui-styles"> mounted by
3814
4183
  // apply(); the panel itself renders no <style> element.
@@ -3819,6 +4188,40 @@ window.__ModuleLoader__.load({
3819
4188
  }, tt('team.stale')));
3820
4189
 
3821
4190
  const members = team?.members ?? [];
4191
+ // Lead-first roster order for the group chat view: the lead card sits
4192
+ // on top in the org chart, so its messages lead the merged stream.
4193
+ const orderedMembers = (() => {
4194
+ const leadMember = members.find((member) => member && member.role === 'lead');
4195
+ return leadMember === undefined ? members : [leadMember, ...members.filter((member) => member !== leadMember)];
4196
+ })();
4197
+ // Panel view tabs: 群聊 (merged member messages) and the roster view.
4198
+ // Hooks must run before any early return — an effect that is skipped
4199
+ // on one render and run on the next would desynchronise the retain/
4200
+ // release pairing this tab owns.
4201
+ // The roster stays the default view: every existing assertion and the
4202
+ // regression red lines (member cards, task board, edges) are read from
4203
+ // this pane. 群聊 is a sibling tab, added without displacing anything.
4204
+ // `activeTab` is an optional override the tab button supplies when it
4205
+ // switches (so one render carries the click); omitted means local state.
4206
+ // The sessions service arrives through the existing cabinetSessions
4207
+ // listeners (same channel as the usage cards) so a late injection or a
4208
+ // disposal re-runs the retain/release pairing below.
4209
+ const [groupService, setGroupService] = React.useState(cabinetSessions);
4210
+ React.useEffect(() => {
4211
+ const notify = () => setGroupService(cabinetSessions);
4212
+ cabinetSessionsListeners.add(notify); notify();
4213
+ return () => cabinetSessionsListeners.delete(notify);
4214
+ }, []);
4215
+ const group = useCabinetGroupChat(orderedMembers, activeTab, groupService);
4216
+ // The 5s usage tick also folds the newest event window while the tab is
4217
+ // open, so a settled message lands without waiting for the next frame.
4218
+ React.useEffect(() => {
4219
+ if (activeTab !== 'groupchat' || !groupService) return undefined;
4220
+ const timer = setInterval(() => group.forceSync(), PROJECTION_REFRESH_MS);
4221
+ return () => clearInterval(timer);
4222
+ }, [activeTab, groupService]);
4223
+ // The switch is a state word on the 通政使 row. Nothing is rendered when off:
4224
+ // no banner, no instruction sentence, no roster notice.
3822
4225
  const tasks = (team?.tasks ?? []).filter((task) => task.status !== 'deleted');
3823
4226
  const runningOf = (id) => (statusMap?.get?.(id)?.running ?? list?.byId?.[id]?.running) === true;
3824
4227
  const modelOf = (id) => projections?.[id]?.values?.modelSelection?.next?.model;
@@ -3864,13 +4267,24 @@ window.__ModuleLoader__.load({
3864
4267
  const lead = members.find((member) => member.role === 'lead');
3865
4268
  const leadShown = lead ?? { id: sessionId, name: 'lead', role: 'lead', phase: 'active' };
3866
4269
  const mates = members.filter((member) => member.role !== 'lead');
3867
- // Usage hooks stay above the empty-team return. Ensure initial/settled
3868
- // projections, retry live sessions at a bounded cadence, and consume
3869
- // host updates via useSessions. Ready host snapshots may remain cached.
4270
+ // Usage hooks stay above the empty-team return.
4271
+ //
4272
+ // The numbers move because the Host pushes projection frames
4273
+ // (`sessionProjections.onChanged` → control stream, control.js:9-19) into
4274
+ // the store read by useSessions — NOT because this panel re-reads them:
4275
+ // `refreshProjections` really reads a session once and resolves without
4276
+ // reading once that load is `ready` (manager.js:268-272). What is left for
4277
+ // this panel is (a) one ensure call per member the first time we see it,
4278
+ // (b) a bounded retry for a session that never loaded or just changed
4279
+ // state, and (c) a 5s re-render so the elapsed clock advances.
3870
4280
  const [usageTick, setUsageTick] = React.useState(0);
3871
4281
  const usageNow = Date.now();
3872
4282
  const usageOfMember = (member) => (member !== undefined && member !== null && typeof member.id === 'string' && member.id !== '')
3873
- ? usageFor(projections !== undefined && projections !== null ? projections[member.id]?.values : undefined, usageNow)
4283
+ ? usageFor(
4284
+ projections !== undefined && projections !== null ? projections[member.id]?.values : undefined,
4285
+ usageNow,
4286
+ runningOf(member.id)
4287
+ )
3874
4288
  : null;
3875
4289
  const leadUsage = usageOfMember(leadShown);
3876
4290
  const mateUsages = mates.map((member) => usageOfMember(member));
@@ -3905,8 +4319,9 @@ window.__ModuleLoader__.load({
3905
4319
  if (!due) continue;
3906
4320
  const record = {live, at: Date.now(), pending: true};
3907
4321
  states.set(id, record);
3908
- // Public refresh is ensure/retry: ready snapshots may be cached by
3909
- // the host. Live updates arrive through useSessions, not forced RPCs.
4322
+ // Ensure/retry only: the first call per member really reads; a `ready`
4323
+ // session resolves without reading, so this is not a re-read loop.
4324
+ // Live updates arrive through useSessions (host push frames).
3910
4325
  try { Promise.resolve(usageService.refreshProjections(id)).catch(() => {}).finally(() => { record.pending = false; if (record.retry && !states.disposed) { states.delete(id); setUsageTick(tick => tick + 1); } }); }
3911
4326
  catch (_) { record.pending = false; }
3912
4327
  }
@@ -3918,7 +4333,70 @@ window.__ModuleLoader__.load({
3918
4333
  const timer = setInterval(() => setUsageTick((tick) => tick + 1), PROJECTION_REFRESH_MS);
3919
4334
  return () => { clearInterval(timer); };
3920
4335
  }, [usageService, runningUsageKey]);
4336
+ // The first paint has no fold yet; a live delta is shown from the
4337
+ // service's current window instead (settle rows replace it at commit).
4338
+ const liveText = orderedMembers.map((member) => group.views(member.id).liveText)
4339
+ .filter((text) => text !== '').join('\n');
4340
+ // Each folded row keeps the member it came from: the row itself only
4341
+ // carries {kind,time,seq,text,tools}, so the portrait and the office
4342
+ // name would otherwise have nothing to resolve against.
4343
+ const groupRows = mergeGroupChat(orderedMembers.flatMap((member) => {
4344
+ const view = group.views(member.id);
4345
+ return view.fold === null ? [] : view.fold.rows.map((row) => ({ ...row, member }));
4346
+ }));
4347
+
3921
4348
 
4349
+ // A member without a live view (retain failed, or the window has not
4350
+ // settled yet) still needs its row: 不可用 when the channel failed,
4351
+ // an empty state otherwise.
4352
+ for (const id of group.members()) {
4353
+ if (orderedMembers.some((member) => member && member.id === id)) continue;
4354
+ const view = group.views(id);
4355
+ if (view.fold === null && view.error !== null) groupRows.push({ kind: 'error', time: 0, seq: 0, text: view.error, tools: [], memberName: id });
4356
+ }
4357
+ for (const member of orderedMembers) {
4358
+ if (member === undefined || member === null || typeof member.id !== 'string' || member.id === '') continue;
4359
+ const view = group.views(member.id);
4360
+ if (view.fold !== null || view.error === null) continue;
4361
+ groupRows.push({ kind: 'error', time: 0, seq: 0, text: view.error === GROUP_UNAVAILABLE ? tt('groupchat.unavailable') : view.error, tools: [], memberName: member.name || member.id });
4362
+ }
4363
+ // Stable time merge: a member's rows keep their window order, equal
4364
+ // timestamps keep roster order, and the 不可用 rows join last.
4365
+ groupRows.sort((a, b) => Number(a.kind === 'error') - Number(b.kind === 'error') || (a.time - b.time) || (a.seq - b.seq));
4366
+ body.push(h('div', {
4367
+ key: 'tabs',
4368
+ role: 'tablist',
4369
+ 'data-cabinet-panel-tabs': '1',
4370
+ style: { display: 'flex', gap: 6, marginTop: 12, marginBottom: 8, flexWrap: 'wrap' }
4371
+ }, PANEL_TABS.map((id) => h('button', {
4372
+ key: id,
4373
+ type: 'button',
4374
+ role: 'tab',
4375
+ 'aria-selected': activeTab === id,
4376
+ 'data-cabinet-panel-tab': id,
4377
+ 'data-cabinet-panel-active': activeTab === id ? '1' : '0',
4378
+ style: { fontSize: 11, cursor: 'pointer', padding: '3px 8px', borderRadius: 6, border: '1px solid var(--dsw-alias-border-l3, rgba(127,127,127,.4))', background: activeTab === id ? 'rgba(79,140,255,.16)' : 'transparent', color: activeTab === id ? INK : INK2 },
4379
+ onClick: () => setActiveTab(id)
4380
+ }, tt('panel.tab.' + id)))));
4381
+ if (activeTab === 'groupchat') {
4382
+ const rows = groupRows.length > 0 ? groupRows : (liveText === '' ? [] : [{ kind: 'live', time: 0, seq: 0, text: liveText, tools: [] }]);
4383
+ body.push(h('div', {
4384
+ key: 'groupchat',
4385
+ role: 'tabpanel',
4386
+ 'data-cabinet-groupchat': '1',
4387
+ style: { display: 'flex', flexDirection: 'column', gap: 8 }
4388
+ }, [
4389
+ rows.length === 0
4390
+ ? h('div', { key: 'empty', 'data-cabinet-groupchat-empty': '1', style: { fontSize: 12, color: INK2, lineHeight: 1.6 } }, tt('groupchat.empty'))
4391
+ : rows.map((row) => h(GroupChatRow, {
4392
+ key: JSON.stringify([row.member?.id || row.memberName, row.kind, row.attemptId || row.seq]),
4393
+ row,
4394
+ member: row.member || memberByName.get(row.memberName),
4395
+ t: tt
4396
+ }))
4397
+ ]));
4398
+ return h('div', { ref: panelRef, style: PANEL }, body);
4399
+ }
3922
4400
  if (!team) {
3923
4401
  body.push(h('div', {
3924
4402
  key: 'empty',
@@ -3980,7 +4458,7 @@ window.__ModuleLoader__.load({
3980
4458
  t: tt,
3981
4459
  onOpen: openMemberSession,
3982
4460
  usage: leadUsage,
3983
- teamUsage: teamUsageOf(mateUsages)
4461
+ teamUsage: teamUsageOf([leadUsage, ...mateUsages])
3984
4462
  });
3985
4463
 
3986
4464
  // Cells: every minister first, then 未分派 / 首辅自办 / 不在册 as
@@ -4103,12 +4581,13 @@ window.__ModuleLoader__.load({
4103
4581
  const MEMBER_SECTION_FIELDS = AVATAR_KEYS;
4104
4582
 
4105
4583
  function memberAvatarOf(key, overrides) {
4584
+ if (key === 'tongzheng') return AVATARS.neutral;
4106
4585
  return overrides ? (overrides[key] || AVATARS[key]) : (memberConfig.avatars.get(key) || AVATARS[key]);
4107
4586
  }
4108
4587
 
4109
4588
  function createMemberEditor(form, notify) {
4110
4589
  let active = true, epoch = 0, uploads = {};
4111
- const state = { draft: emptyMemberDraft(), avatars: {}, errors: {}, ready: false, dirty: false, busy: false, conflict: false, revision: undefined, status: '' };
4590
+ const state = { draft: emptyMemberDraft(), avatars: {}, errors: {}, associationMode: false, ready: false, dirty: false, busy: false, conflict: false, revision: undefined, status: '' };
4112
4591
  const emit = () => { if (active) notify(); };
4113
4592
  const ready = s => s?.status === 'ready' && s.value !== undefined && s.writable === true && s.revision !== undefined;
4114
4593
  const adopt = s => {
@@ -4117,8 +4596,9 @@ window.__ModuleLoader__.load({
4117
4596
  state.draft = emptyMemberDraft(); state.avatars = {}; state.errors = {};
4118
4597
  for (const key of AVATAR_KEYS) {
4119
4598
  state.draft[key] = { name: config.names.get(key) || '', prompt: config.prompts.get(key) || '', mode: config.modes.get(key) || '', model: config.models.get(key) || '' };
4120
- state.avatars[key] = config.avatars.get(key) || '';
4599
+ state.avatars[key] = key === 'tongzheng' ? '' : (config.avatars.get(key) || '');
4121
4600
  }
4601
+ state.associationMode = config.associationMode === true;
4122
4602
  state.revision = s?.revision; state.ready = ready(s); state.dirty = false; state.conflict = false;
4123
4603
  };
4124
4604
  const sync = () => {
@@ -4136,6 +4616,7 @@ window.__ModuleLoader__.load({
4136
4616
  state,
4137
4617
  connect() { active = true; sync(); unsubscribe = form?.subscribe(sync); return () => { active = false; epoch++; unsubscribe?.(); }; },
4138
4618
  update(key, patch) { if (!editable()) return; state.draft = { ...state.draft, [key]: { ...state.draft[key], ...patch } }; changed(); },
4619
+ association(enabled) { if (!editable()) return; state.associationMode = enabled === true; changed(); },
4139
4620
  avatar(key, url) { if (!editable()) return; uploads[key] = (uploads[key] || 0) + 1; state.avatars = { ...state.avatars, [key]: url }; changed(); },
4140
4621
  async upload(key, file) {
4141
4622
  if (!editable() || !file) return;
@@ -4149,6 +4630,7 @@ window.__ModuleLoader__.load({
4149
4630
  if (!editable()) return;
4150
4631
  epoch++; uploads = {};
4151
4632
  const keys = key ? [key] : AVATAR_KEYS;
4633
+ if (!key || key === 'tongzheng') state.associationMode = false;
4152
4634
  for (const k of keys) { state.draft[k] = { name: '', prompt: '', mode: '', model: '' }; state.avatars[k] = ''; }
4153
4635
  state.draft = { ...state.draft }; state.avatars = { ...state.avatars }; state.errors = {}; changed();
4154
4636
  },
@@ -4162,8 +4644,11 @@ window.__ModuleLoader__.load({
4162
4644
  }
4163
4645
  const current = form.getSnapshot();
4164
4646
  if (!ready(current) || current.revision !== state.revision) { state.conflict = true; state.status = 'member.status.conflict'; emit(); return false; }
4165
- const ops = [{ op: 'set', path: ['members'], value: membersPayload(state.draft) }];
4166
- for (const key of AVATAR_KEYS) ops.push({ op: 'set', path: [MEMBER_AVATAR_FIELDS[key]], value: state.avatars[key] || '' });
4647
+ const ops = [
4648
+ { op: 'set', path: ['members'], value: membersPayload(state.draft) },
4649
+ { op: 'set', path: ['associationMode'], value: state.associationMode === true }
4650
+ ];
4651
+ for (const key of MEMBER_EDITOR_KEYS) ops.push({ op: 'set', path: [MEMBER_AVATAR_FIELDS[key]], value: state.avatars[key] || '' });
4167
4652
  epoch++; state.busy = true; emit();
4168
4653
  try {
4169
4654
  const ok = await form.mutate(ops, state.revision);
@@ -4488,11 +4973,12 @@ window.__ModuleLoader__.load({
4488
4973
  onClick: () => resetMember(key)
4489
4974
  }, t('member.reset'))
4490
4975
  ]),
4491
- activeTab === 'avatars' ? h('div', { key: 'builtin', style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap', marginBottom: 6 } }, [
4976
+ activeTab === 'avatars' && key === 'tongzheng' ? h('div', { key: 'neutral', style: { fontSize: 11, color: INK3, marginBottom: 6 } }, t('member.avatar.neutral')) : null,
4977
+ activeTab === 'avatars' && key !== 'tongzheng' ? h('div', { key: 'builtin', style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap', marginBottom: 6 } }, [
4492
4978
  h('span', { key: 'l', style: { fontSize: 11, color: INK3 } }, t('member.builtin')),
4493
4979
  ...(function () {
4494
4980
  const out = [];
4495
- for (const other of AVATAR_KEYS) {
4981
+ for (const other of MEMBER_EDITOR_KEYS) {
4496
4982
  out.push(h('button', {
4497
4983
  key: 'b-' + other,
4498
4984
  type: 'button',
@@ -4573,7 +5059,21 @@ window.__ModuleLoader__.load({
4573
5059
  update(key, { prompt: value, mode }, false);
4574
5060
  }
4575
5061
  }),
4576
- key === 'lead' ? h('div', { key: 'hint', style: { fontSize: 11, color: INK3, marginTop: 4 } }, t('member.lead.hint')) : null
5062
+ key === 'lead' ? h('div', { key: 'hint', style: { fontSize: 11, color: INK3, marginTop: 4 } }, t('member.lead.hint')) : null,
5063
+ key === 'tongzheng' ? h('label', {
5064
+ key: 'association',
5065
+ style: { display: 'flex', alignItems: 'center', gap: 6, marginTop: 8, fontSize: 12, color: INK }
5066
+ }, [
5067
+ h('input', {
5068
+ key: 'switch',
5069
+ type: 'checkbox',
5070
+ checked: editor.state.associationMode === true,
5071
+ 'data-cabinet-association-switch': '1',
5072
+ onChange: (event) => editor.association(event?.target?.checked === true)
5073
+ }),
5074
+ h('span', { key: 'label' }, t('member.association')),
5075
+ h('span', { key: 'help', style: { fontSize: 11, color: INK3 } }, t('member.association.hint'))
5076
+ ]) : null
4577
5077
  ] : null
4578
5078
  ]);
4579
5079
  });
@@ -4641,28 +5141,42 @@ window.__ModuleLoader__.load({
4641
5141
  'usage.tokens': 'token',
4642
5142
  'usage.elapsed': '耗时',
4643
5143
  'usage.context': '上下文',
4644
- 'usage.team': '团队',
5144
+ 'usage.team': '团队合计(含首辅)',
4645
5145
  'usage.none': '—',
4646
5146
  'task.leadOwn': '首辅自办',
4647
5147
  'task.waits': '等待',
4648
5148
  'task.none': '暂无任务',
5149
+ 'task.description': '任务书',
5150
+ 'task.writeScopes': '写入范围',
5151
+ 'task.absent': '未记载',
4649
5152
  'legend': '任务状态',
4650
- 'empty.hint': '尚无内阁数据:请在已建团队板的首辅会话中打开本页。'
5153
+ 'empty.hint': '尚无内阁数据:请在已建团队板的首辅会话中打开本页。',
5154
+ 'panel.tab.groupchat': '群聊',
5155
+ 'panel.tab.roster': '名册',
5156
+ 'groupchat.unavailable': '不可用',
5157
+ 'groupchat.empty': '暂无群聊消息:成员会话打开后,首辅与阁臣的消息会按时间合并显示在这里。',
5158
+ 'groupchat.unknown': '未知成员',
5159
+ 'groupchat.tools.count': '{n} 个工具',
5160
+ 'groupchat.tools.hide': '收起工具'
4651
5161
  ,
4652
5162
  'member.nav': '内阁成员',
4653
5163
  'member.title': '内阁成员',
4654
- 'member.desc': '五员的名字、头像与提示词。未配置时保持出厂行为;头像归一为 96×96 PNG,单张不超过 48KB。',
5164
+ 'member.desc': '六员的名字、头像与提示词。未配置时保持出厂行为;头像归一为 96×96 PNG,单张不超过 48KB。通政使使用中性头像。',
4655
5165
  'member.lead': '内阁首辅',
4656
5166
  'member.hanlin': '翰林院编修',
4657
5167
  'member.works': '工部尚书',
4658
5168
  'member.dali': '大理寺卿',
4659
5169
  'member.yushi': '左都御史',
5170
+ 'member.tongzheng': '通政使',
5171
+ 'member.association': '联想模式',
5172
+ 'member.association.hint': '开启会增加 token 用量',
4660
5173
  'member.name': '显示名(留空则用官职与原始 ID)',
4661
5174
  'member.name.unset': '未设置',
4662
5175
  'member.name.placeholder': '运行时名字',
4663
5176
  'member.prompt': '提示词',
4664
5177
  'member.prompt.placeholder': '留空则不注入该段',
4665
5178
  'member.builtin': '内置头像:',
5179
+ 'member.avatar.neutral': '通政使使用中性头像,不可更换。',
4666
5180
  'member.upload': '上传图片',
4667
5181
  'member.avatar.clear': '恢复内置',
4668
5182
  'member.reset': '恢复默认',
@@ -4734,28 +5248,42 @@ window.__ModuleLoader__.load({
4734
5248
  'usage.tokens': 'tokens',
4735
5249
  'usage.elapsed': 'elapsed',
4736
5250
  'usage.context': 'context',
4737
- 'usage.team': 'team',
5251
+ 'usage.team': 'team total (incl. lead)',
4738
5252
  'usage.none': '—',
4739
5253
  'task.leadOwn': 'lead-owned',
4740
5254
  'task.waits': 'blocked by',
4741
5255
  'task.none': 'no tasks',
5256
+ 'task.description': 'Task sheet',
5257
+ 'task.writeScopes': 'Write scope',
5258
+ 'task.absent': 'not recorded',
4742
5259
  'legend': 'Task status',
4743
- 'empty.hint': 'No cabinet data yet: open this tab from the Lead session that owns the team board.'
5260
+ 'empty.hint': 'No cabinet data yet: open this tab from the Lead session that owns the team board.',
5261
+ 'panel.tab.groupchat': 'Group chat',
5262
+ 'panel.tab.roster': 'Roster',
5263
+ 'groupchat.empty': 'No group chat messages yet: once member sessions open, Lead and minister messages merge here in time order.',
5264
+ 'groupchat.unavailable': 'Unavailable',
5265
+ 'groupchat.unknown': 'Unknown member',
5266
+ 'groupchat.tools.count': '{n} tools',
5267
+ 'groupchat.tools.hide': 'Hide tools'
4744
5268
  ,
4745
5269
  'member.nav': 'Cabinet members',
4746
5270
  'member.title': 'Cabinet members',
4747
- 'member.desc': 'Names, avatars and prompts for the five members. Unconfigured keeps the factory behaviour; avatars are normalized to 96×96 PNG, at most 48KB each.',
5271
+ 'member.desc': 'Names, avatars and prompts for the six members. Unconfigured keeps the factory behaviour; avatars are normalized to 96×96 PNG, at most 48KB each. The association minister uses the neutral portrait.',
4748
5272
  'member.lead': '内阁首辅',
4749
5273
  'member.hanlin': '翰林院编修',
4750
5274
  'member.works': '工部尚书',
4751
5275
  'member.dali': '大理寺卿',
4752
5276
  'member.yushi': '左都御史',
5277
+ 'member.tongzheng': '通政使',
5278
+ 'member.association': '联想模式',
5279
+ 'member.association.hint': '开启会增加 token 用量',
4753
5280
  'member.name': 'Display name (empty keeps office and original ID)',
4754
5281
  'member.name.unset': 'unset',
4755
5282
  'member.name.placeholder': 'runtime name',
4756
5283
  'member.prompt': 'Prompt',
4757
5284
  'member.prompt.placeholder': 'empty = inject nothing',
4758
5285
  'member.builtin': 'Built-in avatars:',
5286
+ 'member.avatar.neutral': 'The 通政使 keeps the neutral portrait; it cannot be changed.',
4759
5287
  'member.upload': 'Upload image',
4760
5288
  'member.avatar.clear': 'Use built-in',
4761
5289
  'member.reset': 'Restore default',