'use server';
import { resolve } from '../../lib/server-container.js';
/**
 * Rebuild the full application-creation prompt for an existing
 * application. Debug-only — lets the operator see exactly what Shep
 * handed to the agent on turn 1 of the session.
 *
 * The prompt is reconstructed from the stored description + repo path,
 * so it matches what `createApplication` would have generated at the
 * moment of creation (the builder is deterministic per input).
 */
export async function getApplicationDebugPrompt(applicationId) {
    try {
        if (!applicationId?.trim()) {
            return { error: 'applicationId is required' };
        }
        const getApp = resolve('GetApplicationUseCase');
        const application = await getApp.execute(applicationId);
        if (!application) {
            return { error: 'Application not found' };
        }
        const builder = resolve('IApplicationCreationPromptBuilder');
        const { systemPrompt, userMessage } = builder.build({
            description: application.description ?? '',
            workspace: {
                workingDirectory: application.repositoryPath,
                platform: process.platform === 'win32' ? 'windows' : 'posix',
            },
        });
        const combined = `# SYSTEM PROMPT\n\n${systemPrompt}\n\n---\n\n# USER MESSAGE\n\n${userMessage}\n`;
        return { systemPrompt, userMessage, combined };
    }
    catch (error) {
        const message = error instanceof Error ? error.message : 'Failed to build debug prompt';
        return { error: message };
    }
}
