From ca1738785a5b1f27a60434c4a68c3f99b2a0007c Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Wed, 10 Jun 2026 15:47:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20TaskFormatError=20=E6=9C=AA=E8=A2=AB?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E5=AF=BC=E8=87=B4=E6=98=BE=E7=A4=BA=E5=8F=91?= =?UTF-8?q?=E7=94=9F=E6=9C=AA=E9=A2=84=E6=9C=9F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/assembler.ts | 13 +++++++++++-- tests/core/assembler.test.ts | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/assembler.ts b/src/core/assembler.ts index 22dd300..9ed6c1f 100644 --- a/src/core/assembler.ts +++ b/src/core/assembler.ts @@ -4,7 +4,7 @@ import { join } from "node:path"; import type { RuneConfig } from "../types.ts"; import { CommandError } from "../cli/errors.ts"; import { getChangeDir } from "./config.ts"; -import { parseTasks, validateTaskFormat } from "./task-parser.ts"; +import { parseTasks, validateTaskFormat, TaskFormatError } from "./task-parser.ts"; import { applyCommandPrefix, getPmPrefix } from "./pm.ts"; export function assembleDiscussPrompt(config: RuneConfig): string { @@ -100,7 +100,16 @@ export async function assembleBuildPrompt( }); } - validateTaskFormat(taskContent); + try { + validateTaskFormat(taskContent); + } catch (e) { + if (e instanceof TaskFormatError) { + throw new CommandError(e.message, { + hint: `请确保 ${taskPath} 中包含格式正确的 checkbox 任务项(如 - [ ] 任务描述)`, + }); + } + throw e; + } const tasks = parseTasks(taskContent); const pendingTasks = tasks.filter((t) => !t.checked); diff --git a/tests/core/assembler.test.ts b/tests/core/assembler.test.ts index 936e7b9..e281c20 100644 --- a/tests/core/assembler.test.ts +++ b/tests/core/assembler.test.ts @@ -179,6 +179,7 @@ describe("assembleBuildPrompt", () => { } catch (e: any) { expect(e.message).toContain("task.md"); expect(e.message).toContain("checkbox"); + expect(e.hint).toBeTruthy(); } }); @@ -195,6 +196,7 @@ describe("assembleBuildPrompt", () => { expect.unreachable(); } catch (e: any) { expect(e.message).toContain("checkbox"); + expect(e.hint).toBeTruthy(); } }); });