"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getVariablesCommand = void 0;
exports.getVariables = getVariables;
const debugFailWrapper_1 = require("../util/debugFailWrapper");
const constants_1 = require("../../../constants");
const debugCommands_1 = require("../../debugCommands");
const DebugSession_1 = require("@mablhq-internal/runtime/debug/DebugSession");
const debugVariableBridge_1 = require("@mablhq-internal/runtime/debug/debugVariableBridge");
async function getVariables(parsed) {
    const sessionId = parsed[constants_1.CommandArgSessionId];
    const session = (0, DebugSession_1.readSession)(sessionId);
    const variables = await (0, debugVariableBridge_1.getCurrentVariables)(sessionId, session.variables);
    process.stdout.write(JSON.stringify(variables) + '\n');
}
exports.getVariablesCommand = (0, debugCommands_1.defineLeaf)({
    command: `get-variables <${constants_1.CommandArgSessionId}>`,
    describe: 'Print current variable context as JSON. Sources from state.json when available (the canonical-tree store the rest of the debug surface speaks); falls back to session.json for legacy sessions.',
    builder: (yargs) => {
        yargs.positional(constants_1.CommandArgSessionId, {
            type: 'string',
            demandOption: true,
            describe: 'Debug session id (returned by `session start`).',
        });
    },
    handler: (0, debugFailWrapper_1.debugFailWrapper)(getVariables),
});
