beecork 1.3.9 → 1.3.11

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.
@@ -23,22 +23,6 @@ export async function startDaemon() {
23
23
  console.log(`Beecork daemon is already running (PID: ${existingPid})`);
24
24
  return;
25
25
  }
26
- // Check if WhatsApp needs pairing
27
- const config = getConfig();
28
- const waSessionPath = config.whatsapp?.sessionPath ?? `${process.env.HOME}/.beecork/whatsapp-session`;
29
- const waEnabled = config.whatsapp?.enabled;
30
- const waHasSession = waEnabled && fs.existsSync(waSessionPath) && fs.readdirSync(waSessionPath).length > 0;
31
- if (waEnabled && !waHasSession) {
32
- console.log('\n⚠ WhatsApp is enabled but not yet paired.');
33
- console.log(' Starting daemon in foreground so you can scan the QR code...');
34
- console.log(' Once paired, press Ctrl+C and run "beecork start" again.\n');
35
- const daemonPath = new URL('../daemon.js', import.meta.url).pathname;
36
- const child = spawn('node', [daemonPath], {
37
- stdio: 'inherit',
38
- });
39
- process.on('SIGINT', () => { child.kill(); process.exit(0); });
40
- return;
41
- }
42
26
  try {
43
27
  startService();
44
28
  console.log('Beecork daemon started via system service.');
package/dist/index.js CHANGED
@@ -135,7 +135,7 @@ channelCmd
135
135
  });
136
136
  program
137
137
  .command('discord')
138
- .description('Configure Discord channel')
138
+ .description('Set up Discord — interactive setup for bot token and user ID')
139
139
  .action(async () => {
140
140
  const readline = await import('node:readline');
141
141
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
@@ -163,15 +163,16 @@ program
163
163
  });
164
164
  program
165
165
  .command('whatsapp')
166
- .description('Configure WhatsApp channel')
166
+ .description('Set up WhatsApp — enter phone number, then scan QR code to pair')
167
167
  .action(async () => {
168
168
  const readline = await import('node:readline');
169
+ const fs = await import('node:fs');
169
170
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
170
171
  const ask = (q, def) => new Promise(r => rl.question(def ? `${q} [${def}]: ` : `${q}: `, a => r(a.trim() || def || '')));
171
172
  console.log('\nWhatsApp Setup\n');
172
173
  console.log(' WhatsApp connects via QR code scanning (like WhatsApp Web).');
173
- console.log(' After setup, run "beecork start" and the QR code will appear');
174
- console.log(' in your terminal. Scan it with your phone to pair.\n');
174
+ console.log(' After entering your phone number, a QR code will appear.');
175
+ console.log(' Scan it with your phone to pair.\n');
175
176
  const number = await ask('Your WhatsApp phone number (e.g., 14155551234)');
176
177
  if (!number) {
177
178
  console.log('No number provided. Cancelled.');
@@ -181,22 +182,53 @@ program
181
182
  const { getConfig, saveConfig } = await import('./config.js');
182
183
  const { getBeecorkHome } = await import('./util/paths.js');
183
184
  const config = getConfig();
185
+ const sessionPath = `${getBeecorkHome()}/whatsapp-session`;
184
186
  config.whatsapp = {
185
187
  enabled: true,
186
188
  mode: 'baileys',
187
- sessionPath: `${getBeecorkHome()}/whatsapp-session`,
189
+ sessionPath,
188
190
  allowedNumbers: [number],
189
191
  };
190
192
  saveConfig(config);
191
- console.log('\n✓ WhatsApp configured.');
192
- console.log(' Next: run "beecork start" — the QR code will appear in your terminal.');
193
- console.log(' Scan it with your phone to pair. Once paired, press Ctrl+C and');
194
- console.log(' run "beecork start" again for background operation.\n');
193
+ console.log('\n✓ Config saved. Connecting to WhatsApp...\n');
195
194
  rl.close();
195
+ // Pair immediately — show QR code in this terminal
196
+ try {
197
+ const { default: makeWASocket, useMultiFileAuthState, DisconnectReason } = await import('@whiskeysockets/baileys');
198
+ fs.mkdirSync(sessionPath, { recursive: true, mode: 0o700 });
199
+ const { state, saveCreds } = await useMultiFileAuthState(sessionPath);
200
+ const sock = makeWASocket({
201
+ auth: state,
202
+ printQRInTerminal: true,
203
+ });
204
+ sock.ev.on('creds.update', saveCreds);
205
+ sock.ev.on('connection.update', (update) => {
206
+ if (update.connection === 'open') {
207
+ console.log('\n✓ WhatsApp paired successfully!');
208
+ console.log(' You can now start the daemon: beecork start\n');
209
+ sock.end(undefined);
210
+ process.exit(0);
211
+ }
212
+ if (update.connection === 'close') {
213
+ const reason = update.lastDisconnect?.error?.output?.statusCode;
214
+ if (reason === DisconnectReason.loggedOut) {
215
+ console.log('\n✗ WhatsApp logged out. Please try again.\n');
216
+ process.exit(1);
217
+ }
218
+ }
219
+ });
220
+ console.log('Scan the QR code above with your phone (WhatsApp → Linked Devices → Link a Device)');
221
+ console.log('Waiting for pairing... (Ctrl+C to cancel)\n');
222
+ }
223
+ catch (err) {
224
+ console.error('Failed to connect to WhatsApp:', err instanceof Error ? err.message : err);
225
+ console.log('\nConfig is saved. You can try pairing later by running: beecork whatsapp');
226
+ process.exit(1);
227
+ }
196
228
  });
197
229
  program
198
230
  .command('webhook')
199
- .description('Configure Webhook channel')
231
+ .description('Set up Webhook — enable HTTP API for triggering Beecork from any service')
200
232
  .action(async () => {
201
233
  const readline = await import('node:readline');
202
234
  const crypto = await import('node:crypto');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beecork",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "description": "Claude Code always-on infrastructure — a phone number, a memory, and an alarm clock",
5
5
  "type": "module",
6
6
  "bin": {