write tui debug/crash logs into the configured pi agent dir (#6958)
fixes #6652
This commit is contained in:
@@ -319,15 +319,17 @@ export class TUI extends Container {
|
||||
private pendingOsc11BackgroundQueries: PendingOsc11BackgroundQuery[] = [];
|
||||
private terminalColorSchemeListeners = new Set<(scheme: TerminalColorScheme) => void>();
|
||||
private terminalColorSchemeNotificationsEnabled = false;
|
||||
private readonly logDirectory: string;
|
||||
|
||||
// Overlay stack for modal components rendered on top of base content
|
||||
private focusOrderCounter = 0;
|
||||
private overlayStack: OverlayStackEntry[] = [];
|
||||
private overlayFocusRestore: OverlayFocusRestoreState = { status: "inactive" };
|
||||
|
||||
constructor(terminal: Terminal, showHardwareCursor?: boolean) {
|
||||
constructor(terminal: Terminal, showHardwareCursor?: boolean, logDirectory?: string) {
|
||||
super();
|
||||
this.terminal = terminal;
|
||||
this.logDirectory = logDirectory ?? process.env.PI_CODING_AGENT_DIR ?? path.join(os.homedir(), ".pi", "agent");
|
||||
if (showHardwareCursor !== undefined) {
|
||||
this.showHardwareCursor = showHardwareCursor;
|
||||
}
|
||||
@@ -1329,8 +1331,9 @@ export class TUI extends Container {
|
||||
const debugRedraw = process.env.PI_DEBUG_REDRAW === "1";
|
||||
const logRedraw = (reason: string): void => {
|
||||
if (!debugRedraw) return;
|
||||
const logPath = path.join(os.homedir(), ".pi", "agent", "pi-debug.log");
|
||||
const logPath = path.join(this.logDirectory, "pi-debug.log");
|
||||
const msg = `[${new Date().toISOString()}] fullRender: ${reason} (prev=${this.previousLines.length}, new=${newLines.length}, height=${height})\n`;
|
||||
fs.mkdirSync(path.dirname(logPath), { recursive: true });
|
||||
fs.appendFileSync(logPath, msg);
|
||||
};
|
||||
|
||||
@@ -1521,7 +1524,7 @@ export class TUI extends Container {
|
||||
buffer += "\x1b[2K"; // Clear current line
|
||||
if (!isImage && visibleWidth(line) > width) {
|
||||
// Log all lines to crash file for debugging
|
||||
const crashLogPath = path.join(os.homedir(), ".pi", "agent", "pi-crash.log");
|
||||
const crashLogPath = path.join(this.logDirectory, "pi-crash.log");
|
||||
const crashData = [
|
||||
`Crash at ${new Date().toISOString()}`,
|
||||
`Terminal width: ${width}`,
|
||||
|
||||
Reference in New Issue
Block a user