diff --git a/src/renderer/src/components/new-workspace/RunTargetCombobox.host-identity.test.tsx b/src/renderer/src/components/new-workspace/RunTargetCombobox.host-identity.test.tsx index 31f6c91378b..b589f1f8e79 100644 --- a/src/renderer/src/components/new-workspace/RunTargetCombobox.host-identity.test.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetCombobox.host-identity.test.tsx @@ -66,6 +66,27 @@ describe('run target host identity', () => { expect(onHostChange).toHaveBeenCalledWith(JSON.stringify(['same-id', 'ssh:builder'])) }) + it('shows a merged machine row when the selection names its other host id', () => { + const serverOption: ReadyProjectHostSetupOption = { + ...sshOption, + id: 'server-setup', + hostId: 'runtime:builder-server', + aliasSetups: [{ id: 'ssh-setup', hostId: 'ssh:builder' }] + } + render( + + ) + + const field = screen.getByRole('combobox', { name: 'Run on' }) + expect(field.parentElement?.parentElement?.textContent).toContain('Builder') + }) + it('gives duplicate setup IDs distinct keyboard navigation keys', () => { const { rows } = buildRunTargetRows({ hostOptions: options, diff --git a/src/renderer/src/components/new-workspace/RunTargetCombobox.tsx b/src/renderer/src/components/new-workspace/RunTargetCombobox.tsx index 787c02d9c6c..e6cc92baebe 100644 --- a/src/renderer/src/components/new-workspace/RunTargetCombobox.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetCombobox.tsx @@ -88,11 +88,12 @@ export default function RunTargetCombobox({ () => hostOptions.filter((option) => option.kind === 'ready'), [hostOptions] ) + const isSelected = (candidate: { id: string; hostId: string }): boolean => + candidate.id === hostValue && (!hostExecutionHostId || candidate.hostId === hostExecutionHostId) const selectedHost = - readyHostOptions.find( - (option) => - option.id === hostValue && (!hostExecutionHostId || option.hostId === hostExecutionHostId) - ) ?? + readyHostOptions.find(isSelected) ?? + // Why: a selection on a merged machine's other id still belongs to that machine's one row. + readyHostOptions.find((option) => option.aliasSetups?.some(isSelected)) ?? readyHostOptions[0] ?? null const selectedRecipe = recipes.find((recipe) => recipe.id === recipeValue) ?? null diff --git a/src/renderer/src/lib/project-host-setup-options.test.ts b/src/renderer/src/lib/project-host-setup-options.test.ts index 3cb30ea47ae..23e6a82a8db 100644 --- a/src/renderer/src/lib/project-host-setup-options.test.ts +++ b/src/renderer/src/lib/project-host-setup-options.test.ts @@ -612,4 +612,67 @@ describe('buildProjectHostSetupOptions', () => { expect.objectContaining({ kind: 'needs-setup', hostId: 'runtime:omarchy-server' }) ]) }) + + function managedOpenclawHosts(): ExecutionHostRegistryEntry[] { + return buildExecutionHostRegistry({ + repos: [], + settings: null, + hostSource: 'configured-only', + sshTargetLabels: new Map([['openclaw-target', 'openclaw']]), + runtimeEnvironments: [ + { + id: 'openclaw-server', + name: 'openclaw', + orcadDeployment: { sshTargetId: 'openclaw-target' } + } + ] + }) + } + + it('shows one row when an SSH host and its managed server report the same checkout', () => { + const checkout = { path: '/home/neil/projects/orca' } + const options = buildProjectHostSetupOptions({ + projectId: 'project-1', + eligibleRepos: [repo('local-repo'), repo('ssh-repo'), repo('server-repo')], + hosts: [host('local'), ...managedOpenclawHosts()], + projectHostSetups: [ + setup('local', 'project-1', 'local', 'local-repo'), + // The SSH repo predates the managed server, so it comes first in store order. + setup('ssh', 'project-1', 'ssh:openclaw-target', 'ssh-repo', checkout), + setup('server', 'project-1', 'runtime:openclaw-server', 'server-repo', checkout) + ] + }) + + expect(options.filter((option) => option.label === 'openclaw')).toEqual([ + expect.objectContaining({ + kind: 'ready', + id: 'server', + hostId: 'runtime:openclaw-server', + aliasSetups: [{ id: 'ssh', hostId: 'ssh:openclaw-target' }] + }) + ]) + }) + + it('keeps distinct checkouts on an SSH host and its managed server as separate rows', () => { + const options = buildProjectHostSetupOptions({ + projectId: 'project-1', + eligibleRepos: [repo('ssh-repo'), repo('server-repo')], + hosts: managedOpenclawHosts(), + projectHostSetups: [ + setup('ssh', 'project-1', 'ssh:openclaw-target', 'ssh-repo', { path: '/home/neil/a' }), + setup('server', 'project-1', 'runtime:openclaw-server', 'server-repo', { + path: '/home/neil/b' + }) + ] + }) + + expect( + options + .filter((option) => option.kind === 'ready') + .map((option) => [option.id, option.hostId]) + ).toEqual([ + ['ssh', 'ssh:openclaw-target'], + ['server', 'runtime:openclaw-server'] + ]) + }) }) diff --git a/src/renderer/src/lib/project-host-setup-options.ts b/src/renderer/src/lib/project-host-setup-options.ts index a8aa1158ee6..3b1dafddcab 100644 --- a/src/renderer/src/lib/project-host-setup-options.ts +++ b/src/renderer/src/lib/project-host-setup-options.ts @@ -16,6 +16,9 @@ import { import type { ProjectHostSetup } from '../../../shared/project-types' import type { Repo } from '../../../shared/repo-types' import { translate } from '@/i18n/i18n' +import { dedupeReadySetupRows } from './project-host-setup-row-dedupe' + +export type ProjectHostSetupSelection = { id: string; hostId: ExecutionHostId } export type ProjectHostSetupOption = | { @@ -27,6 +30,8 @@ export type ProjectHostSetupOption = label: string detail: string path: string + /** Same-checkout setups on this machine's other host id that this row stands for. */ + aliasSetups?: readonly ProjectHostSetupSelection[] } | { id: string @@ -128,7 +133,7 @@ function buildReadySetupOptions({ }: BuildReadySetupOptionsInput): ReadyProjectHostSetupOption[] { const eligibleRepoIds = new Set(eligibleRepos.map((repo) => repo.id)) const hostById = new Map(hosts.map((host) => [host.id, host])) - return projectHostSetups + const options = projectHostSetups .filter((setup) => { const host = hostById.get(setup.hostId) return ( @@ -150,23 +155,7 @@ function buildReadySetupOptions({ detail: setup.displayName, path: setup.path })) - .filter(dedupeByHost()) -} - -// Why: a project resolves to at most one setup per host — resolveWorkspaceCreationTarget takes the -// first project+host match and ignores the rest, so extra same-host setups are unreachable. Legacy -// profiles can still hold them (a linked worktree added as its own project projects a second local -// setup), which rendered as repeated identical "Local Mac" rows. Keep the first in input order so -// the row shown is the one workspace creation actually uses. -function dedupeByHost(): (option: ReadyProjectHostSetupOption) => boolean { - const seenHosts = new Set() - return (option) => { - if (seenHosts.has(option.hostId)) { - return false - } - seenHosts.add(option.hostId) - return true - } + return dedupeReadySetupRows(options, hostById) } function buildNeedsSetupOptions({ diff --git a/src/renderer/src/lib/project-host-setup-row-dedupe.ts b/src/renderer/src/lib/project-host-setup-row-dedupe.ts new file mode 100644 index 00000000000..1f3c423f866 --- /dev/null +++ b/src/renderer/src/lib/project-host-setup-row-dedupe.ts @@ -0,0 +1,62 @@ +import type { ExecutionHostId } from '../../../shared/execution-host' +import type { ExecutionHostRegistryEntry } from '../../../shared/execution-host-registry' +import type { + ProjectHostSetupSelection, + ReadyProjectHostSetupOption +} from './project-host-setup-options' + +/** Collapses ready setup rows to one per host, then one per checkout on a merged machine. */ +export function dedupeReadySetupRows( + options: readonly ReadyProjectHostSetupOption[], + hostById: ReadonlyMap +): ReadyProjectHostSetupOption[] { + return collapseMergedHostCheckouts(options.filter(dedupeByHost()), hostById) +} + +// Why: a project resolves to at most one setup per host — resolveWorkspaceCreationTarget takes the +// first project+host match and ignores the rest, so extra same-host setups are unreachable. Legacy +// profiles can still hold them (a linked worktree added as its own project projects a second local +// setup), which rendered as repeated identical "Local Mac" rows. Keep the first in input order so +// the row shown is the one workspace creation actually uses. +function dedupeByHost(): (option: ReadyProjectHostSetupOption) => boolean { + const seenHosts = new Set() + return (option) => { + if (seenHosts.has(option.hostId)) { + return false + } + seenHosts.add(option.hostId) + return true + } +} + +// Why: an SSH host and its managed Orca server are one machine, and both can report the same +// checkout (the old SSH repo locally, the server's own setup remotely), which rendered as two +// identical rows. Keep the one on the row the picker shows, the route serving the host now. A +// different path on the other id is a distinct checkout, so it keeps its own row. +function collapseMergedHostCheckouts( + options: readonly ReadyProjectHostSetupOption[], + hostById: ReadonlyMap +): ReadyProjectHostSetupOption[] { + const findShown = (option: ReadyProjectHostSetupOption): ReadyProjectHostSetupOption | null => { + const mergedIntoHostId = hostById.get(option.hostId)?.mergedIntoHostId + return mergedIntoHostId + ? (options.find((other) => other.hostId === mergedIntoHostId && other.path === option.path) ?? + null) + : null + } + const aliasesByShown = new Map() + for (const option of options) { + const shown = findShown(option) + if (shown) { + const aliases = aliasesByShown.get(shown) ?? [] + aliases.push({ id: option.id, hostId: option.hostId }) + aliasesByShown.set(shown, aliases) + } + } + return options + .filter((option) => !findShown(option)) + .map((option) => { + const aliasSetups = aliasesByShown.get(option) + return aliasSetups ? { ...option, aliasSetups } : option + }) +}