-
Notifications
You must be signed in to change notification settings - Fork 385
Comparing changes
Open a pull request
base repository: CodebuffAI/codebuff
base: main
head repository: CodebuffAI/codebuff
compare: refactoring-phase-2
- 20 commits
- 104 files changed
- 1 contributor
Commits on Jan 23, 2026
-
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
Configuration menu - View commit details
-
Copy full SHA for ed2c97f - Browse repository at this point
Copy the full SHA ed2c97fView commit details -
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
Configuration menu - View commit details
-
Copy full SHA for eebabc8 - Browse repository at this point
Copy the full SHA eebabc8View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 848ab2c - Browse repository at this point
Copy the full SHA 848ab2cView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 139cf38 - Browse repository at this point
Copy the full SHA 139cf38View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 558f654 - Browse repository at this point
Copy the full SHA 558f654View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for f3a68e3 - Browse repository at this point
Copy the full SHA f3a68e3View commit details -
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)
Configuration menu - View commit details
-
Copy full SHA for bf0ffb7 - Browse repository at this point
Copy the full SHA bf0ffb7View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for a5b31db - Browse repository at this point
Copy the full SHA a5b31dbView commit details -
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
Configuration menu - View commit details
-
Copy full SHA for d311633 - Browse repository at this point
Copy the full SHA d311633View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 577bb07 - Browse repository at this point
Copy the full SHA 577bb07View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for e45a179 - Browse repository at this point
Copy the full SHA e45a179View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for b377901 - Browse repository at this point
Copy the full SHA b377901View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 23343b3 - Browse repository at this point
Copy the full SHA 23343b3View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 2b720c9 - Browse repository at this point
Copy the full SHA 2b720c9View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for e3fec21 - Browse repository at this point
Copy the full SHA e3fec21View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 77dea85 - Browse repository at this point
Copy the full SHA 77dea85View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 7367ae1 - Browse repository at this point
Copy the full SHA 7367ae1View commit details -
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
Configuration menu - View commit details
-
Copy full SHA for 36293ad - Browse repository at this point
Copy the full SHA 36293adView commit details -
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)
Configuration menu - View commit details
-
Copy full SHA for 200fb3c - Browse repository at this point
Copy the full SHA 200fb3cView commit details -
Configuration menu - View commit details
-
Copy full SHA for b7e3cb3 - Browse repository at this point
Copy the full SHA b7e3cb3View commit details
This comparison is taking too long to generate.
Unfortunately it looks like we can’t render this comparison for you right now. It might be too big, or there might be something weird with your repository.
You can try running this command locally to see the comparison on your machine:
git diff main...refactoring-phase-2