Skip to content

Commit 3d00bd8

Browse files
committed
feat(tasks): enhance task and subtask deletion
1 parent b6e90f2 commit 3d00bd8

3 files changed

Lines changed: 133 additions & 30 deletions

File tree

src/core/taskmaster/TaskMaster.ts

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export class TaskMaster {
428428
* @param numTasksToGenerate Number of tasks to generate (default: 10)
429429
* @param allowAdvancedResearch Allow advanced research for task generation
430430
* @param appendToExistingTasks Whether to append to existing tasks
431-
* @param tag tag for the generated tasks
431+
* @param tag Context tag
432432
*/
433433
public async parseAsync(
434434
inputFilePath: string,
@@ -480,7 +480,7 @@ export class TaskMaster {
480480
// TODO: done
481481
/**
482482
* @description Decomposes all tasks using AI
483-
* @param tag tag for the tasks to decompose
483+
* @param tag Context tag
484484
*/
485485
public async decomposeAsync(tag: string): Promise<void> {
486486
await this.executeCommandAsync(
@@ -690,7 +690,7 @@ export class TaskMaster {
690690
* @description Adds a new task using AI
691691
* @param prompt Description of the task to create
692692
* @param allowAdvancedResearch Use research capabilities
693-
* @param tag Tag context for the task
693+
* @param tag Context tag
694694
*/
695695
public async addTaskByAIAsync(
696696
prompt: string,
@@ -888,26 +888,25 @@ export class TaskMaster {
888888
* @description Updates the status of one or more tasks
889889
* @param ids Array of task IDs (can be main tasks or hierarchical subtask IDs)
890890
* @param status The new status to set for the tasks
891-
* @param tag Optional tag to filter tasks
891+
* @param tag Context tag
892892
*/
893893
public async updateTaskStatusAsync(
894894
ids: string[],
895895
status: string,
896-
tag?: string,
896+
tag: string,
897897
): Promise<void> {
898898
const formatedIds = ids.length > 1 ? ids.join(",") : ids[0];
899-
const args = ["set-status", `--id=${formatedIds}`, `--status=${status}`];
900-
901-
if (tag) {
902-
args.push(`--tag=${tag}`);
903-
}
904-
905899
await this.executeCommandAsync(
906900
`Updating status of task(s) ${formatedIds} to ${status}...`,
907901
`Status of task(s) ${formatedIds} updated successfully!`,
908902
`Failed to update status of task(s) ${formatedIds}`,
909903
this._mainCommand,
910-
args,
904+
[
905+
"set-status",
906+
`--id=${formatedIds}`,
907+
`--status=${status}`,
908+
`--tag=${tag}`,
909+
],
911910
);
912911
}
913912

@@ -932,7 +931,93 @@ export class TaskMaster {
932931
}
933932

934933
// ==============================================
935-
// Dependencies
934+
// Deleting Methods
935+
// ==============================================
936+
937+
/**
938+
* @description Delete a task by ID (including subtasks)
939+
* @param id The ID of the task to remove
940+
* @param tag Context tag
941+
*/
942+
public async deleteTaskAsync(id: number, tag: string): Promise<void> {
943+
const { confirm } = await inquirer.prompt({
944+
type: "confirm",
945+
name: "confirm",
946+
message: chalk.red(`Are you sure you want to delete task ${id}?`),
947+
default: false,
948+
});
949+
950+
if (confirm) {
951+
await this.executeCommandAsync(
952+
`Deleting task ${id}...`,
953+
`Task ${id} deleted successfully!`,
954+
`Failed to delete task ${id}`,
955+
this._mainCommand,
956+
["remove-task", `--id=${id}`, `--tag=${tag}`, "-y"],
957+
);
958+
}
959+
}
960+
961+
/**
962+
* @description Delete a specific subtask
963+
* @param hierarchicalId The hierarchical ID of the subtask
964+
* @param tag Context tag
965+
*/
966+
public async deleteSubtaskAsync(
967+
hierarchicalId: string,
968+
tag: string,
969+
): Promise<void> {
970+
const { confirm } = await inquirer.prompt({
971+
type: "confirm",
972+
name: "confirm",
973+
message: chalk.red(
974+
`Are you sure you want to delete subtask ${hierarchicalId}?`,
975+
),
976+
default: false,
977+
});
978+
979+
if (confirm) {
980+
await this.executeCommandAsync(
981+
`Deleting subtask ${hierarchicalId}...`,
982+
`Subtask ${hierarchicalId} deleted successfully!`,
983+
`Failed to delete subtask ${hierarchicalId}`,
984+
this._mainCommand,
985+
["remove-subtask", `--id=${hierarchicalId}`, `--tag=${tag}`],
986+
);
987+
}
988+
}
989+
990+
/**
991+
* @description Deletes all subtasks from a specific task
992+
* @param id The ID of the task to clear subtasks from
993+
* @param tag Context tag
994+
*/
995+
public async deleteAllSubtasksFromTaskAsync(
996+
id: number,
997+
tag: string,
998+
): Promise<void> {
999+
const { confirm } = await inquirer.prompt({
1000+
type: "confirm",
1001+
name: "confirm",
1002+
message: chalk.red(
1003+
`Are you sure you want to delete all subtasks from task ${id}?`,
1004+
),
1005+
default: false,
1006+
});
1007+
1008+
if (confirm) {
1009+
await this.executeCommandAsync(
1010+
`Deleting all subtasks from task ${id}...`,
1011+
`All subtasks deleted from task ${id} successfully!`,
1012+
`Failed to delete subtasks from task ${id}`,
1013+
this._mainCommand,
1014+
["clear-subtasks", `--id=${id}`, `--tag=${tag}`],
1015+
);
1016+
}
1017+
}
1018+
1019+
// ==============================================
1020+
// Dependencies Methods
9361021
// ==============================================
9371022

9381023
// TODO: in-progress

src/core/taskmaster/exec.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,34 @@ export async function tmaiManageAsync() {
284284
const { tmaiDeleteTasksMenu } = await inquirer.prompt(
285285
tmaiDeleteTasksMenu_prompt,
286286
);
287-
if (tmaiDeleteTasksMenu === "tmai-deletetasks") {
288-
console.log("Executing task deletion...");
287+
const { mainIDs, subtasksIDs } = await tmai.getAllTaskIdsAsync(tasks);
288+
const tag = await askTaskTagAsync();
289+
290+
switch (tmaiDeleteTasksMenu) {
291+
case "tmai-deletetask": {
292+
await tmai.listAsync(tasks, TASKS_STATUSES.join(","), true, true);
293+
const taskId = await askTaskIdAsync(mainIDs);
294+
await tmai.deleteTaskAsync(taskId, tag);
295+
tasks = await tmai.getTasksContentAsync();
296+
await tmai.listAsync(tasks, TASKS_STATUSES.join(","), true, true);
297+
break;
298+
}
299+
case "tmai-deletesubtask": {
300+
await tmai.listAsync(tasks, TASKS_STATUSES.join(","), true, true);
301+
const subtaskId = await askHierarchicalTaskIdAsync(subtasksIDs);
302+
await tmai.deleteSubtaskAsync(subtaskId, tag);
303+
tasks = await tmai.getTasksContentAsync();
304+
await tmai.listAsync(tasks, TASKS_STATUSES.join(","), true, true);
305+
break;
306+
}
307+
case "tmai-deleteallsubtasksfromtask": {
308+
await tmai.listAsync(tasks, TASKS_STATUSES.join(","), true, true);
309+
const taskId = await askTaskIdAsync(mainIDs);
310+
await tmai.deleteAllSubtasksFromTaskAsync(taskId, tag);
311+
tasks = await tmai.getTasksContentAsync();
312+
await tmai.listAsync(tasks, TASKS_STATUSES.join(","), true, true);
313+
break;
314+
}
289315
}
290316
break;
291317
}

src/prompt.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,28 +275,20 @@ export const tmaiDeleteTasksMenu_prompt = [
275275
name: "tmaiDeleteTasksMenu",
276276
message: chalk.bgBlue("Choose an operation"),
277277
loop: true,
278-
pageSize: 15,
278+
pageSize: 7,
279279
choices: [
280280
new inquirer.Separator("=== Deleting tasks ==="),
281281
{
282-
name: `${emoji.get("wastebasket")} Delete task`,
282+
name: `${emoji.get("wastebasket")} Delete a task (including subtasks)`,
283283
value: "tmai-deletetask",
284284
},
285285
{
286-
name: `${emoji.get("scissors")} Delete subtask`,
286+
name: `${emoji.get("wastebasket")} Delete a subtask`,
287287
value: "tmai-deletesubtask",
288288
},
289289
{
290-
name: `${emoji.get("recycle")} Convert subtask to task`,
291-
value: "tmai-deletesubtaskconvert",
292-
},
293-
{
294-
name: `${emoji.get("broom")} Clear subtasks from task`,
295-
value: "tmai-clearsubtasks",
296-
},
297-
{
298-
name: `${emoji.get("fire")} Clear all subtasks`,
299-
value: "tmai-clearsubtasksall",
290+
name: `${emoji.get("wastebasket")} Clear all subtasks from a task`,
291+
value: "tmai-deleteallsubtasksfromtask",
300292
},
301293
],
302294
},
@@ -392,13 +384,13 @@ export const tmaiBackupRestoreClearClear_prompt = [
392384
},
393385
{
394386
name: chalk.red(
395-
`${emoji.get("boom")} Clear all subtasks only (excluding main tasks)`,
387+
`${emoji.get("broom")} Clear all subtasks only (excluding main tasks)`,
396388
),
397389
value: "tmai-clearallsubtasks",
398390
},
399391
{
400392
name: chalk.red(
401-
`${emoji.get("boom")} Clear all current tasks (including subtasks) and all related tmai files`,
393+
`${emoji.get("broom")} Clear all current tasks (including subtasks) and all related tmai files`,
402394
),
403395
value: "tmai-clearall",
404396
},

0 commit comments

Comments
 (0)