Writing a SafeContext connector
A connector copies data from one place (a chat app, an export file, a folder of transcripts) into SafeContext. SafeContext scrubs every item on the Mac before storing it, then serves the result to AI.
Anyone can write a connector. Connectors ship inside SafeContext: you open a pull request, it gets reviewed, and it goes out in the next signed release. SafeContext never loads code from outside the app. A connector sees raw data before the scrubber does, so every one is reviewed.
The rules
These protect the promise SafeContext makes to its users. A pull request that breaks one is not merged.
- Read-only. Never send, change or delete anything at the source.
- Nothing leaves the Mac. No network calls, except to the service's own official API when the connector is an API connector (see below). No analytics and no “phone home”.
- Everything goes through the scrubber. Return
RawItems fromto_itemand letReaderSourcedo the rest. Never write to the store, and never overridesync()or_syncer(). The registry refuses a connector that does. - Keep raw data out of logs. Log ids and counts only, never message text, names, numbers or addresses.
- Ask, don't take. Declare every permission in
requirementswith a plainwhy. Check access incheck_access()without triggering a macOS prompt, and raiseNeedsPermissionwith apermission_helpentry that tells the user what to do. - Only fixture data in tests. Build fake databases or files in a temp folder (see
demo/fake_messages.py). Never read real user data, not even your own. - No new dependencies without asking first in the pull request.
How to write one
Start from tests/example_connector.py. It is a complete working connector for a chat export file.
- The reader goes in
src/safecontext/readers/<name>.py. It knows the source's format and nothing about SafeContext: a function or class that yields plain dataclasses, oldest first, starting after a cursor. - The connector goes in
src/safecontext/sources/<name>.py. SubclassReaderSourceand provide the items in the table below. Batching, scrubbing, storing, the cursor, locking, progress and error handling all come fromReaderSource. - Register it: add the class to
CONNECTORSinsources/__init__.py, and remove its entry fromCOMING_SOONif it had one. - Test it: add a
ConnectorFixturefor it totests/test_connector_conformance.pyand put it inFIXTURES. The kit (tests/connector_kit.py) then checks first sync, resuming, a bad record, a crash while reading, undeclared kinds, permissions, disconnect, and that card numbers and one-time codes never reach the store's files. Add tests of your own for the mapping into_item. - Run
.venv/bin/pytest. Every test must pass.
idLowercase, stable, never changes: items are stored under it.name,descriptionShown on the Sources screen.kindsOne or more ofmessage,event,chat,transcript. The scrubber picks its rules by kind, so new kinds aren't allowed.api_version1, the currentCONNECTOR_API_VERSION.requirementsWhat the connector needs, each with a reason for the user.link_prefixesOptional.https://deep links the app may open for an item.read(cursor)Records aftercursor(Nonemeans everything), oldest first.to_item(record)One record to oneRawItem, orNoneto skip it.cursor_of(record)A string that makesreadresume after this record.check_access()Optional. RaiseNeedsPermissionwhen access is missing.
API connectors
Connectors for web services that need a sign-in (like Gmail and Google Calendar) sync through their own API syncer and are not covered by the kit yet. Open an issue before starting one, so the sign-in and token storage can be designed with you.
Pull request checklist
- Reader in
readers/, connector insources/, registered inCONNECTORS - Conformance fixture added;
.venv/bin/pytestpasses - Follows the rules above: read-only, no network, no raw logging, fixture data only
- Every requirement has a plain-language
why - New dependencies, if any, are explained