@wahooks/channel 2.2.1 → 2.3.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 (2) hide show
  1. package/dist/index.js +3 -90
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -164,35 +164,6 @@ let claudeConnected = false;
164
164
  const WAHOOKS_DIR = path.join(os.homedir(), ".wahooks");
165
165
  const REMINDERS_FILE = path.join(WAHOOKS_DIR, "reminders.json");
166
166
  const PENDING_FILE = path.join(WAHOOKS_DIR, "pending.json");
167
- const LOCK_FILE = path.join(WAHOOKS_DIR, ".pending.lock");
168
- function acquireLock() {
169
- try {
170
- fs.writeFileSync(LOCK_FILE, String(process.pid), { flag: "wx" });
171
- return true;
172
- }
173
- catch {
174
- try {
175
- const pid = parseInt(fs.readFileSync(LOCK_FILE, "utf-8"));
176
- try {
177
- process.kill(pid, 0);
178
- return false;
179
- }
180
- catch {
181
- fs.writeFileSync(LOCK_FILE, String(process.pid));
182
- return true;
183
- }
184
- }
185
- catch {
186
- return false;
187
- }
188
- }
189
- }
190
- function releaseLock() {
191
- try {
192
- fs.unlinkSync(LOCK_FILE);
193
- }
194
- catch { }
195
- }
196
167
  function readReminders() {
197
168
  try {
198
169
  return JSON.parse(fs.readFileSync(REMINDERS_FILE, "utf-8"));
@@ -205,58 +176,6 @@ function writeReminders(reminders) {
205
176
  fs.mkdirSync(WAHOOKS_DIR, { recursive: true });
206
177
  fs.writeFileSync(REMINDERS_FILE, JSON.stringify(reminders, null, 2) + "\n", { mode: 0o600 });
207
178
  }
208
- function readPending() {
209
- try {
210
- return JSON.parse(fs.readFileSync(PENDING_FILE, "utf-8"));
211
- }
212
- catch {
213
- return [];
214
- }
215
- }
216
- function writePending(items) {
217
- fs.mkdirSync(WAHOOKS_DIR, { recursive: true });
218
- fs.writeFileSync(PENDING_FILE, JSON.stringify(items, null, 2) + "\n", { mode: 0o600 });
219
- }
220
- async function processPendingQueue() {
221
- if (!claudeConnected)
222
- return;
223
- if (!acquireLock())
224
- return;
225
- try {
226
- const pending = readPending();
227
- if (pending.length === 0)
228
- return;
229
- // Prune stale items (>24h)
230
- const cutoff = new Date(Date.now() - 24 * 60 * 60 * 1000);
231
- const active = pending.filter((p) => new Date(p.addedAt) > cutoff);
232
- for (const item of active) {
233
- try {
234
- console.error(`[wahooks-channel] Sending reminder ${item.reminderId} to Claude...`);
235
- await mcp.notification({
236
- method: "notifications/claude/channel",
237
- params: {
238
- content: `[Scheduled Reminder] ${item.task}\n\nTarget chat: ${item.chatId}\nScheduled for: ${item.scheduledFor}\n\nPlease execute this task now and send the results to the target chat using wahooks_reply.`,
239
- meta: {
240
- from: item.chatId,
241
- reminder_id: item.reminderId,
242
- },
243
- },
244
- });
245
- console.error(`[wahooks-channel] Delivered reminder ${item.reminderId}`);
246
- }
247
- catch (err) {
248
- claudeConnected = false;
249
- console.error(`[wahooks-channel] Claude disconnected during reminder delivery: ${err}`);
250
- return; // stop processing, items stay in queue
251
- }
252
- }
253
- // All delivered — clear the queue
254
- writePending([]);
255
- }
256
- finally {
257
- releaseLock();
258
- }
259
- }
260
179
  // ─── MCP Server ─────────────────────────────────────────────────────────
261
180
  const mcp = new Server({ name: "wahooks-channel", version: "0.1.0" }, {
262
181
  capabilities: {
@@ -723,7 +642,8 @@ async function main() {
723
642
  const transport = new StdioServerTransport();
724
643
  transport.onclose = () => {
725
644
  claudeConnected = false;
726
- console.error("[wahooks-channel] Claude disconnected");
645
+ console.error("[wahooks-channel] Claude disconnected — exiting");
646
+ process.exit(0);
727
647
  };
728
648
  await mcp.connect(transport);
729
649
  claudeConnected = true;
@@ -754,15 +674,11 @@ async function main() {
754
674
  fs.writeFileSync(PENDING_FILE, "[]", { mode: 0o600 });
755
675
  return;
756
676
  }
757
- const debugLog = path.join(WAHOOKS_DIR, "channel-debug.log");
758
- const log = (msg) => fs.appendFileSync(debugLog, `${new Date().toISOString()} ${msg}\n`);
759
- log(`Found ${active.length} pending, claudeConnected=${claudeConnected}`);
760
677
  console.error(`[wahooks-channel] Found ${active.length} pending reminder(s), delivering...`);
761
678
  for (const item of active) {
762
- log(`Delivering: ${item.reminderId}`);
763
679
  console.error(`[wahooks-channel] Delivering: ${item.reminderId}`);
764
680
  try {
765
- const result = await mcp.notification({
681
+ await mcp.notification({
766
682
  method: "notifications/claude/channel",
767
683
  params: {
768
684
  content: `[Scheduled Reminder] ${item.task}\n\nTarget chat: ${item.chatId}\nScheduled for: ${item.scheduledFor}\n\nPlease execute this task now and send the results to the target chat using wahooks_reply.`,
@@ -772,11 +688,9 @@ async function main() {
772
688
  },
773
689
  },
774
690
  });
775
- log(`Delivered: ${item.reminderId}, result=${JSON.stringify(result)}`);
776
691
  console.error(`[wahooks-channel] Delivered: ${item.reminderId}`);
777
692
  }
778
693
  catch (err) {
779
- log(`FAILED: ${item.reminderId}, error=${err}`);
780
694
  console.error(`[wahooks-channel] Delivery failed: ${err}`);
781
695
  claudeConnected = false;
782
696
  return;
@@ -784,7 +698,6 @@ async function main() {
784
698
  }
785
699
  // Clear queue after all delivered
786
700
  fs.writeFileSync(PENDING_FILE, "[]", { mode: 0o600 });
787
- log("Queue cleared");
788
701
  }
789
702
  // Poll every 10s
790
703
  setInterval(pollPending, 10_000);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wahooks/channel",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "WhatsApp channel for Claude Code — chat with Claude via WhatsApp",
5
5
  "type": "module",
6
6
  "bin": {