Skip to content

fix(cli): honour NO_COLOR in manager warning, add --no-color flag - #848

Closed
lakshya-dhariwal wants to merge 2 commits into
FailproofAI:mainfrom
lakshya-dhariwal:fix/no-color-manager
Closed

lakshya-dhariwal wants to merge 2 commits into
FailproofAI:mainfrom
lakshya-dhariwal:fix/no-color-manager

Conversation

@lakshya-dhariwal

@lakshya-dhariwal lakshya-dhariwal commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #688. One note up front: by the time I got here, the policies listing itself was already routed through paint()/chip() in tui.ts, so the 16 hardcoded sites this issue describes had shrunk to exactly one - the duplicate-scope warning in src/hooks/manager.ts, which still printed \x1B[33m…\x1B[0m regardless of NO_COLOR. This PR finishes the job rather than pretending the listing was still broken:

  • src/hooks/manager.ts: the warning now uses paint(!process.env.NO_COLOR).warn(...) (the install-prompt.ts pattern), so no hardcoded escapes remain in the file.
  • src/hooks/tui.ts: new applyNoColorFlag(args) helper - sets NO_COLOR=1 and strips --no-color from argv, so no subcommand's flag parser ever sees it.
  • bin/failproofai.mjs: calls it once, right after argv is read; documents --no-color in the top-level help footer and in policies --help.
  • __tests__/hooks/no-color.test.ts: covers the TTY gate (colorsEnabled false under NO_COLOR), the painter emitting zero ESC bytes under NO_COLOR, the flag helper's strip-and-set behaviour, and a regression lock asserting manager.ts never reintroduces a hardcoded escape.

I verified the help screens stay within the layout budget the help-index test enforces: index goes 25 to 26 lines (cap 30), max column stays 78 (cap 80). I measured by rendering helpScreen with the real specs, since this environment has no bun to spawn the binary.

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation

Checklist

  • npm run lint passes (eslint on the touched files - clean)
  • npx tsc --noEmit passes
  • npm run test:run passes - ran the related suites instead: no-color.test.ts (new, 5 tests), tui.test.ts, tui-kit.test.ts, manager.test.ts, manager-cloud-listing.test.ts - 152/152 green. Full test:run + build need bun, which I don't have here - flagging rather than ticking a box I didn't run. The bun-driven suites (help-index, unified-policies-surface) should exercise the help layout and the new flag in CI.
  • npm run build succeeds - same bun constraint.

Summary by CodeRabbit

  • New Features
    • Added a --no-color option to disable colored output across commands. It can also be enabled with NO_COLOR=1, and is documented in the command-line help.
  • Bug Fixes
    • Duplicate-scope warnings now respect the no-color setting instead of always displaying colored text.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks @lakshya-dhariwal for your contribution to Failproof AI! 🙌

We'd love to discuss your PR and welcome you to our community.

Discord: https://discord.befailproof.ai/
Reddit: https://www.reddit.com/r/failproofai/

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: dc55de6c-7511-4fd6-994d-3db70b90309a

📥 Commits

Reviewing files that changed from the base of the PR and between e40de6c and d3c2e33.

📒 Files selected for processing (4)
  • __tests__/hooks/no-color.test.ts
  • bin/failproofai.mjs
  • src/hooks/manager.ts
  • src/hooks/tui.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The CLI now removes --no-color before command dispatch and sets NO_COLOR=1 when the flag is present. Help text documents the option. The duplicate-scope warning uses the shared color helper and respects NO_COLOR.

Changes

Color output controls

Layer / File(s) Summary
Global no-color flag
src/hooks/tui.ts, bin/failproofai.mjs, __tests__/hooks/no-color.test.ts
The CLI removes --no-color before dispatch and sets NO_COLOR=1 when the flag is present. Help text documents the option. Tests cover flag handling and color output.
Multi-scope warning color
src/hooks/manager.ts
The duplicate-scope warning uses paint and disables color when NO_COLOR is set.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: chhhee10

Merge Risk: ⚪ Minimal · up to d3c2e

The CLI color-control change appears ready to merge after normal checks.

Architecture Summary

Architecture risk: 🔵 Low · up to d3c2e

The change affects 3 systems.

Changed systems: src, bin, __tests__

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (service) was modified; 2 changed files map to changed impact.
  • observed — bin (service) was modified; 1 changed file maps to changed impact.
  • observed — tests (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in tests/hooks/no-color.test.ts: Adds a Node-environment Vitest suite that checks the stated NO_COLOR and flag-handling expectations, restores the environment variable after each test, and scans manager.ts for hardcoded ANSI escape sequences.
  • observed — Modified behavior in bin/failproofai.mjs: Before command normalization and dispatch, the entry point now lazily loads applyNoColorFlag and applies it to the argument list, allowing the flag to affect every command before subcommand parsing.
  • observed — Modified behavior in bin/failproofai.mjs: The top-level help footer now documents --no-color as plain output equivalent to NO_COLOR=1.
  • observed — Modified behavior in bin/failproofai.mjs: The policies options now document --no-color and state that it works across commands.
🚥 Pre-merge checks | ✅ 6 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: honoring NO_COLOR in the manager warning and adding the --no-color flag.
Description check ✅ Passed The description follows the repository template, explains the changes, identifies the issue, and reports completed and unavailable validation steps.
Linked Issues check ✅ Passed The description references and addresses issue #688. The stated implementation matches the issue objectives.
Out of Scope Changes check ✅ Passed The changes remain within scope: CLI color handling, flag processing, documentation, and related tests.
Linked Issues check ✅ Passed Issue #688 requires NO_COLOR=1 and --no-color to disable ANSI output for failproofai policies, with tests and use of the existing paint() path. The reviewed head routes the duplicate-scope war…
Out of Scope Changes check ✅ Passed The changes stay within issue #688. The manager update fixes the hardcoded warning color. The CLI helper, help text, and tests support the requested --no-color behavior. No unrelated production beha…
  • Fix all pre-merge checks with AI

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

__tests__/hooks/no-color.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

bin/failproofai.mjs

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

src/hooks/manager.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

  • 1 others

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

A rabbit hops through terminal light,
Then dims the colors, clean and bright.
The flag is caught before commands run,
The warning prints without its hue.
Tests keep watch on every cue.
One quiet burrow, plain output too.

Comment @coderabbitai help to get the list of available commands.

hermes-exosphere pushed a commit that referenced this pull request Nov 30, 2026
* fix(cli): honor no-color for policy output

(cherry picked from commit 8b8e9db)

* fix(policies): honour NO_COLOR in hooks manager output; add --no-color

Closes #688. `failproofai policies` printed ANSI colour even when NO_COLOR
was set, because src/hooks/manager.ts hardcoded ANSI escapes at 16 sites
instead of gating on the shared predicate the rest of the CLI uses.

- Add an ansiHelpers() factory in manager.ts that gates on tui.ts's existing
  colorsEnabled() (!!out.isTTY && !process.env.NO_COLOR) — no new colour
  module (per #256). All 16 sites now route through green/yellow/red/dim
  wrappers that return the string unchanged when colour is off, so plain-text
  glyphs and column widths are byte-identical minus the escape sequences.
- Add a global --no-color flag in bin/failproofai.mjs that sets NO_COLOR=1 and
  is stripped from args before subcommand parsing; documented in COMMANDS help.
- Add a vitest regression test asserting listHooks emits zero ESC bytes under
  NO_COLOR (isTTY forced true) and still emits them with colour on.

Resolved onto current main: the 16 hardcoded escapes this replaced were
already removed when the policies listing moved onto tui.ts (#738, #880),
and the --no-color flag block is identical to the one from #695. Only the
listHooks NO_COLOR test is kept from this commit.

(cherry picked from commit f40a782)

* test(policies): harden NO_COLOR test per review

- Assert on the convention-policy status row (team-policies.mjs) so the
  color-on test measures manager.ts's own gated output rather than incidental
  color elsewhere.
- Use vi.stubEnv("NO_COLOR", "") instead of delete process.env.NO_COLOR so
  vi.unstubAllEnvs() restores the worker's original value in afterEach.

(cherry picked from commit 4838d73)

* fix(cli): honour NO_COLOR in manager warning and add --no-color flag (#688)

Resolved onto current main with no code change. The duplicate-scope
warning this moved onto paint() now goes through screenKit().caution(),
and the flag stays inline in bin/failproofai.mjs (from #695) rather than
in tui.ts: importing tui.ts at the top of the bin reorders the bundle,
which renames the builtin policies' `ctx` parameters and so changes the
audit cache key, and it would load the kit on every --hook call. Kept
for credit; the tests from the next commit still apply.

(cherry picked from commit b0a30c8)

* test(cli): cover NO_COLOR gating, --no-color flag, and raw-escape regression

(cherry picked from commit d3c2e33)

* test(cli): adapt the #700 and #848 NO_COLOR tests to current main

The listing now renders through tui.ts's printBlock, so the listHooks test
captures process.stdout.write instead of console.log, isolates
FAILPROOFAI_HOME and the pack directory, and checks the current header.

applyNoColorFlag() was not taken (the flag stays inline in the bin), so its
two unit tests become one that locks where the bin consumes --no-color:
before the aliases and the --hook fast path, with no tui.ts import ahead of
them. The flag itself is covered end to end in cli-args.e2e.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: document --no-color and add the #688 changelog entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): fit the --no-color help row on one line

At 80 columns "works with every command" wrapped "command" onto a row of its
own; every other row on the policies help page fits on one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: add the PR number to the --no-color changelog entry

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: mjq2020 <74635395+mjq2020@users.noreply.github.com>
Co-authored-by: Vladimir Babin <vovababin@gmail.com>
Co-authored-by: lakshya-dhariwal <lakshyadhariwal9@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@NiveditJain

Copy link
Copy Markdown
Member

Thank you @lakshya-dhariwal for this contribution. Both of your commits were merged into main through #1067, which combined the three PRs for #688. Your tests went in: the NO_COLOR gating checks and the lock that keeps hardcoded escapes out of manager.ts. The applyNoColorFlag() helper wasn't taken, because importing tui.ts at the top of the CLI changes the bundle order (and with it the audit cache key) and would load it on every hook call; the flag stays inline in bin/failproofai.mjs, and one of your tests was adapted to lock that in. You're credited as a co-author on the merge commit (8e9d7bd), and #688 is now closed.

Closing this one in favour of #1067. Thanks again!

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.

CLI: failproofai policies ignores NO_COLOR, and --no-color does not exist

2 participants