Add the MessagesCore library product with the reads a mirror needs (#1) #3

Merged
svc-agent-writer merged 2 commits from issue-1-messagescore into main 2026-11-13 04:42:18 +00:00

Closes #1

What this change does

It splits the package into two library products and adds the read-only reads that a mirror of the history needs.

  • MessagesCore holds the read-only store, the schema, the models, the typedstream decoder, the config and the errors. It depends on SQLite only and links no MCP package.
  • AppleMessagesBlade depends on MessagesCore, re-exports it, and keeps the nine tools and the attachment byte reader.
  • The package still ships no binary.

The two commits

Commit Holds
641923f The package split, the mirror reads of the issue, and the fixes from the review.
60b3de5 Seven read-only additions that the wire contract of the first consumer needs. The issue does not list them.

Acceptance criteria

Criterion Proof
MessagesCore builds with no MCP dependency The MessagesCore target depends on the SQLite product only. testCoreHasNoMCPDependency proves it.
Every existing blade test passes unchanged Tests/AppleMessagesBladeTests has no diff. 28 tests run, 3 live smoke tests skip, 0 fail.
New tests on a synthetic history MessagesCoreTests: 34 tests, 0 failures. They cover each case that the issue names.
No code path writes to the history or sends a message One Connection(, opened with readonly: true. Every statement is a SELECT. testPackageSourcesContainNoWriteSQL guards both.
Ready for a v0.2.0 tag CHANGELOG.md [Unreleased] is complete. Version.swift is not changed; the owner bumps it in the tag commit.

Fixes from the review

  • A read no longer crashes the process on a SQLite step error. The query runner iterated with a try! inside SQLite.swift. It now throws. This defect was in the code before this change, and the fix holds for the nine tools too. testStepErrorThrowsAndDoesNotTrap traps the test process when the old loop is restored.
  • The Tapback code check cannot overflow on a hostile value.
  • A Tapback target in none of the three stored forms gives no Tapback.
  • A time that is not a whole number above zero is in no time-ordered page.
  • A row that the owner sent never gives the handle of the other member of a one-to-one chat as its sender.
  • An IN list binds at most 500 values.

The seven additions in 60b3de5

  • messages(withGUIDs:): the rows of a list of guids.
  • ChatWithMembers.style and isGroup: the stored chat.style value.
  • highestIssuedMessageRowID(): it does not fall when the newest row is deleted.
  • messagesByDateDescending(before:limit:inChatOnly:): a newest-first page by the stored date.
  • MirrorMessage.chatIDs: every chat that holds the row.
  • RecentlyDeletedRecord.chatIDs, isFromMe, senderHandleID and senderHandle.
  • TapbackKind.other: a Tapback code that the package does not know still gives its target.

What a reviewer should know

  • README.md changed. It has a new "Products" section. It states what MessagesCore promises to a consumer, and what it leaves to that consumer: the deny list, the redaction and the access control. The section "No external exposure" now binds the AppleMessagesBlade tools only.
  • Schema facts that only the synthetic fixture tests: chat.style 43 and 45, date_edited, the unit of chat_recoverable_message_join.delete_date, the Tapback codes 2006 and 2007, and the deleted_messages table. schemaReport() on a real history is the check. The owner runs it.
  • No CI runs on this repository. The test results above come from a local run of swift test on macOS.
  • No format lint ran. swift-format is not installed on the build host.
  • Not in this change: the v0.2.0 tag and the Version.swift bump. The owner does both.

🤖 Generated with Claude Code

Closes #1 ## What this change does It splits the package into two library products and adds the read-only reads that a mirror of the history needs. - `MessagesCore` holds the read-only store, the schema, the models, the typedstream decoder, the config and the errors. It depends on SQLite only and links no MCP package. - `AppleMessagesBlade` depends on `MessagesCore`, re-exports it, and keeps the nine tools and the attachment byte reader. - The package still ships no binary. ## The two commits | Commit | Holds | |---|---| | `641923f` | The package split, the mirror reads of the issue, and the fixes from the review. | | `60b3de5` | Seven read-only additions that the wire contract of the first consumer needs. The issue does not list them. | ## Acceptance criteria | Criterion | Proof | |---|---| | `MessagesCore` builds with no MCP dependency | The `MessagesCore` target depends on the `SQLite` product only. `testCoreHasNoMCPDependency` proves it. | | Every existing blade test passes unchanged | `Tests/AppleMessagesBladeTests` has no diff. 28 tests run, 3 live smoke tests skip, 0 fail. | | New tests on a synthetic history | `MessagesCoreTests`: 34 tests, 0 failures. They cover each case that the issue names. | | No code path writes to the history or sends a message | One `Connection(`, opened with `readonly: true`. Every statement is a `SELECT`. `testPackageSourcesContainNoWriteSQL` guards both. | | Ready for a `v0.2.0` tag | `CHANGELOG.md` `[Unreleased]` is complete. `Version.swift` is not changed; the owner bumps it in the tag commit. | ## Fixes from the review - **A read no longer crashes the process on a SQLite step error.** The query runner iterated with a `try!` inside SQLite.swift. It now throws. This defect was in the code before this change, and the fix holds for the nine tools too. `testStepErrorThrowsAndDoesNotTrap` traps the test process when the old loop is restored. - The Tapback code check cannot overflow on a hostile value. - A Tapback target in none of the three stored forms gives no Tapback. - A time that is not a whole number above zero is in no time-ordered page. - A row that the owner sent never gives the handle of the other member of a one-to-one chat as its sender. - An `IN` list binds at most 500 values. ## The seven additions in `60b3de5` - `messages(withGUIDs:)`: the rows of a list of guids. - `ChatWithMembers.style` and `isGroup`: the stored `chat.style` value. - `highestIssuedMessageRowID()`: it does not fall when the newest row is deleted. - `messagesByDateDescending(before:limit:inChatOnly:)`: a newest-first page by the stored date. - `MirrorMessage.chatIDs`: every chat that holds the row. - `RecentlyDeletedRecord.chatIDs`, `isFromMe`, `senderHandleID` and `senderHandle`. - `TapbackKind.other`: a Tapback code that the package does not know still gives its target. ## What a reviewer should know - **`README.md` changed.** It has a new "Products" section. It states what `MessagesCore` promises to a consumer, and what it leaves to that consumer: the deny list, the redaction and the access control. The section "No external exposure" now binds the `AppleMessagesBlade` tools only. - **Schema facts that only the synthetic fixture tests:** `chat.style` 43 and 45, `date_edited`, the unit of `chat_recoverable_message_join.delete_date`, the Tapback codes 2006 and 2007, and the `deleted_messages` table. `schemaReport()` on a real history is the check. The owner runs it. - **No CI runs on this repository.** The test results above come from a local run of `swift test` on macOS. - **No format lint ran.** `swift-format` is not installed on the build host. - **Not in this change:** the `v0.2.0` tag and the `Version.swift` bump. The owner does both. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Split the package into two library products. MessagesCore holds the
read-only store, the schema, the models, the typedstream decoder, the
config and the errors. It depends on SQLite only and links no MCP
package. AppleMessagesBlade depends on MessagesCore, re-exports it and
keeps the nine tools and the attachment byte reader. The package still
ships no binary.

Add the reads that a mirror needs, all read-only and keyset-paged:

- messagesAfter and messagesBefore: pages across all chats by row id.
- messagesEditedAfter: edited and unsent rows by the edit time in Unix
  milliseconds and then the row id.
- chatsWithMembers, and a filter that keeps only a row in a chat.
- recentlyDeleted: one record for each message, by its earliest
  deletion time that is a whole number above zero.
- hardDeletions and hardDeletionCount: the records of deleted_messages
  and the all-time count from sqlite_sequence.
- attachmentInfo: type and size only, never a file name or a path.
- schemaReport: an advisory report of present, missing and new columns.

MessagesCore never selects the edit-history blob or the text of a
deleted message part.

Fixes from the review of this change:

- A read no longer crashes the process on a SQLite step error. The
  query runner iterated with a try! inside SQLite.swift; it now throws.
  This holds for every read of the store, the nine tools included.
- The Tapback code check cannot overflow, and a target in none of the
  three stored forms gives no Tapback.
- A time that is not a whole number above zero is in no time page.
- A row that the owner sent never gives the handle of the other member
  of a one-to-one chat as its sender.
- An IN list binds at most 500 values.

README gains a Products section. It states what MessagesCore promises
to a consumer and what it leaves to that consumer: the deny list, the
redaction and the access control.

Tests: MessagesCoreTests has 25 tests on a synthetic history. The 28
existing blade tests pass unchanged (3 live smoke tests skipped).

Version.swift is not changed. The owner bumps it in the v0.2.0 tag
commit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A review of the mirror reads against the wire contract of their first
consumer found seven rules that a consumer could not meet from the
public API alone. Each addition is read-only, and each closes one gap.
None is in the list of the issue; all are in its purpose.

- messages(withGUIDs:): the rows of a list of guids, so a consumer
  can learn the chat and the sender of a reply target or of a Tapback
  target before it serves that target.
- ChatWithMembers.style and isGroup: the stored chat.style value. A
  count of members is a guess, and a rule that hides a one-to-one
  chat must not depend on a guess. The values 43 and 45 come from
  public descriptions of the schema; only the synthetic fixture tests
  them.
- highestIssuedMessageRowID(): the greater of the sqlite_sequence
  value and the highest present row id. The highest present row id
  alone falls when the newest row is deleted.
- messagesByDateDescending: a newest-first page by the stored date,
  for a consumer that needs the newest row by date.
- MirrorMessage.chatIDs: every chat that holds the row. The lowest
  chat id alone can hide a second chat.
- RecentlyDeletedRecord gains chatIDs, isFromMe and the sender, from
  the same statement, so a consumer decides what to hide without a
  second read that can miss.
- TapbackKind.other: a code in 2008-2999 or 3008-3999 gives a Tapback
  with its target. Before, such a row gave no target at all.

Tests: MessagesCoreTests has 34 tests with 0 failures. The 28 existing
blade tests pass unchanged (3 live smoke tests skipped).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.