Refactor: Remove legacy data access objects and logging utilities
- Deleted MemoryStore, OverviewStore, SessionStore, StreamingSessionStore, and TranscriptEventStore classes to streamline database interactions. - Removed logger and rolling log utilities to simplify logging mechanisms. - Updated index file to reflect the removal of stores and logging functionalities.
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Simple logging utility for claude-mem
|
||||
*/
|
||||
|
||||
export interface LogLevel {
|
||||
DEBUG: number;
|
||||
INFO: number;
|
||||
WARN: number;
|
||||
ERROR: number;
|
||||
}
|
||||
|
||||
const LOG_LEVELS: LogLevel = {
|
||||
DEBUG: 0,
|
||||
INFO: 1,
|
||||
WARN: 2,
|
||||
ERROR: 3,
|
||||
};
|
||||
|
||||
class Logger {
|
||||
// <Block> 2.1 ====================================
|
||||
private level: number = LOG_LEVELS.INFO;
|
||||
|
||||
setLevel(level: keyof LogLevel): void {
|
||||
this.level = LOG_LEVELS[level];
|
||||
}
|
||||
// </Block> =======================================
|
||||
|
||||
// <Block> 2.2 ====================================
|
||||
debug(message: string, ...args: any[]): void {
|
||||
if (this.level <= LOG_LEVELS.DEBUG) {
|
||||
console.debug(`[DEBUG] ${message}`, ...args);
|
||||
}
|
||||
}
|
||||
// </Block> =======================================
|
||||
|
||||
// <Block> 2.3 ====================================
|
||||
info(message: string, ...args: any[]): void {
|
||||
if (this.level <= LOG_LEVELS.INFO) {
|
||||
console.info(`[INFO] ${message}`, ...args);
|
||||
}
|
||||
}
|
||||
// </Block> =======================================
|
||||
|
||||
// <Block> 2.4 ====================================
|
||||
warn(message: string, ...args: any[]): void {
|
||||
if (this.level <= LOG_LEVELS.WARN) {
|
||||
console.warn(`[WARN] ${message}`, ...args);
|
||||
}
|
||||
}
|
||||
// </Block> =======================================
|
||||
|
||||
// <Block> 2.5 ====================================
|
||||
error(message: string, error?: any, context?: any): void {
|
||||
if (this.level <= LOG_LEVELS.ERROR) {
|
||||
console.error(`[ERROR] ${message}`);
|
||||
if (error) {
|
||||
console.error(error);
|
||||
}
|
||||
if (context) {
|
||||
console.error('Context:', context);
|
||||
}
|
||||
}
|
||||
}
|
||||
// </Block> =======================================
|
||||
}
|
||||
|
||||
export const log = new Logger();
|
||||
@@ -1,42 +0,0 @@
|
||||
import { appendFileSync, existsSync, mkdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { PathDiscovery } from '../services/path-discovery.js';
|
||||
|
||||
let logPath: string | null = null;
|
||||
|
||||
function ensureLogPath(): string {
|
||||
if (logPath) {
|
||||
return logPath;
|
||||
}
|
||||
|
||||
const discovery = PathDiscovery.getInstance();
|
||||
const logsDir = discovery.getLogsDirectory();
|
||||
|
||||
if (!existsSync(logsDir)) {
|
||||
mkdirSync(logsDir, { recursive: true });
|
||||
}
|
||||
|
||||
logPath = join(logsDir, 'rolling-memory.log');
|
||||
return logPath;
|
||||
}
|
||||
|
||||
export type RollingLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
||||
|
||||
export function rollingLog(
|
||||
level: RollingLogLevel,
|
||||
message: string,
|
||||
payload: Record<string, unknown> = {}
|
||||
): void {
|
||||
try {
|
||||
const file = ensureLogPath();
|
||||
const entry = {
|
||||
timestamp: new Date().toISOString(),
|
||||
level,
|
||||
message,
|
||||
...payload
|
||||
};
|
||||
appendFileSync(file, `${JSON.stringify(entry)}\n`, 'utf8');
|
||||
} catch {
|
||||
// Logging should never throw user-facing errors
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
import { readSettings } from './settings.js';
|
||||
|
||||
export interface RollingSettings {
|
||||
captureEnabled: boolean;
|
||||
summaryEnabled: boolean;
|
||||
sessionStartEnabled: boolean;
|
||||
chunkTokenLimit: number;
|
||||
chunkOverlapTokens: number;
|
||||
summaryTurnLimit: number;
|
||||
}
|
||||
|
||||
const DEFAULTS: RollingSettings = {
|
||||
captureEnabled: true,
|
||||
summaryEnabled: true,
|
||||
sessionStartEnabled: true,
|
||||
chunkTokenLimit: 600,
|
||||
chunkOverlapTokens: 200,
|
||||
summaryTurnLimit: 20
|
||||
};
|
||||
|
||||
function normalizeBoolean(value: unknown, fallback: boolean): boolean {
|
||||
if (typeof value === 'boolean') {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
const lowered = value.toLowerCase();
|
||||
if (lowered === 'true') return true;
|
||||
if (lowered === 'false') return false;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
function normalizeNumber(value: unknown, fallback: number): number {
|
||||
if (typeof value === 'number' && Number.isFinite(value)) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === 'string') {
|
||||
const parsed = Number(value);
|
||||
if (!Number.isNaN(parsed) && Number.isFinite(parsed)) {
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function getRollingSettings(): RollingSettings {
|
||||
const settings = readSettings();
|
||||
|
||||
return {
|
||||
captureEnabled: normalizeBoolean(
|
||||
settings.rollingCaptureEnabled,
|
||||
DEFAULTS.captureEnabled
|
||||
),
|
||||
summaryEnabled: normalizeBoolean(
|
||||
settings.rollingSummaryEnabled,
|
||||
DEFAULTS.summaryEnabled
|
||||
),
|
||||
sessionStartEnabled: normalizeBoolean(
|
||||
settings.rollingSessionStartEnabled,
|
||||
DEFAULTS.sessionStartEnabled
|
||||
),
|
||||
chunkTokenLimit: normalizeNumber(
|
||||
settings.rollingChunkTokens,
|
||||
DEFAULTS.chunkTokenLimit
|
||||
),
|
||||
chunkOverlapTokens: normalizeNumber(
|
||||
settings.rollingChunkOverlapTokens,
|
||||
DEFAULTS.chunkOverlapTokens
|
||||
),
|
||||
summaryTurnLimit: normalizeNumber(
|
||||
settings.rollingSummaryTurnLimit,
|
||||
DEFAULTS.summaryTurnLimit
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
export function isRollingCaptureEnabled(): boolean {
|
||||
return getRollingSettings().captureEnabled;
|
||||
}
|
||||
|
||||
export function isRollingSummaryEnabled(): boolean {
|
||||
return getRollingSettings().summaryEnabled;
|
||||
}
|
||||
|
||||
export function isRollingSessionStartEnabled(): boolean {
|
||||
return getRollingSettings().sessionStartEnabled;
|
||||
}
|
||||
Reference in New Issue
Block a user