Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(connection-audit): resolve the audit dir per write instead of caching the first GBRAIN_HOME seen in the process
garrytanab0adbf572c8
diff --git a/src/core/connection-audit.ts b/src/core/connection-audit.tsindex 41739277c5..380037324d 100644--- a/src/core/connection-audit.ts+++ b/src/core/connection-audit.ts@@ -30,19 +30,12 @@ export interface ConnectionEvent {error?: { code?: string; message: string };}-let _auditDirCache: string | null = null;let _auditEnabled = true;export function setAuditEnabled(enabled: boolean): void {_auditEnabled = enabled;}-function getAuditDir(): string {- if (_auditDirCache) return _auditDirCache;- _auditDirCache = gbrainPath('audit');- return _auditDirCache;-}-function getIsoWeekFilename(d: Date = new Date()): string {// ISO 8601 week date: year + week number. Match shell-audit.ts format.const target = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));@@ -58,7 +51,7 @@ function getIsoWeekFilename(d: Date = new Date()): string {export function logConnectionEvent(event: ConnectionEvent): void {if (!_auditEnabled) return;try {- const dir = getAuditDir();+ const dir = gbrainPath('audit');mkdirSync(dir, { recursive: true });const path = join(dir, getIsoWeekFilename());const line = {@@ -87,7 +80,7 @@ export function logConnectionEvent(event: ConnectionEvent): void {*/export function tailRecentErrors(limit: number = 5): ConnectionEvent[] {try {- const dir = getAuditDir();+ const dir = gbrainPath('audit');if (!existsSync(dir)) return [];const path = join(dir, getIsoWeekFilename());if (!existsSync(path)) return [];