/**
 * ids.mjs — task-id generation + path helpers (C29).
 */
import { join, resolve } from 'node:path';
/**
 * Format a date according to user preferences.
 * Supported formats: YY-MM-DD (default, sorts chronologically), DD-MM-YY, MM-DD-YY
 * Uses hyphens as separators for filesystem safety.
 */
export function formatDateForTask(dateFormat, now = new Date()) {
    const yy = String(now.getFullYear()).slice(2);
    const mm = String(now.getMonth() + 1).padStart(2, '0');
    const dd = String(now.getDate()).padStart(2, '0');
    switch (dateFormat) {
        case 'DD-MM-YY':
            return `${dd}-${mm}-${yy}`;
        case 'MM-DD-YY':
            return `${mm}-${dd}-${yy}`;
        case 'YY-MM-DD':
        default:
            return `${yy}-${mm}-${dd}`;
    }
}
/**
 * Generate a short task ID from description + timestamp.
 * Format: {slug}_{date}
 * Slug comes first so task lists scan by verb instead of by date.
 * Date format is configurable via preferences.date_format in config.
 * Same-day same-slug collisions are disambiguated by the caller
 * (see commands/task.mjs) via a numeric -2, -3, … suffix; this
 * generator never emits a counter or a random hash.
 */
export function generateTaskId(description, config, now = new Date()) {
    const slug = description
        .toLowerCase()
        .replace(/[^a-z0-9]+/g, '-')
        .slice(0, 40)
        .replace(/^-|-$/g, '') || 'task';
    const dateFormat = config?.preferences?.date_format || 'YY-MM-DD';
    const date = formatDateForTask(dateFormat, now);
    return `${slug}_${date}`;
}
export function getTaskDir(projectDir, taskId) {
    return join(resolve(projectDir), '.aperant', 'tasks', taskId);
}
/**
 * C28 — scope-aware proof directory.
 * Returns `.aperant/proof/{scope}/{task-id}/` for proof evidence that belongs
 * to a specific task. Callers pass the task's scope (from state.active_tasks)
 * so unseeded tasks default cleanly.
 */
export function getProofDir(projectDir, scope, taskId) {
    const resolvedScope = (scope || 'project').trim() || 'project';
    return join(resolve(projectDir), '.aperant', 'proof', resolvedScope, taskId);
}
//# sourceMappingURL=ids.mjs.map