import { appendFileSync, existsSync, mkdirSync } from "fs"; import { randomUUID } from "crypto"; import { join } from "path"; export const SKILL_NAME = "generate-env"; export const SESSION_ID = randomUUID().slice(0, 8); export const SKILLS_OUTPUT_DIR = process.env.SKILLS_OUTPUT_DIR || join(process.cwd(), ".skills"); export const LOGS_DIR = join(SKILLS_OUTPUT_DIR, "logs", SKILL_NAME); export const SESSION_TIMESTAMP = new Date().toISOString().replace(/[:.]/g, "_").slice(0, 19); export function ensureDir(dir: string) { if (!existsSync(dir)) { mkdirSync(dir, { recursive: true }); } } export function log(message: string, level: "info" | "error" | "success" | "warn" = "info") { ensureDir(LOGS_DIR); const timestamp = new Date().toISOString(); const logFile = join(LOGS_DIR, `log_${SESSION_TIMESTAMP}_${SESSION_ID}.log`); const logEntry = `[${timestamp}] [${level.toUpperCase()}] ${message}\n`; appendFileSync(logFile, logEntry); const prefix = level === "error" ? "❌" : level === "success" ? "✅" : level === "warn" ? "⚠️" : "ℹ️"; if (level === "error") { console.error(`${prefix} ${message}`); } else { console.log(`${prefix} ${message}`); } }