@gonzih/cc-discord 0.2.8 → 0.2.9
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.
- package/dist/bot.d.ts +6 -0
- package/dist/bot.js +65 -1
- package/dist/notifier.js +2 -2
- package/package.json +1 -1
package/dist/bot.d.ts
CHANGED
|
@@ -66,6 +66,12 @@ export declare class CcDiscordBot {
|
|
|
66
66
|
private sendToChannel;
|
|
67
67
|
/** Send to a channel by ID — used by notifier callbacks. */
|
|
68
68
|
sendToChannelById(channelId: string, text: string): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Send text to a channel by ID, scanning for absolute file paths and attaching them.
|
|
71
|
+
* Used exclusively for Claude coordinator output (meta-agent flush).
|
|
72
|
+
* Falls back to plain text send if no valid files are found.
|
|
73
|
+
*/
|
|
74
|
+
sendWithFileDetection(channelId: string, text: string): Promise<void>;
|
|
69
75
|
private isAllowed;
|
|
70
76
|
private handleMessage;
|
|
71
77
|
private handleVoice;
|
package/dist/bot.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* One ClaudeProcess per channel (or channel:thread) — sessions are isolated per channel.
|
|
4
4
|
*/
|
|
5
5
|
import { Client, GatewayIntentBits, REST, Routes, SlashCommandBuilder, EmbedBuilder, AttachmentBuilder, Events, ChannelType, } from "discord.js";
|
|
6
|
-
import { existsSync, createWriteStream, mkdirSync } from "fs";
|
|
6
|
+
import { existsSync, createWriteStream, mkdirSync, statSync } from "fs";
|
|
7
7
|
import { resolve, basename, join } from "path";
|
|
8
8
|
import https from "https";
|
|
9
9
|
import http from "http";
|
|
@@ -301,6 +301,70 @@ export class CcDiscordBot {
|
|
|
301
301
|
}
|
|
302
302
|
await this.sendToChannel(channel, text);
|
|
303
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Send text to a channel by ID, scanning for absolute file paths and attaching them.
|
|
306
|
+
* Used exclusively for Claude coordinator output (meta-agent flush).
|
|
307
|
+
* Falls back to plain text send if no valid files are found.
|
|
308
|
+
*/
|
|
309
|
+
async sendWithFileDetection(channelId, text) {
|
|
310
|
+
const channel = await this.getChannel(channelId);
|
|
311
|
+
if (!channel) {
|
|
312
|
+
console.warn(`[bot] sendWithFileDetection: channel ${channelId} not found`);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
// Extract absolute paths from text — handle bare paths and backtick-wrapped paths
|
|
316
|
+
const rawMatches = text.match(/`(\/[^`\s]+)`|\/[^\s`'"]+/g) ?? [];
|
|
317
|
+
const candidates = rawMatches.map((m) => m.replace(/^`|`$/g, ""));
|
|
318
|
+
const MAX_SIZE = 8 * 1024 * 1024;
|
|
319
|
+
const validPaths = [];
|
|
320
|
+
const seen = new Set();
|
|
321
|
+
for (const candidate of candidates) {
|
|
322
|
+
// Strip trailing punctuation that may have been caught by the regex
|
|
323
|
+
const p = candidate.replace(/[.,;:!?)]+$/, "");
|
|
324
|
+
if (seen.has(p))
|
|
325
|
+
continue;
|
|
326
|
+
seen.add(p);
|
|
327
|
+
try {
|
|
328
|
+
if (existsSync(p)) {
|
|
329
|
+
const st = statSync(p);
|
|
330
|
+
if (st.isFile() && st.size < MAX_SIZE) {
|
|
331
|
+
validPaths.push(p);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
// ignore stat errors
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (validPaths.length > 0) {
|
|
340
|
+
const formatted = formatForDiscord(text);
|
|
341
|
+
const chunks = splitLongMessage(formatted);
|
|
342
|
+
// Send first chunk with file attachments, remaining chunks as plain text
|
|
343
|
+
const files = validPaths.map((p) => ({ attachment: p, name: basename(p) }));
|
|
344
|
+
try {
|
|
345
|
+
await channel.send({ content: chunks[0] || undefined, files });
|
|
346
|
+
}
|
|
347
|
+
catch (err) {
|
|
348
|
+
console.warn(`[bot] sendWithFileDetection attach failed:`, err.message);
|
|
349
|
+
// Fall back to plain text for the first chunk
|
|
350
|
+
if (chunks[0]?.trim()) {
|
|
351
|
+
await channel.send(chunks[0]).catch((e) => {
|
|
352
|
+
console.error("[bot] sendWithFileDetection fallback failed:", e.message);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
for (const chunk of chunks.slice(1)) {
|
|
357
|
+
if (!chunk.trim())
|
|
358
|
+
continue;
|
|
359
|
+
await channel.send(chunk).catch((e) => {
|
|
360
|
+
console.error("[bot] send failed:", e.message);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
await this.sendToChannel(channel, text);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
304
368
|
isAllowed(userId) {
|
|
305
369
|
if (!this.opts.allowedUserIds?.length)
|
|
306
370
|
return true;
|
package/dist/notifier.js
CHANGED
|
@@ -214,8 +214,8 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
|
|
|
214
214
|
const deliverTo = bot.getLoopThreadId(targetChannelId) ?? targetChannelId;
|
|
215
215
|
const chunks = splitLongMessage(text);
|
|
216
216
|
for (const chunk of chunks) {
|
|
217
|
-
bot.
|
|
218
|
-
log("warn", `meta-agent flush
|
|
217
|
+
bot.sendWithFileDetection(deliverTo, chunk).catch((err) => {
|
|
218
|
+
log("warn", `meta-agent flush sendWithFileDetection failed (ns=${ns}):`, err.message);
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
}
|