"""Search memory (simple keyword match)."""

from _store import search_namespace

from core.pathways.context import Context
from core.pathways.models.tool import ToolOutput


async def run(
    query: str,
    namespace: str = "default",
    limit: int = 10,
    _context: Context | None = None,
) -> ToolOutput:
    """
    Search memory for matching entries.

    Args:
        query: Search query (simple keyword match)
        namespace: Memory namespace to search
        limit: Maximum results to return
        context: Execution context

    Returns
    -------
        {"results": [{"key": str, "value": Any, "score": float}]}
    """
    if not query:
        return ToolOutput(success=False, error="query is required")

    results = search_namespace(namespace, query, limit)

    return ToolOutput(
        success=True,
        data={
            "query": query,
            "namespace": namespace,
            "results": results,
            "total": len(results),
        },
    )
