"use strict";
/**
 * Shell-quoting and validation helpers.
 * Used by all agent shims to safely quote values for tmux launch commands.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.quotePath = void 0;
exports.quoteValue = quoteValue;
exports.validateValue = validateValue;
const SHELL_METACHARACTERS = /[$\`;|&<>()\\"']/;
class InvalidValueError extends Error {
    constructor(field, value) {
        super(`Invalid ${field}: contains shell metacharacters. ` +
            `Got: ${value}`);
        this.name = 'InvalidValueError';
    }
}
/**
 * Quote a string for safe use in shell commands (bash %q equivalent).
 * Uses single-quote wrapping with escaped embedded quotes.
 * Safe to pass to `tmux new-session -d -s <name> "..."`.
 */
function quoteValue(s) {
    // Wrap in single quotes, escape any embedded single quotes
    return `'${s.replace(/'/g, `'\\''`)}'`;
}
/**
 * Quote a filesystem path for safe use in shell commands.
 * Identical to quoteValue; kept separate for semantic clarity.
 */
exports.quotePath = quoteValue;
/**
 * Validate a value against shell metacharacters.
 * Throws InvalidValueError if validation fails.
 * Use BEFORE building launch commands to catch bad input early.
 */
function validateValue(field, value) {
    if (value === undefined || value === '') {
        return; // empty/undefined is OK
    }
    if (SHELL_METACHARACTERS.test(value)) {
        throw new InvalidValueError(field, value);
    }
}
//# sourceMappingURL=quote.js.map