Skip to content

feat(output): honor NO_COLOR for JSON output - #170

Closed
markstuart-oai wants to merge 1 commit into
mainfrom
markstuart-oai/c21-no-color
Closed

feat(output): honor NO_COLOR for JSON output#170
markstuart-oai wants to merge 1 commit into
mainfrom
markstuart-oai/c21-no-color

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Honor nonempty NO_COLOR (including 0) when JSON, JSONL, or default auto output would otherwise add terminal color. Empty or unset NO_COLOR preserves automatic behavior. Explicit FORCE_COLOR=1 and FORCE_COLOR=0 retain precedence, including redirected output.

Both pager backends now avoid injecting FORCE_COLOR=1 when NO_COLOR is active, keeping buffered and streamed output consistent. The change adds focused regression tests and documents precedence; payloads, escaping, transforms, newlines, destinations, and iterator limits retain their behavior.

Validation

Local Go 1.27.0 on Linux:

  • Clean-main baseline and candidate CLI probes: 160 invocations each using the same synthetic localhost/PTY harness; 36 intended color-only changes, identical payloads/newlines after SGR-only stripping, all exits 0 and empty stderr.
  • Native sized-PTY RED/GREEN regressions for JSON/JSONL, both pager backends, and pagination; native PTY race checks, including inherited NO_COLOR.
  • Focused output/binary tests; go test ./internal/...; go test ./... -run '^$' (compilation only).
  • go mod verify; ./scripts/lint (Go build); focused vet and selected output race tests.
  • All-package Windows amd64 test cross-compilation; no native Windows execution.
  • Two consecutive independent local review rounds without findings on the final diff.
  • Trusted-current-main custom-code check on committed 043aeaee842956f516fcac7abe4018e70a86bc1b: 495/1000 lines, verified generated snapshot, isolation passed.

Full local mock suite not run: the supported pinned Steady launcher reports Missing or linked Steady cache. The previously blocked setup route was not retried. Hosted CI and full mock tests passed on the published head via test merge 254a0be7bc0847a447bd68f6b1bcb2051136418c, using Go 1.25.14/Linux. The log confirms pinned mock integrity/health checks, all-package tests, Windows test cross-compilation, and cleanup.

@markstuart-oai
markstuart-oai requested a review from a team as a code owner September 8, 2026 07:33
Copilot AI lite review requested due to automatic review settings September 8, 2026 07:33
@markstuart-oai markstuart-oai added the autoimprove Scoped automated improvement label Sep 8, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-08T07:36:44.153644Z 043aeae PR opened
🔒 Security Review Completed 2026-09-08T07:36:33.332466Z 043aeae PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Castiron custom code

✅ No new custom-code files detected.

5 mixed files remain; 0 existing customizations changed.

Compared 265cf6378ab2043aeaee8429. Generated baselines verified.

5 existing customizations unchanged
  • pkg/cmd/adminorganizationcertificate.go
  • pkg/cmd/cmd.go
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 34200521124 --repo openai/openai-cli \
  --name castiron-custom-code-34200521124-1 --dir /tmp/castiron-custom-code-34200521124-1
git apply --stat /tmp/castiron-custom-code-34200521124-1/custom-code.patch
cat /tmp/castiron-custom-code-34200521124-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin 265cf6378ab2e6a27c17bc7c0b6a6cbe6dbd477b 043aeaee842956f516fcac7abe4018e70a86bc1b
python3 scripts/castiron/custom_code_report.py report \
  --base 265cf6378ab2e6a27c17bc7c0b6a6cbe6dbd477b \
  --head 043aeaee842956f516fcac7abe4018e70a86bc1b --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-043aeaee8429
cat /tmp/castiron-custom-code-043aeaee8429/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped to JSON/JSONL color gating and pager env behavior, with clear precedence semantics and comprehensive targeted regression tests.

Pull request overview

This PR updates the CLI’s JSON/JSONL (and default auto) output coloring behavior to honor NO_COLOR while preserving FORCE_COLOR precedence, including when output is routed through a pager, and adds targeted regression coverage plus documentation.

Changes:

  • Update JSON/JSONL color selection to disable default terminal color when NO_COLOR is nonempty, while keeping FORCE_COLOR=1/0 overrides.
  • Prevent both pager backends from injecting FORCE_COLOR=1 when NO_COLOR is active, keeping pre-pager and in-pager formatting consistent.
  • Add focused environment-precedence tests (including pager backend coverage) and document the precedence rules in the README.
File summaries
File Description
README.md Documents NO_COLOR/FORCE_COLOR precedence for JSON/JSONL/auto output.
pkg/cmd/cmdutil.go Implements NO_COLOR handling in color selection and avoids forcing color for the pipe pager backend when NO_COLOR is set.
pkg/cmd/cmdutil_unix.go Applies the same “don’t inject FORCE_COLOR=1 under NO_COLOR” rule to the Unix socket-pair pager backend.
pkg/cmd/cmdutil_test.go Stabilizes existing color-related terminal tests by explicitly clearing inherited NO_COLOR.
pkg/cmd/cmdutil_color_unix_test.go Adds regression coverage ensuring both pager backends preserve color env precedence and don’t override user choices under NO_COLOR.
pkg/cmd/cmdutil_color_test.go Adds matrix tests for NO_COLOR/FORCE_COLOR precedence across formats and destinations, plus a pager iterator regression for NO_COLOR.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jbeckwith-oai jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the complete six-file change at the current exact head. Nonempty NO_COLOR now disables automatic JSON, JSONL, and auto-format terminal color, including both pager backends, while FORCE_COLOR=1 and FORCE_COLOR=0 keep explicit precedence and other values retain automatic behavior. I traced the buffered/pre-pager and streamed/post-pager paths and found payload, escaping, transforms, destinations, and iterator bounds unchanged; the output-control change does not introduce a new terminal-escape path. Focused color and pager tests, the full internal package suite, lint/build, Go vet, and whitespace checks pass locally. All hosted checks, including the mock-backed suite and CodeQL, are green. I found no blocking issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autoimprove Scoped automated improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants