feat(settings): Codex Bağlama, on by default

Settings → Codex Bağlama runs the bundled bridge for an OpenAI Codex install on
the same computer: the IDE's models and combos appear in Codex and switching
models keeps the conversation. The IDE points Codex's openai_base_url at the
bridge only after the bridge answers, keeps it running across logins, and
removes every trace when the setting is turned off. A Codex that already uses
another base URL is left untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HRDGW1LiKcDUZYUdKBoWYW
This commit is contained in:
yilsemandClaude Opus 5.5 committed 2026-10-09 15:59:39 +03:00
1 parent 1ce5ab82cf
commit dea67fc153
16 files changed
+2317 -2

No files matched your search

@@ -0,0 +1,193 @@
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { I18nProvider } from '@/i18n/context'
import type { CodexLinkStatus } from '../../../electron/codex-link-types'
import { CodexLinkSettings } from './codex-link-settings'
const notifyError = vi.hoisted(() => vi.fn())
vi.mock('@/store/notifications', () => ({ notifyError }))
const RUNNING: CodexLinkStatus = {
enabled: true,
codexFound: true,
venvReady: true,
foreign: false,
bridgeRunning: true,
ideDurum: 'tamam',
ideModel: 12,
ozet: true,
lastError: null
}
const get = vi.fn<() => Promise<CodexLinkStatus>>()
const set = vi.fn<(patch: { enabled?: boolean; sync?: boolean }) => Promise<CodexLinkStatus>>()
function renderPage(locale: 'en' | 'tr' = 'tr') {
return render(
<I18nProvider configClient={null} initialLocale={locale}>
<CodexLinkSettings />
</I18nProvider>
)
}
function statusTexts() {
return screen.getAllByRole('listitem').map(item => item.textContent)
}
beforeEach(() => {
;(window as unknown as { hermesDesktop: unknown }).hermesDesktop = { codexLink: { get, set } }
})
afterEach(() => {
cleanup()
vi.resetAllMocks()
delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
})
describe('Codex Link settings', () => {
it('explains the feature and shows a healthy link in Turkish', async () => {
get.mockResolvedValue(RUNNING)
renderPage()
expect(await screen.findByText('Köprü çalışıyor.')).toBeTruthy()
expect(statusTexts()).toEqual(['Bu bilgisayarda Codex bulundu.', 'Köprü çalışıyor.', "Codex'e 12 model eklendi."])
expect(
screen.getByText(
"AITURK IDE'deki modelleri ve comboları bu bilgisayardaki Codex'e ekler; modeller arasında geçerken sohbet bağlamını korur."
)
).toBeTruthy()
expect(screen.getByText("Codex'te yeni modelleri görmek için Codex'i yeniden açın.")).toBeTruthy()
expect(screen.getByRole('switch', { name: 'Codex Bağlama' }).getAttribute('aria-checked')).toBe('true')
expect(set).not.toHaveBeenCalled()
})
it('renders in English for other locales', async () => {
get.mockResolvedValue(RUNNING)
renderPage('en')
expect(await screen.findByText('The bridge is running.')).toBeTruthy()
expect(statusTexts()).toEqual([
'Codex was found on this computer.',
'The bridge is running.',
'12 models added to Codex.'
])
expect(screen.getByRole('button', { name: 'Sync now' })).toBeTruthy()
})
it('says only that Codex is missing when it is not installed', async () => {
get.mockResolvedValue({ ...RUNNING, codexFound: false, bridgeRunning: false, ideDurum: null, ideModel: null })
renderPage()
expect(await screen.findByText('Bu bilgisayarda Codex bulunamadı.')).toBeTruthy()
expect(statusTexts()).toEqual(['Bu bilgisayarda Codex bulunamadı.'])
})
it('says another bridge is in charge and does not claim ours is running', async () => {
get.mockResolvedValue({ ...RUNNING, foreign: true })
renderPage()
expect(await screen.findByText(/başka bir köprü kullanıyor/)).toBeTruthy()
expect(statusTexts()).toEqual([
'Bu bilgisayarda Codex bulundu.',
'Bu bilgisayarda Codex başka bir köprü kullanıyor; ayarına dokunulmadı.'
])
})
it('says it is waiting for the IDE setup', async () => {
get.mockResolvedValue({ ...RUNNING, venvReady: false, bridgeRunning: false, ideDurum: null, ideModel: null })
renderPage()
expect(await screen.findByText('IDE kurulumu tamamlanınca etkinleşecek.')).toBeTruthy()
expect(screen.queryByText('Köprü çalışmıyor.')).toBeNull()
})
it('asks for a sign-in when the bridge has no IDE session', async () => {
get.mockResolvedValue({ ...RUNNING, ideDurum: 'anahtar-yok', ideModel: 0 })
renderPage()
expect(await screen.findByText('IDE oturumu bulunamadı, giriş yapın.')).toBeTruthy()
expect(screen.queryByText(/model eklendi/)).toBeNull()
})
it('shows a stopped bridge together with the last error', async () => {
get.mockResolvedValue({
...RUNNING,
bridgeRunning: false,
ideDurum: null,
ideModel: null,
lastError: 'bridge-start-failed'
})
renderPage()
expect(await screen.findByText('Köprü çalışmıyor.')).toBeTruthy()
expect(screen.getByText('Köprü başlatılamadı; Codex ayarına dokunulmadı.')).toBeTruthy()
})
it('turns the link off through the bridge and adopts the reply', async () => {
get.mockResolvedValue(RUNNING)
set.mockResolvedValue({ ...RUNNING, enabled: false, bridgeRunning: false, ideDurum: null, ideModel: null })
renderPage()
await screen.findByText('Köprü çalışıyor.')
fireEvent.click(screen.getByRole('switch', { name: 'Codex Bağlama' }))
expect(set).toHaveBeenCalledWith({ enabled: false })
expect(await screen.findByText('Codex Bağlama kapalı. Codex kendi ayarlarıyla çalışıyor.')).toBeTruthy()
expect(screen.getByRole('switch', { name: 'Codex Bağlama' }).getAttribute('aria-checked')).toBe('false')
})
it('rolls the switch back and reports when the change fails', async () => {
get.mockResolvedValue(RUNNING)
set.mockRejectedValue(new Error('codex-link:unavailable'))
renderPage()
await screen.findByText('Köprü çalışıyor.')
fireEvent.click(screen.getByRole('switch', { name: 'Codex Bağlama' }))
await waitFor(() => expect(notifyError).toHaveBeenCalledWith(expect.any(Error), 'Codex Bağlama değiştirilemedi.'))
expect(screen.getByRole('switch', { name: 'Codex Bağlama' }).getAttribute('aria-checked')).toBe('true')
expect(screen.getByText('Köprü çalışıyor.')).toBeTruthy()
})
it('syncs on demand and keeps the button disabled while it runs', async () => {
get.mockResolvedValue({ ...RUNNING, bridgeRunning: false, ideDurum: null, ideModel: null })
let finish: (status: CodexLinkStatus) => void = () => undefined
set.mockReturnValue(
new Promise<CodexLinkStatus>(resolve => {
finish = resolve
})
)
renderPage()
await screen.findByText('Köprü çalışmıyor.')
fireEvent.click(screen.getByRole('button', { name: 'Şimdi eşitle' }))
expect(set).toHaveBeenCalledTimes(1)
expect(set).toHaveBeenCalledWith({ sync: true })
const pending = screen.getByRole('button', { name: 'Eşitleniyor…' }) as HTMLButtonElement
expect(pending.disabled).toBe(true)
fireEvent.click(pending)
expect(set).toHaveBeenCalledTimes(1)
finish(RUNNING)
expect(await screen.findByText('Köprü çalışıyor.')).toBeTruthy()
expect((screen.getByRole('button', { name: 'Şimdi eşitle' }) as HTMLButtonElement).disabled).toBe(false)
})
it('offers nothing to click where the desktop bridge is absent', () => {
delete (window as unknown as { hermesDesktop?: unknown }).hermesDesktop
renderPage()
expect(screen.getByText('Codex Bağlama yalnızca Windows masaüstü uygulamasında kullanılabilir.')).toBeTruthy()
expect(screen.queryByRole('switch')).toBeNull()
expect(get).not.toHaveBeenCalled()
})
})
@@ -0,0 +1,233 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { Button } from '@/components/ui/button'
import { Switch } from '@/components/ui/switch'
import { type CodexLinkCopy, useCodexLinkCopy } from '@/i18n/codex-link'
import { triggerHaptic } from '@/lib/haptics'
import { AlertTriangle, Check, CircleIcon, Link, RefreshCw } from '@/lib/icons'
import { cn } from '@/lib/utils'
import { notifyError } from '@/store/notifications'
import type { CodexLinkPatch, CodexLinkStatus } from '../../../electron/codex-link-types'
import { EmptyState, ListRow, ListRowSkeleton, SettingsContent, SettingsSection } from './primitives'
type Tone = 'muted' | 'ok' | 'warn'
interface StatusLine {
id: string
text: string
tone: Tone
}
/**
* What the user needs to know, top-down, stopping at the first fact that makes
* the rest moot (no Codex → nothing else to say; another bridge → ours is not
* involved; setup pending → the bridge cannot be running yet).
*/
export function codexLinkStatusLines(status: CodexLinkStatus, copy: CodexLinkCopy): StatusLine[] {
const lines: StatusLine[] = []
const error = status.lastError ? [{ id: 'error', text: copy.errors[status.lastError], tone: 'warn' as const }] : []
if (!status.codexFound) {
return [{ id: 'codex', text: copy.codexMissing, tone: 'muted' }, ...error]
}
lines.push({ id: 'codex', text: copy.codexFound, tone: 'ok' })
if (status.foreign) {
return [...lines, { id: 'foreign', text: copy.foreign, tone: 'warn' }, ...error]
}
if (!status.enabled) {
return [...lines, { id: 'off', text: copy.off, tone: 'muted' }, ...error]
}
if (!status.venvReady) {
return [...lines, { id: 'venv', text: copy.venvPending, tone: 'muted' }, ...error]
}
if (!status.bridgeRunning) {
return [...lines, { id: 'bridge', text: copy.bridgeStopped, tone: 'warn' }, ...error]
}
lines.push({ id: 'bridge', text: copy.bridgeRunning, tone: 'ok' })
if (status.ideDurum === 'anahtar-yok') {
lines.push({ id: 'ide', text: copy.signIn, tone: 'warn' })
} else if (status.ideDurum === 'tamam' && status.ideModel !== null) {
lines.push({ id: 'ide', text: copy.models(status.ideModel), tone: 'ok' })
}
return [...lines, ...error]
}
const TONE_ICON = { muted: CircleIcon, ok: Check, warn: AlertTriangle } as const
const TONE_CLASS: Record<Tone, string> = {
muted: 'text-(--ui-text-tertiary)',
ok: 'text-(--ui-text-secondary)',
warn: 'text-amber-500/90'
}
// Phone-sized hit area around the compact switch: the visible control keeps the
// design-system size, the label that wraps it is the 44px target.
const TOUCH_TARGET = 'flex min-h-11 min-w-11 cursor-pointer items-center @2xl:justify-end'
/**
* Settings → Codex Link. Main owns everything real (the preference file, the
* bridge, Codex's config, the login item); this page reads the state it reports
* and asks for changes, adopting whatever comes back as the truth.
*/
export function CodexLinkSettings() {
const copy = useCodexLinkCopy()
const bridge = typeof window === 'undefined' ? undefined : window.hermesDesktop?.codexLink
const [status, setStatus] = useState<CodexLinkStatus | null>(null)
const [loadFailed, setLoadFailed] = useState(false)
const [busy, setBusy] = useState<'sync' | 'toggle' | null>(null)
// A slow initial read must not overwrite the answer to a newer change.
const generation = useRef(0)
useEffect(() => {
if (!bridge) {
return
}
const ticket = generation.current
bridge.get().then(
next => {
if (generation.current === ticket) {
setStatus(next)
}
},
() => {
if (generation.current === ticket) {
setLoadFailed(true)
}
}
)
}, [bridge])
const change = useCallback(
async (patch: CodexLinkPatch, kind: 'sync' | 'toggle') => {
if (!bridge || busy) {
return
}
const before = status
generation.current += 1
setBusy(kind)
setLoadFailed(false)
// The switch moves at once; main's reply (or the rollback) has the last word.
if (typeof patch.enabled === 'boolean' && before) {
setStatus({ ...before, enabled: patch.enabled })
}
try {
setStatus(await bridge.set(patch))
} catch (error) {
setStatus(before)
notifyError(error, copy.saveFailed)
} finally {
setBusy(null)
}
},
[bridge, busy, copy.saveFailed, status]
)
if (!bridge) {
return (
<SettingsContent>
<EmptyState description={copy.unavailable} title={copy.title} />
</SettingsContent>
)
}
const lines = status ? codexLinkStatusLines(status, copy) : []
return (
<SettingsContent>
<SettingsSection icon={Link} title={copy.title}>
<ListRow
action={
<label className={TOUCH_TARGET}>
<Switch
aria-label={copy.title}
checked={status?.enabled ?? true}
disabled={!status || busy !== null}
onCheckedChange={enabled => {
triggerHaptic('selection')
void change({ enabled }, 'toggle')
}}
/>
</label>
}
description={copy.description}
title={copy.title}
/>
{!status && !loadFailed && <ListRowSkeleton wide />}
{loadFailed && !status && (
<p className="py-3 text-[length:var(--conversation-caption-font-size)] text-amber-500/90" role="alert">
{copy.loadFailed}
</p>
)}
{status && (
<ListRow
below={
<ul aria-live="polite" className="mt-1.5 grid gap-1.5">
{lines.map(line => {
const Icon = TONE_ICON[line.tone]
return (
<li
className={cn(
'flex min-w-0 items-start gap-2 text-[length:var(--conversation-caption-font-size)] leading-(--conversation-caption-line-height)',
TONE_CLASS[line.tone]
)}
data-tone={line.tone}
key={line.id}
>
<Icon aria-hidden className="mt-0.5 size-3.5 shrink-0" />
<span className="min-w-0 break-words">{line.text}</span>
</li>
)
})}
</ul>
}
title={copy.statusTitle}
wide
/>
)}
<ListRow
action={
<Button
className="min-h-11 w-full @2xl:w-auto"
disabled={!status || busy !== null}
onClick={() => {
triggerHaptic('open')
void change({ sync: true }, 'sync')
}}
type="button"
variant="secondary"
>
<RefreshCw />
{busy === 'sync' ? copy.syncing : copy.sync}
</Button>
}
description={copy.syncDesc}
title={copy.syncTitle}
/>
<p className="pt-2 text-[length:var(--conversation-caption-font-size)] leading-(--conversation-caption-line-height) text-(--ui-text-tertiary)">
{copy.restartNote}
</p>
</SettingsSection>
</SettingsContent>
)
}
+21 -1
View File
@@ -9,6 +9,7 @@ import { Tip } from '@/components/ui/tooltip'
import { getHermesConfigDefaults, getHermesConfigRecord, saveHermesConfig } from '@/hermes'
import { useI18n } from '@/i18n'
import { useAiturkCopy } from '@/i18n/aiturk'
import { useCodexLinkCopy } from '@/i18n/codex-link'
import { triggerHaptic } from '@/lib/haptics'
import {
Archive,
@@ -20,6 +21,7 @@ import {
Info,
Keyboard,
KeyRound,
Link,
Package,
RefreshCw,
Search,
@@ -46,6 +48,7 @@ import { SKILLS_ROUTE } from '../routes'
import { AboutSettings } from './about-settings'
import { AppearanceSettings } from './appearance-settings'
import { BillingSettings } from './billing'
import { CodexLinkSettings } from './codex-link-settings'
import { ConfigSettings } from './config-settings'
import { SECTIONS } from './constants'
import { GatewaySettings } from './gateway-settings'
@@ -68,6 +71,7 @@ const SETTINGS_VIEWS: readonly SettingsViewId[] = [
'keys',
'notifications',
'billing',
'codex-link',
'plugins',
'sessions',
'about'
@@ -76,6 +80,7 @@ const SETTINGS_VIEWS: readonly SettingsViewId[] = [
export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: SettingsPageProps) {
const { t } = useI18n()
const aiturkCopy = useAiturkCopy()
const codexLinkCopy = useCodexLinkCopy()
const navigate = useNavigate()
const { hash, pathname, search } = useLocation()
@@ -267,6 +272,19 @@ export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: Set
}
]
: []),
// "Codex Bağlama": present only where the desktop bridge offers it
// (Windows). A stale ?tab=codex-link elsewhere renders its own notice.
...(window.hermesDesktop?.codexLink
? [
{
active: activeView === 'codex-link',
icon: Link,
id: 'codex-link',
label: codexLinkCopy.nav,
onSelect: () => setActiveView('codex-link')
}
]
: []),
{
active: activeView === 'keybinds',
icon: Keyboard,
@@ -320,7 +338,7 @@ export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: Set
onSelect: () => setActiveView('about')
}
],
[activeView, keysView, providerView, t, aiturkCopy, setActiveView, openProviderView, openKeysView]
[activeView, keysView, providerView, t, aiturkCopy, codexLinkCopy, setActiveView, openProviderView, openKeysView]
)
// Type-to-search: printable keystrokes on the Settings surface (outside any
@@ -439,6 +457,8 @@ export function SettingsView({ onClose, onConfigSaved, onMainModelChanged }: Set
<BillingSettings />
) : activeView === 'plugins' ? (
<PluginsSettings />
) : activeView === 'codex-link' ? (
<CodexLinkSettings />
) : (
<SessionsSettings />
)
+1
View File
@@ -7,6 +7,7 @@ import type { EnvVarInfo } from '@/types/hermes'
export type SettingsView =
| 'about'
| 'billing'
| 'codex-link'
| 'connections'
| 'gateway'
| 'keybinds'
+8
View File
@@ -1,6 +1,7 @@
import type { GatewayWsUrlResult } from '@hermes/shared'
import type { TranslucencyState } from '@hermes/shared/translucency'
import type { CodexLinkPatch, CodexLinkStatus } from '../electron/codex-link-types'
import type { PoolLimits } from '../electron/pool-limits'
import type { WakeIndicatorState } from './lib/wake-indicator'
@@ -335,6 +336,13 @@ declare global {
aiturkMobile?: {
open: () => Promise<{ ok: true }>
}
/** "Codex Bağlama" (electron/codex-link.ts): lets the Codex on this machine
* use the IDE's models. `get` only reads; `set` applies and returns the
* state that actually resulted. Windows only. */
codexLink?: {
get: () => Promise<CodexLinkStatus>
set: (patch: CodexLinkPatch) => Promise<CodexLinkStatus>
}
/** One-shot loopback callback listener for MCP OAuth against remote
* backends (electron/mcp-oauth-callback-ipc.ts): bind on THIS machine,
* pass redirectUri as client_redirect_uri to mcp.servers.oauth.start,
+80
View File
@@ -0,0 +1,80 @@
import type { CodexLinkError } from '../../electron/codex-link-types'
import { useI18n } from './context'
// Copy for Settings → Codex Link ("Codex Bağlama"). Kept beside the other
// AITURK-distribution strings (see ./aiturk): Turkish for `tr`, English for
// every other locale.
const en = {
nav: 'Codex Link',
title: 'Codex Link',
description:
'Adds the models and combos from AITURK IDE to the Codex on this computer and keeps the conversation context when you switch between models.',
unavailable: 'Codex Link is only available in the Windows desktop app.',
loadFailed: 'Could not read the Codex Link status.',
saveFailed: 'Could not change Codex Link.',
statusTitle: 'Status',
off: 'Codex Link is off. Codex runs with its own settings.',
codexFound: 'Codex was found on this computer.',
codexMissing: 'Codex was not found on this computer.',
foreign: 'Codex on this computer uses another bridge; its settings were not touched.',
venvPending: 'It will turn on once the IDE setup is complete.',
bridgeRunning: 'The bridge is running.',
bridgeStopped: 'The bridge is not running.',
models: (count: number) => (count === 1 ? '1 model added to Codex.' : `${count} models added to Codex.`),
signIn: 'No IDE session was found; sign in.',
errors: {
'autostart-failed': 'Could not set the bridge to start with Windows.',
'bridge-config-failed': 'Could not write the bridge settings.',
'bridge-missing': 'The bridge files are missing from this installation.',
'bridge-start-failed': 'The bridge could not be started; the Codex settings were left unchanged.',
'config-write-failed': 'Could not write the Codex settings file.',
'settings-write-failed': 'Could not save this setting.'
} satisfies Record<CodexLinkError, string>,
syncTitle: 'Sync now',
syncDesc: 'Checks the bridge and the Codex settings again.',
sync: 'Sync now',
syncing: 'Syncing…',
restartNote: 'Reopen Codex to see new models there.'
}
const tr: typeof en = {
nav: 'Codex Bağlama',
title: 'Codex Bağlama',
description:
"AITURK IDE'deki modelleri ve comboları bu bilgisayardaki Codex'e ekler; modeller arasında geçerken sohbet bağlamını korur.",
unavailable: 'Codex Bağlama yalnızca Windows masaüstü uygulamasında kullanılabilir.',
loadFailed: 'Codex Bağlama durumu okunamadı.',
saveFailed: 'Codex Bağlama değiştirilemedi.',
statusTitle: 'Durum',
off: 'Codex Bağlama kapalı. Codex kendi ayarlarıyla çalışıyor.',
codexFound: 'Bu bilgisayarda Codex bulundu.',
codexMissing: 'Bu bilgisayarda Codex bulunamadı.',
foreign: 'Bu bilgisayarda Codex başka bir köprü kullanıyor; ayarına dokunulmadı.',
venvPending: 'IDE kurulumu tamamlanınca etkinleşecek.',
bridgeRunning: 'Köprü çalışıyor.',
bridgeStopped: 'Köprü çalışmıyor.',
models: (count: number) => `Codex'e ${count} model eklendi.`,
signIn: 'IDE oturumu bulunamadı, giriş yapın.',
errors: {
'autostart-failed': 'Köprü Windows açılışında başlayacak şekilde ayarlanamadı.',
'bridge-config-failed': 'Köprü ayarları yazılamadı.',
'bridge-missing': 'Köprü dosyaları bu kurulumda bulunamadı.',
'bridge-start-failed': 'Köprü başlatılamadı; Codex ayarına dokunulmadı.',
'config-write-failed': 'Codex ayar dosyası yazılamadı.',
'settings-write-failed': 'Bu ayar kaydedilemedi.'
},
syncTitle: 'Şimdi eşitle',
syncDesc: 'Köprüyü ve Codex ayarını yeniden denetler.',
sync: 'Şimdi eşitle',
syncing: 'Eşitleniyor…',
restartNote: "Codex'te yeni modelleri görmek için Codex'i yeniden açın."
}
export type CodexLinkCopy = typeof en
export function useCodexLinkCopy(): CodexLinkCopy {
const { locale } = useI18n()
return locale === 'tr' ? tr : en
}