@ghostpaw/email 0.5.6 → 0.5.8

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/README.md CHANGED
@@ -77,6 +77,10 @@ The surface database defaults to `~/.ghostpaw/email.db`; point `--db` at an
77
77
  existing account cache to read it. Each network call opens and closes its IMAP
78
78
  session. Connection commands do not retain a session between calls.
79
79
 
80
+ On POSIX, new accounts files and SQLite caches (including WAL/SHM sidecars) use mode `0600`, and newly created storage directories use `0700`. Existing permissions are preserved, except rewriting `accounts.json` sets it to `0600`.
81
+
82
+ Use `ghostpaw-email skill --short` for a compact command cheat sheet, `ghostpaw-email skill` for the full reference, and `ghostpaw-email skill --list` to list guides.
83
+
80
84
  ## Noun-verb CLI
81
85
 
82
86
  Both `email` and `ghostpaw-email` accept this additive command tree. Existing
@@ -156,7 +160,7 @@ and print one with `ghostpaw-email skill compose-and-send`.
156
160
 
157
161
  Each line downloads the latest release asset, checks it against the release's SHA256SUMS and installs it on the PATH (~/.local/bin on Linux/macOS; the Windows script adds its folder to the user PATH).
158
162
 
159
- These lines never edit ~/.profile or other shell startup files: `export PATH` applies to the current shell only. To keep it, add `export PATH="$HOME/.local/bin:$PATH"` to your shell profile yourself.
163
+ These lines never edit ~/.profile or other shell startup files: `export PATH` applies to the current shell only. To keep it in new shells, use the `~/.profile` line below.
160
164
 
161
165
  linux-x64:
162
166
 
@@ -191,7 +195,13 @@ irm https://raw.githubusercontent.com/GhostPawJS/email/main/install.ps1 | iex
191
195
  Pinned to a release:
192
196
 
193
197
  ```sh
194
- curl -fsSL https://raw.githubusercontent.com/GhostPawJS/email/main/install.sh | sh -s -- --target linux-x64 --version 0.5.6 && export PATH="$HOME/.local/bin:$PATH"
198
+ curl -fsSL https://raw.githubusercontent.com/GhostPawJS/email/main/install.sh | sh -s -- --target linux-x64 --version 0.5.8 && export PATH="$HOME/.local/bin:$PATH"
199
+ ```
200
+
201
+ Also adding ~/.local/bin to ~/.profile (edits ~/.profile once; skipped if it already mentions ~/.local/bin; zsh login shells read ~/.zprofile instead, so use that file name there):
202
+
203
+ ```sh
204
+ curl -fsSL https://raw.githubusercontent.com/GhostPawJS/email/main/install.sh | sh -s -- --target linux-x64 && { grep -qs '.local/bin' ~/.profile || echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.profile; } && export PATH="$HOME/.local/bin:$PATH"
195
205
  ```
196
206
 
197
207
  To skip the persistent user PATH edit (the installer still installs and prints the folder to add):
@@ -202,7 +212,7 @@ $env:GHOSTPAW_NO_MODIFY_PATH=1; irm https://raw.githubusercontent.com/GhostPawJS
202
212
 
203
213
  ```text
204
214
  $ ghostpaw-email --version
205
- email 0.5.6 (binary, linux-x64)
215
+ email 0.5.8 (binary, linux-x64)
206
216
  ```
207
217
 
208
218
  Scripts that compare versions should use `--version --short` or `--version --json`.
@@ -476,6 +486,19 @@ email read queue --json | jq '.entities[].title'
476
486
  echo "body text" | email compose send --to bob@example.com --subject "Hi"
477
487
  ```
478
488
 
489
+ `--attach` (on `compose send` and `compose reply`) takes one or more file
490
+ paths, comma-separated:
491
+
492
+ ```bash
493
+ email compose send --to bob@example.com --subject "Report" --body "Attached" \
494
+ --attach ./report.pdf,./data.csv
495
+ ```
496
+
497
+ Each path must be a regular file. Symlinks are followed to their target;
498
+ directories, devices, FIFOs and sockets are rejected with exit code 1
499
+ (`invalid_flag_value`) before anything is sent. The MIME type comes from the
500
+ file extension (unknown extensions are sent without an explicit type).
501
+
479
502
  All commands return the same `{ outcome, summary, entities, nextSteps }`
480
503
  shape as the tool layer, with consistent exit codes (0 success, 1 user error,
481
504
  2 config, 3 auth, 4 network, 5 tool error).
package/SKILL.md CHANGED
@@ -25,6 +25,8 @@ Run tools as `ghostpaw-email ...`; use `~/.local/bin/ghostpaw-email` if it is no
25
25
 
26
26
  Read and search cached email offline. Configure live accounts with email account add before network operations. Inspect messages before replying or changing folders. Confirm recipients and content before sending; trash and folder deletion can remove mail. Credentials use the existing email CLI account configuration or EMAIL_* environment variables.
27
27
 
28
+ For the compact cheat sheet, run `ghostpaw-email skill --short`.
29
+
28
30
  ## Calling tools
29
31
 
30
32
  MCP: connect to ghostpaw-email, then call a tool by name with its JSON arguments.
@@ -47,7 +49,7 @@ Nested requirements apply within the parent for the selected action.
47
49
 
48
50
  | Parameter | Type | Required | Values / description |
49
51
  | --- | --- | --- | --- |
50
- | view | string | yes | folders, queue, thread, message, attachment, eml. What to read. |
52
+ | view | string | yes | eml. What to read. |
51
53
  | folder | string | no | Folder path (required for queue/message/attachment/eml). |
52
54
  | uid | integer | no | Message UID (required for message/attachment/eml). |
53
55
  | threadId | string | no | Thread ID (required for thread view). |
@@ -105,12 +107,45 @@ Nested requirements apply within the parent for the selected action.
105
107
 
106
108
  | Parameter | Type | Required | Values / description |
107
109
  | --- | --- | --- | --- |
108
- | action | string | yes | send, reply, forward, save_draft, update_draft, send_draft. |
110
+ | action | string | yes | send_draft. string value. |
109
111
  | folder | string | no | Source folder (required for reply/forward). |
110
112
  | uid | integer | no | Source message UID (required for reply/forward/update_draft/send_draft). |
111
113
  | input | object | no | ComposeInput / ReplyInput / ForwardInput payload. |
114
+ | input.from | object | no | Object: address (required), name. |
115
+ | input.from.address | string | yes | Email address. |
116
+ | input.from.name | string | no | Display name. |
117
+ | input.sender | object | no | Object: address (required), name. |
118
+ | input.sender.address | string | yes | Email address. |
119
+ | input.sender.name | string | no | Display name. |
120
+ | input.envelopeFrom | object | no | Object: address (required), name. |
121
+ | input.envelopeFrom.address | string | yes | Email address. |
122
+ | input.envelopeFrom.name | string | no | Display name. |
123
+ | input.replyTo | object | no | Object: address (required), name. |
124
+ | input.replyTo.address | string | yes | Email address. |
125
+ | input.replyTo.name | string | no | Display name. |
112
126
  | input.to | array | yes | Recipient addresses. |
127
+ | input.to[].address | string | yes | Email address. |
128
+ | input.to[].name | string | no | Display name. |
129
+ | input.cc | array | no | Recipient addresses. |
130
+ | input.cc[].address | string | yes | Email address. |
131
+ | input.cc[].name | string | no | Display name. |
132
+ | input.bcc | array | no | Recipient addresses. |
133
+ | input.bcc[].address | string | yes | Email address. |
134
+ | input.bcc[].name | string | no | Display name. |
113
135
  | input.subject | string | yes | Message subject. |
136
+ | input.text | string | no | Plain text body. |
137
+ | input.html | string | no | HTML body. |
138
+ | input.replyAll | boolean | no | Reply to all original recipients. |
139
+ | input.mode | string | no | inline, attachment. string value. |
140
+ | input.attachments | array | no | Message attachments. |
141
+ | input.attachments[].filename | string | yes | string value. |
142
+ | input.attachments[].content | any | yes | Attachment bytes (Buffer in library calls). |
143
+ | input.attachments[].mimeType | string | no | string value. |
144
+ | input.attachments[].inline | boolean | no | boolean value. |
145
+ | input.attachments[].contentId | string | no | string value. |
146
+ | input.inReplyTo | string | no | string value. |
147
+ | input.references | array | no | Array of string. |
148
+ | input.headers | object | no | object value. |
114
149
 
115
150
  Examples:
116
151
 
@@ -134,7 +169,7 @@ Nested requirements apply within the parent for the selected action.
134
169
 
135
170
  | Parameter | Type | Required | Values / description |
136
171
  | --- | --- | --- | --- |
137
- | action | string | yes | mark_read, mark_unread, star, unstar, mark_answered, copy, move, archive, trash, junk, not_junk, set_labels, add_labels, remove_labels, create_folder, rename_folder, delete_folder, subscribe_folder, unsubscribe_folder. |
172
+ | action | string | yes | unsubscribe_folder. string value. |
138
173
  | folder | string | no | Source folder (required for message actions). |
139
174
  | uids | array | no | Message UIDs to act on. |
140
175
  | destination | string | no | Destination folder (required for copy/move). |
@@ -165,7 +200,7 @@ Nested requirements apply within the parent for the selected action.
165
200
 
166
201
  | Parameter | Type | Required | Values / description |
167
202
  | --- | --- | --- | --- |
168
- | action | string | yes | connect, disconnect, reconnect, sync, refresh_folders, watch. |
203
+ | action | string | yes | connect, disconnect, reconnect, sync, refresh_folders, watch. string value. |
169
204
  | folders | array | no | Folders to sync or watch (optional — defaults to all subscribed folders). |
170
205
  | bodies | string | no | none, missing, all. Body fetch strategy for sync (default: missing). |
171
206
 
@@ -179,15 +214,15 @@ ghostpaw-email call mail_sync '{"action":"reconnect"}'
179
214
 
180
215
  ## Workflow guides
181
216
 
182
- - `ghostpaw-email skill triage-inbox` ([triage-inbox](skills/email/references/triage-inbox.md)): Process a full inbox from scratch: sync to get latest state, read message queue, selectively fetch bodies for decisions, then bulk-organize by priority.
183
- - `ghostpaw-email skill read-and-reply` ([read-and-reply](skills/email/references/read-and-reply.md)): Read a message with full thread context, then compose and send a properly-threaded reply with quoted attribution.
184
- - `ghostpaw-email skill connect-and-sync` ([connect-and-sync](skills/email/references/connect-and-sync.md)): Establish or restore an IMAP connection, refresh the folder list, and pull new messages — handling first-run vs incremental scenarios.
185
- - `ghostpaw-email skill search-and-act` ([search-and-act](skills/email/references/search-and-act.md)): Find messages matching criteria (local FTS first, remote IMAP SEARCH as fallback), verify targets, then act — organize, reply, or present.
186
- - `ghostpaw-email skill compose-and-send` ([compose-and-send](skills/email/references/compose-and-send.md)): Full draft lifecycle — save, review, update, then send — plus direct send, reply, and forward with proper threading and forwarded-header blocks.
187
- - `ghostpaw-email skill organize-bulk` ([organize-bulk](skills/email/references/organize-bulk.md)): Bulk organize messages across folders — flagging, moving, archiving, labelling — and manage the folder hierarchy as part of the flow.
188
- - `ghostpaw-email skill attachment-workflow` ([attachment-workflow](skills/email/references/attachment-workflow.md)): Discover, inspect, and fetch email attachments on demand; embed attachments in outbound messages; and export or import full .eml files.
189
- - `ghostpaw-email skill recover-from-disruption` ([recover-from-disruption](skills/email/references/recover-from-disruption.md)): Detect and recover from connection loss or IMAP/SMTP failures — reconnect with back-off, re-sync to reconcile state, and handle auth vs transient errors distinctly.
190
- - `ghostpaw-email skill cli` ([cli](skills/email/references/cli.md)): Complete existing email CLI guide.
217
+ - `ghostpaw-email skill triage-inbox`: Process a full inbox from scratch: sync to get latest state, read message queue, selectively fetch bodies for decisions, then bulk-organize by priority.
218
+ - `ghostpaw-email skill read-and-reply`: Read a message with full thread context, then compose and send a properly-threaded reply with quoted attribution.
219
+ - `ghostpaw-email skill connect-and-sync`: Establish or restore an IMAP connection, refresh the folder list, and pull new messages — handling first-run vs incremental scenarios.
220
+ - `ghostpaw-email skill search-and-act`: Find messages matching criteria (local FTS first, remote IMAP SEARCH as fallback), verify targets, then act — organize, reply, or present.
221
+ - `ghostpaw-email skill compose-and-send`: Full draft lifecycle — save, review, update, then send — plus direct send, reply, and forward with proper threading and forwarded-header blocks.
222
+ - `ghostpaw-email skill organize-bulk`: Bulk organize messages across folders — flagging, moving, archiving, labelling — and manage the folder hierarchy as part of the flow.
223
+ - `ghostpaw-email skill attachment-workflow`: Discover, inspect, and fetch email attachments on demand; embed attachments in outbound messages; and export or import full .eml files.
224
+ - `ghostpaw-email skill recover-from-disruption`: Detect and recover from connection loss or IMAP/SMTP failures — reconnect with back-off, re-sync to reconcile state, and handle auth vs transient errors distinctly.
225
+ - `ghostpaw-email skill cli`: Complete existing email CLI guide.
191
226
 
192
227
  ## Principles
193
228
 
package/dist/cli.js CHANGED
@@ -4,9 +4,9 @@ import f from 'node:readline';
4
4
  import * as tty from 'node:tty';
5
5
  import { WriteStream } from 'node:tty';
6
6
  import { isSea } from 'node:sea';
7
- import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
7
+ import { readFileSync, mkdirSync, closeSync, openSync, chmodSync, fchmodSync, ftruncateSync, writeFileSync, statSync } from 'node:fs';
8
8
  import { homedir } from 'node:os';
9
- import { sep, dirname, join, basename, extname } from 'node:path';
9
+ import { sep, join, dirname, basename, extname } from 'node:path';
10
10
  import { EventEmitter } from 'node:events';
11
11
  import * as net from 'node:net';
12
12
  import * as tls from 'node:tls';
@@ -808,7 +808,7 @@ var init_cli_version = __esm({
808
808
  var emailVersion;
809
809
  var init_version = __esm({
810
810
  "src/version.ts"() {
811
- emailVersion = "0.5.6";
811
+ emailVersion = "0.5.8";
812
812
  }
813
813
  });
814
814
  function getConfigDir() {
@@ -830,10 +830,10 @@ function dbPathForAccount(slug) {
830
830
  return join(getDataDir(), `${slug}.db`);
831
831
  }
832
832
  function ensureConfigDir() {
833
- mkdirSync(getConfigDir(), { recursive: true });
833
+ mkdirSync(getConfigDir(), { recursive: true, mode: 448 });
834
834
  }
835
835
  function ensureDataDir() {
836
- mkdirSync(getDataDir(), { recursive: true });
836
+ mkdirSync(getDataDir(), { recursive: true, mode: 448 });
837
837
  }
838
838
  function loadAccounts() {
839
839
  let raw2;
@@ -853,7 +853,14 @@ function loadAccounts() {
853
853
  }
854
854
  function saveAccounts(data) {
855
855
  ensureConfigDir();
856
- writeFileSync(accountsFilePath(), JSON.stringify(data, null, " ") + "\n", "utf-8");
856
+ const fd = openSync(accountsFilePath(), "a", 384);
857
+ try {
858
+ if (process.platform !== "win32") fchmodSync(fd, 384);
859
+ ftruncateSync(fd, 0);
860
+ writeFileSync(fd, JSON.stringify(data, null, " ") + "\n", "utf-8");
861
+ } finally {
862
+ closeSync(fd);
863
+ }
857
864
  }
858
865
  function validateAccounts(data) {
859
866
  if (typeof data !== "object" || data === null || Array.isArray(data)) {
@@ -6094,6 +6101,42 @@ var init_read = __esm({
6094
6101
  init_store();
6095
6102
  }
6096
6103
  });
6104
+ function preparePrivateStorage(path) {
6105
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
6106
+ const created = [];
6107
+ for (const file of [path, `${path}-wal`, `${path}-shm`]) {
6108
+ try {
6109
+ closeSync(openSync(file, "wx", 384));
6110
+ created.push(file);
6111
+ } catch (error) {
6112
+ if (error.code !== "EEXIST") throw error;
6113
+ }
6114
+ }
6115
+ return () => {
6116
+ if (process.platform !== "win32")
6117
+ for (const file of created) {
6118
+ try {
6119
+ chmodSync(file, 384);
6120
+ } catch (error) {
6121
+ if (error.code !== "ENOENT") throw error;
6122
+ }
6123
+ }
6124
+ };
6125
+ }
6126
+ function withPrivateCreation(operation, secure) {
6127
+ if (process.platform === "win32") return operation();
6128
+ const previous = process.umask(63);
6129
+ try {
6130
+ return operation();
6131
+ } finally {
6132
+ process.umask(previous);
6133
+ secure?.();
6134
+ }
6135
+ }
6136
+ var init_private_storage = __esm({
6137
+ "src/private_storage.ts"() {
6138
+ }
6139
+ });
6097
6140
 
6098
6141
  // src/schema/create_fts.ts
6099
6142
  function createFts(db) {
@@ -7442,6 +7485,39 @@ var init_cli_commands = __esm({
7442
7485
  }
7443
7486
  });
7444
7487
 
7488
+ // src/surfaces/parameter_rows.ts
7489
+ function parameterRows(schema, prefix = "") {
7490
+ const rows = [];
7491
+ const properties = { ...schema.properties };
7492
+ for (const branch of schema.oneOf ?? []) Object.assign(properties, branch.properties);
7493
+ for (const [name, property] of Object.entries(properties)) {
7494
+ const alternatives = [property, ...property.oneOf ?? []];
7495
+ for (const branch of schema.oneOf ?? []) {
7496
+ const nested2 = branch.properties?.[name];
7497
+ if (nested2) alternatives.push(nested2, ...nested2.oneOf ?? []);
7498
+ }
7499
+ const nested = { properties: {}, required: [] };
7500
+ for (const alternative of alternatives) {
7501
+ Object.assign(nested.properties ?? {}, alternative.properties);
7502
+ nested.required = [.../* @__PURE__ */ new Set([...nested.required ?? [], ...alternative.required ?? []])];
7503
+ }
7504
+ const keys = Object.keys(nested.properties ?? {});
7505
+ const type = property.type ?? property.oneOf?.map((branch) => branch.type ?? "any").join(" / ") ?? "any";
7506
+ const fallback = keys.length ? `Object: ${keys.map((key) => key + (nested.required?.includes(key) ? " (required)" : "")).join(", ")}.` : property.items ? `Array of ${property.items.type ?? "values"}.` : `${type} value.`;
7507
+ const description = ((property.enum ? `${property.enum.join(", ")}. ` : "") + (property.description?.trim() || fallback)).replaceAll("|", "\\|").replaceAll("\n", " ");
7508
+ rows.push(
7509
+ `| ${prefix}${name} | ${type} | ${schema.required?.includes(name) ? "yes" : "no"} | ${description} |`
7510
+ );
7511
+ if (keys.length) rows.push(...parameterRows(nested, `${prefix}${name}.`));
7512
+ if (property.items) rows.push(...parameterRows(property.items, `${prefix}${name}[].`));
7513
+ }
7514
+ return rows;
7515
+ }
7516
+ var init_parameter_rows = __esm({
7517
+ "src/surfaces/parameter_rows.ts"() {
7518
+ }
7519
+ });
7520
+
7445
7521
  // src/surfaces/surface_types.ts
7446
7522
  function isErrorResult(result) {
7447
7523
  return typeof result === "object" && result !== null && "ok" in result && result.ok === false;
@@ -7542,11 +7618,7 @@ Not for: ${tool.whenNotToUse ?? ""}
7542
7618
  Read only: ${tool.readOnly ?? false}
7543
7619
 
7544
7620
  Parameter | Type | Required | Description
7545
- ${Object.entries(
7546
- tool.inputSchema.properties ?? {}
7547
- ).map(
7548
- ([key, schema]) => `${key} | ${schema.type ?? "oneOf"} | ${tool.inputSchema.required?.includes(key) ?? false} | ${schema.description ?? ""}`
7549
- ).join("\n")}
7621
+ ${parameterRows(tool.inputSchema).join("\n")}
7550
7622
 
7551
7623
  ${JSON.stringify(tool.inputSchema, null, 2)}
7552
7624
  `
@@ -7636,6 +7708,7 @@ var init_cli = __esm({
7636
7708
  "src/surfaces/cli.ts"() {
7637
7709
  init_cli_version();
7638
7710
  init_cli_commands();
7711
+ init_parameter_rows();
7639
7712
  init_surface_types();
7640
7713
  init_validate_input();
7641
7714
  }
@@ -7814,6 +7887,8 @@ email compose forward --folder INBOX --uid 1921 --to bob@example.com --body "FYI
7814
7887
  # Attach files (comma-separated paths)
7815
7888
  email compose send --to a@b.com --subject "Report" --body "See attached" \\
7816
7889
  --attach /path/to/report.pdf,/path/to/data.csv --json
7890
+ # --attach paths must be regular files (symlinks are followed); directories,
7891
+ # devices, FIFOs and sockets fail with invalid_flag_value before sending.
7817
7892
 
7818
7893
  # Drafts
7819
7894
  email compose draft --save --to a@b.com --subject "Draft" --body "WIP" --json
@@ -8305,6 +8380,56 @@ var init_email_skills = __esm({
8305
8380
  }
8306
8381
  });
8307
8382
 
8383
+ // src/surface/email_skill_short.ts
8384
+ var emailSkillShort;
8385
+ var init_email_skill_short = __esm({
8386
+ "src/surface/email_skill_short.ts"() {
8387
+ init_version();
8388
+ emailSkillShort = `# ghostpaw-email cheat sheet
8389
+ Version: ${emailVersion}
8390
+
8391
+ Install (Node 24+):
8392
+ npm install -g @ghostpaw/email
8393
+ Check version:
8394
+ ghostpaw-email --version
8395
+
8396
+ Configure an account:
8397
+ ghostpaw-email account add --name work --imap-host imap.example.com --imap-port 993 --smtp-host smtp.example.com --smtp-port 587 --user reader@example.com --pass PASSWORD
8398
+ Connect and synchronize:
8399
+ ghostpaw-email sync connect
8400
+ List folders:
8401
+ ghostpaw-email read folders
8402
+ Search cached mail:
8403
+ ghostpaw-email mail search "meeting"
8404
+ Save a draft:
8405
+ ghostpaw-email compose draft --save --to reader@example.com --subject Hello --body Hello
8406
+ Mark a message read:
8407
+ ghostpaw-email organize mark-read --folder INBOX --uids 1
8408
+ List tool names:
8409
+ ghostpaw-email tools
8410
+ Inspect a tool and its parameters:
8411
+ ghostpaw-email describe mail_search
8412
+ Call a tool with JSON:
8413
+ ghostpaw-email call mail_search '{"query":"meeting"}'
8414
+ Start the MCP server:
8415
+ ghostpaw-email mcp
8416
+ Select a cache:
8417
+ ghostpaw-email --db ./email.sqlite tools
8418
+
8419
+ List workflow guides:
8420
+ ghostpaw-email skill --list
8421
+ Read a guide:
8422
+ ghostpaw-email skill cli
8423
+ Read the full tool reference:
8424
+ ghostpaw-email skill
8425
+ Show this compact cheat sheet:
8426
+ ghostpaw-email skill --short
8427
+ Show skill command help:
8428
+ ghostpaw-email skill --help
8429
+ `;
8430
+ }
8431
+ });
8432
+
8308
8433
  // src/surface/email_surface_tools.ts
8309
8434
  var emailMcpTools, emailSurfaceTools;
8310
8435
  var init_email_surface_tools = __esm({
@@ -8412,20 +8537,23 @@ async function openEmailDb(path) {
8412
8537
  } finally {
8413
8538
  process.emitWarning = original;
8414
8539
  }
8415
- if (path !== ":memory:") mkdirSync(dirname(path), { recursive: true });
8416
- const db = new sqlite.DatabaseSync(path);
8417
- try {
8418
- db.exec("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;");
8419
- const context = db;
8420
- initSchema(context);
8421
- return context;
8422
- } catch (error) {
8423
- db.close();
8424
- throw error;
8425
- }
8540
+ const secure = path !== ":memory:" ? preparePrivateStorage(path) : void 0;
8541
+ return withPrivateCreation(() => {
8542
+ const db = new sqlite.DatabaseSync(path);
8543
+ try {
8544
+ db.exec("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;");
8545
+ const context = db;
8546
+ initSchema(context);
8547
+ return context;
8548
+ } catch (error) {
8549
+ db.close();
8550
+ throw error;
8551
+ }
8552
+ }, secure);
8426
8553
  }
8427
8554
  var init_open_email_db = __esm({
8428
8555
  "src/surface/open_email_db.ts"() {
8556
+ init_private_storage();
8429
8557
  init_schema();
8430
8558
  }
8431
8559
  });
@@ -8688,7 +8816,7 @@ var skill_markdown_exports = {};
8688
8816
  __export(skill_markdown_exports, {
8689
8817
  renderSkillMarkdown: () => renderSkillMarkdown
8690
8818
  });
8691
- function renderSkillMarkdown(spec, { referencesBase = "references" } = {}) {
8819
+ function renderSkillMarkdown(spec, { referencesBase: _referencesBase = "references" } = {}) {
8692
8820
  if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(spec.name) || spec.name.length > 64)
8693
8821
  throw new Error("Invalid skill name");
8694
8822
  if (!spec.description.trim() || spec.description.length > 1024 || !spec.description.includes("Use when"))
@@ -8726,6 +8854,8 @@ function renderSkillMarkdown(spec, { referencesBase = "references" } = {}) {
8726
8854
  "",
8727
8855
  spec.about,
8728
8856
  "",
8857
+ "For the compact cheat sheet, run `ghostpaw-email skill --short`.",
8858
+ "",
8729
8859
  "## Calling tools",
8730
8860
  "",
8731
8861
  `MCP: connect to ${spec.server}, then call a tool by name with its JSON arguments.`,
@@ -8752,27 +8882,7 @@ function renderSkillMarkdown(spec, { referencesBase = "references" } = {}) {
8752
8882
  "| Parameter | Type | Required | Values / description |",
8753
8883
  "| --- | --- | --- | --- |"
8754
8884
  );
8755
- const row = (name, property, required) => `| ${name} | ${property.type ?? property.oneOf?.map((branch) => branch.type).join(" / ") ?? "any"} | ${required ? "yes" : "no"} | ${(property.enum ? `${property.enum.join(", ")}. ` : "") + (property.description ?? "").replaceAll("|", "\\|").replaceAll("\n", " ")} |`;
8756
- const fields = (schema, prefix = "") => {
8757
- const properties = Object.entries(schema.properties ?? {});
8758
- for (const [name, property] of properties) {
8759
- if (prefix && properties.length > 8 && !schema.required?.includes(name)) continue;
8760
- lines.push(row(`${prefix}${name}`, property, schema.required?.includes(name) ?? false));
8761
- const objects = [property, ...property.oneOf ?? []].filter((s4) => s4.properties);
8762
- if (!objects.length)
8763
- for (const branch of tool.inputSchema.oneOf ?? []) {
8764
- const nested = branch.properties?.[name];
8765
- if (nested?.properties) objects.push(nested);
8766
- }
8767
- const merged = { properties: {}, required: [] };
8768
- for (const object of objects) {
8769
- Object.assign(merged.properties ?? {}, object.properties);
8770
- merged.required = [.../* @__PURE__ */ new Set([...merged.required ?? [], ...object.required ?? []])];
8771
- }
8772
- if (objects.length) fields(merged, `${prefix}${name}.`);
8773
- }
8774
- };
8775
- fields(tool.inputSchema);
8885
+ lines.push(...parameterRows(tool.inputSchema));
8776
8886
  lines.push("", "Examples:", "", "```sh");
8777
8887
  const actions = tool.inputSchema.properties?.action?.enum?.slice(0, 3) ?? [void 0];
8778
8888
  for (const action of actions) {
@@ -8786,7 +8896,7 @@ function renderSkillMarkdown(spec, { referencesBase = "references" } = {}) {
8786
8896
  "## Workflow guides",
8787
8897
  "",
8788
8898
  ...spec.workflows.map(
8789
- (workflow) => `- \`${spec.bin} skill ${workflow.name}\` ([${workflow.name}](${referencesBase}/${workflow.name}.md)): ${workflow.description}`
8899
+ (workflow) => `- \`${spec.bin} skill ${workflow.name}\`: ${workflow.description}`
8790
8900
  ),
8791
8901
  "",
8792
8902
  "## Principles",
@@ -8807,6 +8917,7 @@ function renderSkillMarkdown(spec, { referencesBase = "references" } = {}) {
8807
8917
  }
8808
8918
  var init_skill_markdown = __esm({
8809
8919
  "src/surfaces/skill_markdown.ts"() {
8920
+ init_parameter_rows();
8810
8921
  init_schema_example();
8811
8922
  }
8812
8923
  });
@@ -8852,6 +8963,7 @@ var init_email_cli_options = __esm({
8852
8963
  init_cli_guide();
8853
8964
  init_email_skills();
8854
8965
  init_version();
8966
+ init_email_skill_short();
8855
8967
  init_email_surface_tools();
8856
8968
  emailCliOptions = {
8857
8969
  bin: "ghostpaw-email",
@@ -8879,8 +8991,9 @@ var init_email_cli_options = __esm({
8879
8991
  },
8880
8992
  skill: async (args = []) => {
8881
8993
  const guides = [...emailSkills, cliGuide];
8994
+ if (args.length === 1 && args[0] === "--short") return emailSkillShort;
8882
8995
  if (args[0] === "--help" || args[0] === "-h")
8883
- return "Usage: ghostpaw-email skill\n ghostpaw-email skill --list\n ghostpaw-email skill <guide>\n";
8996
+ return "Usage: ghostpaw-email skill\n ghostpaw-email skill --short (compact cheat sheet)\n ghostpaw-email skill --list\n ghostpaw-email skill <guide>\n";
8884
8997
  if (args[0] === "--list")
8885
8998
  return `${guides.map((guide) => `${guide.name} ${guide.description.replace(/\s+/g, " ")}`).join("\n")}
8886
8999
  `;
@@ -10651,6 +10764,59 @@ function getEmailToolByName(name) {
10651
10764
 
10652
10765
  // src/cli/commands/compose.ts
10653
10766
  init_account();
10767
+
10768
+ // src/cli/attachments.ts
10769
+ init_errors2();
10770
+ function loadAttachments(paths) {
10771
+ const list = paths.split(",").map((p) => p.trim()).filter((p) => p.length > 0);
10772
+ if (list.length === 0) {
10773
+ throw new CliError("invalid_flag_value", "--attach needs at least one file path.");
10774
+ }
10775
+ return list.map((filePath) => {
10776
+ let stat;
10777
+ try {
10778
+ stat = statSync(filePath);
10779
+ } catch {
10780
+ throw new CliError("invalid_flag_value", `--attach: file not found: "${filePath}"`);
10781
+ }
10782
+ if (stat.isDirectory()) {
10783
+ throw new CliError(
10784
+ "invalid_flag_value",
10785
+ `--attach: "${filePath}" is a directory; attach individual files instead.`
10786
+ );
10787
+ }
10788
+ if (!stat.isFile()) {
10789
+ throw new CliError(
10790
+ "invalid_flag_value",
10791
+ `--attach: "${filePath}" is not a regular file (device, FIFO or socket).`
10792
+ );
10793
+ }
10794
+ const content = readFileSync(filePath);
10795
+ const filename = basename(filePath);
10796
+ const mimeType = MIME_MAP[extname(filename).toLowerCase()];
10797
+ return mimeType ? { filename, content, mimeType } : { filename, content };
10798
+ });
10799
+ }
10800
+ var MIME_MAP = {
10801
+ ".pdf": "application/pdf",
10802
+ ".png": "image/png",
10803
+ ".jpg": "image/jpeg",
10804
+ ".jpeg": "image/jpeg",
10805
+ ".gif": "image/gif",
10806
+ ".txt": "text/plain",
10807
+ ".html": "text/html",
10808
+ ".htm": "text/html",
10809
+ ".csv": "text/csv",
10810
+ ".json": "application/json",
10811
+ ".zip": "application/zip",
10812
+ ".xml": "application/xml",
10813
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
10814
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
10815
+ ".mp4": "video/mp4",
10816
+ ".mp3": "audio/mpeg"
10817
+ };
10818
+
10819
+ // src/cli/commands/compose.ts
10654
10820
  init_errors2();
10655
10821
 
10656
10822
  // src/mailbox.ts
@@ -10659,15 +10825,19 @@ init_network();
10659
10825
  init_read();
10660
10826
 
10661
10827
  // src/runtime.ts
10828
+ init_private_storage();
10662
10829
  init_schema();
10663
10830
  function init2(config) {
10664
10831
  const dbPath = config.storage ?? ":memory:";
10665
10832
  const { DatabaseSync } = process.getBuiltinModule("node:sqlite");
10666
- const db = new DatabaseSync(dbPath);
10667
- if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
10668
- db.exec("PRAGMA busy_timeout=5000");
10669
- initSchema(db);
10670
- return { db };
10833
+ const secure = dbPath !== ":memory:" ? preparePrivateStorage(dbPath) : void 0;
10834
+ return withPrivateCreation(() => {
10835
+ const db = new DatabaseSync(dbPath);
10836
+ if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
10837
+ db.exec("PRAGMA busy_timeout=5000");
10838
+ initSchema(db);
10839
+ return { db };
10840
+ }, secure);
10671
10841
  }
10672
10842
 
10673
10843
  // src/mailbox.ts
@@ -10842,7 +11012,10 @@ var composeCommand = defineCommand({
10842
11012
  cc: { type: "string", description: "CC recipient(s), comma-separated" },
10843
11013
  bcc: { type: "string", description: "BCC recipient(s), comma-separated" },
10844
11014
  from: { type: "string", description: "From address (overrides account identity)" },
10845
- attach: { type: "string", description: "File path(s) to attach, comma-separated" }
11015
+ attach: {
11016
+ type: "string",
11017
+ description: "Regular file path(s) to attach, comma-separated (directories and special files are rejected)"
11018
+ }
10846
11019
  },
10847
11020
  async run({ args: _args }) {
10848
11021
  const args = _args;
@@ -10879,7 +11052,10 @@ var composeCommand = defineCommand({
10879
11052
  to: { type: "string", description: "Override recipient(s)" },
10880
11053
  cc: { type: "string", description: "CC recipient(s)" },
10881
11054
  "reply-all": { type: "boolean", description: "Reply to all recipients", default: false },
10882
- attach: { type: "string", description: "File path(s) to attach, comma-separated" }
11055
+ attach: {
11056
+ type: "string",
11057
+ description: "Regular file path(s) to attach, comma-separated (directories and special files are rejected)"
11058
+ }
10883
11059
  },
10884
11060
  async run({ args: _args }) {
10885
11061
  const args = _args;
@@ -11047,36 +11223,6 @@ function parseUid(raw2) {
11047
11223
  }
11048
11224
  return n3;
11049
11225
  }
11050
- function loadAttachments(paths) {
11051
- return paths.split(",").map((p) => {
11052
- const filePath = p.trim();
11053
- const content = readFileSync(filePath);
11054
- const filename = basename(filePath);
11055
- const mimeType = extensionToMime(extname(filename).toLowerCase());
11056
- return mimeType ? { filename, content, mimeType } : { filename, content };
11057
- });
11058
- }
11059
- var MIME_MAP = {
11060
- ".pdf": "application/pdf",
11061
- ".png": "image/png",
11062
- ".jpg": "image/jpeg",
11063
- ".jpeg": "image/jpeg",
11064
- ".gif": "image/gif",
11065
- ".txt": "text/plain",
11066
- ".html": "text/html",
11067
- ".htm": "text/html",
11068
- ".csv": "text/csv",
11069
- ".json": "application/json",
11070
- ".zip": "application/zip",
11071
- ".xml": "application/xml",
11072
- ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
11073
- ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
11074
- ".mp4": "video/mp4",
11075
- ".mp3": "audio/mpeg"
11076
- };
11077
- function extensionToMime(ext) {
11078
- return MIME_MAP[ext];
11079
- }
11080
11226
 
11081
11227
  // src/cli/commands/organize.ts
11082
11228
  init_account();
package/dist/index.cjs CHANGED
@@ -4,6 +4,8 @@ var node_events = require('node:events');
4
4
  var net = require('node:net');
5
5
  var tls = require('node:tls');
6
6
  var zlib = require('node:zlib');
7
+ var node_fs = require('node:fs');
8
+ var node_path = require('node:path');
7
9
  var node_crypto = require('node:crypto');
8
10
 
9
11
  function _interopNamespace(e) {
@@ -3720,6 +3722,38 @@ var runtime_exports = {};
3720
3722
  __export(runtime_exports, {
3721
3723
  init: () => init
3722
3724
  });
3725
+ function preparePrivateStorage(path) {
3726
+ node_fs.mkdirSync(node_path.dirname(path), { recursive: true, mode: 448 });
3727
+ const created = [];
3728
+ for (const file of [path, `${path}-wal`, `${path}-shm`]) {
3729
+ try {
3730
+ node_fs.closeSync(node_fs.openSync(file, "wx", 384));
3731
+ created.push(file);
3732
+ } catch (error) {
3733
+ if (error.code !== "EEXIST") throw error;
3734
+ }
3735
+ }
3736
+ return () => {
3737
+ if (process.platform !== "win32")
3738
+ for (const file of created) {
3739
+ try {
3740
+ node_fs.chmodSync(file, 384);
3741
+ } catch (error) {
3742
+ if (error.code !== "ENOENT") throw error;
3743
+ }
3744
+ }
3745
+ };
3746
+ }
3747
+ function withPrivateCreation(operation, secure) {
3748
+ if (process.platform === "win32") return operation();
3749
+ const previous = process.umask(63);
3750
+ try {
3751
+ return operation();
3752
+ } finally {
3753
+ process.umask(previous);
3754
+ secure?.();
3755
+ }
3756
+ }
3723
3757
 
3724
3758
  // src/schema/index.ts
3725
3759
  var schema_exports = {};
@@ -3870,11 +3904,14 @@ function initSchema(db) {
3870
3904
  function init(config) {
3871
3905
  const dbPath = config.storage ?? ":memory:";
3872
3906
  const { DatabaseSync } = process.getBuiltinModule("node:sqlite");
3873
- const db = new DatabaseSync(dbPath);
3874
- if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
3875
- db.exec("PRAGMA busy_timeout=5000");
3876
- initSchema(db);
3877
- return { db };
3907
+ const secure = dbPath !== ":memory:" ? preparePrivateStorage(dbPath) : void 0;
3908
+ return withPrivateCreation(() => {
3909
+ const db = new DatabaseSync(dbPath);
3910
+ if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
3911
+ db.exec("PRAGMA busy_timeout=5000");
3912
+ initSchema(db);
3913
+ return { db };
3914
+ }, secure);
3878
3915
  }
3879
3916
 
3880
3917
  // src/write.ts
package/dist/index.js CHANGED
@@ -2,6 +2,8 @@ import { EventEmitter } from 'node:events';
2
2
  import * as net from 'node:net';
3
3
  import * as tls from 'node:tls';
4
4
  import * as zlib from 'node:zlib';
5
+ import { mkdirSync, closeSync, openSync, chmodSync } from 'node:fs';
6
+ import { dirname } from 'node:path';
5
7
  import { randomUUID } from 'node:crypto';
6
8
 
7
9
  var __defProp = Object.defineProperty;
@@ -3696,6 +3698,38 @@ var runtime_exports = {};
3696
3698
  __export(runtime_exports, {
3697
3699
  init: () => init
3698
3700
  });
3701
+ function preparePrivateStorage(path) {
3702
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
3703
+ const created = [];
3704
+ for (const file of [path, `${path}-wal`, `${path}-shm`]) {
3705
+ try {
3706
+ closeSync(openSync(file, "wx", 384));
3707
+ created.push(file);
3708
+ } catch (error) {
3709
+ if (error.code !== "EEXIST") throw error;
3710
+ }
3711
+ }
3712
+ return () => {
3713
+ if (process.platform !== "win32")
3714
+ for (const file of created) {
3715
+ try {
3716
+ chmodSync(file, 384);
3717
+ } catch (error) {
3718
+ if (error.code !== "ENOENT") throw error;
3719
+ }
3720
+ }
3721
+ };
3722
+ }
3723
+ function withPrivateCreation(operation, secure) {
3724
+ if (process.platform === "win32") return operation();
3725
+ const previous = process.umask(63);
3726
+ try {
3727
+ return operation();
3728
+ } finally {
3729
+ process.umask(previous);
3730
+ secure?.();
3731
+ }
3732
+ }
3699
3733
 
3700
3734
  // src/schema/index.ts
3701
3735
  var schema_exports = {};
@@ -3846,11 +3880,14 @@ function initSchema(db) {
3846
3880
  function init(config) {
3847
3881
  const dbPath = config.storage ?? ":memory:";
3848
3882
  const { DatabaseSync } = process.getBuiltinModule("node:sqlite");
3849
- const db = new DatabaseSync(dbPath);
3850
- if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
3851
- db.exec("PRAGMA busy_timeout=5000");
3852
- initSchema(db);
3853
- return { db };
3883
+ const secure = dbPath !== ":memory:" ? preparePrivateStorage(dbPath) : void 0;
3884
+ return withPrivateCreation(() => {
3885
+ const db = new DatabaseSync(dbPath);
3886
+ if (dbPath !== ":memory:") db.exec("PRAGMA journal_mode=WAL");
3887
+ db.exec("PRAGMA busy_timeout=5000");
3888
+ initSchema(db);
3889
+ return { db };
3890
+ }, secure);
3854
3891
  }
3855
3892
 
3856
3893
  // src/write.ts
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { readFileSync, mkdirSync } from 'node:fs';
2
+ import { readFileSync, mkdirSync, closeSync, openSync, chmodSync } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
4
  import { join, dirname } from 'node:path';
5
5
  import { EventEmitter } from 'node:events';
@@ -316,7 +316,7 @@ var init_mcp_stdio = __esm({
316
316
  var emailVersion;
317
317
  var init_version = __esm({
318
318
  "src/version.ts"() {
319
- emailVersion = "0.5.6";
319
+ emailVersion = "0.5.8";
320
320
  }
321
321
  });
322
322
 
@@ -6343,6 +6343,42 @@ var init_email_mcp_options = __esm({
6343
6343
  init_email_surface_tools();
6344
6344
  }
6345
6345
  });
6346
+ function preparePrivateStorage(path) {
6347
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
6348
+ const created = [];
6349
+ for (const file of [path, `${path}-wal`, `${path}-shm`]) {
6350
+ try {
6351
+ closeSync(openSync(file, "wx", 384));
6352
+ created.push(file);
6353
+ } catch (error) {
6354
+ if (error.code !== "EEXIST") throw error;
6355
+ }
6356
+ }
6357
+ return () => {
6358
+ if (process.platform !== "win32")
6359
+ for (const file of created) {
6360
+ try {
6361
+ chmodSync(file, 384);
6362
+ } catch (error) {
6363
+ if (error.code !== "ENOENT") throw error;
6364
+ }
6365
+ }
6366
+ };
6367
+ }
6368
+ function withPrivateCreation(operation, secure) {
6369
+ if (process.platform === "win32") return operation();
6370
+ const previous = process.umask(63);
6371
+ try {
6372
+ return operation();
6373
+ } finally {
6374
+ process.umask(previous);
6375
+ secure?.();
6376
+ }
6377
+ }
6378
+ var init_private_storage = __esm({
6379
+ "src/private_storage.ts"() {
6380
+ }
6381
+ });
6346
6382
 
6347
6383
  // src/schema/create_fts.ts
6348
6384
  function createFts(db) {
@@ -6505,6 +6541,8 @@ var init_schema = __esm({
6505
6541
  init_init_schema();
6506
6542
  }
6507
6543
  });
6544
+
6545
+ // src/surface/open_email_db.ts
6508
6546
  async function openEmailDb(path) {
6509
6547
  const original = process.emitWarning;
6510
6548
  process.emitWarning = ((warning, ...args2) => {
@@ -6520,20 +6558,23 @@ async function openEmailDb(path) {
6520
6558
  } finally {
6521
6559
  process.emitWarning = original;
6522
6560
  }
6523
- if (path !== ":memory:") mkdirSync(dirname(path), { recursive: true });
6524
- const db = new sqlite.DatabaseSync(path);
6525
- try {
6526
- db.exec("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;");
6527
- const context = db;
6528
- initSchema(context);
6529
- return context;
6530
- } catch (error) {
6531
- db.close();
6532
- throw error;
6533
- }
6561
+ const secure = path !== ":memory:" ? preparePrivateStorage(path) : void 0;
6562
+ return withPrivateCreation(() => {
6563
+ const db = new sqlite.DatabaseSync(path);
6564
+ try {
6565
+ db.exec("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;");
6566
+ const context = db;
6567
+ initSchema(context);
6568
+ return context;
6569
+ } catch (error) {
6570
+ db.close();
6571
+ throw error;
6572
+ }
6573
+ }, secure);
6534
6574
  }
6535
6575
  var init_open_email_db = __esm({
6536
6576
  "src/surface/open_email_db.ts"() {
6577
+ init_private_storage();
6537
6578
  init_schema();
6538
6579
  }
6539
6580
  });
package/dist/mcp.cjs CHANGED
@@ -5007,7 +5007,7 @@ var init_network = __esm({
5007
5007
  });
5008
5008
 
5009
5009
  // src/version.ts
5010
- var emailVersion = "0.5.6";
5010
+ var emailVersion = "0.5.8";
5011
5011
 
5012
5012
  // src/surface/email_mcp_instructions.ts
5013
5013
  var emailMcpInstructions = "Read and search cached email offline. Configure live accounts with email account add before network operations. Inspect messages before replying or changing folders. Confirm recipients and content before sending; trash and folder deletion can remove mail. Credentials use the existing email CLI account configuration or EMAIL_* environment variables.";
@@ -6129,6 +6129,38 @@ function emailMcpOptions(context) {
6129
6129
  })
6130
6130
  };
6131
6131
  }
6132
+ function preparePrivateStorage(path) {
6133
+ node_fs.mkdirSync(node_path.dirname(path), { recursive: true, mode: 448 });
6134
+ const created = [];
6135
+ for (const file of [path, `${path}-wal`, `${path}-shm`]) {
6136
+ try {
6137
+ node_fs.closeSync(node_fs.openSync(file, "wx", 384));
6138
+ created.push(file);
6139
+ } catch (error) {
6140
+ if (error.code !== "EEXIST") throw error;
6141
+ }
6142
+ }
6143
+ return () => {
6144
+ if (process.platform !== "win32")
6145
+ for (const file of created) {
6146
+ try {
6147
+ node_fs.chmodSync(file, 384);
6148
+ } catch (error) {
6149
+ if (error.code !== "ENOENT") throw error;
6150
+ }
6151
+ }
6152
+ };
6153
+ }
6154
+ function withPrivateCreation(operation, secure) {
6155
+ if (process.platform === "win32") return operation();
6156
+ const previous = process.umask(63);
6157
+ try {
6158
+ return operation();
6159
+ } finally {
6160
+ process.umask(previous);
6161
+ secure?.();
6162
+ }
6163
+ }
6132
6164
 
6133
6165
  // src/schema/create_fts.ts
6134
6166
  function createFts(db) {
@@ -6282,17 +6314,19 @@ async function openEmailDb(path) {
6282
6314
  } finally {
6283
6315
  process.emitWarning = original;
6284
6316
  }
6285
- if (path !== ":memory:") node_fs.mkdirSync(node_path.dirname(path), { recursive: true });
6286
- const db = new sqlite.DatabaseSync(path);
6287
- try {
6288
- db.exec("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;");
6289
- const context = db;
6290
- initSchema(context);
6291
- return context;
6292
- } catch (error) {
6293
- db.close();
6294
- throw error;
6295
- }
6317
+ const secure = path !== ":memory:" ? preparePrivateStorage(path) : void 0;
6318
+ return withPrivateCreation(() => {
6319
+ const db = new sqlite.DatabaseSync(path);
6320
+ try {
6321
+ db.exec("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;");
6322
+ const context = db;
6323
+ initSchema(context);
6324
+ return context;
6325
+ } catch (error) {
6326
+ db.close();
6327
+ throw error;
6328
+ }
6329
+ }, secure);
6296
6330
  }
6297
6331
  function resolveEmailDbPath(options = {}) {
6298
6332
  return options.flag ?? ((options.env ?? process.env).GHOSTPAW_EMAIL_DB || node_path.join(node_os.homedir(), ".ghostpaw", "email.db"));
package/dist/mcp.js CHANGED
@@ -1,4 +1,4 @@
1
- import { readFileSync, mkdirSync } from 'node:fs';
1
+ import { readFileSync, mkdirSync, closeSync, openSync, chmodSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { join, dirname } from 'node:path';
4
4
  import { EventEmitter } from 'node:events';
@@ -4983,7 +4983,7 @@ var init_network = __esm({
4983
4983
  });
4984
4984
 
4985
4985
  // src/version.ts
4986
- var emailVersion = "0.5.6";
4986
+ var emailVersion = "0.5.8";
4987
4987
 
4988
4988
  // src/surface/email_mcp_instructions.ts
4989
4989
  var emailMcpInstructions = "Read and search cached email offline. Configure live accounts with email account add before network operations. Inspect messages before replying or changing folders. Confirm recipients and content before sending; trash and folder deletion can remove mail. Credentials use the existing email CLI account configuration or EMAIL_* environment variables.";
@@ -6105,6 +6105,38 @@ function emailMcpOptions(context) {
6105
6105
  })
6106
6106
  };
6107
6107
  }
6108
+ function preparePrivateStorage(path) {
6109
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
6110
+ const created = [];
6111
+ for (const file of [path, `${path}-wal`, `${path}-shm`]) {
6112
+ try {
6113
+ closeSync(openSync(file, "wx", 384));
6114
+ created.push(file);
6115
+ } catch (error) {
6116
+ if (error.code !== "EEXIST") throw error;
6117
+ }
6118
+ }
6119
+ return () => {
6120
+ if (process.platform !== "win32")
6121
+ for (const file of created) {
6122
+ try {
6123
+ chmodSync(file, 384);
6124
+ } catch (error) {
6125
+ if (error.code !== "ENOENT") throw error;
6126
+ }
6127
+ }
6128
+ };
6129
+ }
6130
+ function withPrivateCreation(operation, secure) {
6131
+ if (process.platform === "win32") return operation();
6132
+ const previous = process.umask(63);
6133
+ try {
6134
+ return operation();
6135
+ } finally {
6136
+ process.umask(previous);
6137
+ secure?.();
6138
+ }
6139
+ }
6108
6140
 
6109
6141
  // src/schema/create_fts.ts
6110
6142
  function createFts(db) {
@@ -6258,17 +6290,19 @@ async function openEmailDb(path) {
6258
6290
  } finally {
6259
6291
  process.emitWarning = original;
6260
6292
  }
6261
- if (path !== ":memory:") mkdirSync(dirname(path), { recursive: true });
6262
- const db = new sqlite.DatabaseSync(path);
6263
- try {
6264
- db.exec("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;");
6265
- const context = db;
6266
- initSchema(context);
6267
- return context;
6268
- } catch (error) {
6269
- db.close();
6270
- throw error;
6271
- }
6293
+ const secure = path !== ":memory:" ? preparePrivateStorage(path) : void 0;
6294
+ return withPrivateCreation(() => {
6295
+ const db = new sqlite.DatabaseSync(path);
6296
+ try {
6297
+ db.exec("PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;");
6298
+ const context = db;
6299
+ initSchema(context);
6300
+ return context;
6301
+ } catch (error) {
6302
+ db.close();
6303
+ throw error;
6304
+ }
6305
+ }, secure);
6272
6306
  }
6273
6307
  function resolveEmailDbPath(options = {}) {
6274
6308
  return options.flag ?? ((options.env ?? process.env).GHOSTPAW_EMAIL_DB || join(homedir(), ".ghostpaw", "email.db"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghostpaw/email",
3
- "version": "0.5.6",
3
+ "version": "0.5.8",
4
4
  "description": "Standalone IMAP/SMTP email engine for Node.js — SQLite local cache, threading, sync, zero dependencies, with a built-in LLM tool facade",
5
5
  "type": "module",
6
6
  "exports": {
@@ -25,6 +25,8 @@ Run tools as `ghostpaw-email ...`; use `~/.local/bin/ghostpaw-email` if it is no
25
25
 
26
26
  Read and search cached email offline. Configure live accounts with email account add before network operations. Inspect messages before replying or changing folders. Confirm recipients and content before sending; trash and folder deletion can remove mail. Credentials use the existing email CLI account configuration or EMAIL_* environment variables.
27
27
 
28
+ For the compact cheat sheet, run `ghostpaw-email skill --short`.
29
+
28
30
  ## Calling tools
29
31
 
30
32
  MCP: connect to ghostpaw-email, then call a tool by name with its JSON arguments.
@@ -47,7 +49,7 @@ Nested requirements apply within the parent for the selected action.
47
49
 
48
50
  | Parameter | Type | Required | Values / description |
49
51
  | --- | --- | --- | --- |
50
- | view | string | yes | folders, queue, thread, message, attachment, eml. What to read. |
52
+ | view | string | yes | eml. What to read. |
51
53
  | folder | string | no | Folder path (required for queue/message/attachment/eml). |
52
54
  | uid | integer | no | Message UID (required for message/attachment/eml). |
53
55
  | threadId | string | no | Thread ID (required for thread view). |
@@ -105,12 +107,45 @@ Nested requirements apply within the parent for the selected action.
105
107
 
106
108
  | Parameter | Type | Required | Values / description |
107
109
  | --- | --- | --- | --- |
108
- | action | string | yes | send, reply, forward, save_draft, update_draft, send_draft. |
110
+ | action | string | yes | send_draft. string value. |
109
111
  | folder | string | no | Source folder (required for reply/forward). |
110
112
  | uid | integer | no | Source message UID (required for reply/forward/update_draft/send_draft). |
111
113
  | input | object | no | ComposeInput / ReplyInput / ForwardInput payload. |
114
+ | input.from | object | no | Object: address (required), name. |
115
+ | input.from.address | string | yes | Email address. |
116
+ | input.from.name | string | no | Display name. |
117
+ | input.sender | object | no | Object: address (required), name. |
118
+ | input.sender.address | string | yes | Email address. |
119
+ | input.sender.name | string | no | Display name. |
120
+ | input.envelopeFrom | object | no | Object: address (required), name. |
121
+ | input.envelopeFrom.address | string | yes | Email address. |
122
+ | input.envelopeFrom.name | string | no | Display name. |
123
+ | input.replyTo | object | no | Object: address (required), name. |
124
+ | input.replyTo.address | string | yes | Email address. |
125
+ | input.replyTo.name | string | no | Display name. |
112
126
  | input.to | array | yes | Recipient addresses. |
127
+ | input.to[].address | string | yes | Email address. |
128
+ | input.to[].name | string | no | Display name. |
129
+ | input.cc | array | no | Recipient addresses. |
130
+ | input.cc[].address | string | yes | Email address. |
131
+ | input.cc[].name | string | no | Display name. |
132
+ | input.bcc | array | no | Recipient addresses. |
133
+ | input.bcc[].address | string | yes | Email address. |
134
+ | input.bcc[].name | string | no | Display name. |
113
135
  | input.subject | string | yes | Message subject. |
136
+ | input.text | string | no | Plain text body. |
137
+ | input.html | string | no | HTML body. |
138
+ | input.replyAll | boolean | no | Reply to all original recipients. |
139
+ | input.mode | string | no | inline, attachment. string value. |
140
+ | input.attachments | array | no | Message attachments. |
141
+ | input.attachments[].filename | string | yes | string value. |
142
+ | input.attachments[].content | any | yes | Attachment bytes (Buffer in library calls). |
143
+ | input.attachments[].mimeType | string | no | string value. |
144
+ | input.attachments[].inline | boolean | no | boolean value. |
145
+ | input.attachments[].contentId | string | no | string value. |
146
+ | input.inReplyTo | string | no | string value. |
147
+ | input.references | array | no | Array of string. |
148
+ | input.headers | object | no | object value. |
114
149
 
115
150
  Examples:
116
151
 
@@ -134,7 +169,7 @@ Nested requirements apply within the parent for the selected action.
134
169
 
135
170
  | Parameter | Type | Required | Values / description |
136
171
  | --- | --- | --- | --- |
137
- | action | string | yes | mark_read, mark_unread, star, unstar, mark_answered, copy, move, archive, trash, junk, not_junk, set_labels, add_labels, remove_labels, create_folder, rename_folder, delete_folder, subscribe_folder, unsubscribe_folder. |
172
+ | action | string | yes | unsubscribe_folder. string value. |
138
173
  | folder | string | no | Source folder (required for message actions). |
139
174
  | uids | array | no | Message UIDs to act on. |
140
175
  | destination | string | no | Destination folder (required for copy/move). |
@@ -165,7 +200,7 @@ Nested requirements apply within the parent for the selected action.
165
200
 
166
201
  | Parameter | Type | Required | Values / description |
167
202
  | --- | --- | --- | --- |
168
- | action | string | yes | connect, disconnect, reconnect, sync, refresh_folders, watch. |
203
+ | action | string | yes | connect, disconnect, reconnect, sync, refresh_folders, watch. string value. |
169
204
  | folders | array | no | Folders to sync or watch (optional — defaults to all subscribed folders). |
170
205
  | bodies | string | no | none, missing, all. Body fetch strategy for sync (default: missing). |
171
206
 
@@ -179,15 +214,15 @@ ghostpaw-email call mail_sync '{"action":"reconnect"}'
179
214
 
180
215
  ## Workflow guides
181
216
 
182
- - `ghostpaw-email skill triage-inbox` ([triage-inbox](references/triage-inbox.md)): Process a full inbox from scratch: sync to get latest state, read message queue, selectively fetch bodies for decisions, then bulk-organize by priority.
183
- - `ghostpaw-email skill read-and-reply` ([read-and-reply](references/read-and-reply.md)): Read a message with full thread context, then compose and send a properly-threaded reply with quoted attribution.
184
- - `ghostpaw-email skill connect-and-sync` ([connect-and-sync](references/connect-and-sync.md)): Establish or restore an IMAP connection, refresh the folder list, and pull new messages — handling first-run vs incremental scenarios.
185
- - `ghostpaw-email skill search-and-act` ([search-and-act](references/search-and-act.md)): Find messages matching criteria (local FTS first, remote IMAP SEARCH as fallback), verify targets, then act — organize, reply, or present.
186
- - `ghostpaw-email skill compose-and-send` ([compose-and-send](references/compose-and-send.md)): Full draft lifecycle — save, review, update, then send — plus direct send, reply, and forward with proper threading and forwarded-header blocks.
187
- - `ghostpaw-email skill organize-bulk` ([organize-bulk](references/organize-bulk.md)): Bulk organize messages across folders — flagging, moving, archiving, labelling — and manage the folder hierarchy as part of the flow.
188
- - `ghostpaw-email skill attachment-workflow` ([attachment-workflow](references/attachment-workflow.md)): Discover, inspect, and fetch email attachments on demand; embed attachments in outbound messages; and export or import full .eml files.
189
- - `ghostpaw-email skill recover-from-disruption` ([recover-from-disruption](references/recover-from-disruption.md)): Detect and recover from connection loss or IMAP/SMTP failures — reconnect with back-off, re-sync to reconcile state, and handle auth vs transient errors distinctly.
190
- - `ghostpaw-email skill cli` ([cli](references/cli.md)): Complete existing email CLI guide.
217
+ - `ghostpaw-email skill triage-inbox`: Process a full inbox from scratch: sync to get latest state, read message queue, selectively fetch bodies for decisions, then bulk-organize by priority.
218
+ - `ghostpaw-email skill read-and-reply`: Read a message with full thread context, then compose and send a properly-threaded reply with quoted attribution.
219
+ - `ghostpaw-email skill connect-and-sync`: Establish or restore an IMAP connection, refresh the folder list, and pull new messages — handling first-run vs incremental scenarios.
220
+ - `ghostpaw-email skill search-and-act`: Find messages matching criteria (local FTS first, remote IMAP SEARCH as fallback), verify targets, then act — organize, reply, or present.
221
+ - `ghostpaw-email skill compose-and-send`: Full draft lifecycle — save, review, update, then send — plus direct send, reply, and forward with proper threading and forwarded-header blocks.
222
+ - `ghostpaw-email skill organize-bulk`: Bulk organize messages across folders — flagging, moving, archiving, labelling — and manage the folder hierarchy as part of the flow.
223
+ - `ghostpaw-email skill attachment-workflow`: Discover, inspect, and fetch email attachments on demand; embed attachments in outbound messages; and export or import full .eml files.
224
+ - `ghostpaw-email skill recover-from-disruption`: Detect and recover from connection loss or IMAP/SMTP failures — reconnect with back-off, re-sync to reconcile state, and handle auth vs transient errors distinctly.
225
+ - `ghostpaw-email skill cli`: Complete existing email CLI guide.
191
226
 
192
227
  ## Principles
193
228
 
@@ -154,6 +154,8 @@ email compose forward --folder INBOX --uid 1921 --to bob@example.com --body "FYI
154
154
  # Attach files (comma-separated paths)
155
155
  email compose send --to a@b.com --subject "Report" --body "See attached" \
156
156
  --attach /path/to/report.pdf,/path/to/data.csv --json
157
+ # --attach paths must be regular files (symlinks are followed); directories,
158
+ # devices, FIFOs and sockets fail with invalid_flag_value before sending.
157
159
 
158
160
  # Drafts
159
161
  email compose draft --save --to a@b.com --subject "Draft" --body "WIP" --json