Skip to content

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

Closed

Description

@Sinity

Context

After the substrate renewals, the user-facing surfaces should be simplified to consume the new contracts directly. Today some CLI/MCP/UI paths still compensate for earlier substrate ambiguity with duplicated formatting/coercion logic, dict-shaped request envelopes, and repeated destination/output branching.

Scope

Focus on surface contraction over already-renewed substrate contracts:

  • polylogue/cli/
  • polylogue/mcp/
  • selected polylogue/ui/, polylogue/rendering/, and polylogue/site/ modules when they still carry substrate-shaped glue

Anchor rewrites

The architectural center for this tranche should stay focused on a small set of surface-contract files:

  • polylogue/cli/query.py
  • polylogue/cli/query_output.py
  • polylogue/cli/query_actions.py
  • polylogue/cli/query_verbs.py
  • polylogue/cli/root_request.py
  • polylogue/cli/commands/products.py
  • polylogue/mcp/server_product_tools.py
  • polylogue/ui/facade_console.py
  • polylogue/rendering/block_models.py

Mechanical follow-through

Once the new request/output contracts are established, narrower follow-through can propagate through:

  • polylogue/cli/query_stats.py
  • polylogue/cli/query_semantic.py
  • polylogue/cli/schema_rendering_results.py
  • polylogue/cli/schema_rendering_explain.py
  • polylogue/cli/products_rendering.py
  • polylogue/cli/commands/check.py
  • polylogue/cli/commands/schema.py
  • polylogue/cli/shell_completion_values.py
  • adjacent MCP/UI/rendering helpers required by the new surface contracts

Acceptance criteria

  • Surface layers consume explicit substrate/product models rather than rebuilding them ad hoc.
  • Dict-based CLI envelopes are replaced or materially reduced in favor of typed request/plan/output models.
  • Repeated output-format and destination-dispatch glue is centralized instead of duplicated.
  • CLI and MCP machine/human outputs stay contract-consistent over the same underlying semantics.
  • The tranche lands as one coherent PR with full verification.

Out of scope

  • Large substrate rewrites that belong in earlier tranches
  • Broad test-suite modernization beyond fallout and targeted coverage

Activity

  1. added
    type:refactor
    on Apr 20, 2026
  2. Sinity commented on Apr 20, 2026

    @Sinity
    OwnerAuthor

    Planned execution shape for this tranche:

    Anchor rewrites to keep local:

    • polylogue/cli/query.py
    • polylogue/cli/query_output.py
    • polylogue/cli/query_actions.py
    • polylogue/cli/query_verbs.py
    • polylogue/cli/root_request.py
    • polylogue/cli/commands/products.py
    • polylogue/mcp/server_product_tools.py
    • polylogue/ui/facade_console.py
    • polylogue/rendering/block_models.py
    • polylogue/rendering/core_messages.py

    Mechanical follow-through candidates after the anchor contracts land:

    • polylogue/cli/query_stats.py
    • polylogue/cli/query_semantic.py
    • polylogue/cli/schema_rendering_results.py
    • polylogue/cli/schema_rendering_explain.py
    • polylogue/cli/products_rendering.py
    • polylogue/cli/commands/check.py
    • polylogue/cli/commands/schema.py
    • polylogue/cli/shell_completion_values.py
    • polylogue/rendering/core_markdown.py
    • polylogue/rendering/blocks.py

    Main repeated patterns to remove:

    • dict-shaped CLI request envelopes crossing module boundaries
    • repeated output-format branching and no-results rendering
    • repeated destination dispatch (stdout, clipboard, browser, file path)
    • repeated timestamp normalization and block/message coercion across rendering surfaces
    • MCP product-tool wrapper setup carrying normalization logic inline rather than via shared helpers

    Execution intent:

    1. tighten the core CLI request/plan/output contracts
    2. contract MCP and rendering/UI surfaces over those same shapes
    3. fan the shared helpers through the narrower follow-through files
    4. keep tests mostly to fallout and targeted surface contract coverage
  3. Sinity commented on Apr 22, 2026

    @Sinity
    OwnerAuthor

    Starting execution on feature/refactor/surface-contracts.

    Initial decisions:

    • This is the next open executable renewal issue after the already-closed deployment, command-surface, and architecture-completeness slices.
    • refactor: renew verification, test helpers, and quality tooling contracts #274 follows after this because verification/test helper cleanup should reflect the renewed surface contracts rather than race them.
    • I will start by surveying the named anchor files and remove duplication only where a typed/shared surface contract actually replaces old glue.
    • Scope guard: no substrate/storage rewrite unless a surface boundary cannot be contracted without a small supporting type/helper.
  4. Sinity commented on Apr 22, 2026

    @Sinity
    OwnerAuthor

    Implementation update for #273:

    • Opened PR refactor(cli): contract query and product outputs (#365) #365: refactor(cli): contract query and product outputs (#365) #365
    • Commit: e9fb8b9d refactor(cli): contract query and product outputs
    • Scope landed:
      • added polylogue/cli/query_output_contracts.py with StructuredRowsDocument and QueryOutputDocument;
      • routed summary/search-hit list output through the shared row-rendering contract;
      • routed query output delivery through an explicit document contract while preserving the existing _send_output test seam;
      • added product_items_payload() and reused it from both CLI JSON product rendering and MCP product list tools.
    • Boundary decision: the named UI/rendering anchors already consume explicit rendering models (RenderableBlock, RenderedMessage) from prior renewal work, so this tranche targeted the remaining active glue rather than rewriting already-contracted surfaces.

    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
    • push hook ran devtools verify --quick -> verify: all checks passed
  5. Sinity commented on Apr 22, 2026

    @Sinity
    OwnerAuthor

    #273 merged in PR #365.

    Merge commit: d458ad1873e8eb560e6984fd67968b65e1ba28d8

    Final checks before merge:

    • Local devtools verify passed before opening the PR.
    • Push hook devtools verify --quick passed.
    • GitHub checks observed green before merge: PR policy, GitGuardian, lint, typecheck, showcase-verify, Nix build/check, CodeQL, CodeRabbit.
    • The Python matrix was still pending when merged; local full pytest had already passed as part of devtools verify, and this matched the CI-quota constraint for this run.
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:cliarea:mcparea:sitetype:refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions