Add SQLite FTS5 scrollback index (no UI yet) - #29
Merged
Conversation
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ScrollbackStorealready performs to per-channel JSONL. Adds the indexer, the search/clear API, and idempotent cold-start backfill that runs through the existing rehydrate path. No UI in this PR — that lands in a follow-up so this can be reviewed and reverted independently.sqlite3_*C surface lives entirely inside anactorand the public API takes/returns Swift value types only (Message,UUID,Date,String)."foo bar",bar*,term1 AND term2 NOT term3,sender:alice).Changes
Sources/BryggaCore/Persistence/ScrollbackIndex.swift— new file. Publicactor ScrollbackIndexwithindex(_:serverID:target:),search(_:scope:limit:), andclear(serverID:target:). PublicSearchScopeenum andSearchHitstruct. Schema: onemessagesFTS5 virtual table withsender/contentindexed andmsg_id/server_id/target/timestamp/kindUNINDEXED, tokenizerunicode61 remove_diacritics 2. Database opens lazily on first call; PRAGMAjournal_mode=WAL+synchronous=NORMAL. Idempotent onmsg_idso cold-start replay never double-counts.Sources/BryggaCore/IRC/IRCSession.swift— three new index sites alongside the existingScrollbackStore.append:record(_:in:),recordServer(_:), and the chathistory finalize loop.loadScrollbackIfNeeded(for:)now also indexes loaded messages so channels first seen post-launch (JOIN, openQuery) backfill into the index.Sources/BryggaCore/Models/AppState.swift—restoreFromStore's rehydrate task indexes every loaded message after insertion (cold-start backfill on the canonical channel name).closePrivateMessageandremoveServernow clear the index for the closed scope. Backfill is "lazy through the rehydrate loop" rather than a filesystem walker, so we always use real channel names instead of the sanitized JSONL filenames.Tests/ScrollbackIndexTests.swift— new file. 10 unit tests covering single-message search, idempotency, server/channel scope filtering, clear semantics, FTS5 phrase + prefix + column-scoped queries, timestamp/kind round-trip, and empty-query handling. Each test uses:memory:for full isolation.Test plan
swift build— passesswift test— 131 tests pass (+10 new)swiftformat --lint .— cleanlldbsession callawait ScrollbackIndex.shared.search("...")to confirm the index is being populated.~/Library/Application Support/Brygga/scrollback.sqliteis created and contains rows:sqlite3 scrollback.sqlite 'SELECT count(*) FROM messages'.Risk / rollback
~/Library/Application Support/Brygga/scrollback.sqlite. Disk footprint scales with scrollback volume; FTS5 typically uses ~1.5–2× the indexed text size. Safe to delete the file at any time — the next launch's rehydrate will repopulate.ScrollbackStore.appendso a failing index write can't break the existing JSONL pipeline.OpaquePointerandsqlite3_*calls are not visible to the rest of the codebase.deinit-time cleanup (would requireisolated deinitfrom macOS 15.4); production singleton never deinits,:memory:test instances cleaned up at process exit. Documented in-source.scrollback.sqlitefile becomes orphaned on disk after revert; users can delete it manually with no impact on chat history (which still lives in JSONL).