Skip to content

MCP + CLI session-recall surface: filters, pagination, resources #540

Closed

Description

@Sinity

Problem

Companion to #539. Once realtime ingestion lands, conversations are in the archive within seconds. The remaining gap is the recall surface — how a fresh Claude Code (or Codex) session in a project repo reaches recent-session context without a human pasting chatlog excerpts, and how the archive is queryable for power workflows beyond recall.

The MCP surface (`polylogue/mcp/`) already has `search`, `list_conversations` (rich filter chain), `get_conversation` (projection flags), `neighbor_candidates`, `session_profile`, `archive_coverage`, `get_session_tree`, `stats`. The fragmentation isn't in coverage — it's in parameter language: filter chain lives only on `list_conversations`, projections only on `get_conversation`, and projection flags are individual booleans rather than a coherent set. The CLI mirrors this fragmentation.

This issue is a clean revamp — no backwards-compatibility shims, no deprecation paths. Names that are wrong get renamed; flags that don't compose get unified.

Real gaps for session-recall

  1. `cwd_prefix` filter missing. The current `path` parameter on `list_conversations` filters by file paths referenced in conversations (via tool_use). There's no filter on the working directory the session ran in. Claude Code records carry `cwd`; never indexed as a pushdown. Required for "sessions in this repo."
  2. `path` is overloaded. Rename to `referenced_path` to distinguish from the new `cwd_prefix`.
  3. Recaps not surfaceable. Claude Code emits `type=summary` records (mid-session compaction summaries). They're regular messages with a distinct type — already in the archive — but `message_type` isn't a filter primitive on read paths. Once it is, `get_messages(id, message_type=summary)` returns recaps. No special table, no special tool — they are messages.
  4. No paginated message access. `get_conversation` returns whole conversations including all messages — too much for long sessions. Need `get_messages(id, ..., limit, offset)`.

Power axes (in scope)

  • `since_session(id)` filter — "everything in this cwd after that session." Common workflow.
  • `raw_records(id, limit, offset)` — paginated raw provider records (debugging, fidelity-preserving views).
  • MCP resources for stable URIs (cheaper than tool calls; LLM clients can attach as context):
    • `polylogue://conversation/{id}`
    • `polylogue://messages/{id}`
    • `polylogue://session-tree/{id}`
    • `polylogue://provider/{name}/recent`

Power axes deferred to follow-up issues

These are noted here so they're not lost. Each gets a separate issue when there's demand:

  • Saved/named filter chains — persisted, callable by name from CLI/MCP.
  • `compare(id_a, id_b)` — diff two conversations (shared topics, divergent paths).
  • Topic similarity beyond `neighbor_candidates` — alternate similarity strategies.
  • Dedicated file-touch index — currently subsumed by `referenced_path` filter via tool_use action records.

Solution

Filter chain (CLI + MCP, identical parameter names)

Extend `ConversationFilter` (`lib/filters.py`); CLI flags and MCP params propagate from there.

  • `cwd_prefix(path)` — new pushdown. Codex parity contingent on whether codex records carry cwd; investigate during impl. If absent for codex, document as Claude-Code-only.
  • `referenced_path(path_terms)` — rename of current `path`.
  • `message_type(types)` — first-class read-path filter (currently partial / role-centric). Surface `summary`, `tool_use`, `tool_result`, `thinking`.
  • `since_session(conversation_id)` — "newer than this session's most-recent message timestamp, same cwd or unscoped per the surrounding filter."

Projection (granular flags, consistent across read tools)

Keep granular flags only — they compose. No `mode` enum.

  • `no_code_blocks`, `no_tool_calls`, `no_tool_outputs`, `no_file_reads`, `prose_only`
  • `message_role` (already exists)
  • `message_type` (new — see filter chain above)

These apply consistently to `get_conversation`, `get_messages`, `raw_records`.

Pagination

`limit` + `offset` on every read tool returning lists:

  • `list_conversations` (already has limit; add offset)
  • `get_messages` (new)
  • `raw_records` (new)
  • `get_session_tree` (add)

`get_conversation` returns header + summary stats (no message body); message body goes through `get_messages`. This is a clean shape change — old shape is dropped without a compat path.

New MCP tools

  • `get_messages(conversation_id, *, message_role=None, message_type=None, no_code_blocks=False, no_tool_calls=False, no_tool_outputs=False, no_file_reads=False, prose_only=False, limit=50, offset=0)` — paginated, projected message list.
  • `raw_records(conversation_id, *, limit=50, offset=0)` — paginated raw provider records.

MCP resources

  • `polylogue://conversation/{id}` — header + stats.
  • `polylogue://messages/{id}` — first page of messages, default projection.
  • `polylogue://session-tree/{id}` — existing tree.
  • `polylogue://provider/{name}/recent` — recent N for one provider.

CLI revamp (same scope)

CLI mirrors MCP. Concrete changes:

  • New flags: `--cwd-prefix`, `--since-session`, `--message-type`, `--offset`.
  • Rename: `--path` → `--referenced-path`.
  • Verify projection flags exist on relevant verbs (`show`, `list`).
  • New verbs (or option on existing): `messages ` (paginated), `raw ` (paginated raw).

Schema

No new tables. `message_type` filter pushdown may need an index if the existing schema doesn't support it efficiently (existing precomputed columns include `has_thinking`, `has_tool_use` — adding `type` direct filter is a small extension).

Acceptance

  1. `--cwd-prefix` end-to-end (CLI + MCP), tested against real Claude Code records.
  2. `--path` → `--referenced-path` rename complete; no `path` synonym remains.
  3. `get_messages(id, message_type=summary)` returns Claude Code recap records.
  4. `get_messages` + `raw_records` paginated tools functional with consistent projection flags.
  5. MCP resources: 4 URIs listed above resolve.
  6. `--since-session ID` works.
  7. CLI flag names match MCP param names exactly.
  8. Tests for each filter, projection, pagination, resource.

Verification

```bash

session-recall workflow

nix develop -c polylogue --cwd-prefix /realm/project/polylogue --order recent --limit 3 list
nix develop -c polylogue messages --message-role user --limit 5
nix develop -c polylogue messages --message-type summary # recaps

pagination

nix develop -c polylogue messages --limit 50 --offset 0
nix develop -c polylogue messages --limit 50 --offset 50

MCP resource resolution (via test client)

nix develop -c pytest -q tests/unit/mcp/

devtools verify

nix develop -c devtools verify
```

Depends on

Follow-ups

  • Sinnix sibling PR: SessionStart hook invoking the new query surface; global CLAUDE.md instruction.

Activity

  1. changed the title [-]Session-recall MCP surface: generic session lookup, recap capture, context injection[/-] [+]MCP + CLI session-recall surface: filters, pagination, resources[/+] on Apr 27, 2026
  2. Sinity commented on Apr 27, 2026

    @Sinity
    OwnerAuthor

    Adding to deferred axes above: Saved/named projections — same as named filter chains, but for projection presets (e.g., "my-default-recap-view" = message_role=user,assistant + no_tool_calls + no_tool_outputs). Combine with named filters for callable composed views. Separate follow-up issue alongside saved filters.

  3. Sinity commented on Apr 27, 2026

    @Sinity
    OwnerAuthor

    First slice landed via #543: cwd_prefix filter end-to-end (spec → plan → record_query → SQL pushdown → CLI --cwd-prefix → MCP cwd_prefix param). Tests: 11 covering full chain + escape behaviour. The MCP wire-schema witness (tests/data/witnesses/mcp-tool-schemas.json) has been regenerated.

    Codex parity: codex records carry git.repository_url not cwd. cwd_prefix matches Claude Code only until a codex-side cwd-extraction lands.

    Remaining acceptance items from issue body:

    • path → referenced_path clean rename (no compat shim).
    • message_type first-class read filter (recaps queryable via get_messages(id, message_type=summary)).
    • since_session(id) filter.
    • Paginated get_messages(id, ..., limit, offset) MCP tool + CLI verb.
    • Paginated raw_records(id, limit, offset) MCP tool + CLI verb.
    • MCP resources: polylogue://conversation/{id}, polylogue://messages/{id}, polylogue://session-tree/{id}, polylogue://provider/{name}/recent.
    • CLI mirror for above (flag/verb names match MCP params).
  4. Sinity commented on Apr 29, 2026

    @Sinity
    OwnerAuthor

    Already implemented. All requested features exist in the current codebase:

    • cwd_prefix filter — SQL pushdown via JSON_EXTRACT on provider_meta (lib/filter/builder.py)
    • referenced_path rename — CLI flag, MCP param, and filter method all use this name
    • message_type filter — first-class filter on messages and conversations
    • since_session filter — time+CWD-based filtering
    • Pagination — limit + offset on all read tools
    • get_messages MCP tool — paginated, projected message list (mcp/server_tools.py:242)
    • raw_records MCP tool — paginated raw provider records (mcp/server_tools.py:303)
    • MCP resources — all 4 URIs exist (conversation/{id}, messages/{id}, session-tree/{id}, provider/{name}/recent)
    • CLI flags — --cwd-prefix, --since-session, --message-type, --offset all wired in click_option_groups.py
  5. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    2026-05-01 query/read supersession note

    This issue is closed and should stay closed as historical session-recall surface work, but current read-surface naming is now owned by #621/#635.

    Target read commands:

    polylogue search
    polylogue list
    polylogue show
    polylogue messages
    polylogue raw-artifacts
    

    raw_records should not remain the public/API name for current raw artifact behavior. Reserve provider_records for true per-provider-event paging. Machine output is --format json only; do not preserve --json aliases.

    Ref #621
    Ref #635

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

    area:mcptype:feat

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions