package com.correx.apps.server.memory

import com.correx.core.tasks.KnowledgeHit
import com.correx.core.tasks.TaskKnowledgeRetriever

/**
 * Late-bound holder for the task knowledge retriever. The task tools are built at tool-registry
 * construction time, which is before the L3 retriever exists in the composition root; this holder
 * is created early, captured by the tools and the route, and has its [delegate] set once the L3
 * retriever is available. Until then (or when L3 is disabled) it returns no hits.
 */
class DeferredTaskKnowledgeRetriever : TaskKnowledgeRetriever {
    @Volatile
    var delegate: TaskKnowledgeRetriever? = null

    override suspend fun retrieve(query: String, limit: Int): List<KnowledgeHit> =
        delegate?.retrieve(query, limit) ?: emptyList()
}
