Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: create PGLite data dir before lock (#85)
Francisco Maranchelloadb02b7826a0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 15fd0fa937..207be5ffeb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,12 @@All notable changes to GBrain will be documented in this file.+## [0.9.2] - 2026-04-12++### Fixed++- **Fresh local installs initialize cleanly again.** `gbrain init` now creates the local PGLite data directory before taking its advisory lock, so first-run setup no longer misreports a missing directory as a lock timeout.+## [0.9.1] - 2026-04-11### Fixeddiff --git a/VERSION b/VERSIONindex f374f6662e..2003b639c4 100644--- a/VERSION+++ b/VERSION@@ -1 +1 @@-0.9.1+0.9.2diff --git a/package.json b/package.jsonindex 532e590689..1acb742e0a 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "gbrain",- "version": "0.9.1",+ "version": "0.9.2","description": "Postgres-native personal knowledge brain with hybrid RAG search","type": "module","main": "src/core/index.ts",diff --git a/src/core/pglite-lock.ts b/src/core/pglite-lock.tsindex cd6b94a1c5..440e4304ff 100644--- a/src/core/pglite-lock.ts+++ b/src/core/pglite-lock.ts@@ -59,6 +59,8 @@ export async function acquireLock(dataDir: string | undefined, opts?: { timeoutMreturn { lockDir: '', acquired: true };}+ mkdirSync(dataDir, { recursive: true });+const timeoutMs = opts?.timeoutMs ?? 30_000; // 30 second default timeoutconst startTime = Date.now();diff --git a/test/pglite-lock.test.ts b/test/pglite-lock.test.tsindex d4acffe689..3253aa41bf 100644--- a/test/pglite-lock.test.ts+++ b/test/pglite-lock.test.ts@@ -26,6 +26,18 @@ describe('pglite-lock', () => {expect(existsSync(join(TEST_DIR, '.gbrain-lock'))).toBe(false);});+ test('creates missing data directory before acquiring lock', async () => {+ const missingDataDir = join(TEST_DIR, 'missing-data-dir');++ const lock = await acquireLock(missingDataDir);+ expect(lock.acquired).toBe(true);+ expect(existsSync(missingDataDir)).toBe(true);+ expect(existsSync(join(missingDataDir, '.gbrain-lock'))).toBe(true);++ await releaseLock(lock);+ expect(existsSync(join(missingDataDir, '.gbrain-lock'))).toBe(false);+ });+test('prevents concurrent lock acquisition', async () => {const lock1 = await acquireLock(TEST_DIR, { timeoutMs: 2000 });expect(lock1.acquired).toBe(true);