/**
 * Session management helpers for agent execution
 */
import { loadPersonaSessions, updatePersonaSession, resolveWorkflowConfigValue } from '../../../infra/config/index.js';
/**
 * Execute a function with agent session management.
 * Automatically loads existing session and saves updated session ID.
 */
export async function withPersonaSession(cwd, personaName, fn, provider) {
    const resolvedProvider = provider ?? resolveWorkflowConfigValue(cwd, 'provider');
    const sessions = loadPersonaSessions(cwd, resolvedProvider);
    const sessionId = sessions[personaName];
    const result = await fn(sessionId);
    if (result.sessionId) {
        updatePersonaSession(cwd, personaName, result.sessionId, resolvedProvider);
    }
    return result;
}
//# sourceMappingURL=session.js.map