Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@tannerlinsley/imessage

Read, search, draft, and explicitly send iMessages on a Mac, using only built-in macOS tools.

FollowFork

Files

AGENTS.md

56 lines · 4.8 KB · Markdown

iMessage package

Use this package to read, search, draft, and explicitly send through the user's Mac. Do not install imsg, Homebrew packages, Python packages, or a native helper. Only shipped macOS tools are required at runtime.

Execution

Pin every native operation to the Mac execution context the user intends. Never allow cloud or another device as a fallback. Conversation IDs are local to that Mac. For this owner's currently registered Mac, select the context named tanners-macbook-pro from the current context list rather than assuming an ID stays valid.

Use CLI execute with --context and static imports. Do not use --local for native calls, because it does not provide kody.command. Host commands must be enabled. Call the root status export first. It checks reading only. Signed desktop builds need version 0.1.4 or newer for Messages automation. Reading the Messages app name alone does not prove Automation permission, use a harmless existing-chat lookup before an approved send. If permissions are missing, explain Full Disk Access for Kody Desktop or the actual daemon host and restart, do not bypass macOS privacy controls.

Imports

import contacts from "kody:@tannerlinsley/imessage/contacts";
import status from "kody:@tannerlinsley/imessage";
import conversations from "kody:@tannerlinsley/imessage/conversations";
import messages from "kody:@tannerlinsley/imessage/messages";
import search from "kody:@tannerlinsley/imessage/search";
import prepare from "kody:@tannerlinsley/imessage/draft";
import send from "kody:@tannerlinsley/imessage/send";

All exports reject unknown input keys. Dates require an ISO timestamp with timezone. Read and search support beforeMessageId, and return nextBeforeMessageId. Continue even after an empty search page when hasMore is true. Report unavailable and truncated rows when completeness matters. Search is literal, case-insensitive, bounded to scanLimit (max 200). Message results are newest stored first, not necessarily chronological after sync. Conversation results are newest created first, not most recently active. Never dump unrelated private content while testing.

Sending

Prepare a draft, show its exact target and body, and obtain explicit user approval before calling send with confirmSend:true. A general request to build or test the package never authorizes a message. Confirm participants for chat IDs, never guess a contact name or phone number. The digest detects edits only, it does not prove human consent. Keep this package private unless the owner asks otherwise.

send({draft}) and send({draft,confirmSend:false}) are previews with no host commands. Never pass true in a smoke test. No automatic retries, fallback recipient, fallback transport, or replay after a timeout. uncertain means inspect Messages before retrying. recorded confirms only a local outgoing database row and does not establish remote delivery. macOS controls any system-level fallback behavior.

New recipients use iMessage. SMS or RCS replies require an existing verified chatId and an explicit matching service on the draft. Never change service after review.

Drafts are returned objects, not Messages.app drafts. Attachments and database writes are unsupported.

Verification

Run npm test on Node 26/macOS. Fixture tests use a synthetic SQLite database and a Foundation archive containing synthetic text. Confirmed-send wrapper tests use a mocked runtime, native send error tests replace the automation task before invocation. No test may execute real Messages sending.

Before publish, run Kody dev check, commit and push, then packagePublishExternalPush. After publishing, smoke the root readiness export and read exports on the selected Mac, returning only counts to avoid exposing private history. Smoke draft and send with confirmSend:false. Do not claim reads are verified if macOS access is blocked, report the exact readiness issue.

Contact names

Use /contacts to resolve a name before searching that person's conversations. query matches a name; handle resolves a phone or email with Apple's matching rules. Never choose the first of several matches. If ambiguous or hasMore, ask which contact or narrow the query. Use each confirmed phone/email with /conversations({participant}), inspect participants and service, then read the chosen chat and select incoming messages. The participant filter normalizes formatting only, it never guesses country codes or phone suffixes.

Desktop 0.1.5 or newer is required for Contacts permission. Status and ordinary reads never prompt. Only an explicit contacts({query,requestAccess:true}) may initiate first access; the user approves macOS consent. Missing access leaves raw message reads usable, with null names and a contactLookup issue. Respect limited contact access. Names are local labels, not identity verification. Do not use name lookup as send approval or resolve an ambiguous draft silently.