Fix coding-agent terminal shortcuts not working on Windows (#1509)
* Fix coding-agent terminal shortcuts not working on Windows On Windows, opening a Terminal profile (Claude Code / Codex / OpenCode) did nothing, and afterwards even a plain New Terminal stopped working until restart. Three Windows-specific problems combined: - A failed node-pty conpty spawn completes asynchronously on its conout worker thread; the uncaught exception escaped the per-request try/catch and crashed the whole terminal worker, severing every terminal. Add uncaughtException / unhandledRejection guards so a single bad spawn keeps the worker alive. - Profile commands were passed to conpty unresolved. conpty's CreateProcess ignores PATHEXT, so bare codex (npm codex.cmd) wasn't found and .cmd/.bat shims can't run directly. Add resolveTerminalSpawnCommand() to resolve the real path and route .cmd/.bat through cmd.exe /c on Windows. - winget-installed CLIs (e.g. Claude Code) live under the winget Packages dir and aren't on PATH. findExecutable() now falls back to those known install locations, so all providers and terminal profiles benefit. Also surface a failed terminal create to the user via a toast instead of silently dropping the error. * Address review: simplify winget scan, narrow worker exception guard - Drop the single-element WINGET_PACKAGE_BIN_SUBDIRS loop in executable.ts and map package dirs directly to the root <name>.exe candidate. - Remove the unhandledRejection handler in the terminal worker (only the uncaughtException path is exercised by conpty's async spawn failure) and expand the comment to explain the keep-alive trade-off and the absence of a worker restart path. * Refactor executable resolution out of utils * Serialize terminal create requests in worker --------- Co-authored-by: danniel <liminfhu@gmail.com> Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
co-authored by
danniel
Mohamed Boudra
parent
bf8f2510c8
commit
f352072dac
@@ -43,6 +43,7 @@ interface UseWorkspaceTerminalsInput {
|
||||
onScriptTerminalSelected: (terminalId: string) => void;
|
||||
onWorkspacePathUnavailable: () => void;
|
||||
onTerminalCreateQueued: () => void;
|
||||
onTerminalCreateFailed: (reason: string) => void;
|
||||
}
|
||||
|
||||
export function useWorkspaceTerminals(input: UseWorkspaceTerminalsInput) {
|
||||
@@ -60,6 +61,7 @@ export function useWorkspaceTerminals(input: UseWorkspaceTerminalsInput) {
|
||||
onScriptTerminalSelected,
|
||||
onWorkspacePathUnavailable,
|
||||
onTerminalCreateQueued,
|
||||
onTerminalCreateFailed,
|
||||
} = input;
|
||||
const { t } = useTranslation();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -119,11 +121,19 @@ export function useWorkspaceTerminals(input: UseWorkspaceTerminalsInput) {
|
||||
if (!client || !workspaceDirectory) {
|
||||
throw new Error(t("workspace.terminal.hostDisconnected"));
|
||||
}
|
||||
if (_input?.profile) {
|
||||
const { name, command, args } = _input.profile;
|
||||
return await client.createTerminal(workspaceDirectory, name, undefined, { command, args });
|
||||
const payload = _input?.profile
|
||||
? await client.createTerminal(workspaceDirectory, _input.profile.name, undefined, {
|
||||
command: _input.profile.command,
|
||||
args: _input.profile.args,
|
||||
})
|
||||
: await client.createTerminal(workspaceDirectory);
|
||||
// The daemon reports a failed spawn (e.g. a profile command that isn't
|
||||
// installed) via payload.error with a null terminal. Surface it instead
|
||||
// of silently treating the create as a no-op success.
|
||||
if (!payload.terminal && payload.error) {
|
||||
throw new Error(payload.error);
|
||||
}
|
||||
return await client.createTerminal(workspaceDirectory);
|
||||
return payload;
|
||||
},
|
||||
onSuccess: (payload, createInput) => {
|
||||
const createdTerminal = payload.terminal;
|
||||
@@ -145,6 +155,9 @@ export function useWorkspaceTerminals(input: UseWorkspaceTerminalsInput) {
|
||||
});
|
||||
}
|
||||
},
|
||||
onError: (error: unknown) => {
|
||||
onTerminalCreateFailed(error instanceof Error ? error.message : String(error));
|
||||
},
|
||||
});
|
||||
const killMutation = useMutation({
|
||||
mutationFn: async (terminalId: string) => {
|
||||
|
||||
@@ -1642,6 +1642,7 @@ interface WorkspaceTerminalTabActions {
|
||||
handleScriptTerminalSelected: (terminalId: string) => void;
|
||||
handleWorkspacePathUnavailable: () => void;
|
||||
handleTerminalCreateQueued: () => void;
|
||||
handleTerminalCreateFailed: (reason: string) => void;
|
||||
}
|
||||
|
||||
function useWorkspaceTerminalTabActions({
|
||||
@@ -1678,12 +1679,19 @@ function useWorkspaceTerminalTabActions({
|
||||
const handleTerminalCreateQueued = useCallback(() => {
|
||||
toast.show(labels.terminalQueued);
|
||||
}, [labels.terminalQueued, toast]);
|
||||
const handleTerminalCreateFailed = useCallback(
|
||||
(reason: string) => {
|
||||
toast.error(reason);
|
||||
},
|
||||
[toast],
|
||||
);
|
||||
|
||||
return {
|
||||
handleTerminalCreated,
|
||||
handleScriptTerminalSelected,
|
||||
handleWorkspacePathUnavailable,
|
||||
handleTerminalCreateQueued,
|
||||
handleTerminalCreateFailed,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1826,6 +1834,7 @@ function WorkspaceScreenContent({
|
||||
handleScriptTerminalSelected,
|
||||
handleWorkspacePathUnavailable,
|
||||
handleTerminalCreateQueued,
|
||||
handleTerminalCreateFailed,
|
||||
} = useWorkspaceTerminalTabActions({
|
||||
persistenceKey,
|
||||
focusWorkspacePane,
|
||||
@@ -1866,6 +1875,7 @@ function WorkspaceScreenContent({
|
||||
onScriptTerminalSelected: handleScriptTerminalSelected,
|
||||
onWorkspacePathUnavailable: handleWorkspacePathUnavailable,
|
||||
onTerminalCreateQueued: handleTerminalCreateQueued,
|
||||
onTerminalCreateFailed: handleTerminalCreateFailed,
|
||||
});
|
||||
const { archiveAgent } = useArchiveAgent();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user