The best way to control Claude Code, Codex and more from any computer or phone

main
ts 137 lines 4.49 KB
Raw
1 import { describe, expect, it } from "@effect/vitest";
2
3 import { ProviderInstanceId, type ModelSelection } from "@t3tools/contracts";
4
5 import { compileClaudeModelSelection } from "./claudeModelOptions.ts";
6 import {
7 BUNDLED_CLAUDE_MODEL_CATALOG,
8 scopeClaudeModelCatalog,
9 } from "./provider/ClaudeModelCatalog.ts";
10
11 const selection = (
12 model: string,
13 options: NonNullable<ModelSelection["options"]>,
14 ): ModelSelection => ({
15 instanceId: ProviderInstanceId.make("claude_test"),
16 model,
17 options,
18 });
19
20 describe("compileClaudeModelSelection", () => {
21 it("compiles context, effort, and settings together", () => {
22 expect(
23 compileClaudeModelSelection(
24 selection("claude-opus-4-6", [
25 { id: "contextWindow", value: "1m" },
26 { id: "effort", value: "max" },
27 { id: "fastMode", value: true },
28 ]),
29 ),
30 ).toMatchObject({
31 apiModelId: "claude-opus-4-6[1m]",
32 effort: "max",
33 settings: { fastMode: true },
34 });
35 });
36
37 it("runs Ultracode at the chosen effort and reads the old Ultracode effort as xhigh", () => {
38 expect(
39 compileClaudeModelSelection(
40 selection("claude-opus-5-5", [
41 { id: "effort", value: "high" },
42 { id: "ultracode", value: true },
43 ]),
44 ),
45 ).toMatchObject({ effort: "high", settings: { ultracode: true } });
46 expect(
47 compileClaudeModelSelection(
48 selection("claude-opus-5-5", [{ id: "effort", value: "ultracode" }]),
49 ),
50 ).toMatchObject({ effort: "xhigh", settings: { ultracode: true } });
51 const legacyTurnedOff = compileClaudeModelSelection(
52 selection("claude-opus-5-5", [
53 { id: "effort", value: "ultracode" },
54 { id: "ultracode", value: false },
55 ]),
56 );
57 expect(legacyTurnedOff.effort).toBe("xhigh");
58 expect(legacyTurnedOff.settings.ultracode).toBe(false);
59 expect(
60 compileClaudeModelSelection(selection("claude-opus-5-5", [{ id: "effort", value: "high" }]))
61 .settings,
62 ).not.toHaveProperty("ultracode");
63 });
64
65 it("keeps old Ultracode defaults and selections at Extra High on custom models", () => {
66 const customModel = (slug: string, choices: ReadonlyArray<string>) => ({
67 slug,
68 name: slug,
69 capabilities: {
70 optionDescriptors: [
71 {
72 id: "effort",
73 label: "Reasoning",
74 type: "select" as const,
75 currentValue: "ultracode",
76 options: choices.map((id) => ({ id, label: id, isDefault: id === "ultracode" })),
77 },
78 ],
79 },
80 });
81 const catalog = scopeClaudeModelCatalog(BUNDLED_CLAUDE_MODEL_CATALOG, [
82 customModel("claude-custom-tuned", ["high", "xhigh", "ultracode"]),
83 customModel("claude-custom-no-xhigh", ["high", "ultracode"]),
84 ]);
85
86 for (const model of ["claude-custom-tuned", "claude-custom-no-xhigh"]) {
87 expect(compileClaudeModelSelection(selection(model, []), catalog)).toMatchObject({
88 effort: "xhigh",
89 settings: { ultracode: true },
90 });
91 expect(
92 compileClaudeModelSelection(
93 selection(model, [{ id: "effort", value: "ultracode" }]),
94 catalog,
95 ),
96 ).toMatchObject({ effort: "xhigh", settings: { ultracode: true } });
97 }
98 });
99
100 it("uses the model default SDK effort alongside prompt-injected effort", () => {
101 expect(
102 compileClaudeModelSelection(
103 selection("claude-sonnet-4-6", [{ id: "effort", value: "ultrathink" }]),
104 ),
105 ).toMatchObject({ effort: "high", promptEffort: "ultrathink" });
106 });
107
108 it("ignores thinking for catalog models without a thinking option", () => {
109 expect(
110 compileClaudeModelSelection(selection("claude-opus-5-5", [{ id: "thinking", value: false }]))
111 .settings,
112 ).not.toHaveProperty("alwaysThinkingEnabled");
113 });
114
115 it.each(["gateway-route", "gateway-route[1m]"])(
116 "keeps explicit effort and thinking for %s outside the local catalog",
117 (model) => {
118 for (const thinking of [true, false]) {
119 expect(
120 compileClaudeModelSelection(
121 selection(model, [
122 { id: "effort", value: "max" },
123 { id: "thinking", value: thinking },
124 ]),
125 ),
126 ).toMatchObject({
127 apiModelId: model,
128 effort: "max",
129 settings: { alwaysThinkingEnabled: thinking },
130 });
131 }
132 const unconfigured = compileClaudeModelSelection(selection(model, []));
133 expect(unconfigured.effort).toBeUndefined();
134 expect(unconfigured.settings).toEqual({});
135 },
136 );
137 });