/** * Small shared helpers extracted from the source repository (ISC; see LICENSE). */ export function sanitizePathSegment(value: string): string { const sanitized = value.replace(/[^a-zA-Z0-9_.-]+/g, '-').replace(/^-+|-+$/g, ''); return sanitized || 'session'; } export function stripMatchingQuotes(value: string): string { const trimmed = value.trim(); if (trimmed.length >= 2) { const first = trimmed[0]; const last = trimmed[trimmed.length - 1]; if ((first === '"' && last === '"') || (first === "'" && last === "'")) { return trimmed.slice(1, -1); } } return trimmed; } export function compactWhitespace(value: string): string { return value.replace(/\s+/gu, ' ').trim(); } export function truncateChars(value: string, maxChars: number): string { if (value.length <= maxChars) return value; return `${value.slice(0, Math.max(0, maxChars - 1))}…`; } export function normalizeTaskName(value: unknown): string | undefined { if (typeof value !== 'string') return undefined; const normalized = compactWhitespace(stripMatchingQuotes(value)); if (!normalized) return undefined; return truncateChars(normalized, 80); } export function shellQuote(value: string): string { return `'${value.replace(/'/g, `'"'"'`)}'`; }