"use strict";
/**
 * Account dispatch flow — account-based profile (work, personal) with instance isolation.
 *
 * Extracted from src/ccs.ts main() profileInfo.type === 'account' branch.
 * Uses CLAUDE_CONFIG_DIR for per-profile instance isolation on all platforms.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.runAccountFlow = void 0;
const shell_executor_1 = require("../../utils/shell-executor");
const resume_lane_warning_1 = require("../../auth/resume-lane-warning");
const shared_resource_policy_1 = require("../../auth/shared-resource-policy");
const environment_builder_1 = require("../environment-builder");
async function runAccountFlow(ctx) {
    const { profileInfo, claudeCli, nativeClaudeRemainingArgs, InstanceManager, ProfileRegistry, resolveAccountContextPolicy, isAccountContextMetadata, } = ctx;
    const registry = new ProfileRegistry();
    const instanceMgr = new InstanceManager();
    const accountMetadata = isAccountContextMetadata(profileInfo.profile)
        ? profileInfo.profile
        : undefined;
    const isBareProfile = (0, shared_resource_policy_1.isProfileLocalSharedResourceMode)(typeof profileInfo.profile === 'object' && profileInfo.profile !== null
        ? profileInfo.profile
        : undefined);
    const contextPolicy = resolveAccountContextPolicy(accountMetadata);
    // Ensure instance exists (lazy init if needed)
    const instancePath = await instanceMgr.ensureInstance(profileInfo.name, contextPolicy, {
        bare: isBareProfile,
    });
    // Update last_used timestamp (check unified config first, fallback to legacy)
    if (registry.hasAccountUnified(profileInfo.name)) {
        registry.touchAccountUnified(profileInfo.name);
    }
    else {
        registry.touchProfile(profileInfo.name);
    }
    // Execute Claude with instance isolation.
    // Skip WebSearch hook — account profiles use native server-side WebSearch.
    // Skip Image Analyzer hook — account profiles have native vision support.
    const envVars = {
        CLAUDE_CONFIG_DIR: instancePath,
        CCS_PROFILE_TYPE: 'account',
        CCS_WEBSEARCH_SKIP: '1',
        CCS_IMAGE_ANALYSIS_SKIP: '1',
    };
    await (0, resume_lane_warning_1.maybeWarnAboutResumeLaneMismatch)(profileInfo.name, instancePath, nativeClaudeRemainingArgs);
    const launchArgs = (0, environment_builder_1.resolveNativeClaudeLaunchArgs)(nativeClaudeRemainingArgs, 'account', instancePath);
    (0, shell_executor_1.execClaude)(claudeCli, launchArgs, envVars);
}
exports.runAccountFlow = runAccountFlow;
//# sourceMappingURL=account-flow.js.map