"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.
Object.defineProperty(exports, "__esModule", { value: true });
exports.runResumeCommand = runResumeCommand;
/**
 * `smartperfetto resume <sessionId> --query <...>` — continue a prior session.
 *
 * Thin wrapper: shares `turnRunner.continueSession` with the REPL. The
 * three-level degradation (Level 1/2 trace reload, Level 3 fresh-load +
 * preamble) lives in the runner, not here — keep this file boring.
 */
const bootstrap_1 = require("../bootstrap");
const cliAnalyzeService_1 = require("../services/cliAnalyzeService");
const renderer_1 = require("../repl/renderer");
const turnRunner_1 = require("../services/turnRunner");
const runtimeGuard_1 = require("../services/runtimeGuard");
const stdio_1 = require("../io/stdio");
const sessionStore_1 = require("../io/sessionStore");
async function runResumeCommand(args) {
    const { paths } = (0, bootstrap_1.bootstrap)({ envFile: args.envFile, sessionDir: args.sessionDir });
    const renderer = (0, renderer_1.createRenderer)({ verbose: args.verbose, useColor: !args.noColor, format: args.format });
    const service = new cliAnalyzeService_1.CliAnalyzeService();
    let exitCode = 0;
    try {
        await (0, stdio_1.withConsoleLogToStderr)(renderer.format !== 'text', async () => {
            const { config } = (0, sessionStore_1.loadSession)(paths, args.sessionId);
            (0, runtimeGuard_1.assertAnalysisRuntimeReady)(config
                ? { providerId: config.providerId, runtimeOverride: config.agentRuntimeKind }
                : {});
            const turn = await (0, turnRunner_1.continueSession)({ paths, service, renderer }, {
                sessionId: args.sessionId,
                query: args.query,
            });
            exitCode = turn.success ? 0 : 1;
        });
        return exitCode;
    }
    catch (err) {
        renderer.printError(err.message);
        return 1;
    }
    finally {
        await service.shutdown();
    }
}
//# sourceMappingURL=resume.js.map