/**
 * `shep bedrock sync --app <id>`
 *
 * Dispatches RunBedrockLifecycleUseCase with action=Sync. Streams subprocess
 * output to stdout via the typed onProgress callback.
 */
import { Command } from 'commander';
import { container } from '../../../../../packages/core/src/infrastructure/di/container.js';
import { RunBedrockLifecycleUseCaseToken } from '../../../../../packages/core/src/infrastructure/di/tokens.js';
import { BedrockLifecycleAction } from '../../../../../packages/core/src/domain/generated/output.js';
import { messages } from '../../ui/index.js';
import { appOption, pipeProgressToStdout, renderBedrockError } from './shared.js';
export function createBedrockSyncCommand() {
    const cmd = new Command('sync').description('Reconcile bedrock memory with git state inside the application worktree');
    appOption(cmd).action(async (options) => {
        try {
            const useCase = container.resolve(RunBedrockLifecycleUseCaseToken);
            const result = await useCase.execute({
                applicationId: options.app,
                action: BedrockLifecycleAction.Sync,
                onProgress: pipeProgressToStdout,
            });
            if (result.exitCode !== 0) {
                messages.error(`bedrock sync failed (exit code ${result.exitCode})`);
                process.exitCode = 1;
                return;
            }
            messages.success(`Bedrock memory synced for application ${options.app}`);
        }
        catch (error) {
            renderBedrockError('Failed to sync bedrock', error);
        }
    });
    return cmd;
}
