"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.runShowCommand = runShowCommand;
/**
 * `smartperfetto show <sessionId>` — print a session's latest conclusion
 * and report location. Optional `--open` opens the HTML report.
 */
const fs = __importStar(require("fs"));
const bootstrap_1 = require("../bootstrap");
const sessionStore_1 = require("../io/sessionStore");
const openFile_1 = require("../io/openFile");
async function runShowCommand(args) {
    const { paths } = (0, bootstrap_1.bootstrap)({ envFile: args.envFile, sessionDir: args.sessionDir, requireLlm: false });
    const { sp, config } = (0, sessionStore_1.loadSession)(paths, args.sessionId);
    if (!config) {
        console.error(`Error: no session found at ${sp.dir}`);
        return 1;
    }
    // Header: session metadata. Short format — full details belong in `list --json`.
    console.log(`session  ${args.sessionId}`);
    console.log(`trace    ${config.tracePath}`);
    console.log(`turns    ${config.turnCount}`);
    console.log(`updated  ${new Date(config.lastTurnAt).toISOString()}`);
    console.log('');
    // Body: latest conclusion. Session folder always has conclusion.md after
    // the first turn — if it's missing the session is corrupt or mid-analysis.
    if (fs.existsSync(sp.conclusion)) {
        console.log(fs.readFileSync(sp.conclusion, 'utf-8'));
    }
    else {
        console.log('(no conclusion yet — session is pending or incomplete)');
    }
    // Footer: report pointer. Surface always, even without --open, so the user
    // can copy it into a browser manually.
    if (fs.existsSync(sp.report)) {
        console.log(`\nreport: ${sp.report}`);
        if (args.open) {
            const r = (0, openFile_1.openPath)(sp.report);
            if (!r.ok)
                console.error(`(open failed: ${r.reason})`);
        }
    }
    else if (args.open) {
        console.error('(no report.html in session folder — nothing to open)');
    }
    return 0;
}
//# sourceMappingURL=show.js.map