task-o-matic 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/commands/tasks/create.d.ts.map +1 -1
  2. package/dist/commands/tasks/create.js +6 -13
  3. package/dist/commands/tasks/document/add.d.ts +3 -0
  4. package/dist/commands/tasks/document/add.d.ts.map +1 -0
  5. package/dist/commands/tasks/document/add.js +35 -0
  6. package/dist/commands/tasks/document/analyze.d.ts +3 -0
  7. package/dist/commands/tasks/document/analyze.d.ts.map +1 -0
  8. package/dist/commands/tasks/document/analyze.js +49 -0
  9. package/dist/commands/tasks/document/get.d.ts +3 -0
  10. package/dist/commands/tasks/document/get.d.ts.map +1 -0
  11. package/dist/commands/tasks/document/get.js +29 -0
  12. package/dist/commands/tasks/document/index.d.ts +8 -0
  13. package/dist/commands/tasks/document/index.d.ts.map +1 -0
  14. package/dist/commands/tasks/document/index.js +13 -0
  15. package/dist/commands/tasks/enhance.d.ts.map +1 -1
  16. package/dist/commands/tasks/enhance.js +64 -61
  17. package/dist/commands/tasks/execute-loop.d.ts.map +1 -1
  18. package/dist/commands/tasks/execute-loop.js +66 -97
  19. package/dist/commands/tasks/execute.d.ts.map +1 -1
  20. package/dist/commands/tasks/execute.js +52 -16
  21. package/dist/commands/tasks/plan/create.d.ts +3 -0
  22. package/dist/commands/tasks/plan/create.d.ts.map +1 -0
  23. package/dist/commands/tasks/plan/create.js +37 -0
  24. package/dist/commands/tasks/plan/delete.d.ts +3 -0
  25. package/dist/commands/tasks/plan/delete.d.ts.map +1 -0
  26. package/dist/commands/tasks/plan/delete.js +14 -0
  27. package/dist/commands/tasks/plan/get.d.ts +3 -0
  28. package/dist/commands/tasks/plan/get.d.ts.map +1 -0
  29. package/dist/commands/tasks/plan/get.js +24 -0
  30. package/dist/commands/tasks/plan/index.d.ts +10 -0
  31. package/dist/commands/tasks/plan/index.d.ts.map +1 -0
  32. package/dist/commands/tasks/plan/index.js +17 -0
  33. package/dist/commands/tasks/plan/list.d.ts +3 -0
  34. package/dist/commands/tasks/plan/list.d.ts.map +1 -0
  35. package/dist/commands/tasks/plan/list.js +21 -0
  36. package/dist/commands/tasks/plan/set.d.ts +3 -0
  37. package/dist/commands/tasks/plan/set.d.ts.map +1 -0
  38. package/dist/commands/tasks/plan/set.js +33 -0
  39. package/dist/commands/tasks/split.d.ts.map +1 -1
  40. package/dist/commands/tasks/split.js +65 -60
  41. package/dist/lib/ai-service/documentation-operations.d.ts.map +1 -1
  42. package/dist/lib/ai-service/documentation-operations.js +22 -12
  43. package/dist/lib/ai-service/prd-operations.d.ts.map +1 -1
  44. package/dist/lib/ai-service/prd-operations.js +18 -25
  45. package/dist/lib/executors/opencode-executor.d.ts.map +1 -1
  46. package/dist/lib/executors/opencode-executor.js +3 -1
  47. package/dist/lib/git-utils.d.ts +45 -0
  48. package/dist/lib/git-utils.d.ts.map +1 -0
  49. package/dist/lib/git-utils.js +160 -0
  50. package/dist/lib/prompt-builder.d.ts +11 -0
  51. package/dist/lib/prompt-builder.d.ts.map +1 -1
  52. package/dist/lib/prompt-builder.js +59 -0
  53. package/dist/lib/prompt-registry.d.ts.map +1 -1
  54. package/dist/lib/prompt-registry.js +158 -0
  55. package/dist/lib/task-execution-core.d.ts +7 -0
  56. package/dist/lib/task-execution-core.d.ts.map +1 -0
  57. package/dist/lib/task-execution-core.js +360 -0
  58. package/dist/lib/task-execution.d.ts +4 -0
  59. package/dist/lib/task-execution.d.ts.map +1 -1
  60. package/dist/lib/task-execution.js +31 -178
  61. package/dist/lib/task-loop-execution.d.ts +1 -19
  62. package/dist/lib/task-loop-execution.d.ts.map +1 -1
  63. package/dist/lib/task-loop-execution.js +50 -592
  64. package/dist/lib/task-planning.d.ts +28 -0
  65. package/dist/lib/task-planning.d.ts.map +1 -0
  66. package/dist/lib/task-planning.js +109 -0
  67. package/dist/lib/task-review.d.ts +27 -0
  68. package/dist/lib/task-review.d.ts.map +1 -0
  69. package/dist/lib/task-review.js +106 -0
  70. package/dist/lib/validation.d.ts +20 -3
  71. package/dist/lib/validation.d.ts.map +1 -1
  72. package/dist/lib/validation.js +39 -10
  73. package/dist/prompts/documentation-recap.d.ts +3 -0
  74. package/dist/prompts/documentation-recap.d.ts.map +1 -0
  75. package/dist/prompts/documentation-recap.js +13 -0
  76. package/dist/prompts/index.d.ts +4 -0
  77. package/dist/prompts/index.d.ts.map +1 -1
  78. package/dist/prompts/index.js +4 -0
  79. package/dist/prompts/prd-question-answer.d.ts +3 -0
  80. package/dist/prompts/prd-question-answer.d.ts.map +1 -0
  81. package/dist/prompts/prd-question-answer.js +27 -0
  82. package/dist/prompts/task-execution.d.ts +3 -0
  83. package/dist/prompts/task-execution.d.ts.map +1 -0
  84. package/dist/prompts/task-execution.js +21 -0
  85. package/dist/prompts/workflow-prompts.d.ts +9 -0
  86. package/dist/prompts/workflow-prompts.d.ts.map +1 -0
  87. package/dist/prompts/workflow-prompts.js +93 -0
  88. package/dist/services/workflow-ai-assistant.d.ts.map +1 -1
  89. package/dist/services/workflow-ai-assistant.js +72 -94
  90. package/dist/test/task-loop-git.test.js +6 -6
  91. package/dist/types/cli-options.d.ts +138 -0
  92. package/dist/types/cli-options.d.ts.map +1 -0
  93. package/dist/types/cli-options.js +6 -0
  94. package/dist/types/index.d.ts +38 -0
  95. package/dist/types/index.d.ts.map +1 -1
  96. package/dist/utils/bulk-operations.d.ts +51 -0
  97. package/dist/utils/bulk-operations.d.ts.map +1 -0
  98. package/dist/utils/bulk-operations.js +68 -0
  99. package/dist/utils/cli-validators.d.ts +54 -0
  100. package/dist/utils/cli-validators.d.ts.map +1 -0
  101. package/dist/utils/cli-validators.js +75 -0
  102. package/dist/utils/command-error-handler.d.ts +32 -0
  103. package/dist/utils/command-error-handler.d.ts.map +1 -0
  104. package/dist/utils/command-error-handler.js +52 -0
  105. package/dist/utils/confirmation.d.ts +19 -0
  106. package/dist/utils/confirmation.d.ts.map +1 -0
  107. package/dist/utils/confirmation.js +39 -0
  108. package/dist/utils/display-helpers.d.ts +81 -0
  109. package/dist/utils/display-helpers.d.ts.map +1 -0
  110. package/dist/utils/display-helpers.js +109 -0
  111. package/dist/utils/model-executor-parser.d.ts +38 -0
  112. package/dist/utils/model-executor-parser.d.ts.map +1 -0
  113. package/dist/utils/model-executor-parser.js +67 -0
  114. package/dist/utils/progress-tracking.d.ts +28 -0
  115. package/dist/utils/progress-tracking.d.ts.map +1 -0
  116. package/dist/utils/progress-tracking.js +43 -0
  117. package/package.json +1 -1
  118. package/dist/commands/tasks/document.d.ts +0 -5
  119. package/dist/commands/tasks/document.d.ts.map +0 -1
  120. package/dist/commands/tasks/document.js +0 -118
  121. package/dist/commands/tasks/plan.d.ts +0 -7
  122. package/dist/commands/tasks/plan.d.ts.map +0 -1
  123. package/dist/commands/tasks/plan.js +0 -131
@@ -0,0 +1,360 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.executeTaskCore = executeTaskCore;
7
+ const tasks_1 = require("../services/tasks");
8
+ const executor_factory_1 = require("./executors/executor-factory");
9
+ const validation_1 = require("./validation");
10
+ const ai_service_factory_1 = require("../utils/ai-service-factory");
11
+ const hooks_1 = require("./hooks");
12
+ const prompt_builder_1 = require("./prompt-builder");
13
+ const task_planning_1 = require("./task-planning");
14
+ const task_review_1 = require("./task-review");
15
+ const git_utils_1 = require("./git-utils");
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ /**
18
+ * Execute a single task with all features (retry, planning, review, etc.)
19
+ * This is the core unified execution logic used by both execute and execute-loop commands
20
+ */
21
+ async function executeTaskCore(taskId, config) {
22
+ const { tool, executorConfig, customMessage, verificationCommands = [], enableRetry = false, maxRetries = 3, tryModels, enablePlanPhase = false, planModel, reviewPlan = false, enableReviewPhase = false, reviewModel, autoCommit: enableAutoCommit = false, executeSubtasks = true, dry = false, } = config;
23
+ // Load task
24
+ const task = await tasks_1.taskService.getTask(taskId);
25
+ if (!task) {
26
+ throw new Error(`Task with ID ${taskId} not found`);
27
+ }
28
+ // Check if task has subtasks and should execute them recursively
29
+ if (executeSubtasks && !customMessage) {
30
+ const subtasks = await tasks_1.taskService.getSubtasks(taskId);
31
+ if (subtasks.length > 0) {
32
+ return await executeTaskWithSubtasks(task, subtasks, config);
33
+ }
34
+ }
35
+ // ----------------------------------------------------------------------
36
+ // PLANNING PHASE
37
+ // ----------------------------------------------------------------------
38
+ let planContent;
39
+ if (enablePlanPhase) {
40
+ const planningResult = await (0, task_planning_1.executePlanningPhase)(task, tool, {
41
+ planModel,
42
+ reviewPlan,
43
+ autoCommit: enableAutoCommit,
44
+ dry,
45
+ });
46
+ if (planningResult.success && planningResult.planContent) {
47
+ planContent = planningResult.planContent;
48
+ }
49
+ }
50
+ // ----------------------------------------------------------------------
51
+ // EXECUTION PHASE (with optional retry logic)
52
+ // ----------------------------------------------------------------------
53
+ const attempts = [];
54
+ if (enableRetry) {
55
+ // Execute with retry logic
56
+ return await executeTaskWithRetry(task, config, attempts, planContent);
57
+ }
58
+ else {
59
+ // Execute once without retry (simpler path for execute command)
60
+ return await executeSingleAttempt(task, config, attempts, planContent, 1, maxRetries);
61
+ }
62
+ }
63
+ /**
64
+ * Execute task with subtasks recursively
65
+ */
66
+ async function executeTaskWithSubtasks(task, subtasks, config) {
67
+ const { dry } = config;
68
+ console.log(chalk_1.default.blue(`📋 Task has ${subtasks.length} subtasks, executing recursively...`));
69
+ const subtaskResults = [];
70
+ let allSuccess = true;
71
+ // Execute subtasks one by one
72
+ for (let i = 0; i < subtasks.length; i++) {
73
+ const subtask = subtasks[i];
74
+ console.log(chalk_1.default.cyan(`\n[${i + 1}/${subtasks.length}] Executing subtask: ${subtask.title} (${subtask.id})`));
75
+ try {
76
+ const result = await executeTaskCore(subtask.id, config);
77
+ subtaskResults.push(result);
78
+ if (!result.success) {
79
+ allSuccess = false;
80
+ console.error(chalk_1.default.red(`❌ Failed to execute subtask ${subtask.id}: ${subtask.title}`));
81
+ break; // Stop on first failure
82
+ }
83
+ }
84
+ catch (error) {
85
+ allSuccess = false;
86
+ console.error(chalk_1.default.red(`❌ Failed to execute subtask ${subtask.id}: ${error instanceof Error ? error.message : "Unknown error"}`));
87
+ break;
88
+ }
89
+ }
90
+ // After all subtasks are done (or on failure), update the main task status
91
+ if (!dry) {
92
+ if (allSuccess) {
93
+ await tasks_1.taskService.setTaskStatus(task.id, "completed");
94
+ console.log(chalk_1.default.green(`✅ Main task ${task.title} completed after all subtasks`));
95
+ }
96
+ else {
97
+ await tasks_1.taskService.setTaskStatus(task.id, "todo");
98
+ console.log(chalk_1.default.red(`❌ Main task ${task.title} failed due to subtask failure, status reset to todo`));
99
+ }
100
+ }
101
+ return {
102
+ success: allSuccess,
103
+ attempts: [], // Parent task doesn't have its own attempts
104
+ subtaskResults,
105
+ };
106
+ }
107
+ /**
108
+ * Execute task with retry logic
109
+ */
110
+ async function executeTaskWithRetry(task, config, attempts, planContent) {
111
+ const { tool, maxRetries = 3, tryModels, verificationCommands = [], enableReviewPhase = false, reviewModel, autoCommit: enableAutoCommit = false, dry = false, } = config;
112
+ let currentAttempt = 1;
113
+ let lastError;
114
+ while (currentAttempt <= maxRetries) {
115
+ // Determine which executor and model to use for this attempt
116
+ let currentExecutor = tool;
117
+ let currentModel;
118
+ if (tryModels && tryModels.length > 0) {
119
+ const modelConfigIndex = Math.min(currentAttempt - 1, tryModels.length - 1);
120
+ const modelConfig = tryModels[modelConfigIndex];
121
+ if (modelConfig.executor) {
122
+ currentExecutor = modelConfig.executor;
123
+ }
124
+ if (modelConfig.model) {
125
+ currentModel = modelConfig.model;
126
+ }
127
+ }
128
+ console.log(chalk_1.default.blue(`\n🎯 Attempt ${currentAttempt}/${maxRetries} for task: ${task.title} (${task.id})`));
129
+ if (currentModel) {
130
+ console.log(chalk_1.default.cyan(` Using executor: ${currentExecutor} with model: ${currentModel}`));
131
+ }
132
+ else {
133
+ console.log(chalk_1.default.cyan(` Using executor: ${currentExecutor}`));
134
+ }
135
+ // Build retry context if this is a retry attempt
136
+ let retryContext = "";
137
+ if (currentAttempt > 1 && lastError) {
138
+ const retryParts = [];
139
+ retryParts.push(`# RETRY ATTEMPT ${currentAttempt}/${maxRetries}\n\n`);
140
+ if (currentModel) {
141
+ retryParts.push(`**Note**: You are ${currentExecutor} using the ${currentModel} model. This is a more capable model than the previous attempt.\n\n`);
142
+ }
143
+ retryParts.push(`## Previous Attempt Failed With Error:\n\n${lastError}\n\n`);
144
+ retryParts.push(`Please analyze the error carefully and fix it. The error might be due to:\n`);
145
+ retryParts.push(`- Syntax errors\n`);
146
+ retryParts.push(`- Logic errors\n`);
147
+ retryParts.push(`- Missing dependencies or imports\n`);
148
+ retryParts.push(`- Incorrect configuration\n`);
149
+ retryParts.push(`- Build or test failures\n\n`);
150
+ retryParts.push(`Please fix the error above and complete the task successfully.\n\n`);
151
+ retryContext = retryParts.join("");
152
+ }
153
+ // Update executor config for this attempt
154
+ const attemptConfig = {
155
+ ...config,
156
+ tool: currentExecutor,
157
+ executorConfig: {
158
+ ...config.executorConfig,
159
+ model: currentModel,
160
+ continueLastSession: currentAttempt > 1, // Resume session on retries
161
+ },
162
+ };
163
+ try {
164
+ const result = await executeSingleAttempt(task, attemptConfig, attempts, planContent, currentAttempt, maxRetries, retryContext);
165
+ // Check if all verifications passed
166
+ const allVerificationsPassed = result.attempts[result.attempts.length - 1]
167
+ ?.verificationResults?.every((r) => r.success) ?? true;
168
+ if (!allVerificationsPassed) {
169
+ const failedVerification = result.attempts[result.attempts.length - 1]
170
+ ?.verificationResults?.find((r) => !r.success);
171
+ lastError = `Verification command "${failedVerification?.command}" failed:\n${failedVerification?.error}`;
172
+ currentAttempt++;
173
+ continue;
174
+ }
175
+ // ----------------------------------------------------------------------
176
+ // AI REVIEW PHASE
177
+ // ----------------------------------------------------------------------
178
+ if (enableReviewPhase && !dry) {
179
+ const reviewResult = await (0, task_review_1.executeReviewPhase)(task, {
180
+ reviewModel,
181
+ planContent,
182
+ dry,
183
+ });
184
+ if (!reviewResult.approved) {
185
+ lastError = `AI Review Failed:\n${reviewResult.feedback}`;
186
+ console.log(chalk_1.default.red(`❌ AI Review Rejected Changes: ${reviewResult.feedback}`));
187
+ currentAttempt++;
188
+ continue;
189
+ }
190
+ else {
191
+ console.log(chalk_1.default.green(`✅ AI Review Approved: ${reviewResult.feedback}`));
192
+ result.reviewFeedback = reviewResult.feedback;
193
+ }
194
+ }
195
+ // Success! Return the result
196
+ return result;
197
+ }
198
+ catch (error) {
199
+ lastError = error instanceof Error ? error.message : String(error);
200
+ console.log(chalk_1.default.red(`❌ Task execution failed on attempt ${currentAttempt}: ${lastError}`));
201
+ if (!dry && currentAttempt < maxRetries) {
202
+ await tasks_1.taskService.setTaskStatus(task.id, "todo");
203
+ console.log(chalk_1.default.yellow("⏸ Task status reset to todo for retry"));
204
+ }
205
+ currentAttempt++;
206
+ }
207
+ }
208
+ // All retries exhausted
209
+ if (!dry) {
210
+ await tasks_1.taskService.setTaskStatus(task.id, "todo");
211
+ console.log(chalk_1.default.red("❌ All retry attempts exhausted, task status reset to todo"));
212
+ }
213
+ return {
214
+ success: false,
215
+ attempts,
216
+ };
217
+ }
218
+ /**
219
+ * Execute a single attempt of the task
220
+ */
221
+ async function executeSingleAttempt(task, config, attempts, planContent, attemptNumber, maxRetries, retryContext) {
222
+ const { tool, executorConfig, customMessage, verificationCommands = [], autoCommit: enableAutoCommit = false, dry = false, } = config;
223
+ const attemptStartTime = Date.now();
224
+ console.log(chalk_1.default.blue(`🎯 ${dry ? "DRY RUN" : "Executing"} task: ${task.title} (${task.id})`));
225
+ // Capture git state before execution
226
+ const gitStateBefore = await (0, git_utils_1.captureGitState)();
227
+ // Build execution message
228
+ let executionMessage;
229
+ if (customMessage) {
230
+ // Use custom message override
231
+ executionMessage = customMessage;
232
+ console.log(chalk_1.default.cyan("📝 Using custom execution message"));
233
+ }
234
+ else {
235
+ // Build comprehensive execution message with full context
236
+ const contextBuilder = (0, ai_service_factory_1.getContextBuilder)();
237
+ const taskContext = await contextBuilder.buildContext(task.id);
238
+ // Get task plan if available
239
+ const storedPlanData = await tasks_1.taskService.getTaskPlan(task.id);
240
+ let finalPlan;
241
+ if (planContent) {
242
+ finalPlan = `${planContent}\n\nPlease follow this plan to implement the task.`;
243
+ }
244
+ else if (storedPlanData) {
245
+ finalPlan = storedPlanData.plan;
246
+ }
247
+ // Build execution prompt using PromptBuilder
248
+ const promptResult = prompt_builder_1.PromptBuilder.buildExecutionPrompt({
249
+ taskTitle: task.title,
250
+ taskDescription: task.description,
251
+ taskPlan: finalPlan,
252
+ stack: taskContext.stack,
253
+ documentation: taskContext.documentation,
254
+ retryContext,
255
+ });
256
+ if (!promptResult.success) {
257
+ throw new Error(`Failed to build execution prompt: ${promptResult.error}`);
258
+ }
259
+ executionMessage = promptResult.prompt;
260
+ }
261
+ // Update task status to in-progress
262
+ if (!dry) {
263
+ await tasks_1.taskService.setTaskStatus(task.id, "in-progress");
264
+ console.log(chalk_1.default.yellow("⏳ Task status updated to in-progress"));
265
+ }
266
+ // Emit execution:start event
267
+ await hooks_1.hooks.emit("execution:start", { taskId: task.id, tool });
268
+ try {
269
+ // Create executor and run
270
+ const executor = executor_factory_1.ExecutorFactory.create(tool, executorConfig);
271
+ // Log session resumption if applicable
272
+ if (executorConfig?.continueLastSession && attemptNumber > 1) {
273
+ console.log(chalk_1.default.cyan("🔄 Resuming previous session to provide error feedback to AI"));
274
+ }
275
+ await executor.execute(executionMessage, dry, executorConfig);
276
+ // Run verification commands
277
+ const verificationResults = await (0, validation_1.runValidations)(verificationCommands, dry);
278
+ const allVerificationsPassed = verificationResults.every((r) => r.success);
279
+ if (!allVerificationsPassed) {
280
+ const failedVerification = verificationResults.find((r) => !r.success);
281
+ const error = `Verification command "${failedVerification?.command}" failed:\n${failedVerification?.error}`;
282
+ attempts.push({
283
+ attemptNumber,
284
+ success: false,
285
+ error,
286
+ executor: tool,
287
+ model: executorConfig?.model,
288
+ verificationResults,
289
+ timestamp: Date.now() - attemptStartTime,
290
+ });
291
+ console.log(chalk_1.default.red(`❌ Task execution failed verification on attempt ${attemptNumber}`));
292
+ throw new Error(error);
293
+ }
294
+ // Extract commit info if enabled
295
+ let commitInfo;
296
+ if (enableAutoCommit && !dry) {
297
+ console.log(chalk_1.default.blue("📝 Extracting commit information..."));
298
+ const gitStateAfter = await (0, git_utils_1.captureGitState)();
299
+ const gitState = {
300
+ beforeHead: gitStateBefore.beforeHead || "",
301
+ afterHead: gitStateAfter.afterHead || "",
302
+ hasUncommittedChanges: gitStateAfter.hasUncommittedChanges || false,
303
+ };
304
+ commitInfo = await (0, git_utils_1.extractCommitInfo)(task.id, task.title, executionMessage, gitState);
305
+ console.log(chalk_1.default.green(`✅ Commit message: ${commitInfo.message}`));
306
+ if (commitInfo.files.length > 0) {
307
+ console.log(chalk_1.default.green(`📁 Changed files: ${commitInfo.files.join(", ")}`));
308
+ }
309
+ // Auto-commit the changes
310
+ await (0, git_utils_1.autoCommit)(commitInfo);
311
+ }
312
+ // Update task status to completed
313
+ if (!dry) {
314
+ await tasks_1.taskService.setTaskStatus(task.id, "completed");
315
+ console.log(chalk_1.default.green("✅ Task execution completed successfully"));
316
+ }
317
+ // Record successful attempt
318
+ attempts.push({
319
+ attemptNumber,
320
+ success: true,
321
+ executor: tool,
322
+ model: executorConfig?.model,
323
+ verificationResults,
324
+ commitInfo,
325
+ timestamp: Date.now() - attemptStartTime,
326
+ });
327
+ // Emit execution:end event
328
+ await hooks_1.hooks.emit("execution:end", { taskId: task.id, success: true });
329
+ return {
330
+ success: true,
331
+ attempts,
332
+ commitInfo,
333
+ planContent,
334
+ };
335
+ }
336
+ catch (error) {
337
+ const errorMessage = error instanceof Error ? error.message : String(error);
338
+ // Record failed attempt if not already recorded
339
+ if (attempts.length === 0 || attempts[attempts.length - 1].attemptNumber !== attemptNumber) {
340
+ attempts.push({
341
+ attemptNumber,
342
+ success: false,
343
+ error: errorMessage,
344
+ executor: tool,
345
+ model: executorConfig?.model,
346
+ timestamp: Date.now() - attemptStartTime,
347
+ });
348
+ }
349
+ // Emit execution:error event
350
+ await hooks_1.hooks.emit("execution:error", {
351
+ taskId: task.id,
352
+ error: error instanceof Error ? error : new Error(String(error)),
353
+ });
354
+ if (!dry) {
355
+ await tasks_1.taskService.setTaskStatus(task.id, "todo");
356
+ console.log(chalk_1.default.red("❌ Task execution failed, status reset to todo"));
357
+ }
358
+ throw error;
359
+ }
360
+ }
@@ -1,3 +1,7 @@
1
1
  import { ExecuteTaskOptions } from "../types";
2
+ /**
3
+ * Execute a task using an external coding assistant
4
+ * This is the simplified entry point that delegates to the unified core
5
+ */
2
6
  export declare function executeTask(options: ExecuteTaskOptions): Promise<void>;
3
7
  //# sourceMappingURL=task-execution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"task-execution.d.ts","sourceRoot":"","sources":["../../src/lib/task-execution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAgC,MAAM,UAAU,CAAC;AAgM5E,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgF5E"}
1
+ {"version":3,"file":"task-execution.d.ts","sourceRoot":"","sources":["../../src/lib/task-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAEnB,MAAM,UAAU,CAAC;AAGlB;;;GAGG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiD5E"}
@@ -1,186 +1,39 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.executeTask = executeTask;
7
- const tasks_1 = require("../services/tasks");
8
- const executor_factory_1 = require("./executors/executor-factory");
9
- const validation_1 = require("./validation");
10
- const ai_service_factory_1 = require("../utils/ai-service-factory");
11
- const hooks_1 = require("./hooks");
12
- const chalk_1 = __importDefault(require("chalk"));
13
- async function executeSingleTask(taskId, tool, dry, executorConfig) {
14
- // Load task
15
- const task = await tasks_1.taskService.getTask(taskId);
16
- if (!task) {
17
- throw new Error(`Task with ID ${taskId} not found`);
18
- }
19
- console.log(chalk_1.default.blue(`🎯 ${dry ? "DRY RUN" : "Executing"} task: ${task.title} (${taskId})`));
20
- // Build comprehensive execution message with full context
21
- const contextBuilder = (0, ai_service_factory_1.getContextBuilder)();
22
- const taskContext = await contextBuilder.buildContext(taskId);
23
- // Build execution message with ALL context
24
- const messageParts = [];
25
- // Add task plan if available
26
- const planData = await tasks_1.taskService.getTaskPlan(taskId);
27
- if (planData) {
28
- messageParts.push(`# Task Plan\n\n${planData.plan}\n`);
29
- }
30
- else {
31
- messageParts.push(`# Task: ${task.title}\n\n${task.description || "No description"}\n`);
32
- }
33
- // Add PRD context if available
34
- if (taskContext.prdContent) {
35
- messageParts.push(`\n# Product Requirements Document\n\n${taskContext.prdContent}\n`);
36
- }
37
- // Add stack/technology context
38
- if (taskContext.stack) {
39
- messageParts.push(`\n# Technology Stack\n\n`);
40
- messageParts.push(`- **Project**: ${taskContext.stack.projectName}\n`);
41
- messageParts.push(`- **Frontend**: ${taskContext.stack.frontend}\n`);
42
- messageParts.push(`- **Backend**: ${taskContext.stack.backend}\n`);
43
- if (taskContext.stack.database !== "none") {
44
- messageParts.push(`- **Database**: ${taskContext.stack.database}\n`);
45
- }
46
- if (taskContext.stack.orm !== "none") {
47
- messageParts.push(`- **ORM**: ${taskContext.stack.orm}\n`);
48
- }
49
- messageParts.push(`- **Auth**: ${taskContext.stack.auth}\n`);
50
- if (taskContext.stack.addons.length > 0) {
51
- messageParts.push(`- **Addons**: ${taskContext.stack.addons.join(", ")}\n`);
52
- }
53
- messageParts.push(`- **Package Manager**: ${taskContext.stack.packageManager}\n`);
54
- }
55
- // Add documentation context if available
56
- if (taskContext.documentation) {
57
- messageParts.push(`\n# Documentation Context\n\n`);
58
- messageParts.push(`${taskContext.documentation.recap}\n`);
59
- if (taskContext.documentation.files.length > 0) {
60
- messageParts.push(`\n**Relevant Documentation Files**:\n`);
61
- taskContext.documentation.files.forEach((file) => {
62
- messageParts.push(`- ${file.path}\n`);
63
- });
64
- }
65
- }
66
- const executionMessage = messageParts.join("");
67
- if (!dry) {
68
- // Update task status to in-progress
69
- await tasks_1.taskService.setTaskStatus(taskId, "in-progress");
70
- console.log(chalk_1.default.yellow("⏳ Task status updated to in-progress"));
71
- }
72
- // Emit execution:start event
73
- await hooks_1.hooks.emit("execution:start", { taskId, tool });
74
- try {
75
- // Create executor and run
76
- const executor = executor_factory_1.ExecutorFactory.create(tool, executorConfig);
77
- await executor.execute(executionMessage, dry, executorConfig);
78
- if (!dry) {
79
- // Update task status to completed
80
- await tasks_1.taskService.setTaskStatus(taskId, "completed");
81
- console.log(chalk_1.default.green("✅ Task execution completed successfully"));
82
- }
83
- // Emit execution:end event
84
- await hooks_1.hooks.emit("execution:end", { taskId, success: true });
85
- }
86
- catch (error) {
87
- // Emit execution:error event
88
- await hooks_1.hooks.emit("execution:error", {
89
- taskId,
90
- error: error instanceof Error ? error : new Error(String(error)),
91
- });
92
- if (!dry) {
93
- // Update task status back to todo on failure
94
- await tasks_1.taskService.setTaskStatus(taskId, "todo");
95
- console.log(chalk_1.default.red("❌ Task execution failed, status reset to todo"));
96
- }
97
- throw error;
98
- }
99
- }
100
- async function executeTaskWithSubtasks(taskId, tool, dry, executorConfig) {
101
- const task = await tasks_1.taskService.getTask(taskId);
102
- if (!task) {
103
- throw new Error(`Task with ID ${taskId} not found`);
104
- }
105
- // Get subtasks
106
- const subtasks = await tasks_1.taskService.getSubtasks(taskId);
107
- if (subtasks.length === 0) {
108
- // No subtasks, execute this task directly
109
- await executeSingleTask(taskId, tool, dry);
110
- return;
111
- }
112
- // Has subtasks - execute them one by one
113
- console.log(chalk_1.default.blue(`📋 Task has ${subtasks.length} subtasks, executing recursively...`));
114
- for (let i = 0; i < subtasks.length; i++) {
115
- const subtask = subtasks[i];
116
- console.log(chalk_1.default.cyan(`\n[${i + 1}/${subtasks.length}] Executing subtask: ${subtask.title} (${subtask.id})`));
117
- try {
118
- await executeTaskWithSubtasks(subtask.id, tool, dry, executorConfig);
119
- }
120
- catch (error) {
121
- console.error(chalk_1.default.red(`❌ Failed to execute subtask ${subtask.id}: ${error instanceof Error ? error.message : "Unknown error"}`));
122
- throw error;
123
- }
124
- }
125
- // After all subtasks are done, mark the main task as completed
126
- if (!dry) {
127
- await tasks_1.taskService.setTaskStatus(taskId, "completed");
128
- console.log(chalk_1.default.green(`✅ Main task ${task.title} completed after all subtasks`));
129
- }
130
- else {
131
- console.log(chalk_1.default.cyan(`🔍 DRY RUN - Main task ${task.title} would be completed after all subtasks`));
132
- }
133
- }
4
+ const task_execution_core_1 = require("./task-execution-core");
5
+ /**
6
+ * Execute a task using an external coding assistant
7
+ * This is the simplified entry point that delegates to the unified core
8
+ */
134
9
  async function executeTask(options) {
135
- const { taskId, tool = "opencode", message, model, continueSession, dry = false, validate = [], } = options;
136
- // Build executor config from options
137
- const executorConfig = model || continueSession
138
- ? {
10
+ const { taskId, tool = "opencode", message, model, continueSession, dry = false, validate = [], maxRetries, tryModels, plan, planModel, reviewPlan, review, reviewModel, autoCommit, } = options;
11
+ // Build unified task execution config
12
+ const config = {
13
+ tool,
14
+ executorConfig: {
139
15
  model,
140
16
  continueLastSession: continueSession,
141
- }
142
- : undefined;
143
- // If custom message is provided, execute just this task (ignore subtasks)
144
- if (message) {
145
- const task = await tasks_1.taskService.getTask(taskId);
146
- if (!task) {
147
- throw new Error(`Task with ID ${taskId} not found`);
148
- }
149
- console.log(chalk_1.default.blue(`🎯 ${dry ? "DRY RUN - Would execute" : "Executing"} task with custom message: ${task.title} (${taskId})`));
150
- if (!dry) {
151
- await tasks_1.taskService.setTaskStatus(taskId, "in-progress");
152
- console.log(chalk_1.default.yellow("⏳ Task status updated to in-progress"));
153
- }
154
- // Emit execution:start event
155
- await hooks_1.hooks.emit("execution:start", { taskId, tool });
156
- try {
157
- const executor = executor_factory_1.ExecutorFactory.create(tool, executorConfig);
158
- await executor.execute(message, dry, executorConfig);
159
- if (!dry) {
160
- await tasks_1.taskService.setTaskStatus(taskId, "completed");
161
- console.log(chalk_1.default.green("Task execution completed successfully"));
162
- }
163
- // Emit execution:end event
164
- await hooks_1.hooks.emit("execution:end", { taskId, success: true });
165
- // Run validations after task completion
166
- await (0, validation_1.runValidations)(validate, dry);
167
- }
168
- catch (error) {
169
- if (!dry) {
170
- await tasks_1.taskService.setTaskStatus(taskId, "todo");
171
- console.log(chalk_1.default.red("❌ Task execution failed, status reset to todo"));
172
- }
173
- // Emit execution:error event
174
- await hooks_1.hooks.emit("execution:error", {
175
- taskId,
176
- error: error instanceof Error ? error : new Error(String(error)),
177
- });
178
- throw error;
179
- }
180
- return;
17
+ },
18
+ customMessage: message,
19
+ verificationCommands: validate,
20
+ enableRetry: maxRetries !== undefined && maxRetries > 0, // Opt-in retry
21
+ maxRetries: maxRetries || 3,
22
+ tryModels,
23
+ enablePlanPhase: plan,
24
+ planModel,
25
+ reviewPlan,
26
+ enableReviewPhase: review,
27
+ reviewModel,
28
+ autoCommit,
29
+ executeSubtasks: true, // Always execute subtasks in execute command
30
+ dry,
31
+ };
32
+ // Delegate to unified core execution
33
+ const result = await (0, task_execution_core_1.executeTaskCore)(taskId, config);
34
+ // Throw error if execution failed (maintains backward compatibility)
35
+ if (!result.success) {
36
+ const lastAttempt = result.attempts[result.attempts.length - 1];
37
+ throw new Error(lastAttempt?.error || "Task execution failed");
181
38
  }
182
- // No custom message - execute recursively with subtasks
183
- await executeTaskWithSubtasks(taskId, tool, dry, executorConfig);
184
- // Run validations after all subtasks complete
185
- await (0, validation_1.runValidations)(validate, dry);
186
39
  }
@@ -1,25 +1,7 @@
1
1
  import { ExecuteLoopOptions, ExecuteLoopResult } from "../types";
2
- /**
3
- * Extract commit message and file list from AI conversation/output
4
- * This function analyzes the executor's work and generates appropriate commit info
5
- */
6
- /**
7
- * Extract commit message and file list from git state
8
- * This function analyzes the actual git state to generate appropriate commit info
9
- */
10
- export declare function extractCommitInfo(taskId: string, taskTitle: string, executionMessage: string, gitState: {
11
- beforeHead: string;
12
- afterHead: string;
13
- hasUncommittedChanges: boolean;
14
- }, execFn?: (command: string) => Promise<{
15
- stdout: string;
16
- stderr: string;
17
- }>, aiOps?: any): Promise<{
18
- message: string;
19
- files: string[];
20
- }>;
21
2
  /**
22
3
  * Execute multiple tasks in a loop with retry and verification
4
+ * This delegates to the unified executeTaskCore for each task
23
5
  */
24
6
  export declare function executeTaskLoop(options: ExecuteLoopOptions): Promise<ExecuteLoopResult>;
25
7
  //# sourceMappingURL=task-loop-execution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"task-loop-execution.d.ts","sourceRoot":"","sources":["../../src/lib/task-loop-execution.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EAMlB,MAAM,UAAU,CAAC;AAelB;;;GAGG;AACH;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE;IACR,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,qBAAqB,EAAE,OAAO,CAAC;CAChC,EACD,MAAM,GAAE,CACN,OAAO,EAAE,MAAM,KACZ,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAa,EAC5D,KAAK,GAAE,GAAuB,GAC7B,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CA+G/C;AA4pBD;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAmK5B"}
1
+ {"version":3,"file":"task-loop-execution.d.ts","sourceRoot":"","sources":["../../src/lib/task-loop-execution.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EAIlB,MAAM,UAAU,CAAC;AAIlB;;;GAGG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAgL5B"}