@ghostpaw/email 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/SKILL.md ADDED
@@ -0,0 +1,283 @@
1
+ # SKILL.md — `email` CLI as an Agent Tool Surface
2
+
3
+ The `email` binary is a local-first email CLI built on top of `@ghostpaw/email`. It exposes five
4
+ intent-shaped commands that map directly to the library's tool layer. Agents invoke it as a
5
+ subprocess via bash; no MCP server or standing process is needed.
6
+
7
+ ---
8
+
9
+ ## Prerequisites
10
+
11
+ - Node.js ≥ 24
12
+ - Install once:
13
+ ```bash
14
+ npm install -g @ghostpaw/email # global install, `email` in PATH
15
+ npx @ghostpaw/email account add ... # or zero-install via npx
16
+ ```
17
+
18
+ ---
19
+
20
+ ## Account Setup
21
+
22
+ ```bash
23
+ email account add \
24
+ --name work \
25
+ --imap-host imap.fastmail.com --imap-port 993 \
26
+ --smtp-host smtp.fastmail.com --smtp-port 587 \
27
+ --user me@fastmail.com --pass "app-password"
28
+
29
+ email account list # see all accounts
30
+ email account set-default --name work
31
+ email account show # shows config (password redacted)
32
+ ```
33
+
34
+ ### Environment variables (no config file needed — useful in CI)
35
+
36
+ | Variable | Purpose |
37
+ |---|---|
38
+ | `EMAIL_ACCOUNT` | Select account by slug |
39
+ | `EMAIL_IMAP_HOST` | IMAP hostname |
40
+ | `EMAIL_IMAP_PORT` | IMAP port (default: 993) |
41
+ | `EMAIL_IMAP_TLS` | `"false"` to disable TLS |
42
+ | `EMAIL_SMTP_HOST` | SMTP hostname |
43
+ | `EMAIL_SMTP_PORT` | SMTP port (default: 587) |
44
+ | `EMAIL_SMTP_TLS` | `"false"` to disable TLS |
45
+ | `EMAIL_USER` | Auth username |
46
+ | `EMAIL_PASS` | Password auth |
47
+ | `EMAIL_ACCESS_TOKEN` | OAuth2 access token |
48
+ | `EMAIL_REFRESH_TOKEN` | OAuth2 refresh token |
49
+ | `EMAIL_CONFIG_DIR` | Override config directory (full path) |
50
+ | `EMAIL_DATA_DIR` | Override SQLite data directory (full path) |
51
+ | `NO_COLOR` | Disable ANSI color output |
52
+
53
+ ---
54
+
55
+ ## `--json` — Machine-Readable Output
56
+
57
+ **Always use `--json` when invoking from an agent.** Every command outputs a JSON object:
58
+
59
+ ```json
60
+ {
61
+ "outcome": "success",
62
+ "summary": "42 message(s) in INBOX.",
63
+ "entities": [
64
+ { "kind": "message", "id": "1921", "title": "Re: Q2 roadmap" }
65
+ ],
66
+ "nextSteps": [
67
+ "Use view: \"message\" with folder and uid to read a specific message."
68
+ ]
69
+ }
70
+ ```
71
+
72
+ `outcome` values:
73
+ - `"success"` — operation completed
74
+ - `"no_op"` — nothing to do (not an error)
75
+ - `"needs_clarification"` — more information required; check `nextSteps`
76
+ - `"error"` — operation failed; check `summary` for details and `nextSteps` for guidance
77
+
78
+ **On error, `--json` output still goes to stdout** (not stderr) so downstream parsers can always
79
+ parse stdout unconditionally.
80
+
81
+ ---
82
+
83
+ ## Exit Codes
84
+
85
+ | Code | When |
86
+ |---|---|
87
+ | `0` | `success` or `no_op` |
88
+ | `1` | Missing required flag, invalid value, body required |
89
+ | `2` | No config, malformed config, unknown account, no default account |
90
+ | `3` | Authentication failure |
91
+ | `4` | Network / connection failure |
92
+ | `5` | Tool returned `outcome: "error"` |
93
+ | `6` | Tool returned `outcome: "needs_clarification"` |
94
+ | `127` | Unexpected / unhandled error |
95
+
96
+ ---
97
+
98
+ ## Commands
99
+
100
+ ### `email read [view]`
101
+
102
+ Read mailbox state. Default view: `queue` (INBOX).
103
+
104
+ ```bash
105
+ email read --json # queue view, INBOX
106
+ email read folders --json # list all folders
107
+ email read queue --folder Sent --limit 20 --json
108
+ email read queue --unread-only --json
109
+ email read thread --thread-id <id> --json
110
+ email read message --folder INBOX --uid 1921 --json
111
+ email read attachment --folder INBOX --uid 1921 --json # list attachments
112
+ email read eml --folder INBOX --uid 1921 # raw EML bytes to stdout
113
+ ```
114
+
115
+ **`eml` view:** writes raw EML bytes to stdout. In `--json` mode the bytes are base64-encoded
116
+ under a `"data"` key.
117
+
118
+ ```bash
119
+ email read eml --folder INBOX --uid 42 > message.eml
120
+ email read eml --folder INBOX --uid 42 --json | jq -r '.data' | base64 -d > message.eml
121
+ ```
122
+
123
+ ### `email search <query>`
124
+
125
+ Search messages via local FTS5 (default) or remote IMAP SEARCH.
126
+
127
+ ```bash
128
+ email search "invoice" --json
129
+ email search "from:boss@work.com subject:quarterly" --json
130
+ email search "budget 2026" --folder Archive --limit 10 --json
131
+ email search "urgent" --mode remote --json
132
+ email search "report" --since 2026-01-01 --before 2026-04-01 --json
133
+ email search "contract" --has-attachments --json
134
+ ```
135
+
136
+ ### `email compose <action>`
137
+
138
+ Compose and send email. Body comes from `--body` or piped stdin.
139
+
140
+ ```bash
141
+ # Send
142
+ email compose send --to alice@example.com --subject "Hello" --body "Hi there" --json
143
+ echo "Meeting at 3pm?" | email compose send --to alice@example.com --subject "Quick question"
144
+
145
+ # Reply (body from stdin)
146
+ echo "Sounds good!" | email compose reply --folder INBOX --uid 1921
147
+
148
+ # Reply-all
149
+ email compose reply --folder INBOX --uid 1921 --body "Thanks all" --reply-all --json
150
+
151
+ # Forward
152
+ email compose forward --folder INBOX --uid 1921 --to bob@example.com --body "FYI" --json
153
+
154
+ # Attach files (comma-separated paths)
155
+ email compose send --to a@b.com --subject "Report" --body "See attached" \
156
+ --attach /path/to/report.pdf,/path/to/data.csv --json
157
+
158
+ # Drafts
159
+ email compose draft --save --to a@b.com --subject "Draft" --body "WIP" --json
160
+ email compose draft --send-draft 42 --json
161
+ ```
162
+
163
+ ### `email organize <action>`
164
+
165
+ Organize messages and folders. `--uids` accepts comma-separated UIDs.
166
+
167
+ ```bash
168
+ email organize mark-read --folder INBOX --uids 1,2,3 --json
169
+ email organize star --folder INBOX --uids 42 --json
170
+ email organize archive --folder INBOX --uids 1921,1922 --json
171
+ email organize trash --folder INBOX --uids 1800 --json
172
+ email organize move --folder INBOX --uids 100 --destination Archive --json
173
+ email organize set-labels --folder INBOX --uids 42 --labels "work,priority" --json
174
+ email organize create-folder --path "Projects/2026" --json
175
+ email organize rename-folder --old-path "Projects" --new-path "Work/Projects" --json
176
+ email organize delete-folder --path "OldFolder" --json
177
+ ```
178
+
179
+ ### `email sync [action]`
180
+
181
+ Manage IMAP connection and sync local SQLite state. Default action: `sync`.
182
+
183
+ ```bash
184
+ email sync --json # sync all folders (default)
185
+ email sync sync --folders INBOX,Sent --json
186
+ email sync sync --bodies all --json # fetch all bodies
187
+ email sync refresh-folders --json
188
+ email sync connect --json
189
+ email sync disconnect --json
190
+ email sync watch --json # syncs then exits; continuous watching needs the library
191
+ ```
192
+
193
+ ---
194
+
195
+ ## Multi-Step Workflow Examples
196
+
197
+ ### Triage inbox
198
+
199
+ ```bash
200
+ # Get unread messages
201
+ UNREAD=$(email read queue --unread-only --json)
202
+ echo "$UNREAD" | jq '.entities[].id'
203
+
204
+ # Archive a batch
205
+ email organize archive --folder INBOX --uids 1,2,3 --json
206
+ ```
207
+
208
+ ### Read and reply
209
+
210
+ ```bash
211
+ # Read a specific message
212
+ MSG=$(email read message --folder INBOX --uid 1921 --json)
213
+ echo "$MSG" | jq '.summary'
214
+
215
+ # Reply
216
+ echo "Thanks, will do." | email compose reply --folder INBOX --uid 1921 --json
217
+ ```
218
+
219
+ ### Search and act
220
+
221
+ ```bash
222
+ # Find all invoices from last month
223
+ RESULTS=$(email search "invoice" --since 2026-02-01 --before 2026-03-01 --json)
224
+ UIDS=$(echo "$RESULTS" | jq -r '.entities[].id' | tr '\n' ',' | sed 's/,$//')
225
+
226
+ # Move them to an Archive folder
227
+ email organize move --folder INBOX --uids "$UIDS" --destination Archive --json
228
+ ```
229
+
230
+ ### Full sync then read
231
+
232
+ ```bash
233
+ email sync --json
234
+ email read queue --limit 20 --json
235
+ ```
236
+
237
+ ### Export an attachment
238
+
239
+ ```bash
240
+ # List attachments
241
+ ATTS=$(email read attachment --folder INBOX --uid 1921 --json)
242
+ PART=$(echo "$ATTS" | jq -r '.entities[0].id')
243
+
244
+ # Download raw bytes
245
+ email read attachment --folder INBOX --uid 1921 --part-path "$PART" > attachment.pdf
246
+ ```
247
+
248
+ ---
249
+
250
+ ## Error Handling for Agents
251
+
252
+ - **Always check `outcome`** before acting on `entities`. Even exit code 0 can return `"no_op"`.
253
+ - **Do not retry auth errors** (exit 3) — they require credential changes.
254
+ - **On `needs_clarification`** (exit 6) — read `nextSteps` and ask the user for more information.
255
+ - **On `error`** (exit 5) — the tool's `summary` and `nextSteps` contain actionable guidance.
256
+ - **Network errors** (exit 4) — retry after a brief pause; check host/port if it persists.
257
+
258
+ ---
259
+
260
+ ## Piping Patterns
261
+
262
+ ```bash
263
+ # Pipe body from stdin
264
+ echo "Hello" | email compose send --to x@y.com --subject "Hi"
265
+
266
+ # Export EML and forward to another tool
267
+ email read eml --folder INBOX --uid 42 | mail -s "fwd" target@example.com
268
+
269
+ # JSON pipeline
270
+ email read queue --json | jq '.entities[] | select(.title | test("invoice"; "i")) | .id'
271
+
272
+ # Quiet mode — only exit code matters
273
+ email organize archive --folder INBOX --uids 42 --quiet && echo "archived"
274
+ ```
275
+
276
+ ---
277
+
278
+ ## What the CLI Does NOT Do
279
+
280
+ - **No persistent daemon.** Every invocation opens a fresh IMAP connection and closes it cleanly.
281
+ - **No continuous IDLE watch.** `email sync watch` syncs once and exits. For push-style updates,
282
+ use `Mailbox.network.watch()` from the library directly.
283
+ - **No interactive prompts.** All input comes from flags or stdin.