@litmers/cursorflow-orchestrator 0.1.31 → 0.1.36

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/CHANGELOG.md +27 -0
  2. package/README.md +182 -59
  3. package/commands/cursorflow-add.md +159 -0
  4. package/commands/cursorflow-doctor.md +45 -23
  5. package/commands/cursorflow-monitor.md +23 -2
  6. package/commands/cursorflow-new.md +87 -0
  7. package/commands/cursorflow-run.md +60 -111
  8. package/dist/cli/add.d.ts +7 -0
  9. package/dist/cli/add.js +377 -0
  10. package/dist/cli/add.js.map +1 -0
  11. package/dist/cli/clean.js +1 -0
  12. package/dist/cli/clean.js.map +1 -1
  13. package/dist/cli/config.d.ts +7 -0
  14. package/dist/cli/config.js +181 -0
  15. package/dist/cli/config.js.map +1 -0
  16. package/dist/cli/doctor.js +47 -4
  17. package/dist/cli/doctor.js.map +1 -1
  18. package/dist/cli/index.js +34 -30
  19. package/dist/cli/index.js.map +1 -1
  20. package/dist/cli/logs.js +17 -34
  21. package/dist/cli/logs.js.map +1 -1
  22. package/dist/cli/monitor.js +62 -65
  23. package/dist/cli/monitor.js.map +1 -1
  24. package/dist/cli/new.d.ts +7 -0
  25. package/dist/cli/new.js +232 -0
  26. package/dist/cli/new.js.map +1 -0
  27. package/dist/cli/prepare.js +95 -193
  28. package/dist/cli/prepare.js.map +1 -1
  29. package/dist/cli/resume.js +57 -68
  30. package/dist/cli/resume.js.map +1 -1
  31. package/dist/cli/run.js +60 -30
  32. package/dist/cli/run.js.map +1 -1
  33. package/dist/cli/stop.js +6 -0
  34. package/dist/cli/stop.js.map +1 -1
  35. package/dist/cli/tasks.d.ts +5 -3
  36. package/dist/cli/tasks.js +181 -29
  37. package/dist/cli/tasks.js.map +1 -1
  38. package/dist/core/failure-policy.d.ts +9 -0
  39. package/dist/core/failure-policy.js +9 -0
  40. package/dist/core/failure-policy.js.map +1 -1
  41. package/dist/core/orchestrator.d.ts +20 -6
  42. package/dist/core/orchestrator.js +215 -334
  43. package/dist/core/orchestrator.js.map +1 -1
  44. package/dist/core/runner/agent.d.ts +27 -0
  45. package/dist/core/runner/agent.js +294 -0
  46. package/dist/core/runner/agent.js.map +1 -0
  47. package/dist/core/runner/index.d.ts +5 -0
  48. package/dist/core/runner/index.js +22 -0
  49. package/dist/core/runner/index.js.map +1 -0
  50. package/dist/core/runner/pipeline.d.ts +9 -0
  51. package/dist/core/runner/pipeline.js +539 -0
  52. package/dist/core/runner/pipeline.js.map +1 -0
  53. package/dist/core/runner/prompt.d.ts +25 -0
  54. package/dist/core/runner/prompt.js +175 -0
  55. package/dist/core/runner/prompt.js.map +1 -0
  56. package/dist/core/runner/task.d.ts +26 -0
  57. package/dist/core/runner/task.js +283 -0
  58. package/dist/core/runner/task.js.map +1 -0
  59. package/dist/core/runner/utils.d.ts +37 -0
  60. package/dist/core/runner/utils.js +161 -0
  61. package/dist/core/runner/utils.js.map +1 -0
  62. package/dist/core/runner.d.ts +2 -96
  63. package/dist/core/runner.js +11 -1136
  64. package/dist/core/runner.js.map +1 -1
  65. package/dist/core/stall-detection.d.ts +326 -0
  66. package/dist/core/stall-detection.js +781 -0
  67. package/dist/core/stall-detection.js.map +1 -0
  68. package/dist/services/logging/console.js +2 -1
  69. package/dist/services/logging/console.js.map +1 -1
  70. package/dist/types/config.d.ts +6 -6
  71. package/dist/types/flow.d.ts +84 -0
  72. package/dist/types/flow.js +10 -0
  73. package/dist/types/flow.js.map +1 -0
  74. package/dist/types/index.d.ts +1 -0
  75. package/dist/types/index.js +3 -3
  76. package/dist/types/index.js.map +1 -1
  77. package/dist/types/lane.d.ts +0 -2
  78. package/dist/types/logging.d.ts +5 -1
  79. package/dist/types/task.d.ts +7 -11
  80. package/dist/utils/config.d.ts +5 -1
  81. package/dist/utils/config.js +15 -16
  82. package/dist/utils/config.js.map +1 -1
  83. package/dist/utils/dependency.d.ts +36 -1
  84. package/dist/utils/dependency.js +256 -1
  85. package/dist/utils/dependency.js.map +1 -1
  86. package/dist/utils/doctor.js +40 -8
  87. package/dist/utils/doctor.js.map +1 -1
  88. package/dist/utils/enhanced-logger.d.ts +45 -82
  89. package/dist/utils/enhanced-logger.js +239 -844
  90. package/dist/utils/enhanced-logger.js.map +1 -1
  91. package/dist/utils/flow.d.ts +9 -0
  92. package/dist/utils/flow.js +73 -0
  93. package/dist/utils/flow.js.map +1 -0
  94. package/dist/utils/git.d.ts +29 -0
  95. package/dist/utils/git.js +115 -5
  96. package/dist/utils/git.js.map +1 -1
  97. package/dist/utils/state.js +0 -2
  98. package/dist/utils/state.js.map +1 -1
  99. package/dist/utils/task-service.d.ts +2 -2
  100. package/dist/utils/task-service.js +40 -31
  101. package/dist/utils/task-service.js.map +1 -1
  102. package/package.json +4 -3
  103. package/src/cli/add.ts +397 -0
  104. package/src/cli/clean.ts +1 -0
  105. package/src/cli/config.ts +177 -0
  106. package/src/cli/doctor.ts +48 -4
  107. package/src/cli/index.ts +36 -32
  108. package/src/cli/logs.ts +20 -33
  109. package/src/cli/monitor.ts +70 -75
  110. package/src/cli/new.ts +235 -0
  111. package/src/cli/prepare.ts +98 -205
  112. package/src/cli/resume.ts +61 -76
  113. package/src/cli/run.ts +333 -306
  114. package/src/cli/stop.ts +8 -0
  115. package/src/cli/tasks.ts +200 -21
  116. package/src/core/failure-policy.ts +9 -0
  117. package/src/core/orchestrator.ts +279 -379
  118. package/src/core/runner/agent.ts +314 -0
  119. package/src/core/runner/index.ts +6 -0
  120. package/src/core/runner/pipeline.ts +567 -0
  121. package/src/core/runner/prompt.ts +174 -0
  122. package/src/core/runner/task.ts +320 -0
  123. package/src/core/runner/utils.ts +142 -0
  124. package/src/core/runner.ts +8 -1347
  125. package/src/core/stall-detection.ts +936 -0
  126. package/src/services/logging/console.ts +2 -1
  127. package/src/types/config.ts +6 -6
  128. package/src/types/flow.ts +91 -0
  129. package/src/types/index.ts +15 -3
  130. package/src/types/lane.ts +0 -2
  131. package/src/types/logging.ts +5 -1
  132. package/src/types/task.ts +7 -11
  133. package/src/utils/config.ts +16 -17
  134. package/src/utils/dependency.ts +311 -2
  135. package/src/utils/doctor.ts +36 -8
  136. package/src/utils/enhanced-logger.ts +264 -927
  137. package/src/utils/flow.ts +42 -0
  138. package/src/utils/git.ts +145 -5
  139. package/src/utils/state.ts +0 -2
  140. package/src/utils/task-service.ts +48 -40
  141. package/commands/cursorflow-review.md +0 -56
  142. package/commands/cursorflow-runs.md +0 -59
  143. package/dist/cli/runs.d.ts +0 -5
  144. package/dist/cli/runs.js +0 -214
  145. package/dist/cli/runs.js.map +0 -1
  146. package/dist/core/reviewer.d.ts +0 -66
  147. package/dist/core/reviewer.js +0 -265
  148. package/dist/core/reviewer.js.map +0 -1
  149. package/src/cli/runs.ts +0 -212
  150. package/src/core/reviewer.ts +0 -285
package/src/cli/runs.ts DELETED
@@ -1,212 +0,0 @@
1
- /**
2
- * CursorFlow runs command - List and view run details
3
- */
4
-
5
- import * as fs from 'fs';
6
- import * as path from 'path';
7
- import * as logger from '../utils/logger';
8
- import { loadConfig, getLogsDir } from '../utils/config';
9
- import { RunService } from '../utils/run-service';
10
- import { RunStatus, RunInfo } from '../utils/types';
11
- import { safeJoin } from '../utils/path';
12
-
13
- interface RunsOptions {
14
- status?: RunStatus;
15
- json: boolean;
16
- help: boolean;
17
- runId?: string;
18
- }
19
-
20
- function printHelp(): void {
21
- console.log(`
22
- Usage: cursorflow runs [run-id] [options]
23
-
24
- List all runs or view details of a specific run.
25
-
26
- Options:
27
- [run-id] View details of a specific run
28
- --running Filter to show only running runs
29
- --status <status> Filter by status: running, completed, failed, partial, pending
30
- --json Output in JSON format
31
- --help, -h Show help
32
-
33
- Examples:
34
- cursorflow runs # List all runs
35
- cursorflow runs --running # List only running runs
36
- cursorflow runs run-123 # View details of run-123
37
- `);
38
- }
39
-
40
- function parseArgs(args: string[]): RunsOptions {
41
- const statusIdx = args.indexOf('--status');
42
- const running = args.includes('--running');
43
-
44
- // Find run ID (first non-option argument)
45
- const runId = args.find((arg, i) => {
46
- if (arg.startsWith('--') || arg.startsWith('-')) return false;
47
- // Skip values for options
48
- const prevArg = args[i - 1];
49
- if (prevArg && ['--status'].includes(prevArg)) {
50
- return false;
51
- }
52
- return true;
53
- });
54
-
55
- return {
56
- runId,
57
- status: running ? 'running' : (statusIdx >= 0 ? args[statusIdx + 1] as RunStatus : undefined),
58
- json: args.includes('--json'),
59
- help: args.includes('--help') || args.includes('-h'),
60
- };
61
- }
62
-
63
- /**
64
- * Format duration in a human-readable way
65
- */
66
- function formatDuration(ms: number): string {
67
- if (ms < 1000) return `${ms}ms`;
68
- const seconds = Math.floor(ms / 1000);
69
- if (seconds < 60) return `${seconds}s`;
70
- const minutes = Math.floor(seconds / 60);
71
- const remainingSeconds = seconds % 60;
72
- if (minutes < 60) return `${minutes}m ${remainingSeconds}s`;
73
- const hours = Math.floor(minutes / 60);
74
- const remainingMinutes = minutes % 60;
75
- return `${hours}h ${remainingMinutes}m`;
76
- }
77
-
78
- /**
79
- * Get status color and emoji
80
- */
81
- function getStatusDisplay(status: RunStatus): string {
82
- switch (status) {
83
- case 'running':
84
- return `${logger.COLORS.blue}🔄 running${logger.COLORS.reset}`;
85
- case 'completed':
86
- return `${logger.COLORS.green}✅ done ${logger.COLORS.reset}`;
87
- case 'failed':
88
- return `${logger.COLORS.red}❌ failed ${logger.COLORS.reset}`;
89
- case 'partial':
90
- return `${logger.COLORS.yellow}⚠️ partial${logger.COLORS.reset}`;
91
- case 'pending':
92
- return `${logger.COLORS.gray}⏳ pending${logger.COLORS.reset}`;
93
- default:
94
- return status;
95
- }
96
- }
97
-
98
- /**
99
- * Display list of runs
100
- */
101
- function displayRunList(runs: RunInfo[]): void {
102
- if (runs.length === 0) {
103
- console.log('No runs found.');
104
- return;
105
- }
106
-
107
- console.log(` Run ID Task Status Lanes Duration`);
108
- console.log(`${logger.COLORS.cyan}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${logger.COLORS.reset}`);
109
-
110
- for (const run of runs) {
111
- const isRunning = run.status === 'running';
112
- const prefix = isRunning ? `${logger.COLORS.blue} ▶${logger.COLORS.reset}` : ' ';
113
-
114
- const id = run.id.padEnd(20);
115
- const task = (run.taskName || 'unnamed').substring(0, 15).padEnd(15);
116
- const status = getStatusDisplay(run.status);
117
-
118
- const completedLanes = run.lanes.filter(l => l.status === 'completed').length;
119
- const totalLanes = run.lanes.length;
120
- const lanes = `${completedLanes}/${totalLanes}`.padEnd(10);
121
-
122
- const duration = formatDuration(run.duration);
123
-
124
- console.log(`${prefix} ${id} ${task} ${status} ${lanes} ${duration}`);
125
- }
126
- }
127
-
128
- /**
129
- * Display detailed information for a single run
130
- */
131
- function displayRunDetail(run: RunInfo): void {
132
- logger.section(`Run Details: ${run.id}`);
133
-
134
- console.log(`${logger.COLORS.bold}Task:${logger.COLORS.reset} ${run.taskName}`);
135
- console.log(`${logger.COLORS.bold}Status:${logger.COLORS.reset} ${getStatusDisplay(run.status)}`);
136
- console.log(`${logger.COLORS.bold}Start Time:${logger.COLORS.reset} ${new Date(run.startTime).toLocaleString()}`);
137
- console.log(`${logger.COLORS.bold}Duration:${logger.COLORS.reset} ${formatDuration(run.duration)}`);
138
- console.log(`${logger.COLORS.bold}Path:${logger.COLORS.reset} ${run.path}`);
139
-
140
- console.log(`\n${logger.COLORS.bold}Lanes:${logger.COLORS.reset}`);
141
- for (const lane of run.lanes) {
142
- const statusColor = lane.status === 'completed' ? logger.COLORS.green :
143
- lane.status === 'failed' ? logger.COLORS.red :
144
- lane.status === 'running' ? logger.COLORS.blue : logger.COLORS.reset;
145
-
146
- console.log(` - ${lane.name.padEnd(20)} [${statusColor}${lane.status.toUpperCase()}${logger.COLORS.reset}] Task ${lane.currentTask}/${lane.totalTasks} (PID: ${lane.pid || 'N/A'})`);
147
- }
148
-
149
- if (run.branches.length > 0) {
150
- console.log(`\n${logger.COLORS.bold}Branches:${logger.COLORS.reset}`);
151
- for (const branch of run.branches) {
152
- console.log(` - ${branch}`);
153
- }
154
- }
155
-
156
- if (run.worktrees.length > 0) {
157
- console.log(`\n${logger.COLORS.bold}Worktrees:${logger.COLORS.reset}`);
158
- for (const wt of run.worktrees) {
159
- console.log(` - ${wt}`);
160
- }
161
- }
162
-
163
- console.log(`\nView logs: ${logger.COLORS.cyan}cursorflow logs ${run.id} --all${logger.COLORS.reset}`);
164
- }
165
-
166
- async function runs(args: string[]): Promise<void> {
167
- const options = parseArgs(args);
168
-
169
- if (options.help) {
170
- printHelp();
171
- return;
172
- }
173
-
174
- const config = loadConfig();
175
- const logsDir = getLogsDir(config);
176
- const runsDir = safeJoin(logsDir, 'runs');
177
-
178
- if (!fs.existsSync(runsDir)) {
179
- if (options.json) {
180
- console.log('[]');
181
- } else {
182
- console.log('No runs found. (Runs directory does not exist)');
183
- }
184
- return;
185
- }
186
-
187
- const runService = new RunService(runsDir);
188
-
189
- if (options.runId) {
190
- const run = runService.getRunInfo(options.runId);
191
- if (!run) {
192
- throw new Error(`Run not found: ${options.runId}`);
193
- }
194
-
195
- if (options.json) {
196
- console.log(JSON.stringify(run, null, 2));
197
- } else {
198
- displayRunDetail(run);
199
- }
200
- return;
201
- }
202
-
203
- const runsList = runService.listRuns({ status: options.status });
204
-
205
- if (options.json) {
206
- console.log(JSON.stringify(runsList, null, 2));
207
- } else {
208
- displayRunList(runsList);
209
- }
210
- }
211
-
212
- export = runs;
@@ -1,285 +0,0 @@
1
- /**
2
- * Reviewer - Code review agent
3
- *
4
- * Adapted from reviewer-agent.js
5
- */
6
-
7
- import * as logger from '../utils/logger';
8
- import { appendLog, createConversationEntry } from '../utils/state';
9
- import * as path from 'path';
10
- import { ReviewResult, ReviewIssue, TaskResult, RunnerConfig, AgentSendResult } from '../utils/types';
11
- import { events } from '../utils/events';
12
-
13
- /**
14
- * Build review prompt
15
- */
16
- export function buildReviewPrompt({ taskName, taskBranch, acceptanceCriteria = [] }: { taskName: string; taskBranch: string; acceptanceCriteria?: string[] }): string {
17
- const criteriaList = acceptanceCriteria.length > 0
18
- ? acceptanceCriteria.map((c, i) => `${i + 1}. ${c}`).join('\n')
19
- : 'Work should be completed properly.';
20
-
21
- return `# Code Review: ${taskName}
22
-
23
- ## Role
24
- You are a senior code reviewer. Please review the results of this task.
25
-
26
- ## Task Details
27
- - Name: ${taskName}
28
- - Branch: ${taskBranch}
29
-
30
- ## Acceptance Criteria
31
- ${criteriaList}
32
-
33
- ## Review Checklist
34
- 1. **Build Success**: Does \`pnpm build\` complete without errors?
35
- 2. **Code Quality**: Are there no linting or TypeScript type errors?
36
- 3. **Completeness**: Are all acceptance criteria met?
37
- 4. **Bugs**: Are there any obvious bugs or logic errors?
38
- 5. **Commit Status**: Are changes properly committed and pushed?
39
-
40
- ## Output Format (MUST follow exactly)
41
- \`\`\`json
42
- {
43
- "status": "approved" | "needs_changes",
44
- "buildSuccess": true | false,
45
- "issues": [
46
- {
47
- "severity": "critical" | "major" | "minor",
48
- "description": "...",
49
- "file": "...",
50
- "suggestion": "..."
51
- }
52
- ],
53
- "suggestions": ["..."],
54
- "summary": "One-line summary"
55
- }
56
- \`\`\`
57
-
58
- IMPORTANT: You MUST respond in the exact JSON format above. "status" must be either "approved" or "needs_changes".
59
- `;
60
- }
61
-
62
- /**
63
- * Parse review result
64
- */
65
- export function parseReviewResult(text: string): ReviewResult {
66
- const t = String(text || '');
67
-
68
- // Try JSON block
69
- const jsonMatch = t.match(/```json\n([\s\S]*?)\n```/);
70
- if (jsonMatch) {
71
- try {
72
- const parsed = JSON.parse(jsonMatch[1]!);
73
- return {
74
- status: parsed.status || 'needs_changes',
75
- buildSuccess: parsed.buildSuccess !== false,
76
- issues: Array.isArray(parsed.issues) ? (parsed.issues as ReviewIssue[]) : [],
77
- suggestions: Array.isArray(parsed.suggestions) ? (parsed.suggestions as string[]) : [],
78
- summary: parsed.summary || '',
79
- raw: t,
80
- };
81
- } catch (err: any) {
82
- logger.warn(`JSON parse failed: ${err.message}`);
83
- }
84
- }
85
-
86
- // Fallback parsing
87
- const hasApproved = t.toLowerCase().includes('approved');
88
- const hasIssues = t.toLowerCase().includes('needs_changes') ||
89
- t.toLowerCase().includes('error') ||
90
- t.toLowerCase().includes('failed');
91
-
92
- return {
93
- status: hasApproved && !hasIssues ? 'approved' : 'needs_changes',
94
- buildSuccess: !t.toLowerCase().includes('build') || !t.toLowerCase().includes('fail'),
95
- issues: hasIssues ? [{ severity: 'major', description: 'Parse failed, see logs' }] : [],
96
- suggestions: [],
97
- summary: 'Auto-parsed - check original response',
98
- raw: t,
99
- };
100
- }
101
-
102
- /**
103
- * Build feedback prompt
104
- */
105
- export function buildFeedbackPrompt(review: ReviewResult): string {
106
- const lines: string[] = [];
107
- lines.push('# Code Review Feedback');
108
- lines.push('');
109
- lines.push('The reviewer found the following issues. Please fix them:');
110
- lines.push('');
111
-
112
- if (!review.buildSuccess) {
113
- lines.push('## CRITICAL: Build Failed');
114
- lines.push('- \`pnpm build\` failed. Fix build errors first.');
115
- lines.push('');
116
- }
117
-
118
- for (const issue of review.issues || []) {
119
- const severity = (issue.severity || 'major').toUpperCase();
120
- lines.push(`## ${severity}: ${issue.description}`);
121
- if (issue.file) lines.push(`- File: ${issue.file}`);
122
- if (issue.suggestion) lines.push(`- Suggestion: ${issue.suggestion}`);
123
- lines.push('');
124
- }
125
-
126
- if (review.suggestions && review.suggestions.length > 0) {
127
- lines.push('## Additional Suggestions');
128
- for (const s of review.suggestions) {
129
- lines.push(`- ${s}`);
130
- }
131
- lines.push('');
132
- }
133
-
134
- lines.push('## Requirements');
135
- lines.push('1. Fix all issues listed above');
136
- lines.push('2. Ensure \`pnpm build\` succeeds');
137
- lines.push('3. Commit and push your changes');
138
- lines.push('');
139
- lines.push('**Let me know when fixes are complete.**');
140
-
141
- return lines.join('\n');
142
- }
143
-
144
- /**
145
- * Review task
146
- */
147
- export async function reviewTask({ taskResult, worktreeDir, runDir, config, model, cursorAgentSend, cursorAgentCreateChat }: {
148
- taskResult: TaskResult;
149
- worktreeDir: string;
150
- runDir: string;
151
- config: RunnerConfig;
152
- model?: string;
153
- cursorAgentSend: (options: {
154
- workspaceDir: string;
155
- chatId: string;
156
- prompt: string;
157
- model?: string;
158
- outputFormat?: 'stream-json' | 'json' | 'plain';
159
- taskName?: string;
160
- }) => Promise<AgentSendResult>;
161
- cursorAgentCreateChat: () => string;
162
- }): Promise<ReviewResult> {
163
- const reviewPrompt = buildReviewPrompt({
164
- taskName: taskResult.taskName,
165
- taskBranch: taskResult.taskBranch,
166
- acceptanceCriteria: taskResult.acceptanceCriteria || config.acceptanceCriteria || [],
167
- });
168
-
169
- logger.info(`Reviewing: ${taskResult.taskName}`);
170
-
171
- events.emit('review.started', {
172
- taskName: taskResult.taskName,
173
- taskBranch: taskResult.taskBranch,
174
- });
175
-
176
- const reviewChatId = cursorAgentCreateChat();
177
- const reviewModel = model || config.reviewModel || config.model || 'sonnet-4.5';
178
-
179
- const reviewResult = await cursorAgentSend({
180
- workspaceDir: worktreeDir,
181
- chatId: reviewChatId,
182
- prompt: reviewPrompt,
183
- model: reviewModel,
184
- outputFormat: config.agentOutputFormat,
185
- taskName: `review:${taskResult.taskName}`,
186
- });
187
-
188
- const review = parseReviewResult(reviewResult.resultText || '');
189
-
190
- // Log review
191
- const convoPath = path.join(runDir, 'conversation.jsonl');
192
- appendLog(convoPath, createConversationEntry('reviewer', reviewResult.resultText || 'No result', {
193
- task: taskResult.taskName,
194
- model: reviewModel,
195
- }));
196
-
197
- logger.info(`Review result: ${review.status} (${review.issues?.length || 0} issues)`);
198
-
199
- events.emit('review.completed', {
200
- taskName: taskResult.taskName,
201
- status: review.status,
202
- issueCount: review.issues?.length || 0,
203
- summary: review.summary,
204
- });
205
-
206
- return review;
207
- }
208
-
209
- /**
210
- * Review loop with feedback
211
- */
212
- export async function runReviewLoop({ taskResult, worktreeDir, runDir, config, workChatId, model, cursorAgentSend, cursorAgentCreateChat }: {
213
- taskResult: TaskResult;
214
- worktreeDir: string;
215
- runDir: string;
216
- config: RunnerConfig;
217
- workChatId: string;
218
- model?: string;
219
- cursorAgentSend: (options: {
220
- workspaceDir: string;
221
- chatId: string;
222
- prompt: string;
223
- model?: string;
224
- outputFormat?: 'stream-json' | 'json' | 'plain';
225
- taskName?: string;
226
- }) => Promise<AgentSendResult>;
227
- cursorAgentCreateChat: () => string;
228
- }): Promise<{ approved: boolean; review: ReviewResult; iterations: number; error?: string }> {
229
- const maxIterations = config.maxReviewIterations || 3;
230
- let iteration = 0;
231
- let currentReview: ReviewResult | null = null;
232
-
233
- while (iteration < maxIterations) {
234
- currentReview = await reviewTask({
235
- taskResult,
236
- worktreeDir,
237
- runDir,
238
- config,
239
- model,
240
- cursorAgentSend,
241
- cursorAgentCreateChat,
242
- });
243
-
244
- if (currentReview.status === 'approved') {
245
- logger.success(`Review passed: ${taskResult.taskName} (iteration ${iteration + 1})`);
246
- events.emit('review.approved', {
247
- taskName: taskResult.taskName,
248
- iterations: iteration + 1,
249
- });
250
- return { approved: true, review: currentReview, iterations: iteration + 1 };
251
- }
252
-
253
- iteration++;
254
-
255
- if (iteration >= maxIterations) {
256
- logger.warn(`Max review iterations (${maxIterations}) reached: ${taskResult.taskName}`);
257
- events.emit('review.rejected', {
258
- taskName: taskResult.taskName,
259
- reason: 'Max iterations reached',
260
- iterations: iteration,
261
- });
262
- break;
263
- }
264
-
265
- // Send feedback
266
- logger.info(`Sending feedback (iteration ${iteration}/${maxIterations})`);
267
- const feedbackPrompt = buildFeedbackPrompt(currentReview);
268
-
269
- const fixResult = await cursorAgentSend({
270
- workspaceDir: worktreeDir,
271
- chatId: workChatId,
272
- prompt: feedbackPrompt,
273
- model: config.model,
274
- outputFormat: config.agentOutputFormat,
275
- taskName: taskResult.taskName,
276
- });
277
-
278
- if (!fixResult.ok) {
279
- logger.error(`Feedback application failed: ${fixResult.error}`);
280
- return { approved: false, review: currentReview, iterations: iteration, error: fixResult.error };
281
- }
282
- }
283
-
284
- return { approved: false, review: currentReview!, iterations: iteration };
285
- }