Skip to content

refactor(cli): contract query and product outputs (#365) - #365

Merged
Sinity merged 1 commit into
masterfrom
feature/refactor/surface-contracts
Apr 22, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/refactor/surface-contracts

Conversation

@Sinity

@Sinity Sinity commented Apr 22, 2026

Copy link
Copy Markdown
Owner

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

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
@Sinity Sinity changed the title refactor(cli): contract query and product outputs refactor(cli): contract query and product outputs (#365) Apr 22, 2026
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 37 minutes and 38 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: bb016124-4957-4c1b-9d5d-7b2f0059ca5b

📥 Commits

Reviewing files that changed from the base of the PR and between d837ab1 and e9fb8b9.

📒 Files selected for processing (6)
  • polylogue/cli/query_output.py
  • polylogue/cli/query_output_contracts.py
  • polylogue/mcp/server_product_tools.py
  • polylogue/products/registry.py
  • tests/unit/cli/test_products.py
  • tests/unit/cli/test_query_fmt.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/surface-contracts

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.

@Sinity
Sinity merged commit d458ad1 into master Apr 22, 2026
11 of 14 checks passed
@Sinity
Sinity deleted the feature/refactor/surface-contracts branch April 22, 2026 19:22
@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. Breezy!

ℹ️ 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:53
@Sinity
Sinity removed the request for review from Copilot May 1, 2026 02:15
Sinity added a commit that referenced this pull request May 7, 2026
## 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`
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.

refactor: contract CLI, MCP, and UI surfaces over renewed substrate

1 participant