Skip to content

The agent that grows with you

fix(desktop): map URL-remote per-profile label to backend profile via remoteProfile (#88282)

Merge_Conflict - Pasi39faafb61688
diff --git a/apps/desktop/electron/connection-config.test.ts b/apps/desktop/electron/connection-config.test.ts
index cfd9239e4f1..6a3f55aec25 100644
--- a/apps/desktop/electron/connection-config.test.ts
+++ b/apps/desktop/electron/connection-config.test.ts
@@ -254,6 +254,37 @@ test('SSH remains separate from URL-shaped remote modes and preserves an explici
})
})
+test('profileRemoteOverride preserves an explicit remote profile mapping on a URL override', () => {
+ const config = {
+ profiles: { gris: { mode: 'remote', url: 'https://agent.example.com/hermes', remoteProfile: 'main-gris' } }
+ }
+
+ assert.deepEqual(profileRemoteOverride(config, 'gris'), {
+ url: 'https://agent.example.com/hermes',
+ authMode: 'token',
+ token: undefined,
+ remoteProfile: 'main-gris'
+ })
+})
+
+test('profileRemoteOverride drops invalid or reserved remote profile mappings', () => {
+ assert.equal(
+ profileRemoteOverride({ profiles: { p: { mode: 'remote', url: 'https://x', remoteProfile: 'bad profile' } } }, 'p')
+ ?.remoteProfile,
+ undefined
+ )
+ assert.equal(
+ profileRemoteOverride({ profiles: { p: { mode: 'cloud', url: 'https://x', remoteProfile: 'root' } } }, 'p')
+ ?.remoteProfile,
+ undefined
+ )
+ assert.equal(
+ profileRemoteOverride({ profiles: { p: { mode: 'remote', url: 'https://x', remoteProfile: '' } } }, 'p')
+ ?.remoteProfile,
+ undefined
+ )
+})
+
test('normalizeSshConfig rejects unsafe remote profile mappings', () => {
assert.deepEqual(normalizeSshConfig({ mode: 'ssh', host: 'box', remoteProfile: 'writer_2' }), {
mode: 'ssh',
@@ -700,6 +731,32 @@ test('pathWithGlobalRemoteProfile translates a desktop SSH alias in an explicit
)
})
+test('pathWithGlobalRemoteProfile translates a URL-remote override alias via backendProfile', () => {
+ // A URL-remote per-profile override (gris → main-gris) must rewrite the
+ // self-profile scope the same way the SSH mapping does, or the backend 404s
+ // on a profile it does not have (#88282).
+ assert.equal(
+ pathWithGlobalRemoteProfile('/api/cron/jobs?profile=gris', 'gris', {
+ globalRemote: false,
+ profileRemoteOverride: true,
+ backendProfile: 'main-gris'
+ }),
+ '/api/cron/jobs?profile=main-gris'
+ )
+})
+
+test('pathWithGlobalRemoteProfile keeps the local label when a URL override has no mapping', () => {
+ // Blank remoteProfile → the label itself is the scope (historical behavior).
+ assert.equal(
+ pathWithGlobalRemoteProfile('/api/cron/jobs?profile=gris', 'gris', {
+ globalRemote: false,
+ profileRemoteOverride: true,
+ backendProfile: undefined
+ }),
+ '/api/cron/jobs?profile=gris'
+ )
+})
+
test('pathWithGlobalRemoteProfile preserves cross-profile selectors when translating an SSH alias', () => {
const opts = {
globalRemote: false,
diff --git a/apps/desktop/electron/connection-config.ts b/apps/desktop/electron/connection-config.ts
index 6538377337b..d37bb362485 100644
--- a/apps/desktop/electron/connection-config.ts
+++ b/apps/desktop/electron/connection-config.ts
@@ -562,10 +562,28 @@ function profileRemoteOverride(config, profile) {
url,
authMode: normAuthMode(entry.authMode),
token: entry.token,
- ...(Object.keys(headers).length > 0 ? { headers } : {})
+ ...(Object.keys(headers).length > 0 ? { headers } : {}),
+ // A URL-remote/cloud host serves every profile via ?profile=, so a Desktop
+ // profile that is only a routing label (e.g. `gris` for the backend's
+ // `main-gris`) can map its explicit self-profile scope into the backend's
+ // namespace — same contract as the managed-SSH `remoteProfile`.
+ ...(normalizeRemoteProfileName(entry.remoteProfile) ?? {})
}
}
+// Validate a remote profile mapping the same way the SSH path does (a valid
+// Hermes profile identifier, never a reserved alias). Invalid/blank → no
+// mapping, so callers fall back to the historical same-name behavior.
+function normalizeRemoteProfileName(value) {
+ const remoteProfile = String(value || '').trim()
+
+ if (/^[a-z0-9][a-z0-9_-]{0,63}$/.test(remoteProfile) && !RESERVED_REMOTE_PROFILES.has(remoteProfile)) {
+ return { remoteProfile }
+ }
+
+ return null
+}
+
export interface ProfileRouteOptions {
/** Profile name on a separately-scoped backend when it differs from the
* desktop's local routing label (managed SSH `remoteProfile`). */
@@ -1144,6 +1162,7 @@ export {
modeIsRemoteLike,
normalizeRemoteBaseUrl,
normalizeRemoteHeaders,
+ normalizeRemoteProfileName,
normalizeSshConfig,
normAuthMode,
pathForRegistryBackendRequest,
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index b10d96eee17..7c85312f489 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -148,6 +148,7 @@ import {
modeIsRemoteLike,
normalizeRemoteBaseUrl,
normalizeRemoteHeaders,
+ normalizeRemoteProfileName,
normalizeSshConfig,
normAuthMode,
pathForRegistryBackendRequest,
@@ -8820,6 +8821,7 @@ function sanitizeConnectionProfiles(raw: Record<string, any>) {
headers?: object
org?: string
name?: string
+ remoteProfile?: string
savedSsh?: object
} = {
mode: modeIsRemoteLike(entry.mode) ? entry.mode : 'local'
@@ -8845,6 +8847,14 @@ function sanitizeConnectionProfiles(raw: Record<string, any>) {
cleaned.token = entry.token
}
+ // A URL-remote/cloud per-profile override can map its Desktop routing label
+ // onto the backend's profile namespace (same contract as SSH remoteProfile).
+ const remoteProfileName = normalizeRemoteProfileName((entry as any).remoteProfile)
+
+ if (remoteProfileName) {
+ cleaned.remoteProfile = remoteProfileName.remoteProfile
+ }
+
const headers = normalizeRemoteHeaders((entry as any).headers)
if (Object.keys(headers).length > 0) {
@@ -9392,12 +9402,20 @@ async function sanitizeDesktopConnectionConfig(config = readDesktopConnectionCon
// `org` (optional) is the Hermes Cloud org slug/id the instance was discovered
// under — persisted so Settings can reopen into the same org; omitted from the
// block when empty so plain remote connections stay unchanged.
-function buildRemoteBlock(remoteUrl, authMode, token, org?: string, headers?: object, name?: string) {
+function buildRemoteBlock(remoteUrl, authMode, token, org?: string, headers?: object, name?: string, remoteProfile?: string) {
if (authMode !== 'oauth' && !decryptDesktopSecret(token)) {
throw new Error('Remote gateway session token is required.')
}
- const block: { url: string; authMode: string; token: object; headers?: object; org?: string; name?: string } = {
+ const block: {
+ url: string
+ authMode: string
+ token: object
+ headers?: object
+ org?: string
+ name?: string
+ remoteProfile?: string
+ } = {
url: normalizeRemoteBaseUrl(remoteUrl),
authMode,
token
@@ -9421,6 +9439,12 @@ function buildRemoteBlock(remoteUrl, authMode, token, org?: string, headers?: ob
block.org = orgValue
}
+ const remoteProfileName = normalizeRemoteProfileName(remoteProfile)
+
+ if (remoteProfileName) {
+ block.remoteProfile = remoteProfileName.remoteProfile
+ }
+
return block
}
@@ -9508,7 +9532,7 @@ function coerceDesktopConnectionConfig(input: any = {}, existing = readDesktopCo
if (remoteLike) {
profiles[key] = {
mode,
- ...buildRemoteBlock(remoteUrl, authMode, nextToken, cloudOrg, remoteHeaders, cloudName)
+ ...buildRemoteBlock(remoteUrl, authMode, nextToken, cloudOrg, remoteHeaders, cloudName, input.remoteProfile)
}
} else {
const localEntry = localProfileEntry(rawExistingBlock)
@@ -10900,15 +10924,17 @@ function profileRouteOptions(
): ProfileRouteOptions {
const config = readDesktopConnectionConfig()
const sshOverride = profileSshOverride(config, profile)
+ const urlOverride = profileRemoteOverride(config, profile)
const key = connectionScopeKey(profile) || primaryProfileKey()
return {
// A desktop profile can be only a client-side routing alias. Keep backend
- // endpoint filters in the SSH target's namespace (e.g. mara → default).
- backendProfile: sshOverride?.remoteProfile,
+ // endpoint filters in the target's namespace (e.g. mara → default for a
+ // managed SSH, gris → main-gris for a URL-remote/cloud per-profile host).
+ backendProfile: sshOverride?.remoteProfile || urlOverride?.remoteProfile,
globalRemote: globalRemoteActive(),
primaryProfile: primaryProfileKey(),
- profileRemoteOverride: Boolean(profileRemoteOverride(config, profile) || sshOverride),
+ profileRemoteOverride: Boolean(urlOverride || sshOverride),
// The primary profile's own backend resolves to a remote host (its
// per-profile override, env, or global). Unknown sub-profiles on that
// gateway must route THROUGH it, not spawn local backends (#88296).
diff --git a/apps/desktop/src/global.d.ts b/apps/desktop/src/global.d.ts
index 95b05a46596..0ef2f3d9afb 100644
--- a/apps/desktop/src/global.d.ts
+++ b/apps/desktop/src/global.d.ts
@@ -1048,6 +1048,9 @@ export interface DesktopConnectionConfigInput {
sshKeyPath?: string
sshRemoteHermesPath?: string
sshRemoteProfile?: string
+ // For a URL-remote/cloud per-profile override: the profile name on the remote
+ // host when it differs from this Desktop routing label.
+ remoteProfile?: string
}
export interface DesktopConnectionTestResult {