fix: aggregate subagent pending interactions when mirroring conversation state to project cards

This commit is contained in:
Aisland
2026-08-20 00:43:19 +08:00
parent 817db79638
commit 7a2e75acd9
8 changed files with 411 additions and 3 deletions
+41 -3
View File
@@ -1043,7 +1043,25 @@ function buildCustomLayoutPrompt(req: string): string {
return () => { sessionsSnapshotStore.listeners.delete(l) }
}, [])
/** 项目 → 提醒态:绑定会话 completed=done / pendingInteraction=need(ack 过则不亮) */
/** 收集某会话的子代理 id 集:byId 的 parentId 标注 + subagentsByParent 目录双通道 */
const collectKids = useCallback((sid: string): Set<string> => {
const kids = new Set<string>()
const snap = sessionsSnapshotStore.snapshot
const byId = snap?.byId ?? {}
for (const [cid, ce] of Object.entries<any>(byId)) {
if (ce?.parentId === sid) kids.add(cid)
}
const subMap = snap?.subagentsByParent ?? {}
const v = (subMap as any)[sid]
const arr = Array.isArray(v) ? v : (v?.entries ?? v?.items ?? [])
if (Array.isArray(arr)) arr.forEach((c: any) => {
const cid = c?.sessionId ?? c?.id
if (typeof cid === 'string') kids.add(cid)
})
return kids
}, [])
/** 项目 → 提醒态:绑定会话(含其子代理)completed=done / pendingInteraction=need(ack 过则不亮) */
const bindNotifyMap: Record<string, 'done' | 'need' | 'busy'> = useMemo(() => {
const map: Record<string, 'done' | 'need' | 'busy'> = {}
const byId = sessionsSnapshotStore.snapshot?.byId ?? {}
@@ -1052,20 +1070,40 @@ function buildCustomLayoutPrompt(req: string): string {
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 }
}
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 (e.running === true) map[pid] = 'busy'
}
return map
}, [projects.bindings, notifyTick])
}, [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)
for (const cid of collectKids(sid)) {
if (sessionNotifyState(byId[cid]) === 'need') saveNotifyAck(cid, 'need')
}
try {
const face = sessionBridge?.sessions?.binding?.(sid)?.session?.getSnapshot?.()
if (Array.isArray(face?.pending) && face.pending.length > 0) saveNotifyAck(sid, 'need')
} catch {}
}
// ── 有效排序 ──
@@ -1002,6 +1002,21 @@
全 20 STEP ERROR_COUNT: 0。
- 备注:纯客户端改动,F5 即生效。
## 补记(修复:待决状态挂在子代理上导致黄点镜像失效)
- 用户反馈:助理机器人项目在工作区是黄点(需要判断),工作台卡片仍显示蓝色工作态。
- 排查(dumpstate/findpending 探针):宿主快照 byId 的 pendingInteraction 只出现在真正待决的
会话条目上;「父会话 running + 子代理待决」场景下父条目没有该字段——用户在工作区看到的
黄点来自子代理行。
- 修复:bindNotifyMap 聚合父会话 + 其子代理(collectKids:byId.parentId 标注 + subagentsByParent
目录双通道)的 pendingInteraction → need;另加会话面 binding(id).session.getSnapshot().pending
非空兜底;ackProjectNotify 同步 ack 子代理待决。优先级不变:need > done > busy。
- 验证(probe-childpending.cjs):注入子代理 pendingInteraction=question + 父 running →
attr=need、黄 rgb(210,153,34) ✓(真实待决会话同样落 need);functional-diag 全 20 STEP
ERROR_COUNT: 0。
- 备注:纯客户端改动,F5 即生效。
+52
View File
@@ -0,0 +1,52 @@
// dumpstate-mini.cjs — 找出「待判断」在快照里的真实字段:dump 所有 running 会话的完整 byId 条目
const http = require('http');
const { spawn } = require('child_process');
const WebSocket = require('ws');
const PORT = 9359;
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-dumpstate',
'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.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.__dshSessions"); if (ready === true) break; }
await sleep(800);
const step = await evaluate(`(function(){
var snap = window.__dshSessions.list.getSnapshot();
var byId = snap.byId || {};
var out = { top: {}, entries: [] };
out.topKeys = Object.keys(snap);
Object.keys(byId).forEach(function(k){
var e = byId[k];
if (e.running === true || e.completed === true || e.pendingInteraction != null || e.blank === false && e.updatedAt > Date.now() - 3600000) {
out.entries.push({ id: k.slice(0, 14), title: (e.displayTitle||'').slice(0, 24), keys: Object.keys(e), running: e.running, completed: e.completed, pending: e.pendingInteraction != null ? JSON.stringify(e.pendingInteraction).slice(0, 60) : null, phase: e.phase, projection: e.projectionValues ? JSON.stringify(e.projectionValues).slice(0, 120) : null });
}
});
return JSON.stringify(out);
})()`);
console.log('DUMPSTATE:', JSON.stringify(step).slice(0, 3600));
ws.close(); proc.kill(); process.exit(0);
})().catch((e) => { console.error('FATAL', e && e.stack || e); try { proc.kill(); } catch {} process.exit(1); });
+57
View File
@@ -0,0 +1,57 @@
// findpending-mini.cjs — 找出当前 pendingInteraction 的会话及其父级关系
const http = require('http');
const { spawn } = require('child_process');
const WebSocket = require('ws');
const PORT = 9362;
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-findpending',
'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.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.__dshSessions"); if (ready === true) break; }
await sleep(800);
const step = await evaluate(`(function(){
var snap = window.__dshSessions.list.getSnapshot();
var byId = snap.byId || {};
var out = { pendings: [], subs: {} };
Object.keys(byId).forEach(function(k){
var e = byId[k];
if (e.pendingInteraction != null) {
out.pendings.push({ id: k.slice(0,14), title: (e.displayTitle||'').slice(0,24), parentId: e.parentId ? e.parentId.slice(0,14) : null, pending: JSON.stringify(e.pendingInteraction), running: e.running });
}
});
var subs = snap.subagentsByParent || {};
Object.keys(subs).forEach(function(pid){
var v = subs[pid];
var arr = Array.isArray(v) ? v : (v && (v.entries || v.items || []));
out.subs[pid.slice(0,14)] = (arr||[]).map(function(c){ return { id: (c.sessionId||c.id||'').slice(0,14), kind: c.kind, activity: c.activity }; });
});
return JSON.stringify(out);
})()`);
console.log('FINDPENDING:', JSON.stringify(step).slice(0, 2400));
ws.close(); proc.kill(); process.exit(0);
})().catch((e) => { console.error('FATAL', e && e.stack || e); try { proc.kill(); } catch {} process.exit(1); });
+72
View File
@@ -0,0 +1,72 @@
// pendinghunt-mini.cjs — 全面排查:subagentsByParent / jobsBySession / 全 byId / 搜索结果
const http = require('http');
const { spawn } = require('child_process');
const WebSocket = require('ws');
const PORT = 9361;
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-pendinghunt',
'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.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.__dshSessions"); if (ready === true) break; }
await sleep(800);
const step = await evaluate(`(async function(){
var out = {};
var S = window.__dshSessions;
var snap = S.list.getSnapshot();
var byId = snap.byId || {};
// 全部 byId 条目的字段并集
var keyUnion = {};
Object.keys(byId).forEach(function(k){ Object.keys(byId[k]).forEach(function(kk){ keyUnion[kk] = true; }); });
out.allKeys = Object.keys(keyUnion);
// 子代理目录
var subs = snap.subagentsByParent || {};
Object.keys(subs).forEach(function(pid){
var v = subs[pid];
var arr = Array.isArray(v) ? v : (v && (v.entries || v.items || []));
(arr||[]).forEach(function(c){
var cid = c && (c.sessionId || c.id);
var e = byId[cid];
out['sub_' + pid.slice(0,8)] = { child: cid ? cid.slice(0,12) : null, kind: c && c.kind, activity: c && c.activity, mode: c && c.mode, byIdEntry: e ? { keys: Object.keys(e), running: e.running } : null };
});
});
// jobs
var jobs = snap.jobsBySession || {};
Object.keys(jobs).forEach(function(k){
var j = jobs[k];
if (Array.isArray(j) && j.length) out['job_' + k.slice(0,8)] = j.map(function(x){ return { status: x.status, kind: x.kind }; });
});
// 搜索结果结构化
try {
var sr = await S.search('robot');
out.searchShape = JSON.stringify(sr).slice(0, 500);
} catch(e) { out.searchErr = String(e); }
return JSON.stringify(out);
})()`);
console.log('PENDINGHUNT:', JSON.stringify(step).slice(0, 3600));
ws.close(); proc.kill(); process.exit(0);
})().catch((e) => { console.error('FATAL', e && e.stack || e); try { proc.kill(); } catch {} process.exit(1); });
+93
View File
@@ -0,0 +1,93 @@
// probe-childpending.cjs — 子代理待决 → 项目卡必须黄;父 running 不压黄;face.pending 兜底
const http = require('http');
const { spawn } = require('child_process');
const WebSocket = require('ws');
const PORT = 9363;
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-childpending',
'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);
// 父会话 running:true + 注入子代理 child-1(parentId=父,pendingInteraction=question)
var fake = function(patch, extraChild){ 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); if (extraChild) { s.byId['child-1'] = Object.assign({}, e, extraChild); } } return s; }; };
listStore.getSnapshot = fake({ running: true }, { id: 'child-1', parentId: boundId, running: false, pendingInteraction: 'question', displayTitle: '子代理' });
window.__dshSyncSessionScope();
await sleep(600);
var btn = card.querySelector('.dsh-wt_bindBtn');
out.attrChildPending = btn.getAttribute('data-bound');
out.colorChildPending = getComputedStyle(btn).color;
// 子代理待决移除 → 父 running → busy
listStore.getSnapshot = fake({ running: true }, null);
window.__dshSyncSessionScope();
await sleep(600);
var btn2 = card.querySelector('.dsh-wt_bindBtn');
out.attrParentRunning = btn2.getAttribute('data-bound');
// face.pending 兜底:父列表无 pendingInteraction 但会话面 pending 队列非空 → 黄
var origBinding = S.binding.bind(S);
S.binding = function(sid){ var b = origBinding(sid); if (b && b.session && b.session.getSnapshot) { var og = b.session.getSnapshot.bind(b.session); b.session.getSnapshot = function(){ var s = og(); s.pending = [{ kind: 'question' }]; return s; }; } return b; };
listStore.getSnapshot = fake({ running: true }, null);
window.__dshSyncSessionScope();
await sleep(600);
var btn3 = card.querySelector('.dsh-wt_bindBtn');
out.attrFacePending = btn3.getAttribute('data-bound');
// 清理
listStore.getSnapshot = orig;
S.binding = origBinding;
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('CHILDPENDING:', 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); });
+77
View File
@@ -0,0 +1,77 @@
// sessionface-mini.cjs — 读 auto-robot 会话面的真实状态(binding.session.getSnapshot)+ 搜索 API
const http = require('http');
const { spawn } = require('child_process');
const WebSocket = require('ws');
const PORT = 9360;
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-sessionface',
'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.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.__dshSessions"); if (ready === true) break; }
await sleep(800);
const step = await evaluate(`(async function(){
var out = {};
var S = window.__dshSessions;
var snap = S.list.getSnapshot();
var byId = snap.byId || {};
var target = Object.keys(byId).find(function(k){ return (byId[k].displayTitle||'').indexOf('auto-robot') >= 0 || (byId[k].displayTitle||'').indexOf('助理') >= 0; });
out.targetId = target;
if (!target) { out.noTarget = true; return JSON.stringify(out); }
try {
var b = S.binding(target);
out.bindingKeys = b ? Object.keys(b) : null;
var sess = b && b.session;
out.hasSession = !!sess;
if (sess && typeof sess.getSnapshot === 'function') {
var ss = sess.getSnapshot();
out.snapKeys = ss ? Object.keys(ss) : null;
out.phase = ss ? ss.phase : null;
out.pendingInteraction = ss ? ss.pendingInteraction : null;
out.running = ss ? ss.running : null;
out.completed = ss ? ss.completed : null;
// 逐字段安全序列化(绕过 toJSON 代理)
var safe = {};
if (ss) Object.keys(ss).forEach(function(k){
var v = ss[k];
if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') safe[k] = v;
else if (v == null) safe[k] = null;
else if (typeof v === 'object') safe[k] = '[object ' + (Array.isArray(v) ? 'array len=' + v.length : 'obj keys=' + Object.keys(v).slice(0,8).join(',')) + ']';
});
out.safe = safe;
}
// 搜索 API 结果(服务端 summaries 可能带 pendingInteraction)
try {
var sr = await S.search('auto-robot');
out.searchResult = sr && sr.result ? { ok: sr.result.ok, valueType: typeof sr.result.value } : String(sr).slice(0, 80);
} catch(e) { out.searchErr = String(e); }
} catch(e) { out.err = String(e); }
return JSON.stringify(out);
})()`);
console.log('SESSIONFACE:', JSON.stringify(step).slice(0, 3200));
ws.close(); proc.kill(); process.exit(0);
})().catch((e) => { console.error('FATAL', e && e.stack || e); try { proc.kill(); } catch {} process.exit(1); });
+4
View File
@@ -61,6 +61,10 @@ node --check lib/index.js
**工作中(busy)**:byId[sid].running === true → data-bound=busy,蓝色 #4f8ef7 发光 +
dsh-wt-busyA/B 关键帧两圆交替亮灭(对应 DSH 转圈标记);优先级 need > done > busy——等待判断时 pendingInteraction 与 running 同时为真,
原生 UI 以黄点优先,镜像必须一致;busy 无需 ack,running 变 false 自动切换。
**子代理聚合**:待决状态常挂在子代理会话上(父会话只有 running)——bindNotifyMap 用
collectKids(byId.parentId + subagentsByParent 双通道)聚合父会话及其子代理的 pending;
会话面 binding(id).session.getSnapshot().pending 非空也判 need(列表不映射时的兜底);
ackProjectNotify 同步 ack 子代理。
## 安装 / 重启