Skip to content

Replace Write-Host console UI with .format.ps1xml views on PSCustomObject output #28

@ocalvo

Description

@ocalvo

Problem

PwrCortex currently renders results via hand-rolled Write-Host UI (Write-ResponseBox, Write-Status, box drawing, colored banners in Private/Rendering.ps1 and the Public cmdlets). This violates the directive in PwrClaude/CLAUDE.md:

Rich/structured output: emit objects + a .format.ps1xml formatter, never hand-roll Write-Host UI.

Write-Host output is non-capturable, non-suppressible, non-pipeable, and forces one hardcoded layout on every caller. It also ignores Format-Table/Format-List overrides, terminal width, and -AutoSize.

Files with Write-Host that should be converted:

  • Public/Send-LLMMessage.ps1
  • Public/Invoke-LLM.ps1
  • Public/Invoke-LLMAgent.ps1
  • Public/Invoke-LLMSwarm.ps1
  • Public/Get-LLMProviders.ps1
  • Public/Expand-LLMProcess.ps1
  • Public/Enter-LLMChat.ps1
  • Private/Swarm.ps1
  • Private/Rendering.ps1

Proposed fix

  1. Ensure every public cmdlet returns a real [PSCustomObject] (LLMResponse, LLMSwarmResult, LLMProvider, etc.) with named types via PSTypeName.
  2. Add PwrCortex.format.ps1xml with <View> definitions for each type: list view for LLMResponse (content + tokens + steps), table view for LLMProvider (name, model, has-key), custom view for LLMSwarmResult.
  3. Register the formatter via FormatsToProcess in PwrCortex.psd1.
  4. Remove Write-ResponseBox, Write-Status, and the ANSI palette / box-drawing helpers in Config.ps1 used only by hand-rolled UI.
  5. Interactive REPL (Enter-LLMChat) is allowed to keep terminal-only literal text (prompts, banners) — that is legitimate Write-Host.

Acceptance

  • Invoke-LLM ... | Export-Csv works (object pipeline intact).
  • Invoke-LLM ... | Format-List * shows all fields; default view is concise.
  • No Write-Host -ForegroundColor Red anywhere in the module.
  • -Quiet becomes unnecessary for machine-readable pipelines (the formatter is off by default when piping).

Related

  • Sibling issue: "Expand LLMSwarmResult.Synthesis into structured PSCustomObject"
  • Sibling issue: "Use Write-Progress for long-running operations"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions