export class FileMemory {
    segments = [];
    maxSegments;
    constructor(maxSegments = 3) {
        this.maxSegments = Math.max(1, maxSegments);
    }
    ingestFromTool(toolName, args, resultText, turn) {
        const path = this.extractPath(toolName, args);
        if (!path) {
            return;
        }
        const snippet = resultText.trim().slice(0, 400);
        if (!snippet) {
            return;
        }
        const segment = { path, snippet, turn };
        this.segments = [segment, ...this.segments.filter((existing) => existing.path !== path)].slice(0, this.maxSegments);
    }
    getActiveSegments() {
        return [...this.segments];
    }
    extractPath(toolName, args) {
        if (!args || typeof args !== "object") {
            return undefined;
        }
        const record = args;
        if (toolName === "read" || toolName === "write" || toolName === "edit") {
            const path = record.path ?? record.file_path;
            return typeof path === "string" && path.trim().length > 0 ? path : undefined;
        }
        if (toolName === "grep" || toolName === "find" || toolName === "ls") {
            const path = record.path;
            return typeof path === "string" && path.trim().length > 0 ? path : undefined;
        }
        return undefined;
    }
}
//# sourceMappingURL=file-memory.js.map