Preserve native Codex history and add configurable cross-model compression
Server CI and Windows package / verify (push) Successful in 4m47s
Server CI and Windows package / windows-package (push) Successful in 8m47s

Separate encrypted reasoning from actual compaction, stop migration after native return, and retain full history and recent exchanges. Add typed settings, Gemini fallback, verified provider windows, bounded summaries and durable concurrent checkpoints.

Validation: 245 bridge tests plus focused concurrency tests; 71 settings/connection tests; 66 supplementary tests; TypeScript checks; renderer and Electron bundles; real primary/native/fallback summary probes and 700K input acceptance.
This commit is contained in:
yilsem committed 2026-10-13 03:36:42 +03:00
1 parent 1c6e3656b8
commit 91ecad8e5c
27 files changed
+1119 -117

No files matched your search

@@ -0,0 +1,21 @@
export interface CompressionSettings {
schemaVersion: 1
primaryModel: string
fallbackModel: string
currentModelFallback: boolean
level: 'mini' | 'az' | 'orta' | 'fazla' | 'cok-fazla'
keepTurns: number
budgetMode: 'percent' | 'tokens'
transferPercent: number
maxTokens: number
autoEnabled: boolean
triggerPercent: number
targetPercent: number
timeoutSeconds: number
}
export interface CompressionState {
settings: CompressionSettings
models: { id: string; name: string; window: number; source: string }[]
modelsAvailable: boolean
}
@@ -0,0 +1,31 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { afterEach, expect, it } from 'vitest'
import { createCompressionStore } from './compression-settings'
const dirs: string[] = []
afterEach(() => { for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true }) })
it('persists complete settings and survives reopening', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'compression-store-'))
dirs.push(dir)
const store = createCompressionStore(dir)
const settings = { ...store.get(), keepTurns: 12, primaryModel: 'ide/primary', fallbackModel: 'ide/backup' }
store.save(settings)
expect(createCompressionStore(dir).get()).toEqual(settings)
expect(fs.readdirSync(dir)).toEqual(['compression-settings.json'])
})
it('rejects invalid thresholds without replacing saved settings', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'compression-store-'))
dirs.push(dir)
const store = createCompressionStore(dir)
const original = store.save(store.get())
for (const patch of [{ keepTurns: 0 }, { targetPercent: 70 }, { maxTokens: NaN }, { autoEnabled: 'yes' }]) {
expect(() => store.save({ ...original, ...patch })).toThrow()
expect(store.get()).toEqual(original)
}
})
@@ -0,0 +1,48 @@
import fs from 'node:fs'
import path from 'node:path'
import defaults from '../assets/codex-bridge/compression-defaults.json'
import type { CompressionSettings } from './compression-settings-types'
export function validateCompression(value: unknown): CompressionSettings {
if (!value || typeof value !== 'object') throw new Error('Invalid compression settings')
const v = value as CompressionSettings
if (Object.keys(v).sort().join() !== Object.keys(defaults).sort().join()) throw new Error('Invalid settings fields')
if (v.schemaVersion !== 1 || !['mini', 'az', 'orta', 'fazla', 'cok-fazla'].includes(v.level) || !['percent', 'tokens'].includes(v.budgetMode)) throw new Error('Invalid compression mode')
for (const key of ['primaryModel', 'fallbackModel'] as const) {
if (typeof v[key] !== 'string' || v[key].length > 256) throw new Error('Invalid model')
}
for (const key of ['autoEnabled', 'currentModelFallback'] as const) {
if (typeof v[key] !== 'boolean') throw new Error('Invalid option')
}
const limits: [keyof CompressionSettings, number, number][] = [
['keepTurns', 1, 100], ['transferPercent', 10, 90], ['triggerPercent', 20, 90],
['targetPercent', 10, 80], ['maxTokens', 1024, 2000000], ['timeoutSeconds', 1, 3600]
]
for (const [key, low, high] of limits) {
const n = v[key]
if (typeof n !== 'number' || !Number.isInteger(n) || n < low || n > high) throw new Error(`Invalid ${key}`)
}
if (v.targetPercent >= v.triggerPercent) throw new Error('Target must be below trigger')
return structuredClone(v)
}
export function createCompressionStore(directory: string) {
const file = path.join(directory, 'compression-settings.json')
return {
get: (): CompressionSettings => validateCompression(fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : defaults),
save(value: unknown): CompressionSettings {
const next = validateCompression(value)
fs.mkdirSync(directory, { recursive: true })
const tmp = `${file}.${process.pid}.tmp`
try {
fs.writeFileSync(tmp, JSON.stringify(next, null, 2), { mode: 0o600 })
fs.renameSync(tmp, file)
} finally {
if (fs.existsSync(tmp)) fs.unlinkSync(tmp)
}
return next
}
}
}
+26
View File
@@ -379,6 +379,7 @@ import { createBootstrapCoordinator, sshConfigFingerprint } from './ssh-bootstra
import { collectSshConfigHosts, parseSshGOutput } from './ssh-config'
import { createSshProbeConnection, pickLocalPort, redactSecrets, SshConnection } from './ssh-connection'
import { createStagedTransitionStore } from './staged-transition'
import { createCompressionStore } from './compression-settings'
import { createStreamThrottle } from './stream-throttle'
import { registerTerminalIpc } from './terminal-ipc'
import { nativeOverlayWidth as computeNativeOverlayWidth, macTitleBarOverlayHeight } from './titlebar-overlay-width'
@@ -17193,6 +17194,7 @@ ipcMain.handle('hermes:quick-entry:settings:set', async (_event, patch) => {
// resulting state and asks for changes over IPC. Windows only (the login item is
// a Run-key value). All decisions live in electron/codex-link.ts.
const AITURK_IDE_DATA_ROOT = path.dirname(HERMES_HOME)
const compressionStore = createCompressionStore(path.join(AITURK_IDE_DATA_ROOT, 'codex-bridge'))
const stagedTransition = createStagedTransitionStore(
path.join(AITURK_IDE_DATA_ROOT, 'codex-bridge'),
path.join(app.getPath('home'), '.typesafe', 'typesafe.env'),
@@ -17281,6 +17283,30 @@ ipcMain.handle('aiturk:staged-transition:get', async event => {
return stagedTransitionState()
})
async function compressionState() {
const settings = compressionStore.get()
try {
const response = await fetch('http://127.0.0.1:8795/aiturk/codex-baglama/status', { signal: AbortSignal.timeout(5000) })
if (!response.ok) throw new Error('Bridge unavailable')
const body = await response.json()
const available = Array.isArray(body.compression_models)
return { settings, models: available ? body.compression_models : [], modelsAvailable: available }
} catch {
return { settings, models: [], modelsAvailable: false }
}
}
ipcMain.handle('aiturk:compression:get', async event => {
assertCodexLinkSender(event)
return compressionState()
})
ipcMain.handle('aiturk:compression:set', async (event, settings) => {
assertCodexLinkSender(event)
compressionStore.save(settings)
return compressionState()
})
ipcMain.handle('aiturk:staged-transition:set', async (event, patch) => {
assertCodexLinkSender(event)
stagedTransition.save(patch)
+3 -2
View File
@@ -103,11 +103,12 @@ it.skipIf(!process.env.AITURK_TEST_BACKEND_PORT)(
).toBe(200)
expect((await call(`${route}/resume?profile=default`, 'POST')).status).toBe(200)
await new Promise<void>((resolve, reject) => {
const ws = new WebSocket(`wss://127.0.0.1:${proxyPort}/api/ws?profile=default`, {
const tlsOptions: https.RequestOptions = {
ca: identity.cert,
checkServerIdentity,
headers: { Authorization: `Bearer ${deviceToken}` }
})
}
const ws = new WebSocket(`wss://127.0.0.1:${proxyPort}/api/ws?profile=default`, tlsOptions)
const timer = setTimeout(() => {
ws.terminate()
reject(new Error('Chat ping timed out'))
+2
View File
@@ -295,6 +295,8 @@ contextBridge.exposeInMainWorld('hermesDesktop', {
...(process.platform === 'win32'
? {
codexLink: {
getCompression: () => ipcRenderer.invoke('aiturk:compression:get'),
setCompression: settings => ipcRenderer.invoke('aiturk:compression:set', settings),
getStagedTransition: () => ipcRenderer.invoke('aiturk:staged-transition:get'),
setStagedTransition: patch => ipcRenderer.invoke('aiturk:staged-transition:set', patch),
get: () => ipcRenderer.invoke('aiturk:codex-link:get'),