Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: CodebuffAI/codebuff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: CodebuffAI/codebuff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: refactoring-phase-2
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 20 commits
  • 104 files changed
  • 1 contributor

Commits on Jan 23, 2026

  1. refactor(cli): improve send-message hook architecture (Commit 2.1)

    Extracts and reorganizes the send-message hook into focused modules:
    - use-message-execution.ts: Core SDK execution with agent resolution
    - use-run-state-persistence.ts: Run state management and persistence
    - helpers/send-message.ts: Helper functions for message preparation and error handling
    
    Fixes out-of-credits (402) error handling regression:
    - Preserves statusCode in ExecuteMessageError for HTTP errors
    - Detects 402 errors in the non-throwing path and handles them properly
    - Ensures UI switches to out-of-credits mode when credits are exhausted
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    ed2c97f View commit details
    Browse the repository at this point in the history
  2. refactor(cli): consolidate block utils and add tree traversal primiti…

    …ves (Commit 2.2)
    
    Creates centralized block-tree-utils.ts with reusable tree traversal primitives:
    - traverseBlocks: visit all blocks with early exit support
    - findBlockByPredicate: find first matching block
    - mapBlocks: transform blocks with reference preservation
    - updateBlockById: update by any ID type (agentId, toolCallId, thinkingId, id)
    - updateAgentBlockById: update specifically agent blocks
    - toggleBlockCollapse: toggle collapsed state with userOpened tracking
    
    Comprehensive tests (33 tests) including:
    - Deep nesting (3+ levels) coverage
    - Proper type narrowing (isAgentBlock guard instead of "as any")
    - Multiple toggle cycle verification
    - Parent + children transformation tests
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    eebabc8 View commit details
    Browse the repository at this point in the history
  3. refactor(agent-runtime): extract helpers from run-agent-step.ts (Comm…

    …it 2.3)
    
    📊 ~1,050 implementation lines, ~540 test lines
    
    Extracts 6 helper functions from run-agent-step.ts into agent-step-helpers.ts:
    - initializeAgentRun: Resolves agent template, starts run, builds system prompt and tools
    - buildInitialMessages: Constructs initial message history
    - buildToolDefinitions: Converts ToolSet to serializable format for token counting
    - prepareStepContext: Prepares context for agent step including token counting
    - handleOutputSchemaRetry: Handles missing output schema validation
    - Error utilities: extractErrorMessage, isPaymentRequiredError, getErrorStatusCode
    
    Includes comprehensive unit tests (35 tests) with section headers for readability.
    
    Fixes model parameter in callTokenCountAPI to ensure correct tokenizer is used.
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    848ab2c View commit details
    Browse the repository at this point in the history
  4. refactor(billing): consolidate billing duplication (Commit 2.4)

    📊 ~540 implementation lines, ~1,140 test lines
    
    Extracts shared billing logic into billing-core.ts:
    - consumeFromOrderedGrants: Core grant consumption algorithm
    - getOrderedActiveGrants: Grant ordering and filtering
    - calculateGrantCreditsToConsume: Per-grant consumption calculation
    
    Includes comprehensive unit tests (160 tests) covering:
    - Basic consumption scenarios
    - Grant ordering (expiration, type priority)
    - Boundary conditions and edge cases
    - Negative balance handling
    
    Fixes boundary condition: uses strict > comparison instead of >= for threshold checks.
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    139cf38 View commit details
    Browse the repository at this point in the history
  5. refactor(cli): simplify use-activity-query.ts (Commit 2.6)

    📊 ~810 implementation lines, ~1,630 test lines
    
    Extracts query infrastructure from use-activity-query.ts into focused modules:
    - query-cache.ts: LRU cache with generation tracking to prevent stale updates
    - query-executor.ts: Debounced query execution with cancellation
    - query-invalidation.ts: Cache invalidation utilities
    
    Includes comprehensive unit tests (100+ tests) covering:
    - Cache operations (get, set, delete, TTL)
    - Generation tracking to prevent cache resurrection
    - Query deduplication and debouncing
    - Invalidation patterns
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    558f654 View commit details
    Browse the repository at this point in the history
  6. refactor(common): consolidate XML parsing (Commit 2.7)

    Consolidates XML parsing utilities into a dedicated directory structure:
    - common/src/util/xml/index.ts: Unified re-exports
    - common/src/util/xml/saxy.ts: Streaming XML parser (moved)
    - common/src/util/xml/tag-utils.ts: closeXml, getStopSequences
    - common/src/util/xml/tool-call-parser.ts: parseToolCallXml
    
    Added package.json export for @codebuff/common/util/xml
    Updated all consumers to use new import paths
    
    Comprehensive unit tests added:
    - tool-call-parser.test.ts: 39 tests for XML parsing
    - tag-utils.test.ts: 10 tests for tag utilities
    - Total: 49 new tests
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    f3a68e3 View commit details
    Browse the repository at this point in the history
  7. refactor(common): consolidate analytics (Commit 2.8)

    Consolidates analytics utilities into a dedicated directory structure:
    - common/src/analytics/index.ts: Unified re-exports
    - common/src/analytics/core.ts: PostHog client factory, types
    - common/src/analytics/dispatcher.ts: Cross-platform event dispatcher with buffering
    - common/src/analytics/log-helpers.ts: Log data conversion, PII filtering
    - common/src/analytics/track-event.ts: Server-side tracking with lazy client init
    
    Key features:
    - PII filtering with allowlist/blocklist approach
    - MAX_BUFFER_SIZE=100 prevents unbounded memory growth
    - Lazy PostHog client initialization in production only
    - resetAnalyticsClient() helper exported for testing
    
    Comprehensive unit tests added:
    - track-event.test.ts: 16 tests for trackEvent, flushAnalytics, resetAnalyticsClient
    - Tests cover lazy init, error handling, env gating, edge cases (empty userId)
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    bf0ffb7 View commit details
    Browse the repository at this point in the history
  8. refactor(internal): extract doStream helpers (Commit 2.9)

    📊 ~1,560 implementation lines, ~1,590 test lines
    
    Extracts stream handling logic into focused helper modules:
    
    CLI (suggestion engine):
    - suggestion-parsing.ts: Parse AI suggestions from text
    - suggestion-filtering.ts: Filter and rank suggestions
    
    OpenAI-compatible package (stream processing):
    - stream-content-tracker.ts: Track streaming content chunks
    - stream-tool-call-handler.ts: Handle tool call assembly
    - stream-usage-tracker.ts: Track token usage from stream
    
    Includes comprehensive unit tests and mutation tests for parsing robustness.
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    a5b31db View commit details
    Browse the repository at this point in the history
  9. refactor(common): consolidate browser-actions parsing (Commit 2.13)

    - Create parseActionValue() utility for string→type conversion
    - Create LAZY_EDIT_PATTERNS constant for pattern matching
    - Update parseBrowserActionXML and parseBrowserActionAttributes
    - Simplify hasLazyEdit() and replaceNonStandardPlaceholderComments()
    - Add comprehensive unit tests
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    d311633 View commit details
    Browse the repository at this point in the history
  10. refactor(agents): extract file I/O helpers in agent-builder.ts (Commi…

    …t 2.14)
    
    - Create readAgentFile() helper with graceful error handling
    - Create EXAMPLE_AGENT_PATHS constant for file path maintainability
    - Add critical file validation for type definitions
    - Reduce duplicated readFileSync calls
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    577bb07 View commit details
    Browse the repository at this point in the history
  11. refactor(sdk): extract helpers from promptAiSdkStream (Commit 2.15)

    📊 ~1,450 implementation lines, ~970 test lines
    
    Extracts helpers from run-state.ts and llm.ts into focused modules:
    - claude-oauth-errors.ts: OAuth error detection and handling
    - file-tree-builder.ts: Project file tree construction
    - git-operations.ts: Git status and diff operations
    - knowledge-files.ts: Knowledge file loading
    - project-discovery.ts: Project root and file discovery
    - session-state-processors.ts: Session state building
    - stream-cost-tracker.ts: Streaming cost calculation
    - tool-call-repair.ts: Malformed tool call recovery
    
    Includes comprehensive unit tests (150+ tests) for each extracted module.
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    e45a179 View commit details
    Browse the repository at this point in the history
  12. refactor(billing): DRY up auto-topup logic (Commit 3.1)

    - Create auto-topup-helpers.ts with shared payment method helpers
    - Extract fetchPaymentMethods, isValidPaymentMethod, filterValidPaymentMethods
    - Extract findValidPaymentMethod, createPaymentIntent, getOrSetDefaultPaymentMethod
    - Reduce duplication between user and org auto-topup flows
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    b377901 View commit details
    Browse the repository at this point in the history
  13. refactor(internal): split db/schema.ts into domain files (Commit 3.2)

    Splits the monolithic db/schema.ts into domain-specific schema files:
    - schema/users.ts: User-related tables
    - schema/organizations.ts: Org-related tables
    - schema/billing.ts: Billing and credit tables
    - schema/runs.ts: Run and agent tables
    - schema/enums.ts: Shared enums
    - schema/index.ts: Re-exports all schemas
    
    Fixes: Restores .notNull() constraints on org auto_topup_threshold and auto_topup_amount fields that were accidentally dropped during extraction.
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    23343b3 View commit details
    Browse the repository at this point in the history
  14. refactor: remove dead code (Commits 3.3 + 3.4)

    - Delete tool-stream-parser.old.ts (217 lines of unused code)
    - Remove deprecated type aliases and unused exports
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    2b720c9 View commit details
    Browse the repository at this point in the history
  15. test(billing): add comprehensive unit tests for auto-topup-helpers

    - Add 17 tests for isValidPaymentMethod (card expiration, link, unsupported types)
    - Add 8 tests for filterValidPaymentMethods (empty, valid, invalid, mixed)
    - Add 11 tests for findValidPaymentMethod (first valid, order preservation)
    - Add 6 tests for fetchPaymentMethods (Stripe API mocking)
    - Add 9 tests for createPaymentIntent (params, idempotency, metadata)
    - Add 10 tests for getOrSetDefaultPaymentMethod (default reuse, setting new)
    - Total: 61 comprehensive tests with Stripe API mocking
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    e3fec21 View commit details
    Browse the repository at this point in the history
  16. feat(cli): Escape key now closes slash and mention dropdown menus

    - Add handleEscapeKey action to keyboard-actions.ts
    - Integrate escape handling in use-chat-keyboard.ts
    - Update chat.tsx to support dropdown dismissal
    - Add comprehensive unit tests for keyboard actions
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    77dea85 View commit details
    Browse the repository at this point in the history
  17. chore: clean up old files after analytics and XML consolidation

    - Delete common/src/analytics-core.ts (moved to analytics/core.ts)
    - Delete common/src/analytics.ts (moved to analytics/track-event.ts)
    - Delete common/src/util/analytics-dispatcher.ts (moved to analytics/dispatcher.ts)
    - Delete common/src/util/analytics-log.ts (moved to analytics/log-helpers.ts)
    - Delete common/src/util/saxy.ts (moved to util/xml/saxy.ts)
    - Delete common/src/util/xml-parser.ts (moved to util/xml/tool-call-parser.ts)
    - Delete common/src/util/xml.ts (moved to util/xml/tag-utils.ts)
    - Update trace-processing.ts imports
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    7367ae1 View commit details
    Browse the repository at this point in the history
  18. fix(cli): update command registry tests for compatibility

    - Update bash-command.test.ts for new test patterns
    - Update command-args.test.ts for new test patterns
    - Minor updates to command-registry.ts
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    36293ad View commit details
    Browse the repository at this point in the history
  19. fix: address critical issues from code review

    - fix(sdk): add 10s timeout to git operations to prevent hanging
    - fix(sdk): add maxFiles limit (10000) to discoverProjectFiles to prevent memory issues
    - fix(billing): add guard for empty paymentMethods array in getOrSetDefaultPaymentMethod
    - fix(billing): fix card expiration check to use end of month (not start)
    
    - fix(cli): prevent in-flight fetches from resurrecting deleted cache entries
      - Generation counter now persists after deletion
      - Added comprehensive tests for deletion protection
    
    - test(cli): add unit tests for use-keyboard-navigation hook (40 tests)
    - test(cli): add unit tests for use-keyboard-shortcuts hook (49 tests)
    - test(cli): add tests for cache deletion and in-flight request protection (7 tests)
    brandonkachen committed Jan 23, 2026
    Configuration menu
    Copy the full SHA
    200fb3c View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    b7e3cb3 View commit details
    Browse the repository at this point in the history
Loading