// 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); });