/**
 * studiograph commit
 *
 * Git commit entity changes across workspace repos.
 * Works after enrich run, manual edits, or any other modification.
 */
import { Command } from 'commander';
import { Workspace } from '../../core/workspace.js';
import { WorkspaceManager } from '../../core/workspace-manager.js';
import { header, dimText, error as errorColor } from '../colors.js';
export const commitCommand = new Command('commit')
    .description('Git commit entity changes across workspace repos')
    .option('--message <prefix>', 'Commit message prefix (default: "update")')
    .option('--config', 'Also commit .studiograph/ config repo changes')
    .action(async (opts) => {
    const workspace = new Workspace(process.cwd());
    if (!workspace.isWorkspace()) {
        console.error('Not in a Studiograph workspace.');
        process.exit(1);
    }
    try {
        const config = await workspace.loadConfig();
        const gitUser = { id: 'system', name: 'system', email: 'system@local' };
        const manager = new WorkspaceManager(process.cwd(), config, gitUser);
        const messagePrefix = opts.message ?? 'update';
        let committed = false;
        const repoNames = manager.getRepoNames();
        for (const name of repoNames) {
            try {
                const graph = manager.getGraph(name);
                const git = graph.gitService;
                if (!git)
                    continue;
                const status = await git.status();
                if (status && status.length > 0) {
                    await git.commitAll(`${messagePrefix}: ${name}`, gitUser);
                    console.log(dimText(`Git commit: ${name} (${status.length} changes)`));
                    committed = true;
                }
            }
            catch {
                // Skip individual repo failures
            }
        }
        if (committed) {
            console.log(`\n${header('Done.')} Changes committed.`);
        }
        else {
            console.log('No uncommitted changes in any repo.');
        }
    }
    catch (err) {
        console.error(errorColor('Commit failed:'), err instanceof Error ? err.message : String(err));
        process.exit(1);
    }
});
//# sourceMappingURL=commit.js.map