Repository navigation
refactor(cli): use format json for machine output - #677
Conversation
Problem: Polylogue still exposed a parallel --json flag on user CLI commands after the surface cleanup decided machine output should be requested through the format option. That left command help, proof subjects, showcase scenarios, and machine-error detection split across two names for the same contract. What changed: Removed public --json options from Polylogue CLI commands and routed JSON output through --format json. Updated proof JSON-command subjects, scenario surfaces, showcase catalog/baselines, CLI docs, and tests to use the single machine-output spelling. Devtools control-plane --json flags are intentionally unchanged. Verification: ruff format --check polylogue tests devtools && ruff check polylogue tests devtools; mypy polylogue/; devtools render-all --check; devtools verify-topology && devtools verify-layering && devtools verify-test-ownership; pytest -q <focused CLI/scenario/proof set> -> 416 passed; jq empty polylogue/showcase/exercise_catalog.json && pytest -q tests/unit/showcase/test_catalog_loader_runtime.py tests/unit/showcase/test_exercise_catalog.py tests/unit/cli/test_json_envelope_contract.py tests/unit/proof/test_evidence_runners.py -> 68 passed; pytest -q --ignore=tests/integration -> 5774 passed in 185.94s. Ref #635
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis pull request systematically replaces Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
Polylogue Proof PackRefs: Affected Domains
Required Gates
Known Gaps
Oracle / Cost
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f982bddca3
ℹ️ 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".
| @click.option("--since", default=None, help="Limit supported insights to rows at/after this timestamp or date.") | ||
| @click.option("--until", default=None, help="Limit supported insights to rows at/before this timestamp or date.") | ||
| @click.option("--format", "output_format", type=click.Choice(["jsonl"]), default="jsonl", show_default=True) | ||
| @click.option("--bundle-format", type=click.Choice(["jsonl"]), default="jsonl", show_default=True) |
There was a problem hiding this comment.
Add bundle-format to machine-error command parsing
The new --bundle-format option on insights export is not recognized by extract_command, so when JSON-mode error handling is active (for example with --format json) and the command fails before normal rendering, the emitted machine error can include an incorrect command path (it treats jsonl as a positional token). This breaks the machine envelope’s command metadata for insights export failures and can mislead automation that routes on command.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Refactors Polylogue’s CLI machine-readable output contract to standardize on --format json (and deprecate/remove parallel --json boolean flags), updating generated verification surfaces, proof subjects, docs, and tests accordingly.
Changes:
- Removed public
--jsonoptions from multiple CLI commands and migrated callers/tests/docs to--format json. - Updated raw argv machine-error detection to recognize JSON intent via
--format json,--format=json, and-f json. - Split insights export “artifact/bundle format” from “machine output format” (
--bundle-format jsonlvs--format json).
Reviewed changes
Copilot reviewed 81 out of 81 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/storage/test_repository_lifecycle_laws.py | Updates scenario command invocation to doctor --format json. |
| tests/unit/showcase/test_scenario_models.py | Updates showcase scenario args from --json to --format json. |
| tests/unit/showcase/test_invariants_runtime.py | Updates JSON-valid invariant tests to use --format json. |
| tests/unit/showcase/test_exercise_catalog.py | Updates curated JSON contract exercise args to --format json. |
| tests/unit/showcase/test_cli_boundary.py | Updates CLI boundary display command to --format json. |
| tests/unit/showcase/test_catalog_loader_runtime.py | Updates catalog loader expectations for --format json. |
| tests/unit/scenarios/test_runtime.py | Updates runtime command resolution assertions for --format json. |
| tests/unit/scenarios/test_operational_surfaces.py | Updates operational surface args to --format json. |
| tests/unit/scenarios/test_insight_surfaces.py | Updates insight surface args to --format json. |
| tests/unit/proof/test_evidence_runners.py | Updates proof obligation subject id to --format json. |
| tests/unit/devtools/test_validation_lanes.py | Updates lane command assertions to --format json. |
| tests/unit/devtools/test_execution_specs.py | Updates execution rendering expectations for --format json. |
| tests/unit/devtools/test_executable_scenarios.py | Updates inferred executable scenario args to --format json. |
| tests/unit/cli/test_run.py | Updates CLI tests for tags/embed stats JSON output to --format json. |
| tests/unit/cli/test_neighbors_command.py | Updates neighbors JSON payload test to --format json. |
| tests/unit/cli/test_machine_main_runtime.py | Updates machine entry argv for JSON-mode error handling to --format json. |
| tests/unit/cli/test_machine_main.py | Updates machine entry argv to --format json. |
| tests/unit/cli/test_machine_contract.py | Updates docs/tests around JSON intent detection and removes --json cases. |
| tests/unit/cli/test_json_envelope_contract.py | Updates JSON envelope contract tests to invoke --format json. |
| tests/unit/cli/test_insights_command_runtime.py | Updates insights command runtime tests for removed json_mode and new bundle/output format split. |
| tests/unit/cli/test_insights.py | Updates insights command invocations to --format json and export changes. |
| tests/unit/cli/test_embed.py | Updates run embed help/options and JSON requires stats behavior to --format json. |
| tests/unit/cli/test_deterministic_output.py | Updates deterministic-output contract text and invocations to --format json. |
| tests/unit/cli/test_command_aux_runtime.py | Updates tags command aux runtime test to --format json. |
| tests/unit/cli/snapshots/test_terminal_snapshots.ambr | Updates help snapshot removing --json and showing --format [json]. |
| tests/unit/browser_capture/test_receiver.py | Updates browser-capture status JSON output test to --format json. |
| tests/proof/laws/completeness/test_every_json_command_has_envelope_claim.py | Updates completeness law wording to --format json. |
| tests/integration/test_schema_operator_workflow.py | Updates schema integration workflow tests to --format json. |
| tests/integration/test_cli_machine_contract.py | Updates integration machine-contract tests to invoke --format json. |
| tests/data/witnesses/cli-command-surface.json | Removes --json from machine-output alias list. |
| tests/baselines/showcase/help-tags.txt | Updates help baseline removing --json and using --format json. |
| tests/baselines/showcase/help-schema-list.txt | Removes --json from schema list help baseline. |
| tests/baselines/showcase/help-schema-explain.txt | Removes --json from schema explain help baseline. |
| tests/baselines/showcase/help-schema-compare.txt | Removes --json from schema compare help baseline. |
| tests/baselines/showcase/help-run-embed.txt | Updates embed help baseline to --format [json] for stats output. |
| tests/baselines/showcase/help-resume.txt | Removes --json from resume help baseline. |
| tests/baselines/showcase/help-neighbors.txt | Removes --json from neighbors help baseline. |
| tests/baselines/showcase/help-main.txt | Updates main help baseline text for insights wording/ordering. |
| tests/baselines/showcase/help-insights.txt | Updates insights group help baseline wording and export/status labels. |
| tests/baselines/showcase/help-insights-work-events.txt | Removes --json from insights work-events help baseline. |
| tests/baselines/showcase/help-insights-week-summaries.txt | Removes --json from insights week-summaries help baseline. |
| tests/baselines/showcase/help-insights-threads.txt | Removes --json from insights threads help baseline. |
| tests/baselines/showcase/help-insights-tags.txt | Removes --json from insights tags help baseline. |
| tests/baselines/showcase/help-insights-status.txt | Removes --json, renames --product→--insight, keeps --format. |
| tests/baselines/showcase/help-insights-profiles.txt | Removes --json from insights profiles help baseline. |
| tests/baselines/showcase/help-insights-phases.txt | Removes --json from insights phases help baseline. |
| tests/baselines/showcase/help-insights-export.txt | Splits export bundle format vs metadata format (--bundle-format, --format). |
| tests/baselines/showcase/help-insights-enrichments.txt | Removes --json from insights enrichments help baseline. |
| tests/baselines/showcase/help-insights-debt.txt | Removes --json from insights debt help baseline. |
| tests/baselines/showcase/help-insights-day-summaries.txt | Removes --json from insights day-summaries help baseline. |
| tests/baselines/showcase/help-insights-costs.txt | Removes --json from insights costs help baseline. |
| tests/baselines/showcase/help-insights-cost-rollups.txt | Removes --json from insights cost-rollups help baseline. |
| tests/baselines/showcase/help-insights-analytics.txt | Removes --json from insights analytics help baseline. |
| tests/baselines/showcase/help-doctor.txt | Removes --json from doctor help baseline and shows --format [json]. |
| tests/baselines/showcase/help-browser-capture-status.txt | Updates browser-capture status help baseline to --format [json]. |
| polylogue/showcase/invariants.py | Updates JSON validity invariant detection to key off --format/-f json instead of --json. |
| polylogue/showcase/generators.py | Switches JSON-contract scenario discovery from --json to --format presence. |
| polylogue/showcase/exercise_catalog.json | Updates generated catalog argv/expectations away from --json. |
| polylogue/scenarios/operational_surfaces.py | Updates operational surface families to include --format json. |
| polylogue/scenarios/insight_surfaces.py | Updates insight surface lane variants to include --format json. |
| polylogue/scenarios/execution.py | Adds argv JSON-intent detection helper and updates metadata tagging to match --format/-f json. |
| polylogue/scenarios/cli_surfaces.py | Updates default surface suffix args to --format json. |
| polylogue/proof/subjects.py | Updates proof subject IDs/display names and json args to --format json. |
| polylogue/proof/runners.py | Updates default subject json args to --format json. |
| polylogue/cli/shared/machine_errors.py | Updates pre-Click argv scan to detect JSON intent via --format/-f. |
| polylogue/cli/shared/insight_command_contracts.py | Removes json_mode; wants_json now based on output_format == \"json\". |
| polylogue/cli/shared/check_options.py | Replaces --json with --format [json] option for doctor. |
| polylogue/cli/commands/tags.py | Removes --json flag and gates JSON output on output_format. |
| polylogue/cli/commands/schema.py | Removes --json flags and switches schema JSON rendering to output_format. |
| polylogue/cli/commands/run.py | Replaces embed --json with --format [json] and updates error messaging. |
| polylogue/cli/commands/resume.py | Removes --json flag and uses output_format (incl. inherited root format). |
| polylogue/cli/commands/neighbors.py | Removes --json flag and gates JSON output on output_format. |
| polylogue/cli/commands/insights.py | Removes --json; splits export bundle format (--bundle-format) from machine output (--format). |
| polylogue/cli/commands/check.py | Updates doctor command signature to use output_format and map to json_output. |
| polylogue/cli/commands/browser_capture.py | Replaces --json with --format [json] for status command output. |
| polylogue/cli/click_app.py | Updates CLI entrypoint docstring to reference --format json for machine errors. |
| docs/verification-catalog.md | Updates generated verification catalog references/line numbers for refactor. |
| docs/test-quality-workflows.md | Updates workflow docs to reference --format json in generated exercise descriptions. |
| docs/cli-reference.md | Updates CLI reference excerpts to remove --json and document --format. |
Comments suppressed due to low confidence (2)
polylogue/cli/shared/machine_errors.py:177
wants_json()treats-f json/--format jsonanywhere in argv as machine-output intent. Because the root CLI already has its own-f/--formatoption,polylogue -f json <subcommand>can trigger JSON-wrapped Click errors even when the subcommand itself will still render success output as plain text (since many subcommands only check their localoutput_format). This can break the “machine output is JSON when format is json” contract.
Consider aligning these layers by either (a) making JSON-capable subcommands inherit the root output_format as well, or (b) tightening wants_json() to only match a -f/--format json that applies to the invoked subcommand/query verb (not the root option).
def wants_json(argv: list[str]) -> bool:
"""Detect JSON machine-output intent from raw argv before Click parses."""
for index, arg in enumerate(argv):
if arg == "--format" and index + 1 < len(argv) and argv[index + 1] == "json":
return True
if arg.startswith("--format=") and arg.split("=", 1)[1] == "json":
return True
if arg == "-f" and index + 1 < len(argv) and argv[index + 1] == "json":
return True
return False
tests/unit/cli/test_json_envelope_contract.py:141
test_json_alias_uses_success_envelopeno longer exercises an alias path (all parametrized args use--format json). Renaming this test (and/or updating its docstring) would avoid confusion about whether a--jsonalias is still supported.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tags = dict(list(tags.items())[:count]) | ||
|
|
||
| if json_mode or output_format == "json": | ||
| if output_format == "json": |
|
|
||
| if json_mode or output_format == "json": | ||
| if output_format == "json": | ||
| emit_success( | ||
| { |
| """Health check with optional maintenance and cleanup previews.""" | ||
| options = CheckCommandOptions( | ||
| json_output=json_output, | ||
| json_output=output_format == "json", | ||
| verbose=verbose, |
Summary Normalize Polylogue user-facing machine output on `--format json` by removing the parallel public `--json` flags from CLI commands and generated verification surfaces. Problem The CLI cleanup direction says machine-readable output should use the existing format option rather than a second boolean spelling. Keeping both `--json` and `--format json` made help text, proof subjects, scenario exercises, and machine-error handling drift across two names for the same contract. Solution - Removed public `--json` options from Polylogue CLI commands: `doctor`, `tags`, `neighbors`, `resume`, schema inspect commands, browser-capture status, run embed stats, and registry-driven insight commands. - Kept devtools control-plane `--json` flags unchanged. - Updated raw machine-error detection so structured Click errors are emitted only for `--format json`, `--format=json`, or `-f json`. - Updated proof JSON-command subjects, evidence runner args, scenario surfaces, showcase exercises, help baselines, generated CLI/docs/verification references, and tests to use `--format json`. - Split insight export artifact format from machine-output format: artifact format is now `--bundle-format jsonl`; metadata output uses `--format json`. Verification - `ruff format --check polylogue tests devtools && ruff check polylogue tests devtools` - `mypy polylogue/` - `devtools render-all --check` - `devtools verify-topology && devtools verify-layering && devtools verify-test-ownership` - focused CLI/scenario/proof run: `416 passed in 15.40s` - catalog/JSON follow-up run: `68 passed in 10.76s` - full non-integration suite: `5774 passed in 185.94s (0:03:05)` - pre-push `devtools verify --quick`: all checks passed Ref #635
Summary
Normalize Polylogue user-facing machine output on
--format jsonby removing the parallel public--jsonflags from CLI commands and generated verification surfaces.Problem
The CLI cleanup direction says machine-readable output should use the existing format option rather than a second boolean spelling. Keeping both
--jsonand--format jsonmade help text, proof subjects, scenario exercises, and machine-error handling drift across two names for the same contract.Solution
--jsonoptions from Polylogue CLI commands:doctor,tags,neighbors,resume, schema inspect commands, browser-capture status, run embed stats, and registry-driven insight commands.--jsonflags unchanged.--format json,--format=json, or-f json.--format json.--bundle-format jsonl; metadata output uses--format json.Verification
Results:
416 passed in 15.40s68 passed in 10.76s5774 passed in 185.94s (0:03:05)devtools verify --quick: all checks passedRef #635
Summary by CodeRabbit
--jsonflag to--format jsonoptiondoctor,tags,run embed,schemasubcommands,insightssubcommands,neighbors,resume,browser-capture status, andcheck