diff --git a/application/app/AppHandlers.ts b/application/app/AppHandlers.ts index b0964172a..9f6871a4e 100644 --- a/application/app/AppHandlers.ts +++ b/application/app/AppHandlers.ts @@ -4,6 +4,7 @@ import type { Host, HostProtocol, TerminalSession } from '../../types'; import type { PassphraseRequest } from '../../components/PassphraseModal'; import type { TerminalPopupPayload } from '../../domain/systemManager/types'; import { getEffectiveHostDistro, classifyDistroId, hostRestrictsExtraSshChannels, shouldProbeSessionCwd } from '../../domain/host'; +import { resolveHostDefaultLocalShell } from '../../domain/localShellHost'; import { getAvailablePaneMagnificationController } from '../../domain/paneMagnification'; import { sanitizeHostIconFields } from '../../domain/hostIcon'; import { resolveEffectiveTerminalProtocol } from '../../domain/terminalProtocol'; @@ -1108,26 +1109,11 @@ export function handleConnectToHostImpl(getCtx: AppContextGetter, host: Host, hi { const { username, hostname: localHost } = systemInfoRef.current; - let effectiveHost = resolveEffectiveHost(host); - - // Local-shell vault hosts saved with "System default shell" carry no - // localShell; resolve the Settings → Terminal shell here (the same - // resolution ordinary local-terminal creation uses) so those hosts do not - // silently fall back to the OS default shell. - if (effectiveHost.protocol === 'local' && !effectiveHost.localShell) { - const configuredShell = terminalSettings?.localShell ?? ''; - const resolved = resolveShellSetting?.(configuredShell, discoveredShells ?? [], terminalSettings?.localShellArgs); - if (resolved?.command) { - const matchedShell = discoveredShells?.find?.((s) => s.id === configuredShell); - effectiveHost = { - ...effectiveHost, - localShell: resolved.command, - localShellArgs: resolved.args, - localShellName: matchedShell?.name, - localShellIcon: matchedShell?.icon, - }; - } - } + const effectiveHost = resolveHostDefaultLocalShell(resolveEffectiveHost(host), { + discoveredShells, + resolveShellSetting, + terminalSettings, + }); // Handle serial hosts separately if (effectiveHost.protocol === 'serial') { diff --git a/application/app/AppSideEffects.tsx b/application/app/AppSideEffects.tsx index 8f9eb41d1..99cebafc3 100755 --- a/application/app/AppSideEffects.tsx +++ b/application/app/AppSideEffects.tsx @@ -38,6 +38,7 @@ import { import { isTerminalBootEpochCurrent } from '../../domain/terminalBootEpoch'; import { useI18n } from '../i18n/I18nProvider'; import { matchesKeyBinding } from '../../domain/models'; +import { resolveHostDefaultLocalShell } from '../../domain/localShellHost'; import { resolveGroupDefaults, applyGroupDefaults } from '../../domain/groupConfig'; import { upsertKnownHost } from '../../domain/knownHosts'; import { materializeHostProxyProfile } from '../../domain/proxyProfiles'; @@ -1366,8 +1367,18 @@ export function AppSideEffects() { { validProxyProfileIds: proxyProfileIdSet }, ) : applyGroupDefaults(host, {}, { validProxyProfileIds: proxyProfileIdSet }); - return materializeHostProxyProfile(withGroupDefaults, proxyProfiles); - }, [groupConfigs, proxyProfileIdSet, proxyProfiles]); + const effectiveHost = materializeHostProxyProfile(withGroupDefaults, proxyProfiles); + // Local-shell vault hosts saved with "System default shell" carry no + // localShell; resolve the Settings → Terminal shell here at the shared + // effective-host boundary so every launch path (connect, tray/dock open, + // workspace creation/append, tunnels) uses the configured shell instead + // of silently falling back to the backend OS default shell. + return resolveHostDefaultLocalShell(effectiveHost, { + discoveredShells, + resolveShellSetting, + terminalSettings, + }); + }, [groupConfigs, proxyProfileIdSet, proxyProfiles, discoveredShells, terminalSettings]); const createWorkspaceWithEffectiveHosts = useCallback((name: string, selectedHosts: Host[]) => { createWorkspaceWithHosts(name, selectedHosts.map(resolveEffectiveHost)); diff --git a/application/app/AppView.tsx b/application/app/AppView.tsx index 886c3f542..5baa3c96d 100644 --- a/application/app/AppView.tsx +++ b/application/app/AppView.tsx @@ -37,6 +37,7 @@ import { useExternalMcpToggleState } from '../state/useExternalMcpToggleState'; import { selectPluginThemeTokens } from '../state/pluginContributionEnvironment'; import { netcattyBridge } from '../../infrastructure/services/netcattyBridge'; import { resolveEffectiveTerminalHost } from '../../domain/terminalHostResolution'; +import { useDefaultLocalShellContext } from '../../lib/useDiscoveredShells'; import { getAvailablePaneMagnificationController } from '../../domain/paneMagnification'; import { pluginViewTabStore, usePluginViewTabs } from '../state/pluginViewTabStore'; import { buildPluginSettingScopeCatalog } from '../state/usePluginSettingScopeCatalog'; @@ -354,14 +355,16 @@ function AppViewInner({ domains }: AppViewProps) { [proxyProfiles], ); + const defaultLocalShell = useDefaultLocalShellContext(terminalSettings); const resolveWorkspaceAppendHost = useCallback((host: typeof hosts[number]) => ( resolveEffectiveTerminalHost({ host, groupConfigs, proxyProfiles, validProxyProfileIds, + defaultLocalShell, }) - ), [groupConfigs, proxyProfiles, validProxyProfileIds]); + ), [groupConfigs, proxyProfiles, validProxyProfileIds, defaultLocalShell]); const handleAppendHostToWorkspace = useCallback((workspaceId: string, hostId: string) => { const host = hosts.find((entry) => entry.id === hostId); diff --git a/components/SelectHostPanel.tsx b/components/SelectHostPanel.tsx index 4193c7ce2..83d3a94bb 100644 --- a/components/SelectHostPanel.tsx +++ b/components/SelectHostPanel.tsx @@ -30,6 +30,8 @@ interface SelectHostPanelProps { resizable?: boolean; persistWidthStorageKey?: string; resizeAriaLabel?: string; + /** Allow saved local-shell (CMD/PowerShell/...) hosts as targets, e.g. snippet/script runners. */ + allowLocalHosts?: boolean; } const SelectHostPanel: React.FC = ({ @@ -56,6 +58,7 @@ const SelectHostPanel: React.FC = ({ resizable = false, persistWidthStorageKey, resizeAriaLabel, + allowLocalHosts = false, }) => { const { t } = useI18n(); const [newHostPanelOpen, setNewHostPanelOpen] = useState(false); @@ -103,6 +106,7 @@ const SelectHostPanel: React.FC = ({ onSaveHost={onSaveHost} onCreateGroup={onCreateGroup} onNewHostPanelOpenChange={setNewHostPanelOpen} + allowLocalHosts={allowLocalHosts} className="flex-1 min-h-0" /> diff --git a/components/SelectHostPanelContent.tsx b/components/SelectHostPanelContent.tsx index 5810e9088..8fc5daf2d 100644 --- a/components/SelectHostPanelContent.tsx +++ b/components/SelectHostPanelContent.tsx @@ -58,6 +58,8 @@ export interface SelectHostPanelContentProps { onSaveHost?: (host: Host) => void; onCreateGroup?: (groupPath: string) => void; onNewHostPanelOpenChange?: (open: boolean) => void; + /** Allow saved local-shell (CMD/PowerShell/...) hosts as targets, e.g. snippet/script runners. */ + allowLocalHosts?: boolean; className?: string; } @@ -85,6 +87,7 @@ export const SelectHostPanelContent: React.FC = ({ onSaveHost, onCreateGroup, onNewHostPanelOpenChange, + allowLocalHosts = false, className, }) => { const { t } = useI18n(); @@ -106,12 +109,14 @@ export const SelectHostPanelContent: React.FC = ({ onNewHostPanelOpenChange?.(showNewHostPanel); }, [onNewHostPanelOpenChange, showNewHostPanel]); - // This panel picks remote hosts for SSH-backed capabilities (tunnels, - // keychain targets, snippet/script runs); serial and local-shell hosts have - // no SSH session to target, so they are not selectable here. + // This panel picks hosts for SSH-backed capabilities (tunnels, keychain + // key export targets); serial hosts have no SSH session to target and, by + // default, neither do local-shell hosts. Snippet/script target pickers pass + // `allowLocalHosts` because their domain treats every non-serial host + // (including saved CMD/PowerShell shells) as a runnable target. const selectableHosts = useMemo( - () => hosts.filter((host) => host.protocol !== 'serial' && host.protocol !== 'local'), - [hosts], + () => hosts.filter((host) => host.protocol !== 'serial' && (allowLocalHosts || host.protocol !== 'local')), + [hosts, allowLocalHosts], ); const selectedHostIdSet = useMemo( () => new Set(selectedHostIds), diff --git a/components/SnippetsRightPanel.tsx b/components/SnippetsRightPanel.tsx index 97ebf131a..2ff8a730b 100644 --- a/components/SnippetsRightPanel.tsx +++ b/components/SnippetsRightPanel.tsx @@ -132,6 +132,7 @@ export const SnippetsRightPanel: React.FC = ({ customGroups={customGroups} selectedHostIds={targetSelection} multiSelect={true} + allowLocalHosts={true} onSelect={handleTargetSelect} onSelectionChange={handleTargetSelectionChange} onBack={handleTargetPickerBack} diff --git a/components/TerminalLayer.tsx b/components/TerminalLayer.tsx index 5d9e81fd9..a8263ff2a 100644 --- a/components/TerminalLayer.tsx +++ b/components/TerminalLayer.tsx @@ -50,6 +50,7 @@ import { resolveTerminalChainHosts, resolveTerminalSessionHost, } from '../domain/terminalHostResolution'; +import { useDefaultLocalShellContext } from '../lib/useDiscoveredShells'; import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip'; import { toast } from './ui/toast'; import { useI18n } from '../application/i18n/I18nProvider'; @@ -1193,14 +1194,16 @@ const TerminalLayerInner: React.FC = ({ () => new Set(proxyProfiles.map((profile) => profile.id)), [proxyProfiles], ); + const defaultLocalShell = useDefaultLocalShellContext(terminalSettings); const effectiveHosts = useMemo( () => hosts.map((host) => resolveEffectiveTerminalHost({ host, groupConfigs, proxyProfiles, validProxyProfileIds: proxyProfileIdSet, + defaultLocalShell, })), - [groupConfigs, hosts, proxyProfileIdSet, proxyProfiles], + [groupConfigs, hosts, proxyProfileIdSet, proxyProfiles, defaultLocalShell], ); // Pre-compute fallback hosts to avoid creating new objects on every render @@ -1213,11 +1216,12 @@ const TerminalLayerInner: React.FC = ({ groupConfigs, proxyProfiles, localOs: detectLocalOs(navigator.userAgent || navigator.platform), + defaultLocalShell, }); map.set(session.id, applySessionFontSizeToHost(hostForSession, session)); } return map; - }, [sessions, hosts, groupConfigs, proxyProfiles]); + }, [sessions, hosts, groupConfigs, proxyProfiles, defaultLocalShell]); const resolvedSessionHostIds = useMemo(() => { const ids = new Set(); for (const session of sessions) { diff --git a/components/scripts/ScriptEditorModal.tsx b/components/scripts/ScriptEditorModal.tsx index 6d9d0d4f0..2566ef2d0 100644 --- a/components/scripts/ScriptEditorModal.tsx +++ b/components/scripts/ScriptEditorModal.tsx @@ -200,6 +200,7 @@ export const ScriptEditorModal: React.FC = ({ customGroups={customGroups} selectedHostIds={selectedHostIds} multiSelect + allowLocalHosts={true} onSelect={onSelectHost} onSelectionChange={onSelectionChange} onConfirm={handleTargetsConfirm} diff --git a/components/sftp/SftpHostPicker.tsx b/components/sftp/SftpHostPicker.tsx index 83c306230..bfb7122b1 100644 --- a/components/sftp/SftpHostPicker.tsx +++ b/components/sftp/SftpHostPicker.tsx @@ -10,7 +10,7 @@ import { sftpSourceSessionIdForHost, type SftpConnectedHostEntry, } from '../../domain/sftpConnectedHosts'; -import { isPluginHostProtocol } from '../../domain/pluginConnection'; +import { canOpenDualPaneSftp } from '../../domain/sftpDualPaneOpen'; import { Host } from '../../types'; import { DistroAvatar } from '../DistroAvatar'; import { getQuickSwitcherRowStateClass, shouldUseQuickSwitcherPointerNavigation } from '../QuickSwitcher'; @@ -95,9 +95,11 @@ const SftpHostPickerInner: React.FC = ({ const filteredHosts = useMemo(() => { return hosts.filter((h) => { - // SFTP is an SSH-specific host capability. Plugin protocols may - // provide arbitrary transports and cannot be treated as SSH. - if (h.protocol === "serial" || isPluginHostProtocol(h.protocol)) return false; + // SFTP is an SSH-specific host capability. Reuse the dual-pane + // opener's predicate so serial, local-shell (no SSH channel — + // selecting one would SSH into localhost) and plugin protocols + // are excluded the same way everywhere. + if (!canOpenDualPaneSftp(h)) return false; // Hide a saved host only when Connected already shows the same endpoint. // If the vault host was edited after connect, keep both: Live (old) + Saved (new). const connected = connectedByHostId.get(h.id); diff --git a/domain/localShellHost.ts b/domain/localShellHost.ts index cb0b81764..bac46f6cc 100644 --- a/domain/localShellHost.ts +++ b/domain/localShellHost.ts @@ -67,3 +67,43 @@ export const getVaultHostRowSubtitle = ( ? getLocalShellHostSubtitle(host, options?.localFallback) : `${host.username ?? ''}@${host.hostname ?? ''}` ); + +export interface ResolveDefaultLocalShellContext { + discoveredShells?: DiscoveredShell[]; + terminalSettings?: { localShell?: string; localShellArgs?: string[] }; + resolveShellSetting?: ( + localShell: string, + discoveredShells: DiscoveredShell[], + customArgs?: string[], + ) => { command: string; args?: string[] } | null; +} + +/** + * Saved local-shell hosts created with "System default shell" carry no + * `localShell`. Resolve the Settings → Terminal shell for them so every save + * path that materializes effective hosts (host connect, tray/dock open, + * workspace creation/append, ...) launches the configured shell instead of + * silently falling back to the backend OS default. A no-op for non-local + * hosts and for hosts that already specify a shell. + */ +export const resolveHostDefaultLocalShell = ( + host: Host, + ctx: ResolveDefaultLocalShellContext, +): Host => { + if (host.protocol !== 'local' || host.localShell) return host; + const configuredShell = ctx.terminalSettings?.localShell ?? ''; + const resolved = ctx.resolveShellSetting?.( + configuredShell, + ctx.discoveredShells ?? [], + ctx.terminalSettings?.localShellArgs, + ); + if (!resolved?.command) return host; + const matchedShell = ctx.discoveredShells?.find((s) => s.id === configuredShell); + return { + ...host, + localShell: resolved.command, + localShellArgs: resolved.args, + localShellName: matchedShell?.name, + localShellIcon: matchedShell?.icon, + }; +}; diff --git a/domain/terminalHostResolution.ts b/domain/terminalHostResolution.ts index c62e3fa9d..691a308c6 100644 --- a/domain/terminalHostResolution.ts +++ b/domain/terminalHostResolution.ts @@ -2,6 +2,7 @@ import type { GroupConfig, Host, ProxyProfile, TerminalSession } from "./models" import { applyGroupDefaults, resolveGroupDefaults } from "./groupConfig"; import { materializeHostProxyProfile } from "./proxyProfiles"; import { sanitizePluginConnection } from "./pluginConnection"; +import { resolveHostDefaultLocalShell, type ResolveDefaultLocalShellContext } from "./localShellHost"; type LocalOs = Host["os"]; @@ -10,6 +11,8 @@ interface ResolveEffectiveHostOptions { groupConfigs: GroupConfig[]; proxyProfiles: ProxyProfile[]; validProxyProfileIds?: ReadonlySet; + /** When provided, saved local hosts with no shell resolve the Settings shell. */ + defaultLocalShell?: ResolveDefaultLocalShellContext; } interface ResolveTerminalSessionHostOptions { @@ -18,6 +21,8 @@ interface ResolveTerminalSessionHostOptions { groupConfigs: GroupConfig[]; proxyProfiles: ProxyProfile[]; localOs: LocalOs; + /** When provided, saved local hosts with no shell resolve the Settings shell. */ + defaultLocalShell?: ResolveDefaultLocalShellContext; } interface ResolveTerminalChainHostsOptions { @@ -41,14 +46,18 @@ export function resolveEffectiveTerminalHost({ groupConfigs, proxyProfiles, validProxyProfileIds = new Set(proxyProfiles.map((profile) => profile.id)), + defaultLocalShell, }: ResolveEffectiveHostOptions): Host { const groupDefaults = host.group ? resolveGroupDefaults(host.group, groupConfigs, { validProxyProfileIds }) : {}; - return materializeHostProxyProfile( + const effectiveHost = materializeHostProxyProfile( applyGroupDefaults(host, groupDefaults, { validProxyProfileIds }), proxyProfiles, ); + return defaultLocalShell + ? resolveHostDefaultLocalShell(effectiveHost, defaultLocalShell) + : effectiveHost; } const suppressDeviceTypeForShellTransport = (host: Host): Host => { @@ -92,6 +101,7 @@ export function resolveTerminalSessionHost({ groupConfigs, proxyProfiles, localOs, + defaultLocalShell, }: ResolveTerminalSessionHostOptions): Host { const vaultHost = hosts.find((host) => host.id === session.hostId); if (!vaultHost) return buildFallbackHostFromSession(session, localOs); @@ -100,6 +110,7 @@ export function resolveTerminalSessionHost({ host: vaultHost, groupConfigs, proxyProfiles, + defaultLocalShell, }); const protocol = session.protocol ?? existingHost.protocol; diff --git a/domain/vaultImport/csvExport.ts b/domain/vaultImport/csvExport.ts index 49ca3b91c..c3c6d58f4 100644 --- a/domain/vaultImport/csvExport.ts +++ b/domain/vaultImport/csvExport.ts @@ -56,12 +56,16 @@ export const getVaultCsvTemplate = ( // The legacy CSV format has no per-host shell columns, so local-shell vault // hosts are serialized as one encoded "LocalShell" field; hosts with a // non-default shell are otherwise lost on reimport (backup data silently -// changed). Default-shell local hosts need no field: connecting resolves the -// Settings shell the same way ordinary local-terminal creation does. +// changed). Default-shell Windows/macOS local hosts still export their OS: +// reimport defaults to Linux, and the OS is part of the reimport dedupe key, +// so a macOS default-shell entry without an OS field would be reimported as +// (and collapse with) a Linux host. Linux default-shell hosts match the +// reimport default and need no field. const getLocalShellSpec = (host: Host): CsvLocalShellSpec | null => ( host.protocol === "local" && (host.localShell || host.localShellName || host.localShellIcon - || host.localStartDir || host.localShellArgs?.length || host.os === "windows") + || host.localStartDir || host.localShellArgs?.length + || host.os === "windows" || host.os === "macos") ? { shell: host.localShell || undefined, shellArgs: host.localShellArgs?.length ? host.localShellArgs : undefined, diff --git a/lib/useDiscoveredShells.ts b/lib/useDiscoveredShells.ts index 7c0609a78..0bc05d493 100644 --- a/lib/useDiscoveredShells.ts +++ b/lib/useDiscoveredShells.ts @@ -1,5 +1,6 @@ -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { netcattyBridge } from "../infrastructure/services/netcattyBridge"; +import type { ResolveDefaultLocalShellContext } from "../domain/localShellHost"; let shellCache: DiscoveredShell[] | null = null; let shellPromise: Promise | null = null; @@ -208,3 +209,18 @@ export function getShellIconPath(iconId: string): string { export function isMonochromeShellIcon(iconId: string): boolean { return DISTRO_ICONS.has(iconId); } + +/** + * Build the context consumed by `resolveHostDefaultLocalShell` (Settings shell + * + discovered shells + resolver) so every effective-host/session-creation + * boundary can resolve saved local hosts saved with "System default shell". + */ +export function useDefaultLocalShellContext( + terminalSettings?: { localShell?: string; localShellArgs?: string[] }, +): ResolveDefaultLocalShellContext { + const discoveredShells = useDiscoveredShells(); + return useMemo( + () => ({ discoveredShells, resolveShellSetting, terminalSettings }), + [discoveredShells, terminalSettings], + ); +}