Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(chunker): add table awareness and increase Telegram chunk limit
Naiyuan Qing30e90410845a
diff --git a/src/channels/plugins/telegram.ts b/src/channels/plugins/telegram.tsindex b9a38ce687..a07512b42b 100644--- a/src/channels/plugins/telegram.ts+++ b/src/channels/plugins/telegram.ts@@ -4,6 +4,9 @@* Uses grammy to connect to Telegram Bot API via long polling.* - Private chats: all messages are processed* - Group chats: only messages that @mention the bot or reply to the bot+ *+ * @see docs/channels/README.md — Channel system overview+ * @see docs/channels/media-handling.md — Media processing pipeline*/import { writeFile, mkdir } from "node:fs/promises";@@ -53,6 +56,11 @@ export const telegramChannel: ChannelPlugin = {name: "Telegram",description: "Telegram bot integration via long polling",},+ chunkerConfig: {+ minChars: 200,+ maxChars: 4000, // Telegram API limit: 4096; leave room for HTML formatting overhead+ breakPreference: "paragraph",+ },config: {listAccountIds(config: ChannelsConfig): string[] {diff --git a/src/hub/block-chunker.ts b/src/hub/block-chunker.tsindex 6daadad010..0595442ac1 100644--- a/src/hub/block-chunker.ts+++ b/src/hub/block-chunker.ts@@ -68,6 +68,36 @@ function isInsideFence(text: string, position: number): boolean {return detectFenceAt(text, position) !== null;}+/** A line that looks like a Markdown table row (starts with |) */+function isTableRow(line: string): boolean {+ return line.startsWith("|");+}++/**+ * Check if position falls between two Markdown table rows.+ * Prevents breaking a table in the middle — table rows lose their header+ * context when split across messages.+ */+function isInsideTable(text: string, position: number): boolean {+ // Find the last non-empty line before position+ let i = position - 1;+ while (i >= 0 && text[i] === "\n") i--;+ if (i < 0) return false;+ let lineStart = i;+ while (lineStart > 0 && text[lineStart - 1] !== "\n") lineStart--;+ const prevLine = text.slice(lineStart, i + 1).trim();++ // Find the first non-empty line at/after position+ let j = position;+ while (j < text.length && text[j] === "\n") j++;+ if (j >= text.length) return false;+ let lineEnd = j;+ while (lineEnd < text.length && text[lineEnd] !== "\n") lineEnd++;+ const nextLine = text.slice(j, lineEnd).trim();++ return isTableRow(prevLine) && isTableRow(nextLine);+}+/*** If a chunk ends inside an open fence, close it in the chunk* and reopen it in the remainder.@@ -152,7 +182,7 @@ export class BlockChunker {for (const breaker of breakers) {const index = breaker(buffer, searchStart, searchEnd, bufLen);- if (index !== -1 && !isInsideFence(buffer, index)) {+ if (index !== -1 && !isInsideFence(buffer, index) && !isInsideTable(buffer, index)) {return index;}}