@gonzih/cc-discord 0.2.42 → 0.2.44

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.
@@ -223,53 +223,24 @@ function wireStdoutToRedis(proc, ns, wire) {
223
223
  result: resultText,
224
224
  is_error: parsed.is_error ?? false,
225
225
  };
226
- if (resultText && !parsed.is_error) {
227
- const msg = {
228
- id: crypto.randomUUID(),
229
- source: "claude",
230
- role: "assistant",
231
- content: resultText,
232
- timestamp: new Date().toISOString(),
233
- chatId: 0,
234
- };
235
- // Publish text first (logs to chat history), then signal done for immediate finalization
236
- wire.discord.publishOutgoing(ns, msg).then(() => {
237
- rawRedis.publish(discordChatOutgoing(ns), JSON.stringify({
238
- id: crypto.randomUUID(), source: "claude", role: "assistant",
239
- content: "", event: "done", timestamp: new Date().toISOString(), chatId: 0,
240
- })).catch(() => { });
241
- }).catch((err) => {
242
- console.warn(`[meta-agent-manager] publishOutgoing (result) failed (ns=${ns}):`, err.message);
243
- // Still signal done even if text publish failed
244
- rawRedis.publish(discordChatOutgoing(ns), JSON.stringify({
245
- id: crypto.randomUUID(), source: "claude", role: "assistant",
246
- content: "", event: "done", timestamp: new Date().toISOString(), chatId: 0,
247
- })).catch(() => { });
248
- });
249
- }
250
- else if (parsed.is_error) {
251
- // Error result: publish error text and signal done
226
+ if (parsed.is_error && resultText) {
227
+ // Error case: assistant event may not carry the error message — publish it directly
252
228
  const errMsg = {
253
229
  id: crypto.randomUUID(),
254
230
  source: "claude",
255
231
  role: "assistant",
256
- content: `⚠️ Error: ${resultText || "unknown error"}`,
232
+ content: `⚠️ Error: ${resultText}`,
257
233
  timestamp: new Date().toISOString(),
258
234
  chatId: 0,
259
235
  };
260
236
  wire.discord.publishOutgoing(ns, errMsg).catch(() => { });
261
- rawRedis.publish(discordChatOutgoing(ns), JSON.stringify({
262
- id: crypto.randomUUID(), source: "claude", role: "assistant",
263
- content: "", event: "done", timestamp: new Date().toISOString(), chatId: 0,
264
- })).catch(() => { });
265
- }
266
- else {
267
- // Empty result — just signal done
268
- rawRedis.publish(discordChatOutgoing(ns), JSON.stringify({
269
- id: crypto.randomUUID(), source: "claude", role: "assistant",
270
- content: "", event: "done", timestamp: new Date().toISOString(), chatId: 0,
271
- })).catch(() => { });
272
237
  }
238
+ // Signal turn completion — text was already published via the assistant event above.
239
+ // Do NOT re-publish resultText here: that would double-deliver the same content.
240
+ rawRedis.publish(discordChatOutgoing(ns), JSON.stringify({
241
+ id: crypto.randomUUID(), source: "claude", role: "assistant",
242
+ content: "", event: "done", timestamp: new Date().toISOString(), chatId: 0,
243
+ })).catch(() => { });
273
244
  }
274
245
  else {
275
246
  structuredEvent = parsed;
@@ -551,13 +522,19 @@ export function createMetaAgentManager() {
551
522
  return; // already running
552
523
  wireRef = wire;
553
524
  startWatchdog();
525
+ // Grace period: don't run stale-instance check until 20s after startup.
526
+ // The instance key write (in index.ts "ready" handler) is async — if the poll
527
+ // loop fires before that write completes, this instance sees the OLD key,
528
+ // incorrectly thinks it's stale, and self-destructs (SIGTERM to all sessions).
529
+ const pollStartTime = Date.now();
530
+ const STALE_CHECK_GRACE_MS = 20_000;
554
531
  pollInterval = setInterval(() => {
555
532
  const namespaces = getNamespaces();
556
533
  if (namespaces.length === 0)
557
534
  return;
558
535
  for (const { namespace: ns, repoUrl } of namespaces) {
559
- // Stale-instance check
560
- if (instanceId) {
536
+ // Stale-instance check — skip during grace period
537
+ if (instanceId && Date.now() - pollStartTime > STALE_CHECK_GRACE_MS) {
561
538
  wire._redis.get(DISCORD_INSTANCE_KEY).then((current) => {
562
539
  if (current && current !== instanceId) {
563
540
  console.log(`[meta-agent-manager] stale instance detected (current=${current}, ours=${instanceId}) — exiting`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-discord",
3
- "version": "0.2.42",
3
+ "version": "0.2.44",
4
4
  "description": "Claude Code Discord bot — chat with Claude Code via Discord",
5
5
  "type": "module",
6
6
  "bin": {