task-o-matic 0.0.12 → 0.0.14

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 (150) hide show
  1. package/dist/commands/init.js +41 -8
  2. package/dist/commands/tasks/create.d.ts.map +1 -1
  3. package/dist/commands/tasks/create.js +6 -13
  4. package/dist/commands/tasks/document/add.d.ts +3 -0
  5. package/dist/commands/tasks/document/add.d.ts.map +1 -0
  6. package/dist/commands/tasks/document/add.js +35 -0
  7. package/dist/commands/tasks/document/analyze.d.ts +3 -0
  8. package/dist/commands/tasks/document/analyze.d.ts.map +1 -0
  9. package/dist/commands/tasks/document/analyze.js +49 -0
  10. package/dist/commands/tasks/document/get.d.ts +3 -0
  11. package/dist/commands/tasks/document/get.d.ts.map +1 -0
  12. package/dist/commands/tasks/document/get.js +29 -0
  13. package/dist/commands/tasks/document/index.d.ts +8 -0
  14. package/dist/commands/tasks/document/index.d.ts.map +1 -0
  15. package/dist/commands/tasks/document/index.js +13 -0
  16. package/dist/commands/tasks/enhance.d.ts.map +1 -1
  17. package/dist/commands/tasks/enhance.js +64 -61
  18. package/dist/commands/tasks/execute-loop.d.ts.map +1 -1
  19. package/dist/commands/tasks/execute-loop.js +64 -90
  20. package/dist/commands/tasks/execute.d.ts.map +1 -1
  21. package/dist/commands/tasks/execute.js +52 -16
  22. package/dist/commands/tasks/list.js +2 -2
  23. package/dist/commands/tasks/next.js +4 -4
  24. package/dist/commands/tasks/plan/create.d.ts +3 -0
  25. package/dist/commands/tasks/plan/create.d.ts.map +1 -0
  26. package/dist/commands/tasks/plan/create.js +37 -0
  27. package/dist/commands/tasks/plan/delete.d.ts +3 -0
  28. package/dist/commands/tasks/plan/delete.d.ts.map +1 -0
  29. package/dist/commands/tasks/plan/delete.js +14 -0
  30. package/dist/commands/tasks/plan/get.d.ts +3 -0
  31. package/dist/commands/tasks/plan/get.d.ts.map +1 -0
  32. package/dist/commands/tasks/plan/get.js +24 -0
  33. package/dist/commands/tasks/plan/index.d.ts +10 -0
  34. package/dist/commands/tasks/plan/index.d.ts.map +1 -0
  35. package/dist/commands/tasks/plan/index.js +17 -0
  36. package/dist/commands/tasks/plan/list.d.ts +3 -0
  37. package/dist/commands/tasks/plan/list.d.ts.map +1 -0
  38. package/dist/commands/tasks/plan/list.js +21 -0
  39. package/dist/commands/tasks/plan/set.d.ts +3 -0
  40. package/dist/commands/tasks/plan/set.d.ts.map +1 -0
  41. package/dist/commands/tasks/plan/set.js +33 -0
  42. package/dist/commands/tasks/split.d.ts.map +1 -1
  43. package/dist/commands/tasks/split.js +65 -60
  44. package/dist/commands/tasks/status.js +2 -2
  45. package/dist/lib/ai-service/ai-operations.d.ts +1 -1
  46. package/dist/lib/ai-service/ai-operations.d.ts.map +1 -1
  47. package/dist/lib/ai-service/base-operations.d.ts +22 -0
  48. package/dist/lib/ai-service/base-operations.d.ts.map +1 -1
  49. package/dist/lib/ai-service/base-operations.js +29 -1
  50. package/dist/lib/ai-service/task-operations.d.ts +1 -1
  51. package/dist/lib/ai-service/task-operations.d.ts.map +1 -1
  52. package/dist/lib/better-t-stack-cli.d.ts +36 -21
  53. package/dist/lib/better-t-stack-cli.d.ts.map +1 -1
  54. package/dist/lib/better-t-stack-cli.js +212 -33
  55. package/dist/lib/bootstrap/cli-bootstrap.d.ts +14 -0
  56. package/dist/lib/bootstrap/cli-bootstrap.d.ts.map +1 -0
  57. package/dist/lib/bootstrap/cli-bootstrap.js +325 -0
  58. package/dist/lib/bootstrap/index.d.ts +4 -0
  59. package/dist/lib/bootstrap/index.d.ts.map +1 -0
  60. package/dist/lib/bootstrap/index.js +19 -0
  61. package/dist/lib/bootstrap/medusa-bootstrap.d.ts +14 -0
  62. package/dist/lib/bootstrap/medusa-bootstrap.d.ts.map +1 -0
  63. package/dist/lib/bootstrap/medusa-bootstrap.js +218 -0
  64. package/dist/lib/bootstrap/opentui-bootstrap.d.ts +11 -0
  65. package/dist/lib/bootstrap/opentui-bootstrap.d.ts.map +1 -0
  66. package/dist/lib/bootstrap/opentui-bootstrap.js +342 -0
  67. package/dist/lib/config.d.ts +14 -0
  68. package/dist/lib/config.d.ts.map +1 -1
  69. package/dist/lib/config.js +18 -0
  70. package/dist/lib/git-utils.d.ts +45 -0
  71. package/dist/lib/git-utils.d.ts.map +1 -0
  72. package/dist/lib/git-utils.js +160 -0
  73. package/dist/lib/task-execution-core.d.ts +7 -0
  74. package/dist/lib/task-execution-core.d.ts.map +1 -0
  75. package/dist/lib/task-execution-core.js +360 -0
  76. package/dist/lib/task-execution.d.ts +4 -0
  77. package/dist/lib/task-execution.d.ts.map +1 -1
  78. package/dist/lib/task-execution.js +31 -149
  79. package/dist/lib/task-loop-execution.d.ts +1 -19
  80. package/dist/lib/task-loop-execution.d.ts.map +1 -1
  81. package/dist/lib/task-loop-execution.js +50 -585
  82. package/dist/lib/task-planning.d.ts +28 -0
  83. package/dist/lib/task-planning.d.ts.map +1 -0
  84. package/dist/lib/task-planning.js +109 -0
  85. package/dist/lib/task-review.d.ts +27 -0
  86. package/dist/lib/task-review.d.ts.map +1 -0
  87. package/dist/lib/task-review.js +106 -0
  88. package/dist/lib/validation.d.ts +20 -3
  89. package/dist/lib/validation.d.ts.map +1 -1
  90. package/dist/lib/validation.js +39 -10
  91. package/dist/services/prd.d.ts.map +1 -1
  92. package/dist/services/prd.js +18 -45
  93. package/dist/services/tasks.d.ts +2 -2
  94. package/dist/services/tasks.d.ts.map +1 -1
  95. package/dist/services/tasks.js +55 -85
  96. package/dist/test/task-loop-git.test.js +6 -6
  97. package/dist/types/cli-options.d.ts +138 -0
  98. package/dist/types/cli-options.d.ts.map +1 -0
  99. package/dist/types/cli-options.js +6 -0
  100. package/dist/types/index.d.ts +74 -1
  101. package/dist/types/index.d.ts.map +1 -1
  102. package/dist/types/results.d.ts +60 -6
  103. package/dist/types/results.d.ts.map +1 -1
  104. package/dist/utils/bulk-operations.d.ts +51 -0
  105. package/dist/utils/bulk-operations.d.ts.map +1 -0
  106. package/dist/utils/bulk-operations.js +68 -0
  107. package/dist/utils/cli-validators.d.ts +54 -0
  108. package/dist/utils/cli-validators.d.ts.map +1 -0
  109. package/dist/utils/cli-validators.js +75 -0
  110. package/dist/utils/command-error-handler.d.ts +32 -0
  111. package/dist/utils/command-error-handler.d.ts.map +1 -0
  112. package/dist/utils/command-error-handler.js +52 -0
  113. package/dist/utils/confirmation.d.ts +19 -0
  114. package/dist/utils/confirmation.d.ts.map +1 -0
  115. package/dist/utils/confirmation.js +39 -0
  116. package/dist/utils/display-helpers.d.ts +81 -0
  117. package/dist/utils/display-helpers.d.ts.map +1 -0
  118. package/dist/utils/display-helpers.js +109 -0
  119. package/dist/utils/error-utils.d.ts +70 -0
  120. package/dist/utils/error-utils.d.ts.map +1 -0
  121. package/dist/utils/error-utils.js +103 -0
  122. package/dist/utils/file-utils.d.ts +49 -0
  123. package/dist/utils/file-utils.d.ts.map +1 -0
  124. package/dist/utils/file-utils.js +77 -0
  125. package/dist/utils/id-generator.d.ts +92 -0
  126. package/dist/utils/id-generator.d.ts.map +1 -0
  127. package/dist/utils/id-generator.js +140 -0
  128. package/dist/utils/model-executor-parser.d.ts +38 -0
  129. package/dist/utils/model-executor-parser.d.ts.map +1 -0
  130. package/dist/utils/model-executor-parser.js +67 -0
  131. package/dist/utils/progress-tracking.d.ts +28 -0
  132. package/dist/utils/progress-tracking.d.ts.map +1 -0
  133. package/dist/utils/progress-tracking.js +43 -0
  134. package/dist/utils/stack-formatter.d.ts +2 -1
  135. package/dist/utils/stack-formatter.d.ts.map +1 -1
  136. package/dist/utils/stack-formatter.js +8 -2
  137. package/dist/utils/storage-utils.d.ts +49 -0
  138. package/dist/utils/storage-utils.d.ts.map +1 -0
  139. package/dist/utils/storage-utils.js +79 -0
  140. package/dist/utils/streaming-utils.d.ts +38 -0
  141. package/dist/utils/streaming-utils.d.ts.map +1 -0
  142. package/dist/utils/streaming-utils.js +56 -0
  143. package/docs/agents/cli.md +58 -149
  144. package/package.json +1 -1
  145. package/dist/commands/tasks/document.d.ts +0 -5
  146. package/dist/commands/tasks/document.d.ts.map +0 -1
  147. package/dist/commands/tasks/document.js +0 -118
  148. package/dist/commands/tasks/plan.d.ts +0 -7
  149. package/dist/commands/tasks/plan.d.ts.map +0 -1
  150. package/dist/commands/tasks/plan.js +0 -131
@@ -0,0 +1,109 @@
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.displayOperationStart = displayOperationStart;
7
+ exports.displayOperationSuccess = displayOperationSuccess;
8
+ exports.displayOperationError = displayOperationError;
9
+ exports.displayBulkProgress = displayBulkProgress;
10
+ exports.displaySeparator = displaySeparator;
11
+ exports.displaySectionHeader = displaySectionHeader;
12
+ const chalk_1 = __importDefault(require("chalk"));
13
+ /**
14
+ * Display the start of an operation
15
+ *
16
+ * @param operation - Name of the operation (e.g., "Enhancing", "Splitting")
17
+ * @param target - Target of the operation (e.g., task title, file name)
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * displayOperationStart("Enhancing", "task-123");
22
+ * // Output: 🚀 Enhancing task-123...
23
+ * ```
24
+ */
25
+ function displayOperationStart(operation, target) {
26
+ console.log(chalk_1.default.blue(`\n🚀 ${operation} ${target}...`));
27
+ }
28
+ /**
29
+ * Display successful completion of an operation
30
+ *
31
+ * @param operation - Name of the operation
32
+ * @param details - Optional details to append
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * displayOperationSuccess("Enhancement", "with Context7");
37
+ * // Output: ✅ Enhancement completed successfully: with Context7
38
+ * ```
39
+ */
40
+ function displayOperationSuccess(operation, details) {
41
+ const message = details
42
+ ? `✅ ${operation} completed successfully: ${details}`
43
+ : `✅ ${operation} completed successfully`;
44
+ console.log(chalk_1.default.green(message));
45
+ }
46
+ /**
47
+ * Display an operation error
48
+ *
49
+ * @param operation - Name of the operation
50
+ * @param error - The error that occurred
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * displayOperationError("Enhancement", new Error("API failed"));
55
+ * // Output: ❌ Enhancement failed: API failed
56
+ * ```
57
+ */
58
+ function displayOperationError(operation, error) {
59
+ console.log(chalk_1.default.red(`❌ ${operation} failed: ${error.message}`));
60
+ }
61
+ /**
62
+ * Display progress in a bulk operation
63
+ *
64
+ * @param current - Current item number (1-indexed)
65
+ * @param total - Total number of items
66
+ * @param operation - Operation being performed
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * displayBulkProgress(3, 10, "Enhancing task ABC");
71
+ * // Output: [3/10] Enhancing task ABC...
72
+ * ```
73
+ */
74
+ function displayBulkProgress(current, total, operation) {
75
+ console.log(chalk_1.default.cyan(`\n[${current}/${total}] ${operation}...`));
76
+ }
77
+ /**
78
+ * Display a separator line
79
+ *
80
+ * @param length - Length of the separator (default: 60)
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * displaySeparator();
85
+ * // Output: ============================================================
86
+ * ```
87
+ */
88
+ function displaySeparator(length = 60) {
89
+ console.log(chalk_1.default.blue("=".repeat(length)));
90
+ }
91
+ /**
92
+ * Display a section header
93
+ *
94
+ * @param title - Section title
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * displaySectionHeader("Execution Summary");
99
+ * // Output:
100
+ * // ============================================================
101
+ * // 📊 Execution Summary
102
+ * // ============================================================
103
+ * ```
104
+ */
105
+ function displaySectionHeader(title) {
106
+ displaySeparator();
107
+ console.log(chalk_1.default.blue.bold(`📊 ${title}`));
108
+ displaySeparator();
109
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Extracts a readable error message from an unknown error value.
3
+ * Handles Error objects, strings, objects with message property, and unknown types.
4
+ *
5
+ * @param error - The error value to extract message from
6
+ * @returns A string error message
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * try {
11
+ * throw new Error("Something went wrong");
12
+ * } catch (error) {
13
+ * console.log(getErrorMessage(error)); // "Something went wrong"
14
+ * }
15
+ * ```
16
+ */
17
+ export declare function getErrorMessage(error: unknown): string;
18
+ /**
19
+ * Formats an error with optional context information.
20
+ * Useful for adding context to error messages when rethrowing.
21
+ *
22
+ * @param error - The error value
23
+ * @param context - Optional context string to prepend to the error message
24
+ * @returns Formatted error message
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * try {
29
+ * await fetchData();
30
+ * } catch (error) {
31
+ * throw new Error(formatError(error, "Failed to fetch data"));
32
+ * // Result: "Failed to fetch data: Connection timeout"
33
+ * }
34
+ * ```
35
+ */
36
+ export declare function formatError(error: unknown, context?: string): string;
37
+ /**
38
+ * Creates an error with a formatted message including context.
39
+ *
40
+ * @param error - The original error
41
+ * @param context - Context to add to the error
42
+ * @returns A new Error instance with formatted message
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * try {
47
+ * await operation();
48
+ * } catch (error) {
49
+ * throw createContextError(error, "Operation failed");
50
+ * }
51
+ * ```
52
+ */
53
+ export declare function createContextError(error: unknown, context: string): Error;
54
+ /**
55
+ * Type guard to check if an error is an Error instance.
56
+ *
57
+ * @param error - Value to check
58
+ * @returns true if error is an Error instance
59
+ */
60
+ export declare function isError(error: unknown): error is Error;
61
+ /**
62
+ * Safely converts any value to an Error instance.
63
+ * If the value is already an Error, returns it unchanged.
64
+ * Otherwise, creates a new Error with the string representation.
65
+ *
66
+ * @param error - Value to convert
67
+ * @returns An Error instance
68
+ */
69
+ export declare function toError(error: unknown): Error;
70
+ //# sourceMappingURL=error-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBtD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAGpE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAEtD;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAK7C"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorMessage = getErrorMessage;
4
+ exports.formatError = formatError;
5
+ exports.createContextError = createContextError;
6
+ exports.isError = isError;
7
+ exports.toError = toError;
8
+ /**
9
+ * Extracts a readable error message from an unknown error value.
10
+ * Handles Error objects, strings, objects with message property, and unknown types.
11
+ *
12
+ * @param error - The error value to extract message from
13
+ * @returns A string error message
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * try {
18
+ * throw new Error("Something went wrong");
19
+ * } catch (error) {
20
+ * console.log(getErrorMessage(error)); // "Something went wrong"
21
+ * }
22
+ * ```
23
+ */
24
+ function getErrorMessage(error) {
25
+ // Error instance
26
+ if (error instanceof Error) {
27
+ return error.message;
28
+ }
29
+ // String error
30
+ if (typeof error === "string") {
31
+ return error;
32
+ }
33
+ // Object with message property
34
+ if (error && typeof error === "object" && "message" in error) {
35
+ return String(error.message);
36
+ }
37
+ // Unknown type - convert to string
38
+ return "Unknown error occurred";
39
+ }
40
+ /**
41
+ * Formats an error with optional context information.
42
+ * Useful for adding context to error messages when rethrowing.
43
+ *
44
+ * @param error - The error value
45
+ * @param context - Optional context string to prepend to the error message
46
+ * @returns Formatted error message
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * try {
51
+ * await fetchData();
52
+ * } catch (error) {
53
+ * throw new Error(formatError(error, "Failed to fetch data"));
54
+ * // Result: "Failed to fetch data: Connection timeout"
55
+ * }
56
+ * ```
57
+ */
58
+ function formatError(error, context) {
59
+ const message = getErrorMessage(error);
60
+ return context ? `${context}: ${message}` : message;
61
+ }
62
+ /**
63
+ * Creates an error with a formatted message including context.
64
+ *
65
+ * @param error - The original error
66
+ * @param context - Context to add to the error
67
+ * @returns A new Error instance with formatted message
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * try {
72
+ * await operation();
73
+ * } catch (error) {
74
+ * throw createContextError(error, "Operation failed");
75
+ * }
76
+ * ```
77
+ */
78
+ function createContextError(error, context) {
79
+ return new Error(formatError(error, context));
80
+ }
81
+ /**
82
+ * Type guard to check if an error is an Error instance.
83
+ *
84
+ * @param error - Value to check
85
+ * @returns true if error is an Error instance
86
+ */
87
+ function isError(error) {
88
+ return error instanceof Error;
89
+ }
90
+ /**
91
+ * Safely converts any value to an Error instance.
92
+ * If the value is already an Error, returns it unchanged.
93
+ * Otherwise, creates a new Error with the string representation.
94
+ *
95
+ * @param error - Value to convert
96
+ * @returns An Error instance
97
+ */
98
+ function toError(error) {
99
+ if (error instanceof Error) {
100
+ return error;
101
+ }
102
+ return new Error(getErrorMessage(error));
103
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Validates that a file exists at the given path (synchronous).
3
+ * Throws an error with a custom message if the file doesn't exist.
4
+ *
5
+ * @param filePath - Path to the file to validate
6
+ * @param customMessage - Optional custom error message
7
+ * @throws Error if file doesn't exist
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * validateFileExists("./config.json", "Configuration file not found");
12
+ * // Throws: Error("Configuration file not found") if file doesn't exist
13
+ * ```
14
+ */
15
+ export declare function validateFileExists(filePath: string, customMessage?: string): void;
16
+ /**
17
+ * Validates that a file exists at the given path (asynchronous).
18
+ * Throws an error with a custom message if the file doesn't exist.
19
+ *
20
+ * @param filePath - Path to the file to validate
21
+ * @param customMessage - Optional custom error message
22
+ * @throws Error if file doesn't exist
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * await validateFileExistsAsync("./data.json");
27
+ * // Throws: Error("File not found: ./data.json") if file doesn't exist
28
+ * ```
29
+ */
30
+ export declare function validateFileExistsAsync(filePath: string, customMessage?: string): Promise<void>;
31
+ /**
32
+ * Checks if a file exists at the given path (synchronous).
33
+ * Returns true if file exists, false otherwise.
34
+ * Unlike validateFileExists, this doesn't throw an error.
35
+ *
36
+ * @param filePath - Path to check
37
+ * @returns true if file exists, false otherwise
38
+ */
39
+ export declare function fileExists(filePath: string): boolean;
40
+ /**
41
+ * Checks if a file exists at the given path (asynchronous).
42
+ * Returns true if file exists, false otherwise.
43
+ * Unlike validateFileExistsAsync, this doesn't throw an error.
44
+ *
45
+ * @param filePath - Path to check
46
+ * @returns Promise resolving to true if file exists, false otherwise
47
+ */
48
+ export declare function fileExistsAsync(filePath: string): Promise<boolean>;
49
+ //# sourceMappingURL=file-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-utils.d.ts","sourceRoot":"","sources":["../../src/utils/file-utils.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,MAAM,GACrB,IAAI,CAIN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC,CAMf;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOxE"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateFileExists = validateFileExists;
4
+ exports.validateFileExistsAsync = validateFileExistsAsync;
5
+ exports.fileExists = fileExists;
6
+ exports.fileExistsAsync = fileExistsAsync;
7
+ const fs_1 = require("fs");
8
+ const promises_1 = require("fs/promises");
9
+ /**
10
+ * Validates that a file exists at the given path (synchronous).
11
+ * Throws an error with a custom message if the file doesn't exist.
12
+ *
13
+ * @param filePath - Path to the file to validate
14
+ * @param customMessage - Optional custom error message
15
+ * @throws Error if file doesn't exist
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * validateFileExists("./config.json", "Configuration file not found");
20
+ * // Throws: Error("Configuration file not found") if file doesn't exist
21
+ * ```
22
+ */
23
+ function validateFileExists(filePath, customMessage) {
24
+ if (!(0, fs_1.existsSync)(filePath)) {
25
+ throw new Error(customMessage || `File not found: ${filePath}`);
26
+ }
27
+ }
28
+ /**
29
+ * Validates that a file exists at the given path (asynchronous).
30
+ * Throws an error with a custom message if the file doesn't exist.
31
+ *
32
+ * @param filePath - Path to the file to validate
33
+ * @param customMessage - Optional custom error message
34
+ * @throws Error if file doesn't exist
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * await validateFileExistsAsync("./data.json");
39
+ * // Throws: Error("File not found: ./data.json") if file doesn't exist
40
+ * ```
41
+ */
42
+ async function validateFileExistsAsync(filePath, customMessage) {
43
+ try {
44
+ await (0, promises_1.access)(filePath, promises_1.constants.F_OK);
45
+ }
46
+ catch {
47
+ throw new Error(customMessage || `File not found: ${filePath}`);
48
+ }
49
+ }
50
+ /**
51
+ * Checks if a file exists at the given path (synchronous).
52
+ * Returns true if file exists, false otherwise.
53
+ * Unlike validateFileExists, this doesn't throw an error.
54
+ *
55
+ * @param filePath - Path to check
56
+ * @returns true if file exists, false otherwise
57
+ */
58
+ function fileExists(filePath) {
59
+ return (0, fs_1.existsSync)(filePath);
60
+ }
61
+ /**
62
+ * Checks if a file exists at the given path (asynchronous).
63
+ * Returns true if file exists, false otherwise.
64
+ * Unlike validateFileExistsAsync, this doesn't throw an error.
65
+ *
66
+ * @param filePath - Path to check
67
+ * @returns Promise resolving to true if file exists, false otherwise
68
+ */
69
+ async function fileExistsAsync(filePath) {
70
+ try {
71
+ await (0, promises_1.access)(filePath, promises_1.constants.F_OK);
72
+ return true;
73
+ }
74
+ catch {
75
+ return false;
76
+ }
77
+ }
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Generates unique task IDs with consistent format.
3
+ * Uses timestamp + random hex for uniqueness.
4
+ */
5
+ export declare class TaskIDGenerator {
6
+ /**
7
+ * Generates a unique task ID with format: prefix-timestamp-random
8
+ *
9
+ * @param prefix - Prefix for the ID (default: "task")
10
+ * @returns Unique task ID
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const id = TaskIDGenerator.generate();
15
+ * // Returns: "task-1733750400000-a1b2c3d4"
16
+ *
17
+ * const customId = TaskIDGenerator.generate("subtask");
18
+ * // Returns: "subtask-1733750400000-e5f6g7h8"
19
+ * ```
20
+ */
21
+ static generate(prefix?: string): string;
22
+ /**
23
+ * Validates a task ID format.
24
+ * Accepts three formats:
25
+ * - Timestamped: "task-1234567890-abcd1234"
26
+ * - Hierarchical: "1.2.3"
27
+ * - Numeric: "123"
28
+ *
29
+ * @param id - Task ID to validate
30
+ * @returns true if ID format is valid
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * TaskIDGenerator.validate("task-1234-abcd"); // true
35
+ * TaskIDGenerator.validate("1.2.3"); // true
36
+ * TaskIDGenerator.validate("123"); // true
37
+ * TaskIDGenerator.validate("invalid!"); // false
38
+ * ```
39
+ */
40
+ static validate(id: string): boolean;
41
+ /**
42
+ * Checks if an ID is unique within a set of existing IDs.
43
+ *
44
+ * @param id - ID to check
45
+ * @param existingIds - Set of existing IDs
46
+ * @returns true if ID is unique
47
+ */
48
+ static isUnique(id: string, existingIds: Set<string>): boolean;
49
+ /**
50
+ * Generates a unique ID that doesn't exist in the provided set.
51
+ * Retries up to maxAttempts times if collisions occur.
52
+ *
53
+ * @param existingIds - Set of existing IDs to avoid
54
+ * @param prefix - Prefix for the ID
55
+ * @param maxAttempts - Maximum number of generation attempts
56
+ * @returns Unique task ID
57
+ * @throws Error if unable to generate unique ID after maxAttempts
58
+ */
59
+ static generateUnique(existingIds: Set<string>, prefix?: string, maxAttempts?: number): string;
60
+ /**
61
+ * Generates a hierarchical child ID from a parent ID.
62
+ * If parent is "1.2", generates "1.2.1", "1.2.2", etc.
63
+ *
64
+ * @param parentId - Parent task ID
65
+ * @param childIndex - Index of the child (1-based)
66
+ * @returns Child task ID
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * TaskIDGenerator.generateChildId("1", 1); // "1.1"
71
+ * TaskIDGenerator.generateChildId("1.2", 3); // "1.2.3"
72
+ * ```
73
+ */
74
+ static generateChildId(parentId: string, childIndex: number): string;
75
+ /**
76
+ * Parses a hierarchical ID to extract parent ID and child index.
77
+ *
78
+ * @param id - Hierarchical task ID
79
+ * @returns Object with parentId and childIndex, or null if not hierarchical
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * TaskIDGenerator.parseHierarchicalId("1.2.3");
84
+ * // Returns: { parentId: "1.2", childIndex: 3 }
85
+ * ```
86
+ */
87
+ static parseHierarchicalId(id: string): {
88
+ parentId: string;
89
+ childIndex: number;
90
+ } | null;
91
+ }
92
+ //# sourceMappingURL=id-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-generator.d.ts","sourceRoot":"","sources":["../../src/utils/id-generator.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,eAAe;IAC1B;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAE,MAAe,GAAG,MAAM;IAMhD;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IA0BpC;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,OAAO;IAI9D;;;;;;;;;OASG;IACH,MAAM,CAAC,cAAc,CACnB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,EACxB,MAAM,GAAE,MAAe,EACvB,WAAW,GAAE,MAAW,GACvB,MAAM;IAaT;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IAIpE;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,mBAAmB,CACxB,EAAE,EAAE,MAAM,GACT;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAcnD"}
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskIDGenerator = void 0;
4
+ const crypto_1 = require("crypto");
5
+ /**
6
+ * Generates unique task IDs with consistent format.
7
+ * Uses timestamp + random hex for uniqueness.
8
+ */
9
+ class TaskIDGenerator {
10
+ /**
11
+ * Generates a unique task ID with format: prefix-timestamp-random
12
+ *
13
+ * @param prefix - Prefix for the ID (default: "task")
14
+ * @returns Unique task ID
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const id = TaskIDGenerator.generate();
19
+ * // Returns: "task-1733750400000-a1b2c3d4"
20
+ *
21
+ * const customId = TaskIDGenerator.generate("subtask");
22
+ * // Returns: "subtask-1733750400000-e5f6g7h8"
23
+ * ```
24
+ */
25
+ static generate(prefix = "task") {
26
+ const timestamp = Date.now();
27
+ const random = (0, crypto_1.randomBytes)(4).toString("hex");
28
+ return `${prefix}-${timestamp}-${random}`;
29
+ }
30
+ /**
31
+ * Validates a task ID format.
32
+ * Accepts three formats:
33
+ * - Timestamped: "task-1234567890-abcd1234"
34
+ * - Hierarchical: "1.2.3"
35
+ * - Numeric: "123"
36
+ *
37
+ * @param id - Task ID to validate
38
+ * @returns true if ID format is valid
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * TaskIDGenerator.validate("task-1234-abcd"); // true
43
+ * TaskIDGenerator.validate("1.2.3"); // true
44
+ * TaskIDGenerator.validate("123"); // true
45
+ * TaskIDGenerator.validate("invalid!"); // false
46
+ * ```
47
+ */
48
+ static validate(id) {
49
+ if (!id || typeof id !== "string") {
50
+ return false;
51
+ }
52
+ // Format 1: Timestamped (task-timestamp-random)
53
+ const timestampedPattern = /^[a-z]+-\d+-[a-f0-9]{8}$/;
54
+ if (timestampedPattern.test(id)) {
55
+ return true;
56
+ }
57
+ // Format 2: Hierarchical (1.2.3)
58
+ const hierarchicalPattern = /^[\d.]+$/;
59
+ if (hierarchicalPattern.test(id)) {
60
+ return true;
61
+ }
62
+ // Format 3: Numeric (123)
63
+ const numericPattern = /^\d+$/;
64
+ if (numericPattern.test(id)) {
65
+ return true;
66
+ }
67
+ return false;
68
+ }
69
+ /**
70
+ * Checks if an ID is unique within a set of existing IDs.
71
+ *
72
+ * @param id - ID to check
73
+ * @param existingIds - Set of existing IDs
74
+ * @returns true if ID is unique
75
+ */
76
+ static isUnique(id, existingIds) {
77
+ return !existingIds.has(id);
78
+ }
79
+ /**
80
+ * Generates a unique ID that doesn't exist in the provided set.
81
+ * Retries up to maxAttempts times if collisions occur.
82
+ *
83
+ * @param existingIds - Set of existing IDs to avoid
84
+ * @param prefix - Prefix for the ID
85
+ * @param maxAttempts - Maximum number of generation attempts
86
+ * @returns Unique task ID
87
+ * @throws Error if unable to generate unique ID after maxAttempts
88
+ */
89
+ static generateUnique(existingIds, prefix = "task", maxAttempts = 10) {
90
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
91
+ const id = this.generate(prefix);
92
+ if (this.isUnique(id, existingIds)) {
93
+ return id;
94
+ }
95
+ }
96
+ throw new Error(`Failed to generate unique ID after ${maxAttempts} attempts`);
97
+ }
98
+ /**
99
+ * Generates a hierarchical child ID from a parent ID.
100
+ * If parent is "1.2", generates "1.2.1", "1.2.2", etc.
101
+ *
102
+ * @param parentId - Parent task ID
103
+ * @param childIndex - Index of the child (1-based)
104
+ * @returns Child task ID
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * TaskIDGenerator.generateChildId("1", 1); // "1.1"
109
+ * TaskIDGenerator.generateChildId("1.2", 3); // "1.2.3"
110
+ * ```
111
+ */
112
+ static generateChildId(parentId, childIndex) {
113
+ return `${parentId}.${childIndex}`;
114
+ }
115
+ /**
116
+ * Parses a hierarchical ID to extract parent ID and child index.
117
+ *
118
+ * @param id - Hierarchical task ID
119
+ * @returns Object with parentId and childIndex, or null if not hierarchical
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * TaskIDGenerator.parseHierarchicalId("1.2.3");
124
+ * // Returns: { parentId: "1.2", childIndex: 3 }
125
+ * ```
126
+ */
127
+ static parseHierarchicalId(id) {
128
+ const parts = id.split(".");
129
+ if (parts.length < 2) {
130
+ return null;
131
+ }
132
+ const childIndex = parseInt(parts[parts.length - 1], 10);
133
+ if (isNaN(childIndex)) {
134
+ return null;
135
+ }
136
+ const parentId = parts.slice(0, -1).join(".");
137
+ return { parentId, childIndex };
138
+ }
139
+ }
140
+ exports.TaskIDGenerator = TaskIDGenerator;
@@ -0,0 +1,38 @@
1
+ import { ExecutorTool, ModelAttemptConfig } from "../types";
2
+ /**
3
+ * Valid executor tools
4
+ */
5
+ export declare const VALID_EXECUTORS: ExecutorTool[];
6
+ /**
7
+ * Parse --try-models option into ModelAttemptConfig array
8
+ * Supports formats:
9
+ * - "model1,model2,model3" - just models (uses default executor)
10
+ * - "opencode:gpt-4o,claude:sonnet-4" - executor:model format
11
+ * - Mixed: "gpt-4o,claude:sonnet-4,gemini:gemini-2.0"
12
+ *
13
+ * @param value - Comma-separated model/executor specifications
14
+ * @returns Array of model attempt configurations
15
+ * @throws Error if an invalid executor is specified
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * parseTryModels("gpt-4o-mini,gpt-4o"); // [{ model: "gpt-4o-mini" }, { model: "gpt-4o" }]
20
+ * parseTryModels("opencode:gpt-4o,claude:sonnet-4"); // [{ executor: "opencode", model: "gpt-4o" }, ...]
21
+ * ```
22
+ */
23
+ export declare function parseTryModels(value: string): ModelAttemptConfig[];
24
+ /**
25
+ * Validate that an executor name is valid
26
+ *
27
+ * @param executor - Executor name to validate
28
+ * @returns Type guard confirming executor is valid
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * if (validateExecutor(options.tool)) {
33
+ * // TypeScript knows options.tool is ExecutorTool
34
+ * }
35
+ * ```
36
+ */
37
+ export declare function validateExecutor(executor: string): executor is ExecutorTool;
38
+ //# sourceMappingURL=model-executor-parser.d.ts.map