@danj/hey-email
HEY.com email for Kody: search threads, read messages, download PDF attachments, and write drafts. Sending is barred until you allow it.
- Version
- 2.0.0
- License
- Published
- November 30, 2026
- Pinned commit
3f72e37- Rating
- No ratings yet
- Forks
- 0
- Adaptation effort
- —
README
Agent docs@danj/hey-email
Intent
Let your agents, and the Kody packages they build, search, read, and draft
your HEY mail. The package calls HEY at app.hey.com, through the same API
that HEY's CLI and SDK use. Kody never runs the hey CLI. You run it once on
your computer, to sign in for Kody.
Sending is barred until you allow it. SENDING in src/config.js is the
switch. While it is 'barred', no function sends mail, and your agent saves
drafts for you to send. The section "The sending switch" explains how to
allow sending.
The package is publish-locked on Kody. A change goes live only after you review it and click Promote this commit.
What you can ask your agent
Ask your agent for any of these:
- "Find the invoice from Acme last week and read me its total from the PDF."
- "Summarize my thread with Ada."
- "Draft a reply to Ada that says the Tuesday slot works." The agent saves a reply draft and gives you its edit link.
- "Email Bob that I'm running late." The agent saves a new draft addressed to Bob and gives you its edit link.
- "Move this Logos newsletter thread to Paper Trail." The agent moves that one thread. Other mail from the same sender stays where it is.
You do these yourself:
- Send each draft. Open its edit link in HEY, check the text and the recipients, and send.
- Sign in to HEY, and save that login in Kody with the setup script.
- Review and promote each change to the package on Kody.
- Decide whether sending is ever allowed.
What it does
Each ./name export imports as kody:@danj/hey-email/name.
| Export | What it does | HEY calls |
|---|---|---|
kody:@danj/hey-email | Returns your HEY { id, name }. Use it as a shallow check of your setup. | GET /identity |
./search | Searches your mail. Pass limit greater than 10 to fetch further pages. | GET /advanced_search.json, then ?page=2 and so on |
./paper-trail | Moves one thread to the Paper Trail, by topic id or entry id. | GET /boxes.json, then POST /topics/{id}/moves.json |
./boxes | Lists your boxes, such as the Imbox and the Feed. | GET /boxes.json |
./topic | Reads one thread. | GET /topics/{id}.json |
./entries | Lists the messages in a thread. | GET /topics/{id}/entries.json |
./message | Reads one message with its HTML body. | GET /messages/{id}.json |
./attachments | Lists PDF attachments on a message, then downloads one file as base64. The default export is listPdfs: metadata only, no bytes. | GET /messages/{id}.json to list. One GET for a chosen PDF. |
./drafts | Lists, reads, and saves drafts with their recipients. HEY keeps each saved draft as a draft. It also exports the three send functions. | GET /entries/drafts.json, GET /messages/{id}/edit.json, POST /messages.json, POST /entries/{id}/replies.json |
./reply | Saves a reply draft on a thread. | GET /entries/{id}/replies/new.json, POST /entries/{id}/replies.json |
./send | sendMessage, sendReply, and sendDraft. | None while sending is barred. While it is allowed, a confirmed send calls POST /messages.json, POST /entries/{id}/replies.json, or PUT /messages/{id}.json. |
AGENTS.md lists each function's inputs, results, and errors.
The default export of ./attachments is listPdfs. It returns metadata only
(index, filename, contentType, url, filesize) and has no bytes.
There is no combined download of every file. Call downloadPdf for one PDF
as base64.
Set it up
You do the steps that need your HEY sign-in or your review. Your agent does the rest. Your HEY tokens never pass through the agent.
Kody keeps your HEY login as one login credential named hey. It holds
the refresh token and the install id of Kody's HEY login. Kody runs HEY's
token refresh, saves a new refresh token when HEY returns one, and places
the access token on each request to app.hey.com. The package never sees
either token.
You need a HEY account. HEY is a paid 37signals product with a free trial at hey.com. A
@hey.comaddress and a HEY for Domains address both work.You install the HEY CLI on your computer, version 1.4.0 or later. Follow the hey-cli install guide. You also need Node 22 or later, and a checkout of this package's repository. If the Kody CLI is not signed in, run
npx --yes @kodycodes/cli@latest auth login.You sign in to HEY for Kody, in a new folder. To HEY, Kody is then a separate device, like a second computer. Your own CLI login stays as it is. Run these lines in one terminal window, and keep that window for steps 4 and 6.
HEY_KODY=$(mktemp -d) XDG_CONFIG_HOME="$HEY_KODY" HEY_NO_KEYRING=1 hey auth login XDG_CONFIG_HOME="$HEY_KODY" HEY_NO_KEYRING=1 hey auth statushey auth loginopens HEY's sign-in page in your browser.HEY_NO_KEYRINGmakes the CLI save this login in the folder, not in your keychain. In the status, theAuth:line must showoauth, and theStorage:line must showfile. Do not add--cookieor--tokento the login. Those logins store no refresh token, so Kody cannot use them. HEY can email you about a sign-in from a new device.You save the login in Kody. From the checkout, in the same window, run:
node scripts/provision-login.mjs --dir "$HEY_KODY"The script reads the refresh token and the install id from the folder and sends them to Kody on stdin. It never prints them. Its last line must be
status=pass. It stops, and saves nothing, when Kody already has a credential namedhey. If it printsSave unconfirmed, checkheyin Kody Credentials before you run it again.In Kody Credentials, map
heyto this package and to each package that imports it, if Kody did not. Tell your agent. Your agent runsidentity(). It must return your HEY id and name.You delete the folder with
rm -rf "${HEY_KODY:?}". Kody now holds the only copy of this login. Nothing else refreshes its tokens, so Kody's copy stays valid.Your agent locks the package on Kody, if it is not locked yet. From then on, each change waits on the package page until you click Promote this commit. Only you can unlock it, on the package's settings page.
Reconnect
When Kody reports login_needs_reconnect, HEY no longer accepts the saved
refresh token. Run setup steps 3, 4, and 6 again, and add --reconnect to
the script:
node scripts/provision-login.mjs --dir "$HEY_KODY" --reconnectIts last line must be status=pass. The script saves the new value onto the
same hey, which keeps its id and mappings.
Use it from another package
The agent that builds your package follows these steps.
- Add
"@danj/hey-email": "*"tokody.dependencies, and import the exports askody:@danj/hey-email/<export>. In a fork of this package, use your own scope instead of@danj. - Read
AGENTS.mdfor each function's inputs, results, and errors. - Your package bundles a snapshot of this one. After each change here, republish your package.
The sending switch
SENDING in src/config.js is the switch. Its committed value is
'barred'. Only you decide to change it.
SENDING = 'barred' (committed) | SENDING = 'allowed' | |
|---|---|---|
sendMessage, sendReply, sendDraft | Return the barred result, with barred: true and sent: false. No request reaches HEY. | Send when confirm is exactly true. Otherwise, return a dry run, and send nothing. |
createDraft, createReplyDraft | Save a draft with its recipients. HEY does not send it. | Same. |
An agent must not change SENDING to finish an email request. While sending
is allowed, an agent still saves a draft, unless you ask it in plain words to
send now. An agent must not send from an unattended run, such as a reminder
job. The code does not enforce these two rules, so the lock on Kody matters.
Allowing sending
- You change
SENDINGto'allowed'. You can commit to main, or open a pull request. You can also ask your agent in plain words to make this change. - Three test files and the test hook pin the barred value. The same commit
updates
test/sending-gate.test.js,test/sending-allowed.test.js,test/redirects.test.js, andtest/hooks.mjs. It also updates the two package descriptions inpackage.json. - The
sending-policy-suitecheck fails on a branch or pull request that sets'allowed'while main is still'barred'. So a pull request with this change shows a failed check. You can still merge it. After that, later branches carry'allowed'from main, and the check passes them. - Your agent publishes the package to Kody. You review the change on the package page, and click Promote this commit. Then your agent republishes the packages that use this one.
Security posture
| Credential | What it holds | Kody sends it to | Kody updates it |
|---|---|---|---|
hey (kind login) | The refresh token and the install id of Kody's HEY login | app.hey.com/oauth/tokens, in HEY's refresh request | When HEY returns a new refresh token |
| The access token | Kody gets it from each refresh, and keeps it until it expires. | app.hey.com, in the Authorization header | At each refresh |
The package declares the need hey in kody.credentials, with kind
login. It sends each app.hey.com request through credential('hey'),
and holds no token. Every request asks Kody to fill secret placeholders only
in headers (x-kody-secret-resolution: headers-only), so draft text that
quotes a placeholder is sent as written.
What this design guarantees:
- The access token goes only to
app.hey.com.resolveHeyUrlrefuses every other origin, and Kody sends the token only to the credential's host. - The package follows redirects itself. A redirect off
app.hey.comdrops the credential. PDF downloads continue to the file storage host as a plainGET. JSON calls refuse the redirect. - The package retries nothing. When
app.hey.comanswers 401 to a request with no body, Kody refreshes the token once and retries that request once. A write that gets a 401 is not replayed. A 401 from the PDF storage host starts no refresh. - No function sends mail while
SENDINGis'barred'. - The package is publish-locked. No change, including a change to
SENDING, goes live on Kody before you promote it.
What it leaves open:
- Any code that imports this package can read all your mail and save
drafts. While
SENDINGis'allowed', that code can also send mail. - GitHub refuses branch protection on this private repository on the free
plan. So the
sending-policy-suitecheck does not block a merge or a push to main. The lock on Kody is the control that holds.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
HEY 401 <path> on a read | HEY refused the token, and Kody's one retry did not help. | Wait a minute, and read again. If it still fails, follow the Kody error code that the next read returns. |
HEY 401 <path> on a write | HEY refused the token. Kody does not retry a request with a body, and neither does the package. | See "After a write fails with HEY 401" below. |
credential_unbound | The package's need hey is not mapped to a credential. | In Kody Credentials, map hey to this package. If hey does not exist, run setup steps 3 to 6. |
login_failed | Kody's refresh request to HEY failed. | Wait retryAfterSeconds, or a minute, then try again. |
login_retry_later | Kody is waiting after a recent refresh failure. | Wait retryAfterSeconds, or a minute, then try again. |
login_needs_reconnect | HEY refused the saved refresh token. A token from a --cookie or --token login gives the same error. | Follow "Reconnect" under "Set it up". |
Refusing to send HEY credentials to <origin> | A URL outside app.hey.com reached the package, such as a PDF link in an email. downloadPdf stops there and returns no file. | Open the file in HEY. |
Refusing to follow HEY redirect to <origin> | HEY redirected a JSON call off app.hey.com. | None. The package refuses it. |
listPdfs returns no PDFs | The HTML came from the entries list, which omits attachments. | Pass the message id. |
After a write fails with HEY 401
A write that throws HEY 401 <path> may or may not have taken effect.
- Check whether it happened:
listDrafts()for a draft, orgetTopic()for a reply or a move. - Make a read, such as
identity(). - If the read also fails with a 401 or
login_retry_later, waitretryAfterSeconds, or a minute, and read again. Onlogin_needs_reconnect, you reconnect: a freshhey auth login, then the script with--reconnect, as "Reconnect" under "Set it up" shows. Its last line must bestatus=pass. - Repeat the write only after a read succeeds and the check shows that the write did not happen.
Development
The package has no dependencies. npm test runs the Node test runner. The
test hooks in test/hooks.mjs stub kody:runtime: its credential()
records the key and marks each request it sends. The hooks also load a second
copy of src/ where SENDING is 'allowed'. The committed file stays
'barred'.
The sending-policy-suite GitHub Actions workflow runs on Node 22, on pull
requests and on pushes to every branch except main. It runs
scripts/sending-policy-check.mjs, then npm test. The script fails when
the branch sets SENDING to 'allowed' and origin/main does not. Its last
lines are status=pass, status=fail, or status=blocked when it cannot
read origin/main, with a reason= line when it does not pass.
For your own terminal, use the HEY CLI directly. It also ships an agent skill and an MCP server, described in the hey-cli agent guide.
Credits and license
This package is a fork of @noah/hey-email on Kody, by Noah (HiThereHey).
Noah wrote the first HEY API wrapper, the draft and send functions, and the
token refresh. Daniel Jomphe's fork adds the redirect rules, the sending
switch, the HEY SDK request format, the separate Kody login, and the move of
the tokens into the Kody login credential hey.
MIT. LICENSE keeps Noah's copyright notice, and adds Daniel Jomphe's for
the fork's changes.
Report this listing
Log in to report this listing.