vibecodingmachine-cli 2026.3.14-1537 → 2026.6.17-1956

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 (162) hide show
  1. package/bin/auth/auth-compliance.js +7 -7
  2. package/bin/commands/agent-commands.js +15 -15
  3. package/bin/commands/auto-commands.js +3 -3
  4. package/bin/commands/command-aliases.js +13 -4
  5. package/bin/config/cli-config.js +15 -5
  6. package/bin/update/update-checker.js +5 -5
  7. package/bin/vibecodingmachine.js +2 -2
  8. package/package.json +2 -2
  9. package/src/commands/agents/add.js +5 -5
  10. package/src/commands/agents/check.js +19 -19
  11. package/src/commands/agents/list.js +24 -24
  12. package/src/commands/agents/remove.js +4 -4
  13. package/src/commands/agents-check.js +1 -1
  14. package/src/commands/analyze-file-sizes.js +43 -43
  15. package/src/commands/auto-direct/auto-provider-manager.js +19 -19
  16. package/src/commands/auto-direct/auto-start-phases.js +493 -0
  17. package/src/commands/auto-direct/auto-status-display.js +35 -35
  18. package/src/commands/auto-direct/auto-utils.js +50 -50
  19. package/src/commands/auto-direct/cline-installer.js +56 -0
  20. package/src/commands/auto-direct/code-processor.js +27 -27
  21. package/src/commands/auto-direct/file-scanner.js +19 -19
  22. package/src/commands/auto-direct/ide-completion-waiter.js +485 -0
  23. package/src/commands/auto-direct/ide-fallback-runner.js +226 -0
  24. package/src/commands/auto-direct/ide-provider-runner.js +103 -0
  25. package/src/commands/auto-direct/iteration-handlers.js +189 -0
  26. package/src/commands/auto-direct/iteration-runner.js +485 -0
  27. package/src/commands/auto-direct/provider-config.js +38 -7
  28. package/src/commands/auto-direct/provider-manager.js +132 -6
  29. package/src/commands/auto-direct/requirement-manager.js +169 -104
  30. package/src/commands/auto-direct/requirement-mover.js +350 -0
  31. package/src/commands/auto-direct/spec-handlers.js +155 -0
  32. package/src/commands/auto-direct/spec-ide-runner.js +318 -0
  33. package/src/commands/auto-direct/spec-processing.js +203 -0
  34. package/src/commands/auto-direct/status-display.js +9 -9
  35. package/src/commands/auto-direct/utils.js +83 -1
  36. package/src/commands/auto-direct-refactored.js +1 -413
  37. package/src/commands/auto-direct.js +127 -4119
  38. package/src/commands/auto-execution.js +21 -21
  39. package/src/commands/auto-status-helpers.js +0 -2
  40. package/src/commands/auto.js +22 -22
  41. package/src/commands/check-compliance.js +65 -65
  42. package/src/commands/computers.js +39 -39
  43. package/src/commands/continuous-scan.js +19 -19
  44. package/src/commands/ide.js +4 -4
  45. package/src/commands/locale.js +7 -7
  46. package/src/commands/refactor-file.js +59 -59
  47. package/src/commands/requirements/commands.js +17 -17
  48. package/src/commands/requirements/default-handlers.js +30 -30
  49. package/src/commands/requirements/disable.js +3 -3
  50. package/src/commands/requirements/enable.js +3 -3
  51. package/src/commands/requirements/utils.js +6 -6
  52. package/src/commands/requirements-refactored.js +3 -3
  53. package/src/commands/requirements-remote.js +38 -38
  54. package/src/commands/requirements.js +3 -3
  55. package/src/commands/settings.js +111 -0
  56. package/src/commands/specs/count.js +60 -0
  57. package/src/commands/specs/disable.js +3 -3
  58. package/src/commands/specs/enable.js +3 -3
  59. package/src/commands/status.js +10 -10
  60. package/src/commands/sync.js +25 -25
  61. package/src/commands/timeout.js +35 -35
  62. package/src/trui/TruiInterface.js +2 -2
  63. package/src/trui/agents/AgentInterface.js +4 -4
  64. package/src/trui/agents/handlers/CommandHandler.js +4 -4
  65. package/src/trui/agents/handlers/ContextManager.js +1 -1
  66. package/src/trui/agents/handlers/DisplayHandler.js +11 -11
  67. package/src/trui/agents/handlers/HelpHandler.js +1 -1
  68. package/src/utils/agent-selector.js +6 -6
  69. package/src/utils/antigravity-installer.js +4 -4
  70. package/src/utils/asset-cleanup.js +1 -1
  71. package/src/utils/auth.js +9 -12
  72. package/src/utils/clarification-actions.js +4 -4
  73. package/src/utils/cline-js-handler.js +5 -5
  74. package/src/utils/compliance-check.js +6 -6
  75. package/src/utils/config.js +12 -12
  76. package/src/utils/display-formatters-complete.js +2 -2
  77. package/src/utils/display-formatters-extracted.js +2 -2
  78. package/src/utils/display-formatters.js +2 -2
  79. package/src/utils/feedback-handler.js +2 -2
  80. package/src/utils/first-run.js +7 -7
  81. package/src/utils/ide-detection.js +1 -1
  82. package/src/utils/ide-handlers.js +6 -6
  83. package/src/utils/interactive/clarification-actions.js +3 -3
  84. package/src/utils/interactive/core-ui.js +7 -7
  85. package/src/utils/interactive/file-backup.js +6 -6
  86. package/src/utils/interactive/file-import-export.js +49 -49
  87. package/src/utils/interactive/file-operations.js +3 -3
  88. package/src/utils/interactive/file-validation.js +41 -41
  89. package/src/utils/interactive/interactive-prompts.js +41 -41
  90. package/src/utils/interactive/requirement-actions.js +5 -5
  91. package/src/utils/interactive/requirement-crud.js +4 -4
  92. package/src/utils/interactive/requirements-navigation.js +10 -10
  93. package/src/utils/interactive-broken.js +6 -6
  94. package/src/utils/interactive.js +37 -37
  95. package/src/utils/keyboard-handler.js +4 -4
  96. package/src/utils/prompt-helper.js +6 -6
  97. package/src/utils/provider-checker/agent-checker.js +1 -1
  98. package/src/utils/provider-checker/agent-runner.js +203 -314
  99. package/src/utils/provider-checker/agents-file-lock.js +134 -0
  100. package/src/utils/provider-checker/agents-manager.js +224 -36
  101. package/src/utils/provider-checker/cli-installer.js +28 -28
  102. package/src/utils/provider-checker/cli-utils.js +2 -2
  103. package/src/utils/provider-checker/cursor-approval-clicker.js +108 -0
  104. package/src/utils/provider-checker/format-utils.js +4 -4
  105. package/src/utils/provider-checker/ide-installer-helper.js +96 -0
  106. package/src/utils/provider-checker/ide-manager.js +19 -8
  107. package/src/utils/provider-checker/ide-quota-checker.js +120 -0
  108. package/src/utils/provider-checker/ide-utils.js +2 -2
  109. package/src/utils/provider-checker/node-detector.js +4 -4
  110. package/src/utils/provider-checker/node-utils.js +5 -5
  111. package/src/utils/provider-checker/opencode-checker.js +107 -73
  112. package/src/utils/provider-checker/process-utils.js +1 -1
  113. package/src/utils/provider-checker/provider-validator.js +11 -11
  114. package/src/utils/provider-checker/quota-checker.js +5 -5
  115. package/src/utils/provider-checker/quota-detector.js +5 -5
  116. package/src/utils/provider-checker/requirements-manager.js +6 -6
  117. package/src/utils/provider-checker/test-requirements.js +1 -1
  118. package/src/utils/provider-checker/vscode-approval-clicker.js +328 -0
  119. package/src/utils/provider-checker-new.js +6 -6
  120. package/src/utils/provider-checker.js +6 -6
  121. package/src/utils/provider-checkers/ide-manager.js +13 -13
  122. package/src/utils/provider-checkers/node-executable-finder.js +4 -4
  123. package/src/utils/provider-checkers/provider-checker-core.js +5 -5
  124. package/src/utils/provider-checkers/provider-checker-main.js +17 -17
  125. package/src/utils/provider-registry.js +5 -6
  126. package/src/utils/provider-utils.js +12 -12
  127. package/src/utils/quota-detectors.js +32 -32
  128. package/src/utils/requirement-action-handlers.js +12 -12
  129. package/src/utils/requirement-actions/requirement-operations.js +3 -3
  130. package/src/utils/requirement-actions.js +1 -1
  131. package/src/utils/requirement-file-operations.js +5 -5
  132. package/src/utils/requirement-helpers.js +1 -1
  133. package/src/utils/requirement-management.js +5 -5
  134. package/src/utils/requirement-navigation.js +2 -2
  135. package/src/utils/requirement-organization.js +3 -3
  136. package/src/utils/rui-trui-adapter.js +14 -14
  137. package/src/utils/simple-trui.js +3 -3
  138. package/src/utils/status-helpers-extracted.js +3 -3
  139. package/src/utils/trui-clarifications.js +11 -11
  140. package/src/utils/trui-debug.js +3 -2
  141. package/src/utils/trui-devin.js +217 -0
  142. package/src/utils/trui-feedback.js +7 -7
  143. package/src/utils/trui-kiro-integration.js +34 -34
  144. package/src/utils/trui-main-handlers.js +20 -21
  145. package/src/utils/trui-main-menu.js +19 -19
  146. package/src/utils/trui-nav-agents.js +59 -8
  147. package/src/utils/trui-nav-requirements.js +3 -3
  148. package/src/utils/trui-nav-settings.js +10 -10
  149. package/src/utils/trui-nav-specifications.js +1 -1
  150. package/src/utils/trui-navigation-backup.js +11 -11
  151. package/src/utils/trui-navigation.js +9 -9
  152. package/src/utils/trui-provider-health.js +25 -25
  153. package/src/utils/trui-provider-manager.js +28 -28
  154. package/src/utils/trui-quick-menu.js +2 -2
  155. package/src/utils/trui-req-actions-backup.js +21 -21
  156. package/src/utils/trui-req-actions.js +20 -20
  157. package/src/utils/trui-req-editor.js +10 -10
  158. package/src/utils/trui-req-file-ops.js +3 -3
  159. package/src/utils/trui-req-tree.js +7 -7
  160. package/src/utils/trui-windsurf.js +103 -103
  161. package/src/utils/user-tracking.js +15 -15
  162. package/src/utils/trui-req-tree-old.js +0 -719
@@ -0,0 +1,226 @@
1
+ /**
2
+ * IDE Fallback Runner - Direct IDE Iteration Handler
3
+ *
4
+ * Extracted from iteration-handlers.js for constitutional compliance (<555 lines per file)
5
+ * Handles IDE fallback iterations (no context gathering, direct IDE spawn).
6
+ */
7
+
8
+ const chalk = require('chalk');
9
+ const vibecodingmachineCore = require('vibecodingmachine-core');
10
+ const { TimeoutCalculator, t } = vibecodingmachineCore;
11
+
12
+ // Import auto mode utilities
13
+ const { handleAntigravityRateLimit } = require('../../utils/antigravity-js-handler');
14
+ const { handleKiroRateLimit } = require('../../utils/kiro-js-handler');
15
+ const { handleClineRateLimit } = require('../../utils/cline-js-handler');
16
+
17
+ // Import modular functions
18
+ const {
19
+ updateRequirementsStatus,
20
+ moveRequirementToVerify
21
+ } = require('./requirement-manager');
22
+
23
+ const {
24
+ printStatusCard
25
+ } = require('./status-display');
26
+
27
+ // Import split module functions
28
+ const { waitForIdeCompletion } = require('./ide-completion-waiter');
29
+ const { runIdeProviderIteration } = require('./ide-provider-runner');
30
+
31
+ // Shared variables set by parent module
32
+ let sharedProviderManager = null;
33
+ let sharedHealthTracker = null;
34
+
35
+ /**
36
+ * Initialize module with shared instances
37
+ */
38
+ function initialize(deps) {
39
+ sharedProviderManager = deps.providerManager;
40
+ sharedHealthTracker = deps.healthTracker;
41
+ }
42
+
43
+ /**
44
+ * Run an IDE fallback iteration (no context gathering, direct IDE spawn)
45
+ * @param {Object} requirement - Requirement object
46
+ * @param {Object} providerConfig - Provider configuration
47
+ * @param {string} repoPath - Repository path
48
+ * @param {Object} providerManager - Provider manager instance
49
+ * @param {Object} llm - DirectLLMManager instance
50
+ * @param {number} startTime - Start time timestamp
51
+ * @returns {Promise<{success: boolean, error?: string, shouldRetry?: boolean}>}
52
+ */
53
+ async function runIdeFallbackIteration(requirement, providerConfig, repoPath, providerManager, llm, startTime) {
54
+ // Update console and requirements file with PREPARE status
55
+ printStatusCard(requirement.text, 'PREPARE', 'active');
56
+ await updateRequirementsStatus(repoPath, 'PREPARE');
57
+ console.log(chalk.gray(`${t('auto.direct.ide.skipping.context')}\n`));
58
+
59
+ // Update console and requirements file with ACT status
60
+ printStatusCard(requirement.text, 'ACT', 'active');
61
+ await updateRequirementsStatus(repoPath, 'ACT');
62
+ const ideResult = await runIdeProviderIteration(providerConfig, repoPath);
63
+
64
+ if (!ideResult.success) {
65
+ if (ideResult.antigravityRateLimited) {
66
+ providerManager.markRateLimited(providerConfig.provider, providerConfig.model, 'Quota limit reached');
67
+ const switchResult = await handleAntigravityRateLimit();
68
+ if (switchResult && switchResult.modelSwitched) {
69
+ return { success: false, error: `Antigravity switched to ${switchResult.nextModel}, retrying.`, shouldRetry: true };
70
+ }
71
+ return { success: false, error: 'Antigravity rate limit reached, retrying with next provider.', shouldRetry: true };
72
+ }
73
+
74
+ // CRITICAL: Mark provider as unavailable for ANY error so acquireProviderConfig() will skip it
75
+ // EXCEPT for web-based IDEs where the error is platform/browser related
76
+ const error = ideResult.output || ideResult.error || 'IDE provider failed';
77
+ const isWebBasedIDE = providerConfig.provider === 'replit';
78
+ const isPlatformError = error.includes('xdg-open') || error.includes('command not found') || error.includes('Unable to find application');
79
+
80
+ if (!isWebBasedIDE || !isPlatformError) {
81
+ providerManager.markRateLimited(providerConfig.provider, providerConfig.model, error);
82
+ } else {
83
+ // For web-based IDEs with platform errors, don't mark as rate limited
84
+ // Just log the error and let the system try the next provider
85
+ console.log(chalk.yellow(`⚠ Web-based IDE ${providerConfig.provider} failed due to platform issue: ${error}`));
86
+ }
87
+
88
+ return { success: false, error: ideResult.error || 'IDE provider failed' };
89
+ }
90
+
91
+ console.log(chalk.green(`✓ ${t('auto.direct.ide.prompt.sent')}`));
92
+
93
+ // Calculate adaptive timeout based on IDE's historical performance
94
+ const ideType = providerConfig.provider || providerConfig.ide;
95
+ const healthMetrics = sharedHealthTracker.getHealthMetrics(ideType);
96
+ let adaptiveTimeoutMs = 30 * 60 * 1000; // Default 30 minutes
97
+
98
+ if (healthMetrics && healthMetrics.responseTimes.length > 0) {
99
+ // Use adaptive timeout calculation if we have historical data
100
+ const stats = TimeoutCalculator.calculateTimeout(healthMetrics.responseTimes, {
101
+ defaultTimeout: 30 * 60 * 1000,
102
+ minTimeout: 5 * 60 * 1000, // 5 minutes minimum
103
+ maxTimeout: 60 * 60 * 1000, // 60 minutes maximum
104
+ bufferPercentage: 0.5 // 50% buffer
105
+ });
106
+ adaptiveTimeoutMs = stats.timeout;
107
+ console.log(chalk.gray(` Using adaptive timeout: ${Math.floor(adaptiveTimeoutMs / 60000)} minutes (based on ${healthMetrics.responseTimes.length} historical response times)`));
108
+ } else {
109
+ console.log(chalk.gray(` Using default timeout: ${Math.floor(adaptiveTimeoutMs / 60000)} minutes (no historical data for ${ideType})`));
110
+ }
111
+
112
+ // Wait for IDE agent to complete the work (IDE will update status to DONE itself)
113
+ const ideCompletionStartTime = Date.now();
114
+ const completionResult = await waitForIdeCompletion(repoPath, requirement.text, ideType, adaptiveTimeoutMs);
115
+ const ideResponseTime = Date.now() - ideCompletionStartTime;
116
+
117
+ // Track IDE health metrics based on completion result
118
+ if (completionResult.success) {
119
+ // Record success with response time
120
+ await sharedHealthTracker.recordSuccess(ideType, ideResponseTime, {
121
+ requirementId: requirement.id || requirement.text.substring(0, 50),
122
+ continuationPromptsDetected: 0, // Will be updated when continuation detection is implemented
123
+ });
124
+ } else if (completionResult.rateLimited) {
125
+ // Record quota event (does NOT increment success/failure counters per FR-008)
126
+ await sharedHealthTracker.recordQuota(ideType, completionResult.matchedLine || 'Quota limit detected', {
127
+ requirementId: requirement.id || requirement.text.substring(0, 50),
128
+ });
129
+ } else if (completionResult.reason === 'timeout') {
130
+ // Record failure due to timeout
131
+ await sharedHealthTracker.recordFailure(ideType, 'Timeout exceeded', {
132
+ timeoutUsed: adaptiveTimeoutMs, // Use the adaptive timeout that was actually used
133
+ requirementId: requirement.id || requirement.text.substring(0, 50),
134
+ });
135
+ } else {
136
+ // Record other failure
137
+ await sharedHealthTracker.recordFailure(ideType, completionResult.error || 'Unknown error', {
138
+ requirementId: requirement.id || requirement.text.substring(0, 50),
139
+ });
140
+ }
141
+
142
+ if (!completionResult.success) {
143
+ // Special-case behavior for Antigravity CLI installs (they have special handling)
144
+ if (completionResult.antigravityRateLimited) {
145
+ console.log(chalk.yellow(`⚠ ${t('auto.direct.provider.quota.exhausted', { provider: 'Antigravity' })}\n`));
146
+ providerManager.markRateLimited(providerConfig.provider, providerConfig.model, 'Quota limit reached');
147
+
148
+ const switchResult = await handleAntigravityRateLimit();
149
+ if (switchResult && switchResult.modelSwitched) {
150
+ return { success: false, error: `Antigravity switched to ${switchResult.nextModel}, retrying.`, shouldRetry: true };
151
+ }
152
+
153
+ return { success: false, error: 'Antigravity quota limit', shouldRetry: true };
154
+ }
155
+
156
+ // Special-case behavior for Kiro IDE (they have special handling)
157
+ if (completionResult.kiroRateLimited) {
158
+ console.log(chalk.yellow(`⚠ ${t('auto.direct.provider.quota.exhausted', { provider: 'AWS Kiro' })}\n`));
159
+ providerManager.markRateLimited(providerConfig.provider, providerConfig.model, 'Quota limit reached');
160
+
161
+ const switchResult = await handleKiroRateLimit();
162
+ if (switchResult && switchResult.success) {
163
+ return { success: false, error: `AWS Kiro switched to ${switchResult.nextProvider}, retrying.`, shouldRetry: true };
164
+ }
165
+
166
+ return { success: false, error: 'AWS Kiro quota limit', shouldRetry: true };
167
+ }
168
+
169
+ // Special-case behavior for Cline IDE
170
+ if (completionResult.clineRateLimited) {
171
+ console.log(chalk.yellow(`⚠ ${t('auto.direct.provider.quota.exhausted', { provider: 'Cline' })}\n`));
172
+ providerManager.markRateLimited(providerConfig.provider, providerConfig.model, 'Quota limit reached');
173
+
174
+ const switchResult = await handleClineRateLimit();
175
+ if (switchResult && switchResult.success) {
176
+ return { success: false, error: `Cline switched to ${switchResult.nextProvider}, retrying.`, shouldRetry: true };
177
+ }
178
+
179
+ return { success: false, error: 'Cline quota limit', shouldRetry: true };
180
+ }
181
+
182
+ // Generic rate-limited behavior: if the completion detected a rate-limited message in REQUIREMENTS,
183
+ // mark the provider as rate-limited and retry with the next available provider.
184
+ if (completionResult.rateLimited) {
185
+ console.log(chalk.yellow(`⚠ Provider ${providerConfig.provider} reported quota/exhaustion: ${completionResult.matchedLine || ''}\n`));
186
+ providerManager.markRateLimited(providerConfig.provider, providerConfig.model, completionResult.matchedLine || 'Quota limit detected');
187
+ return { success: false, error: 'Provider quota limit', shouldRetry: true };
188
+ }
189
+
190
+ const errorMsg = completionResult.reason === 'timeout'
191
+ ? 'IDE agent timed out'
192
+ : 'IDE agent failed to complete';
193
+ providerManager.markRateLimited(providerConfig.provider, providerConfig.model, errorMsg);
194
+
195
+ // Automatically retry with next IDE on timeout (T024: automatic IDE switching)
196
+ if (completionResult.reason === 'timeout') {
197
+ console.log(chalk.yellow(`⏱ Timeout detected - switching to next available IDE\n`));
198
+ return { success: false, error: errorMsg, shouldRetry: true };
199
+ }
200
+
201
+ return { success: false, error: errorMsg };
202
+ }
203
+
204
+ printStatusCard(requirement.text, 'VERIFY', 'active');
205
+ console.log(chalk.green(`✓ ${t('auto.direct.provider.completed')}\n`));
206
+
207
+ printStatusCard(requirement.text, 'DONE', 'active');
208
+ const duration = Date.now() - startTime;
209
+ providerManager.recordPerformance(providerConfig.provider, providerConfig.model, duration);
210
+
211
+ const moved = await moveRequirementToVerify(repoPath, requirement.text);
212
+ if (moved) {
213
+ console.log(chalk.green(`✓ ${t('auto.direct.status.verification.pending')}`));
214
+ }
215
+
216
+ console.log();
217
+ console.log(chalk.gray(' '.repeat(80)));
218
+ console.log();
219
+
220
+ return { success: true, changes: [] };
221
+ }
222
+
223
+ module.exports = {
224
+ initialize,
225
+ runIdeFallbackIteration
226
+ };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * IDE Provider Runner - IDE Provider Iteration Spawning
3
+ *
4
+ * Extracted from iteration-handlers.js for constitutional compliance (<555 lines per file)
5
+ * Handles spawning of IDE provider iterations via auto:start subprocess.
6
+ */
7
+
8
+ const chalk = require('chalk');
9
+ const { spawn } = require('child_process');
10
+ const vibecodingmachineCore = require('vibecodingmachine-core');
11
+ const { t } = vibecodingmachineCore;
12
+
13
+ // Import auto mode utilities
14
+ const { checkAntigravityRateLimit } = require('../../utils/antigravity-js-handler');
15
+ const { checkKiroRateLimit } = require('../../utils/kiro-js-handler');
16
+ const { checkClineRateLimit } = require('../../utils/cline-js-handler');
17
+
18
+ // Import modular functions
19
+ const { isRateLimitMessage } = require('./utils');
20
+
21
+ // Shared variables set by parent module
22
+ let CLI_ENTRY_POINT = null;
23
+
24
+ /**
25
+ * Initialize module with shared instances
26
+ */
27
+ function initialize(deps) {
28
+ CLI_ENTRY_POINT = deps.cliEntryPoint;
29
+ }
30
+
31
+ /**
32
+ * Run an IDE provider iteration by spawning auto:start subprocess
33
+ * @param {Object} providerConfig - Provider configuration
34
+ * @param {string} repoPath - Repository path
35
+ * @returns {Promise<{success: boolean, error?: string, output?: string, rateLimited?: boolean}>}
36
+ */
37
+ async function runIdeProviderIteration(providerConfig, repoPath) {
38
+ return new Promise((resolve) => {
39
+ console.log(chalk.cyan(`🚀 ${t('auto.direct.provider.launching', { provider: providerConfig.displayName })}\n`));
40
+
41
+ const args = [CLI_ENTRY_POINT, 'auto:start', '--ide', providerConfig.ide || providerConfig.provider, '--max-chats', String(providerConfig.maxChats || 1)];
42
+ if (providerConfig.model) {
43
+ args.push('--ide-model', String(providerConfig.model));
44
+ }
45
+ // Pass extension information for VS Code extensions
46
+ if (providerConfig.extension) {
47
+ args.push('--extension', String(providerConfig.extension));
48
+ }
49
+ const child = spawn(process.execPath, args, {
50
+ cwd: repoPath,
51
+ env: process.env,
52
+ stdio: ['inherit', 'pipe', 'pipe']
53
+ });
54
+
55
+ let combinedOutput = '';
56
+
57
+ child.stdout.on('data', (data) => {
58
+ const text = data.toString();
59
+ combinedOutput += text;
60
+ process.stdout.write(text);
61
+ });
62
+
63
+ child.stderr.on('data', (data) => {
64
+ const text = data.toString();
65
+ combinedOutput += text;
66
+ process.stderr.write(text);
67
+ });
68
+
69
+ child.on('error', (error) => {
70
+ resolve({
71
+ success: false,
72
+ error: `Failed to start ${providerConfig.displayName}: ${error.message}`,
73
+ output: combinedOutput
74
+ });
75
+ });
76
+
77
+ child.on('exit', (code) => {
78
+ if (code === 0) {
79
+ resolve({ success: true, output: combinedOutput });
80
+ } else {
81
+ const message = `${providerConfig.displayName} exited with code ${code}`;
82
+ const antigravityRateLimit = checkAntigravityRateLimit(combinedOutput);
83
+ const kiroRateLimit = checkKiroRateLimit(combinedOutput);
84
+ const clineRateLimit = checkClineRateLimit(combinedOutput);
85
+
86
+ resolve({
87
+ success: false,
88
+ error: combinedOutput ? `${message}\n${combinedOutput}` : message,
89
+ output: combinedOutput,
90
+ rateLimited: isRateLimitMessage(combinedOutput) || antigravityRateLimit.isRateLimited || kiroRateLimit.isRateLimited || clineRateLimit.isRateLimited,
91
+ antigravityRateLimited: antigravityRateLimit.isRateLimited,
92
+ kiroRateLimited: kiroRateLimit.isRateLimited,
93
+ clineRateLimited: clineRateLimit.isRateLimited
94
+ });
95
+ }
96
+ });
97
+ });
98
+ }
99
+
100
+ module.exports = {
101
+ initialize,
102
+ runIdeProviderIteration
103
+ };
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Iteration Handlers - IDE Provider Interaction Management
3
+ *
4
+ * This module contains functions for managing IDE provider iterations in autonomous mode.
5
+ * It handles IDE provider spawning, completion monitoring, fallback iteration logic,
6
+ * spec-based iterations, and the main iteration workflow.
7
+ *
8
+ * IMPORTANT: These functions require access to parent module functions:
9
+ * - countSpecCheckboxes() - Count done/total checkboxes in spec tasks.md
10
+ * - storedStatusTitle, storedStatus - Global status tracking variables
11
+ * - sharedProviderManager - Shared ProviderManager instance for rate limit tracking
12
+ * - sharedHealthTracker - Shared IDEHealthTracker instance for health monitoring
13
+ * - CLI_ENTRY_POINT - Path to CLI entry point for spawning child processes
14
+ *
15
+ * @module iteration-handlers
16
+ */
17
+
18
+ const chalk = require('chalk');
19
+ const fs = require('fs-extra');
20
+ const path = require('path');
21
+ const { spawn } = require('child_process');
22
+ const chokidar = require('chokidar');
23
+ const vibecodingmachineCore = require('vibecodingmachine-core');
24
+ const {
25
+ DirectLLMManager,
26
+ AppleScriptManager,
27
+ QuotaDetector,
28
+ TimeoutCalculator,
29
+ t,
30
+ getRequirementsPath
31
+ } = vibecodingmachineCore;
32
+
33
+ // Import auto mode utilities
34
+ const { getAutoConfig } = require('../../utils/config');
35
+ const { checkAntigravityRateLimit, handleAntigravityRateLimit } = require('../../utils/antigravity-js-handler');
36
+ const { checkKiroRateLimit, handleKiroRateLimit } = require('../../utils/kiro-js-handler');
37
+ const { checkClineRateLimit, handleClineRateLimit } = require('../../utils/cline-js-handler');
38
+ const { stopAutoMode } = require('../../utils/auto-mode');
39
+
40
+ // Import modular functions from auto-direct/ subdirectory
41
+ const {
42
+ getLogTimestamp,
43
+ isRateLimitMessage,
44
+ safeLog
45
+ } = require('./utils');
46
+
47
+ const {
48
+ updateRequirementsStatus,
49
+ moveRequirementToVerify
50
+ } = require('./requirement-manager');
51
+
52
+ const {
53
+ parseSearchReplaceBlocks,
54
+ applyFileChange
55
+ } = require('./code-processor');
56
+
57
+ const {
58
+ findRelevantFiles,
59
+ readFileSnippets
60
+ } = require('./file-scanner');
61
+
62
+ const {
63
+ printStatusCard
64
+ } = require('./status-display');
65
+
66
+ // Import split module functions
67
+ const { waitForIdeCompletion: waitForIdeCompletionImpl } = require('./ide-completion-waiter');
68
+ const { runIteration: runIterationImpl, initialize: initializeIterationRunner } = require('./iteration-runner');
69
+
70
+ // Import extracted module functions
71
+ const { ensureClineInstalled: ensureClineInstalledImpl } = require('./cline-installer');
72
+ const { runIdeProviderIteration: runIdeProviderIterationImpl, initialize: initializeIdeProviderRunner } = require('./ide-provider-runner');
73
+ const { runIdeFallbackIteration: runIdeFallbackIterationImpl, initialize: initializeIdeFallbackRunner } = require('./ide-fallback-runner');
74
+ const { runSpecIdeIteration: runSpecIdeIterationImpl, initialize: initializeSpecIdeRunner } = require('./spec-ide-runner');
75
+
76
+ // These will be set by the parent module (auto-direct.js)
77
+ let sharedProviderManager = null;
78
+ let sharedHealthTracker = null;
79
+ let CLI_ENTRY_POINT = null;
80
+ let storedStatusTitle = null;
81
+ let storedStatus = null;
82
+
83
+ /**
84
+ * Initialize module with shared instances from parent
85
+ * @param {Object} deps - Dependencies object
86
+ * @param {Object} deps.providerManager - Shared ProviderManager instance
87
+ * @param {Object} deps.healthTracker - Shared IDEHealthTracker instance
88
+ * @param {string} deps.cliEntryPoint - Path to CLI entry point
89
+ * @param {Object} deps.statusVars - Object containing storedStatusTitle and storedStatus references
90
+ */
91
+ function initialize(deps) {
92
+ sharedProviderManager = deps.providerManager;
93
+ sharedHealthTracker = deps.healthTracker;
94
+ CLI_ENTRY_POINT = deps.cliEntryPoint;
95
+ storedStatusTitle = deps.statusVars.storedStatusTitle;
96
+ storedStatus = deps.statusVars.storedStatus;
97
+
98
+ // Initialize imported modules
99
+ require('./ide-completion-waiter').initialize(deps);
100
+ initializeIdeProviderRunner(deps);
101
+ initializeIdeFallbackRunner(deps);
102
+ initializeSpecIdeRunner(deps);
103
+ initializeIterationRunner({ ...deps, runIdeFallbackIteration });
104
+ }
105
+
106
+ /**
107
+ * Auto-install Cline CLI if not available
108
+ * Wrapper function that delegates to the implementation in cline-installer.js
109
+ * @param {boolean} forceInstall - Force installation even if already available
110
+ * @returns {Promise<boolean>} - Returns true if Cline CLI is available after installation
111
+ */
112
+ async function ensureClineInstalled(forceInstall = false) {
113
+ return ensureClineInstalledImpl(forceInstall);
114
+ }
115
+
116
+ /**
117
+ * Run an IDE provider iteration by spawning auto:start subprocess
118
+ * Wrapper function that delegates to the implementation in ide-provider-runner.js
119
+ * @param {Object} providerConfig - Provider configuration
120
+ * @param {string} repoPath - Repository path
121
+ * @returns {Promise<{success: boolean, error?: string, output?: string, rateLimited?: boolean}>}
122
+ */
123
+ async function runIdeProviderIteration(providerConfig, repoPath) {
124
+ return runIdeProviderIterationImpl(providerConfig, repoPath);
125
+ }
126
+
127
+
128
+ /**
129
+ * Wait for IDE agent to complete work by monitoring requirements file
130
+ * Wrapper function that delegates to the implementation in ide-completion-waiter.js
131
+ * @param {string} repoPath - Repository path
132
+ * @param {string} requirementText - Requirement text to watch for
133
+ * @param {string} ideType - IDE type (e.g., 'antigravity') for quota limit handling
134
+ * @param {number} timeoutMs - Timeout in milliseconds (default: 30 minutes)
135
+ * @returns {Promise<{success: boolean, reason?: string}>}
136
+ */
137
+ async function waitForIdeCompletion(repoPath, requirementText, ideType = '', timeoutMs = 30 * 60 * 1000) {
138
+ return waitForIdeCompletionImpl(repoPath, requirementText, ideType, timeoutMs);
139
+ }
140
+
141
+ /**
142
+ * Run an IDE fallback iteration (no context gathering, direct IDE spawn)
143
+ * Wrapper function that delegates to the implementation in ide-fallback-runner.js
144
+ * @param {Object} requirement - Requirement object
145
+ * @param {Object} providerConfig - Provider configuration
146
+ * @param {string} repoPath - Repository path
147
+ * @param {Object} providerManager - Provider manager instance
148
+ * @param {Object} llm - DirectLLMManager instance
149
+ * @param {number} startTime - Start time timestamp
150
+ * @returns {Promise<{success: boolean, error?: string, shouldRetry?: boolean}>}
151
+ */
152
+ async function runIdeFallbackIteration(requirement, providerConfig, repoPath, providerManager, llm, startTime) {
153
+ return runIdeFallbackIterationImpl(requirement, providerConfig, repoPath, providerManager, llm, startTime);
154
+ }
155
+
156
+ /**
157
+ * Run a spec iteration using an IDE provider (AppleScript).
158
+ * Wrapper function that delegates to the implementation in spec-ide-runner.js
159
+ * @param {Object} spec - Spec object with .path, .directory, .hasTasks, .hasPlan, .hasPlanPrompt
160
+ * @param {string} taskText - Text of the NEXT unchecked task (for display)
161
+ * @param {string} taskLine - Full line from tasks.md (used if this is a continuation)
162
+ * @param {Object} providerConfig - Provider config with .provider/.ide and .displayName
163
+ * @param {Function} countSpecCheckboxes - Function to count checkboxes in spec tasks.md
164
+ * @returns {Promise<{success: boolean, error?: string, shouldRetry?: boolean}>}
165
+ */
166
+ async function runSpecIdeIteration(spec, taskText, taskLine, providerConfig, countSpecCheckboxes) {
167
+ return runSpecIdeIterationImpl(spec, taskText, taskLine, providerConfig, countSpecCheckboxes);
168
+ }
169
+
170
+ /**
171
+ * Run one iteration of autonomous mode with full workflow
172
+ * Wrapper function that delegates to the implementation in iteration-runner.js
173
+ * @param {Object} requirement - Requirement object
174
+ * @param {Object} providerConfig - Provider configuration
175
+ * @param {string} repoPath - Repository path
176
+ * @returns {Promise<{success: boolean, changes?: Array, error?: string}>}
177
+ */
178
+ async function runIteration(requirement, providerConfig, repoPath) {
179
+ return runIterationImpl(requirement, providerConfig, repoPath);
180
+ }
181
+ module.exports = {
182
+ initialize,
183
+ ensureClineInstalled,
184
+ runIdeProviderIteration,
185
+ waitForIdeCompletion,
186
+ runIdeFallbackIteration,
187
+ runSpecIdeIteration,
188
+ runIteration
189
+ };