@sylphx/flow 2.1.2 → 2.1.4
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.
- package/CHANGELOG.md +23 -0
- package/README.md +44 -0
- package/package.json +79 -73
- package/src/commands/flow/execute-v2.ts +39 -30
- package/src/commands/flow/index.ts +2 -4
- package/src/commands/flow/prompt.ts +5 -3
- package/src/commands/flow/types.ts +0 -9
- package/src/commands/flow-command.ts +20 -13
- package/src/commands/hook-command.ts +1 -3
- package/src/commands/settings-command.ts +36 -33
- package/src/config/ai-config.ts +60 -41
- package/src/core/agent-loader.ts +11 -6
- package/src/core/attach-manager.ts +92 -84
- package/src/core/backup-manager.ts +35 -29
- package/src/core/cleanup-handler.ts +11 -8
- package/src/core/error-handling.ts +23 -30
- package/src/core/flow-executor.ts +58 -76
- package/src/core/formatting/bytes.ts +2 -4
- package/src/core/functional/async.ts +5 -4
- package/src/core/functional/error-handler.ts +2 -2
- package/src/core/git-stash-manager.ts +21 -10
- package/src/core/installers/file-installer.ts +0 -1
- package/src/core/installers/mcp-installer.ts +0 -1
- package/src/core/project-manager.ts +24 -18
- package/src/core/secrets-manager.ts +54 -73
- package/src/core/session-manager.ts +20 -22
- package/src/core/state-detector.ts +139 -80
- package/src/core/template-loader.ts +13 -31
- package/src/core/upgrade-manager.ts +122 -69
- package/src/index.ts +8 -5
- package/src/services/auto-upgrade.ts +1 -1
- package/src/services/config-service.ts +41 -29
- package/src/services/global-config.ts +2 -2
- package/src/services/target-installer.ts +9 -7
- package/src/targets/claude-code.ts +28 -15
- package/src/targets/opencode.ts +17 -6
- package/src/types/cli.types.ts +2 -2
- package/src/types/provider.types.ts +1 -7
- package/src/types/session.types.ts +11 -11
- package/src/types/target.types.ts +3 -1
- package/src/types/todo.types.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils/__tests__/package-manager-detector.test.ts +6 -6
- package/src/utils/agent-enhancer.ts +111 -3
- package/src/utils/config/paths.ts +3 -1
- package/src/utils/config/target-utils.ts +2 -2
- package/src/utils/display/banner.ts +2 -2
- package/src/utils/display/notifications.ts +58 -45
- package/src/utils/display/status.ts +29 -12
- package/src/utils/files/file-operations.ts +1 -1
- package/src/utils/files/sync-utils.ts +38 -41
- package/src/utils/index.ts +19 -27
- package/src/utils/package-manager-detector.ts +15 -5
- package/src/utils/security/security.ts +8 -4
- package/src/utils/target-selection.ts +5 -2
- package/src/utils/version.ts +4 -2
- package/src/commands/flow/execute.ts +0 -453
- package/src/commands/flow/setup.ts +0 -312
- package/src/commands/flow-orchestrator.ts +0 -328
- package/src/commands/init-command.ts +0 -92
- package/src/commands/init-core.ts +0 -331
- package/src/commands/run-command.ts +0 -126
- package/src/core/agent-manager.ts +0 -174
- package/src/core/loop-controller.ts +0 -200
- package/src/core/rule-loader.ts +0 -147
- package/src/core/rule-manager.ts +0 -240
- package/src/services/claude-config-service.ts +0 -252
- package/src/services/first-run-setup.ts +0 -220
- package/src/services/smart-config-service.ts +0 -269
- package/src/types/api.types.ts +0 -9
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Execution Logic for Flow Command
|
|
3
|
-
* Command execution for single-run and loop modes
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
import { targetManager } from '../../core/target-manager.js';
|
|
8
|
-
import { StateDetector } from '../../core/state-detector.js';
|
|
9
|
-
import { UpgradeManager } from '../../core/upgrade-manager.js';
|
|
10
|
-
import { projectSettings } from '../../utils/config/settings.js';
|
|
11
|
-
import { showWelcome } from '../../utils/display/banner.js';
|
|
12
|
-
import { showStatus } from '../../utils/display/status.js';
|
|
13
|
-
import { loadAgentContent, extractAgentInstructions } from '../run-command.js';
|
|
14
|
-
import { CLIError } from '../../utils/error-handler.js';
|
|
15
|
-
import type { RunCommandOptions } from '../../types.js';
|
|
16
|
-
import type { FlowOptions, SetupContext } from './types.js';
|
|
17
|
-
import { resolvePrompt } from './prompt.js';
|
|
18
|
-
import { executeSetupPhase } from './setup.js';
|
|
19
|
-
import { getExecutableTargets } from './targets.js';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Execute command using target's executeCommand method
|
|
23
|
-
*/
|
|
24
|
-
export async function executeTargetCommand(
|
|
25
|
-
targetId: string,
|
|
26
|
-
systemPrompt: string,
|
|
27
|
-
userPrompt: string,
|
|
28
|
-
options: RunCommandOptions
|
|
29
|
-
): Promise<void> {
|
|
30
|
-
const targetOption = targetManager.getTarget(targetId);
|
|
31
|
-
|
|
32
|
-
if (targetOption._tag === 'None') {
|
|
33
|
-
throw new CLIError(`Target not found: ${targetId}`, 'TARGET_NOT_FOUND');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const target = targetOption.value;
|
|
37
|
-
|
|
38
|
-
if (!target.isImplemented) {
|
|
39
|
-
throw new CLIError(
|
|
40
|
-
`Target '${targetId}' is not implemented. Supported targets: ${getExecutableTargets().join(', ')}`,
|
|
41
|
-
'TARGET_NOT_IMPLEMENTED'
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!target.executeCommand) {
|
|
46
|
-
throw new CLIError(
|
|
47
|
-
`Target '${targetId}' does not support command execution. Supported targets: ${getExecutableTargets().join(', ')}`,
|
|
48
|
-
'EXECUTION_NOT_SUPPORTED'
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return target.executeCommand(systemPrompt, userPrompt, options);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Execute command only (for loop mode iterations)
|
|
57
|
-
* Uses pre-setup context to execute command without re-doing setup
|
|
58
|
-
*/
|
|
59
|
-
export async function executeCommandOnly(
|
|
60
|
-
context: SetupContext,
|
|
61
|
-
prompt: string | undefined,
|
|
62
|
-
options: FlowOptions
|
|
63
|
-
): Promise<void> {
|
|
64
|
-
const userPrompt = prompt?.trim() || '';
|
|
65
|
-
|
|
66
|
-
// Update continue flag in runOptions
|
|
67
|
-
const runOptions = {
|
|
68
|
-
...context.runOptions,
|
|
69
|
-
continue: options.continue,
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
await executeTargetCommand(context.resolvedTarget, context.systemPrompt!, userPrompt, runOptions);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error(chalk.red.bold('\n✗ Launch failed:'), error);
|
|
76
|
-
throw error;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Single flow execution (used by both normal and loop mode)
|
|
82
|
-
*/
|
|
83
|
-
export async function executeFlowOnce(prompt: string | undefined, options: FlowOptions): Promise<void> {
|
|
84
|
-
// Quick mode: enable useDefaults and skip prompts
|
|
85
|
-
if (options.quick) {
|
|
86
|
-
options.useDefaults = true;
|
|
87
|
-
console.log(chalk.cyan('⚡ Quick mode enabled - using saved defaults\n'));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Continue mode always requires print mode
|
|
91
|
-
if (options.continue && !options.print) {
|
|
92
|
-
options.print = true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Import orchestrator functions
|
|
96
|
-
const {
|
|
97
|
-
checkUpgrades,
|
|
98
|
-
checkComponentIntegrity,
|
|
99
|
-
checkSyncStatus,
|
|
100
|
-
} = await import('../flow-orchestrator.js');
|
|
101
|
-
|
|
102
|
-
// Show welcome banner
|
|
103
|
-
showWelcome();
|
|
104
|
-
|
|
105
|
-
// Declare at function level to persist across steps
|
|
106
|
-
let selectedTarget: string | undefined;
|
|
107
|
-
let state = undefined;
|
|
108
|
-
|
|
109
|
-
// First: determine target (from options, saved settings, or init will prompt)
|
|
110
|
-
const initialTarget = options.target || (await projectSettings.getDefaultTarget());
|
|
111
|
-
|
|
112
|
-
// Only detect state if we have a target (can't check components without knowing target structure)
|
|
113
|
-
if (initialTarget && !options.sync) {
|
|
114
|
-
const detector = new StateDetector();
|
|
115
|
-
const upgradeManager = new UpgradeManager();
|
|
116
|
-
|
|
117
|
-
if (options.verbose) {
|
|
118
|
-
console.log(chalk.dim('🤔 Checking project status...\n'));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
state = await detector.detect();
|
|
122
|
-
|
|
123
|
-
if (options.verbose) {
|
|
124
|
-
await showStatus(state);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Step 1: Check for upgrades (non-intrusive notification)
|
|
128
|
-
if (!options.quick) {
|
|
129
|
-
await checkUpgrades(state, options);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Step 2.5: Check component integrity (only if we have valid state)
|
|
133
|
-
await checkComponentIntegrity(state, options);
|
|
134
|
-
|
|
135
|
-
// Step 2.6: Check sync status (new templates available)
|
|
136
|
-
await checkSyncStatus(state, options);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Step 3: Initialize (only if actually needed)
|
|
140
|
-
const shouldInitialize =
|
|
141
|
-
!state?.initialized ||
|
|
142
|
-
options.sync ||
|
|
143
|
-
options.repair ||
|
|
144
|
-
options.initOnly;
|
|
145
|
-
|
|
146
|
-
if (shouldInitialize) {
|
|
147
|
-
console.log(chalk.cyan.bold('━━━ 🚀 Initializing Project\n'));
|
|
148
|
-
selectedTarget = await initializeProject(options, state);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Step 4: Launch target (if not init-only)
|
|
152
|
-
if (!options.initOnly) {
|
|
153
|
-
await launchTarget(prompt, options, state, selectedTarget);
|
|
154
|
-
} else {
|
|
155
|
-
console.log(chalk.dim('✓ Init-only mode, skipping execution\n'));
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Initialize project with components
|
|
161
|
-
*/
|
|
162
|
-
async function initializeProject(options: FlowOptions, state: any): Promise<string | undefined> {
|
|
163
|
-
const {
|
|
164
|
-
selectAndValidateTarget,
|
|
165
|
-
previewDryRun,
|
|
166
|
-
installComponents,
|
|
167
|
-
} = await import('../init-core.js');
|
|
168
|
-
|
|
169
|
-
let selectedTarget: string | undefined;
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
// In repair mode, use existing target from state
|
|
173
|
-
const targetForInit = options.repair && state?.target
|
|
174
|
-
? state.target
|
|
175
|
-
: options.target;
|
|
176
|
-
|
|
177
|
-
// Prepare init options
|
|
178
|
-
const initOptions = {
|
|
179
|
-
target: targetForInit,
|
|
180
|
-
verbose: options.verbose,
|
|
181
|
-
dryRun: options.dryRun,
|
|
182
|
-
clear: options.sync || false,
|
|
183
|
-
mcp: options.mcp !== false,
|
|
184
|
-
agents: options.agents !== false,
|
|
185
|
-
rules: options.rules !== false,
|
|
186
|
-
outputStyles: options.outputStyles !== false,
|
|
187
|
-
slashCommands: options.slashCommands !== false,
|
|
188
|
-
hooks: options.hooks !== false,
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// Handle sync mode - delete template files first
|
|
192
|
-
if (options.sync && !options.dryRun) {
|
|
193
|
-
selectedTarget = await handleSyncMode(initOptions);
|
|
194
|
-
} else {
|
|
195
|
-
// Select and validate target
|
|
196
|
-
const targetId = await selectAndValidateTarget(initOptions);
|
|
197
|
-
selectedTarget = targetId;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// Dry run preview
|
|
201
|
-
if (options.dryRun) {
|
|
202
|
-
if (!selectedTarget) {
|
|
203
|
-
const targetId = await selectAndValidateTarget(initOptions);
|
|
204
|
-
selectedTarget = targetId;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
await previewDryRun(selectedTarget, initOptions);
|
|
208
|
-
console.log(chalk.dim('✓ Initialization dry run complete\n'));
|
|
209
|
-
} else {
|
|
210
|
-
// Actually install components
|
|
211
|
-
if (!selectedTarget) {
|
|
212
|
-
const targetId = await selectAndValidateTarget(initOptions);
|
|
213
|
-
selectedTarget = targetId;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
await installComponents(selectedTarget, initOptions);
|
|
217
|
-
console.log(chalk.green.bold('✓ Initialization complete\n'));
|
|
218
|
-
}
|
|
219
|
-
} catch (error) {
|
|
220
|
-
console.error(chalk.red.bold('✗ Initialization failed:'), error);
|
|
221
|
-
process.exit(1);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
return selectedTarget;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Handle sync mode
|
|
229
|
-
*/
|
|
230
|
-
async function handleSyncMode(initOptions: any): Promise<string> {
|
|
231
|
-
const { buildSyncManifest, showSyncPreview, selectUnknownFilesToRemove, showFinalSummary, confirmSync, executeSyncDelete, removeMCPServers, removeHooks } = await import('../../utils/files/sync-utils.js');
|
|
232
|
-
const { selectAndValidateTarget } = await import('../init-core.js');
|
|
233
|
-
|
|
234
|
-
const targetId = await selectAndValidateTarget(initOptions);
|
|
235
|
-
|
|
236
|
-
const targetOption = targetManager.getTarget(targetId);
|
|
237
|
-
if (targetOption._tag === 'None') {
|
|
238
|
-
throw new Error(`Target not found: ${targetId}`);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const target = targetOption.value;
|
|
242
|
-
const manifest = await buildSyncManifest(process.cwd(), target);
|
|
243
|
-
|
|
244
|
-
console.log(chalk.cyan.bold('━━━ 🔄 Synchronizing Files\n'));
|
|
245
|
-
showSyncPreview(manifest, process.cwd(), target);
|
|
246
|
-
|
|
247
|
-
const selectedUnknowns = await selectUnknownFilesToRemove(manifest);
|
|
248
|
-
showFinalSummary(manifest, selectedUnknowns);
|
|
249
|
-
|
|
250
|
-
const confirmed = await confirmSync();
|
|
251
|
-
if (!confirmed) {
|
|
252
|
-
console.log(chalk.yellow('\n✗ Sync cancelled\n'));
|
|
253
|
-
process.exit(0);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const { templates, unknowns } = await executeSyncDelete(manifest, selectedUnknowns);
|
|
257
|
-
|
|
258
|
-
let mcpRemoved = 0;
|
|
259
|
-
if (selectedUnknowns.mcpServers.length > 0) {
|
|
260
|
-
mcpRemoved = await removeMCPServers(process.cwd(), selectedUnknowns.mcpServers);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
let hooksRemoved = 0;
|
|
264
|
-
if (selectedUnknowns.hooks.length > 0) {
|
|
265
|
-
hooksRemoved = await removeHooks(process.cwd(), selectedUnknowns.hooks);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
console.log(chalk.green(`\n✓ Synced ${templates} templates`));
|
|
269
|
-
const totalRemoved = unknowns + mcpRemoved + hooksRemoved;
|
|
270
|
-
if (totalRemoved > 0) {
|
|
271
|
-
console.log(chalk.green(`✓ Removed ${totalRemoved} items`));
|
|
272
|
-
}
|
|
273
|
-
const totalSelected = selectedUnknowns.files.length + selectedUnknowns.mcpServers.length + selectedUnknowns.hooks.length;
|
|
274
|
-
const preserved = manifest.agents.unknown.length + manifest.slashCommands.unknown.length + manifest.rules.unknown.length + manifest.mcpServers.notInRegistry.length + manifest.hooks.orphaned.length - totalSelected;
|
|
275
|
-
if (preserved > 0) {
|
|
276
|
-
console.log(chalk.green(`✓ Preserved ${preserved} custom items`));
|
|
277
|
-
}
|
|
278
|
-
console.log('');
|
|
279
|
-
|
|
280
|
-
return targetId;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Launch target with agent
|
|
285
|
-
*/
|
|
286
|
-
async function launchTarget(
|
|
287
|
-
prompt: string | undefined,
|
|
288
|
-
options: FlowOptions,
|
|
289
|
-
state: any,
|
|
290
|
-
selectedTarget: string | undefined
|
|
291
|
-
): Promise<void> {
|
|
292
|
-
// Resolve target - use the target we just selected
|
|
293
|
-
let targetForResolution = options.target || state?.target || selectedTarget;
|
|
294
|
-
|
|
295
|
-
// If we just selected a target during init, use that
|
|
296
|
-
if (selectedTarget) {
|
|
297
|
-
targetForResolution = selectedTarget;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (!targetForResolution) {
|
|
301
|
-
console.error(chalk.red.bold('✗ No target selected. Use --target or run init first.'));
|
|
302
|
-
process.exit(1);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const resolvedTarget = await targetManager.resolveTarget({
|
|
306
|
-
target: targetForResolution,
|
|
307
|
-
allowSelection: false,
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
console.log(chalk.cyan.bold(`━━━ 🎯 Launching ${resolvedTarget}\n`));
|
|
311
|
-
|
|
312
|
-
// Check if target supports command execution
|
|
313
|
-
const { getTargetsWithCommandSupport } = await import('../../config/targets.js');
|
|
314
|
-
const supportedTargets = getTargetsWithCommandSupport().map(t => t.id);
|
|
315
|
-
|
|
316
|
-
if (!supportedTargets.includes(resolvedTarget)) {
|
|
317
|
-
console.log(chalk.red.bold('✗ Unsupported target platform\n'));
|
|
318
|
-
console.log(chalk.yellow(`Target '${resolvedTarget}' does not support agent execution.`));
|
|
319
|
-
console.log(chalk.cyan(`Supported platforms: ${supportedTargets.join(', ')}\n`));
|
|
320
|
-
console.log(chalk.dim('Tip: Use --target claude-code to specify Claude Code platform'));
|
|
321
|
-
console.log(chalk.dim('Example: bun dev:flow --target claude-code\n'));
|
|
322
|
-
process.exit(1);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Claude Code handling - needs provider/agent setup
|
|
326
|
-
if (resolvedTarget === 'claude-code') {
|
|
327
|
-
await setupClaudeCode(options);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const agent = options.agent || 'coder';
|
|
331
|
-
const verbose = options.verbose || false;
|
|
332
|
-
|
|
333
|
-
if (verbose || options.runOnly || !options.quick) {
|
|
334
|
-
console.log(` 🤖 Agent: ${chalk.cyan(agent)}`);
|
|
335
|
-
console.log(` 🎯 Target: ${chalk.cyan(resolvedTarget)}`);
|
|
336
|
-
if (prompt) {
|
|
337
|
-
console.log(` 💬 Prompt: ${chalk.dim(prompt)}\n`);
|
|
338
|
-
} else {
|
|
339
|
-
console.log(` 💬 Mode: ${chalk.dim('Interactive')}\n`);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// Load agent and prepare prompts
|
|
344
|
-
const agentContent = await loadAgentContent(agent, options.agentFile);
|
|
345
|
-
const agentInstructions = extractAgentInstructions(agentContent);
|
|
346
|
-
const systemPrompt = `AGENT INSTRUCTIONS:\n${agentInstructions}`;
|
|
347
|
-
|
|
348
|
-
const userPrompt = prompt?.trim() || '';
|
|
349
|
-
|
|
350
|
-
// Run options
|
|
351
|
-
const runOptions: RunCommandOptions = {
|
|
352
|
-
target: resolvedTarget,
|
|
353
|
-
verbose,
|
|
354
|
-
dryRun: options.dryRun,
|
|
355
|
-
agent,
|
|
356
|
-
agentFile: options.agentFile,
|
|
357
|
-
prompt,
|
|
358
|
-
print: options.print,
|
|
359
|
-
continue: options.continue,
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
try {
|
|
363
|
-
await executeTargetCommand(resolvedTarget, systemPrompt, userPrompt, runOptions);
|
|
364
|
-
} catch (error) {
|
|
365
|
-
console.error(chalk.red.bold('\n✗ Launch failed:'), error);
|
|
366
|
-
process.exit(1);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (!options.dryRun) {
|
|
370
|
-
console.log(chalk.dim('━━━\n'));
|
|
371
|
-
console.log(chalk.green('✓ Session complete\n'));
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Setup Claude Code provider and agent
|
|
377
|
-
*/
|
|
378
|
-
async function setupClaudeCode(options: FlowOptions): Promise<void> {
|
|
379
|
-
const { SmartConfigService } = await import('../../services/smart-config-service.js');
|
|
380
|
-
const { ConfigService } = await import('../../services/config-service.js');
|
|
381
|
-
|
|
382
|
-
if (!(await ConfigService.hasInitialSetup())) {
|
|
383
|
-
console.log(chalk.cyan('🔑 First-time setup for Claude Code\n'));
|
|
384
|
-
await SmartConfigService.initialSetup();
|
|
385
|
-
console.log(chalk.green('✓ Setup complete!\n'));
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const runtimeChoices = await SmartConfigService.selectRuntimeChoices({
|
|
389
|
-
selectProvider: options.selectProvider,
|
|
390
|
-
selectAgent: options.selectAgent,
|
|
391
|
-
useDefaults: options.useDefaults,
|
|
392
|
-
provider: options.provider,
|
|
393
|
-
agent: options.agent,
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
await SmartConfigService.setupEnvironment(runtimeChoices.provider!);
|
|
397
|
-
options.agent = runtimeChoices.agent;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Main flow execution logic - simplified with orchestrator
|
|
402
|
-
*/
|
|
403
|
-
export async function executeFlow(prompt: string | undefined, options: FlowOptions): Promise<void> {
|
|
404
|
-
// Resolve prompt (handle file input)
|
|
405
|
-
const resolvedPrompt = await resolvePrompt(prompt);
|
|
406
|
-
|
|
407
|
-
// Loop mode: Setup once, then loop only execution
|
|
408
|
-
if (options.loop !== undefined) {
|
|
409
|
-
const { LoopController } = await import('../../core/loop-controller.js');
|
|
410
|
-
const controller = new LoopController();
|
|
411
|
-
|
|
412
|
-
// Default to 0s (no cooldown) if just --loop with no value
|
|
413
|
-
const interval = typeof options.loop === 'number' ? options.loop : 0;
|
|
414
|
-
|
|
415
|
-
// Auto-enable headless mode for loop
|
|
416
|
-
options.print = true;
|
|
417
|
-
|
|
418
|
-
// ONE-TIME SETUP: Do all initialization once before loop starts
|
|
419
|
-
const setupContext = await executeSetupPhase(resolvedPrompt, options);
|
|
420
|
-
|
|
421
|
-
// Save original continue flag
|
|
422
|
-
const originalContinue = options.continue || false;
|
|
423
|
-
|
|
424
|
-
// LOOP: Only execute the command repeatedly
|
|
425
|
-
await controller.run(
|
|
426
|
-
async () => {
|
|
427
|
-
const isFirstIteration = controller['state'].iteration === 1;
|
|
428
|
-
|
|
429
|
-
// Continue logic:
|
|
430
|
-
// - If user specified --continue, always use it (all iterations)
|
|
431
|
-
// - If user didn't specify, only use from 2nd iteration onwards
|
|
432
|
-
options.continue = originalContinue || !isFirstIteration;
|
|
433
|
-
|
|
434
|
-
try {
|
|
435
|
-
await executeCommandOnly(setupContext, resolvedPrompt, options);
|
|
436
|
-
return { exitCode: 0 };
|
|
437
|
-
} catch (error) {
|
|
438
|
-
return { exitCode: 1, error: error as Error };
|
|
439
|
-
}
|
|
440
|
-
},
|
|
441
|
-
{
|
|
442
|
-
enabled: true,
|
|
443
|
-
interval,
|
|
444
|
-
maxRuns: options.maxRuns,
|
|
445
|
-
}
|
|
446
|
-
);
|
|
447
|
-
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// Normal execution (non-loop)
|
|
452
|
-
await executeFlowOnce(resolvedPrompt, options);
|
|
453
|
-
}
|