Initial monorepo setup with npm workspaces and dual TypeScript configuration
- Set up npm workspaces for three packages: pi-tui, pi-agent, and pi (pods) - Implemented dual TypeScript configuration: - Root tsconfig.json with path mappings for development and type checking - Package-specific tsconfig.build.json for clean production builds - Configured lockstep versioning with sync script for inter-package dependencies - Added comprehensive documentation for development and publishing workflows - All packages at version 0.5.0 ready for npm publishing
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { appendFileSync, writeFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
export interface LoggerConfig {
|
||||
enabled: boolean;
|
||||
logFile: string;
|
||||
logLevel: "debug" | "info" | "warn" | "error";
|
||||
}
|
||||
|
||||
class Logger {
|
||||
private config: LoggerConfig = {
|
||||
enabled: false,
|
||||
logFile: join(process.cwd(), "tui-debug.log"),
|
||||
logLevel: "debug",
|
||||
};
|
||||
|
||||
configure(config: Partial<LoggerConfig>): void {
|
||||
this.config = { ...this.config, ...config };
|
||||
|
||||
if (this.config.enabled) {
|
||||
// Clear log file on startup
|
||||
try {
|
||||
writeFileSync(this.config.logFile, `=== TUI Debug Log Started ${new Date().toISOString()} ===\n`);
|
||||
} catch (error) {
|
||||
// Silently fail if we can't write to log file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private shouldLog(level: string): boolean {
|
||||
if (!this.config.enabled) return false;
|
||||
|
||||
const levels = ["debug", "info", "warn", "error"];
|
||||
const currentLevel = levels.indexOf(this.config.logLevel);
|
||||
const messageLevel = levels.indexOf(level);
|
||||
|
||||
return messageLevel >= currentLevel;
|
||||
}
|
||||
|
||||
private log(level: string, component: string, message: string, data?: any): void {
|
||||
if (!this.shouldLog(level)) return;
|
||||
|
||||
try {
|
||||
const timestamp = new Date().toISOString();
|
||||
const dataStr = data ? ` | Data: ${JSON.stringify(data)}` : "";
|
||||
const logLine = `[${timestamp}] ${level.toUpperCase()} [${component}] ${message}${dataStr}\n`;
|
||||
|
||||
appendFileSync(this.config.logFile, logLine);
|
||||
} catch (error) {
|
||||
// Silently fail if we can't write to log file
|
||||
}
|
||||
}
|
||||
|
||||
debug(component: string, message: string, data?: any): void {
|
||||
this.log("debug", component, message, data);
|
||||
}
|
||||
|
||||
info(component: string, message: string, data?: any): void {
|
||||
this.log("info", component, message, data);
|
||||
}
|
||||
|
||||
warn(component: string, message: string, data?: any): void {
|
||||
this.log("warn", component, message, data);
|
||||
}
|
||||
|
||||
error(component: string, message: string, data?: any): void {
|
||||
this.log("error", component, message, data);
|
||||
}
|
||||
|
||||
// Specific TUI logging methods
|
||||
keyInput(component: string, keyData: string): void {
|
||||
this.debug(component, "Key input received", {
|
||||
keyData,
|
||||
charCodes: Array.from(keyData).map((c) => c.charCodeAt(0)),
|
||||
});
|
||||
}
|
||||
|
||||
render(component: string, renderResult: any): void {
|
||||
this.debug(component, "Render result", renderResult);
|
||||
}
|
||||
|
||||
focus(component: string, focused: boolean): void {
|
||||
this.info(component, `Focus ${focused ? "gained" : "lost"}`);
|
||||
}
|
||||
|
||||
componentLifecycle(component: string, action: string, details?: any): void {
|
||||
this.info(component, `Component ${action}`, details);
|
||||
}
|
||||
|
||||
stateChange(component: string, property: string, oldValue: any, newValue: any): void {
|
||||
this.debug(component, `State change: ${property}`, { oldValue, newValue });
|
||||
}
|
||||
}
|
||||
|
||||
export const logger = new Logger();
|
||||
Reference in New Issue
Block a user