task-o-matic 0.0.14 → 0.0.15

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 (110) hide show
  1. package/dist/cli/display/progress.d.ts +15 -2
  2. package/dist/cli/display/progress.d.ts.map +1 -1
  3. package/dist/cli/display/progress.js +72 -4
  4. package/dist/commands/benchmark.d.ts.map +1 -1
  5. package/dist/commands/benchmark.js +11 -3
  6. package/dist/commands/init.d.ts.map +1 -1
  7. package/dist/commands/init.js +19 -4
  8. package/dist/commands/prd.js +7 -1
  9. package/dist/commands/tasks/delete.d.ts.map +1 -1
  10. package/dist/commands/tasks/delete.js +2 -1
  11. package/dist/commands/tasks/document/add.d.ts.map +1 -1
  12. package/dist/commands/tasks/document/add.js +2 -1
  13. package/dist/commands/tasks/document/get.d.ts.map +1 -1
  14. package/dist/commands/tasks/document/get.js +2 -1
  15. package/dist/commands/tasks/plan/set.d.ts.map +1 -1
  16. package/dist/commands/tasks/plan/set.js +11 -3
  17. package/dist/commands/tasks/show.d.ts.map +1 -1
  18. package/dist/commands/tasks/show.js +2 -1
  19. package/dist/commands/tasks/status.d.ts.map +1 -1
  20. package/dist/commands/tasks/status.js +2 -1
  21. package/dist/commands/tasks/update.d.ts.map +1 -1
  22. package/dist/commands/tasks/update.js +7 -1
  23. package/dist/lib/ai-service/model-provider.d.ts.map +1 -1
  24. package/dist/lib/ai-service/model-provider.js +37 -6
  25. package/dist/lib/ai-service/task-operations.d.ts +1 -0
  26. package/dist/lib/ai-service/task-operations.d.ts.map +1 -1
  27. package/dist/lib/ai-service/task-operations.js +135 -173
  28. package/dist/lib/benchmark/registry.d.ts.map +1 -1
  29. package/dist/lib/benchmark/registry.js +6 -10
  30. package/dist/lib/config-validation.d.ts +215 -0
  31. package/dist/lib/config-validation.d.ts.map +1 -0
  32. package/dist/lib/config-validation.js +246 -0
  33. package/dist/lib/config.d.ts.map +1 -1
  34. package/dist/lib/config.js +19 -5
  35. package/dist/lib/storage/file-system.d.ts.map +1 -1
  36. package/dist/lib/storage/file-system.js +81 -21
  37. package/dist/lib/task-execution-core.d.ts.map +1 -1
  38. package/dist/lib/task-execution-core.js +3 -2
  39. package/dist/services/prd.d.ts +17 -0
  40. package/dist/services/prd.d.ts.map +1 -1
  41. package/dist/services/prd.js +49 -15
  42. package/dist/services/tasks.d.ts +315 -1
  43. package/dist/services/tasks.d.ts.map +1 -1
  44. package/dist/services/tasks.js +483 -107
  45. package/dist/services/workflow-ai-assistant.d.ts.map +1 -1
  46. package/dist/services/workflow-ai-assistant.js +19 -6
  47. package/dist/test/lib/ai-service/task-operations.test.d.ts +2 -0
  48. package/dist/test/lib/ai-service/task-operations.test.d.ts.map +1 -0
  49. package/dist/test/lib/ai-service/task-operations.test.js +362 -0
  50. package/dist/test/mocks/mock-ai-operations.d.ts +15 -0
  51. package/dist/test/mocks/mock-ai-operations.d.ts.map +1 -0
  52. package/dist/test/mocks/mock-ai-operations.js +107 -0
  53. package/dist/test/mocks/mock-context-builder.d.ts +10 -0
  54. package/dist/test/mocks/mock-context-builder.d.ts.map +1 -0
  55. package/dist/test/mocks/mock-context-builder.js +81 -0
  56. package/dist/test/mocks/mock-model-provider.d.ts +7 -0
  57. package/dist/test/mocks/mock-model-provider.d.ts.map +1 -0
  58. package/dist/test/mocks/mock-model-provider.js +21 -0
  59. package/dist/test/mocks/mock-service-factory.d.ts +11 -0
  60. package/dist/test/mocks/mock-service-factory.d.ts.map +1 -0
  61. package/dist/test/mocks/mock-service-factory.js +61 -0
  62. package/dist/test/mocks/mock-storage.d.ts +50 -0
  63. package/dist/test/mocks/mock-storage.d.ts.map +1 -0
  64. package/dist/test/mocks/mock-storage.js +145 -0
  65. package/dist/test/services/task-service.test.d.ts +2 -0
  66. package/dist/test/services/task-service.test.d.ts.map +1 -0
  67. package/dist/test/services/task-service.test.js +352 -0
  68. package/dist/test/test-mock-setup.d.ts +26 -0
  69. package/dist/test/test-mock-setup.d.ts.map +1 -0
  70. package/dist/test/test-mock-setup.js +41 -0
  71. package/dist/test/test-setup.d.ts +9 -0
  72. package/dist/test/test-setup.d.ts.map +1 -0
  73. package/dist/test/test-setup.js +44 -0
  74. package/dist/test/test-utils.d.ts +22 -0
  75. package/dist/test/test-utils.d.ts.map +1 -0
  76. package/dist/test/test-utils.js +37 -0
  77. package/dist/test/utils/ai-operation-utility.test.d.ts +2 -0
  78. package/dist/test/utils/ai-operation-utility.test.d.ts.map +1 -0
  79. package/dist/test/utils/ai-operation-utility.test.js +290 -0
  80. package/dist/test/utils/error-handling.test.d.ts +2 -0
  81. package/dist/test/utils/error-handling.test.d.ts.map +1 -0
  82. package/dist/test/utils/error-handling.test.js +231 -0
  83. package/dist/utils/ai-operation-utility.d.ts +142 -0
  84. package/dist/utils/ai-operation-utility.d.ts.map +1 -0
  85. package/dist/utils/ai-operation-utility.js +288 -0
  86. package/dist/utils/ai-service-factory.d.ts +10 -0
  87. package/dist/utils/ai-service-factory.d.ts.map +1 -1
  88. package/dist/utils/ai-service-factory.js +19 -1
  89. package/dist/utils/cli-validators.d.ts +2 -2
  90. package/dist/utils/cli-validators.d.ts.map +1 -1
  91. package/dist/utils/cli-validators.js +7 -6
  92. package/dist/utils/error-utils.d.ts +3 -3
  93. package/dist/utils/error-utils.d.ts.map +1 -1
  94. package/dist/utils/error-utils.js +5 -4
  95. package/dist/utils/file-utils.d.ts +4 -4
  96. package/dist/utils/file-utils.d.ts.map +1 -1
  97. package/dist/utils/file-utils.js +11 -6
  98. package/dist/utils/id-generator.d.ts +1 -1
  99. package/dist/utils/id-generator.d.ts.map +1 -1
  100. package/dist/utils/id-generator.js +8 -2
  101. package/dist/utils/model-executor-parser.d.ts +1 -1
  102. package/dist/utils/model-executor-parser.d.ts.map +1 -1
  103. package/dist/utils/model-executor-parser.js +3 -2
  104. package/dist/utils/storage-utils.d.ts +3 -3
  105. package/dist/utils/storage-utils.d.ts.map +1 -1
  106. package/dist/utils/storage-utils.js +7 -6
  107. package/dist/utils/task-o-matic-error.d.ts +206 -0
  108. package/dist/utils/task-o-matic-error.d.ts.map +1 -0
  109. package/dist/utils/task-o-matic-error.js +304 -0
  110. package/package.json +2 -2
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VALID_EXECUTORS = void 0;
4
4
  exports.parseTryModels = parseTryModels;
5
5
  exports.validateExecutor = validateExecutor;
6
+ const task_o_matic_error_1 = require("./task-o-matic-error");
6
7
  /**
7
8
  * Valid executor tools
8
9
  */
@@ -21,7 +22,7 @@ exports.VALID_EXECUTORS = [
21
22
  *
22
23
  * @param value - Comma-separated model/executor specifications
23
24
  * @returns Array of model attempt configurations
24
- * @throws Error if an invalid executor is specified
25
+ * @throws TaskOMaticError if an invalid executor is specified
25
26
  *
26
27
  * @example
27
28
  * ```typescript
@@ -36,7 +37,7 @@ function parseTryModels(value) {
36
37
  if (trimmed.includes(":")) {
37
38
  const [executor, model] = trimmed.split(":");
38
39
  if (!exports.VALID_EXECUTORS.includes(executor)) {
39
- throw new Error(`Invalid executor "${executor}" in --try-models. Must be one of: ${exports.VALID_EXECUTORS.join(", ")}`);
40
+ throw (0, task_o_matic_error_1.createStandardError)(task_o_matic_error_1.TaskOMaticErrorCodes.INVALID_INPUT, `Invalid executor "${executor}" in --try-models. Must be one of: ${exports.VALID_EXECUTORS.join(", ")}`);
40
41
  }
41
42
  return {
42
43
  executor: executor,
@@ -6,7 +6,7 @@ import { Task } from "../types/index.js";
6
6
  * @param task - Task that may be null
7
7
  * @param taskId - ID of the task for error message
8
8
  * @returns The task if not null
9
- * @throws Error if task is null
9
+ * @throws TaskOMaticError if task is null
10
10
  *
11
11
  * @example
12
12
  * ```typescript
@@ -22,7 +22,7 @@ export declare function requireTask(task: Task | null, taskId: string): Task;
22
22
  * @param tasks - Array of tasks that may contain nulls
23
23
  * @param context - Context for error message (e.g., "subtasks", "dependencies")
24
24
  * @returns Array of tasks with nulls filtered out
25
- * @throws Error if any task is null
25
+ * @throws TaskOMaticError if any task is null
26
26
  */
27
27
  export declare function requireTasks(tasks: (Task | null)[], context?: string): Task[];
28
28
  /**
@@ -43,7 +43,7 @@ export declare function filterNullTasks(tasks: (Task | null)[]): Task[];
43
43
  * Validates that a task ID is a non-empty string.
44
44
  *
45
45
  * @param taskId - Task ID to validate
46
- * @throws Error if task ID is invalid
46
+ * @throws TaskOMaticError if task ID is invalid
47
47
  */
48
48
  export declare function validateTaskId(taskId: string): void;
49
49
  //# sourceMappingURL=storage-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-utils.d.ts","sourceRoot":"","sources":["../../src/utils/storage-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAKnE;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,EACtB,OAAO,GAAE,MAAgB,GACxB,IAAI,EAAE,CAiBR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAInD"}
1
+ {"version":3,"file":"storage-utils.d.ts","sourceRoot":"","sources":["../../src/utils/storage-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAOzC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAKnE;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,EACtB,OAAO,GAAE,MAAgB,GACxB,IAAI,EAAE,CAoBR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAOnD"}
@@ -4,6 +4,7 @@ exports.requireTask = requireTask;
4
4
  exports.requireTasks = requireTasks;
5
5
  exports.filterNullTasks = filterNullTasks;
6
6
  exports.validateTaskId = validateTaskId;
7
+ const task_o_matic_error_1 = require("./task-o-matic-error");
7
8
  /**
8
9
  * Ensures a task is not null, throwing an error if it is.
9
10
  * Useful for enforcing null checks after storage operations.
@@ -11,7 +12,7 @@ exports.validateTaskId = validateTaskId;
11
12
  * @param task - Task that may be null
12
13
  * @param taskId - ID of the task for error message
13
14
  * @returns The task if not null
14
- * @throws Error if task is null
15
+ * @throws TaskOMaticError if task is null
15
16
  *
16
17
  * @example
17
18
  * ```typescript
@@ -22,7 +23,7 @@ exports.validateTaskId = validateTaskId;
22
23
  */
23
24
  function requireTask(task, taskId) {
24
25
  if (!task) {
25
- throw new Error(`Task not found: ${taskId}`);
26
+ throw (0, task_o_matic_error_1.formatTaskNotFoundError)(taskId);
26
27
  }
27
28
  return task;
28
29
  }
@@ -32,7 +33,7 @@ function requireTask(task, taskId) {
32
33
  * @param tasks - Array of tasks that may contain nulls
33
34
  * @param context - Context for error message (e.g., "subtasks", "dependencies")
34
35
  * @returns Array of tasks with nulls filtered out
35
- * @throws Error if any task is null
36
+ * @throws TaskOMaticError if any task is null
36
37
  */
37
38
  function requireTasks(tasks, context = "tasks") {
38
39
  const validTasks = [];
@@ -46,7 +47,7 @@ function requireTasks(tasks, context = "tasks") {
46
47
  }
47
48
  });
48
49
  if (missingIds.length > 0) {
49
- throw new Error(`Missing ${context}: ${missingIds.join(", ")}`);
50
+ throw (0, task_o_matic_error_1.createStandardError)(task_o_matic_error_1.TaskOMaticErrorCodes.STORAGE_INTEGRITY_ERROR, `Missing ${context}: ${missingIds.join(", ")}`);
50
51
  }
51
52
  return validTasks;
52
53
  }
@@ -70,10 +71,10 @@ function filterNullTasks(tasks) {
70
71
  * Validates that a task ID is a non-empty string.
71
72
  *
72
73
  * @param taskId - Task ID to validate
73
- * @throws Error if task ID is invalid
74
+ * @throws TaskOMaticError if task ID is invalid
74
75
  */
75
76
  function validateTaskId(taskId) {
76
77
  if (!taskId || typeof taskId !== "string" || !taskId.trim()) {
77
- throw new Error("Invalid task ID: must be a non-empty string");
78
+ throw (0, task_o_matic_error_1.createStandardError)(task_o_matic_error_1.TaskOMaticErrorCodes.INVALID_INPUT, "Invalid task ID: must be a non-empty string");
78
79
  }
79
80
  }
@@ -0,0 +1,206 @@
1
+ /**
2
+ * TaskOMaticError - Standardized error class for TaskOMatic
3
+ *
4
+ * Provides consistent error handling with context, suggestions, and typing.
5
+ * All errors in the system should use this class or one of the helper functions
6
+ * to ensure consistent error reporting and debugging experience.
7
+ *
8
+ * @example Basic usage
9
+ * ```typescript
10
+ * throw new TaskOMaticError("Task not found", {
11
+ * code: "TASK_NOT_FOUND",
12
+ * context: "Attempted to retrieve task ID: 123",
13
+ * suggestions: [
14
+ * "Verify the task ID is correct",
15
+ * "Check if the task was deleted"
16
+ * ]
17
+ * });
18
+ * ```
19
+ *
20
+ * @example With cause chain
21
+ * ```typescript
22
+ * try {
23
+ * await storage.getTask(id);
24
+ * } catch (error) {
25
+ * throw new TaskOMaticError("Failed to retrieve task", {
26
+ * code: "STORAGE_ERROR",
27
+ * cause: error instanceof Error ? error : new Error(String(error)),
28
+ * context: `Task ID: ${id}`,
29
+ * suggestions: ["Check storage permissions", "Verify storage is initialized"]
30
+ * });
31
+ * }
32
+ * ```
33
+ *
34
+ * @example With metadata
35
+ * ```typescript
36
+ * throw new TaskOMaticError("AI operation timed out", {
37
+ * code: "AI_OPERATION_FAILED",
38
+ * metadata: {
39
+ * operation: "task-breakdown",
40
+ * duration: 30000,
41
+ * retryAttempts: 3
42
+ * },
43
+ * suggestions: ["Increase timeout", "Check AI service status"]
44
+ * });
45
+ * ```
46
+ */
47
+ export declare class TaskOMaticError extends Error {
48
+ /**
49
+ * Error code for categorization
50
+ */
51
+ code: string;
52
+ /**
53
+ * Additional context information
54
+ */
55
+ context?: string;
56
+ /**
57
+ * Actionable suggestions for resolving the error
58
+ */
59
+ suggestions?: string[];
60
+ /**
61
+ * Original error that caused this error (if applicable)
62
+ */
63
+ cause?: Error;
64
+ /**
65
+ * Timestamp when the error occurred
66
+ */
67
+ timestamp: number;
68
+ /**
69
+ * Additional metadata for debugging
70
+ */
71
+ metadata?: Record<string, unknown>;
72
+ /**
73
+ * Create a new TaskOMaticError
74
+ *
75
+ * @param message - Error message
76
+ * @param options - Additional error options
77
+ */
78
+ constructor(message: string, options: {
79
+ code: string;
80
+ context?: string;
81
+ suggestions?: string[];
82
+ cause?: Error;
83
+ metadata?: Record<string, unknown>;
84
+ });
85
+ /**
86
+ * Get full error details as a formatted string
87
+ */
88
+ getDetails(): string;
89
+ /**
90
+ * Get error details as a structured object
91
+ */
92
+ toJSON(): {
93
+ name: string;
94
+ code: string;
95
+ message: string;
96
+ context?: string;
97
+ suggestions?: string[];
98
+ cause?: string;
99
+ timestamp: number;
100
+ metadata?: Record<string, unknown>;
101
+ stack?: string;
102
+ };
103
+ }
104
+ /**
105
+ * Standard error codes for TaskOMatic
106
+ */
107
+ export declare const TaskOMaticErrorCodes: {
108
+ readonly UNEXPECTED_ERROR: "TASK_O_MATIC_001";
109
+ readonly INVALID_INPUT: "TASK_O_MATIC_002";
110
+ readonly CONFIGURATION_ERROR: "TASK_O_MATIC_003";
111
+ readonly TASK_NOT_FOUND: "TASK_O_MATIC_101";
112
+ readonly TASK_ALREADY_EXISTS: "TASK_O_MATIC_102";
113
+ readonly INVALID_TASK_STATUS: "TASK_O_MATIC_103";
114
+ readonly TASK_OPERATION_FAILED: "TASK_O_MATIC_104";
115
+ readonly STORAGE_ERROR: "TASK_O_MATIC_201";
116
+ readonly STORAGE_NOT_INITIALIZED: "TASK_O_MATIC_202";
117
+ readonly STORAGE_INTEGRITY_ERROR: "TASK_O_MATIC_203";
118
+ readonly AI_OPERATION_FAILED: "TASK_O_MATIC_301";
119
+ readonly AI_CONFIGURATION_ERROR: "TASK_O_MATIC_302";
120
+ readonly AI_RATE_LIMIT: "TASK_O_MATIC_303";
121
+ readonly WORKFLOW_VALIDATION_ERROR: "TASK_O_MATIC_401";
122
+ readonly WORKFLOW_EXECUTION_ERROR: "TASK_O_MATIC_402";
123
+ readonly PRD_PARSING_ERROR: "TASK_O_MATIC_501";
124
+ readonly PRD_GENERATION_ERROR: "TASK_O_MATIC_502";
125
+ readonly PRD_VALIDATION_ERROR: "TASK_O_MATIC_503";
126
+ };
127
+ type TaskOMaticErrorCode = (typeof TaskOMaticErrorCodes)[keyof typeof TaskOMaticErrorCodes];
128
+ /**
129
+ * Create a standardized error with context and suggestions
130
+ *
131
+ * Helper function to create TaskOMaticError instances with proper error codes
132
+ * from the TaskOMaticErrorCodes constants.
133
+ *
134
+ * @param code - Error code from TaskOMaticErrorCodes
135
+ * @param message - Human-readable error message
136
+ * @param options - Additional error options
137
+ * @returns Configured TaskOMaticError instance
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * throw createStandardError(
142
+ * TaskOMaticErrorCodes.TASK_NOT_FOUND,
143
+ * "Task with ID '123' not found",
144
+ * {
145
+ * context: "User attempted to retrieve non-existent task",
146
+ * suggestions: ["Verify task ID", "List all tasks to see available IDs"]
147
+ * }
148
+ * );
149
+ * ```
150
+ */
151
+ export declare function createStandardError(code: TaskOMaticErrorCode, message: string, options?: {
152
+ context?: string;
153
+ suggestions?: string[];
154
+ cause?: Error;
155
+ metadata?: Record<string, unknown>;
156
+ }): TaskOMaticError;
157
+ /**
158
+ * Format an existing error into a TaskOMaticError with context and suggestions
159
+ *
160
+ * Useful for wrapping caught errors with additional context while preserving
161
+ * the original error as the cause.
162
+ *
163
+ * @param error - Original error to wrap
164
+ * @param code - Error code from TaskOMaticErrorCodes
165
+ * @param options - Additional error options
166
+ * @returns TaskOMaticError wrapping the original error
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * try {
171
+ * await dangerousOperation();
172
+ * } catch (error) {
173
+ * throw formatStandardError(
174
+ * error,
175
+ * TaskOMaticErrorCodes.STORAGE_ERROR,
176
+ * {
177
+ * context: "Failed during task persistence",
178
+ * suggestions: ["Check disk space", "Verify write permissions"]
179
+ * }
180
+ * );
181
+ * }
182
+ * ```
183
+ */
184
+ export declare function formatStandardError(error: unknown, code: TaskOMaticErrorCode, options?: {
185
+ context?: string;
186
+ suggestions?: string[];
187
+ metadata?: Record<string, unknown>;
188
+ }): TaskOMaticError;
189
+ /**
190
+ * Type guard for TaskOMaticError
191
+ */
192
+ export declare function isTaskOMaticError(error: unknown): error is TaskOMaticError;
193
+ /**
194
+ * Common error formatting functions
195
+ */
196
+ export declare function formatTaskNotFoundError(taskId: string): TaskOMaticError;
197
+ export declare function formatInvalidStatusTransitionError(fromStatus: string, toStatus: string): TaskOMaticError;
198
+ export declare function formatStorageError(operation: string, cause?: Error): TaskOMaticError;
199
+ export declare function formatAIOperationError(operation: string, cause?: Error): TaskOMaticError;
200
+ /**
201
+ * Backward compatibility wrapper
202
+ * Maintains existing error handling patterns while using new error system
203
+ */
204
+ export declare function wrapErrorForBackwardCompatibility(error: unknown, context?: string): Error;
205
+ export {};
206
+ //# sourceMappingURL=task-o-matic-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task-o-matic-error.d.ts","sourceRoot":"","sources":["../../src/utils/task-o-matic-error.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,304 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskOMaticErrorCodes = exports.TaskOMaticError = void 0;
4
+ exports.createStandardError = createStandardError;
5
+ exports.formatStandardError = formatStandardError;
6
+ exports.isTaskOMaticError = isTaskOMaticError;
7
+ exports.formatTaskNotFoundError = formatTaskNotFoundError;
8
+ exports.formatInvalidStatusTransitionError = formatInvalidStatusTransitionError;
9
+ exports.formatStorageError = formatStorageError;
10
+ exports.formatAIOperationError = formatAIOperationError;
11
+ exports.wrapErrorForBackwardCompatibility = wrapErrorForBackwardCompatibility;
12
+ const error_utils_1 = require("./error-utils");
13
+ /**
14
+ * TaskOMaticError - Standardized error class for TaskOMatic
15
+ *
16
+ * Provides consistent error handling with context, suggestions, and typing.
17
+ * All errors in the system should use this class or one of the helper functions
18
+ * to ensure consistent error reporting and debugging experience.
19
+ *
20
+ * @example Basic usage
21
+ * ```typescript
22
+ * throw new TaskOMaticError("Task not found", {
23
+ * code: "TASK_NOT_FOUND",
24
+ * context: "Attempted to retrieve task ID: 123",
25
+ * suggestions: [
26
+ * "Verify the task ID is correct",
27
+ * "Check if the task was deleted"
28
+ * ]
29
+ * });
30
+ * ```
31
+ *
32
+ * @example With cause chain
33
+ * ```typescript
34
+ * try {
35
+ * await storage.getTask(id);
36
+ * } catch (error) {
37
+ * throw new TaskOMaticError("Failed to retrieve task", {
38
+ * code: "STORAGE_ERROR",
39
+ * cause: error instanceof Error ? error : new Error(String(error)),
40
+ * context: `Task ID: ${id}`,
41
+ * suggestions: ["Check storage permissions", "Verify storage is initialized"]
42
+ * });
43
+ * }
44
+ * ```
45
+ *
46
+ * @example With metadata
47
+ * ```typescript
48
+ * throw new TaskOMaticError("AI operation timed out", {
49
+ * code: "AI_OPERATION_FAILED",
50
+ * metadata: {
51
+ * operation: "task-breakdown",
52
+ * duration: 30000,
53
+ * retryAttempts: 3
54
+ * },
55
+ * suggestions: ["Increase timeout", "Check AI service status"]
56
+ * });
57
+ * ```
58
+ */
59
+ class TaskOMaticError extends Error {
60
+ /**
61
+ * Error code for categorization
62
+ */
63
+ code;
64
+ /**
65
+ * Additional context information
66
+ */
67
+ context;
68
+ /**
69
+ * Actionable suggestions for resolving the error
70
+ */
71
+ suggestions;
72
+ /**
73
+ * Original error that caused this error (if applicable)
74
+ */
75
+ cause;
76
+ /**
77
+ * Timestamp when the error occurred
78
+ */
79
+ timestamp;
80
+ /**
81
+ * Additional metadata for debugging
82
+ */
83
+ metadata;
84
+ /**
85
+ * Create a new TaskOMaticError
86
+ *
87
+ * @param message - Error message
88
+ * @param options - Additional error options
89
+ */
90
+ constructor(message, options) {
91
+ super(message);
92
+ this.name = "TaskOMaticError";
93
+ this.code = options.code;
94
+ this.context = options.context;
95
+ this.suggestions = options.suggestions;
96
+ this.cause = options.cause;
97
+ this.timestamp = Date.now();
98
+ this.metadata = options.metadata;
99
+ // Maintain proper stack trace
100
+ if (Error.captureStackTrace) {
101
+ Error.captureStackTrace(this, TaskOMaticError);
102
+ }
103
+ }
104
+ /**
105
+ * Get full error details as a formatted string
106
+ */
107
+ getDetails() {
108
+ let details = `[${this.code}] ${this.message}`;
109
+ if (this.context) {
110
+ details += `\nContext: ${this.context}`;
111
+ }
112
+ if (this.suggestions && this.suggestions.length > 0) {
113
+ details += `\nSuggestions:\n- ${this.suggestions.join("\n- ")}`;
114
+ }
115
+ if (this.cause) {
116
+ details += `\nCaused by: ${this.cause.message}`;
117
+ }
118
+ if (this.metadata && Object.keys(this.metadata).length > 0) {
119
+ details += `\nMetadata: ${JSON.stringify(this.metadata, null, 2)}`;
120
+ }
121
+ return details;
122
+ }
123
+ /**
124
+ * Get error details as a structured object
125
+ */
126
+ toJSON() {
127
+ return {
128
+ name: this.name,
129
+ code: this.code,
130
+ message: this.message,
131
+ context: this.context,
132
+ suggestions: this.suggestions,
133
+ cause: this.cause?.message,
134
+ timestamp: this.timestamp,
135
+ metadata: this.metadata,
136
+ stack: this.stack,
137
+ };
138
+ }
139
+ }
140
+ exports.TaskOMaticError = TaskOMaticError;
141
+ /**
142
+ * Standard error codes for TaskOMatic
143
+ */
144
+ exports.TaskOMaticErrorCodes = {
145
+ // General errors
146
+ UNEXPECTED_ERROR: "TASK_O_MATIC_001",
147
+ INVALID_INPUT: "TASK_O_MATIC_002",
148
+ CONFIGURATION_ERROR: "TASK_O_MATIC_003",
149
+ // Task-related errors
150
+ TASK_NOT_FOUND: "TASK_O_MATIC_101",
151
+ TASK_ALREADY_EXISTS: "TASK_O_MATIC_102",
152
+ INVALID_TASK_STATUS: "TASK_O_MATIC_103",
153
+ TASK_OPERATION_FAILED: "TASK_O_MATIC_104",
154
+ // Storage errors
155
+ STORAGE_ERROR: "TASK_O_MATIC_201",
156
+ STORAGE_NOT_INITIALIZED: "TASK_O_MATIC_202",
157
+ STORAGE_INTEGRITY_ERROR: "TASK_O_MATIC_203",
158
+ // AI operation errors
159
+ AI_OPERATION_FAILED: "TASK_O_MATIC_301",
160
+ AI_CONFIGURATION_ERROR: "TASK_O_MATIC_302",
161
+ AI_RATE_LIMIT: "TASK_O_MATIC_303",
162
+ // Workflow errors
163
+ WORKFLOW_VALIDATION_ERROR: "TASK_O_MATIC_401",
164
+ WORKFLOW_EXECUTION_ERROR: "TASK_O_MATIC_402",
165
+ // PRD errors
166
+ PRD_PARSING_ERROR: "TASK_O_MATIC_501",
167
+ PRD_GENERATION_ERROR: "TASK_O_MATIC_502",
168
+ PRD_VALIDATION_ERROR: "TASK_O_MATIC_503",
169
+ };
170
+ /**
171
+ * Create a standardized error with context and suggestions
172
+ *
173
+ * Helper function to create TaskOMaticError instances with proper error codes
174
+ * from the TaskOMaticErrorCodes constants.
175
+ *
176
+ * @param code - Error code from TaskOMaticErrorCodes
177
+ * @param message - Human-readable error message
178
+ * @param options - Additional error options
179
+ * @returns Configured TaskOMaticError instance
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * throw createStandardError(
184
+ * TaskOMaticErrorCodes.TASK_NOT_FOUND,
185
+ * "Task with ID '123' not found",
186
+ * {
187
+ * context: "User attempted to retrieve non-existent task",
188
+ * suggestions: ["Verify task ID", "List all tasks to see available IDs"]
189
+ * }
190
+ * );
191
+ * ```
192
+ */
193
+ function createStandardError(code, message, options = {}) {
194
+ return new TaskOMaticError(message, {
195
+ code,
196
+ context: options.context,
197
+ suggestions: options.suggestions,
198
+ cause: options.cause,
199
+ metadata: options.metadata,
200
+ });
201
+ }
202
+ /**
203
+ * Format an existing error into a TaskOMaticError with context and suggestions
204
+ *
205
+ * Useful for wrapping caught errors with additional context while preserving
206
+ * the original error as the cause.
207
+ *
208
+ * @param error - Original error to wrap
209
+ * @param code - Error code from TaskOMaticErrorCodes
210
+ * @param options - Additional error options
211
+ * @returns TaskOMaticError wrapping the original error
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * try {
216
+ * await dangerousOperation();
217
+ * } catch (error) {
218
+ * throw formatStandardError(
219
+ * error,
220
+ * TaskOMaticErrorCodes.STORAGE_ERROR,
221
+ * {
222
+ * context: "Failed during task persistence",
223
+ * suggestions: ["Check disk space", "Verify write permissions"]
224
+ * }
225
+ * );
226
+ * }
227
+ * ```
228
+ */
229
+ function formatStandardError(error, code, options = {}) {
230
+ const message = (0, error_utils_1.getErrorMessage)(error);
231
+ const cause = error instanceof Error ? error : undefined;
232
+ return new TaskOMaticError(message, {
233
+ code,
234
+ context: options.context,
235
+ suggestions: options.suggestions,
236
+ cause,
237
+ metadata: options.metadata,
238
+ });
239
+ }
240
+ /**
241
+ * Type guard for TaskOMaticError
242
+ */
243
+ function isTaskOMaticError(error) {
244
+ return error instanceof TaskOMaticError;
245
+ }
246
+ /**
247
+ * Common error formatting functions
248
+ */
249
+ function formatTaskNotFoundError(taskId) {
250
+ return createStandardError(exports.TaskOMaticErrorCodes.TASK_NOT_FOUND, `Task with ID "${taskId}" not found`, {
251
+ context: `The task "${taskId}" could not be found in the storage.`,
252
+ suggestions: [
253
+ "Verify the task ID is correct",
254
+ "Check if the task was deleted",
255
+ "List all tasks to see available IDs",
256
+ ],
257
+ });
258
+ }
259
+ function formatInvalidStatusTransitionError(fromStatus, toStatus) {
260
+ return createStandardError(exports.TaskOMaticErrorCodes.INVALID_TASK_STATUS, `Invalid status transition from "${fromStatus}" to "${toStatus}"`, {
261
+ context: `Task status transitions must follow the workflow: todo -> in-progress -> completed.`,
262
+ suggestions: [
263
+ "Use a valid status transition",
264
+ "Check the current task status",
265
+ "Review the workflow documentation",
266
+ ],
267
+ });
268
+ }
269
+ function formatStorageError(operation, cause) {
270
+ return createStandardError(exports.TaskOMaticErrorCodes.STORAGE_ERROR, `Storage operation "${operation}" failed`, {
271
+ context: `The storage operation "${operation}" could not be completed.`,
272
+ suggestions: [
273
+ "Check storage permissions",
274
+ "Verify storage configuration",
275
+ "Review storage logs for details",
276
+ ],
277
+ cause,
278
+ });
279
+ }
280
+ function formatAIOperationError(operation, cause) {
281
+ return createStandardError(exports.TaskOMaticErrorCodes.AI_OPERATION_FAILED, `AI operation "${operation}" failed`, {
282
+ context: `The AI operation "${operation}" could not be completed.`,
283
+ suggestions: [
284
+ "Check AI configuration",
285
+ "Verify API keys and endpoints",
286
+ "Review AI service status",
287
+ "Check rate limits",
288
+ ],
289
+ cause,
290
+ });
291
+ }
292
+ /**
293
+ * Backward compatibility wrapper
294
+ * Maintains existing error handling patterns while using new error system
295
+ */
296
+ function wrapErrorForBackwardCompatibility(error, context) {
297
+ if (isTaskOMaticError(error)) {
298
+ return error;
299
+ }
300
+ if (error instanceof Error) {
301
+ return error;
302
+ }
303
+ return new Error((0, error_utils_1.formatError)(error, context));
304
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "task-o-matic",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "AI-powered task management CLI",
5
5
  "keywords": [
6
6
  "task-management",
@@ -50,7 +50,7 @@
50
50
  "dev:mcp": "tsx src/mcp/server.ts",
51
51
  "start": "node dist/cli/bin.js",
52
52
  "check-types": "tsc --noEmit --skipLibCheck",
53
- "test": "mocha -r tsx/cjs src/test/**/*.test.ts",
53
+ "test": "mocha -r tsx/cjs src/test/test-setup.ts src/test/**/*.test.ts",
54
54
  "prepare": "npm run build && chmod +x dist/cli/bin.js",
55
55
  "prepublishOnly": "bun run build && chmod +x dist/cli/bin.js && bun test"
56
56
  },