/**
 * Plugin-Install Handoff Context Generator
 *
 * NOTE: This is the legacy plugin-INSTALL handoff (renamed from
 * `handoff-context.ts` in 0867 to free that name for the cross-tool work
 * handoff). It is unrelated to `work-handoff.ts` / `handoff-doc-format.ts`.
 *
 * Generates context information for session handoff, enabling users
 * to continue their work in a new session after plugin installation.
 *
 * The context includes:
 * - Summary of what was accomplished
 * - Original user intent
 * - List of installed plugins
 * - Available skills from those plugins
 * - Suggested continuation prompt
 *
 * @module core/session/install-handoff-context
 */
// ============================================================================
// Constants - Formatting
// ============================================================================
/** Width for section separators */
const SEPARATOR_WIDTH = 50;
/** Heavy separator for main sections */
const HEAVY_SEPARATOR = '='.repeat(SEPARATOR_WIDTH);
/** Light separator for subsections */
const LIGHT_SEPARATOR = '-'.repeat(SEPARATOR_WIDTH);
/** Section headers for formatted output */
const SECTION_HEADERS = {
    title: 'SESSION HANDOFF CONTEXT',
    projectPath: 'PROJECT PATH:',
    navigate: 'TO NAVIGATE:',
    originalIntent: 'ORIGINAL TASK/INTENT:',
    plugins: 'INSTALLED PLUGINS:',
    skills: 'AVAILABLE SKILLS/COMMANDS:',
    howToContinue: 'HOW TO CONTINUE:',
    suggestedPrompt: 'SUGGESTED PROMPT TO RESUME:',
};
/** Instructions for continuing in new session */
const CONTINUATION_INSTRUCTIONS = [
    '1. Open a new Claude Code session',
    '2. Navigate to your project directory',
    '3. Paste this context or describe your task',
    '4. The installed plugins are now active!',
];
// ============================================================================
// Constants - Plugin Skills Mapping
// ============================================================================
/**
 * Skills provided by each plugin
 *
 * This mapping provides the key skills/commands available from each
 * plugin for display in the handoff context.
 */
const PLUGIN_SKILLS = {
    'sw': [
        {
            name: 'sw:increment',
            description: 'Plan a new product increment',
            category: 'workflow',
        },
        {
            name: 'sw:do',
            description: 'Execute tasks from the current increment',
            category: 'workflow',
        },
        {
            name: 'sw:done',
            description: 'Close an increment after completion',
            category: 'workflow',
        },
        {
            name: 'sw:status',
            description: 'View all increment statuses',
            category: 'workflow',
        },
        {
            name: 'sw:progress',
            description: 'Show progress for active increments',
            category: 'workflow',
        },
    ],
    // Domain skills (frontend:*, backend:*) are optional vskill plugins.
    // Only include them in handoff if the plugin is actually installed.
    // The core sw:architect skill handles all domains by default.
    'sw-github': [
        {
            name: 'sw-github:sync',
            description: 'Sync increments with GitHub issues',
            category: 'sync',
        },
    ],
    'sw-jira': [
        {
            name: 'sw-jira:sync',
            description: 'Sync increments with JIRA issues',
            category: 'sync',
        },
    ],
    'sw-ado': [
        {
            name: 'sw-ado:sync',
            description: 'Sync increments with Azure DevOps',
            category: 'sync',
        },
    ],
    'payments': [
        {
            name: 'payments:payment-core',
            description: 'Stripe payment integration',
            category: 'payments',
        },
        {
            name: 'payments:billing',
            description: 'Subscription billing and management',
            category: 'payments',
        },
    ],
    'k8s': [
        {
            name: 'k8s:manifests',
            description: 'Kubernetes architecture and manifests',
            category: 'infrastructure',
        },
    ],
    'infra': [
        {
            name: 'infra:devops',
            description: 'DevOps and infrastructure automation',
            category: 'infrastructure',
        },
    ],
    'testing': [
        {
            name: 'testing:qa',
            description: 'QA strategy and E2E testing',
            category: 'testing',
        },
    ],
    'mobile': [
        {
            name: 'mobile:react-native',
            description: 'Mobile app architecture and React Native development',
            category: 'mobile',
        },
    ],
    'ml': [
        {
            name: 'ml:engineer',
            description: 'Machine learning and MLOps',
            category: 'ml',
        },
        {
            name: 'ml:data-scientist',
            description: 'Data analysis and notebooks',
            category: 'ml',
        },
    ],
    'sw-diagrams': [
        {
            name: 'sw-diagrams:diagrams',
            description: 'Architecture diagrams with Mermaid and C4',
            category: 'documentation',
        },
    ],
    'sw-release': [
        {
            name: 'sw-release:release-manager',
            description: 'Release management and versioning',
            category: 'release',
        },
    ],
    'confluent': [
        {
            name: 'confluent:kafka-connect',
            description: 'Confluent Kafka Connect integration',
            category: 'streaming',
        },
    ],
    'kafka': [
        {
            name: 'kafka:architect',
            description: 'Apache Kafka event streaming',
            category: 'streaming',
        },
    ],
    // NOTE: sw-router REMOVED v1.0.204 - detect-intent now handles routing
};
// ============================================================================
// Helper Functions
// ============================================================================
/**
 * Normalize a path by replacing home directory with ~
 *
 * @param projectPath - Full project path
 * @param userHome - User's home directory
 * @returns Normalized path with ~ for home
 */
function normalizePath(projectPath, userHome) {
    if (!userHome) {
        return projectPath;
    }
    if (projectPath.startsWith(userHome)) {
        return '~' + projectPath.slice(userHome.length);
    }
    return projectPath;
}
/**
 * Get all skills for a list of plugins
 *
 * @param plugins - List of plugin names
 * @returns Array of skills from all plugins
 */
function getSkillsForPlugins(plugins) {
    const skills = [];
    for (const plugin of plugins) {
        const pluginSkills = PLUGIN_SKILLS[plugin];
        if (pluginSkills) {
            skills.push(...pluginSkills);
        }
    }
    return skills;
}
/**
 * Generate a summary based on installed plugins
 *
 * @param plugins - Installed plugins
 * @returns Summary string
 */
function generateSummary(plugins) {
    if (plugins.length === 0) {
        return 'Session completed with no plugins installed.';
    }
    const pluginCount = plugins.length;
    const pluginWord = pluginCount === 1 ? 'plugin' : 'plugins';
    return `Installed ${pluginCount} ${pluginWord} (${plugins.join(', ')}) to enable new capabilities.`;
}
/**
 * Generate a continuation prompt based on context
 *
 * @param originalIntent - Original user intent
 * @param plugins - Installed plugins
 * @param projectPath - Project path
 * @returns Suggested continuation prompt
 */
function generateContinuationPrompt(originalIntent, plugins, projectPath) {
    const parts = [];
    parts.push('I want to continue working on my project.');
    if (projectPath) {
        parts.push(`The project is at: ${projectPath}`);
    }
    if (originalIntent) {
        parts.push(`My original task was: ${originalIntent}`);
    }
    if (plugins && plugins.length > 0) {
        parts.push(`I now have these plugins installed: ${plugins.join(', ')}`);
    }
    parts.push('Please help me proceed.');
    return parts.join(' ');
}
// ============================================================================
// Main Functions
// ============================================================================
/**
 * Generate handoff context for session continuation
 *
 * Creates a structured context object containing all the information
 * needed to continue work in a new session.
 *
 * @param options - Context generation options
 * @returns Generated handoff context
 *
 * @example
 * ```typescript
 * const context = generateHandoffContext({
 *   plugins: ['sw', 'frontend'],
 *   projectPath: '/path/to/project',
 *   originalIntent: 'Create React dashboard'
 * });
 * console.log(context.continuationPrompt);
 * ```
 */
export function generateHandoffContext(options) {
    const { plugins, projectPath, originalIntent, userHome } = options;
    const normalizedPath = projectPath
        ? normalizePath(projectPath, userHome)
        : undefined;
    const availableSkills = getSkillsForPlugins(plugins);
    const summary = generateSummary(plugins);
    const continuationPrompt = generateContinuationPrompt(originalIntent, plugins, projectPath);
    return {
        summary,
        originalIntent,
        plugins,
        projectPath,
        normalizedPath,
        availableSkills,
        continuationPrompt,
    };
}
/**
 * Format handoff context as copy-paste ready text
 *
 * Creates a formatted text block that users can copy and paste
 * into a new session to provide context.
 *
 * @param options - Context generation options
 * @returns Formatted text ready for copy-paste
 *
 * @example
 * ```typescript
 * const text = formatHandoffText({
 *   plugins: ['sw', 'frontend'],
 *   projectPath: '/path/to/project',
 *   originalIntent: 'Create React dashboard'
 * });
 * console.log(text); // Copy-paste ready context
 * ```
 */
export function formatHandoffText(options) {
    const context = generateHandoffContext(options);
    const lines = [];
    // === Header ===
    lines.push(HEAVY_SEPARATOR);
    lines.push(SECTION_HEADERS.title);
    lines.push(HEAVY_SEPARATOR);
    lines.push('');
    // === Project Section ===
    if (context.projectPath) {
        lines.push(SECTION_HEADERS.projectPath);
        lines.push(`  ${context.projectPath}`);
        if (context.normalizedPath && context.normalizedPath !== context.projectPath) {
            lines.push(`  (or: ${context.normalizedPath})`);
        }
        lines.push('');
        lines.push(SECTION_HEADERS.navigate);
        lines.push(`  cd ${context.projectPath}`);
        lines.push('');
    }
    // === Original Intent Section ===
    if (context.originalIntent) {
        lines.push(SECTION_HEADERS.originalIntent);
        lines.push(`  ${context.originalIntent}`);
        lines.push('');
    }
    // === Plugins Section ===
    if (context.plugins.length > 0) {
        lines.push(SECTION_HEADERS.plugins);
        for (const plugin of context.plugins) {
            lines.push(`  - ${plugin}`);
        }
        lines.push('');
    }
    // === Available Skills Section ===
    if (context.availableSkills.length > 0) {
        lines.push(SECTION_HEADERS.skills);
        for (const skill of context.availableSkills) {
            lines.push(`  - ${skill.name}: ${skill.description}`);
        }
        lines.push('');
    }
    // === Instructions Section ===
    lines.push(LIGHT_SEPARATOR);
    lines.push(SECTION_HEADERS.howToContinue);
    CONTINUATION_INSTRUCTIONS.forEach((instruction) => {
        lines.push(`  ${instruction}`);
    });
    lines.push('');
    // === Continuation Prompt Section ===
    lines.push(SECTION_HEADERS.suggestedPrompt);
    lines.push(`  "${context.continuationPrompt}"`);
    lines.push('');
    // === Footer ===
    lines.push(HEAVY_SEPARATOR);
    return lines.join('\n');
}
//# sourceMappingURL=install-handoff-context.js.map