@litmers/cursorflow-orchestrator 0.1.20 → 0.1.26

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 (224) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/commands/cursorflow-clean.md +19 -0
  3. package/commands/cursorflow-runs.md +59 -0
  4. package/commands/cursorflow-stop.md +55 -0
  5. package/dist/cli/clean.js +171 -0
  6. package/dist/cli/clean.js.map +1 -1
  7. package/dist/cli/index.js +7 -0
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/cli/init.js +1 -1
  10. package/dist/cli/init.js.map +1 -1
  11. package/dist/cli/logs.js +83 -42
  12. package/dist/cli/logs.js.map +1 -1
  13. package/dist/cli/monitor.d.ts +7 -0
  14. package/dist/cli/monitor.js +1007 -189
  15. package/dist/cli/monitor.js.map +1 -1
  16. package/dist/cli/prepare.js +4 -3
  17. package/dist/cli/prepare.js.map +1 -1
  18. package/dist/cli/resume.js +188 -236
  19. package/dist/cli/resume.js.map +1 -1
  20. package/dist/cli/run.js +8 -3
  21. package/dist/cli/run.js.map +1 -1
  22. package/dist/cli/runs.d.ts +5 -0
  23. package/dist/cli/runs.js +214 -0
  24. package/dist/cli/runs.js.map +1 -0
  25. package/dist/cli/setup-commands.js +0 -0
  26. package/dist/cli/signal.js +1 -1
  27. package/dist/cli/signal.js.map +1 -1
  28. package/dist/cli/stop.d.ts +5 -0
  29. package/dist/cli/stop.js +215 -0
  30. package/dist/cli/stop.js.map +1 -0
  31. package/dist/cli/tasks.d.ts +10 -0
  32. package/dist/cli/tasks.js +165 -0
  33. package/dist/cli/tasks.js.map +1 -0
  34. package/dist/core/auto-recovery.d.ts +212 -0
  35. package/dist/core/auto-recovery.js +737 -0
  36. package/dist/core/auto-recovery.js.map +1 -0
  37. package/dist/core/failure-policy.d.ts +156 -0
  38. package/dist/core/failure-policy.js +488 -0
  39. package/dist/core/failure-policy.js.map +1 -0
  40. package/dist/core/orchestrator.d.ts +15 -2
  41. package/dist/core/orchestrator.js +392 -15
  42. package/dist/core/orchestrator.js.map +1 -1
  43. package/dist/core/reviewer.d.ts +2 -0
  44. package/dist/core/reviewer.js +2 -0
  45. package/dist/core/reviewer.js.map +1 -1
  46. package/dist/core/runner.d.ts +33 -10
  47. package/dist/core/runner.js +321 -146
  48. package/dist/core/runner.js.map +1 -1
  49. package/dist/services/logging/buffer.d.ts +67 -0
  50. package/dist/services/logging/buffer.js +309 -0
  51. package/dist/services/logging/buffer.js.map +1 -0
  52. package/dist/services/logging/console.d.ts +89 -0
  53. package/dist/services/logging/console.js +169 -0
  54. package/dist/services/logging/console.js.map +1 -0
  55. package/dist/services/logging/file-writer.d.ts +71 -0
  56. package/dist/services/logging/file-writer.js +516 -0
  57. package/dist/services/logging/file-writer.js.map +1 -0
  58. package/dist/services/logging/formatter.d.ts +39 -0
  59. package/dist/services/logging/formatter.js +227 -0
  60. package/dist/services/logging/formatter.js.map +1 -0
  61. package/dist/services/logging/index.d.ts +11 -0
  62. package/dist/services/logging/index.js +30 -0
  63. package/dist/services/logging/index.js.map +1 -0
  64. package/dist/services/logging/parser.d.ts +31 -0
  65. package/dist/services/logging/parser.js +222 -0
  66. package/dist/services/logging/parser.js.map +1 -0
  67. package/dist/services/process/index.d.ts +59 -0
  68. package/dist/services/process/index.js +257 -0
  69. package/dist/services/process/index.js.map +1 -0
  70. package/dist/types/agent.d.ts +20 -0
  71. package/dist/types/agent.js +6 -0
  72. package/dist/types/agent.js.map +1 -0
  73. package/dist/types/config.d.ts +65 -0
  74. package/dist/types/config.js +6 -0
  75. package/dist/types/config.js.map +1 -0
  76. package/dist/types/events.d.ts +125 -0
  77. package/dist/types/events.js +6 -0
  78. package/dist/types/events.js.map +1 -0
  79. package/dist/types/index.d.ts +12 -0
  80. package/dist/types/index.js +37 -0
  81. package/dist/types/index.js.map +1 -0
  82. package/dist/types/lane.d.ts +43 -0
  83. package/dist/types/lane.js +6 -0
  84. package/dist/types/lane.js.map +1 -0
  85. package/dist/types/logging.d.ts +71 -0
  86. package/dist/types/logging.js +16 -0
  87. package/dist/types/logging.js.map +1 -0
  88. package/dist/types/review.d.ts +17 -0
  89. package/dist/types/review.js +6 -0
  90. package/dist/types/review.js.map +1 -0
  91. package/dist/types/run.d.ts +32 -0
  92. package/dist/types/run.js +6 -0
  93. package/dist/types/run.js.map +1 -0
  94. package/dist/types/task.d.ts +71 -0
  95. package/dist/types/task.js +6 -0
  96. package/dist/types/task.js.map +1 -0
  97. package/dist/ui/components.d.ts +134 -0
  98. package/dist/ui/components.js +389 -0
  99. package/dist/ui/components.js.map +1 -0
  100. package/dist/ui/log-viewer.d.ts +49 -0
  101. package/dist/ui/log-viewer.js +449 -0
  102. package/dist/ui/log-viewer.js.map +1 -0
  103. package/dist/utils/checkpoint.d.ts +87 -0
  104. package/dist/utils/checkpoint.js +317 -0
  105. package/dist/utils/checkpoint.js.map +1 -0
  106. package/dist/utils/config.d.ts +4 -0
  107. package/dist/utils/config.js +11 -2
  108. package/dist/utils/config.js.map +1 -1
  109. package/dist/utils/cursor-agent.js.map +1 -1
  110. package/dist/utils/dependency.d.ts +74 -0
  111. package/dist/utils/dependency.js +420 -0
  112. package/dist/utils/dependency.js.map +1 -0
  113. package/dist/utils/doctor.js +10 -5
  114. package/dist/utils/doctor.js.map +1 -1
  115. package/dist/utils/enhanced-logger.d.ts +10 -33
  116. package/dist/utils/enhanced-logger.js +94 -9
  117. package/dist/utils/enhanced-logger.js.map +1 -1
  118. package/dist/utils/git.d.ts +121 -0
  119. package/dist/utils/git.js +322 -2
  120. package/dist/utils/git.js.map +1 -1
  121. package/dist/utils/health.d.ts +91 -0
  122. package/dist/utils/health.js +556 -0
  123. package/dist/utils/health.js.map +1 -0
  124. package/dist/utils/lock.d.ts +95 -0
  125. package/dist/utils/lock.js +332 -0
  126. package/dist/utils/lock.js.map +1 -0
  127. package/dist/utils/log-buffer.d.ts +17 -0
  128. package/dist/utils/log-buffer.js +14 -0
  129. package/dist/utils/log-buffer.js.map +1 -0
  130. package/dist/utils/log-constants.d.ts +23 -0
  131. package/dist/utils/log-constants.js +28 -0
  132. package/dist/utils/log-constants.js.map +1 -0
  133. package/dist/utils/log-formatter.d.ts +9 -0
  134. package/dist/utils/log-formatter.js +113 -70
  135. package/dist/utils/log-formatter.js.map +1 -1
  136. package/dist/utils/log-service.d.ts +19 -0
  137. package/dist/utils/log-service.js +47 -0
  138. package/dist/utils/log-service.js.map +1 -0
  139. package/dist/utils/logger.d.ts +46 -27
  140. package/dist/utils/logger.js +82 -60
  141. package/dist/utils/logger.js.map +1 -1
  142. package/dist/utils/process-manager.d.ts +21 -0
  143. package/dist/utils/process-manager.js +138 -0
  144. package/dist/utils/process-manager.js.map +1 -0
  145. package/dist/utils/retry.d.ts +121 -0
  146. package/dist/utils/retry.js +374 -0
  147. package/dist/utils/retry.js.map +1 -0
  148. package/dist/utils/run-service.d.ts +88 -0
  149. package/dist/utils/run-service.js +412 -0
  150. package/dist/utils/run-service.js.map +1 -0
  151. package/dist/utils/state.d.ts +58 -2
  152. package/dist/utils/state.js +306 -3
  153. package/dist/utils/state.js.map +1 -1
  154. package/dist/utils/task-service.d.ts +82 -0
  155. package/dist/utils/task-service.js +348 -0
  156. package/dist/utils/task-service.js.map +1 -0
  157. package/dist/utils/types.d.ts +2 -272
  158. package/dist/utils/types.js +16 -0
  159. package/dist/utils/types.js.map +1 -1
  160. package/package.json +38 -23
  161. package/scripts/ai-security-check.js +0 -1
  162. package/scripts/local-security-gate.sh +0 -0
  163. package/scripts/monitor-lanes.sh +94 -0
  164. package/scripts/patches/test-cursor-agent.js +0 -1
  165. package/scripts/release.sh +0 -0
  166. package/scripts/setup-security.sh +0 -0
  167. package/scripts/stream-logs.sh +72 -0
  168. package/scripts/verify-and-fix.sh +0 -0
  169. package/src/cli/clean.ts +180 -0
  170. package/src/cli/index.ts +7 -0
  171. package/src/cli/init.ts +1 -1
  172. package/src/cli/logs.ts +79 -42
  173. package/src/cli/monitor.ts +1815 -899
  174. package/src/cli/prepare.ts +4 -3
  175. package/src/cli/resume.ts +220 -277
  176. package/src/cli/run.ts +9 -3
  177. package/src/cli/runs.ts +212 -0
  178. package/src/cli/setup-commands.ts +0 -0
  179. package/src/cli/signal.ts +1 -1
  180. package/src/cli/stop.ts +209 -0
  181. package/src/cli/tasks.ts +154 -0
  182. package/src/core/auto-recovery.ts +909 -0
  183. package/src/core/failure-policy.ts +592 -0
  184. package/src/core/orchestrator.ts +1131 -675
  185. package/src/core/reviewer.ts +4 -0
  186. package/src/core/runner.ts +388 -162
  187. package/src/services/logging/buffer.ts +326 -0
  188. package/src/services/logging/console.ts +193 -0
  189. package/src/services/logging/file-writer.ts +526 -0
  190. package/src/services/logging/formatter.ts +268 -0
  191. package/src/services/logging/index.ts +16 -0
  192. package/src/services/logging/parser.ts +232 -0
  193. package/src/services/process/index.ts +261 -0
  194. package/src/types/agent.ts +24 -0
  195. package/src/types/config.ts +79 -0
  196. package/src/types/events.ts +156 -0
  197. package/src/types/index.ts +29 -0
  198. package/src/types/lane.ts +56 -0
  199. package/src/types/logging.ts +96 -0
  200. package/src/types/review.ts +20 -0
  201. package/src/types/run.ts +37 -0
  202. package/src/types/task.ts +79 -0
  203. package/src/ui/components.ts +430 -0
  204. package/src/ui/log-viewer.ts +485 -0
  205. package/src/utils/checkpoint.ts +374 -0
  206. package/src/utils/config.ts +11 -2
  207. package/src/utils/cursor-agent.ts +1 -1
  208. package/src/utils/dependency.ts +482 -0
  209. package/src/utils/doctor.ts +11 -5
  210. package/src/utils/enhanced-logger.ts +108 -49
  211. package/src/utils/git.ts +374 -2
  212. package/src/utils/health.ts +596 -0
  213. package/src/utils/lock.ts +346 -0
  214. package/src/utils/log-buffer.ts +28 -0
  215. package/src/utils/log-constants.ts +26 -0
  216. package/src/utils/log-formatter.ts +120 -37
  217. package/src/utils/log-service.ts +49 -0
  218. package/src/utils/logger.ts +100 -51
  219. package/src/utils/process-manager.ts +100 -0
  220. package/src/utils/retry.ts +413 -0
  221. package/src/utils/run-service.ts +433 -0
  222. package/src/utils/state.ts +369 -3
  223. package/src/utils/task-service.ts +370 -0
  224. package/src/utils/types.ts +2 -315
@@ -0,0 +1,370 @@
1
+ /**
2
+ * TaskService - Manages CursorFlow task directories and validation
3
+ *
4
+ * Provides:
5
+ * - List prepared task directories
6
+ * - Get task details (lanes, dependencies)
7
+ * - Validate tasks (doctor integration)
8
+ * - Check run eligibility
9
+ */
10
+
11
+ import * as fs from 'fs';
12
+ import * as path from 'path';
13
+ import { TaskDirInfo, LaneFileInfo, ValidationStatus, Task } from './types';
14
+
15
+ // Re-export types for consumers
16
+ export { TaskDirInfo, LaneFileInfo, ValidationStatus } from './types';
17
+ import * as logger from './logger';
18
+
19
+ export interface ValidationResult {
20
+ /** Combined errors + warnings for backwards compatibility */
21
+ issues: string[];
22
+ status: ValidationStatus;
23
+ errors: string[];
24
+ warnings: string[];
25
+ lastValidated: number;
26
+ }
27
+
28
+ // Cache for validation results
29
+ const validationCache = new Map<string, ValidationResult>();
30
+
31
+ export class TaskService {
32
+ private tasksDir: string;
33
+
34
+ constructor(tasksDir: string) {
35
+ this.tasksDir = tasksDir;
36
+ }
37
+
38
+ /**
39
+ * List all prepared task directories
40
+ */
41
+ listTaskDirs(): TaskDirInfo[] {
42
+ if (!fs.existsSync(this.tasksDir)) {
43
+ return [];
44
+ }
45
+
46
+ const dirs = fs.readdirSync(this.tasksDir)
47
+ .filter(name => {
48
+ const dirPath = path.join(this.tasksDir, name);
49
+ return fs.statSync(dirPath).isDirectory() && !name.startsWith('.');
50
+ })
51
+ .sort((a, b) => b.localeCompare(a)); // Most recent first (assuming timestamp prefix)
52
+
53
+ return dirs.map(name => this.getTaskDirInfo(name)).filter((t): t is TaskDirInfo => t !== null);
54
+ }
55
+
56
+ /**
57
+ * Get detailed information about a task directory
58
+ */
59
+ getTaskDirInfo(taskName: string): TaskDirInfo | null {
60
+ const taskPath = path.join(this.tasksDir, taskName);
61
+
62
+ if (!fs.existsSync(taskPath)) {
63
+ return null;
64
+ }
65
+
66
+ try {
67
+ const stat = fs.statSync(taskPath);
68
+ const timestamp = this.parseTimestampFromName(taskName) || stat.mtime;
69
+ const featureName = this.extractFeatureName(taskName);
70
+ const lanes = this.scanLaneFiles(taskPath);
71
+
72
+ // Get cached validation status
73
+ const cached = validationCache.get(taskName);
74
+ const validationStatus = cached?.status || 'unknown';
75
+ const lastValidated = cached?.lastValidated;
76
+
77
+ return {
78
+ name: taskName,
79
+ path: taskPath,
80
+ timestamp,
81
+ featureName,
82
+ lanes,
83
+ validationStatus,
84
+ lastValidated,
85
+ };
86
+ } catch (error) {
87
+ logger.debug(`Failed to read task dir ${taskName}: ${error}`);
88
+ return null;
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Scan lane files in a task directory
94
+ */
95
+ private scanLaneFiles(taskPath: string): LaneFileInfo[] {
96
+ const files = fs.readdirSync(taskPath)
97
+ .filter(name => name.endsWith('.json'))
98
+ .sort();
99
+
100
+ const lanes: LaneFileInfo[] = [];
101
+
102
+ for (const fileName of files) {
103
+ try {
104
+ const filePath = path.join(taskPath, fileName);
105
+ const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
106
+
107
+ const laneName = this.extractLaneName(fileName);
108
+ const tasks = content.tasks || [];
109
+ const dependsOn = content.dependsOn || [];
110
+ const preset = this.detectPreset(tasks);
111
+ const taskFlow = this.generateTaskFlow(tasks);
112
+
113
+ lanes.push({
114
+ fileName,
115
+ laneName,
116
+ preset,
117
+ taskCount: tasks.length,
118
+ taskFlow,
119
+ dependsOn,
120
+ });
121
+ } catch (error) {
122
+ logger.debug(`Failed to parse lane file ${fileName}: ${error}`);
123
+ }
124
+ }
125
+
126
+ return lanes;
127
+ }
128
+
129
+ /**
130
+ * Extract lane name from filename (e.g., "01-lane-1.json" -> "lane-1")
131
+ */
132
+ private extractLaneName(fileName: string): string {
133
+ const baseName = fileName.replace('.json', '');
134
+ // Remove numeric prefix if present (e.g., "01-lane-1" -> "lane-1")
135
+ const match = baseName.match(/^\d+-(.+)$/);
136
+ return match ? match[1] : baseName;
137
+ }
138
+
139
+ /**
140
+ * Parse timestamp from task name (format: YYMMDDHHMM_FeatureName)
141
+ */
142
+ private parseTimestampFromName(taskName: string): Date | null {
143
+ const match = taskName.match(/^(\d{10})_/);
144
+ if (!match) return null;
145
+
146
+ const ts = match[1];
147
+ const year = 2000 + parseInt(ts.substring(0, 2), 10);
148
+ const month = parseInt(ts.substring(2, 4), 10) - 1;
149
+ const day = parseInt(ts.substring(4, 6), 10);
150
+ const hour = parseInt(ts.substring(6, 8), 10);
151
+ const minute = parseInt(ts.substring(8, 10), 10);
152
+
153
+ return new Date(year, month, day, hour, minute);
154
+ }
155
+
156
+ /**
157
+ * Extract feature name from task directory name
158
+ */
159
+ private extractFeatureName(taskName: string): string {
160
+ const parts = taskName.split('_');
161
+ if (parts.length >= 2) {
162
+ return parts.slice(1).join('_');
163
+ }
164
+ return taskName;
165
+ }
166
+
167
+ /**
168
+ * Detect task preset based on task structure
169
+ */
170
+ private detectPreset(tasks: Task[]): string {
171
+ if (tasks.length === 0) return 'empty';
172
+
173
+ const taskNames = tasks.map(t => t.name.toLowerCase());
174
+
175
+ if (taskNames.includes('plan') && taskNames.includes('implement') && taskNames.includes('test')) {
176
+ return 'complex';
177
+ }
178
+ if (taskNames.includes('implement') && taskNames.includes('test') && !taskNames.includes('plan')) {
179
+ return 'simple';
180
+ }
181
+ if (taskNames.includes('merge')) {
182
+ return 'merge';
183
+ }
184
+
185
+ return 'custom';
186
+ }
187
+
188
+ /**
189
+ * Generate task flow string (e.g., "plan → implement → test")
190
+ */
191
+ private generateTaskFlow(tasks: Task[]): string {
192
+ if (tasks.length === 0) return '';
193
+ return tasks.map(t => t.name).join(' → ');
194
+ }
195
+
196
+ /**
197
+ * Validate a task directory
198
+ */
199
+ validateTaskDir(taskName: string): ValidationResult {
200
+ const taskInfo = this.getTaskDirInfo(taskName);
201
+
202
+ if (!taskInfo) {
203
+ return {
204
+ status: 'errors',
205
+ errors: [`Task directory not found: ${taskName}`],
206
+ warnings: [],
207
+ issues: [`Task directory not found: ${taskName}`],
208
+ lastValidated: Date.now(),
209
+ };
210
+ }
211
+
212
+ const errors: string[] = [];
213
+ const warnings: string[] = [];
214
+
215
+ // Check if there are any lane files
216
+ if (taskInfo.lanes.length === 0) {
217
+ errors.push('No lane files found in task directory');
218
+ }
219
+
220
+ // Validate each lane file
221
+ for (const lane of taskInfo.lanes) {
222
+ // Check task count
223
+ if (lane.taskCount === 0) {
224
+ errors.push(`Lane ${lane.fileName} has no tasks defined`);
225
+ }
226
+
227
+ // Check dependencies exist
228
+ for (const dep of lane.dependsOn) {
229
+ const depExists = taskInfo.lanes.some(l =>
230
+ l.laneName === dep || l.fileName === dep || l.fileName === `${dep}.json`
231
+ );
232
+ if (!depExists) {
233
+ warnings.push(`Lane ${lane.fileName} depends on unknown lane: ${dep}`);
234
+ }
235
+ }
236
+
237
+ // Validate lane file structure
238
+ try {
239
+ const filePath = path.join(taskInfo.path, lane.fileName);
240
+ const content = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
241
+
242
+ // Check tasks array
243
+ if (!Array.isArray(content.tasks)) {
244
+ errors.push(`Lane ${lane.fileName}: 'tasks' must be an array`);
245
+ } else {
246
+ // Validate each task
247
+ for (let i = 0; i < content.tasks.length; i++) {
248
+ const task = content.tasks[i];
249
+ if (!task.name) {
250
+ errors.push(`Lane ${lane.fileName}: Task ${i + 1} missing 'name'`);
251
+ }
252
+ if (!task.prompt) {
253
+ errors.push(`Lane ${lane.fileName}: Task ${i + 1} missing 'prompt'`);
254
+ }
255
+ }
256
+ }
257
+ } catch (error) {
258
+ errors.push(`Lane ${lane.fileName}: Invalid JSON - ${error}`);
259
+ }
260
+ }
261
+
262
+ // Check for circular dependencies
263
+ const circularDeps = this.detectCircularDependencies(taskInfo.lanes);
264
+ if (circularDeps.length > 0) {
265
+ errors.push(`Circular dependencies detected: ${circularDeps.join(' -> ')}`);
266
+ }
267
+
268
+ // Determine overall status
269
+ let status: ValidationStatus = 'valid';
270
+ if (errors.length > 0) {
271
+ status = 'errors';
272
+ } else if (warnings.length > 0) {
273
+ status = 'warnings';
274
+ }
275
+
276
+ const issues = [...errors, ...warnings];
277
+ const result: ValidationResult = {
278
+ issues,
279
+ status,
280
+ errors,
281
+ warnings,
282
+ lastValidated: Date.now(),
283
+ };
284
+
285
+ // Cache the result
286
+ validationCache.set(taskName, result);
287
+
288
+ return result;
289
+ }
290
+
291
+ /**
292
+ * Detect circular dependencies in lane dependency graph
293
+ */
294
+ private detectCircularDependencies(lanes: LaneFileInfo[]): string[] {
295
+ const visited = new Set<string>();
296
+ const stack = new Set<string>();
297
+ const cycle: string[] = [];
298
+
299
+ const dfs = (laneName: string): boolean => {
300
+ if (stack.has(laneName)) {
301
+ cycle.push(laneName);
302
+ return true; // Cycle found
303
+ }
304
+ if (visited.has(laneName)) {
305
+ return false;
306
+ }
307
+
308
+ visited.add(laneName);
309
+ stack.add(laneName);
310
+
311
+ const lane = lanes.find(l => l.laneName === laneName);
312
+ if (lane) {
313
+ for (const dep of lane.dependsOn) {
314
+ if (dfs(dep)) {
315
+ cycle.unshift(laneName);
316
+ return true;
317
+ }
318
+ }
319
+ }
320
+
321
+ stack.delete(laneName);
322
+ return false;
323
+ };
324
+
325
+ for (const lane of lanes) {
326
+ if (dfs(lane.laneName)) {
327
+ break;
328
+ }
329
+ }
330
+
331
+ return cycle;
332
+ }
333
+
334
+ /**
335
+ * Get cached validation status
336
+ */
337
+ getValidationStatus(taskName: string): ValidationStatus {
338
+ const cached = validationCache.get(taskName);
339
+ return cached?.status || 'unknown';
340
+ }
341
+
342
+ /**
343
+ * Check if a task can be run
344
+ */
345
+ canRun(taskName: string): { ok: boolean; issues: string[] } {
346
+ const validation = this.validateTaskDir(taskName);
347
+
348
+ if (validation.status === 'errors') {
349
+ return { ok: false, issues: validation.errors };
350
+ }
351
+
352
+ return { ok: true, issues: validation.warnings };
353
+ }
354
+
355
+ /**
356
+ * Clear validation cache
357
+ */
358
+ clearCache(): void {
359
+ validationCache.clear();
360
+ }
361
+ }
362
+
363
+ /**
364
+ * Create a TaskService instance with default paths
365
+ */
366
+ export function createTaskService(projectRoot?: string): TaskService {
367
+ const root = projectRoot || process.cwd();
368
+ const tasksDir = path.join(root, '_cursorflow', 'tasks');
369
+ return new TaskService(tasksDir);
370
+ }
@@ -1,319 +1,6 @@
1
1
  /**
2
2
  * Shared type definitions for CursorFlow
3
+ * Re-exports from central types directory for backward compatibility
3
4
  */
4
5
 
5
- export interface LaneConfig {
6
- devPort: number;
7
- autoCreatePr: boolean;
8
- }
9
-
10
- export interface CursorFlowConfig {
11
- tasksDir: string;
12
- logsDir: string;
13
- baseBranch: string;
14
- branchPrefix: string;
15
- executor: 'cursor-agent' | 'cloud';
16
- pollInterval: number;
17
- allowDependencyChange: boolean;
18
- lockfileReadOnly: boolean;
19
- enableReview: boolean;
20
- reviewModel: string;
21
- reviewAllTasks?: boolean;
22
- maxReviewIterations: number;
23
- defaultLaneConfig: LaneConfig;
24
- logLevel: string;
25
- verboseGit: boolean;
26
- worktreePrefix: string;
27
- maxConcurrentLanes: number;
28
- projectRoot: string;
29
- /** Output format for cursor-agent (default: 'stream-json') */
30
- agentOutputFormat: 'stream-json' | 'json' | 'plain';
31
- webhooks?: WebhookConfig[];
32
- /** Enhanced logging configuration */
33
- enhancedLogging?: Partial<EnhancedLogConfig>;
34
- }
35
-
36
- export interface WebhookConfig {
37
- enabled?: boolean;
38
- url: string;
39
- secret?: string;
40
- events?: string[]; // ['*'] for all, ['task.*'] for wildcards
41
- headers?: Record<string, string>;
42
- retries?: number;
43
- timeoutMs?: number;
44
- }
45
-
46
- /**
47
- * Enhanced logging configuration
48
- */
49
- export interface EnhancedLogConfig {
50
- /** Enable enhanced logging features (default: true) */
51
- enabled: boolean;
52
-
53
- /** Strip ANSI escape codes from clean logs (default: true) */
54
- stripAnsi: boolean;
55
-
56
- /** Add timestamps to each line (default: true) */
57
- addTimestamps: boolean;
58
-
59
- /** Maximum size in bytes before rotation (default: 50MB) */
60
- maxFileSize: number;
61
-
62
- /** Number of rotated files to keep (default: 5) */
63
- maxFiles: number;
64
-
65
- /** Write raw output with ANSI codes to separate file (default: true) */
66
- keepRawLogs: boolean;
67
-
68
- /** Write structured JSON log entries (default: true) */
69
- writeJsonLog: boolean;
70
-
71
- /** Timestamp format: 'iso' | 'relative' | 'short' (default: 'iso') */
72
- timestampFormat: 'iso' | 'relative' | 'short';
73
- }
74
-
75
- export interface CursorFlowEvent<T = Record<string, any>> {
76
- id: string;
77
- type: string;
78
- timestamp: string;
79
- runId: string;
80
- payload: T;
81
- }
82
-
83
- export type EventHandler<T = any> = (event: CursorFlowEvent<T>) => void | Promise<void>;
84
-
85
- // Specific Event Payloads
86
- export interface OrchestrationStartedPayload {
87
- runId: string;
88
- tasksDir: string;
89
- laneCount: number;
90
- runRoot: string;
91
- }
92
-
93
- export interface OrchestrationCompletedPayload {
94
- runId: string;
95
- laneCount: number;
96
- completedCount: number;
97
- failedCount: number;
98
- }
99
-
100
- export interface OrchestrationFailedPayload {
101
- error: string;
102
- blockedLanes?: string[];
103
- }
104
-
105
- export interface LaneStartedPayload {
106
- laneName: string;
107
- pid?: number;
108
- logPath: string;
109
- }
110
-
111
- export interface LaneCompletedPayload {
112
- laneName: string;
113
- exitCode: number;
114
- }
115
-
116
- export interface LaneFailedPayload {
117
- laneName: string;
118
- exitCode: number;
119
- error: string;
120
- }
121
-
122
- export interface LaneDependencyRequestedPayload {
123
- laneName: string;
124
- dependencyRequest: DependencyRequestPlan;
125
- }
126
-
127
- export interface TaskStartedPayload {
128
- taskName: string;
129
- taskBranch: string;
130
- index: number;
131
- }
132
-
133
- export interface TaskCompletedPayload {
134
- taskName: string;
135
- taskBranch: string;
136
- status: string;
137
- }
138
-
139
- export interface TaskFailedPayload {
140
- taskName: string;
141
- taskBranch: string;
142
- error: string;
143
- }
144
-
145
- export interface AgentPromptSentPayload {
146
- taskName: string;
147
- model: string;
148
- promptLength: number;
149
- }
150
-
151
- export interface AgentResponseReceivedPayload {
152
- taskName: string;
153
- ok: boolean;
154
- duration: number;
155
- responseLength: number;
156
- error?: string;
157
- }
158
-
159
- export interface ReviewStartedPayload {
160
- taskName: string;
161
- taskBranch: string;
162
- }
163
-
164
- export interface ReviewCompletedPayload {
165
- taskName: string;
166
- status: 'approved' | 'needs_changes';
167
- issueCount: number;
168
- summary: string;
169
- }
170
-
171
- export interface ReviewApprovedPayload {
172
- taskName: string;
173
- iterations: number;
174
- }
175
-
176
- export interface ReviewRejectedPayload {
177
- taskName: string;
178
- reason: string;
179
- iterations: number;
180
- }
181
-
182
- export interface DependencyPolicy {
183
- allowDependencyChange: boolean;
184
- lockfileReadOnly: boolean;
185
- }
186
-
187
- export interface Task {
188
- name: string;
189
- prompt: string;
190
- model?: string;
191
- /** Acceptance criteria for the AI reviewer to validate */
192
- acceptanceCriteria?: string[];
193
- /** Task-level dependencies (format: "lane:task") */
194
- dependsOn?: string[];
195
- /** Task execution timeout in milliseconds. Overrides lane-level timeout. */
196
- timeout?: number;
197
- }
198
-
199
- export interface RunnerConfig {
200
- tasks: Task[];
201
- dependsOn?: string[];
202
- pipelineBranch?: string;
203
- worktreeDir?: string;
204
- branchPrefix?: string;
205
- worktreeRoot?: string;
206
- baseBranch?: string;
207
- model?: string;
208
- dependencyPolicy: DependencyPolicy;
209
- enableReview?: boolean;
210
- /** Output format for cursor-agent (default: 'stream-json') */
211
- agentOutputFormat?: 'stream-json' | 'json' | 'plain';
212
- reviewModel?: string;
213
- reviewAllTasks?: boolean;
214
- maxReviewIterations?: number;
215
- acceptanceCriteria?: string[];
216
- /** Task execution timeout in milliseconds. Default: 600000 (10 minutes) */
217
- timeout?: number;
218
- /**
219
- * Enable intervention feature (stdin piping for message injection).
220
- * Warning: May cause stdout buffering issues on some systems.
221
- * Default: false
222
- */
223
- enableIntervention?: boolean;
224
- /**
225
- * Disable Git operations (worktree, branch, push, commit).
226
- * Useful for testing or environments without Git remote.
227
- * Default: false
228
- */
229
- noGit?: boolean;
230
- }
231
-
232
- export interface DependencyRequestPlan {
233
- reason: string;
234
- changes: string[];
235
- commands: string[];
236
- notes?: string;
237
- }
238
-
239
- export interface TaskExecutionResult {
240
- taskName: string;
241
- taskBranch: string;
242
- status: 'FINISHED' | 'ERROR' | 'BLOCKED_DEPENDENCY';
243
- error?: string;
244
- dependencyRequest?: DependencyRequestPlan | null;
245
- }
246
-
247
- export interface AgentSendResult {
248
- ok: boolean;
249
- exitCode: number;
250
- error?: string;
251
- sessionId?: string;
252
- resultText?: string;
253
- }
254
-
255
- export interface ReviewIssue {
256
- severity: 'critical' | 'major' | 'minor';
257
- description: string;
258
- file?: string;
259
- suggestion?: string;
260
- }
261
-
262
- export interface ReviewResult {
263
- status: 'approved' | 'needs_changes';
264
- buildSuccess: boolean;
265
- issues: ReviewIssue[];
266
- suggestions: string[];
267
- summary: string;
268
- raw: string;
269
- }
270
-
271
- export interface TaskResult {
272
- taskName: string;
273
- taskBranch: string;
274
- acceptanceCriteria?: string[];
275
- [key: string]: any;
276
- }
277
-
278
- export interface LaneState {
279
- label: string;
280
- status: 'pending' | 'running' | 'completed' | 'failed' | 'paused' | 'waiting' | 'reviewing';
281
- currentTaskIndex: number;
282
- totalTasks: number;
283
- worktreeDir: string | null;
284
- pipelineBranch: string | null;
285
- startTime: number;
286
- endTime: number | null;
287
- error: string | null;
288
- dependencyRequest: DependencyRequestPlan | null;
289
- updatedAt?: number;
290
- tasksFile?: string; // Original tasks file path
291
- dependsOn?: string[];
292
- pid?: number;
293
- /** List of completed task names in this lane */
294
- completedTasks?: string[];
295
- /** Task-level dependencies currently being waited for (format: "lane:task") */
296
- waitingFor?: string[];
297
- }
298
-
299
- export interface ConversationEntry {
300
- timestamp: string;
301
- role: 'user' | 'assistant' | 'reviewer' | 'system';
302
- task: string | null;
303
- fullText: string;
304
- textLength: number;
305
- model: string | null;
306
- }
307
-
308
- export interface GitLogEntry {
309
- timestamp: string;
310
- operation: string;
311
- [key: string]: any;
312
- }
313
-
314
- export interface EventEntry {
315
- timestamp: string;
316
- event: string;
317
- [key: string]: any;
318
- }
319
-
6
+ export * from '../types';