@craftsamo/whatsapp-tools 0.0.0-stage → 0.1.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.
Files changed (34) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/.antigravity-plugin/plugin.json +12 -0
  3. package/.claude-plugin/marketplace.json +17 -0
  4. package/.claude-plugin/plugin.json +18 -0
  5. package/.codex-plugin/plugin.json +32 -0
  6. package/.mcp.json +8 -0
  7. package/LICENSE +429 -0
  8. package/README.md +615 -2
  9. package/__init__.py +36 -0
  10. package/dist/cli.js +30780 -0
  11. package/dist/mcp.js +37772 -0
  12. package/dist/opencode.js +27671 -0
  13. package/mcp_config.json +8 -0
  14. package/package.json +70 -4
  15. package/plugin.yaml +46 -0
  16. package/skills/.gitkeep +0 -0
  17. package/skills/whatsapp-account/SKILL.md +55 -0
  18. package/skills/whatsapp-actions/SKILL.md +109 -0
  19. package/skills/whatsapp-chats/SKILL.md +125 -0
  20. package/skills/whatsapp-contacts/SKILL.md +59 -0
  21. package/skills/whatsapp-count-activity/SKILL.md +63 -0
  22. package/skills/whatsapp-files/SKILL.md +112 -0
  23. package/skills/whatsapp-sends/SKILL.md +50 -0
  24. package/src/hermes/whatsapp_tools_hermes/__init__.py +5 -0
  25. package/src/hermes/whatsapp_tools_hermes/approval.py +325 -0
  26. package/src/hermes/whatsapp_tools_hermes/card.py +507 -0
  27. package/src/hermes/whatsapp_tools_hermes/context.py +34 -0
  28. package/src/hermes/whatsapp_tools_hermes/listing.py +78 -0
  29. package/src/hermes/whatsapp_tools_hermes/plugin.py +38 -0
  30. package/src/hermes/whatsapp_tools_hermes/project.py +47 -0
  31. package/src/hermes/whatsapp_tools_hermes/runtime.py +204 -0
  32. package/src/hermes/whatsapp_tools_hermes/settings.py +117 -0
  33. package/src/hermes/whatsapp_tools_hermes/skills.py +131 -0
  34. package/src/hermes/whatsapp_tools_hermes/tools.py +97 -0
package/README.md CHANGED
@@ -1,3 +1,616 @@
1
- # Temporary Holding Version
1
+ # whatsapp-tools
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ WhatsApp tools for coding agents: chats, messages, contacts, history, received files, sends and actions on the user's own messages and chats.
4
+
5
+ | Harness | Delivery | Pinned by |
6
+ | -------------- | ---------------------------------------------- | ------------------------------ |
7
+ | OpenCode V2 | native plugin (npm package, with skills) | the version in the package |
8
+ | OpenCode V1 | native plugin (npm package, no skills) | the version in the package |
9
+ | Claude Code | plugin: MCP server and skills | the release tag, as the ref |
10
+ | Codex | plugin: MCP server and skills | the release tag, as the ref |
11
+ | Grok Build | plugin: MCP server and skills | the release tag, as `@ref` |
12
+ | Antigravity | plugin: MCP server and skills | the release tag's tree URL |
13
+ | Hermes Agent | native plugin (Python, calls the command line) | the release commit, as the SHA |
14
+ | other MCP host | MCP server from npm | the version in the package |
15
+
16
+ The tools need [Node.js](https://nodejs.org/) 24 or later.
17
+ [`docs/conventions.md`](docs/conventions.md) describes how the tools are named
18
+ and how they behave.
19
+
20
+ ## Install
21
+
22
+ Install from a release, never from the default branch: a release is a tag whose
23
+ commit carries the built `dist/`, and the default branch does not. In the
24
+ commands below, `<version>` is a release's version (`1.2.3`) and `<sha>` is the
25
+ commit its tag names:
26
+
27
+ ```sh
28
+ gh api repos/craft-agent/whatsapp-tools/commits/v<version> --jq .sha
29
+ ```
30
+
31
+ ### OpenCode
32
+
33
+ OpenCode V2 takes the package and its options in `opencode.json`:
34
+
35
+ ```json
36
+ {
37
+ "plugins": [{ "package": "@craftsamo/whatsapp-tools@<version>", "options": { "read_only": false } }],
38
+ "permissions": [{ "action": "whatsapp_*", "resource": "*", "effect": "ask" }]
39
+ }
40
+ ```
41
+
42
+ OpenCode V1 takes the package as a string, or as a pair with its options:
43
+
44
+ ```json
45
+ {
46
+ "plugin": [["@craftsamo/whatsapp-tools@<version>", { "read_only": false }]],
47
+ "permission": { "whatsapp_*": "ask" }
48
+ }
49
+ ```
50
+
51
+ OpenCode allows any action no rule names, so the plugin's request is granted
52
+ silently unless a rule says `ask`. Read tools never ask, so the `whatsapp_*` glob
53
+ is safe.
54
+
55
+ V1 registers no skills. Unpack the package and copy its `skills/*` folders into
56
+ `~/.config/opencode/skills/`:
57
+
58
+ ```sh
59
+ npm pack @craftsamo/whatsapp-tools@<version>
60
+ tar -xzf craftsamo-whatsapp-tools-<version>.tgz
61
+ mkdir -p ~/.config/opencode/skills
62
+ cp -r package/skills/* ~/.config/opencode/skills/
63
+ rm -rf package craftsamo-whatsapp-tools-<version>.tgz
64
+ ```
65
+
66
+ ### Claude Code
67
+
68
+ ```sh
69
+ claude plugin marketplace add craft-agent/whatsapp-tools#v<version>
70
+ claude plugin install whatsapp-tools@craft-agent
71
+ ```
72
+
73
+ ### Codex
74
+
75
+ ```sh
76
+ codex plugin marketplace add craft-agent/whatsapp-tools --ref v<version>
77
+ codex plugin add whatsapp-tools@craft-agent
78
+ ```
79
+
80
+ Codex turns `-` into `_` in server names, so it shows the tools as
81
+ `mcp__whatsapp_tools__whatsapp_*`. It starts the MCP server in the plugin's
82
+ install directory and passes no roots, so the server takes each call's directory
83
+ from what Codex sends with the call: its sandbox state, which the server asks
84
+ for, else the one workspace it names.
85
+
86
+ The plugin declares `default_tools_approval_mode = "writes"`: Codex asks before
87
+ every tool not marked read-only. A user's
88
+ `[plugins."<plugin>".mcp_servers.<server>]` setting can only tighten it. Setting
89
+ `auto` there yields `prompt` (reads asked too), since Codex treats `auto` and
90
+ `writes` as incomparable.
91
+
92
+ ### Grok Build
93
+
94
+ ```sh
95
+ grok plugin install craft-agent/whatsapp-tools@v<version> --trust
96
+ ```
97
+
98
+ Grok starts the MCP server in the session's working directory.
99
+
100
+ ### Antigravity
101
+
102
+ Install from the tree of the release tag, never from the default branch, which
103
+ has no built `dist/`; Antigravity clones the tag into
104
+ `~/.gemini/config/plugins/whatsapp-tools`.
105
+
106
+ ```sh
107
+ agy plugin install https://github.com/craft-agent/whatsapp-tools/tree/v<version>
108
+ ```
109
+
110
+ ### Hermes Agent
111
+
112
+ The plugin needs Hermes Agent 0.22 or later. Hermes installs a commit, not a
113
+ tag, and the plugin installs disabled:
114
+
115
+ ```sh
116
+ hermes plugins install craft-agent/whatsapp-tools --ref <sha>
117
+ hermes plugins enable whatsapp-tools
118
+ ```
119
+
120
+ If a Hermes gateway is already running, restart it (`hermes gateway restart`) to
121
+ load the plugin. While a gateway runs, `hermes chat` runs the plugin's tools in
122
+ the gateway too, so they see the gateway's environment, not the shell's: the
123
+ `PATH` that finds `wacli` and `node`, and any `WHATSAPP_TOOLS_*` variable, are
124
+ the ones the gateway started with.
125
+
126
+ The plugin runs the Node it found when Hermes started. If a version manager
127
+ removes that version while Hermes runs, a call looks for Node again; when it
128
+ finds none, restart Hermes from a shell where `node` runs.
129
+
130
+ ### Any other MCP host
131
+
132
+ Add the server to the host's MCP configuration. Flags go in `args`:
133
+
134
+ ```json
135
+ {
136
+ "mcpServers": {
137
+ "whatsapp-tools": {
138
+ "command": "npx",
139
+ "args": ["-y", "@craftsamo/whatsapp-tools@<version>", "--read-only"]
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ ## Tools and skills
146
+
147
+ Each toolset comes with a skill that tells an agent how to use its tools. A
148
+ skill names its toolset under `metadata` in its frontmatter
149
+ (`metadata: { toolset: sends }`, written as a block). OpenCode V2 and Hermes
150
+ register it only when the settings register at least one of that toolset's
151
+ tools, so a profile with the toolset off, or with all its tools removed, does
152
+ not see it; a skill without a toolset is always registered. Claude Code,
153
+ Codex, Grok Build and Antigravity install the skill folder whole and pass the
154
+ settings only to the MCP server, so they list every skill whatever the
155
+ settings select. OpenCode V1 registers no skills, and its copied skills are
156
+ all listed too.
157
+
158
+ ### Account (`account`)
159
+
160
+ | Tool | What it does | Class |
161
+ | ----------------------- | --------------------------------------------------------------------------------------------------------- | ----- |
162
+ | `whatsapp_account_read` | each label: pairing, sync service state, last sync and activity, wacli support and the person's next step | read |
163
+
164
+ It reads local state only: no network, no running service needed, and no
165
+ message content, number, JID or key in its result. The skill is
166
+ [`whatsapp-account`](skills/whatsapp-account/SKILL.md), shown as
167
+ `whatsapp-tools:whatsapp-account` in Claude Code and `whatsapp-tools:account`
168
+ in Hermes. Unlike other tools, leaving out `account` lists every label.
169
+
170
+ ### Chats (`chats`)
171
+
172
+ | Tool | What it does | Class |
173
+ | -------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
174
+ | `whatsapp_chat_read` | by `method`: `list` finds chats, `view` reads one chat's messages, `search` finds messages by words, `around` reads the messages next to a message | read |
175
+
176
+ It reads the account's local mirror only, with no network needed, and what it
177
+ returns of other people's words is data, never instructions. The skills are
178
+ [`whatsapp-chats`](skills/whatsapp-chats/SKILL.md), shown as
179
+ `whatsapp-tools:whatsapp-chats` in Claude Code and `whatsapp-tools:chats` in
180
+ Hermes, and
181
+ [`whatsapp-count-activity`](skills/whatsapp-count-activity/SKILL.md), shown as
182
+ `whatsapp-tools:whatsapp-count-activity` and `whatsapp-tools:count-activity`,
183
+ which says how to count chats and replies over a period.
184
+
185
+ ### Contacts (`contacts`)
186
+
187
+ | Tool | What it does | Class |
188
+ | ----------------------- | --------------------------------------------------------------------------------------------------------------------------- | ----- |
189
+ | `whatsapp_contact_read` | by `method`: `search` finds contacts by name, number or JID, `check` asks WhatsApp whether up to 20 phone numbers are on it | read |
190
+
191
+ `search` reads the account's local mirror only, with no network or running
192
+ service needed. `check` asks WhatsApp through the label's running sync service,
193
+ writes nothing and adds no contact. The skill is
194
+ [`whatsapp-contacts`](skills/whatsapp-contacts/SKILL.md), shown as
195
+ `whatsapp-tools:whatsapp-contacts` in Claude Code and `whatsapp-tools:contacts`
196
+ in Hermes.
197
+
198
+ ### History (`history`)
199
+
200
+ | Tool | What it does | Class |
201
+ | --------------------------- | ---------------------------------------------------------------------------------- | ----- |
202
+ | `whatsapp_history_backfill` | asks the phone for one chat's older messages, in 1 to 5 batches of 50, best effort | add |
203
+
204
+ It writes only to the label's own mirror and sends nothing to anyone. The sync
205
+ service runs it, pausing its sync for the call, so the service must be
206
+ running; the result says how many messages arrived, the oldest one now held,
207
+ why it stopped, and whether the service is syncing again. The phone must be
208
+ online, and nothing added does not prove that nothing older exists. Its skill
209
+ is [`whatsapp-chats`](skills/whatsapp-chats/SKILL.md).
210
+
211
+ A call can take up to about five minutes. Some harnesses stop a tool call
212
+ sooner by default, and the call then fails, though what arrived stays and the
213
+ service syncs again:
214
+
215
+ - **Codex** stops a call after 60 s by default; the plugin raises the limit to
216
+ 330 s. A server added under `[mcp_servers]` instead of the plugin (see
217
+ [Settings](#settings)) needs `tool_timeout_sec = 330`.
218
+ - **Antigravity** stops a call after 180 s. Give the server
219
+ `"timeoutSeconds": 330` in its MCP configuration.
220
+ - **Hermes** gives the plugin's calls 150 s, and 330 s to
221
+ `whatsapp_history_backfill`, `whatsapp_file_save` and `whatsapp_file_send`;
222
+ nothing needs setting.
223
+
224
+ ### Files (`files`)
225
+
226
+ | Tool | What it does | Class |
227
+ | -------------------- | -------------------------------------------------------------------------------------------------------- | ----- |
228
+ | `whatsapp_file_save` | saves one message's file into `download_dir`, inspecting archives and unpacking one when asked to | add |
229
+ | `whatsapp_file_send` | sends 1 to 10 files, up to 100 MiB, to a person or a group, one message each, checked before any is sent | add |
230
+
231
+ Off by default: turn it on with the `files` toolset. A message's file goes into
232
+ its own folder under `download_dir` (`~/Downloads/whatsapp-tools` by default),
233
+ private and never executable, and nothing is overwritten. Programs,
234
+ installers, disk images, macro documents and archives that cannot be read are
235
+ refused; zip, tar and gzipped tar are inspected first and unpacked only when
236
+ asked. On macOS each saved file carries the quarantine flag. A file WhatsApp's
237
+ server no longer keeps is asked of the phone through the running sync service.
238
+ The skill is
239
+ [`whatsapp-files`](skills/whatsapp-files/SKILL.md), shown as
240
+ `whatsapp-tools:whatsapp-files` in Claude Code and `whatsapp-tools:files` in
241
+ Hermes.
242
+
243
+ A call that falls back to the phone can take a few minutes; the tool time
244
+ limits given above under History apply to it too.
245
+
246
+ `whatsapp_file_send` sends only from the working directory and the
247
+ directories the `send_dirs` setting names, judged by real path; a file
248
+ anywhere else is refused, and so is the state directory. Keys and secrets
249
+ (`.ssh`, `.env`, `*.pem`, …), the data folders of browsers, password managers
250
+ and messengers, empty files, programs, installers and anything holding a
251
+ private key block are never sent, wherever they are; an archive is sent only
252
+ once every entry passes, and is never unpacked. Each file is copied into the
253
+ label's outbox and checked there, so what is checked is what leaves, and a
254
+ `sha256` the user approved makes a changed file `stale`. Each file is its own
255
+ message, in the order given, with the text as the first file's caption (at most
256
+ 1,024 characters, refused on audio). Photos, videos and audio WhatsApp shows
257
+ itself go as such, decided from the name and the first bytes, and everything
258
+ else as a file; `as_document` sends all of them as files. A call that stops
259
+ after some files went out fails and lists in `details` what went out, with
260
+ the message ids, and what did not, so nothing is sent twice; a file that may
261
+ have gone out is `uncertain`. A call takes at most 280 s, and the tool time
262
+ limits given above under History apply to it too.
263
+
264
+ ### Sends (`sends`)
265
+
266
+ | Tool | What it does | Class |
267
+ | ----------------------- | --------------------------------------------------------------------------------------------- | ----- |
268
+ | `whatsapp_message_send` | sends one text, up to 4,000 characters, to a person or a group, with an optional quoted reply | add |
269
+
270
+ On by default, and it goes through the label's running sync service, so the
271
+ service must be running. It sends to people and groups only: a channel, a
272
+ broadcast list and the status feed are refused. The chat is a JID from
273
+ `whatsapp_chat_read`; for someone the mirror does not hold yet, it is the
274
+ `chat` that `whatsapp_contact_read` `check` gives, and WhatsApp is asked right
275
+ before sending whether the number has an account. The text goes out as given,
276
+ surrounding blank space trimmed, never split, and with no link preview. A
277
+ result means WhatsApp accepted the message, not that it was delivered or read.
278
+ A failure known to happen before anything left says so; every other failure
279
+ after the request was handed over is `uncertain`: the message may have gone
280
+ out, and the chat is checked and the user asked before it is sent again. Like
281
+ a message written on the phone, a send lowers the chat's unread count in the
282
+ mirror and sends no read receipt. The skill is
283
+ [`whatsapp-sends`](skills/whatsapp-sends/SKILL.md), shown as
284
+ `whatsapp-tools:whatsapp-sends` in Claude Code and `whatsapp-tools:sends` in
285
+ Hermes.
286
+
287
+ ### Actions (`actions`)
288
+
289
+ | Tool | What it does | Class |
290
+ | ------------------------- | ------------------------------------------------------------------------------ | -------------- |
291
+ | `whatsapp_chat_archive` | archives a chat, or unarchives it | idempotent |
292
+ | `whatsapp_chat_mark` | marks a chat read or unread, optionally sending read receipts | idempotent |
293
+ | `whatsapp_chat_mute` | mutes a chat for 8 hours, a week or always, or unmutes it | idempotent |
294
+ | `whatsapp_chat_pin` | pins a chat, or unpins it, up to the three WhatsApp allows | idempotent |
295
+ | `whatsapp_message_delete` | deletes a message the user sent for everyone, at most two days after it | administrative |
296
+ | `whatsapp_message_edit` | replaces the text of a text message the user sent, at most 15 minutes after it | overwrite |
297
+ | `whatsapp_message_react` | reacts to a message with one emoji, or removes the user's reaction | overwrite |
298
+
299
+ Off by default: turn it on with the `actions` toolset. Each action goes
300
+ through the label's running sync service and acts only on a chat and a message
301
+ the mirror holds, named by JID and id from `whatsapp_chat_read`. Deleting for
302
+ everyone pauses the sync service for the call, a few seconds, and the result
303
+ says whether it syncs again. It keeps to the limits WhatsApp's own apps hold,
304
+ and refuses past them before anything leaves. A result means WhatsApp
305
+ accepted the action; a failure known to happen before anything left says so,
306
+ and every other failure is `uncertain`: the chat is checked and the user asked
307
+ before the action is tried again. A chat's archive, pin, mute and read state
308
+ are states only the user's own devices show, and setting one again is safe,
309
+ so their `uncertain` says so. Marking a chat read tells no one by default;
310
+ only when the user asks for it does `receipts: true` send read receipts for up
311
+ to 100 unread messages instead, which tells their senders and clears only the
312
+ mirror's unread count, not necessarily the phone's mark. The skill is
313
+ [`whatsapp-actions`](skills/whatsapp-actions/SKILL.md), shown as
314
+ `whatsapp-tools:whatsapp-actions` in Claude Code and `whatsapp-tools:actions`
315
+ in Hermes.
316
+
317
+ ## Adding a tool
318
+
319
+ 1. Write the spec in `src/core/<domain>/<verb>.ts` with `defineTool`: an ID
320
+ `<prefix>_<domain>_<verb>`, a title and description, the Zod argument and
321
+ output schemas, its toolset and write class, and `execute(args, context)`.
322
+ A write tool also gives `targets(args, context)`: what the call writes to,
323
+ as a permission rule should name it.
324
+ 2. Test it beside the spec (`<verb>.test.ts`), calling it through `invoke` as
325
+ the entry points do. A tool that runs a program is tested against a fake of
326
+ that program on `PATH`; no test reaches a real service.
327
+ 3. List it in `src/tools.ts`. A new toolset goes into `toolsets` in
328
+ `src/project.ts` (and `defaultToolsets` when it is on by default), a
329
+ setting of the package's own into `options` (and `OPTIONS` in `project.py`
330
+ with `config_schema` in `plugin.yaml`), and a variable the tool reads
331
+ besides the settings into `toolVariables`.
332
+ 4. Add or update the toolset's skill, `skills/<prefix>-<toolset>/SKILL.md`,
333
+ whose frontmatter names the toolset under `metadata`.
334
+ 5. Run `pnpm run build && pnpm run manifests` to list the tool in
335
+ `plugin.yaml` and its variables in Codex's manifest, then describe it under
336
+ "Tools and skills".
337
+
338
+ [`docs/conventions.md`](docs/conventions.md) has the rules each step follows.
339
+
340
+ A package declares each option as `text`, `boolean`, `number`, `list`, `path`
341
+ or `paths`, or as an object with `type` and optional bounds. For example, in
342
+ `src/project.ts`:
343
+
344
+ ```ts
345
+ options: {
346
+ notes_dir: "path",
347
+ note_limit: { type: "number", integer: true, min: 1, max: 50 },
348
+ }
349
+ ```
350
+
351
+ `integer: true` requires a whole number; `min` and `max` bound a number or
352
+ count a `list` or `paths` value's items. An object with only `type` means the
353
+ same as the type alone. Hermes's `OPTIONS` mirrors the declarations on one
354
+ line, with double quotes and Python's `True` for `integer`:
355
+
356
+ ```python
357
+ OPTIONS: dict[str, str | dict[str, object]] = {"notes_dir": "path", "note_limit": {"type": "number", "integer": True, "min": 1, "max": 50}}
358
+ ```
359
+
360
+ ## Reads and writes
361
+
362
+ Every read tool is named `<prefix>_<domain>_read`. Reads can run unasked;
363
+ writes are confirmed by the harness.
364
+
365
+ | Harness | Reads without asking |
366
+ | ----------- | ---------------------------------------------------------------------------------------------------------------- |
367
+ | OpenCode | always; the plugin asks only before a write |
368
+ | Claude Code | the rule `mcp__plugin_whatsapp-tools_whatsapp-tools__*_read` in `permissions.allow` of `~/.claude/settings.json` |
369
+ | Codex | always; Codex runs tools that declare `readOnlyHint` unasked, as the read tools do |
370
+ | Grok Build | `grok --allow 'MCPTool(whatsapp-tools__*_read)' --allow 'MCPTool(whatsapp_*_read)'` (both rules; see below) |
371
+ | Antigravity | the rule `mcp(whatsapp-tools_whatsapp-tools/<tool id>)` in `permissions.allow`, one for each read tool |
372
+ | Hermes | always; the plugin asks only before a write |
373
+
374
+ Where a write is asked about, and where it is not:
375
+
376
+ - **OpenCode** grants any action no rule names, so a write runs unasked unless
377
+ a rule asks for it: add the `whatsapp_*` rule shown under [OpenCode](#opencode).
378
+ - **Codex** asks before every write because of the plugin's approval mode.
379
+ Under `codex exec` it refuses with "MCP tool call requires approval, but
380
+ approval policy is never".
381
+ - **Grok Build** under `grok -p` refuses a write it cannot ask about, unless it
382
+ is allowed beforehand.
383
+ - **Grok Build** calls the plugin's tools through its `use_tool` tool, and the
384
+ agent often names a tool without its server first. Grok checks the rules
385
+ against the name as given, so the server-qualified rule alone does not match
386
+ that first call. The second rule matches the short name; a write still
387
+ matches neither.
388
+ - **Antigravity** asks before any MCP tool no rule allows, reads included, and
389
+ names the plugin's server `whatsapp-tools_whatsapp-tools` (plugin,
390
+ then server). `agy -p` refuses a tool it cannot ask about.
391
+ - **Hermes** `hermes chat -q` refuses a write it cannot ask about; `hermes -z`
392
+ and `--yolo` skip approval, so writes then run unasked.
393
+
394
+ ## Settings
395
+
396
+ Every entry point takes the same settings. A flag wins over its environment
397
+ variable, and an option or setting wins over the variable too, except in
398
+ Hermes, noted below.
399
+
400
+ | Setting | Flag | Variable | Meaning |
401
+ | --------------- | ----------------- | ------------------------------ | --------------------------------------------------------------------------------- |
402
+ | `toolsets` | `--toolsets` | `WHATSAPP_TOOLS_TOOLSETS` | the toolsets that are on, or `all`; default those `src/project.ts` names |
403
+ | `read_only` | `--read-only` | `WHATSAPP_TOOLS_READ_ONLY` | registers no tool that writes; wins over every other setting |
404
+ | `tools` | `--tools` | `WHATSAPP_TOOLS_TOOLS` | single tools to add by ID, whatever their toolset |
405
+ | `exclude_tools` | `--exclude-tools` | `WHATSAPP_TOOLS_EXCLUDE_TOOLS` | single tools to remove by ID; wins over `tools` and `toolsets` |
406
+ | `confirm` | `--confirm` | `WHATSAPP_TOOLS_CONFIRM` | MCP server only: `harness` (default) or `elicitation`, as the conventions say |
407
+ | `language` | `--language` | `WHATSAPP_TOOLS_LANGUAGE` | native plugins only: the approval prompt's language, such as `ja` |
408
+ | `emoji` | — | — | Hermes only: the emoji shown beside each toolset, by toolset name (`""` for none) |
409
+ | `state_dir` | `--state-dir` | `WHATSAPP_TOOLS_STATE_DIR` | `path`: where every label's state lives; default `$XDG_STATE_HOME/whatsapp-tools` |
410
+ | `download_dir` | `--download-dir` | `WHATSAPP_TOOLS_DOWNLOAD_DIR` | `path`: where received files are saved; default `~/Downloads/whatsapp-tools` |
411
+ | `send_dirs` | `--send-dirs` | `WHATSAPP_TOOLS_SEND_DIRS` | `paths`: the directories files may be sent from, besides the working directory |
412
+
413
+ Lists are comma-separated in a flag or a variable. `state_dir`, `download_dir`
414
+ and `send_dirs` are this package's own settings, listed in `options` in
415
+ `src/project.ts` and read the same way. A `path` is trimmed; `~` and `~/…`
416
+ (also with the platform separator) stand for the home directory (`HOME` when
417
+ it is absolute, else the account's). It must then be absolute and reaches the
418
+ tool normalized, without a filesystem check. A blank path counts as unset,
419
+ so the default applies. `paths` is a list of such paths, comma-separated in a
420
+ flag or variable and an array of strings in a plugin option. Blank items are
421
+ dropped, and a list with none left counts as unset. Repeated send directories
422
+ are dropped. Bounds check only a given value, not an unset option. Refused
423
+ values are `invalid_argument`, naming the flag, variable or option and what it
424
+ must be.
425
+ Hermes passes paths and lists to the command line, which checks the paths and
426
+ bounds. Where each harness reads them:
427
+
428
+ - **OpenCode** takes the plugin `options` shown above, with lists as arrays,
429
+ `read_only` as a boolean, `state_dir` and `download_dir` as paths and
430
+ `send_dirs` as an array of paths, and falls back to the variables. V2 runs plugins in
431
+ its background service, which keeps the environment it started with: a
432
+ variable set where `opencode run` starts has no effect until the service is
433
+ restarted in that environment (`opencode service restart`). V1 runs plugins
434
+ in its own process.
435
+ - **Hermes** takes `plugins.entries.whatsapp-tools.settings` in
436
+ `config.yaml`:
437
+
438
+ ```yaml
439
+ plugins:
440
+ entries:
441
+ whatsapp-tools:
442
+ settings:
443
+ read_only: false
444
+ exclude_tools: []
445
+ ```
446
+
447
+ Without a `language` setting, the approval card follows Hermes's own
448
+ `display.language` (or `HERMES_LANGUAGE`), the language of its approval
449
+ buttons, and else stays in English. The plugin passes its own environment
450
+ to the command line it runs, so the variables work too. A setting that is
451
+ off or empty (`read_only: false`, `tools: []`, `exclude_tools: []`,
452
+ `send_dirs: []`) passes nothing, so a variable set in that environment
453
+ still applies: `WHATSAPP_TOOLS_READ_ONLY=true` keeps the plugin read-only
454
+ whatever the setting says. A running gateway keeps the environment it
455
+ started with, and `hermes chat` runs the tools there while it runs; restart
456
+ it (`hermes gateway restart`) after changing one.
457
+
458
+ - **Claude Code, Grok Build and Antigravity** start the plugin's server without
459
+ flags and pass it the client's environment, so set the variables in the
460
+ environment the harness runs in.
461
+ - **Codex** passes a plugin's MCP server only a few basic variables (such as
462
+ `PATH` and `HOME`) and those the plugin's manifest names, which are the
463
+ variables above: set them in the environment Codex runs in. A variable the
464
+ tools read besides the settings belongs in `toolVariables` in
465
+ `src/project.ts`; `pnpm run manifests` adds it to the manifest after the
466
+ settings' variables. To pass flags, or to give the server a variable the
467
+ package does not name, add the server under `[mcp_servers]` in Codex's
468
+ `config.toml` instead of using the plugin: flags go in `args`, `env_vars`
469
+ names the variables to forward from Codex's environment, and `env` sets
470
+ fixed values.
471
+
472
+ ```toml
473
+ [mcp_servers.whatsapp-tools]
474
+ command = "npx"
475
+ args = ["-y", "@craftsamo/whatsapp-tools@<version>", "--read-only"]
476
+ env_vars = ["WHATSAPP_TOOLS_TOOLSETS"]
477
+ tool_timeout_sec = 330
478
+ ```
479
+
480
+ ### Accounts and the sync service
481
+
482
+ The tools use a WhatsApp account as a linked device of the user's phone, the
483
+ way WhatsApp Web does, through [wacli](https://github.com/openclaw/wacli),
484
+ which you install yourself (`brew install openclaw/tap/wacli`, or a release
485
+ binary). They never drive WhatsApp Web or read another client's data.
486
+
487
+ - **wacli 0.26 or later.** WhatsApp stops serving old clients until wacli
488
+ catches up with its protocol, so keep it updated; after an update, restart
489
+ the sync service so it runs the new release.
490
+ - **Each linked device has a label**, 1 to 24 lowercase letters, digits and
491
+ `_` (`default` when pairing names none). A tool's `account` argument picks
492
+ the label; leave it out when only one device is paired. The account tool
493
+ instead lists every label when `account` is absent.
494
+ - **Each label keeps its state in one directory**, `<state_dir>/<label>/`
495
+ (mode 700): wacli's store (the session keys, its mirror of your messages,
496
+ downloaded media), the sync service's socket, and the copies of files being
497
+ sent. `state_dir` defaults to `$XDG_STATE_HOME/whatsapp-tools`, or
498
+ `~/.local/state/whatsapp-tools`. wacli's own accounts in `~/.wacli` are not
499
+ used. Keep the directory out of backups you share: the keys read and send as
500
+ you.
501
+ - **A sync service runs for each label**: it keeps the mirror current, and
502
+ every send and every other write goes through it, so the tools that write
503
+ need it running. Reads work with or without it. History starts when the
504
+ device is paired, with what the phone sends then; older messages can be
505
+ asked of the phone, best effort.
506
+ - **WhatsApp unlinks a device unused for 30 days**, and every linked device
507
+ when the phone has been unused for 14; a phone takes four linked devices at
508
+ most. A running service keeps the device in use. An unlinked label is paired
509
+ again from the phone.
510
+ - **wacli is not an official client.** WhatsApp has no API for personal
511
+ accounts, and it may limit or ban an account it finds using an unofficial
512
+ one.
513
+
514
+ ### Pairing a device and running the sync service
515
+
516
+ Install [wacli 0.26 or later](https://github.com/openclaw/wacli) first: on
517
+ macOS, `brew install openclaw/tap/wacli`; elsewhere, a release binary. macOS
518
+ and Linux are supported; Windows is
519
+ [#11](https://github.com/craft-agent/whatsapp-tools/issues/11).
520
+
521
+ The commands come with the npm package, apart from any harness plugin: a
522
+ plugin gives the tools, not a command on your `PATH`. Install the package
523
+ globally, at the version of the plugin you use, so that the service it
524
+ installs keeps a stable path:
525
+
526
+ ```sh
527
+ npm install -g @craftsamo/whatsapp-tools@<version>
528
+ ```
529
+
530
+ ```sh
531
+ # On the phone, WhatsApp > Linked devices > Link a device, then scan the QR.
532
+ whatsapp-tools-cli pair --account work
533
+
534
+ # Start syncing at logon, and restart after a failure.
535
+ whatsapp-tools-cli service install --account work
536
+ whatsapp-tools-cli service status
537
+ ```
538
+
539
+ `--account` may be left out when only one label exists (`pair` names a new
540
+ one `default`), except by `remove`, which always needs it; every command takes
541
+ `--state-dir` like the tools. With
542
+ several labels, add `--account work` to `service status` too.
543
+
544
+ Every command below follows `whatsapp-tools-cli`:
545
+
546
+ | Command | What it does |
547
+ | ----------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
548
+ | `pair [--account <label>] [--phone <number>] [--full-history [--history-days <n>]]` | pairs this machine from a QR code, or with `--phone` prints a code to enter on the phone, then waits for the first sync |
549
+ | `sync [--account <label>]` | runs the sync service in the foreground, logging to standard error, until stopped |
550
+ | `service install \| uninstall \| status [--account <label>]` | registers/starts the service as a launchd agent (macOS) or systemd user unit (Linux), removes it, or reports its state |
551
+ | `remove --account <label> [--yes]` | uninstalls the service, logs the device out when possible and deletes the label's keys and history after confirmation |
552
+
553
+ - **The service records this package's paths and Node's**, so run
554
+ `service install` again after updating either. Where Node's path holds its
555
+ version, as under a version manager, `service install` records a `node` on
556
+ `PATH` at a path without it that starts the same Node, and warns when there
557
+ is none. That `node` then runs whichever Node the manager makes current.
558
+ `service status` and `whatsapp_account_read` say when the recorded program
559
+ is gone, once the service has been installed with this version. On macOS its
560
+ log is
561
+ `~/Library/Logs/io.github.craft-agent.whatsapp-tools/<label>.log`; on Linux,
562
+ `journalctl --user -u <unit>` as `service status` shows, and
563
+ `loginctl enable-linger` keeps it running while you are logged out.
564
+ - **On macOS, Login Items lists the service as `whatsapp-tools-sync-<label>`**:
565
+ the agent starts through that launcher script, which `service install`
566
+ writes to
567
+ `~/Library/Application Support/io.github.craft-agent.whatsapp-tools/` and
568
+ `service uninstall` deletes. Switching the item off there stops syncing.
569
+ - **A phone takes at most four linked devices**, and each label is one of
570
+ them. WhatsApp unlinks a device unused for 30 days, and every linked device
571
+ when the phone has been unused for 14 days; a running service keeps the
572
+ linked device in use, not the phone.
573
+ - **`--full-history` asks the phone for its full history** while pairing,
574
+ instead of its recent months; `--history-days` limits how far back. It
575
+ takes effect only while pairing, and the phone keeps sending for a while
576
+ after `pair` ends, which reaches the mirror once the service runs. A
577
+ device already paired gets older messages with `whatsapp_history_backfill`,
578
+ one chat at a time, or by being removed and paired again.
579
+ - **To pair a revoked label again**, run `pair` again: the dead session is
580
+ deleted and the mirror is kept. Use a new label for a different account.
581
+ - **Removing a label logs the device out when possible.** If it cannot,
582
+ remove the linked device on the phone under WhatsApp > Linked devices too.
583
+ - `whatsapp_account_read` tells an agent which step a label needs.
584
+
585
+ ## Layout
586
+
587
+ - `src/project.ts` — the package's name, tool ID prefix, setting prefix,
588
+ toolsets, tool options and the other variables its tools read.
589
+ - `src/core/` — the tool contract and the tools, free of any harness and of
590
+ the project's names.
591
+ - `src/tools.ts` — the list of every tool, which each entry point registers.
592
+ - `src/words.ts` — the translations of the tools' words, per language, which
593
+ the native plugins use in their approval prompts.
594
+ - `src/mcp/` — the MCP server, built to `dist/mcp.js` and run by
595
+ `whatsapp-tools`.
596
+ - `src/opencode/` — the OpenCode plugin, built to `dist/opencode.js`.
597
+ - `src/cli/` — the command line the Hermes plugin calls, built to `dist/cli.js`
598
+ and run by `whatsapp-tools-cli`.
599
+ - `src/hermes/`, `plugin.yaml` and `__init__.py` — the Hermes plugin.
600
+ - `skills/` — one skill per toolset, `skills/<name>/SKILL.md`, which every
601
+ harness that takes skills loads from the package or plugin root; the native
602
+ plugins load only those of the toolsets that are on.
603
+ - `.claude-plugin/`, `.codex-plugin/`, `.agents/plugins/`, `.mcp.json`,
604
+ `.antigravity-plugin/` and `mcp_config.json` — the plugin manifests of the
605
+ other harnesses. Codex reads `.codex-plugin/plugin.json`; a root
606
+ `plugin.json` would make it load the plugin as an Agent Plugin, whose tool
607
+ budget hides tools past a fixed size. The root `.mcp.json` is the
608
+ configuration Grok Build reads (with `${CLAUDE_PLUGIN_ROOT}`, the variable
609
+ both Grok Build and Claude Code expand); when working on this repository in
610
+ Claude Code, decline the project MCP server it offers from that file.
611
+
612
+ How a release is made is in [`RELEASING.md`](RELEASING.md).
613
+
614
+ ## License
615
+
616
+ [AGPL-3.0 with Commons Clause](LICENSE)
package/__init__.py ADDED
@@ -0,0 +1,36 @@
1
+ """Loads the plugin package from ``src/hermes/whatsapp_tools_hermes`` for Hermes, which imports this file.
2
+
3
+ The package is loaded as ``<this module's name>._impl``, so Hermes, which evicts
4
+ everything under a plugin's module name when it reloads it or loads it for another
5
+ profile, evicts the package too, and each install path gets a package of its own.
6
+ """
7
+
8
+ import importlib.util
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ _NAME = f"{__name__}._impl"
13
+ _PACKAGE_DIR = Path(__file__).resolve().parent / "src" / "hermes" / "whatsapp_tools_hermes"
14
+
15
+
16
+ def _evict() -> None:
17
+ """Drop the package and its submodules from ``sys.modules``."""
18
+ for name in list(sys.modules):
19
+ if name == _NAME or name.startswith(f"{_NAME}."):
20
+ sys.modules.pop(name, None)
21
+
22
+
23
+ _spec = importlib.util.spec_from_file_location(
24
+ _NAME, _PACKAGE_DIR / "__init__.py", submodule_search_locations=[str(_PACKAGE_DIR)]
25
+ )
26
+ _module = importlib.util.module_from_spec(_spec)
27
+ _evict()
28
+ sys.modules[_NAME] = _module
29
+ try:
30
+ _spec.loader.exec_module(_module)
31
+ except BaseException:
32
+ _evict()
33
+ raise
34
+
35
+ register = _module.register
36
+ __all__ = ["register"]