beecork 1.4.4 → 1.4.6

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.
@@ -37,9 +37,11 @@ export class WhatsAppChannel {
37
37
  fs.mkdirSync(sessionPath, { recursive: true, mode: 0o700 });
38
38
  const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
39
39
  const { version } = await fetchLatestBaileysVersion().catch(() => ({ version: undefined }));
40
+ const pino = (await import('pino')).default;
40
41
  this.sock = makeWASocket({
41
42
  auth: state,
42
43
  version,
44
+ logger: pino({ level: 'silent' }),
43
45
  });
44
46
  const sock = this.sock;
45
47
  sock.ev.on('creds.update', saveCreds);
package/dist/index.js CHANGED
@@ -163,17 +163,48 @@ program
163
163
  });
164
164
  program
165
165
  .command('whatsapp')
166
- .description('Set up WhatsApp enter phone number, then scan QR code to pair')
167
- .action(async () => {
166
+ .description('Set up or disable WhatsApp')
167
+ .option('--disable', 'Disable WhatsApp and remove session')
168
+ .action(async (opts) => {
169
+ if (opts.disable) {
170
+ const { getConfig, saveConfig } = await import('./config.js');
171
+ const { getBeecorkHome } = await import('./util/paths.js');
172
+ const fs = await import('node:fs');
173
+ const config = getConfig();
174
+ if (config.whatsapp) {
175
+ config.whatsapp.enabled = false;
176
+ saveConfig(config);
177
+ }
178
+ // Remove session files
179
+ const sessionPath = `${getBeecorkHome()}/whatsapp-session`;
180
+ if (fs.existsSync(sessionPath)) {
181
+ fs.rmSync(sessionPath, { recursive: true, force: true });
182
+ }
183
+ console.log('✓ WhatsApp disabled and session removed.');
184
+ // Restart daemon if running
185
+ const { getDaemonPid } = await import('./cli/helpers.js');
186
+ if (getDaemonPid()) {
187
+ const { execSync } = await import('node:child_process');
188
+ try {
189
+ execSync('beecork stop', { stdio: 'ignore' });
190
+ execSync('beecork start', { stdio: 'ignore' });
191
+ console.log(' Daemon restarted.');
192
+ }
193
+ catch {
194
+ console.log(' Restart daemon: beecork stop && beecork start');
195
+ }
196
+ }
197
+ return;
198
+ }
168
199
  const readline = await import('node:readline');
169
200
  const fs = await import('node:fs');
170
201
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
171
202
  const ask = (q, def) => new Promise(r => rl.question(def ? `${q} [${def}]: ` : `${q}: `, a => r(a.trim() || def || '')));
172
203
  console.log('\nWhatsApp Setup\n');
173
- console.log(' WhatsApp connects via QR code scanning (like WhatsApp Web).');
174
- console.log(' After entering your phone number, a QR code will appear.');
175
- console.log(' Scan it with your phone to pair.\n');
176
- const number = await ask('Your WhatsApp phone number (e.g., 14155551234)');
204
+ console.log(' You need two WhatsApp accounts:');
205
+ console.log(' 1. A bot account (separate SIM) — will scan the QR code to pair');
206
+ console.log(' 2. Your personal number allowed to message the bot\n');
207
+ const number = await ask('Your personal WhatsApp number (the one that will message the bot, e.g., 14155551234)');
177
208
  if (!number) {
178
209
  console.log('No number provided. Cancelled.');
179
210
  rl.close();
@@ -195,32 +226,56 @@ program
195
226
  // Pair immediately — show QR code in this terminal
196
227
  try {
197
228
  const { default: makeWASocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion } = await import('@whiskeysockets/baileys');
229
+ const pino = (await import('pino')).default;
230
+ const silentLogger = pino({ level: 'silent' });
198
231
  fs.mkdirSync(sessionPath, { recursive: true, mode: 0o700 });
199
232
  let attempts = 0;
200
233
  const maxAttempts = 5;
234
+ let paired = false;
201
235
  const connect = async () => {
202
236
  attempts++;
203
237
  const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
204
238
  const { version } = await fetchLatestBaileysVersion().catch(() => ({ version: undefined }));
205
- const sock = makeWASocket({ auth: state, version });
239
+ const sock = makeWASocket({ auth: state, version, logger: silentLogger });
206
240
  sock.ev.on('creds.update', saveCreds);
207
241
  sock.ev.on('connection.update', async (update) => {
208
242
  if (update.qr) {
209
243
  try {
210
244
  const qrcodeTerminal = await import('qrcode-terminal');
211
245
  (qrcodeTerminal.default || qrcodeTerminal).generate(update.qr, { small: true });
246
+ console.log('Scan with the BOT phone (WhatsApp → Linked Devices → Link a Device)\n');
212
247
  }
213
248
  catch {
214
249
  console.log('QR data:', update.qr);
215
250
  }
216
251
  }
217
252
  if (update.connection === 'open') {
218
- console.log('\n✓ WhatsApp paired successfully!');
219
- console.log(' You can now start the daemon: beecork start\n');
253
+ paired = true;
254
+ console.log(' WhatsApp paired successfully!');
220
255
  sock.end(undefined);
256
+ // Auto-restart daemon
257
+ const { getDaemonPid } = await import('./cli/helpers.js');
258
+ const pid = getDaemonPid();
259
+ if (pid) {
260
+ console.log(' Restarting daemon with WhatsApp enabled...');
261
+ const { execSync } = await import('node:child_process');
262
+ try {
263
+ execSync('beecork stop', { stdio: 'ignore' });
264
+ execSync('beecork start', { stdio: 'ignore' });
265
+ console.log(' ✓ Daemon restarted.\n');
266
+ }
267
+ catch {
268
+ console.log(' Could not restart daemon. Run: beecork stop && beecork start\n');
269
+ }
270
+ }
271
+ else {
272
+ console.log(' Start the daemon: beecork start\n');
273
+ }
221
274
  process.exit(0);
222
275
  }
223
276
  if (update.connection === 'close') {
277
+ if (paired)
278
+ return; // Expected disconnect after pairing
224
279
  const reason = update.lastDisconnect?.error?.output?.statusCode;
225
280
  if (reason === DisconnectReason.loggedOut) {
226
281
  console.log('\n✗ WhatsApp logged out. Please try again.\n');
@@ -230,14 +285,12 @@ program
230
285
  console.log(`\n✗ Could not connect after ${maxAttempts} attempts. Please try again later.\n`);
231
286
  process.exit(1);
232
287
  }
233
- console.log(`Connection dropped, retrying (${attempts}/${maxAttempts})...`);
234
288
  setTimeout(connect, 3000);
235
289
  }
236
290
  });
237
291
  };
238
292
  await connect();
239
- console.log('Scan the QR code above with your phone (WhatsApp Linked Devices → Link a Device)');
240
- console.log('Waiting for pairing... (Ctrl+C to cancel)\n');
293
+ console.log('Waiting for QR code... (Ctrl+C to cancel)\n');
241
294
  }
242
295
  catch (err) {
243
296
  console.error('Failed to connect to WhatsApp:', err instanceof Error ? err.message : err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beecork",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "Claude Code always-on infrastructure — a phone number, a memory, and an alarm clock",
5
5
  "type": "module",
6
6
  "bin": {