Repository navigation
fix(export): apply --message-role / --dialogue-only to single export - #462
Conversation
📝 WalkthroughWalkthroughThe PR implements message-role and dialogue-only filtering for the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
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.
1d156cb to
62333b6
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
docs/verification-catalog.mdpolylogue/cli/commands/export.pytests/unit/cli/test_export.py
| 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 () |
There was a problem hiding this comment.
🧹 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/cliRepository: Sinity/polylogue
Length of output: 3775
🏁 Script executed:
cat -n polylogue/cli/click_app.py | head -100Repository: 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:
- The helper returns
tuple[Role, ...](possibly empty), but the annotation istuple[object, ...], losing type information at call sites. Change totuple[Role, ...]. normalize_message_roles()already returnsMessageRoleFilter = tuple[Role, ...](perpolylogue/lib/message_roles.py), so thetuple()wrapper on line 21 is redundant.- Move the
Roleimport 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.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…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.
Summary
Closes #406. Stacked on #461.
Problem
The single-conversation
exportcommand silently ignored root-level--message-roleand--dialogue-onlyflags. Users had to dump fullJSON and post-filter in Python to extract user-only prose:
Solution
Wires the flags through the same helper the verbs use:
conversation.with_roles(roles). Honors--message-role(one ormore roles); when
--dialogue-onlyis set without an explicit rolefilter, defaults to user+assistant.
Verification
tests/unit/cli/test_export.pycovers both paths against a syntheticconversation with mixed roles (user / assistant / system).
devtools verify(full): all checks pass.