Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(codex): 验证跨供应商与逐线程预算的原生压缩
Dash025d1a0ab467
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.tsindex 2cd773374e..f0c95b30ea 100644--- a/apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts@@ -15,11 +15,16 @@ import { nativeCodexFallbackModel, prepareCodexCustomContextCatalog } from '../cconst binary = process.env.CINDY_CODEX_TEST_BINARY;const logger: Logger = { trace() {}, debug() {}, info() {}, warn() {}, error() {}, fatal() {}, child: () => logger };-it.skipIf(!binary)('cold-resumes the same history, compacts with the larger model, then sends to the smaller model', async () => {+// Different-provider catalogs cannot assume the old model is available. SSH uses+// thread config instead of a local catalog. Neither removes native pre-turn+// compaction with the target model; verify the real requests, not only RPC config.+it.skipIf(!binary).each(['same-provider', 'different-provider', 'thread-budget'] as const)(+ 'cold-resumes and natively compacts before continuing (%s)', async mode => {const root = await fs.mkdtemp(path.join(os.tmpdir(), 'cindy-context-switch-native-'));const home = path.join(root, 'home');const work = path.join(root, 'work');- const windows: Record<string, number> = { 'codex/fixture-wide': 500_000, 'fixture-small': 272_000 };+ const oldModel = mode === 'thread-budget' ? 'fixture-wide' : 'codex/fixture-wide';+ const windows: Record<string, number> = { [oldModel]: 500_000, 'fixture-small': 272_000 };const requests: Array<{ model: string; input: unknown[] }> = [];const server = createServer(async (req, res) => {if (req.method !== 'POST') { res.end('{"models":[]}'); return; }@@ -44,9 +49,12 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger modeawait fs.mkdir(home); await fs.mkdir(work);await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));await fs.writeFile(path.join(home, 'models_cache.json'), JSON.stringify({ models: Object.keys(windows)- .map(slug => nativeCodexFallbackModel(slug.replace(/^codex\//, ''), 'You are a test assistant.')) }));+ .map(slug => ({ ...nativeCodexFallbackModel(slug.replace(/^codex\//, ''), 'You are a test assistant.'),+ max_context_window: 1_000_000 })) }));await fs.writeFile(path.join(home, 'config.toml'), ['model_provider="fixture"', 'cli_auth_credentials_store="ephemeral"',+ // Custom API providers do not necessarily consult the discovery cache.+ 'model_catalog_json="models_cache.json"','check_for_update_on_startup=false', '[analytics]', 'enabled=false','[model_providers.fixture]', 'name="Fixture"',`base_url="http://127.0.0.1:${(server.address() as AddressInfo).port}"`,@@ -55,13 +63,18 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger mode].join('\n'));const makeAgent = () => new CodexAgent({binaryPath: binary!, logger, runtimeConfig: {}, resolveCodexLocalAuthPolicy: () => 'isolated',- resolveCodexThreadContextWindow: (_provider, model) => windows[model] ?? null,+ resolveCodexThreadContextWindow: mode === 'thread-budget' ? undefined : (_provider, model) => windows[model] ?? null,+ resolveModelContextLimit: mode === 'thread-budget' ? (_provider, model) => windows[model] ?? null : undefined,prepareCodexExtraSpawnConfig: async (_providers, ctx) => {- expect(ctx.customContextProviderId).toBe('cprov-fixture');+ if (mode === 'thread-budget') {+ expect(ctx.customContextModel).toBeUndefined();+ return { extraArgs: [], extraEnv: {}, codexProxyActive: true };+ }+ const targetProvider = ctx.customContextProviderId === 'cprov-other';const catalog = await prepareCodexCustomContextCatalog({ binaryPath: binary!, codexHome: home,modelId: ctx.customContextModel!, contextWindow: ctx.customContextWindow!,- modelIds: Object.keys(windows),- resolveContextWindow: model => windows[model] ?? null });+ modelIds: targetProvider ? ['fixture-small'] : Object.keys(windows),+ resolveContextWindow: model => targetProvider ? null : windows[model] ?? null });return { extraArgs: catalog.extraArgs, extraEnv: {}, codexProxyActive: true };},auth: {@@ -75,7 +88,7 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger mode});agent = makeAgent();const options = { sessionId: 'context-switch', providerId: 'cprov-fixture', workingDir: work, makerMemoryEnabled: false };- let handle = await agent.startSession({ ...options, model: 'codex/fixture-wide' });+ let handle = await agent.startSession({ ...options, model: oldModel });const send = async (text: string) => {const finished = (async () => {for await (const event of handle.events()) {@@ -93,10 +106,13 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger modeexpect(handle.getUsageSnapshot().contextWindow).toBe(475_000);await handle.close(); await agent.dispose();agent = makeAgent();- handle = await agent.startSession({ ...options, model: 'fixture-small', resumeSessionId: threadId });+ handle = await agent.startSession({ ...options,+ ...(mode === 'different-provider' ? { providerId: 'cprov-other' } : {}),+ model: 'fixture-small', resumeSessionId: threadId });expect(handle.id).toBe(threadId);await send('CONTINUE_MARKER');- expect(requests.map(request => request.model)).toEqual(['codex/fixture-wide', 'codex/fixture-wide', 'fixture-small']);+ expect(requests.map(request => request.model)).toEqual([oldModel,+ mode === 'same-provider' ? oldModel : 'fixture-small', 'fixture-small']);expect(JSON.stringify(requests[1]!.input)).toContain('ORIGINAL_HISTORY_MARKER');expect(JSON.stringify(requests[1]!.input)).toContain('FIRST_REPLY');expect(JSON.stringify(requests[2]!.input)).toContain('NATIVE_SUMMARY');diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.mdindex 48728a8099..dbe0bdccbc 100644--- a/docs/dev-rules/maker-core-and-agent-behavior.md+++ b/docs/dev-rules/maker-core-and-agent-behavior.md@@ -159,10 +159,15 @@ Claude Code/Pi 的强制换窗线`danger`/`overflow` 的本机会话先走同一套 `context_rebuild` bounded handoff,再落目标route,不能 resume 旧原生窗口。Codex 同引擎切模(包括自动任务、Orca、设备互联与 SSH)保留原生历史,由 Codex 自己判断并执行-压缩;本地冷恢复时可先用旧的大窗口模型压缩,再执行目标模型。不得仅因目标窗口较小、占用到+压缩;本地同供应商冷恢复时可先用旧的大窗口模型压缩,再执行目标模型。跨供应商不假定目标凭证+能调用旧模型;旧模型预算不可用时,原生仍按目标预算在采样前压缩。SSH 的逐 thread 预算也保留+这条目标模型原生压缩路径,不能因无法使用旧模型而提前拒绝切模。不得仅因目标窗口较小、占用到90%/100% 或伙伴账本新鲜而抢先生成 Cindy 交接。窗口预算与用户 override 保持不变;重载模型目录或凭证执行句柄不等于重建历史。Cindy 只在明确的上下文超限、原生压缩失败或历史字节超限后沿用既有兜底及副作用保护。跨引擎交接、显式重启和伙伴空闲间隔刷新仍按各自生命周期规则处理。+真实 CLI 的同供应商、跨供应商与逐 thread 预算回归见+`apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts`;逐 thread 回归在本机+模拟服务运行,不代表完成了真实 SSH 端到端验收。Codex 跨凭证优先保留同一个原生线程;仅当目标需要另一个 host、旧 host 仍持有原生 writer时,关闭该任务的业务 handle 后使用不剥离历史的原生 fork,并等待一次性 fork host 退出,再以任务 owner 与旧 SDK/路由版本为条件原子保存新 SDK thread 和目标路由。任务 ID 与diff --git a/docs/dev-rules/model-catalog-runtime.md b/docs/dev-rules/model-catalog-runtime.mdindex 00f20303be..a32dbed02f 100644--- a/docs/dev-rules/model-catalog-runtime.md+++ b/docs/dev-rules/model-catalog-runtime.md@@ -36,6 +36,10 @@ thread 配置,同时设置窗口和 90% 自动压缩预算,保留原生 5%否则 Codex 在恢复后的缩窗检查中看不到旧窗口大于新窗口,无法先用旧模型压缩。同一 live 模型临时改变显式预算仍沿用 thread 冷恢复配置,切模型重载目录时撤掉这个覆盖。SSH 共享 daemon 保留既有逐 thread 配置,不能传入本机目录路径;原生决定压缩方式。+缺少旧路由预算只影响先用旧模型压缩的优化,不会关闭原生按目标预算触发的采样前压缩。+跨供应商同样不把旧来源的型号和预算搬到目标来源;不能保证目标凭证可以调用旧模型。+这些路径先让原生尝试目标模型压缩,明确失败后才走既有 Cindy 兜底;真实 CLI 回归见+`apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts`。显式设置可以超过原生目录默认最大值;它改变 CLI 预算,不改变供应商实际能接受的长度。已运行任务在当前轮结束后重建执行句柄、保留原生历史;恢复默认删除 override。保存后的运行时刷新失败时,仅恢复本次修改的原账号 override(保留各引擎原值和缺席状态,