"use strict";
// =============================================================================
// Pure Agent - File Operation Result Types
// Ported from Hermes tools/file_operations.py dataclasses
// =============================================================================
Object.defineProperty(exports, "__esModule", { value: true });
exports.readError = readError;
exports.writeError = writeError;
exports.patchError = patchError;
exports.searchError = searchError;
exports.toolResult = toolResult;
exports.toolError = toolError;
exports.isImageFile = isImageFile;
exports.isBinaryFile = isBinaryFile;
exports.detectLineEnding = detectLineEnding;
exports.normalizeLineEndings = normalizeLineEndings;
// ---------------------------------------------------------------------------
// Helper: create error result
// ---------------------------------------------------------------------------
function readError(message) {
    return {
        content: '',
        totalLines: 0,
        fileSize: 0,
        truncated: false,
        isBinary: false,
        isImage: false,
        error: message,
    };
}
function writeError(message) {
    return {
        bytesWritten: 0,
        dirsCreated: false,
        error: message,
    };
}
function patchError(message) {
    return {
        success: false,
        diff: '',
        filesModified: [],
        error: message,
    };
}
function searchError(message) {
    return {
        matches: [],
        totalCount: 0,
        truncated: false,
        error: message,
    };
}
// ---------------------------------------------------------------------------
// Helper: JSON result serialization (matching Hermes pattern)
// ---------------------------------------------------------------------------
function toolResult(data) {
    return JSON.stringify(data);
}
function toolError(message, extra) {
    return JSON.stringify({ error: message, ...extra });
}
// ---------------------------------------------------------------------------
// Image extension detection
// ---------------------------------------------------------------------------
const IMAGE_EXTENSIONS = new Set([
    '.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp', '.svg', '.ico', '.tiff', '.tif',
]);
const BINARY_EXTENSIONS = new Set([
    '.exe', '.dll', '.so', '.dylib', '.bin', '.dat', '.db', '.sqlite', '.sqlite3',
    '.pyc', '.pyo', '.class', '.o', '.obj', '.a', '.lib', '.zip', '.tar', '.gz',
    '.bz2', '.7z', '.rar', '.pdf', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx',
    '.mp3', '.mp4', '.wav', '.avi', '.mkv', '.mov', '.flv', '.wmv', '.wma', '.ogg',
    '.flac', '.aac', '.ttf', '.otf', '.woff', '.woff2', '.eot',
]);
function isImageFile(filepath) {
    const ext = getFileExtension(filepath).toLowerCase();
    return IMAGE_EXTENSIONS.has(ext);
}
function isBinaryFile(filepath) {
    const ext = getFileExtension(filepath).toLowerCase();
    return BINARY_EXTENSIONS.has(ext);
}
function getFileExtension(filepath) {
    const idx = filepath.lastIndexOf('.');
    return idx >= 0 ? filepath.substring(idx) : '';
}
// ---------------------------------------------------------------------------
// Line ending detection
// ---------------------------------------------------------------------------
function detectLineEnding(sample) {
    const crlfCount = (sample.match(/\r\n/g) || []).length;
    const lfOnlyCount = (sample.match(/(?<!\r)\n/g) || []).length;
    if (crlfCount > 0 && crlfCount >= lfOnlyCount)
        return '\r\n';
    if (lfOnlyCount > 0)
        return '\n';
    return null;
}
function normalizeLineEndings(text, target) {
    if (target === '\r\n') {
        return text.replace(/\r\n/g, '\n').replace(/\n/g, '\r\n');
    }
    return text.replace(/\r\n/g, '\n');
}
//# sourceMappingURL=result-types.js.map