Skip to content

fix(export): apply --message-role / --dialogue-only to single export - #462

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/export-message-role
Apr 26, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/export-message-role

Conversation

@Sinity

@Sinity Sinity commented Apr 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #406. Stacked on #461.

Problem

The single-conversation export command silently ignored root-level
--message-role and --dialogue-only flags. Users had to dump full
JSON and post-filter in Python to extract user-only prose:

polylogue --message-role user export <id> --format json
# returns full message list, ignoring --message-role

Solution

Wires the flags through the same helper the verbs use:
conversation.with_roles(roles). Honors --message-role (one or
more roles); when --dialogue-only is set without an explicit role
filter, defaults to user+assistant.

Verification

tests/unit/cli/test_export.py covers both paths against a synthetic
conversation with mixed roles (user / assistant / system).
devtools verify (full): all checks pass.

@coderabbitai

coderabbitai Bot commented Apr 26, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR implements message-role and dialogue-only filtering for the export command. The implementation retrieves filters from the parent Click context and applies them to conversations before output formatting, resolving the issue where these flags were silently ignored during exports.

Changes

Cohort / File(s) Summary
Documentation
docs/verification-catalog.md
Updated source line reference for polylogue export command from :13 to :29 to reflect the expanded function definition.
Core Implementation
polylogue/cli/commands/export.py
Modified export command to accept Click context instead of environment directly, extract environment from context object, and apply message-role filtering via conversation.with_roles() based on --message-role or --dialogue-only flags before formatting output.
Test Coverage
tests/unit/cli/test_export.py
Added two test functions validating filter behavior: one verifying --message-role user exports only user-role messages, another confirming --dialogue-only exports exclusively user and assistant roles, both parsing JSON output to assert role sets.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 The export now filters with thoughtful care,
Message-roles dancing through the air,
No Python loops to round-trip and stall,
Context-passing connects it all! ✨
User prose flows pure, as filters align,
The CLI now works exactly as designed.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: applying --message-role and --dialogue-only flags to the single export command.
Linked Issues check ✅ Passed Code changes fully address issue #406 by wiring --message-role and --dialogue-only flags to the export command via conversation.with_roles() helper.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing message-role filtering for export; documentation and tests appropriately updated to reflect the new functionality.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The pull request description is well-structured and covers all required sections with clear context about the problem, solution, and verification.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/export-message-role

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Base automatically changed from feature/fix/embed-cli-pipeline-cycle to master April 26, 2026 18:00
Closes #406.

The single-conversation ``export`` command silently ignored root-level
``--message-role`` and ``--dialogue-only`` flags. Users had to dump full
JSON and post-filter in Python to extract user-only prose.

Wires the flags through the same helper the verbs use:
``conversation.with_roles(roles)``. Honors ``--message-role`` (one or
more roles) and falls back to user+assistant when ``--dialogue-only`` is
set.

Verification: tests/unit/cli/test_export.py covers both paths against
a synthetic conversation with mixed roles.
@Sinity
Sinity force-pushed the feature/fix/export-message-role branch from 1d156cb to 62333b6 Compare April 26, 2026 18:02

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@polylogue/cli/commands/export.py`:
- Around line 14-26: Update _root_message_roles to return a more specific type:
change the annotation from tuple[object, ...] to tuple[Role, ...]; remove the
redundant tuple(...) wrapper around normalize_message_roles(raw_roles) since
normalize_message_roles already returns MessageRoleFilter (tuple[Role, ...]);
and move the import of Role from inside the dialogue_only branch to the module
top so the type annotation and runtime reference use the same imported Role
symbol. Ensure references include normalize_message_roles and the
_root_message_roles function name when making the edits.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: aa424030-d464-4bd4-8872-5f061d7c3123

📥 Commits

Reviewing files that changed from the base of the PR and between 3b56542 and 62333b6.

📒 Files selected for processing (3)
  • docs/verification-catalog.md
  • polylogue/cli/commands/export.py
  • tests/unit/cli/test_export.py

Comment on lines +14 to +26
def _root_message_roles(ctx: click.Context) -> tuple[object, ...]:
"""Read the parent ``--message-role`` filter; honor ``--dialogue-only``."""
parent = ctx.parent
if parent is None:
return ()
raw_roles = parent.params.get("message_role")
if raw_roles:
return tuple(normalize_message_roles(raw_roles))
if parent.params.get("dialogue_only"):
from polylogue.lib.roles import Role

return (Role.USER, Role.ASSISTANT)
return ()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm --message-role and --dialogue-only are declared on the root `cli` group.
fd -e py click_app.py
rg -nP -C2 '(--message-role|--dialogue-only|"message_role"|"dialogue_only")' polylogue/cli

Repository: Sinity/polylogue

Length of output: 3775


🏁 Script executed:

cat -n polylogue/cli/click_app.py | head -100

Repository: Sinity/polylogue

Length of output: 3716


🏁 Script executed:

rg -n "def normalize_message_roles" -A5 polylogue/

Repository: Sinity/polylogue

Length of output: 577


🏁 Script executed:

rg -n "MessageRoleFilter" -B2 -A2 polylogue/

Repository: Sinity/polylogue

Length of output: 10175


Tighten return type and remove redundant tuple() wrapper.

Three improvements:

  1. The helper returns tuple[Role, ...] (possibly empty), but the annotation is tuple[object, ...], losing type information at call sites. Change to tuple[Role, ...].
  2. normalize_message_roles() already returns MessageRoleFilter = tuple[Role, ...] (per polylogue/lib/message_roles.py), so the tuple() wrapper on line 21 is redundant.
  3. Move the Role import to the top of the file instead of importing it inside the conditional on line 23.
♻️ Proposed cleanup
+from polylogue.lib.roles import Role
+
+
-def _root_message_roles(ctx: click.Context) -> tuple[object, ...]:
+def _root_message_roles(ctx: click.Context) -> tuple[Role, ...]:
     """Read the parent ``--message-role`` filter; honor ``--dialogue-only``."""
     parent = ctx.parent
     if parent is None:
         return ()
     raw_roles = parent.params.get("message_role")
     if raw_roles:
-        return tuple(normalize_message_roles(raw_roles))
+        return normalize_message_roles(raw_roles)
     if parent.params.get("dialogue_only"):
-        from polylogue.lib.roles import Role
-
         return (Role.USER, Role.ASSISTANT)
     return ()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@polylogue/cli/commands/export.py` around lines 14 - 26, Update
_root_message_roles to return a more specific type: change the annotation from
tuple[object, ...] to tuple[Role, ...]; remove the redundant tuple(...) wrapper
around normalize_message_roles(raw_roles) since normalize_message_roles already
returns MessageRoleFilter (tuple[Role, ...]); and move the import of Role from
inside the dialogue_only branch to the module top so the type annotation and
runtime reference use the same imported Role symbol. Ensure references include
normalize_message_roles and the _root_message_roles function name when making
the edits.

@Sinity
Sinity merged commit 846aa16 into master Apr 26, 2026
13 of 15 checks passed
@Sinity
Sinity deleted the feature/fix/export-message-role branch April 26, 2026 18:19
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity
Sinity requested review from Copilot and removed request for Copilot May 1, 2026 00:44
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity
Sinity requested a review from Copilot May 1, 2026 01:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sinity added a commit that referenced this pull request May 7, 2026
…462)

## Summary

Closes #406. Stacked on #461.

## Problem

The single-conversation ``export`` command silently ignored root-level
``--message-role`` and ``--dialogue-only`` flags. Users had to dump full
JSON and post-filter in Python to extract user-only prose:

    polylogue --message-role user export <id> --format json
    # returns full message list, ignoring --message-role

## Solution

Wires the flags through the same helper the verbs use:
``conversation.with_roles(roles)``. Honors ``--message-role`` (one or
more roles); when ``--dialogue-only`` is set without an explicit role
filter, defaults to user+assistant.

## Verification

``tests/unit/cli/test_export.py`` covers both paths against a synthetic
conversation with mixed roles (user / assistant / system).
``devtools verify`` (full): all checks pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(export): apply message-role filters to exports

2 participants