From fcf12550edd1ae900bea3027fe17c711d12e44bb Mon Sep 17 00:00:00 2001 From: zavier <765324639@qq.com> Date: Fri, 14 Aug 2026 22:27:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E7=A7=BB=E9=99=A4=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E4=B8=8E=20schema=20=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=20markdown=20=E5=8A=A0=E7=B2=97=E6=A0=87?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 终端不渲染 markdown 加粗:`**` 在 db_query / db_tables 工具结果展开态 (tool-result-render 的 TruncatedMultiline 原文渲染)会以字面量显示, 且这些标记对 LLM 无信息量。从共享的 llm-zh 装配层移除: - formatting/result-document.ts:连接/数据库/SQL/行数标签去加粗 - formatting/schema-table.ts:索引标题去加粗 - 同步更新两个测试文件的断言 --- __tests__/result-document.test.ts | 10 +++++----- __tests__/schema-table.test.ts | 2 +- formatting/result-document.ts | 10 ++++++---- formatting/schema-table.ts | 3 ++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/__tests__/result-document.test.ts b/__tests__/result-document.test.ts index ebdfa80..ade98ac 100644 --- a/__tests__/result-document.test.ts +++ b/__tests__/result-document.test.ts @@ -46,9 +46,9 @@ describe("renderQueryDocument (llm-zh)", () => { const text = textOf(renderQueryDocument(doc(), { audience: "llm-zh" })); expect(text).toContain("## 数据库查询结果"); - expect(text).toContain("**数据库**:shop"); - expect(text).toContain("**SQL**:SELECT * FROM users"); - expect(text).toContain("**行数**:2(0.010s)"); + expect(text).toContain("数据库:shop"); + expect(text).toContain("SQL:SELECT * FROM users"); + expect(text).toContain("行数:2(0.010s)"); expect(text).toContain("| id | name |"); expect(text).toContain("alice"); }); @@ -57,8 +57,8 @@ describe("renderQueryDocument (llm-zh)", () => { const lines = renderQueryDocument(doc({ connectionId: "main" }), { audience: "llm-zh" }); const text = textOf(lines); - expect(text).toContain("**连接**:main"); - expect(text.indexOf("**连接**")).toBeLessThan(text.indexOf("**数据库**")); + expect(text).toContain("连接:main"); + expect(text.indexOf("连接:main")).toBeLessThan(text.indexOf("数据库:")); }); it("空结果输出(空结果)占位", () => { diff --git a/__tests__/schema-table.test.ts b/__tests__/schema-table.test.ts index 84bccbe..72d5b67 100644 --- a/__tests__/schema-table.test.ts +++ b/__tests__/schema-table.test.ts @@ -36,7 +36,7 @@ describe("formatSchemaMarkdown", () => { expect(out).toContain("| 列 | 类型 | Null | Key | 默认 | Extra | 注释 |"); expect(out).toContain("| id | bigint(20) | | PK | | auto_increment | |"); expect(out).toContain("| user_id | bigint(20) | YES | FK | | | 下单用户 |"); - expect(out).toContain("**索引(2)**"); + expect(out).toContain("索引(2)"); expect(out).toContain("- `PRIMARY` [UNIQUE]: id"); expect(out).toContain("- `idx_user`: user_id"); }); diff --git a/formatting/result-document.ts b/formatting/result-document.ts index 36ab7d1..240f577 100644 --- a/formatting/result-document.ts +++ b/formatting/result-document.ts @@ -133,12 +133,14 @@ function relatedSummary(related: RelatedResult[]): string { // ====== LLM 上下文(中文 markdown,/db query 消息与 db_query 工具共用)====== function renderLlm(doc: QueryResultDoc): DocLine[] { + // 元数据标签不加粗:`**` 在工具结果展开态(tool-result-render 的 + // TruncatedMultiline 原文渲染)会以字面量显示在终端,且对 LLM 无信息量。 const lines: DocLine[] = [{ text: "## 数据库查询结果" }, { text: "" }]; - if (doc.connectionId) lines.push({ text: `**连接**:${doc.connectionId}` }); + if (doc.connectionId) lines.push({ text: `连接:${doc.connectionId}` }); lines.push( - { text: `**数据库**:${doc.database}` }, - { text: `**SQL**:${doc.sql}` }, - { text: `**行数**:${doc.rowCount}(${doc.elapsed})` }, + { text: `数据库:${doc.database}` }, + { text: `SQL:${doc.sql}` }, + { text: `行数:${doc.rowCount}(${doc.elapsed})` }, { text: "" }, ); diff --git a/formatting/schema-table.ts b/formatting/schema-table.ts index 1d5c8d5..a910fa1 100644 --- a/formatting/schema-table.ts +++ b/formatting/schema-table.ts @@ -40,7 +40,8 @@ export function formatSchemaMarkdown( ); } - lines.push("", `**索引(${indexes.length})**`, ""); + // 索引标题不加粗:`**` 在 db_tables 工具结果展开态会以字面量显示在终端。 + lines.push("", `索引(${indexes.length})`, ""); for (const idx of indexes) { lines.push(`- \`${idx.name}\`${idx.unique ? " [UNIQUE]" : ""}: ${idx.columns.join(", ")}`); }