fix(bridge): 不再抢写 snapshot.json(会把别的会话串进浮窗);镜像缓存深度 40→80
实测串台:插件 tick 一停顿,桥就把另一个会话的 40 行写进 snapshot.json,浮窗显示成别人的对话。 现在桥只写 snapshot-bridge.json,浮窗按 sessionId 匹配后才用它补缺字段,永远不会串会话。 镜像缓存每会话保留 80 行(原来 40),仍然每 3 秒落盘一次。
This commit is contained in:
+15
-2
@@ -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
|
||||
|
||||
@@ -236,15 +236,10 @@ function writeSnapshot() {
|
||||
const snap = buildSnapshot()
|
||||
if (!snap) return
|
||||
fs.mkdirSync(STATE_DIR, { recursive: true })
|
||||
// 兜底文件总是写:插件缺的字段(token/上下文估算、标题)由浮窗用它补齐
|
||||
// 只写兜底文件:snapshot.json 是插件的"正本"。桥去写它会把**别的会话**塞给浮窗(实测串台过:
|
||||
// 插件 tick 一停顿,桥就把另一个会话的 40 行写了进去)。浮窗按 sessionId 匹配后再用它补缺字段。
|
||||
fs.writeFileSync(SNAPSHOT_BRIDGE, JSON.stringify(snap))
|
||||
// 插件在写就不抢 snapshot.json:mtime 3 秒内视为它的
|
||||
try {
|
||||
const st = fs.statSync(SNAPSHOT)
|
||||
if (Date.now() - st.mtimeMs < 3000 && readJson(SNAPSHOT)?.source !== 'mirror-bridge') return
|
||||
} catch { }
|
||||
fs.writeFileSync(SNAPSHOT, JSON.stringify(snap))
|
||||
log(`snapshot: ${snap.sessionId} "${(snap.title || '').slice(0, 24)}" turns=${snap.metrics.turns} steps=${snap.metrics.steps} rows=${snap.messages.length} ctx=${snap.metrics.contextUsed == null ? '-' : Math.round(snap.metrics.contextUsed * 100) + '%'}`)
|
||||
log(`bridge: ${snap.sessionId} "${(snap.title || '').slice(0, 20)}" rows=${snap.messages.length} cache=${snap.metrics.cacheHit == null ? '-' : Math.round(snap.metrics.cacheHit * 100) + '%'}`)
|
||||
} catch (e) { log('write failed:', String(e?.message || e)) }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user