@ghostpaw/email 0.2.0
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/LICENSE +21 -0
- package/README.md +242 -0
- package/dist/index.cjs +5933 -0
- package/dist/index.d.cts +2442 -0
- package/dist/index.d.ts +2442 -0
- package/dist/index.js +5879 -0
- package/package.json +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GhostPaw
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
# @ghostpaw/email
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@ghostpaw/email)
|
|
4
|
+
[](https://nodejs.org)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
[](package.json)
|
|
7
|
+
[](https://www.typescriptlang.org)
|
|
8
|
+
|
|
9
|
+
A standalone email engine for Node.js, built on SQLite.
|
|
10
|
+
|
|
11
|
+
Email treats IMAP sync, SMTP send, local caching, threading, search, and
|
|
12
|
+
transport errors as one coherent model instead of a grab bag of protocol
|
|
13
|
+
adapters. It ships as a single prebundled blob with zero runtime dependencies,
|
|
14
|
+
designed for two audiences at once: human developers working directly in code,
|
|
15
|
+
and LLM agents operating through a structured `soul` / `tools` / `skills`
|
|
16
|
+
runtime.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @ghostpaw/email
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Requires **Node.js 24+** (uses the built-in `node:sqlite` module).
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { Mailbox } from '@ghostpaw/email';
|
|
30
|
+
|
|
31
|
+
const mailbox = new Mailbox({
|
|
32
|
+
imap: { host: 'imap.example.com', port: 993, tls: true },
|
|
33
|
+
smtp: { host: 'smtp.example.com', port: 465, tls: true },
|
|
34
|
+
auth: { user: 'user@example.com', pass: 'secret' },
|
|
35
|
+
storage: 'mail.db',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await mailbox.connect();
|
|
39
|
+
|
|
40
|
+
const folders = mailbox.read.folders();
|
|
41
|
+
await mailbox.network.sync();
|
|
42
|
+
const messages = mailbox.read.messages('INBOX', { limit: 20 });
|
|
43
|
+
|
|
44
|
+
await mailbox.write.send({
|
|
45
|
+
to: [{ address: 'bob@example.com' }],
|
|
46
|
+
subject: 'Hello',
|
|
47
|
+
text: 'Sent from @ghostpaw/email.',
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
await mailbox.disconnect();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`connect()` opens the SQLite database, initialises the schema, upserts the
|
|
54
|
+
account, and authenticates the IMAP session — one call does everything.
|
|
55
|
+
|
|
56
|
+
## The Model
|
|
57
|
+
|
|
58
|
+
Seven stored concepts and three derived ones:
|
|
59
|
+
|
|
60
|
+
| Concept | Purpose |
|
|
61
|
+
|---|---|
|
|
62
|
+
| **Account** | One email identity with IMAP/SMTP connection config |
|
|
63
|
+
| **Folder** | One IMAP mailbox path with sync metadata and role detection |
|
|
64
|
+
| **Message** | A locally cached email header record with flags, labels, and envelope |
|
|
65
|
+
| **Body** | The decoded text/html content and raw RFC 2822 bytes of one message |
|
|
66
|
+
| **Attachment** | A decoded MIME part with on-demand binary fetch |
|
|
67
|
+
| **SyncLog** | A record of one completed sync pass per folder |
|
|
68
|
+
| **Thread** | A JWZ conversation tree derived from References/In-Reply-To headers |
|
|
69
|
+
|
|
70
|
+
The model means each kind of mail state has its own home:
|
|
71
|
+
|
|
72
|
+
| What it looks like | What it actually is |
|
|
73
|
+
|---|---|
|
|
74
|
+
| An email inbox | A `Folder` with `role: 'inbox'` and synced messages |
|
|
75
|
+
| A conversation | A `Thread` computed from `References` and `In-Reply-To` chains |
|
|
76
|
+
| An unread email | A `Message` without `\Seen` in its `flags` array |
|
|
77
|
+
| A starred email | A `Message` with `\Flagged` in its `flags` |
|
|
78
|
+
| A PDF attached to a message | An `Attachment` with metadata from BODYSTRUCTURE and data fetched on demand |
|
|
79
|
+
| "Sync found 12 new messages" | A `SyncLog` row recording strategy, counts, and duration |
|
|
80
|
+
|
|
81
|
+
State is derived, not toggled. Thread IDs are computed from header chains at
|
|
82
|
+
sync time, folder roles are detected from IMAP special-use attributes, and
|
|
83
|
+
attachment metadata is extracted from BODYSTRUCTURE — all materialised during
|
|
84
|
+
sync, never stored as manual status fields.
|
|
85
|
+
|
|
86
|
+
## Two Audiences
|
|
87
|
+
|
|
88
|
+
### Human developers
|
|
89
|
+
|
|
90
|
+
Use the `Mailbox` class with typed `read`, `write`, and `network` surfaces for
|
|
91
|
+
direct-code access to every mail operation:
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { Mailbox } from '@ghostpaw/email';
|
|
95
|
+
|
|
96
|
+
const mailbox = new Mailbox(config);
|
|
97
|
+
await mailbox.connect();
|
|
98
|
+
|
|
99
|
+
const threads = mailbox.read.threads('INBOX', { limit: 20 });
|
|
100
|
+
const detail = await mailbox.read.getMessage('INBOX', uid);
|
|
101
|
+
await mailbox.write.reply('INBOX', uid, { text: 'Acknowledged.' });
|
|
102
|
+
await mailbox.write.archive('INBOX', [uid]);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
See [HUMAN.md](docs/HUMAN.md) for the full human-facing guide with worked
|
|
106
|
+
examples.
|
|
107
|
+
|
|
108
|
+
### LLM agents
|
|
109
|
+
|
|
110
|
+
Use the `tools`, `skills`, and `soul` namespaces for a structured runtime
|
|
111
|
+
surface designed to minimise LLM cognitive load:
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { skills, soul, tools } from '@ghostpaw/email';
|
|
115
|
+
|
|
116
|
+
// 5 intent-shaped tools covering the full mailbox lifecycle
|
|
117
|
+
const allTools = tools.emailTools;
|
|
118
|
+
const readTool = tools.getEmailToolByName('mail_read');
|
|
119
|
+
|
|
120
|
+
// 8 reusable workflow skills for multi-step scenarios
|
|
121
|
+
const triageSkill = skills.getEmailSkillByName('triage-inbox');
|
|
122
|
+
|
|
123
|
+
// Thinking foundation for system prompts
|
|
124
|
+
const systemPrompt = soul.renderEmailSoulPromptFoundation();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Every tool returns a structured result with `outcome`, `summary`, `entities`,
|
|
128
|
+
and `nextSteps` — no thrown exceptions to parse, no ambiguous prose.
|
|
129
|
+
|
|
130
|
+
See [LLM.md](docs/LLM.md) for the full AI-facing guide covering soul, tools,
|
|
131
|
+
and skills.
|
|
132
|
+
|
|
133
|
+
## Tools
|
|
134
|
+
|
|
135
|
+
Five tools shaped around operator intent, not raw protocol operations:
|
|
136
|
+
|
|
137
|
+
| Tool | What it does |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `mail_read` | Read folder lists, message queues, threads, bodies, attachments, or raw EML |
|
|
140
|
+
| `mail_search` | FTS5 local search or IMAP SEARCH on the server |
|
|
141
|
+
| `mail_compose` | Send, reply, forward, save/update/send drafts |
|
|
142
|
+
| `mail_organize` | Flags, labels, copy, move, archive, trash, junk, folder management |
|
|
143
|
+
| `mail_sync` | Connect, disconnect, reconnect, sync, refresh folders, watch |
|
|
144
|
+
|
|
145
|
+
## Key Properties
|
|
146
|
+
|
|
147
|
+
- **Zero runtime dependencies.** Only `node:sqlite`, `node:tls`, `node:net`,
|
|
148
|
+
`node:zlib`, `node:crypto` (built into Node 24+).
|
|
149
|
+
- **Single prebundled blob.** One ESM + one CJS entry in `dist/`. No subpath
|
|
150
|
+
exports, no code splitting.
|
|
151
|
+
- **Pure SQLite storage.** FTS5 full-text search, six tables, and deterministic
|
|
152
|
+
derived reads. `Mailbox` creates and manages its own `DatabaseSync` instance.
|
|
153
|
+
- **Full IMAP engine.** Streaming tokenizer, response parser, COMPRESS=DEFLATE,
|
|
154
|
+
IDLE (RFC 2177), CONDSTORE/QRESYNC (RFC 7162), XOAUTH2/OAUTHBEARER.
|
|
155
|
+
- **Full SMTP client.** TLS/STARTTLS/plaintext, PLAIN/LOGIN/XOAUTH2, dot
|
|
156
|
+
stuffing, APPEND to Sent after send.
|
|
157
|
+
- **Fetch-on-demand bodies.** Initial sync pulls headers and BODYSTRUCTURE only.
|
|
158
|
+
Message bodies and attachment bytes are fetched when actually read.
|
|
159
|
+
- **JWZ threading.** Conversation trees computed from References/In-Reply-To
|
|
160
|
+
headers, with depth-ordered rendering and cross-folder support.
|
|
161
|
+
- **Intention-shaped writes.** `send`, `reply`, `forward`, `archive`, `trash`,
|
|
162
|
+
`saveDraft`, `sendDraft` — operations that say what happened, not generic CRUD.
|
|
163
|
+
- **Additive AI runtime.** `soul` for posture, `tools` for actions, `skills` for
|
|
164
|
+
workflow guidance — all optional, all structured.
|
|
165
|
+
- **Colocated tests.** Every non-type module has a colocated `.test.ts` file.
|
|
166
|
+
The documented behaviour is backed by executable coverage.
|
|
167
|
+
|
|
168
|
+
## Package Surface
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import {
|
|
172
|
+
Mailbox, // porcelain class — the primary entry point
|
|
173
|
+
initSchema, // schema setup (called automatically by Mailbox.connect())
|
|
174
|
+
read, // read surface factory
|
|
175
|
+
write, // write surface factory
|
|
176
|
+
network, // network surface factory
|
|
177
|
+
tools, // LLM tool definitions + registry
|
|
178
|
+
skills, // LLM workflow skills + registry
|
|
179
|
+
soul, // thinking foundation for system prompts
|
|
180
|
+
} from '@ghostpaw/email';
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
All domain and runtime types are also available at the root for TypeScript
|
|
184
|
+
consumers:
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
import type {
|
|
188
|
+
EmailConfig,
|
|
189
|
+
AuthConfig,
|
|
190
|
+
EmailReadSurface,
|
|
191
|
+
EmailWriteSurface,
|
|
192
|
+
EmailNetworkSurface,
|
|
193
|
+
EmailToolDefinition,
|
|
194
|
+
EmailToolResult,
|
|
195
|
+
EmailSkill,
|
|
196
|
+
EmailSoul,
|
|
197
|
+
ComposeInput,
|
|
198
|
+
ReplyInput,
|
|
199
|
+
ForwardInput,
|
|
200
|
+
Message,
|
|
201
|
+
MessageDetail,
|
|
202
|
+
Thread,
|
|
203
|
+
Folder,
|
|
204
|
+
Attachment,
|
|
205
|
+
AttachmentMeta,
|
|
206
|
+
SyncResult,
|
|
207
|
+
WatchEvent,
|
|
208
|
+
} from '@ghostpaw/email';
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Documentation
|
|
212
|
+
|
|
213
|
+
| Document | Audience |
|
|
214
|
+
|---|---|
|
|
215
|
+
| [HUMAN.md](docs/HUMAN.md) | Human developers using the `Mailbox` API with `read` / `write` / `network` |
|
|
216
|
+
| [LLM.md](docs/LLM.md) | Agent builders wiring `soul`, `tools`, and `skills` into LLM systems |
|
|
217
|
+
| [docs/README.md](docs/README.md) | Architecture overview: model, invariants, protocol boundaries, source layout |
|
|
218
|
+
| [docs/entities/](docs/entities/) | Per-entity manuals with schema, operations, and invariants |
|
|
219
|
+
|
|
220
|
+
## Development
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
npm install
|
|
224
|
+
npm test # node:test runner
|
|
225
|
+
npm run typecheck # tsc --noEmit
|
|
226
|
+
npm run lint # biome check
|
|
227
|
+
npm run build # ESM + CJS + declarations via tsup
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
The repo is pinned to **Node 24.14.0** via `.nvmrc` / `.node-version` /
|
|
231
|
+
`.tool-versions` / `mise.toml` / Volta. Use whichever version manager you
|
|
232
|
+
prefer.
|
|
233
|
+
|
|
234
|
+
### Support
|
|
235
|
+
|
|
236
|
+
If this package helps your project, consider sponsoring its maintenance:
|
|
237
|
+
|
|
238
|
+
[](https://github.com/sponsors/Anonyfox)
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
**[Anonyfox](https://anonyfox.com) • [MIT License](LICENSE)**
|