Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.
Rust ai-agentsai-gatewayclaude-codecodexcoding-agentcost-optimizationdeepseekllm-gatewayllm-routerlocal-firstmodel-routingrusttask-routingtauri
import assert from 'node:assert/strict';
import test from 'node:test';
import { projectHomeAgents } from '../src/product/home-projections.ts';
import { deriveHomePrimaryMode } from '../src/features/home/state.ts';
test('a collaboration-only connection does not invent a missing model setup or count as configured before enable', () => {
const agent = {
agent_id: 'agent_qoder_default', context_id: 'context/native', configuration_state: 'configured',
settings: { schema: 'hiroute.agent-collaboration-only-settings-status/v2', context_id: 'context/native',
collaboration: { state: 'not_configured', restore_point_ref: null } },
};
const project = value => projectHomeAgents({ agents: [value] });
const projected = project(agent);
assert.equal(projected.agents[0].model, 'unsupported');
assert.equal(projected.agents[0].collaboration, 'unconfigured');
assert.equal(project({ ...agent, agent_id: 'another-collaboration-only-agent' }).agents[0].model, 'unsupported');
assert.equal(project({ ...agent, settings: null }).agents[0].model, 'unknown');
const reads = {
compute: { status: 'ready', data: { sources: [], saveAttempts: [] } },
plans: { status: 'ready', data: { plans: [], drafts: [] } },
agents: { status: 'ready', data: projected },
activity: { status: 'ready', data: { sessions: [], tasks: [] } },
};
assert.equal(deriveHomePrimaryMode(reads), 'first-use');
agent.settings.collaboration = { state: 'configured', restore_point_ref: 'restore/skill', current_selection: { trigger_mode: 'explicit' } };
reads.agents.data = project(agent);
assert.equal(reads.agents.data.agents[0].model, 'unsupported');
assert.equal(reads.agents.data.agents[0].collaboration, 'configured');
assert.equal(deriveHomePrimaryMode(reads), 'partial');
});
test('Agent presentation follows configuration and recovery rather than model verification', () => {
const agent = { agent_id: 'agent_qoder_default', context_id: 'context/native', configuration_state: 'configured',
settings: { state: 'not_configured', model_verified: false,
collaboration: { state: 'configured', restore_point_ref: 'restore/skill' } } };
const project = () => projectHomeAgents({ agents: [agent] }).agents[0];
assert.equal(project().model, 'unconfigured');
assert.equal(project().collaboration, 'configured');
agent.settings.state = 'configured';
assert.equal(project().model, 'configured');
agent.settings.model_verified = true;
assert.equal(project().model, 'configured');
agent.settings.state = 'drift';
assert.equal(project().model, 'degraded');
agent.settings.state = 'pending';
assert.equal(project().model, 'pending');
});
import { agentModelPlanIds } from '../src/features/agents/status.ts';
test('plan usage covers every typed model selection and excludes restored connections', () => {
for (const mode of ['qoder_additional', 'pi_additional', 'dsh_additional', 'opencode_additional']) {
assert.deepEqual(agentModelPlanIds({ mode, allowed_plan_ids: ['plan/free', 'plan/free'] }), ['plan/free']);
}
assert.deepEqual(agentModelPlanIds({ mode: 'codex_default', allowed_plan_ids: ['plan/free'], default_selection: { kind: 'plan', plan_id: 'plan/default' } }), ['plan/free', 'plan/default']);
assert.deepEqual(agentModelPlanIds({ mode: 'claude_launcher', preset_mappings: { opus: { kind: 'plan', plan_id: 'plan/free' }, sonnet: { kind: 'plan', plan_id: 'plan/free' }, haiku: { kind: 'preserve_native' } } }), ['plan/free']);
assert.deepEqual(agentModelPlanIds(null), []);
assert.deepEqual(agentModelPlanIds(undefined), []);
});