Repository navigation
fix(cli): honour NO_COLOR in manager warning, add --no-color flag - #848
lakshya-dhariwal wants to merge 2 commits into
Conversation
|
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/ |
|
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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe CLI now removes ChangesColor output controls
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The CLI color-control change appears ready to merge after normal checks. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 3 systems. Changed systems: Architecture concerns Review detailsSystems and components
Before / after behavior
🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
__tests__/hooks/no-color.test.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. bin/failproofai.mjsESLint skipped: the matched ESLint configuration already failed (missing-dependency). src/hooks/manager.tsESLint skipped: the matched ESLint configuration already failed (missing-dependency).
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. A rabbit hops through terminal light, Comment |
* 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>
|
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 Closing this one in favour of #1067. Thanks again! |
Description
Fixes #688. One note up front: by the time I got here, the
policieslisting itself was already routed throughpaint()/chip()intui.ts, so the 16 hardcoded sites this issue describes had shrunk to exactly one - the duplicate-scope warning insrc/hooks/manager.ts, which still printed\x1B[33m…\x1B[0mregardless ofNO_COLOR. This PR finishes the job rather than pretending the listing was still broken:src/hooks/manager.ts: the warning now usespaint(!process.env.NO_COLOR).warn(...)(the install-prompt.ts pattern), so no hardcoded escapes remain in the file.src/hooks/tui.ts: newapplyNoColorFlag(args)helper - setsNO_COLOR=1and strips--no-colorfrom argv, so no subcommand's flag parser ever sees it.bin/failproofai.mjs: calls it once, right after argv is read; documents--no-colorin the top-level help footer and inpolicies --help.__tests__/hooks/no-color.test.ts: covers the TTY gate (colorsEnabledfalse under NO_COLOR), the painter emitting zero ESC bytes under NO_COLOR, the flag helper's strip-and-set behaviour, and a regression lock assertingmanager.tsnever 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
helpScreenwith the real specs, since this environment has no bun to spawn the binary.Type of Change
Checklist
npm run lintpasses (eslint on the touched files - clean)npx tsc --noEmitpassesnpm run test:runpasses - 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 buildsucceeds - same bun constraint.Summary by CodeRabbit
--no-coloroption to disable colored output across commands. It can also be enabled withNO_COLOR=1, and is documented in the command-line help.