Skip to content

refactor: extract magic numbers to named constants#276

Open
ishaan812 wants to merge 3 commits intoentireio:mainfrom
ishaan812:refactor/extract-magic-number-constants
Open

refactor: extract magic numbers to named constants#276
ishaan812 wants to merge 3 commits intoentireio:mainfrom
ishaan812:refactor/extract-magic-number-constants

Conversation

@ishaan812
Copy link

@ishaan812 ishaan812 commented Feb 11, 2026

Summary

This PR improves code maintainability by replacing hardcoded numeric literals and strings with named constants. This makes the code more self-documenting and easier to maintain.

Changes

1. MaxCommitTraversalDepth constant (1000)

  • Added MaxCommitTraversalDepth constant to strategy/common.go
  • Replaced bare 1000 literals in 4 files:
    • strategy/common.go - IsAncestorOf() function
    • strategy/auto_commit.go - findReferencedCheckpoints() function (also standardized to use errStop sentinel)
    • rewind.go - countCommitsBetween() function
    • explain.go - computeReachableFromMain() function
  • All represent the same concept: safety limit for git commit history traversal

2. Prompt truncation constants

  • Added maxPromptPreviewLen = 100 in hooks_geminicli_handlers.go for log preview truncation
  • Added maxDisplayPromptLen = 500 in manual_commit_condensation.go for display truncation
  • Both are scoped locally to where they're used

3. RedactedPlaceholder constant

  • Added RedactedPlaceholder = "REDACTED" (exported) to redact/redact.go
  • Replaced bare string literal in String() function
  • Makes the redaction behavior more configurable and self-documenting

Testing

  • ✅ All unit tests pass (23 packages)
  • ✅ Build succeeds (go build ./...)
  • ✅ Code formatted with gofmt
  • ✅ No new linter warnings (verified with ReadLints)

Files Changed

  • cmd/entire/cli/explain.go
  • cmd/entire/cli/hooks_geminicli_handlers.go
  • cmd/entire/cli/rewind.go
  • cmd/entire/cli/strategy/auto_commit.go
  • cmd/entire/cli/strategy/common.go
  • cmd/entire/cli/strategy/manual_commit_condensation.go
  • redact/redact.go

Total: 7 files, +20 insertions, -11 deletions

Motivation

This addresses code quality improvements identified during codebase analysis:

  • Reduces risk of inconsistent values if the limit needs to be changed
  • Makes the code more self-documenting (constant names explain intent)
  • Follows Go best practices for avoiding magic numbers

Improves code maintainability by replacing hardcoded numeric literals
and strings with named constants:

- Add MaxCommitTraversalDepth (1000) for git history traversal safety limit
  - Replaces bare 1000 in strategy/common.go, auto_commit.go, rewind.go, explain.go
  - Also standardizes auto_commit.go to use errStop sentinel instead of ad-hoc error

- Add maxPromptPreviewLen (100) in hooks_geminicli_handlers.go for log truncation
- Add maxDisplayPromptLen (500) in manual_commit_condensation.go for display truncation

- Add RedactedPlaceholder constant ("REDACTED") to redact package
  - Replaces bare string literal in String() function

All tests pass (23 packages), build succeeds, formatting verified.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ishaan812 ishaan812 requested a review from a team as a code owner February 11, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant