@@ -977,7 +977,7 @@ export class TaskMaster {
977977 subtaskId : number ,
978978 parentId : number ,
979979 ) : Promise < void > {
980- await this . deleteAllDepsFromTaskAsync ( subtaskId . toString ( ) ) ;
980+ await this . deleteAllDepsSafelyFromTaskAsync ( subtaskId . toString ( ) ) ;
981981 await this . _executeCommandAsync (
982982 `Converting task ${ subtaskId } to subtask of ${ parentId } ...` ,
983983 `Task ${ subtaskId } converted to subtask successfully!` ,
@@ -995,6 +995,7 @@ export class TaskMaster {
995995 public async convertSubtaskToTaskAsync (
996996 hierarchicalId : string ,
997997 ) : Promise < void > {
998+ await this . deleteAllDepsSafelyFromTaskAsync ( hierarchicalId ) ;
998999 await this . _executeCommandAsync (
9991000 `Converting subtask ${ hierarchicalId } to task...` ,
10001001 `Subtask ${ hierarchicalId } converted to task successfully!` ,
@@ -1098,7 +1099,7 @@ export class TaskMaster {
10981099 * @description Clears all dependencies for the specified task or subtask.
10991100 * @param taskId The task ID or hierarchical ID of the subtask
11001101 */
1101- public async deleteAllDepsFromTaskAsync ( taskId : string ) : Promise < void > {
1102+ public async deleteAllDepsSafelyFromTaskAsync ( taskId : string ) : Promise < void > {
11021103 const tasks = await this . getTasksContentAsync ( ) ;
11031104 const dependencyIds = await this . _getAllDependenciesAsync ( tasks , taskId ) ;
11041105
@@ -1126,6 +1127,58 @@ export class TaskMaster {
11261127 }
11271128 }
11281129
1130+ // TODO: done
1131+ /**
1132+ * @description Deletes all dependencies for the specified task or subtask without using external commands.
1133+ * This is a faster but less safe method that directly modifies the tasks.json file.
1134+ * @param taskId The task ID or hierarchical ID of the subtask
1135+ */
1136+ public async deleteAllDepsUnsafeFromTaskAsync ( taskId : string ) : Promise < void > {
1137+ const oraOptions = {
1138+ text : `Clearing dependencies from task ${ taskId } ...` ,
1139+ successText : chalk . bgGreen (
1140+ `Dependencies cleared from task ${ taskId } successfully!` ,
1141+ ) ,
1142+ failText : chalk . bgRed ( `Failed to clear dependencies from task ${ taskId } ` ) ,
1143+ } ;
1144+
1145+ await oraPromise ( async ( ) => {
1146+ const tasks = await this . getTasksContentAsync ( ) ;
1147+
1148+ if ( ! taskId . includes ( "." ) ) {
1149+ // It's a main task
1150+ const idNum = Number . parseInt ( taskId , 10 ) ;
1151+ const task = tasks . master . tasks . find ( ( t ) => t . id === idNum ) ;
1152+ if ( ! task ) {
1153+ throw new Error ( `Task not found: ${ taskId } ` ) ;
1154+ }
1155+ task . dependencies = [ ] ;
1156+ } else {
1157+ // It's a subtask
1158+ const parts = taskId . split ( "." ) ;
1159+ const parentId = Number . parseInt ( parts [ 0 ] , 10 ) ;
1160+ const subtaskIndex = Number . parseInt ( parts [ 1 ] , 10 ) - 1 ;
1161+ const parentTask = tasks . master . tasks . find ( ( t ) => t . id === parentId ) ;
1162+ if ( ! parentTask ) {
1163+ throw new Error ( `Parent task not found for subtask: ${ taskId } ` ) ;
1164+ }
1165+
1166+ if (
1167+ ! parentTask . subtasks ||
1168+ subtaskIndex < 0 ||
1169+ subtaskIndex >= parentTask . subtasks . length
1170+ ) {
1171+ throw new Error ( `Subtask not found: ${ taskId } ` ) ;
1172+ }
1173+
1174+ const subtask = parentTask . subtasks [ subtaskIndex ] ;
1175+ subtask . dependencies = [ ] ;
1176+ }
1177+
1178+ await writeFile ( this . _tasksFilePath , JSON . stringify ( tasks , null , 2 ) ) ;
1179+ } , oraOptions ) ;
1180+ }
1181+
11291182 // ==============================================
11301183 // Dependencies Methods
11311184 // ==============================================
0 commit comments