// cli/commands/audit.ts — planu audit [--path .] (SPEC-124)
import { parseArgs } from 'node:util';
import { resolve } from 'node:path';
import { handleAudit } from '../../tools/audit.js';
import { formatToolResult } from '../formatter.js';
import { detectProjectId } from '../project-detector.js';
import { red } from '../colors.js';
export const auditCommand = {
    name: 'audit',
    description: 'Audit the current project',
    usage: 'planu audit [debt] [--path .] [--project-id ID] [--spec SPEC-001]',
    async run(args, flags) {
        const { values } = parseArgs({
            args,
            options: {
                path: { type: 'string', short: 'p' },
                'project-id': { type: 'string' },
                spec: { type: 'string', short: 's' },
            },
            strict: false,
            allowPositionals: true,
        });
        const path = resolve(values.path ?? process.cwd());
        const projectId = values['project-id'] ?? detectProjectId(path);
        const result = await handleAudit({
            path,
            projectId,
            specId: values.spec ?? undefined,
        });
        if (result.isError) {
            process.stderr.write(`${red(formatToolResult(result, flags))}\n`);
            process.exitCode = 1;
            return;
        }
        const output = formatToolResult(result, flags);
        if (output) {
            process.stdout.write(output + '\n');
        }
    },
};
//# sourceMappingURL=audit.js.map