diff --git a/server/routes/agent-chat.js b/server/routes/agent-chat.js
index c21efbe..5126354 100644
--- a/server/routes/agent-chat.js
+++ b/server/routes/agent-chat.js
@@ -921,12 +921,15 @@ router.post('/task/dispatch', async (req, res) => {
const taskId = `T-${Date.now().toString(36)}`;
const now = new Date().toISOString().slice(0, 16).replace('T', ' ');
+ // 净化多行文本和竖线,防止破坏 Markdown 表格格式
+ const safeTask = task.replace(/\n/g, '
').replace(/\|/g, '|');
+
// 1. 写入目标 Agent 的 todo.md
const todoPath = path.join(targetDir, 'todo.md');
let todoContent = fs.existsSync(todoPath) ? fs.readFileSync(todoPath, 'utf-8') : '';
// 移除空占位行
todoContent = todoContent.replace(/\| *\| *(暂无待办).*\n?/g, '');
- const newTodoRow = `| ${taskId} | ${task} | ⬚ 未开始 | ${from} | ${priority} | ${now} | - |\n`;
+ const newTodoRow = `| ${taskId} | ${safeTask} | ⬚ 未开始 | ${from} | ${priority} | ${now} | - |\n`;
todoContent = todoContent.trimEnd() + '\n' + newTodoRow;
fs.writeFileSync(todoPath, todoContent, 'utf-8');
@@ -935,7 +938,7 @@ router.post('/task/dispatch', async (req, res) => {
const planPath = path.join(senderDir, 'plan.md');
let planContent = fs.existsSync(planPath) ? fs.readFileSync(planPath, 'utf-8') : '';
planContent = planContent.replace(/\| *\| *(暂无计划).*\n?/g, '');
- const newPlanRow = `| ${planId} | ${task} | ${to} | 🔄 已分发 | ${now} | taskId: ${taskId} |\n`;
+ const newPlanRow = `| ${planId} | ${safeTask} | ${to} | 🔄 已分发 | ${now} | taskId: ${taskId} |\n`;
planContent = planContent.trimEnd() + '\n' + newPlanRow;
fs.writeFileSync(planPath, planContent, 'utf-8');
}
@@ -1028,6 +1031,7 @@ router.post('/task/report', (req, res) => {
const now = new Date().toISOString().slice(0, 16).replace('T', ' ');
const statusEmoji = status === 'done' ? '✅ 完成' : status === 'failed' ? '❌ 失败' : '⏸ 阻塞';
+ const safeSummary = (summary || '').replace(/\n/g, '
').replace(/\|/g, '|');
// 1. 更新执行者的 todo.md (标记完成)
const executorDir = path.join(DATA_DIR, from);
@@ -1063,8 +1067,8 @@ router.post('/task/report', (req, res) => {
// cells: ['', '#', '子任务', '责任人', '状态', '上次检查', '备注', '']
cells[4] = ` ${statusEmoji} `;
cells[5] = ` ${now} `;
- if (summary && cells.length >= 7) {
- cells[6] = ` ${summary} `;
+ if (safeSummary && cells.length >= 7) {
+ cells[6] = ` ${safeSummary} `;
}
lines[i] = cells.join(' | ').replace(/\*\*/g, ''); // 去掉粗体
updated = true;