diff --git a/01_content/src/client/index.tsx b/01_content/src/client/index.tsx index 628c6d1..a531b64 100644 --- a/01_content/src/client/index.tsx +++ b/01_content/src/client/index.tsx @@ -550,6 +550,19 @@ function saveNotifyAck(sid: string, state: string) { localStorage.setItem('dsh.worktable.notifyAck.v1', JSON.stringify(ack)) } catch {} } +/** 每会话最近一次观察到的「需要判断」布尔值:状态转移时清除旧 ack(新一轮待决重新点亮) */ +const notifyStateSeenRef: { current: Record } = { current: {} } +/** 清除某会话的 ack 记录(状态转移时调用,保证新问题不会被旧确认压住) */ +function clearNotifyAck(sid: string) { + try { + const all = loadNotifyAck() + if (all[sid]) { + delete all[sid] + localStorage.setItem('dsh.worktable.notifyAck.v1', JSON.stringify(all)) + } + } catch {} +} + /** 会话状态 → 提醒类型:待决(黄) 优先于 完成(绿)——等待用户判断时 pendingInteraction 与 * running 会同时为真,原生 UI 以黄点优先,镜像必须一致 */ function sessionNotifyState(entry: any): 'done' | 'need' | null { @@ -1061,49 +1074,62 @@ function buildCustomLayoutPrompt(req: string): string { return kids }, []) - /** 项目 → 提醒态:绑定会话(含其子代理)completed=done / pendingInteraction=need(ack 过则不亮) */ + /** 项目 → 提醒态:绑定会话(含其子代理)待决(黄) > 完成(绿) > 工作中(蓝); + * 状态转移自动清除旧 ack——原生 UI 每个新问题都会重新亮黄,镜像不得被旧确认压住 */ const bindNotifyMap: Record = useMemo(() => { const map: Record = {} const byId = sessionsSnapshotStore.snapshot?.byId ?? {} const ack = loadNotifyAck() + const seen = notifyStateSeenRef.current for (const [pid, sid] of Object.entries(projects.bindings)) { const e = byId[sid] if (!e) continue - // 优先级:待决(黄)> 完成(绿)> 工作中(蓝)——与原生 UI 一致;ack 过的状态若仍在跑则落 busy - // ① 自身待决 - const state = sessionNotifyState(e) - if (state && ack[sid] !== state) { map[pid] = state; continue } - // ② 子代理待决 → 黄(用户在工作区看到的黄点常来自子代理,父会话自己仍是 running) - let childNeed = false - for (const cid of collectKids(sid)) { - const ce = byId[cid] - if (ce && sessionNotifyState(ce) === 'need' && ack[cid] !== 'need') { childNeed = true; break } + // 是否需要判断:自身列表字段 / 子代理 / 会话面兜底,三通道聚合 + let needNow = sessionNotifyState(e) === 'need' + if (!needNow) { + for (const cid of collectKids(sid)) { + const ce = byId[cid] + if (ce && sessionNotifyState(ce) === 'need') { needNow = true; break } + } } - if (childNeed) { map[pid] = 'need'; continue } - // ③ 会话面 pending 队列兜底(宿主列表不映射 pendingInteraction 时的保险) - try { - const face = sessionBridge?.sessions?.binding?.(sid)?.session?.getSnapshot?.() - if (Array.isArray(face?.pending) && face.pending.length > 0 && ack[sid] !== 'need') { map[pid] = 'need'; continue } - } catch {} + if (!needNow) { + try { + const face = sessionBridge?.sessions?.binding?.(sid)?.session?.getSnapshot?.() + if (Array.isArray(face?.pending) && face.pending.length > 0) needNow = true + } catch {} + } + // 状态转移 → 清除旧 ack(新一轮待决重新点亮) + if (needNow !== seen[sid]) { + if (seen[sid] !== undefined) clearNotifyAck(sid) + seen[sid] = needNow + } + if (needNow) { if (ack[sid] !== 'need') map[pid] = 'need'; continue } + if (sessionNotifyState(e) === 'done' && ack[sid] !== 'done') { map[pid] = 'done'; continue } if (e.running === true) map[pid] = 'busy' } return map }, [projects.bindings, notifyTick, collectKids]) - /** 点开项目 = 确认提醒:ack 当前会话及其子代理的待决状态,圆点恢复常态实心 */ + /** 点开项目 = 确认提醒:ack 当前会话(含子代理)的待决/完成状态,圆点恢复常态实心 */ const ackProjectNotify = (projectId: string) => { const sid = projectsRef.current.projects.bindings[projectId] if (!sid) return const byId = sessionsSnapshotStore.snapshot?.byId ?? {} - const state = sessionNotifyState(byId[sid]) - if (state) saveNotifyAck(sid, state) + let needNow = sessionNotifyState(byId[sid]) === 'need' for (const cid of collectKids(sid)) { - if (sessionNotifyState(byId[cid]) === 'need') saveNotifyAck(cid, 'need') + if (sessionNotifyState(byId[cid]) === 'need') { needNow = true; saveNotifyAck(cid, 'need') } + } + if (!needNow) { + try { + const face = sessionBridge?.sessions?.binding?.(sid)?.session?.getSnapshot?.() + if (Array.isArray(face?.pending) && face.pending.length > 0) needNow = true + } catch {} + } + if (needNow) saveNotifyAck(sid, 'need') + else { + const st = sessionNotifyState(byId[sid]) + if (st === 'done') saveNotifyAck(sid, 'done') } - try { - const face = sessionBridge?.sessions?.binding?.(sid)?.session?.getSnapshot?.() - if (Array.isArray(face?.pending) && face.pending.length > 0) saveNotifyAck(sid, 'need') - } catch {} } // ── 有效排序 ── diff --git a/02_process/worklogs/2026-08-16_worktable-v2.md b/02_process/worklogs/2026-08-16_worktable-v2.md index e9488fd..1f013b2 100644 --- a/02_process/worklogs/2026-08-16_worktable-v2.md +++ b/02_process/worklogs/2026-08-16_worktable-v2.md @@ -1016,6 +1016,20 @@ ERROR_COUNT: 0。 - 备注:纯客户端改动,F5 即生效。 +## 补记(修复:旧 ack 压住新一轮待决提示) + +- 用户反馈:健身记录绑定 FitnessWeb——对话新弹出一个需要判断的黄点,工作台卡片仍蓝色闪烁 + (助理机器人同病)。子代理聚合修复后依旧。 +- 根因:ack 记忆过黏——用户此前点开项目确认过待决(ack['need'] 持久化),此后同一状态值 + 的新问题被旧 ack 压制,落到 busy 蓝。原生 UI 是每个新问题都重新亮黄。 +- 修复:notifyStateSeenRef 跟踪每会话「needNow」布尔;状态转移(真↔假)时 clearNotifyAck + 清除旧 ack。第一轮黄 → 点项目确认 → 解决后(needNow 转假)ack 自动清 → 新一轮问题重新亮黄。 +- 验证(probe-repending.cjs,完整用户流程):firstPending=need → afterAck=true(ack=need) → + afterResolved=busy 且 ackAfterResolve=null → repending=need 黄 rgb(210,153,34) ✓; + functional-diag 全 20 STEP ERROR_COUNT: 0。 +- 备注:纯客户端改动,F5 即生效。 + + diff --git a/04_test/probe-repending.cjs b/04_test/probe-repending.cjs new file mode 100644 index 0000000..a7fca1e --- /dev/null +++ b/04_test/probe-repending.cjs @@ -0,0 +1,100 @@ +// probe-repending.cjs — 复现用户场景:旧 ack 压住新一轮待决 → 必须重新亮黄 +const http = require('http'); +const { spawn } = require('child_process'); +const WebSocket = require('ws'); +const PORT = 9364; +const proc = spawn('C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', [ + '--headless=new', '--disable-gpu', '--no-first-run', '--no-default-browser-check', + '--window-size=1440,900', '--force-device-scale-factor=1', + '--remote-debugging-port=' + PORT, + '--user-data-dir=C:\\Users\\SJL\\AppData\\Local\\Temp\\wt-chrome-repending', + 'about:blank', +], { stdio: 'ignore' }); +const getJSON = (p) => new Promise((res, rej) => { + http.get({ host: '127.0.0.1', port: PORT, path: p }, (r) => { let d=''; r.on('data',c=>d+=c); r.on('end',()=>{try{res(JSON.parse(d))}catch(e){rej(e)}}) }).on('error', rej); +}); +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +(async () => { + let list = null; + for (let i = 0; i < 40; i++) { try { list = await getJSON('/json/list'); if (list && list.length) break; } catch {} await sleep(500); } + const target = list.find((t) => t.type === 'page') || list[0]; + const ws = new WebSocket(target.webSocketDebuggerUrl); + let id = 0; const pending = new Map(); + const send = (method, params) => new Promise((res) => { const mid = ++id; pending.set(mid, res); ws.send(JSON.stringify({ id: mid, method, params })); }); + ws.on('message', (raw) => { const m = JSON.parse(String(raw)); if (m.id && pending.has(m.id)) { pending.get(m.id)(m); pending.delete(m.id); } }); + await new Promise((r) => ws.on('open', r)); + await send('Runtime.enable'); + await send('Page.enable'); + await send('Page.addScriptToEvaluateOnNewDocument', { + source: "try{ if(window===window.top && location.origin==='http://127.0.0.1:3080'){ localStorage.setItem('dsh.worktable.projects.v1', JSON.stringify({order:[],lastUsed:{},hidden:[],nameOverrides:{},shortcuts:[],layouts:[{id:'t-layout',title:'L',top:null,left:null,main:[{id:'p1',title:'W',min:200,content:null}],chatWidth:{default:320,min:240,max:600},chatSide:'right',chatFullHeight:false}],bindings:{},folders:{}})); localStorage.removeItem('dsh.worktable.notifyAck.v1'); } }catch(e){}", + }); + await send('Page.navigate', { url: 'http://127.0.0.1:3080/' }); + const evaluate = async (expr) => { + const r = await send('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true }); + if (r.result && r.result.exceptionDetails) return { __error: (r.result.exceptionDetails.exception || {}).description || r.result.exceptionDetails.text }; + return r.result && r.result.result ? r.result.result.value : undefined; + }; + let ready = null; + for (let i = 0; i < 30; i++) { await sleep(1000); ready = await evaluate("!!window.__dshWorktable && !!window.__dshSyncSessionScope"); if (ready === true) break; } + await sleep(1500); + const step = await evaluate(`(async function(){ + var out = {}; + var sleep = function(ms){ return new Promise(function(r){ setTimeout(r, ms); }); }; + var vis = function(sel){ return [].slice.call(document.querySelectorAll(sel)).find(function(el){ return (getComputedStyle(el).visibility!=='hidden'&&el.getBoundingClientRect().height>0); }); }; + try { + var S = window.__dshSessions; + var card = document.querySelector('.dsh-wt_layout'); + var bbtn = card.querySelector('.dsh-wt_bindBtn'); + bbtn.click(); + await sleep(900); + var items = [].slice.call(document.querySelectorAll('.dsh-wt_bindList .dsh-wt_selectItem')); + if (items[0]) { items[0].click(); } + await sleep(800); + var boundId = JSON.parse(localStorage.getItem('dsh.worktable.projects.v1')).bindings['t-layout']; + var listStore = S.list; + var orig = listStore.getSnapshot.bind(listStore); + var fake = function(patch){ return function(){ var s = orig(); var e = s.byId && s.byId[boundId]; if (e) { s.byId = Object.assign({}, s.byId); s.byId[boundId] = Object.assign({}, e, patch); } return s; }; }; + // 第一轮:待决出现 → 黄 + listStore.getSnapshot = fake({ pendingInteraction: 'question', running: true }); + window.__dshSyncSessionScope(); + await sleep(500); + var b1 = card.querySelector('.dsh-wt_bindBtn'); + out.firstPending = b1.getAttribute('data-bound'); + // 用户点开项目 → ack → 恢复常态(实心 true) + card.click(); + await sleep(900); + var b2 = card.querySelector('.dsh-wt_bindBtn'); + out.afterAck = b2.getAttribute('data-bound'); + out.ackStored = (JSON.parse(localStorage.getItem('dsh.worktable.notifyAck.v1')||'{}')[boundId]) || null; + // 用户在对话里回答了 → 待决消失,仍在运行 → 蓝 + listStore.getSnapshot = fake({ running: true }); + window.__dshSyncSessionScope(); + await sleep(500); + var b3 = card.querySelector('.dsh-wt_bindBtn'); + out.afterResolved = b3.getAttribute('data-bound'); + out.ackAfterResolve = (JSON.parse(localStorage.getItem('dsh.worktable.notifyAck.v1')||'{}')[boundId]) || null; + // 新一轮问题 → 必须重新亮黄(旧 ack 不得压住) + listStore.getSnapshot = fake({ pendingInteraction: 'question', running: true }); + window.__dshSyncSessionScope(); + await sleep(500); + var b4 = card.querySelector('.dsh-wt_bindBtn'); + out.repending = b4.getAttribute('data-bound'); + out.rependingColor = getComputedStyle(b4).color; + // 清理 + listStore.getSnapshot = orig; + st = window.__dshWorktable.splitStore; + st.close(); + await sleep(400); + bbtn = card.querySelector('.dsh-wt_bindBtn'); + bbtn.click(); + await sleep(900); + var unbind = vis('.dsh-wt_bindUnbind'); + if (unbind) { unbind.click(); } + await sleep(500); + localStorage.removeItem('dsh.worktable.notifyAck.v1'); + } catch(e) { out.err = String(e); } + return JSON.stringify(out); + })()`); + console.log('REPENDING:', JSON.stringify(step)); + ws.close(); proc.kill(); process.exit(0); +})().catch((e) => { console.error('FATAL', e && e.stack || e); try { proc.kill(); } catch {} process.exit(1); }); diff --git a/AGENTS.md b/AGENTS.md index 6c6e113..c688038 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -65,6 +65,8 @@ node --check lib/index.js collectKids(byId.parentId + subagentsByParent 双通道)聚合父会话及其子代理的 pending; 会话面 binding(id).session.getSnapshot().pending 非空也判 need(列表不映射时的兜底); ackProjectNotify 同步 ack 子代理。 + **ack 生命周期**:ack 只在「同一轮待决未解决」期间压制提醒;状态转移(needNow 真↔假)时 + clearNotifyAck 自动清除旧 ack——原生 UI 每个新问题都重新亮黄,镜像必须同样重新点亮。 ## 安装 / 重启