import * as os from 'node:os';
import * as path from 'node:path';
import { getShortcutTuiRenderTraceFullSetting, getShortcutTuiRenderTraceSetting } from '../../constants.js';
import { RenderTrace } from '../../tui/render-trace.js';
function isTruthyEnv(value) {
    if (!value)
        return false;
    const normalized = value.trim().toLowerCase();
    return normalized !== '' && normalized !== '0' && normalized !== 'false' && normalized !== 'off';
}
function resolveInteractiveRenderTracePath() {
    const rawSetting = getShortcutTuiRenderTraceSetting();
    if (!isTruthyEnv(rawSetting))
        return undefined;
    const raw = rawSetting.trim();
    const normalized = raw.toLowerCase();
    const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
    if (normalized === '1' || normalized === 'true' || normalized === 'on') {
        return path.join(os.homedir(), '.shortcut', 'agent', 'tui-render-traces', `${timestamp}-${process.pid}.jsonl`);
    }
    if (raw.endsWith(path.sep) || raw.endsWith('/') || raw.endsWith('\\')) {
        return path.join(raw, `${timestamp}-${process.pid}.jsonl`);
    }
    return raw;
}
export function createInteractiveRenderTrace() {
    const tracePath = resolveInteractiveRenderTracePath();
    if (!tracePath)
        return undefined;
    try {
        return new RenderTrace(tracePath, {
            includeFullText: isTruthyEnv(getShortcutTuiRenderTraceFullSetting())
        });
    }
    catch {
        return undefined;
    }
}
//# sourceMappingURL=interactive-render-trace.js.map