@gonzih/cc-discord 0.2.44 → 0.2.46

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.
@@ -155,6 +155,8 @@ function wireStdoutToRedis(proc, ns, wire) {
155
155
  const rawRedis = wire._redis;
156
156
  const streamCh = metaStreamChannel(ns);
157
157
  const logKey = metaLogKey(ns);
158
+ // Deduplicate rate_limit_event: Claude emits multiple per turn; only notify once per session.
159
+ let rateLimitNotified = false;
158
160
  const forwardEventToRedis = (eventJson) => {
159
161
  rawRedis.publish(streamCh, eventJson).catch((err) => {
160
162
  console.warn(`[meta-agent-manager] stream publish failed (ns=${ns}):`, err.message);
@@ -242,6 +244,38 @@ function wireStdoutToRedis(proc, ns, wire) {
242
244
  content: "", event: "done", timestamp: new Date().toISOString(), chatId: 0,
243
245
  })).catch(() => { });
244
246
  }
247
+ else if (type === "rate_limit_event") {
248
+ const rl = parsed.rate_limit_info;
249
+ structuredEvent = parsed;
250
+ // Throttled: five-hour window exhausted and no overage credits.
251
+ // Claude emits multiple rate_limit_events per turn — only act on the first.
252
+ if (rl?.overageStatus === "rejected" && !rateLimitNotified) {
253
+ rateLimitNotified = true;
254
+ const resetsAt = rl.resetsAt ? new Date(rl.resetsAt * 1000).toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit", timeZoneName: "short" }) : "soon";
255
+ const alertMsg = {
256
+ id: crypto.randomUUID(),
257
+ source: "claude",
258
+ role: "assistant",
259
+ content: `⏳ Rate limited — five-hour window exhausted. Resets at **${resetsAt}**. Session paused; send any message after reset to resume.`,
260
+ timestamp: new Date().toISOString(),
261
+ chatId: 0,
262
+ };
263
+ wire.discord.publishOutgoing(ns, alertMsg).catch(() => { });
264
+ // Fire done so notifier finalizes the live message
265
+ rawRedis.publish(discordChatOutgoing(ns), JSON.stringify({
266
+ id: crypto.randomUUID(), source: "claude", role: "assistant",
267
+ content: "", event: "done", timestamp: new Date().toISOString(), chatId: 0,
268
+ })).catch(() => { });
269
+ // Kill the process — API calls will hang until reset anyway
270
+ setTimeout(() => {
271
+ try {
272
+ proc.stdin.end();
273
+ proc.kill("SIGTERM");
274
+ }
275
+ catch { /* ignore */ }
276
+ }, 500);
277
+ }
278
+ }
245
279
  else {
246
280
  structuredEvent = parsed;
247
281
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-discord",
3
- "version": "0.2.44",
3
+ "version": "0.2.46",
4
4
  "description": "Claude Code Discord bot — chat with Claude Code via Discord",
5
5
  "type": "module",
6
6
  "bin": {