Skip to content

Commit 06baf5f

Browse files
authored
An app profile writes drafts and asks HEY to send, which waits for you (#648)
* An app profile writes drafts and asks HEY to send, which waits for you On a profile whose endpoint is the HEY app (#646), every write was refused: an agent could read the Imbox, the Screener and the drafts, but not screen a sender, write a draft or ask for one to go. Now, under HEY_EXPERIMENTAL=app, on an app profile: - hey screener approve|deny <sender id or address> runs the door's screener.decide; an address is looked up in the app's own Screener, waiting and decided, so an agent never meets the app's sender ids. - hey compose --draft and hey reply <thread> --draft run draft.write and draft.reply, and answer the draft under the server's field names with hey -P <profile> draft send <id> as its next step. - hey draft send <id> runs message.send, which the app holds in its window until the person presses Send: it answers meta.status pending, says "Waiting in HEY ... nothing has been sent" and exits 9, a code nothing else exits with; help exit-codes lists 9 under the gate only. - compose and reply without --draft, bulk-reply send and forward are refused before anything happens, pointing at --draft and then hey draft send; flags the door has no field for are refused likewise. - The door's write refusals (not_an_address, not_saved, not_a_sender, disabled, an id it does not hold) and its two answers that may have done something (saved_not_listed, session_ended) say what to do. On every profile, hey screener approve|deny also take a sender's email address, looked up among the clearances waiting, then those decided. Verified: each behaviour red against #646's head first (18 tests; the 3 flag-refusal guards already held there, #646 refusing every write); a test with HEY_TOKEN set and a server that fails if reached runs every verb above, done and refused, and goes red when draft send's app branch is removed. make check green, .surface unchanged, darwin, windows and linux build. Rejected: turning a send into a draft quietly on the app, which would make send mean two things; several senders per screening on the app, which the door decides one at a time, so a partial failure would need its own report. * An id the app does not hold is not found, and a cut-off send says nothing went A fresh review of the app's writes found an app profile answering a sender or draft id the app doesn't hold with exit 1, where the same sender by address, and the server for an id it doesn't hold, answer 2; a send cut off by the app's session end worded as "may have been done", which reads as sent; a disabled send with no arg hinted " takes one of"; and a Screener address lookup stopped at its 100-page cap answering not found, which it never searched. Now an id refusal naming the ids the app holds is exit 2; the cut-off send says it may be waiting in HEY and nothing has been sent without you; the hint names the draft; and a capped lookup is exit 7, pointing at the clearance ID. Verified: each red first against 60d0455 (four subtests and one test), then make check green. * Only a disabled send names the draft, and only a cap stops an address lookup The second review found the previous commit naming the draft as the argument of every message.send refusal without one, so an older app's not_offered got the wrong hint and an unloaded list's unavailable became a usage error (1) instead of the app's (7); and the address lookup's cap check reading the cursor, which an empty last page still carries, so a short Screener could be called past the cap. Now the draft is named in the disabled case alone, and the cap check reads collectPages' Truncated. Verified: three new cases red against f7cf0cf, then make check green. * An app answer that did otherwise sends you to HEY, and refusals keep the profile Bot review (cubic, Copilot) found: an app answer saying it decided or saved something other than what was asked hinted at upgrading hey, and a non-pending answer to a send said only that it wasn't waiting, where both may have changed something; the refusal of a verb that sends now suggested hey draft send without -P, which on a server default profile runs an app draft id against the server; and an address missing from a Screener the app lists only part of answered not found, unsearched. Now those answers say the app may have done something and send you to HEY before running it again; the refusal names -P <profile>; and an address missing from a partial list is exit 7, pointing at the sender ID. The empty-page lookup test's server answers only the PATCH it expects. Verified: five tests red against 6724516 first, then make check green. * The partial-Screener hint names the profile, and both answers word the check alike A review of 9154df1 found the hint for an address missing from a partial Screener naming a bare hey screener list, which on a server default profile lists clearance ids, not the app's senders; and the two "may have done something" answers wording their check two ways. Now the hint names -P <profile> and both say "before running it again". Verified: make check green. * Every hint on an app profile names its commands on that profile Copilot's review of 9154df1 found the saved_not_listed hint naming a bare hey draft list, which on a server default profile lists the server's drafts: the person concludes the save failed and writes the draft again. Eight more hints on the app's paths named a command the same way, some of them listing server ids that the next command would then act on at the server. Now every hint on the app's paths goes through appCommandLine, so each names -P <profile>; TestAppHintsNameTheProfile holds it for seven of them. Verified: red against ddc0175 (the saved_not_listed case and six of seven hints), then make check green. * Tests start with no endpoint and no config, whatever order they run in CI's Race Detection, which runs the suite shuffled, failed on TestAFailedAnswerNamesTheProfile (seed 1794515981961670522): an app profile run before it left answeringEndpoint set, so withProfileMeta added meta it expected not to. A second seed, 1794520381712021194, failed TestAccountOverrideNotice the same way through a leftover cfg. Now the root-flag reset every CLI test uses restores the endpoint and the config after each run, and both tests set what they assume. Verified: both seeds red on thelio before, green after, with four more shuffled runs green. * The Imbox comes from the app however its profile is chosen A dev build was reported answering hey box view imbox with meta.endpoint server under an app profile. Run hermetically, the built binary answers from the app (exit 6 with no door, meta.endpoint app) with the gate, and refuses without it; it answers server only when the config holding the profile isn't the one hey reads (XDG_CONFIG_HOME pointing elsewhere), where there is no app profile to choose. This test holds the routing for the default profile, -P and HEY_PROFILE over a server default, with and without the gate, with a token at hand and a server that fails the test if reached. It passes on a0f020f's code: a guard, not a fix.
1 parent 006911e commit 06baf5f

21 files changed

Lines changed: 1528 additions & 43 deletions

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Configuration (the base URL, the default linked account, the Imbox's cover, and
5959

6060
Named profiles (`profiles` and `default_profile` in the global config, chosen by `-P`/`--profile`, `HEY_PROFILE` or `default_profile`) are ported from basecamp-cli and live in `internal/config/profiles.go` and `internal/cmd/profile*.go`. The CLI's credential is keyed by its origin with no profile active and by `profile:<name>` with one; `hey mcp`'s by `mcp::<origin>` and `mcp:profile:<name>`. A profile's credential goes only to its own server: an override naming another is refused, and a stored sign-in issued by another server is refused too. With no profiles configured nothing reads differently; keep it that way. A repository's `.hey/config.json` sets the profile keys only once `hey config trust-local` trusts them.
6161

62-
A profile's `endpoint` is `server` (the default) or `app`: the HEY app on this computer, reached through `internal/localapp` at the door it opens (`$XDG_RUNTIME_DIR/hey/agent.sock`, or `HEY_LOCAL_SOCKET`). It is experimental: only `HEY_EXPERIMENTAL=app` honours it, and without it an app profile is refused, never answered from HEY's server, and nothing about it shows in help, `.surface` or the docs. On an app profile the commands in `appRoutes` (`internal/cmd/endpoint.go`) answer from the app, every other command that reads a server is refused, and nothing reads a credential; a new route branches on `appEndpoint()` first in its `RunE`. Answers keep the server's field names, and an experimental build names `meta.endpoint`.
62+
A profile's `endpoint` is `server` (the default) or `app`: the HEY app on this computer, reached through `internal/localapp` at the door it opens (`$XDG_RUNTIME_DIR/hey/agent.sock`, or `HEY_LOCAL_SOCKET`). It is experimental: only `HEY_EXPERIMENTAL=app` honours it, and without it an app profile is refused, never answered from HEY's server, and nothing about it shows in help, `.surface` or the docs. On an app profile the commands in `appRoutes` (`internal/cmd/endpoint.go`) answer from the app, every other command that reads a server is refused, and nothing reads a credential; a new route branches on `appEndpoint()` first in its `RunE`. Answers keep the server's field names, and an experimental build names `meta.endpoint`. The app sends nothing without the person: a verb that would send now is refused there (`appSendsNow`), and `hey draft send` answers pending, exit 9 (`output.ErrPending`), which only an app profile produces.
6363

6464
### CLI
6565

‎docs/cli.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ hey screener list --count # just the number waiting
285285
hey screener approve 91 # let a sender through
286286
hey screener approve 91 --box "The Feed" # let them through, into another box
287287
hey screener deny 91 92 # turn several senders away
288+
hey screener deny offers@example.com # turn a sender away by their address
288289
hey screener deny 91 --spam # turn them away and mark what they sent as spam
289290
hey screener history # who has already been screened
290291
hey screener clear # trash everything waiting, deciding no one
@@ -358,7 +359,7 @@ Search accepts free text plus `--required`, `--any`, `--none`, `--exact`, `--fro
358359

359360
Contact updates preserve omitted name, email, and alias fields. Supplying `--alias` replaces the complete alias list; `--alias=` clears it. Contact notes accept positional content, `--note`, stdin, or `$EDITOR`. `hey contact note set` replaces the whole note — HEY has no append — so adding a detail means reading the note, changing it and writing all of it back. `hey contact note show --json` (and `hey contact show --json`) answers the note three ways, each an empty string for a contact with no note: `note`, HEY's plain text, which drops formatting (bold is lost, list items become `•`); `note_html`, as HEY serves it; and `note_markdown`, the note as Markdown. `note_markdown_lossless` says whether that Markdown holds everything in the note. When it is `true`, `note set` writes the Markdown back as the same note — HEY's editor markup becomes plain paragraphs on the first write, and from then on a read and a write give the same Markdown and the same HTML. When it is `false`, the note holds an attachment, an image, a table or other markup Markdown has no syntax for, and setting Markdown would drop it: change `note_html` and write it back with `--note-html` instead. HTML passed to `--note-html` has the `<div class="trix-content">` HEY serves a note in taken off, so writing back `note_html` does not nest the note one level deeper each time. Nothing guards a read and a write against someone else saving in between: the last save wins, as it does in the web app. HEY hides contacts rather than permanently deleting them; hidden contacts leave lists, autocomplete, and search, and can be shown again by ID. `hey contact deliver <contact-id> --to imbox|feed|papertrail|screened-out` changes where a contact's future email arrives. It takes a contact ID — not an email address, clearance ID, box item ID, or box ID — and is write-only because HEY does not expose the current setting as structured data. Imbox removes a custom box preference; choosing a box does not screen a denied contact back in. Screened Out is the blocking choice and applies only to external email contacts. Selecting The Feed removes an existing bundle because HEY cannot keep Feed-designated contacts bundled; Imbox and Paper Trail preserve eligible bundles. Existing mail can move asynchronously, so success means HEY accepted the change, not that every affected thread has already moved. Bundling groups a contact's mail into one row without merging or deleting the underlying threads; unbundling lists those threads separately again. HEY bundles only a contact with no box preference or one sent to the Paper Trail; for any other, bundling answers success and changes nothing. `hey contact photo set <contact-id> <file>` uploads a photo for a contact, replacing any it had, and answers the contact with its new `avatar_url`; `hey contact photo remove <contact-id>` takes it off again, and removing from a contact with no photo succeeds. The file must be a PNG or JPEG — the formats HEY's own photo picker takes — of at most 40 MiB, the most HEY's web form can send, and at most 58 megapixels and 16000 pixels a side. That admits a full-resolution photo from a modern phone (an iPhone's 48 megapixels, or 50 on Android) and stays inside what HEY can resize, which for a JPEG it has to rotate upright is about 58.7 megapixels; the one exception is a CMYK JPEG that has to be rotated, which HEY can resize only up to about 47 megapixels, and which cameras do not produce. HEY shows a contact photo at 300×300 at most anyway. It is judged by its bytes rather than its name, and its header must decode, because HEY stores any file it is handed and fails only later, when it resizes the photo to show it: a HEIC from a phone, a photo too large to resize, or a file that is not an image would be saved and never shown, the contact keeping their initials. HEY crops the photo to a square, so a square image without transparency works best, and it caches avatars, so after a set or a remove the old photo can still show in places for up to 30 minutes. Your own contact takes a photo too. A contact that is hidden, an alias, or another HEY user cannot be edited: updating it, setting or deleting its note, or setting or removing its photo answers `not_found`. `hey contact list` holds only non-HEY senders you have screened in — other HEY users, senders still in or denied by The Screener, aliases and hidden contacts are left out. It has no search: HEY ignores a query on that list, so finding a contact by email means reading every page (`--all`) and filtering, which matches primary addresses only.
360361

361-
The Screener is where first-time senders wait. `hey screener list` returns clearance IDs — not contact IDs — with the sender and the subject of what they sent, plus `topic_id` for reading the thread before deciding. `--count` asks for the number alone, which is a far cheaper request than the queue, and prints it as a bare number like every other command's `--count`, so `n=$(hey screener list --count)` reads it directly. Approving delivers everything the sender has waiting; denying hides it. Either is reversible with the opposite command, and `hey screener history` shows what was already decided. Both listings page the way `hey box view` does: `--all` follows HEY's cursor to the end of the queue (up to 100 pages), and a single-page or capped read reports `next_page` in its JSON meta, which `--page <next_page>` continues from — the cursor is opaque, so a page *number* does not name a position. `hey screener list` also reports `total_count`, the whole queue's size, next to what the read returned. `--box` and `--seen` approve one sender at a time; several IDs go through HEY's bulk endpoint, which takes neither. `--seen` reliably marks the mail read only for a sender with one waiting thread. `--spam` marks what they sent as spam and, for a single ID, trains HEY's filter, which is harder to undo than denying. `hey screener clear` moves everything waiting to Trash (a shared thread loses your access instead) without approving or denying anyone — those senders reappear on their next email.
362+
The Screener is where first-time senders wait. `hey screener list` returns clearance IDs — not contact IDs — with the sender and the subject of what they sent, plus `topic_id` for reading the thread before deciding. `--count` asks for the number alone, which is a far cheaper request than the queue, and prints it as a bare number like every other command's `--count`, so `n=$(hey screener list --count)` reads it directly. Approving delivers everything the sender has waiting; denying hides it. Either is reversible with the opposite command, and `hey screener history` shows what was already decided. Both listings page the way `hey box view` does: `--all` follows HEY's cursor to the end of the queue (up to 100 pages), and a single-page or capped read reports `next_page` in its JSON meta, which `--page <next_page>` continues from — the cursor is opaque, so a page *number* does not name a position. `hey screener list` also reports `total_count`, the whole queue's size, next to what the read returned. `hey screener approve` and `deny` also take a sender's email address in place of a clearance ID, in any case: it is looked up among the senders waiting and then among those already screened, so a decision can be changed by address too; an address nobody there sends from is `not_found` (exit 2). `--box` and `--seen` approve one sender at a time; several IDs go through HEY's bulk endpoint, which takes neither. `--seen` reliably marks the mail read only for a sender with one waiting thread. `--spam` marks what they sent as spam and, for a single ID, trains HEY's filter, which is harder to undo than denying. `hey screener clear` moves everything waiting to Trash (a shared thread loses your access instead) without approving or denying anyone — those senders reappear on their next email.
362363

363364
`hey bulk-reply preview` is read-only and resolves each posting to its latest replyable entry. `hey bulk-reply send` resolves the selection again, skips threads without a replyable entry, keeps HEY's server-provided name tag, and returns the exact reply count, delivery ID, delayed state, undo URL, and undo command. Posting IDs must be positive and unique. The message can come from `-m`, stdin, or `$EDITOR`; `--attach` is repeatable.
364365

‎internal/cmd/accounts_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func TestUnavailableAccountNotice(t *testing.T) {
5555
}
5656

5757
func TestAccountOverrideNotice(t *testing.T) {
58+
// No profile: a run before this one, in whatever order -shuffle picks, may have left one.
59+
previous := cfg
60+
t.Cleanup(func() { cfg = previous })
61+
cfg = nil
5862
if accountOverrideNotice(config.SourceGlobal) != "" {
5963
t.Fatal("global default unexpectedly reported an override")
6064
}

‎internal/cmd/app_endpoint_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ func TestAppRefusesWhatItDoesNotServe(t *testing.T) {
236236
{"screener", "history", "--all"},
237237
{"draft", "list", "--all"},
238238
{"thread", "read", "801"},
239-
{"compose", "--to", "marcus@example.com", "--subject", "Saturday", "--message", "On my way"},
240-
{"draft", "send", "9001"},
241-
{"screener", "approve", "51"},
242239
{"search", "invoice"},
240+
{"draft", "delete", "9001"},
241+
{"screener", "clear"},
242+
{"bulk-reply", "preview", "301"},
243243
{"tui"},
244244
{"doctor"},
245245
} {

‎internal/cmd/app_reads.go‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,7 @@ func (c *draftsCommand) runApp(cmd *cobra.Command) error {
378378

379379
drafts := make([]appDraft, 0, len(answer.Drafts))
380380
for _, d := range answer.Drafts {
381-
drafts = append(drafts, appDraft{
382-
ID: d.ID, Subject: d.Subject, Summary: d.Summary, UpdatedAt: d.SavedAt, ScheduledDeliveryAt: d.SendsAt,
383-
MadeAs: d.MadeAs, Kind: d.Kind, Thread: d.Thread, Account: d.Account,
384-
From: d.From, To: orEmpty(d.To), Cc: orEmpty(d.Cc), Bcc: orEmpty(d.Bcc), Sendable: *d.Sendable,
385-
})
381+
drafts = append(drafts, appDraftFrom(d))
386382
}
387383
notice := ""
388384
if c.limit > 0 && len(drafts) > c.limit {
@@ -415,6 +411,16 @@ func (c *draftsCommand) runApp(cmd *cobra.Command) error {
415411
)
416412
}
417413

414+
// appDraftFrom is a draft the door answered under the server's field names. Its sendable
415+
// has been checked to be there.
416+
func appDraftFrom(d appDoorDraft) appDraft {
417+
return appDraft{
418+
ID: d.ID, Subject: d.Subject, Summary: d.Summary, UpdatedAt: d.SavedAt, ScheduledDeliveryAt: d.SendsAt,
419+
MadeAs: d.MadeAs, Kind: d.Kind, Thread: d.Thread, Account: d.Account,
420+
From: d.From, To: orEmpty(d.To), Cc: orEmpty(d.Cc), Bcc: orEmpty(d.Bcc), Sendable: *d.Sendable,
421+
}
422+
}
423+
418424
// orEmpty keeps a missing address list a list in the JSON, never null.
419425
func orEmpty(addresses []string) []string {
420426
if addresses == nil {

0 commit comments

Comments
 (0)