fix(bridge): 不再抢写 snapshot.json(会把别的会话串进浮窗);镜像缓存深度 40→80

实测串台:插件 tick 一停顿,桥就把另一个会话的 40 行写进 snapshot.json,浮窗显示成别人的对话。
现在桥只写 snapshot-bridge.json,浮窗按 sessionId 匹配后才用它补缺字段,永远不会串会话。
镜像缓存每会话保留 80 行(原来 40),仍然每 3 秒落盘一次。
This commit is contained in:
2026-09-27 18:35:21 +08:00
parent 4e666033d2
commit 891edaafe7
2 changed files with 18 additions and 10 deletions
+15 -2
View File
@@ -252,7 +252,7 @@ export function apply(ctx, config) {
const out = { at: Date.now(), lastSessionId, sessions: {} }
const ids = [...rows.keys()].slice(-8)
for (const id of ids) {
out.sessions[id] = { title: titles.get(id) || null, rows: (rows.get(id) || []).slice(-40), counts: counts.get(id) || null }
out.sessions[id] = { title: titles.get(id) || null, rows: (rows.get(id) || []).slice(-80), counts: counts.get(id) || null }
}
fs.mkdirSync(path.dirname(mirrorCacheFile), { recursive: true })
fs.writeFileSync(mirrorCacheFile, JSON.stringify(out))
@@ -889,12 +889,25 @@ border:1px solid rgba(120,140,180,.35);background:rgba(22,26,34,.92);color:#e6ea
log('services: ' + ['settings', 'sessions', 'tools', 'tokenMeter', 'sessionProjection', 'llm', 'shell', 'sandboxPolicy', 'webServer']
.map((n) => `${n}=${(() => { try { return ctx.get(n) ? 'y' : 'n' } catch { return '?' } })()}`).join(' '))
// 诊断:把 sessionController / apiProxy 暴露的方法名列出来(回填历史要用其中一个)
// 注意:这些对象的方法常常是 getter / 非枚举,Object.keys 看不到 → 用 getOwnPropertyNames
try {
const names = (o, proto = false) => {
try {
const out = new Set(Object.getOwnPropertyNames(o))
if (proto) for (const k of Object.getOwnPropertyNames(Object.getPrototypeOf(o) || {})) out.add(k)
return [...out].filter((k) => !['constructor', 'ctx', 'name', 'store', 'counter', 'projections'].includes(k)).slice(0, 60)
} catch { return [] }
}
const faces = {}
for (const n of ['sessionController', 'apiProxy', 'sessions', 'sessionProjection']) {
try {
const f = ctx.get(n)
if (f) faces[n] = Object.keys(f).slice(0, 80)
if (!f) continue
faces[n] = names(f)
if (f.sessions) faces[n + '.sessions'] = names(f.sessions)
if (f.store) faces[n + '.store'] = names(f.store)
if (f.projections) faces[n + '.projections'] = names(f.projections)
if (f.counter) faces[n + '.counter'] = names(f.counter)
} catch { }
}
status.apiMethods = faces