Skip to content

Add DEBUG=tweakcc env var support and replace raw console.log/warn (#471)#512

Closed
astrosteveo wants to merge 5 commits intoPiebald-AI:mainfrom
astrosteveo:feature/logger-debug-env
Closed

Add DEBUG=tweakcc env var support and replace raw console.log/warn (#471)#512
astrosteveo wants to merge 5 commits intoPiebald-AI:mainfrom
astrosteveo:feature/logger-debug-env

Conversation

@astrosteveo
Copy link
Copy Markdown
Contributor

@astrosteveo astrosteveo commented Feb 11, 2026

Summary

  • Extend isDebug() to check process.env.DEBUG for tweakcc or *, enabling debug output via DEBUG=tweakcc without the --debug CLI flag
  • Add warn() helper to src/utils.ts for consistent warning output
  • Replace raw console.log (diagnostic) with debug() and console.warn with warn() across 8 files

Changes

  • src/utils.ts: isDebug() now checks DEBUG env var; added warn() helper
  • src/patches/helpers.ts: 10 diagnostic console.logdebug()
  • src/patches/conversationTitle.ts: 1 console.logdebug()
  • src/patches/systemPrompts.ts: 3 console.logdebug()
  • src/config.ts: 6 console.warnwarn()
  • src/nativeInstallation.ts: 1 console.warnwarn()
  • src/systemPromptDownload.ts: 1 console.warnwarn()
  • src/patches/fixLspSupport.ts: 3 console.warnwarn()
  • src/patches/suppressNativeInstallerWarning.ts: 1 console.warnwarn()
  • src/tests/logger.test.ts: 6 new tests for isDebug(), debug(), and warn()

User-facing CLI output in index.tsx, commands.ts, and systemPromptSync.ts is intentionally unchanged. All console.error calls are unchanged per requirements.

Testing

  • Tests added/updated
  • Manual testing completed
  • All existing tests pass

Manually verified against CC 2.1.39:

  • DEBUG=tweakcc pnpm start --apply shows diagnostic output
  • pnpm start --apply is clean (no debug noise)
  • --debug flag still works as before
  • All 168 tests pass, lint and typecheck clean

Related Issues

Closes #471

Summary by CodeRabbit

  • Refactor

    • Standardized logging by routing console output through dedicated debug and warn utilities for consistent, configurable diagnostics.
    • Debug activation now also respects the DEBUG environment variable ("tweakcc" or "*"); warn helper ensures consistent warning output and preserved spacing in warnings.
  • Tests

    • Added tests for logger utilities validating debug activation and warn behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

Replaces ad-hoc console.log/console.warn calls with centralized debug() and warn() utilities, adds isDebug()/warn() exports in src/utils.ts, and introduces tests for logger behavior. No public API signatures or control-flow changes introduced. (≤50 words)

Changes

Cohort / File(s) Summary
Logger Utilities
src/utils.ts
Adds isDebug(): boolean (reads in-memory flag or process.env.DEBUG), exports warn(...), and keeps debug(...) gated by isDebug(); documents behavior.
Logger Tests
src/tests/logger.test.ts
New test suite validating isDebug(), debug(), and warn() with mocked console and process.env.DEBUG.
Patch Logging Replacements
src/patches/conversationTitle.ts, src/patches/fixLspSupport.ts, src/patches/helpers.ts, src/patches/suppressNativeInstallerWarning.ts, src/patches/systemPrompts.ts
Replaced console.logdebug and console.warnwarn; added corresponding imports; one change pushes a per-prompt result for unescaped backticks. No control-flow changes.
Source File Logging Replacements
src/config.ts, src/nativeInstallation.ts, src/systemPromptDownload.ts
Replaced console.warn calls with warn(...) for multiple warning sites (config locations, codesign, cache write). Imports updated; behavior unchanged.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • bl-ue

Poem

"I nibble logs with careful paws,
I hush the noisy console claws,
warn whispers low, debug blinks bright,
tiny prints tucked out of sight,
the code hops calm into the night. 🐇"

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: adding DEBUG environment variable support and replacing raw console logging with structured utilities.
Linked Issues check ✅ Passed PR implements core requirements from #471: environment-variable debug toggle (DEBUG=tweakcc), replaces console.log with debug utility, replaces console.warn with warn utility, adds test coverage, and preserves error logging.
Out of Scope Changes check ✅ Passed All changes are scoped to logging infrastructure refactoring: utilities, patch files, config, and new tests. No unrelated functionality modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


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

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

@astrosteveo astrosteveo force-pushed the feature/logger-debug-env branch from e0d848a to c9a8e2d Compare February 11, 2026 16:46
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/patches/systemPrompts.ts`:
- Around line 130-136: The backtick validation currently logs the formatted
error with debug(formatBacktickError(...)) then silently continues (continue)
leaving no trace in results; change these debug() calls to warn() so users see
the actionable message (i.e., call warn(formatBacktickError(...)) and warn('')
instead of debug), and before the continue push a concise failure entry into
results (e.g., mark this prompt as skipped with the formatted error message) so
callers can programmatically observe which prompts were skipped.
🧹 Nitpick comments (2)
src/tests/logger.test.ts (2)

40-54: Spy and env cleanup can leak if an assertion throws.

In the debug test, spy.mockRestore() and delete process.env.DEBUG are after the assertions. If an assertion fails, the spy stays attached and DEBUG remains set, potentially affecting later tests. Consider using afterEach or a try/finally block, consistent with the pattern already used in the isDebug suite.

Suggested structure
 describe('debug', () => {
+  afterEach(() => {
+    delete process.env.DEBUG;
+  });
+
   it('only outputs when debug is enabled', () => {
     const spy = vi.spyOn(console, 'log').mockImplementation(() => {});
-    delete process.env.DEBUG;
-
-    debug('should not appear');
-    expect(spy).not.toHaveBeenCalled();
-
-    process.env.DEBUG = 'tweakcc';
-    debug('should appear');
-    expect(spy).toHaveBeenCalledWith('should appear');
-
-    spy.mockRestore();
-    delete process.env.DEBUG;
+    try {
+      delete process.env.DEBUG;
+      debug('should not appear');
+      expect(spy).not.toHaveBeenCalled();
+
+      process.env.DEBUG = 'tweakcc';
+      debug('should appear');
+      expect(spy).toHaveBeenCalledWith('should appear');
+    } finally {
+      spy.mockRestore();
+    }
   });
 });

57-65: Same cleanup concern for warn spy.

Minor nit — same pattern applies: wrap in try/finally or use afterEach for spy.mockRestore().

@astrosteveo astrosteveo force-pushed the feature/logger-debug-env branch from b2dcaf6 to 7c55623 Compare February 11, 2026 16:55
Backtick errors in user prompt files are actionable user feedback, not
internal diagnostics. Using debug() would silently skip broken prompts.
@astrosteveo astrosteveo force-pushed the feature/logger-debug-env branch from 7c55623 to ae94546 Compare February 11, 2026 16:59
@astrosteveo astrosteveo closed this Mar 4, 2026
@astrosteveo astrosteveo deleted the feature/logger-debug-env branch March 4, 2026 19:44
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.

WHY UGH console.log everywhere?!?! 😫

1 participant