diff --git a/src/main/database/activity.ts b/src/main/database/activity.ts index 22d286f7..2a8239ca 100644 --- a/src/main/database/activity.ts +++ b/src/main/database/activity.ts @@ -1,6 +1,7 @@ import { randomUUID } from "node:crypto"; import type { DatabaseSync } from "node:sqlite"; import type { CommentRecord } from "@shared/types"; +import { normalizeMarkdownText } from "@shared/markdown-text"; import type { ReadAll } from "./helpers"; import { nowIso } from "./helpers"; @@ -19,12 +20,13 @@ export function buildActivityMethods( const taskRow = getDb().prepare("select company_id from tasks where id = ?").get(input.taskId) as { company_id: string } | undefined; if (!taskRow) throw new Error("Task not found."); if (taskRow.company_id !== input.companyId) throw new Error("Task does not belong to this company."); + const body = normalizeMarkdownText(input.body); const id = randomUUID(); const ts = nowIso(); getDb().prepare( "insert into task_comments (id, company_id, task_id, author_agent_id, author_name, body, created_at) values (?, ?, ?, ?, ?, ?, ?)", - ).run(id, input.companyId, input.taskId, input.authorAgentId, input.authorName, input.body, ts); - return { id, companyId: input.companyId, taskId: input.taskId, authorAgentId: input.authorAgentId, authorName: input.authorName, body: input.body, createdAt: ts }; + ).run(id, input.companyId, input.taskId, input.authorAgentId, input.authorName, body, ts); + return { id, companyId: input.companyId, taskId: input.taskId, authorAgentId: input.authorAgentId, authorName: input.authorName, body, createdAt: ts }; }, listComments(taskId: string): CommentRecord[] { diff --git a/src/main/database/messages.ts b/src/main/database/messages.ts index 73243bcb..f17606d7 100644 --- a/src/main/database/messages.ts +++ b/src/main/database/messages.ts @@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto"; import type { DatabaseSync, SQLInputValue } from "node:sqlite"; import log from "electron-log/main.js"; import type { AgentMessageRecord, AgentRecord } from "@shared/types"; +import { normalizeMarkdownText } from "@shared/markdown-text"; import { BOARD_READER_ID, type ReadAll, @@ -66,6 +67,7 @@ export function buildMessageMethods( } const senderKind = input.senderKind ?? (input.fromAgentId === BOARD_READER_ID ? "human" : "agent"); + const body = normalizeMarkdownText(input.body); const id = randomUUID(); const createdAt = nowIso(); // Single transaction: the row and its mention fan-out must land @@ -86,7 +88,7 @@ export function buildMessageMethods( channel, input.channelTargetId ?? null, input.subject, - input.body, + body, input.priority ?? "normal", input.parentMessageId ?? null, input.attachmentsJson ?? "[]", diff --git a/src/main/messaging/dispatch.ts b/src/main/messaging/dispatch.ts index e637d8ed..6db68932 100644 --- a/src/main/messaging/dispatch.ts +++ b/src/main/messaging/dispatch.ts @@ -1,5 +1,6 @@ import type { AppDatabase } from "../database"; import type { AgentMessageRecord, DesktopEvent, MessageChannel, MentionResult, SectionId } from "@shared/types"; +import { normalizeMarkdownText } from "@shared/markdown-text"; /** * The board reader / human participant ID. @@ -120,7 +121,7 @@ export function normalizeAgentMessageInput(input: AgentMessageDispatchInput): No channel, channelTargetId, subject, - body: input.body, + body: normalizeMarkdownText(input.body), priority, parentMessageId, threadId, diff --git a/src/renderer/components/communication/SearchResults.tsx b/src/renderer/components/communication/SearchResults.tsx index 46606b7b..22519e0d 100644 --- a/src/renderer/components/communication/SearchResults.tsx +++ b/src/renderer/components/communication/SearchResults.tsx @@ -8,6 +8,7 @@ import { formatMessageTime } from "../../lib/formatters" import { EmptyState, useReducedMotion } from "../ui" import { useRovingTabIndex } from "../../lib/keyboard" import { useT } from "../../i18n" +import { normalizeMarkdownText } from "@shared/markdown-text" type ChannelConfig = { labelKey: string; icon: React.ElementType; color: string } @@ -121,6 +122,7 @@ export function SearchResults({ results, query, loading, agents, onNavigateToRes const message = results[virtualRow.index] const agent = agentMap.get(message.fromAgentId) const config = channelConfig[message.channel] + const normalizedBody = normalizeMarkdownText(message.body) const ChannelIcon = config.icon return ( @@ -175,7 +177,7 @@ export function SearchResults({ results, query, loading, agents, onNavigateToRes {/* Row 3: Body snippet */}
{event.body}
+