fix(cli): prevent duplicate rendering of auto-approved file tools (#782)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
Charles Packer
2026-02-02 00:36:47 -08:00
committed by GitHub
parent 1ee7a13d8b
commit 7297e334f0
4 changed files with 160 additions and 175 deletions

View File

@@ -1,5 +1,9 @@
// src/utils/debug.ts
// Simple debug logging utility - only logs when LETTA_DEBUG env var is set
// Optionally logs to a file when LETTA_DEBUG_FILE is set
import { appendFileSync } from "node:fs";
import { format } from "node:util";
/**
* Check if debug mode is enabled via LETTA_DEBUG env var
@@ -10,6 +14,30 @@ export function isDebugEnabled(): boolean {
return debug === "1" || debug === "true";
}
function getDebugFile(): string | null {
const path = process.env.LETTA_DEBUG_FILE;
return path && path.trim().length > 0 ? path : null;
}
function writeDebugLine(
prefix: string,
message: string,
args: unknown[],
): void {
const debugFile = getDebugFile();
const line = `${format(`[${prefix}] ${message}`, ...args)}\n`;
if (debugFile) {
try {
appendFileSync(debugFile, line, { encoding: "utf8" });
return;
} catch {
// Fall back to console if file write fails
}
}
// Default to console output
console.log(line.trimEnd());
}
/**
* Log a debug message (only if LETTA_DEBUG is enabled)
* @param prefix - A prefix/tag for the log message (e.g., "check-approval")
@@ -22,7 +50,7 @@ export function debugLog(
...args: unknown[]
): void {
if (isDebugEnabled()) {
console.log(`[${prefix}] ${message}`, ...args);
writeDebugLine(prefix, message, args);
}
}
@@ -38,6 +66,6 @@ export function debugWarn(
...args: unknown[]
): void {
if (isDebugEnabled()) {
console.warn(`[${prefix}] ${message}`, ...args);
writeDebugLine(prefix, `WARN: ${message}`, args);
}
}