Skip to content

Fix Bear app not detecting note changes from CLI#6

Merged
asabirov merged 11 commits into
mainfrom
fix/vector-clock-and-text-asset
Mar 28, 2026
Merged

Fix Bear app not detecting note changes from CLI#6
asabirov merged 11 commits into
mainfrom
fix/vector-clock-and-text-asset

Conversation

@asabirov
Copy link
Copy Markdown
Owner

Summary

  • Vector clock preservation: incrementVectorClock now uses PropertyListSerialization to properly parse and update the bplist, preserving all existing device entries instead of replacing them with only "Bear CLI". This lets Bear correctly detect the note as modified.
  • Clear text asset on edit: When updating note content via textADP, the text asset field is now set to null so Bear doesn't read stale content from the old asset URL.

Test plan

  • Edit a note via bcli edit and verify Bear app shows the updated content after sync
  • Verify vector clock contains both original device entries and "Bear CLI" after edit
  • Test with notes that use asset storage (larger notes) to confirm content updates properly

asabirov and others added 11 commits March 28, 2026 16:15
Extract BearCLICore library and add test infrastructure
CloudKit's records/lookup endpoint can return records without a "fields"
key (e.g. not-found or deleted records), causing a keyNotFound decoding
error. This adds a custom Decodable init that defaults fields to an
empty dictionary, and filters out fieldless records from lookupRecords
so the get command correctly falls through to uniqueIdentifier search.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rd-lookup

Fix crash when CloudKit returns records without fields
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Swift's padding(toLength:) truncates strings longer than the target
length. CloudKit record names can exceed 36 characters, so the
hardcoded 38-column width was silently chopping IDs. Compute the
column width dynamically from the actual data instead.
Fix truncated record IDs in table output
The modified record-level metadata was passing through the old timestamp
from the original record, causing CloudKit to not recognize the update.
Now uses the current timestamp for the modified metadata in both
updateNote() and trashNote().

Also bumps version to 0.3.3.
Fix modification date not updating after note edit
Two issues prevented Bear from recognizing edits made via the CLI:

1. Vector clock was being replaced instead of updated - incrementVectorClock
   created a new clock with only "Bear CLI", discarding all other device
   entries. Bear uses the vector clock to track changes across devices, so
   losing entries caused it to misinterpret the update. Now uses
   PropertyListSerialization to properly parse, preserve all device entries,
   and only increment the "Bear CLI" counter.

2. Text asset field not cleared on edit - when a note stored its content as
   an external asset (text field with downloadURL), the CLI wrote new content
   to textADP but left the old asset reference intact. Bear may read from
   the asset instead of textADP. Now explicitly sets text to null on update.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@asabirov asabirov merged commit 61b1bc7 into main Mar 28, 2026
asabirov pushed a commit that referenced this pull request Apr 8, 2026
Fix vector clock to preserve all device entries on update
asabirov added a commit that referenced this pull request Apr 8, 2026
Add null text field to edit record to trigger Bear desktop sync detection.
Keep upstream's vector clock byte-scanning approach.

(reimplements PR #6)
asabirov added a commit that referenced this pull request Apr 8, 2026
Add null text field to edit record to trigger Bear desktop sync detection.
Keep upstream's vector clock byte-scanning approach.

(reimplements PR #6)
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