From 84d837a78a925300fee473541cd2a1dc03ddcd54 Mon Sep 17 00:00:00 2001 From: Tony Casey Date: Thu, 12 Feb 2026 23:04:09 +0000 Subject: [PATCH 1/2] fix: use project-local .git-mem/logs/ for log directory (GIT-63) Logs now write to /.git-mem/logs/ instead of ~/.git-mem/logs/ so they are relevant and easy to access per project. Co-Authored-By: Claude Opus 4.6 --- src/infrastructure/logging/factory.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/infrastructure/logging/factory.ts b/src/infrastructure/logging/factory.ts index 3104b3ca..59264ace 100644 --- a/src/infrastructure/logging/factory.ts +++ b/src/infrastructure/logging/factory.ts @@ -1,4 +1,3 @@ -import * as os from 'node:os'; import * as path from 'node:path'; import { ILogger, ILoggerOptions, LogLevel } from '../../domain/interfaces/ILogger'; import { Logger } from './Logger'; @@ -11,7 +10,7 @@ function isValidLogLevel(value: string): value is LogLevel { } export function defaultLogDir(): string { - return path.join(os.homedir(), '.git-mem', 'logs'); + return path.join(process.cwd(), '.git-mem', 'logs'); } export function loadLoggerOptions(): ILoggerOptions { From 8d41bb99c3f718403e15276c198b1181cadf1f5d Mon Sep 17 00:00:00 2001 From: Tony Casey Date: Thu, 12 Feb 2026 23:10:05 +0000 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20address=20PR=20review=20=E2=80=94=20?= =?UTF-8?q?use=20git=20root,=20add=20defaultLogDir=20test=20(GIT-63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use git rev-parse --show-toplevel to resolve the project root instead of process.cwd(), with fallback to cwd when not in a git repo. Added unit test asserting defaultLogDir() returns .git-mem/logs under git root. Co-Authored-By: Claude Opus 4.6 --- src/infrastructure/logging/factory.ts | 15 ++++++++++++++- tests/unit/infrastructure/logging/factory.test.ts | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/logging/factory.ts b/src/infrastructure/logging/factory.ts index 59264ace..41a56a2d 100644 --- a/src/infrastructure/logging/factory.ts +++ b/src/infrastructure/logging/factory.ts @@ -1,4 +1,5 @@ import * as path from 'node:path'; +import { execFileSync } from 'node:child_process'; import { ILogger, ILoggerOptions, LogLevel } from '../../domain/interfaces/ILogger'; import { Logger } from './Logger'; import { NullLogger } from './NullLogger'; @@ -9,8 +10,20 @@ function isValidLogLevel(value: string): value is LogLevel { return VALID_LEVELS.includes(value as LogLevel); } +function getGitRoot(): string | null { + try { + return execFileSync('git', ['rev-parse', '--show-toplevel'], { + encoding: 'utf8', + stdio: ['pipe', 'pipe', 'pipe'], + }).trim(); + } catch { + return null; + } +} + export function defaultLogDir(): string { - return path.join(process.cwd(), '.git-mem', 'logs'); + const base = getGitRoot() ?? process.cwd(); + return path.join(base, '.git-mem', 'logs'); } export function loadLoggerOptions(): ILoggerOptions { diff --git a/tests/unit/infrastructure/logging/factory.test.ts b/tests/unit/infrastructure/logging/factory.test.ts index d3366819..5e56d697 100644 --- a/tests/unit/infrastructure/logging/factory.test.ts +++ b/tests/unit/infrastructure/logging/factory.test.ts @@ -1,5 +1,7 @@ import { describe, it, before, after } from 'node:test'; import assert from 'node:assert/strict'; +import { join } from 'path'; +import { execFileSync } from 'child_process'; import { createLogger, createNullLogger, defaultLogDir, loadLoggerOptions } from '../../../../src/infrastructure/logging/factory'; import { Logger } from '../../../../src/infrastructure/logging/Logger'; import { NullLogger } from '../../../../src/infrastructure/logging/NullLogger'; @@ -27,6 +29,16 @@ describe('Logging factory', () => { } }); + describe('defaultLogDir', () => { + it('should return .git-mem/logs under the git root', () => { + const gitRoot = execFileSync('git', ['rev-parse', '--show-toplevel'], { + encoding: 'utf8', + }).trim(); + + assert.equal(defaultLogDir(), join(gitRoot, '.git-mem', 'logs')); + }); + }); + describe('loadLoggerOptions', () => { it('should return defaults when no env vars set', () => { delete process.env['LOG_LEVEL'];