Repository navigation
refactor(cli): contract query and product outputs (#365) - #365
Conversation
Problem: query and product surfaces still repeated list rendering, destination dispatch, and product model-dump payload assembly even after the substrate contracts were typed. What changed: added typed query output row/delivery documents, routed summary and search-hit formatting through the shared row renderer, delivered query output through a single document contract, and centralized product list payload creation for CLI and MCP product tools. Verification: ruff check polylogue/cli/query_output_contracts.py polylogue/cli/query_output.py polylogue/products/registry.py polylogue/mcp/server_product_tools.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_products.py; mypy polylogue/cli/query_output_contracts.py polylogue/cli/query_output.py polylogue/products/registry.py polylogue/mcp/server_product_tools.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_products.py; pytest -q tests/unit/cli/test_query_fmt.py tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_products.py tests/unit/mcp/test_tool_contracts.py. Refs #273
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 37 minutes and 38 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
✨ Finishing Touches🧪 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 |
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ 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". |
## Summary Adds typed query output documents for list-style CLI surfaces, routes query output delivery through an explicit delivery contract, and centralizes archive-product list payload construction so CLI and MCP product tools share the same model-dump semantics. ## Problem Issue #273 tracks contraction of user-facing surfaces over the renewed substrate. The remaining high-value duplication was concentrated in query list output and archive-product listing: summary/search-hit formatters each rebuilt JSON/YAML/CSV/plain rows independently, destination dispatch still accepted loose content arguments, and CLI/MCP product list payloads each rebuilt their own count/items dictionaries. The named UI/rendering anchors already consume explicit rendering models (`RenderableBlock`, `RenderedMessage`) from the previous renewal work, so this PR keeps the change focused on the places where substrate-shaped glue was still active. ## Solution - Added `polylogue/cli/query_output_contracts.py` with `StructuredRowsDocument` and `QueryOutputDocument`. - Reworked `format_summary_list` and `format_search_hit_list` to render through `StructuredRowsDocument` instead of duplicating machine/plain branches. - Replaced loose query delivery internals with `deliver_query_output(env, QueryOutputDocument)` while preserving the existing `_send_output` test seam. - Added `product_items_payload()` to `polylogue/products/registry.py` and reused it from both CLI JSON rendering and MCP product list tools. - Added targeted tests covering the shared row-rendering contract and shared product payload shape. Closes #273. ## Verification - `ruff format polylogue/cli/query_output_contracts.py polylogue/cli/query_output.py polylogue/products/registry.py polylogue/mcp/server_product_tools.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_products.py` - `ruff check polylogue/cli/query_output_contracts.py polylogue/cli/query_output.py polylogue/products/registry.py polylogue/mcp/server_product_tools.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_products.py` - `mypy polylogue/cli/query_output_contracts.py polylogue/cli/query_output.py polylogue/products/registry.py polylogue/mcp/server_product_tools.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_products.py` - `pytest -q tests/unit/cli/test_query_fmt.py tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_products.py tests/unit/mcp/test_tool_contracts.py` -> `216 passed in 18.43s` - `devtools verify` -> `verify: all checks passed` - `git push -u origin feature/refactor/surface-contracts` pre-push hook ran `devtools verify --quick` -> `verify: all checks passed`
Summary
Adds typed query output documents for list-style CLI surfaces, routes query output delivery through an explicit delivery contract, and centralizes archive-product list payload construction so CLI and MCP product tools share the same model-dump semantics.
Problem
Issue #273 tracks contraction of user-facing surfaces over the renewed substrate. The remaining high-value duplication was concentrated in query list output and archive-product listing: summary/search-hit formatters each rebuilt JSON/YAML/CSV/plain rows independently, destination dispatch still accepted loose content arguments, and CLI/MCP product list payloads each rebuilt their own count/items dictionaries.
The named UI/rendering anchors already consume explicit rendering models (
RenderableBlock,RenderedMessage) from the previous renewal work, so this PR keeps the change focused on the places where substrate-shaped glue was still active.Solution
polylogue/cli/query_output_contracts.pywithStructuredRowsDocumentandQueryOutputDocument.format_summary_listandformat_search_hit_listto render throughStructuredRowsDocumentinstead of duplicating machine/plain branches.deliver_query_output(env, QueryOutputDocument)while preserving the existing_send_outputtest seam.product_items_payload()topolylogue/products/registry.pyand reused it from both CLI JSON rendering and MCP product list tools.Closes #273.
Verification
ruff format polylogue/cli/query_output_contracts.py polylogue/cli/query_output.py polylogue/products/registry.py polylogue/mcp/server_product_tools.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_products.pyruff check polylogue/cli/query_output_contracts.py polylogue/cli/query_output.py polylogue/products/registry.py polylogue/mcp/server_product_tools.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_products.pymypy polylogue/cli/query_output_contracts.py polylogue/cli/query_output.py polylogue/products/registry.py polylogue/mcp/server_product_tools.py tests/unit/cli/test_query_fmt.py tests/unit/cli/test_products.pypytest -q tests/unit/cli/test_query_fmt.py tests/unit/cli/test_query_exec_laws.py tests/unit/cli/test_products.py tests/unit/mcp/test_tool_contracts.py->216 passed in 18.43sdevtools verify->verify: all checks passedgit push -u origin feature/refactor/surface-contractspre-push hook randevtools verify --quick->verify: all checks passed