Files
orca/src/main/plugins/plugin-log-buffer.ts
T
OrcaWinandm4air 4085e1cf60 fix(memory): release stale session registries (#21734)
* fix(memory): bound session and lifecycle registries

* fix(memory): bound transient filesystem registries

* fix(memory): cap path and locale caches

* fix(memory): bound runtime recovery registries

* fix(memory): bound host mirror gap verdicts

* fix(memory): bound shell startup env cache

* fix(memory): bound gitlab host context cache

* fix(memory): release removed ssh generations

* fix(memory): expire cloud refresh replay guards

* fix(memory): release retired plugin generations

* fix(memory): bound plugin log key retention

* fix(memory): bound automation authority generations

* fix(memory): bound native chat enrichment cache

* fix(memory): bound web session tracking generations

* fix(memory): bound codex credential absence paths

* fix(memory): bound WSL canonical path cache

* fix(memory): bound sparse checkout cache

* fix(memory): bound shared directory cache

* fix(memory): bound advertised URL scan snapshots

* fix(memory): bound automation manager cache

* fix(memory): bound web session reorder intents

* fix(memory): bound web session focus intents

* fix(memory): bound web session handoffs

* fix(memory): bound automation dispatch tokens

* fix(memory): bound host mirror waiters

* fix(memory): bound retained session activity

* fix(memory): bound retained session activity

* fix(memory): bound web session close intents

* fix(memory): bound cloud session cache

* fix(memory): bound WSL home cache

* fix(memory): bound SSH capability cache

* fix(memory): bound trust grant cooldowns

* fix(memory): bound WSL auth drain state

* fix(memory): bound Linear workspace credential cache

* fix(memory): bound local Git capability cache

* fix(memory): bound WSL Git environment cache

* fix(memory): bound WSL Git environment cache

* fix(memory): bound WSL preflight cache

* fix(memory): keep hot cache entries warm

* fix(memory): preserve generation fences across eviction

* fix(memory): close remaining eviction fences

* fix(memory): align evicted upstream generations

* fix(memory): trim successful capability probes

* fix(auth): retain expired refresh replay evidence

---------

Co-authored-by: m4air <m4air@Mac.localdomain>
2026-09-20 14:41:50 -07:00

54 lines
1.5 KiB
TypeScript

export type PluginLogLine = { ts: number; level: 'info' | 'warn' | 'error'; line: string }
const LOG_RING_LIMIT = 200
export const PLUGIN_LOG_KEY_LIMIT = 256
export class PluginLogBuffer {
private readonly logs = new Map<string, { token: object; lines: PluginLogLine[] }>()
get(pluginKey: string): PluginLogLine[] {
return this.logs.get(pluginKey)?.lines ?? []
}
get size(): number {
return this.logs.size
}
capture(pluginKey: string): (level: PluginLogLine['level'], line: string) => void {
const token = this.ensure(pluginKey).token
return (level, line) => {
if (this.logs.get(pluginKey)?.token === token) {
this.append(pluginKey, level, line)
}
}
}
clear(pluginKey: string): void {
this.logs.delete(pluginKey)
}
private ensure(pluginKey: string): { token: object; lines: PluginLogLine[] } {
let entry = this.logs.get(pluginKey)
if (!entry) {
entry = { token: {}, lines: [] }
this.logs.set(pluginKey, entry)
while (this.logs.size > PLUGIN_LOG_KEY_LIMIT) {
const oldest = this.logs.keys().next()
if (oldest.done) {
break
}
this.logs.delete(oldest.value)
}
}
return entry
}
append(pluginKey: string, level: PluginLogLine['level'], line: string): void {
const ring = this.ensure(pluginKey).lines
ring.push({ ts: Date.now(), level, line })
if (ring.length > LOG_RING_LIMIT) {
ring.splice(0, ring.length - LOG_RING_LIMIT)
}
}
}