-
-
Notifications
You must be signed in to change notification settings - Fork 68
Add opt-in typing history that learns from what the user writes (with Cotypist import) #841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
senadaruc
wants to merge
2
commits into
FuJacob:main
Choose a base branch
from
senadaruc:feat/typing-history
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import Foundation | ||
|
|
||
| /// File overview: | ||
| /// Value types for Cotabby's typing history: the text the user has written in fields Cotabby was | ||
| /// active in (recorded on this Mac, or imported from another autocomplete app), and the user's | ||
| /// preferences for collecting and using it. | ||
| /// | ||
| /// Why a separate subsystem: history is the only Cotabby data that outlives the field it came from. | ||
| /// Everything else in a request (caret text, clipboard, screen) is ephemeral. Keeping these values | ||
| /// apart from `SuggestionSettingsModel` lets the history store own its own storage, encryption, and | ||
| /// lifecycle, while the suggestion pipeline only sees a narrow read contract | ||
| /// (`SuggestionHistoryProviding`). | ||
|
|
||
| /// One field's worth of the user's writing. | ||
| /// | ||
| /// A record is updated in place while the user keeps typing in the same field, so a long email is | ||
| /// one record rather than one per keystroke. `text` is already scrubbed of secret-like tokens | ||
| /// (`TypingHistoryScrubber`) before it is stored. | ||
| nonisolated struct TypingHistoryRecord: Codable, Equatable, Sendable, Identifiable { | ||
| enum Source: String, Codable, Sendable { | ||
| /// Captured by Cotabby while the user typed. | ||
| case recorded | ||
| /// Brought in from another app's export (for example Cotypist). | ||
| case imported | ||
| } | ||
|
|
||
| let id: UUID | ||
| let bundleIdentifier: String | ||
| /// Registrable web domain for browser fields ("claude.ai"), nil for native apps. | ||
| let domain: String? | ||
| let createdAt: Date | ||
| var updatedAt: Date | ||
| var text: String | ||
| let source: Source | ||
| /// How many characters at the start of `text` were before the caret when it was captured. | ||
| /// Text after the caret is usually not the user's: in an email reply it is the quoted thread | ||
| /// other people wrote. Learning only from this part keeps their names and phrasing out of the | ||
| /// user's shortcuts. Nil means the whole text counts (records written before this existed). | ||
| var typedLength: Int? = nil | ||
|
|
||
| /// The part of `text` the user wrote themselves. | ||
| var typedText: String { | ||
| guard let typedLength, typedLength < text.count else { return text } | ||
| return String(text.prefix(typedLength)) | ||
| } | ||
| } | ||
|
|
||
| /// The encrypted file's plaintext payload. Versioned so a future format change can migrate rather | ||
| /// than silently dropping the user's history. | ||
| nonisolated struct TypingHistoryArchive: Codable, Equatable, Sendable { | ||
| static let currentVersion = 1 | ||
|
|
||
| var version: Int | ||
| var records: [TypingHistoryRecord] | ||
| } | ||
|
|
||
| /// The user's typing-history preferences, persisted by `TypingHistoryStore`. | ||
| nonisolated struct TypingHistoryPreferences: Equatable, Sendable { | ||
| /// Whether stored history shapes suggestions (prompt examples and phrase shortcuts). | ||
| var isUsingHistory: Bool | ||
| /// Whether new typing is recorded. Off by default: recording keeps the user's writing on disk, | ||
| /// which is a privacy decision the user makes, not a default Cotabby makes for them. | ||
| var isRecording: Bool | ||
| /// Apps whose fields are never recorded, by bundle identifier. | ||
| var excludedBundleIdentifiers: [String] | ||
|
|
||
| static let defaults = TypingHistoryPreferences( | ||
| isUsingHistory: false, | ||
| isRecording: false, | ||
| excludedBundleIdentifiers: [] | ||
| ) | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.