Files
ccs/src/services/logging/log-paths.ts
T
Tam Nhu Tran 4f6e61739c refactor(config): adopt config-loader-facade across the codebase
Issue #1161. Sweeps 127 files to import from
src/config/config-loader-facade.ts instead of unified-config-loader or
utils/config-manager directly.

WRITE callers (32 files): replaced raw saveUnifiedConfig /
mutateUnifiedConfig / updateUnifiedConfig calls with the facade's
cache-coherent wrappers saveConfig / mutateConfig / updateConfig. This
fixes a latent stale-cache window where direct writes through the
underlying loader bypassed the facade's memoization.

READ callers (95 files): mechanical import-path migration only —
function names unchanged because the facade re-exports them. No
behavior change.

Also updated:
- tests/unit/utils/browser/browser-setup.test.ts (DI interface rename)
- src/management/checks/image-analysis-check.ts (dynamic import rename)
- src/web-server/health-service.ts (dynamic require rename)
- src/ccs.ts (path prefix fix from sweep script)

After sweep: zero raw write callers remain outside src/config/. Direct
imports of config-manager remain only for symbols not in the facade
(getConfigPath, getCcsDirSource, etc). Behavior unchanged; full suite
passes 1824/1824.

Out of scope: switching loadOrCreateUnifiedConfig() callers to
getCachedConfig() — needs per-callsite cache-safety analysis. Tracked
as follow-up.

Refs #1161
2026-05-03 01:42:53 -04:00

41 lines
1.3 KiB
TypeScript

import * as fs from 'fs';
import * as path from 'path';
import { getCcsDir } from '../../config/config-loader-facade';
const LOGS_DIR = 'logs';
const ARCHIVE_DIR = 'archive';
const CURRENT_LOG_FILE = 'current.jsonl';
export function getNativeLogsDir(): string {
return path.join(getCcsDir(), LOGS_DIR);
}
export function getCurrentLogPath(): string {
return path.join(getNativeLogsDir(), CURRENT_LOG_FILE);
}
export function getLogArchiveDir(): string {
return path.join(getNativeLogsDir(), ARCHIVE_DIR);
}
export function getLegacyCliproxyLogsDir(): string {
return path.join(getCcsDir(), 'cliproxy', 'logs');
}
export function ensureLoggingDirectories(): void {
fs.mkdirSync(getNativeLogsDir(), { recursive: true, mode: 0o700 });
fs.mkdirSync(getLogArchiveDir(), { recursive: true, mode: 0o700 });
}
export function isPathInsideDirectory(candidatePath: string, rootDir: string): boolean {
const resolvedCandidate = path.resolve(candidatePath);
const resolvedRoot = path.resolve(rootDir);
const relative = path.relative(resolvedRoot, resolvedCandidate);
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative));
}
export function buildArchiveLogPath(timestamp: Date = new Date()): string {
const compact = timestamp.toISOString().replace(/[:.]/g, '-');
return path.join(getLogArchiveDir(), `ccs-${compact}.jsonl.gz`);
}