Skip to content

Commit 1382fbf

Browse files
committed
feat: 更新任务管理器以支持可读格式的计划和步骤ID,优化创建任务计划的逻辑,增强任务工具的可测试性
1 parent 1d9e658 commit 1382fbf

3 files changed

Lines changed: 19 additions & 10 deletions

File tree

src/core/task-manager.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,12 @@ export class TaskManager {
200200
let planRequired = false;
201201

202202
if (params.overall_plan && params.overall_plan.length > 0) {
203-
for (const planDescription of params.overall_plan) {
204-
const plan = this.createTaskPlan(planDescription, timestamp);
203+
for (let i = 0; i < params.overall_plan.length; i++) {
204+
const plan = this.createTaskPlan(
205+
params.overall_plan[i],
206+
timestamp,
207+
i
208+
);
205209
overallPlan.push(plan);
206210
}
207211
currentPlanId = overallPlan[0].id;
@@ -597,9 +601,13 @@ export class TaskManager {
597601
return { url: story };
598602
}
599603

600-
private createTaskPlan(description: string, timestamp: string): TaskPlan {
604+
private createTaskPlan(
605+
description: string,
606+
timestamp: string,
607+
index?: number
608+
): TaskPlan {
601609
return {
602-
id: `plan-${ulid()}`,
610+
id: index !== undefined ? `plan-${index + 1}` : `plan-${ulid()}`,
603611
description: description.trim(),
604612
status: TaskStatus.ToDo,
605613
hints: [],
@@ -1140,8 +1148,8 @@ export class TaskManager {
11401148
const oldPlanCount = task.overall_plan.length;
11411149
const newPlanDescriptions = params.content as string[];
11421150

1143-
task.overall_plan = newPlanDescriptions.map((description) =>
1144-
this.createTaskPlan(description, timestamp)
1151+
task.overall_plan = newPlanDescriptions.map((description, index) =>
1152+
this.createTaskPlan(description, timestamp, index)
11451153
);
11461154

11471155
task.current_plan_id =
@@ -1187,8 +1195,8 @@ export class TaskManager {
11871195
const oldStepCount = plan.steps.length;
11881196
const newStepDescriptions = params.content as string[];
11891197

1190-
plan.steps = newStepDescriptions.map((description) => ({
1191-
id: `step-${ulid()}`,
1198+
plan.steps = newStepDescriptions.map((description, index) => ({
1199+
id: `step-${index + 1}`,
11921200
description: description.trim(),
11931201
status: TaskStatus.ToDo,
11941202
hints: [],

src/tools/task-tools.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ describe('CurrentTaskInitTool', () => {
221221
expect(task!.overall_plan).toHaveLength(4);
222222

223223
task!.overall_plan.forEach((plan, index) => {
224-
expect(plan.id).toMatch(/^plan-[0-9A-HJKMNP-TV-Z]{26}$/); // ULID格式
224+
expect(plan.id).toMatch(/^plan-\d+$/); // 可读格式
225225
expect(plan.description).toBe(params.overall_plan![index]);
226226
expect(plan.status).toBe(TaskStatus.ToDo);
227227
expect(plan.steps).toHaveLength(0); // 初始时没有步骤

src/tools/task-tools.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ export class CurrentTaskReadTool extends BaseTaskTool {
482482

483483
lines.push('', '## 执行日志');
484484
task.logs.slice(-5).forEach((log: any) => {
485-
lines.push(`- **${log.timestamp}**: ${log.message}`);
485+
const localTime = new Date(log.timestamp).toLocaleString();
486+
lines.push(`- **${localTime}**: ${log.message}`);
486487
});
487488

488489
return lines.join('\n');

0 commit comments

Comments
 (0)