Skip to content

Commit 25398fa

Browse files
committed
streaming commands like commit and expand
1 parent 4f00b0b commit 25398fa

File tree

2 files changed

+88
-11
lines changed

2 files changed

+88
-11
lines changed

electron/ipc/vibe-handlers.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,25 @@ function getVibeExecutablePath() {
1818
return join(appPath, "vibecommit", "win64", "vibe.exe");
1919
}
2020

21+
// Helper function to get command-specific timeout values
22+
function getCommandTimeout(command) {
23+
switch (command) {
24+
case 'expand':
25+
// Expand operations can be very large, especially for commits with many files
26+
return 10 * 60 * 1000; // 10 minutes
27+
case 'commit':
28+
case 'improve':
29+
// Commit operations can also be large when analyzing working directory changes
30+
return 5 * 60 * 1000; // 5 minutes
31+
case 'generate':
32+
case 'info':
33+
case 'help':
34+
default:
35+
// Default timeout for other commands
36+
return 2 * 60 * 1000; // 2 minutes
37+
}
38+
}
39+
2140
// Register Vibe IPC handlers
2241
function registerVibeHandlers() {
2342
const logger = createLogger({ component: 'vibe-ipc' });
@@ -29,7 +48,10 @@ function registerVibeHandlers() {
2948
if (!parsed.success) {
3049
throw new Error(parsed.error.issues.map(i => i.message).join(', '));
3150
}
32-
const { command, args, timeout = 30000, workingDirectory, apiKey } = parsed.data;
51+
const { command, args, timeout, workingDirectory, apiKey } = parsed.data;
52+
53+
// Set command-specific timeouts if not provided
54+
const defaultTimeout = timeout || getCommandTimeout(command);
3355

3456
// Resolve API key from secure store if not provided
3557
let resolvedApiKey = apiKey;
@@ -88,13 +110,13 @@ function registerVibeHandlers() {
88110
executablePath,
89111
[command, ...args],
90112
{
91-
timeout,
113+
timeout: defaultTimeout,
92114
maxBuffer: 1024 * 1024 * 10, // 10MB buffer
93115
cwd: workingDirectory || process.cwd(),
94116
env,
95117
},
96118
);
97-
logger.info('vibe-execute-command success', { command, args, stdoutLength: stdout.length, stderrLength: stderr.length, workingDirectory, timeout });
119+
logger.info('vibe-execute-command success', { command, args, stdoutLength: stdout.length, stderrLength: stderr.length, workingDirectory, timeout: defaultTimeout });
98120
return {
99121
success: true,
100122
stdout,
@@ -248,7 +270,10 @@ function registerVibeHandlers() {
248270
if (!parsed.success) {
249271
throw new Error(parsed.error.issues.map(i => i.message).join(', '));
250272
}
251-
const { command, args, timeout = 30000, workingDirectory, apiKey } = parsed.data;
273+
const { command, args, timeout, workingDirectory, apiKey } = parsed.data;
274+
275+
// Set command-specific timeouts if not provided
276+
const defaultTimeout = timeout || getCommandTimeout(command);
252277

253278
// Resolve API key from secure store if not provided
254279
let resolvedApiKey = apiKey;
@@ -302,14 +327,14 @@ function registerVibeHandlers() {
302327
executablePath,
303328
[command, ...args],
304329
{
305-
timeout,
330+
timeout: defaultTimeout,
306331
maxBuffer: 1024 * 1024 * 10, // 10MB buffer
307332
cwd: workingDirectory || process.cwd(),
308333
env,
309334
},
310335
);
311336

312-
logger.info('vibe-run-command success', { command, args, stdoutLength: stdout.length, stderrLength: stderr.length, workingDirectory, timeout });
337+
logger.info('vibe-run-command success', { command, args, stdoutLength: stdout.length, stderrLength: stderr.length, workingDirectory, timeout: defaultTimeout });
313338
return {
314339
success: true,
315340
stdout,

lib/vibe-command-executor.ts

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,63 @@ export async function executeVibeCommandWithFlow(
4444
notifyExecutingCallbacks();
4545

4646
try {
47-
// Execute the command
48-
const result = await executeVibeCommand(command, args, {
49-
workingDirectory,
50-
apiKey,
51-
});
47+
let result;
48+
49+
// Use streaming execution for long-running commands like expand
50+
if (command === 'expand' || command === 'commit') {
51+
// Import streaming function
52+
const { streamVibeCommand } = await import('@/lib/vibe-api');
53+
54+
let lastOutput = '';
55+
let lastError = '';
56+
let hasError = false;
57+
58+
try {
59+
// Stream the command execution
60+
for await (const event of streamVibeCommand(command, args, {
61+
workingDirectory,
62+
apiKey,
63+
})) {
64+
if (event.type === 'stdout') {
65+
lastOutput += event.data || '';
66+
} else if (event.type === 'stderr') {
67+
lastError += event.data || '';
68+
} else if (event.type === 'error') {
69+
hasError = true;
70+
throw new Error(event.data || 'Command failed');
71+
}
72+
73+
// Log progress for debugging
74+
if (event.type === 'stdout' && event.data) {
75+
console.log(`Vibe ${command} progress:`, event.data.substring(0, 100) + '...');
76+
}
77+
}
78+
79+
// Create a result object compatible with executeVibeCommand
80+
result = {
81+
success: !hasError,
82+
stdout: lastOutput,
83+
stderr: lastError,
84+
command,
85+
args,
86+
timestamp: new Date().toISOString(),
87+
};
88+
} catch (streamError: any) {
89+
// If streaming fails, fall back to regular execution with longer timeout
90+
console.warn(`Streaming execution failed for ${command}, falling back to regular execution:`, streamError);
91+
result = await executeVibeCommand(command, args, {
92+
workingDirectory,
93+
apiKey,
94+
timeout: 10 * 60 * 1000, // 10 minutes timeout for fallback
95+
});
96+
}
97+
} else {
98+
// Use regular execution for faster commands
99+
result = await executeVibeCommand(command, args, {
100+
workingDirectory,
101+
apiKey,
102+
});
103+
}
52104

53105
console.log(`Vibe command ${command} completed:`, result);
54106

0 commit comments

Comments
 (0)