Skip to content

feat: Phase 1 BrainBar formatting foundation#155

Merged
EtanHey merged 1 commit into
mainfrom
phase1/formatting-foundation
Mar 31, 2026
Merged

feat: Phase 1 BrainBar formatting foundation#155
EtanHey merged 1 commit into
mainfrom
phase1/formatting-foundation

Conversation

@EtanHey
Copy link
Copy Markdown
Owner

@EtanHey EtanHey commented Mar 31, 2026

Port Python formatting into native Swift renderers. Models for chunk/entity/digest/kg/stats. Shared SearchResultCard and SearchResultsList. 151 tests pass. Requesting review from @coderabbitai @codex @cursor @BugBot @greptileai

Note

Add typed result models and box-drawing TextFormatter for BrainBar MCP tool responses

  • Introduces typed models (SearchResult, EntityCard, StatsResult, DigestResult, KGSearchResult) in brain-bar/Sources/BrainBar/Models/ to replace raw dictionary handling across MCP tool handlers.
  • Adds TextFormatter.swift with static methods that produce box-drawn text output for search results, entity cards, stats, digests, and knowledge-graph results, replacing the prior Formatters utility.
  • Updates MCPRouter handlers (handleBrainSearch, handleBrainRecall, handleBrainEntity, handleBrainDigest) to map database payloads into typed models and format responses via TextFormatter.
  • Extends BrainDatabase.recallStats to include distinct projects and content_types arrays from the chunks table.
  • Adds reusable SearchResultCard and SearchResultsList SwiftUI components; QuickCapturePanel now renders search results through these shared components.
  • Behavioral Change: MCP tool response text structure changes for brain_search, brain_recall, brain_entity, and brain_digest — clients parsing raw output may see different formatting.
📊 Macroscope summarized 4f9fc99. 16 files reviewed, 4 issues evaluated, 0 issues filtered, 3 comments posted

🗂️ Filtered Issues

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 31, 2026

Warning

Rate limit exceeded

@EtanHey has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 27 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 25 minutes and 27 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5d87fa57-56f7-4b15-8bdf-1ef393f5f9a2

📥 Commits

Reviewing files that changed from the base of the PR and between aab4c0a and 4f9fc99.

📒 Files selected for processing (17)
  • brain-bar/Sources/BrainBar/BrainBarSupport.swift
  • brain-bar/Sources/BrainBar/BrainDatabase.swift
  • brain-bar/Sources/BrainBar/Dashboard/StatusPopoverView.swift
  • brain-bar/Sources/BrainBar/Formatting/TextFormatter.swift
  • brain-bar/Sources/BrainBar/MCPRouter.swift
  • brain-bar/Sources/BrainBar/Models/DigestResult.swift
  • brain-bar/Sources/BrainBar/Models/EntityCard.swift
  • brain-bar/Sources/BrainBar/Models/KGSearchResult.swift
  • brain-bar/Sources/BrainBar/Models/SearchResult.swift
  • brain-bar/Sources/BrainBar/Models/StatsResult.swift
  • brain-bar/Sources/BrainBar/QuickCapturePanel.swift
  • brain-bar/Sources/BrainBar/Views/Components/SearchResultCard.swift
  • brain-bar/Sources/BrainBar/Views/Components/SearchResultsList.swift
  • brain-bar/Tests/BrainBarTests/MCPRouterTests.swift
  • brain-bar/Tests/BrainBarTests/SearchResultPresentationTests.swift
  • brain-bar/Tests/BrainBarTests/TextFormatterParityTests.swift
  • findings.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch phase1/formatting-foundation

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.

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@EtanHey
Copy link
Copy Markdown
Owner Author

EtanHey commented Mar 31, 2026

@coderabbitai review

@EtanHey
Copy link
Copy Markdown
Owner Author

EtanHey commented Mar 31, 2026

@codex review

@EtanHey
Copy link
Copy Markdown
Owner Author

EtanHey commented Mar 31, 2026

@cursor @BugBot review

@EtanHey
Copy link
Copy Markdown
Owner Author

EtanHey commented Mar 31, 2026

@greptileai review

@cursor
Copy link
Copy Markdown

cursor Bot commented Mar 31, 2026

You need to increase your spend limit or enable usage-based billing to run background agents. Go to Cursor

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 31, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Comment on lines +78 to +91
private static func decodeMetadata(_ raw: Any?) -> [String: String] {
if let metadata = raw as? [String: String] {
return metadata
}
guard let text = raw as? String, let data = text.data(using: .utf8),
let parsed = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
return [:]
}
var result: [String: String] = [:]
for (key, value) in parsed {
result[key] = String(describing: value)
}
return result
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Low Models/EntityCard.swift:78

decodeMetadata silently returns an empty dictionary when raw is a [String: Any] dictionary containing non-String values (e.g., integers or booleans). The cast to [String: String] fails, the subsequent cast to String also fails, and all metadata is lost without warning. Consider checking for [String: Any] first and applying String(describing:) to the values, so mixed-type dictionaries are preserved.

-    private static func decodeMetadata(_ raw: Any?) -> [String: String] {
-        if let metadata = raw as? [String: String] {
-            return metadata
-        }
-        guard let text = raw as? String, let data = text.data(using: .utf8),
-              let parsed = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else {
-            return [:]
-        }
-        var result: [String: String] = [:]
-        for (key, value) in parsed {
-            result[key] = String(describing: value)
-        }
-        return result
-    }
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file brain-bar/Sources/BrainBar/Models/EntityCard.swift around lines 78-91:

`decodeMetadata` silently returns an empty dictionary when `raw` is a `[String: Any]` dictionary containing non-String values (e.g., integers or booleans). The cast to `[String: String]` fails, the subsequent cast to `String` also fails, and all metadata is lost without warning. Consider checking for `[String: Any]` first and applying `String(describing:)` to the values, so mixed-type dictionaries are preserved.

Evidence trail:
brain-bar/Sources/BrainBar/Models/EntityCard.swift lines 78-93 at REVIEWED_COMMIT show the `decodeMetadata` function. Line 79-81: first tries `raw as? [String: String]`, fails for mixed-type dictionaries. Line 82: then tries `raw as? String`, fails for any dictionary type. Line 83: returns empty `[:]` when guard fails. The code path for `[String: Any]` dictionaries is not handled, causing silent data loss.

Comment on lines +110 to +114
private static func extractImportance(from metadata: String) -> Int? {
guard let range = metadata.range(of: "imp ") else { return nil }
let digits = metadata[range.upperBound...].prefix { $0.isNumber }
return Int(digits)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Low Models/SearchResult.swift:110

extractImportance(from:) fails to parse negative importance values. When compactMetadata produces "imp -5", the prefix { $0.isNumber } check stops at the - character since it isn't a digit, resulting in an empty string that converts to nil. This causes data loss when reconstructing a SearchResult via init(rowID:title:metadata:tags:) from metadata originally generated by compactMetadata. Consider updating the extraction logic to handle an optional leading - before the digits.

+    private static func extractImportance(from metadata: String) -> Int? {
+        guard let range = metadata.range(of: "imp ") else { return nil }
+        let remainder = metadata[range.upperBound...]
+        let sign = remainder.first == "-" ? "-" : ""
+        let startIndex = sign.isEmpty ? remainder.startIndex : remainder.index(after: remainder.startIndex)
+        let digits = remainder[startIndex...].prefix { $0.isNumber }
+        return Int(sign + digits)
+    }
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file brain-bar/Sources/BrainBar/Models/SearchResult.swift around lines 110-114:

`extractImportance(from:)` fails to parse negative importance values. When `compactMetadata` produces `"imp -5"`, the `prefix { $0.isNumber }` check stops at the `-` character since it isn't a digit, resulting in an empty string that converts to `nil`. This causes data loss when reconstructing a `SearchResult` via `init(rowID:title:metadata:tags:)` from metadata originally generated by `compactMetadata`. Consider updating the extraction logic to handle an optional leading `-` before the digits.

Evidence trail:
brain-bar/Sources/BrainBar/Models/SearchResult.swift lines 10 (importance: Int?), 23-37 (compactMetadata producing "imp \(importance)"), 112-115 (extractImportance using prefix { $0.isNumber }) at REVIEWED_COMMIT. Swift's Character.isNumber returns false for '-' character, causing prefix to return empty string for negative numbers.

Comment on lines +24 to +38
ForEach(results) { result in
SearchResultCard(
result: result,
isSelected: result.id == selectedResultID,
isCopied: result.id == copiedResultID
)
.onTapGesture {
onSelect(result.id)
}
.onTapGesture(count: 2) {
onActivate(result.id)
}
.focusable(false)
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium Components/SearchResultsList.swift:24

The double-tap gesture at line 33 will never fire because the single-tap gesture at line 30 intercepts all touches first. In SwiftUI, gestures are evaluated in modifier order; the single tap wins immediately, so onActivate is never called. Apply the double-tap gesture modifier before the single-tap gesture so both can be recognized.

                    ForEach(results) { result in
                        SearchResultCard(
                            result: result,
                            isSelected: result.id == selectedResultID,
                            isCopied: result.id == copiedResultID
                        )
+                        .onTapGesture(count: 2) {
+                            onActivate(result.id)
+                        }
                        .onTapGesture {
                            onSelect(result.id)
                        }
-                        .onTapGesture(count: 2) {
-                            onActivate(result.id)
-                        }
                        .focusable(false)
                    }
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file brain-bar/Sources/BrainBar/Views/Components/SearchResultsList.swift around lines 24-38:

The double-tap gesture at line 33 will never fire because the single-tap gesture at line 30 intercepts all touches first. In SwiftUI, gestures are evaluated in modifier order; the single tap wins immediately, so `onActivate` is never called. Apply the double-tap gesture modifier before the single-tap gesture so both can be recognized.

Evidence trail:
brain-bar/Sources/BrainBar/Views/Components/SearchResultsList.swift lines 30-35 at REVIEWED_COMMIT - shows single tap gesture (.onTapGesture) applied at line 30 before double tap gesture (.onTapGesture(count: 2)) at line 33. SwiftUI documentation confirms that when combining tap gestures with different counts, the higher count gesture should be applied first to allow proper recognition.

@EtanHey EtanHey merged commit 5e6d0ab into main Mar 31, 2026
3 of 6 checks passed
EtanHey added a commit that referenced this pull request Mar 31, 2026
…er size

Five QA fixes from user testing after overnight sprint PRs #155-#160:

(1) Store freezes UI: Added storeAsync() — runs DB write on background
    DispatchQueue via withCheckedThrowingContinuation. QuickCapture
    submitCapture now uses async path, UI stays responsive.

(2) Search results missing dates: SearchQueryCandidate now includes
    date, project, importance fields. searchCandidates SQL extended to
    SELECT created_at, project, importance. SearchViewModel passes
    these through to SearchResult for display.

(3) Enter in search goes to capture: Changed applySelectedSearchResult()
    to copy result to clipboard instead of switching to capture mode.
    Also auto-selects first result when selectedResultIndex is nil.

(4) Popover oversized: Reduced contentSize from 420x620 to 360x320.

(5) VoiceBar duplicate struct: Merged voicelayer PR #109.

Also: Updated busy_timeout test to match PR #160's 30s value.

212 tests, 0 failures. Build and sign pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
EtanHey added a commit that referenced this pull request Mar 31, 2026
…er size (#161)

Five QA fixes from user testing after overnight sprint PRs #155-#160:

(1) Store freezes UI: Added storeAsync() — runs DB write on background
    DispatchQueue via withCheckedThrowingContinuation. QuickCapture
    submitCapture now uses async path, UI stays responsive.

(2) Search results missing dates: SearchQueryCandidate now includes
    date, project, importance fields. searchCandidates SQL extended to
    SELECT created_at, project, importance. SearchViewModel passes
    these through to SearchResult for display.

(3) Enter in search goes to capture: Changed applySelectedSearchResult()
    to copy result to clipboard instead of switching to capture mode.
    Also auto-selects first result when selectedResultIndex is nil.

(4) Popover oversized: Reduced contentSize from 420x620 to 360x320.

(5) VoiceBar duplicate struct: Merged voicelayer PR #109.

Also: Updated busy_timeout test to match PR #160's 30s value.

212 tests, 0 failures. Build and sign pass.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant