package com.correx.apps.server.memory

import com.correx.apps.server.health.SYSTEM_SESSION
import com.correx.core.kernel.orchestration.RepoKnowledgeRetriever
import com.correx.core.tasks.KnowledgeHit
import com.correx.core.tasks.TaskKnowledgeRetriever

/**
 * Bridges the task context bundle's [TaskKnowledgeRetriever] port to the existing L3 vector
 * retriever ([RepoKnowledgeRetriever], typically [L3RepoKnowledgeRetriever]). Tasks are not
 * session-scoped for retrieval, so the system session is used (the L3 repo retriever ignores it).
 */
class RepoKnowledgeTaskRetriever(
    private val delegate: RepoKnowledgeRetriever,
) : TaskKnowledgeRetriever {
    override suspend fun retrieve(query: String, limit: Int): List<KnowledgeHit> =
        delegate.retrieve(SYSTEM_SESSION, query, limit)
            .map { KnowledgeHit(source = it.path, text = it.text, score = it.score.toDouble()) }
}
