Skip to content

feat: expose evidence-bearing search hits in CLI and MCP #216

Closed

Description

@Sinity

Outcome

Search results should carry enough evidence by default for a user to confirm whether a hit is the conversation they meant, without immediately opening the full conversation.

At minimum, the result contract should be able to expose:

  • matched snippet or excerpt
  • matched message id when relevant
  • match surface or provenance such as title hit, message FTS hit, action hit, attachment hit, hybrid fusion, or semantic lane
  • the retrieval lane used when it materially affects interpretation

Problem or opportunity

The archive substrate already knows more than the public search surfaces expose.

polylogue/storage/search_query_builders.py and polylogue/storage/search_runtime.py already support snippet-producing ranked search over message FTS. polylogue/operations/archive.py can also adapt hydrated conversations into SearchHit records with snippets.

The main discovery surfaces currently discard that evidence:

  • CLI summary-list routing prefers list_summaries() in polylogue/cli/query.py
  • summary rendering in polylogue/cli/query_output.py shows only id/date/provider/title/message count
  • MCP search in polylogue/mcp/server_tools.py returns MCPConversationSummaryPayload, which has no snippet or match provenance

This makes Polylogue strong once a conversation is already identified, but weaker at fuzzy confirmation when several conversations have similar titles or nearby dates.

Expected scope

  • polylogue/cli/query.py
  • polylogue/cli/query_output.py
  • polylogue/mcp/server_tools.py
  • polylogue/mcp/payloads.py
  • polylogue/operations/archive.py
  • polylogue/storage/search_runtime.py
  • polylogue/storage/search_query_builders.py
  • tests under tests/unit/cli/, tests/unit/mcp/, and tests/unit/storage/

Constraints and invariants

  • Keep exact-id retrieval behavior unchanged.
  • Preserve a lightweight summary-list mode for workflows that want compact browsing rather than evidence-bearing hits.
  • Do not force full conversation hydration for every search if the evidence can be sourced from cheaper ranked-hit paths.
  • Keep CLI and MCP result semantics aligned enough that they do not drift into unrelated search contracts.

Acceptance criteria

  • Polylogue defines a first-class search-hit result contract separate from bare conversation summaries.
  • CLI search can show a matched excerpt by default or via a clearly documented evidence-bearing mode.
  • MCP search exposes snippet or excerpt evidence and match provenance, not only summary rows.
  • Search-hit payloads can identify the matched message when relevant.
  • Tests cover snippet-bearing hits and match-provenance fields across CLI and MCP surfaces.

Verification plan

  • add storage-level tests for ranked hit payload fields
  • add CLI output tests for evidence-bearing search rendering
  • add MCP contract tests for search-hit payload shape
  • run devtools verify

Context and evidence

Relevant files:

  • polylogue/storage/search_query_builders.py
  • polylogue/storage/search_runtime.py
  • polylogue/operations/archive.py
  • polylogue/cli/query.py
  • polylogue/cli/query_output.py
  • polylogue/mcp/server_tools.py
  • polylogue/mcp/payloads.py

Non-goals or explicitly deferred work

  • Full absence diagnosis; that belongs in a separate issue.
  • Attachment-id indexing; that belongs in a separate issue.
  • Near-duplicate discovery; that belongs in a separate issue.

Activity

  1. Sinity commented on Apr 22, 2026

    @Sinity
    OwnerAuthor

    Starting #216.

    Tactic:

    • Preserve exact-id and compact list behavior where there is no text-search evidence to expose.
    • Introduce one shared surface search-hit payload rather than separate CLI/MCP shapes.
    • Reuse ranked message FTS snippets when available; derive fallback evidence from hydrated conversations for action/hybrid paths.
    • Keep machine-readable outputs explicit by emitting hit payloads with summary + match fields, while plain output gets a concise evidence line.
    • Add storage/CLI/MCP contract tests before PR.
  2. Sinity commented on Apr 22, 2026

    @Sinity
    OwnerAuthor

    Progress update for #216:

    Implemented the shared evidence-bearing search-hit path across the main surfaces:

    • Added ConversationSearchHit as the canonical archive/CLI/MCP hit contract.
    • Added storage-ranked ConversationSearchEvidenceHit so simple message FTS searches preserve rank, score, message id, snippet, match surface, and retrieval lane without full hydration.
    • Added repository/archive operation support through search_summary_hits() and search_conversation_hits().
    • Rewired CLI list/search rendering to emit conversation identity plus match evidence for machine/plain/rich output.
    • Rewired MCP search to return evidence-bearing hit payloads while keeping list_conversations on compact summaries.
    • Documented the new search result evidence shape in README/library/MCP docs.

    Focused verification so far:

    ruff check polylogue/lib/search_hits.py polylogue/lib/query_search_hits.py polylogue/cli/query.py polylogue/cli/query_output.py polylogue/mcp/payloads.py polylogue/mcp/server_tools.py polylogue/operations/archive.py polylogue/protocols.py polylogue/storage/backends/queries/conversations_search.py polylogue/storage/backends/query_store_archive.py polylogue/storage/repository_archive_search.py polylogue/storage/search_models.py polylogue/surface_payloads.py tests/unit/storage/test_archive_search_contracts.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_query_exec_laws.py tests/unit/mcp/test_tool_contracts.py
    pytest -q tests/unit/storage/test_archive_search_contracts.py tests/unit/cli/test_query_fmt.py::TestListFormatting::test_format_search_hit_list_contract tests/unit/cli/test_query_exec_laws.py::test_async_execute_query_summary_list_uses_evidence_hits_for_search_contract tests/unit/mcp/test_tool_contracts.py::TestQueryTools
    pytest -q tests/unit/cli/test_query_fmt.py tests/unit/cli/test_query_exec_laws.py tests/unit/mcp/test_tool_contracts.py tests/unit/storage/test_archive_search_contracts.py
    mypy polylogue/
    devtools render-all --check

    Next: run devtools verify, then commit/push/open PR if the baseline is clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions