replywizard-whatsapp-mcp 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replywizard-whatsapp-mcp",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Local MCP server that exposes WhatsApp Web (read + value tools) to AI clients via the Reply Wizard Chrome extension.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/protocol.js CHANGED
@@ -43,6 +43,7 @@ export const CONTROL = Object.freeze({
43
43
  PAIRING_REQUEST: 'pairing_request',
44
44
  PAIRING_RESPONSE: 'pairing_response',
45
45
  PAIRING_COMPLETE: 'pairing_complete',
46
+ PAIRING_FAILED: 'pairing_failed',
46
47
  AUTH_SUCCESS: 'auth_success',
47
48
  PING: 'ping',
48
49
  PONG: 'pong',
package/src/wsServer.js CHANGED
@@ -23,9 +23,10 @@
23
23
 
24
24
  import { WebSocketServer } from 'ws';
25
25
  import { randomBytes, randomUUID } from 'node:crypto';
26
- import { homedir } from 'node:os';
26
+ import { homedir, platform } from 'node:os';
27
27
  import { join } from 'node:path';
28
28
  import { mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
29
+ import { spawn } from 'node:child_process';
29
30
  import { CONTROL, DEFAULT_PORT, PROTOCOL_VERSION, VALUE_ACTIONS } from './protocol.js';
30
31
 
31
32
  const log = (...args) => console.error('[replywizard-mcp]', ...args);
@@ -57,6 +58,45 @@ function sixDigitCode() {
57
58
  return String(parseInt(randomBytes(4).toString('hex'), 16) % 1_000_000).padStart(6, '0');
58
59
  }
59
60
 
61
+ // Surface the pairing code as an OS desktop notification so a non-technical user
62
+ // sees it WITHOUT a terminal (the connector launches us in the background, where
63
+ // stderr is invisible). This is a valid out-of-band channel: only someone at the
64
+ // physical machine sees the toast, so it does not weaken pairing the way echoing
65
+ // the code over the (untrusted) extension socket would. Best-effort: never throws,
66
+ // never blocks (detached + unref + stdio ignore), silent if the tool is missing —
67
+ // the 0600 file and stderr remain as backstops. `code` is digits-only (no shell/
68
+ // AppleScript injection risk). Exported for tests.
69
+ export function notifyPairingCode(code) {
70
+ const title = 'Reply Wizard pairing code';
71
+ const body = `Enter ${code} in Reply Wizard (AI Assistants > MCP) to connect.`;
72
+ try {
73
+ let cmd, args;
74
+ const os = platform();
75
+ if (os === 'darwin') {
76
+ cmd = 'osascript';
77
+ args = ['-e', `display notification "${body}" with title "${title}"`];
78
+ } else if (os === 'win32') {
79
+ // PowerShell balloon via WinForms — no external module required.
80
+ const ps =
81
+ 'Add-Type -AssemblyName System.Windows.Forms;' +
82
+ '$n=New-Object System.Windows.Forms.NotifyIcon;' +
83
+ '$n.Icon=[System.Drawing.SystemIcons]::Information;' +
84
+ `$n.BalloonTipTitle=${JSON.stringify(title)};` +
85
+ `$n.BalloonTipText=${JSON.stringify(body)};` +
86
+ '$n.Visible=$true;$n.ShowBalloonTip(20000);Start-Sleep -Seconds 8;$n.Dispose()';
87
+ cmd = 'powershell';
88
+ args = ['-NoProfile', '-WindowStyle', 'Hidden', '-Command', ps];
89
+ } else {
90
+ // Linux / *nix: libnotify.
91
+ cmd = 'notify-send';
92
+ args = ['-u', 'normal', '-t', '30000', title, body];
93
+ }
94
+ const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
95
+ child.on('error', () => {}); // tool absent (e.g. no notify-send) — stay silent
96
+ child.unref();
97
+ } catch { /* notifications are best-effort */ }
98
+ }
99
+
60
100
  export class ExtensionBridge {
61
101
  constructor(opts = {}) {
62
102
  const { port = DEFAULT_PORT, host = '127.0.0.1' } = opts;
@@ -71,6 +111,8 @@ export class ExtensionBridge {
71
111
  this.requestTimeoutMs = opts.requestTimeoutMs ?? 25_000;
72
112
  this.listening = false;
73
113
  this.portConflict = false; // true if the port was already in use at startup
114
+ // Desktop-notification fn for the pairing code (injectable for tests).
115
+ this._notify = opts.notify ?? notifyPairingCode;
74
116
  // Concurrency scheduler (WS-A3): all client sessions multiplex onto the single
75
117
  // extension socket. Reads and value-actions run in INDEPENDENT lanes so a slow
76
118
  // value-action (transcribe/summarize/suggest → LLM/STT) never head-of-line-blocks
@@ -154,11 +196,13 @@ export class ExtensionBridge {
154
196
  } else {
155
197
  this.pairingCode = sixDigitCode();
156
198
  writePairingCode(this.pairingCode);
199
+ try { this._notify(this.pairingCode); } catch { /* notifier is best-effort */ }
157
200
  log('');
158
201
  log(' ┌──────────────────────────────────────────────┐');
159
202
  log(` │ Reply Wizard pairing code: ${this.pairingCode} │`);
160
203
  log(' └──────────────────────────────────────────────┘');
161
204
  log(' Enter it in Reply Wizard → popup → AI client access.');
205
+ log(' (A desktop notification with the code should also appear.)');
162
206
  log(` (Running in the background? Read it from ${pairingFile()})`);
163
207
  this._send({ method: CONTROL.PAIRING_REQUEST, params: { hub_name: 'Reply Wizard MCP', protocol: PROTOCOL_VERSION } });
164
208
  }
@@ -176,6 +220,10 @@ export class ExtensionBridge {
176
220
  this._send({ method: CONTROL.AUTH_SUCCESS, params: {} });
177
221
  log('Pairing approved.');
178
222
  } else {
223
+ // Tell the extension so it can show "incorrect code" instead of just
224
+ // silently staying on "Pairing needed". A rejected code keeps the same
225
+ // pairing code active so the user can retry without a new handshake.
226
+ this._send({ method: CONTROL.PAIRING_FAILED, params: { reason: 'invalid_code' } });
179
227
  log('Pairing rejected or wrong code.');
180
228
  }
181
229
  return;