Skip to content

Commit 0dfef42

Browse files
committed
refactor(core): Improve code structure and validate features
1 parent e252d51 commit 0dfef42

3 files changed

Lines changed: 34 additions & 47 deletions

File tree

src/core/TaskMaster.ts

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class TaskMaster {
7575
// Getters and Setters
7676
// ==============================================
7777

78+
// TODO: done
7879
/**
7980
* @description Retrieves the contents of the tasks.json file
8081
*/
@@ -91,13 +92,32 @@ export class TaskMaster {
9192
);
9293
}
9394

95+
// TODO: done
9496
/**
95-
* @description Sets the tasks file path to use for task-master operations
97+
* @description Extracts all main task IDs and subtask IDs from the tasks data
98+
* @param tasks Tasks data to process
99+
* @returns Object containing two arrays: mainIDs (numbers) and subtasksIDs (strings in the format "parentId.subtaskId")
96100
*/
97-
public setTasksFilePath(tasksFilePath: string): void {
98-
this._tasksFilePath = tasksFilePath;
101+
public async getAllTaskIdsAsync(tasks: I_Tasks): Promise<{
102+
mainIDs: number[];
103+
subtasksIDs: string[];
104+
}> {
105+
const mainIDs: number[] = [];
106+
const subtasksIDs: string[] = [];
107+
108+
for (const task of tasks.master.tasks) {
109+
mainIDs.push(task.id);
110+
if (task.subtasks && task.subtasks.length > 0) {
111+
for (const subtask of task.subtasks) {
112+
subtasksIDs.push(`${task.id}.${subtask.id}`);
113+
}
114+
}
115+
}
116+
117+
return { mainIDs, subtasksIDs };
99118
}
100119

120+
// TODO: done
101121
/**
102122
* @description Retrieves all dependencies for a given task or subtask.
103123
* @param tasks The tasks data structure
@@ -496,7 +516,7 @@ export class TaskMaster {
496516
}
497517

498518
// TODO: done
499-
public _countdown(seconds: number) {
519+
private _countdown(seconds: number) {
500520
return new Promise((resolve) => {
501521
let remaining = seconds;
502522
const rl = readline.createInterface({
@@ -869,31 +889,6 @@ export class TaskMaster {
869889
return output;
870890
}
871891

872-
// TODO: done
873-
/**
874-
* @description Extracts all main task IDs and subtask IDs from the tasks data
875-
* @param tasks Tasks data to process
876-
* @returns Object containing two arrays: mainIDs (numbers) and subtasksIDs (strings in the format "parentId.subtaskId")
877-
*/
878-
public async getAllTaskIdsAsync(tasks: I_Tasks): Promise<{
879-
mainIDs: number[];
880-
subtasksIDs: string[];
881-
}> {
882-
const mainIDs: number[] = [];
883-
const subtasksIDs: string[] = [];
884-
885-
for (const task of tasks.master.tasks) {
886-
mainIDs.push(task.id);
887-
if (task.subtasks && task.subtasks.length > 0) {
888-
for (const subtask of task.subtasks) {
889-
subtasksIDs.push(`${task.id}.${subtask.id}`);
890-
}
891-
}
892-
}
893-
894-
return { mainIDs, subtasksIDs };
895-
}
896-
897892
// TODO: done
898893
/**
899894
* @description Lists tasks with optional status filtering and subtask display
@@ -1039,7 +1034,7 @@ export class TaskMaster {
10391034
// Updating Methods
10401035
// ==============================================
10411036

1042-
// TODO: validate
1037+
// TODO: done
10431038
/**
10441039
* @description Modifies a task using AI
10451040
* @param id ID of the task to modify
@@ -1075,7 +1070,7 @@ export class TaskMaster {
10751070
);
10761071
}
10771072

1078-
// TODO: validate
1073+
// TODO: done
10791074
/**
10801075
* @description Updates multiple tasks using AI from a starting ID
10811076
* @param startingId Starting ID for the update
@@ -1111,7 +1106,7 @@ export class TaskMaster {
11111106
);
11121107
}
11131108

1114-
// TODO: validate
1109+
// TODO: done
11151110
/**
11161111
* @description Modifies a subtask using AI
11171112
* @param hierarchicalId Hierarchical ID of the subtask
@@ -1302,7 +1297,7 @@ export class TaskMaster {
13021297
// Deleting Methods
13031298
// ==============================================
13041299

1305-
// TODO: validate
1300+
// TODO: done
13061301
/**
13071302
* @description Delete a task by ID (including subtasks)
13081303
* @param id The ID of the task to remove
@@ -1327,7 +1322,7 @@ export class TaskMaster {
13271322
}
13281323
}
13291324

1330-
// TODO: validate
1325+
// TODO: done
13311326
/**
13321327
* @description Delete a specific subtask
13331328
* @param hierarchicalId The hierarchical ID of the subtask
@@ -1357,7 +1352,7 @@ export class TaskMaster {
13571352
}
13581353
}
13591354

1360-
// TODO: validate
1355+
// TODO: done
13611356
/**
13621357
* @description Deletes all subtasks from a specific task
13631358
* @param id The ID of the task to clear subtasks from
@@ -1387,7 +1382,7 @@ export class TaskMaster {
13871382
}
13881383
}
13891384

1390-
// TODO: validate
1385+
// TODO: done
13911386
/**
13921387
* @description Clears all dependencies for the specified task or subtask.
13931388
* @param taskId The task ID or hierarchical ID of the subtask
@@ -1401,14 +1396,12 @@ export class TaskMaster {
14011396
return;
14021397
}
14031398

1404-
// For subtasks, dependency IDs are already in the correct format
1405-
// For main tasks, dependency IDs are numbers that need to be converted to string
14061399
const isSubtask = taskId.includes(".");
14071400

14081401
for (const dependencyId of dependencyIds) {
14091402
const dependsOnId = isSubtask
1410-
? dependencyId.toString() // For subtasks, dependencyId is already the full ID
1411-
: dependencyId.toString(); // For main tasks, convert number to string
1403+
? dependencyId.toString()
1404+
: dependencyId.toString();
14121405

14131406
await this._executeCommandAsync(
14141407
`Removing dependency ${dependsOnId} from task ${taskId}...`,

src/core/exec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ export async function tmaiDependenciesAsync() {
388388
subtasksIDs,
389389
);
390390
await tmai.addDependencyAsync(taskId, multipleTaskIds);
391-
await tmai.listAsync(tasks, TASKS_STATUSES.join(","), false, true);
391+
await tmai.listAsync(tasks, TASKS_STATUSES.join(","), true, true);
392392
break;
393393
}
394394
case "tmai-validatedeps": {

tests/index.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,6 @@ describe("TaskMaster Class", () => {
309309
});
310310
});
311311

312-
// describe("_fixIdsToSequentialAsync", () => {
313-
// test("fixes sequential IDs", async () => {
314-
// await tmai._fixIdsToSequentialAsync();
315-
// });
316-
// });
317-
318312
describe("_validateConversionRules", () => {
319313
test("should validate task to subtask conversion with no dependencies", () => {
320314
const tasks: I_Tasks = {

0 commit comments

Comments
 (0)