@exla/rudder 5.0.10 → 5.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/cloud/package.json +7 -1
  2. package/dist/backends.js +22 -10
  3. package/dist/backends.js.map +1 -1
  4. package/dist/board/board.js +4 -4
  5. package/dist/board/daemon.js +19 -2
  6. package/dist/board/daemon.js.map +1 -1
  7. package/dist/cloud.js +31 -15
  8. package/dist/cloud.js.map +1 -1
  9. package/dist/effort.js +1 -5
  10. package/dist/effort.js.map +1 -1
  11. package/dist/jj.d.ts +2 -1
  12. package/dist/jj.js +4 -8
  13. package/dist/jj.js.map +1 -1
  14. package/dist/main.js +7 -6
  15. package/dist/main.js.map +1 -1
  16. package/dist/models.d.ts +60 -8
  17. package/dist/models.js +303 -173
  18. package/dist/models.js.map +1 -1
  19. package/dist/native/darwin-arm64/native-manifest.json +3 -3
  20. package/dist/native/darwin-arm64/rudder-native +0 -0
  21. package/dist/native/linux-x64/native-manifest.json +5 -5
  22. package/dist/native/linux-x64/rudder-jj +0 -0
  23. package/dist/native/linux-x64/rudder-native +0 -0
  24. package/dist/native-agents.js +19 -8
  25. package/dist/native-agents.js.map +1 -1
  26. package/dist/opencode.d.ts +13 -0
  27. package/dist/opencode.js +25 -0
  28. package/dist/opencode.js.map +1 -0
  29. package/dist/project-files/agent-notes.d.ts +40 -0
  30. package/dist/project-files/agent-notes.js +112 -0
  31. package/dist/project-files/agent-notes.js.map +1 -0
  32. package/dist/project-files/file-refs.d.ts +51 -0
  33. package/dist/project-files/file-refs.js +230 -0
  34. package/dist/project-files/file-refs.js.map +1 -0
  35. package/dist/project-files/home.d.ts +5 -1
  36. package/dist/project-files/home.js +27 -16
  37. package/dist/project-files/home.js.map +1 -1
  38. package/dist/project-files/service.d.ts +5 -1
  39. package/dist/project-files/service.js +3 -3
  40. package/dist/project-files/service.js.map +1 -1
  41. package/dist/run-manager.js +13 -5
  42. package/dist/run-manager.js.map +1 -1
  43. package/dist/util.d.ts +4 -0
  44. package/dist/util.js +35 -0
  45. package/dist/util.js.map +1 -1
  46. package/dist/warm-snapshot.d.ts +8 -0
  47. package/dist/warm-snapshot.js +27 -6
  48. package/dist/warm-snapshot.js.map +1 -1
  49. package/package.json +1 -1
  50. package/dist/project-files/notes.d.ts +0 -64
  51. package/dist/project-files/notes.js +0 -212
  52. package/dist/project-files/notes.js.map +0 -1
package/dist/models.js CHANGED
@@ -1,4 +1,4 @@
1
- import { spawn } from "node:child_process";
1
+ import { execFile, spawn } from "node:child_process";
2
2
  import fsp from "node:fs/promises";
3
3
  import fs from "node:fs";
4
4
  import os from "node:os";
@@ -11,22 +11,23 @@ const ANTHROPIC_MODELS_URL = "https://api.anthropic.com/v1/models?limit=100";
11
11
  const ANTHROPIC_VERSION = "2023-06-01";
12
12
  const MODELS_DEV_CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
13
13
  const FETCH_TIMEOUT_MS = 2500;
14
- const MODEL_PICKER_LIMIT = 24;
15
14
  let modelCatalogInFlight;
16
- export async function discoverModelOptions(backend, configuredDefault) {
17
- const defaultDetail = configuredDefault || "CLI default";
18
- const picker = backend === "claude" ? "claude" : "codex";
19
- // The catalog (models.dev, the provider APIs, local history, Claude Code's
20
- // list) and the CLI's own list: Claude Code's /model list or Codex's model
21
- // cache. The CLI's list names a model, its effort levels and its display
22
- // name as soon as the CLI learns it.
23
- const [{ data, claudeCode }, codex] = await Promise.all([
24
- readModelsDev(),
25
- picker === "claude" ? [] : readCodexCliModels(),
26
- ]);
27
- const cli = picker === "claude" ? claudeCode : codex;
28
- const catalog = (picker === "claude" ? data.anthropic : data.openai)?.models ?? {};
29
- return [{ label: "Default", value: undefined, detail: defaultDetail }, ...pickerRows(picker, catalog, cli)];
15
+ /**
16
+ * Every harness's models, one section per HARNESSES row, in its order. A
17
+ * section lists exactly what the harness's CLI lists for this account, with
18
+ * the CLI's names and effort levels; the merged catalog (models.dev, the
19
+ * provider APIs, local history, Claude Code's list) adds detail lines and
20
+ * prices. Reading it also refreshes the catalog the dashboard reads.
21
+ */
22
+ export async function discoverHarnesses() {
23
+ const catalog = await readModelsDev();
24
+ return Promise.all(HARNESSES.map(async (harness) => ({
25
+ id: harness.id,
26
+ label: harness.label,
27
+ account: harness.account,
28
+ models: pickerRows(harness, (harness.catalog && catalog.data[harness.catalog]?.models) || {}, await harness.listed(catalog)),
29
+ default: await harness.defaultModel(catalog),
30
+ })));
30
31
  }
31
32
  /** Refreshes the models.dev catalog the dashboard's own picker reads. */
32
33
  export async function refreshModelCatalog() {
@@ -51,12 +52,27 @@ async function readCodexCacheModels() {
51
52
  return (parsed.models ?? [])
52
53
  .filter((model) => model.slug && model.slug !== "codex-auto-review" && model.visibility !== "hide");
53
54
  }
54
- async function discoverCodexModelsLocal() {
55
- return (await readCodexCacheModels()).map((model) => ({
56
- label: model.slug || model.display_name || "model",
57
- value: model.slug,
58
- detail: model.display_name || model.description || "local Codex cache",
59
- }));
55
+ /**
56
+ * The model Codex runs when it is given none: the top-level `model` in its
57
+ * config.toml, or null when the file sets none.
58
+ */
59
+ async function readCodexConfiguredModel() {
60
+ const file = path.join(process.env.CODEX_HOME || path.join(os.homedir(), ".codex"), "config.toml");
61
+ const raw = await fsp.readFile(file, "utf8").catch(ignoreMissing);
62
+ if (!raw) {
63
+ return null;
64
+ }
65
+ // Top-level keys come before the first [table].
66
+ for (const line of raw.split("\n")) {
67
+ if (/^\s*\[/.test(line)) {
68
+ break;
69
+ }
70
+ const match = /^\s*model\s*=\s*"([^"]+)"/.exec(line);
71
+ if (match) {
72
+ return match[1];
73
+ }
74
+ }
75
+ return null;
60
76
  }
61
77
  async function readCodexCliModels() {
62
78
  return (await readCodexCacheModels()).map((model) => ({
@@ -65,8 +81,85 @@ async function readCodexCliModels() {
65
81
  description: model.description,
66
82
  efforts: (model.supported_reasoning_levels ?? []).flatMap((level) => (level.effort ? [level.effort] : [])),
67
83
  alias: false,
84
+ resolved: model.slug,
68
85
  }));
69
86
  }
87
+ const OPENCODE_TIMEOUT_MS = 20_000;
88
+ /** The OpenCode CLI; RUDDER_OPENCODE_BIN points tests at a stub, as in the dashboard. */
89
+ function opencodeBin() {
90
+ return process.env.RUDDER_OPENCODE_BIN?.trim() || "opencode";
91
+ }
92
+ /**
93
+ * `opencode <args>` run from the home directory: its stdout, or null when
94
+ * OpenCode is not installed. Any other failure is an error with its reason.
95
+ */
96
+ async function opencodeOutput(args) {
97
+ const bin = opencodeBin();
98
+ return await new Promise((resolve, reject) => {
99
+ execFile(bin, args, { cwd: os.homedir(), timeout: OPENCODE_TIMEOUT_MS, maxBuffer: 64 * 1024 * 1024 }, (error, stdout, stderr) => {
100
+ if (error?.code === "ENOENT") {
101
+ resolve(null);
102
+ }
103
+ else if (error) {
104
+ const reason = String(stderr).trim().split("\n")[0] || error.message;
105
+ reject(new Error(`${bin} ${args.join(" ")} failed: ${reason}`));
106
+ }
107
+ else {
108
+ resolve(String(stdout));
109
+ }
110
+ });
111
+ });
112
+ }
113
+ /** OpenCode's model list for this machine's sign-ins, with names and variants. */
114
+ async function readOpencodeModels() {
115
+ const out = await opencodeOutput(["models", "--verbose"]);
116
+ return out === null ? [] : parseOpencodeModels(out);
117
+ }
118
+ /**
119
+ * `opencode models --verbose`: each model's `provider/model` id on a line of
120
+ * its own, then its JSON (name, limit.context, release_date and `variants`,
121
+ * the reasoning levels it runs at, keyed by name).
122
+ */
123
+ export function parseOpencodeModels(out) {
124
+ const lines = out.split("\n");
125
+ const models = [];
126
+ for (let index = 0; index < lines.length; index += 1) {
127
+ const id = lines[index].trim();
128
+ if (!/^[^\s{}"]+\/\S+$/.test(id) || lines[index + 1] !== "{") {
129
+ continue;
130
+ }
131
+ const end = lines.indexOf("}", index + 1);
132
+ if (end < 0) {
133
+ throw new Error(`opencode models --verbose cut off in ${id}`);
134
+ }
135
+ const model = JSON.parse(lines.slice(index + 1, end + 1).join("\n"));
136
+ models.push({
137
+ id,
138
+ name: model.name,
139
+ description: catalogDetail({ limit: model.limit, release_date: model.release_date }),
140
+ efforts: Object.keys(model.variants ?? {}),
141
+ alias: false,
142
+ resolved: id,
143
+ });
144
+ index = end;
145
+ }
146
+ return models;
147
+ }
148
+ /**
149
+ * The model OpenCode runs when it is given none: the `model` its resolved
150
+ * config sets (`opencode debug config`), or null when none does.
151
+ */
152
+ async function readOpencodeConfiguredModel() {
153
+ const out = await opencodeOutput(["debug", "config"]);
154
+ if (out === null) {
155
+ return null;
156
+ }
157
+ const model = JSON.parse(out).model;
158
+ if (typeof model === "string") {
159
+ return model || null;
160
+ }
161
+ return model?.providerID && model.model ? `${model.providerID}/${model.model}` : null;
162
+ }
70
163
  async function readModelsDev() {
71
164
  if (modelCatalogInFlight) {
72
165
  return modelCatalogInFlight;
@@ -105,16 +198,6 @@ function modelsDevCachePath() {
105
198
  // RUDDER_HOME is set — otherwise dynamic model refresh + cached reasoning break.
106
199
  return path.join(rudderHome(), "models-dev.json");
107
200
  }
108
- function isUsableTextModel(id, model) {
109
- if (model.tool_call === false) {
110
- return false;
111
- }
112
- if (isExcludedOpenAiTextModel(id)) {
113
- return false;
114
- }
115
- const output = model.modalities?.output;
116
- return !output || output.includes("text");
117
- }
118
201
  function isClaudePickerModel(id) {
119
202
  // No family-name allowlist: a brand-new model family (fable, and whatever
120
203
  // comes after it) must show up in the picker without a Rudder release. Only
@@ -148,7 +231,7 @@ async function mergeLiveAndLocalModels(data) {
148
231
  for (const model of claudeLocal) {
149
232
  changed = mergeProviderModel(data, "anthropic", model.id, model.meta) || changed;
150
233
  }
151
- for (const model of claudeCodeCatalogModels(data, claudeCode)) {
234
+ for (const model of claudeCodeCatalogModels(data, claudeCode.models)) {
152
235
  changed = mergeProviderModel(data, "anthropic", model.id, model.meta) || changed;
153
236
  }
154
237
  return { changed, claudeCode };
@@ -164,7 +247,7 @@ function claudeCodeCatalogModels(data, listed) {
164
247
  const efforts = new Map();
165
248
  const names = new Map();
166
249
  for (const model of listed) {
167
- efforts.set(model.id, RUDDER_EFFORTS.claude.filter((level) => model.efforts.includes(level)));
250
+ efforts.set(model.id, CLAUDE.efforts.filter((level) => model.efforts.includes(level)));
168
251
  names.set(model.id, model.name);
169
252
  }
170
253
  for (const model of listed) {
@@ -177,7 +260,7 @@ function claudeCodeCatalogModels(data, listed) {
177
260
  id,
178
261
  meta: known[id]
179
262
  ? { efforts: levels }
180
- : { id, name: names.get(id) || prettyClaudeModel(id), tool_call: true, efforts: levels, modalities: { output: ["text"] }, source: "claude-code" },
263
+ : { id, name: names.get(id) || claudeModelName(id), tool_call: true, efforts: levels, modalities: { output: ["text"] }, source: "claude-code" },
181
264
  }));
182
265
  }
183
266
  async function fetchOpenAIModelCatalog() {
@@ -221,7 +304,7 @@ async function fetchAnthropicModelCatalog() {
221
304
  id: model.id,
222
305
  meta: {
223
306
  id: model.id,
224
- name: model.display_name || prettyClaudeModel(model.id),
307
+ name: model.display_name || claudeModelName(model.id),
225
308
  tool_call: true,
226
309
  reasoning: isLikelyReasoningModel("claude", model.id),
227
310
  release_date: typeof model.created_at === "string" ? model.created_at.slice(0, 10) : undefined,
@@ -233,15 +316,15 @@ async function fetchAnthropicModelCatalog() {
233
316
  return [];
234
317
  }
235
318
  async function readCodexLocalModels() {
236
- return (await discoverCodexModelsLocal())
237
- .filter((model) => model.value && isCodexRelevantModel(model.value) && !isExcludedOpenAiTextModel(model.value))
319
+ return (await readCodexCacheModels())
320
+ .filter((model) => isCodexRelevantModel(model.slug) && !isExcludedOpenAiTextModel(model.slug))
238
321
  .map((model) => ({
239
- id: model.value,
322
+ id: model.slug,
240
323
  meta: {
241
- id: model.value,
242
- name: model.detail || model.label,
324
+ id: model.slug,
325
+ name: model.display_name || model.description || model.slug,
243
326
  tool_call: true,
244
- reasoning: isLikelyReasoningModel("codex", model.value),
327
+ reasoning: isLikelyReasoningModel("codex", model.slug),
245
328
  modalities: { output: ["text"] },
246
329
  source: "codex-local-cache",
247
330
  },
@@ -256,7 +339,7 @@ async function readClaudeLocalModelIds() {
256
339
  id,
257
340
  meta: {
258
341
  id,
259
- name: prettyClaudeModel(id),
342
+ name: claudeModelName(id),
260
343
  tool_call: true,
261
344
  reasoning: isLikelyReasoningModel("claude", id),
262
345
  modalities: { output: ["text"] },
@@ -524,117 +607,165 @@ function collectModelFields(value, counts, depth = 0) {
524
607
  collectModelFields(child, counts, depth + 1);
525
608
  }
526
609
  }
527
- function prettyClaudeModel(model) {
528
- if (model === "opus" || model === "sonnet") {
529
- return `${capitalize(model)} latest`;
530
- }
531
- return model
532
- .replace(/^claude-/, "")
533
- .split("-")
534
- .map((part) => (/^\d+$/.test(part) ? part : capitalize(part)))
535
- .join(" ");
610
+ /** The name a Claude id reads as, the picker's way: "claude-fable-5-2" is "Fable 5.2". */
611
+ function claudeModelName(id) {
612
+ return withContext(parseClaudeId(id).name, id);
536
613
  }
537
614
  function capitalize(value) {
538
615
  return `${value.slice(0, 1).toUpperCase()}${value.slice(1)}`;
539
616
  }
540
- const ALIAS_GROUP = "Always the newest";
541
- const CONTEXT_SUFFIX = /\[(\d+)([km])\]$/i;
542
- // The levels the dashboard passes (native/src/models.rs effort_options_for):
543
- // a model with an effort setting takes low to xhigh, and Claude also max.
544
- const RUDDER_EFFORTS = {
545
- claude: ["low", "medium", "high", "xhigh", "max"],
546
- codex: ["low", "medium", "high", "xhigh"],
617
+ const CLAUDE = {
618
+ id: "claude",
619
+ label: "Claude",
620
+ account: "Claude Code",
621
+ catalog: "anthropic",
622
+ listed: async (catalog) => catalog.claudeCode.models,
623
+ defaultModel: async (catalog) => catalog.claudeCode.default,
624
+ parse: parseClaudeId,
625
+ // Claude Code's names already read "Opus 5.5".
626
+ name: (display) => display,
627
+ tiers: tiersByListOrder,
628
+ efforts: ["low", "medium", "high", "xhigh", "max"],
629
+ };
630
+ const CODEX = {
631
+ id: "codex",
632
+ label: "Codex",
633
+ account: "ChatGPT",
634
+ catalog: "openai",
635
+ listed: () => readCodexCliModels(),
636
+ defaultModel: () => readCodexConfiguredModel(),
637
+ parse: parseGptId,
638
+ name: gptName,
639
+ // Codex lists its recommended model first, not its flagship.
640
+ tiers: tiersByPrice,
641
+ efforts: ["low", "medium", "high", "xhigh"],
547
642
  };
548
- function pickerRows(backend, catalog, cli) {
549
- const listed = new Map();
643
+ const OPENCODE = {
644
+ id: "opencode",
645
+ label: "OpenCode",
646
+ // OpenCode runs its own free models with no sign-in, and the models of any
647
+ // provider it is signed in to.
648
+ account: "OpenCode",
649
+ catalog: null,
650
+ listed: () => readOpencodeModels(),
651
+ defaultModel: () => readOpencodeConfiguredModel(),
652
+ parse: parseOpencodeId,
653
+ // OpenCode's names already read "Big Pickle", "Claude Sonnet 4.5".
654
+ name: (display) => display,
655
+ // Providers in the order OpenCode lists them.
656
+ tiers: tiersByListOrder,
657
+ // A model's variants of these names (`opencode models --verbose`); the
658
+ // dashboard runs one as the agent's `variant` (native launch.rs).
659
+ efforts: ["low", "medium", "high", "xhigh", "max"],
660
+ };
661
+ const HARNESSES = [CLAUDE, CODEX, OPENCODE];
662
+ const CONTEXT_SUFFIX = /\[(\d+)([km])\]$/i;
663
+ function pickerRows(harness, catalog, cli) {
664
+ const models = new Map();
550
665
  const aliases = [];
551
666
  for (const model of cli) {
552
667
  if (model.alias) {
553
668
  aliases.push(model);
554
669
  }
555
- else if (!listed.has(model.id)) {
556
- listed.set(model.id, model);
557
- }
558
- }
559
- const ids = new Set(Object.entries(catalog).filter(([id, model]) => isPickerModel(backend, id, model)).map(([id]) => id));
560
- for (const id of listed.keys()) {
561
- ids.add(id);
562
- }
563
- // A dated snapshot repeats its undated twin, so only the twin is listed
564
- // (the dashboard's picker does the same: models.rs dated_duplicate_base).
565
- for (const id of ids) {
566
- const base = /^(.+)-\d{8}$/.exec(id)?.[1];
567
- if (base && ids.has(base)) {
568
- const twin = listed.get(id);
569
- if (twin && !listed.has(base)) {
570
- listed.set(base, twin);
571
- }
572
- ids.delete(id);
670
+ else if (!models.has(model.id)) {
671
+ models.set(model.id, model);
573
672
  }
574
673
  }
575
- const prices = familyPrices(backend, catalog);
576
- const rows = [...ids]
577
- .map((id) => ({ id, parsed: parseModelId(backend, id) }))
578
- .sort((a, b) => compareModelIds(a.parsed, b.parsed, prices) || a.id.localeCompare(b.id))
579
- // Older catalog models make way; every model the CLI lists stays.
580
- .filter((row, index) => listed.has(row.id) || index < MODEL_PICKER_LIMIT)
581
- .map(({ id, parsed }) => ({
582
- label: modelLabel(backend, id, parsed, listed),
583
- value: id,
584
- detail: listed.get(id)?.description || catalogDetail(catalog[id]),
585
- group: parsed.group,
586
- efforts: modelEfforts(backend, id, catalog[id], listed.get(id)),
674
+ const tiers = harness.tiers(harness.parse, cli, catalog);
675
+ // The levels both the CLI lists and the dashboard passes; the dashboard refuses any other.
676
+ const efforts = (model) => harness.efforts.filter((level) => model.efforts.includes(level));
677
+ const rows = [...models.values()]
678
+ .map((model) => ({ model, parsed: harness.parse(model.id) }))
679
+ .sort((a, b) => compareModelIds(a.parsed, b.parsed, tiers) || a.model.id.localeCompare(b.model.id))
680
+ .map(({ model, parsed }) => ({
681
+ label: modelLabel(harness, model.id, parsed, models),
682
+ value: model.id,
683
+ detail: model.description || catalogDetail(catalog[model.id]),
684
+ efforts: efforts(model),
587
685
  }));
686
+ // "opus" reads "Opus 5.5" and sorts where Opus 5.5 does.
588
687
  const aliasRows = aliases
589
- .map((alias) => ({ alias, family: alias.id.replace(CONTEXT_SUFFIX, "") }))
590
- .sort((a, b) => (prices.get(b.family) ?? 0) - (prices.get(a.family) ?? 0) || a.alias.id.localeCompare(b.alias.id))
591
- .map(({ alias }) => ({
592
- label: withContext(capitalize(alias.id.replace(CONTEXT_SUFFIX, "")), alias.id),
688
+ .map((alias) => ({ alias, parsed: harness.parse(alias.resolved) }))
689
+ .sort((a, b) => compareModelIds(a.parsed, b.parsed, tiers) || a.alias.id.localeCompare(b.alias.id))
690
+ .map(({ alias, parsed }) => ({
691
+ label: modelLabel(harness, alias.resolved, parsed, models),
593
692
  value: alias.id,
594
- detail: [alias.name ? `Now ${alias.name}` : "", alias.description ?? ""].filter(Boolean).join(" · "),
595
- group: ALIAS_GROUP,
596
- efforts: modelEfforts(backend, alias.id, catalog[alias.id], alias),
693
+ detail: alias.description ?? "",
694
+ efforts: efforts(alias),
695
+ alias: true,
597
696
  }));
598
697
  return [...rows, ...aliasRows];
599
698
  }
600
- function isPickerModel(backend, id, model) {
601
- if (!isUsableTextModel(id, model)) {
602
- return false;
603
- }
604
- return backend === "claude" ? id.startsWith("claude-") && isClaudePickerModel(id) : isCodexRelevantModel(id);
699
+ /** Families in the order the CLI first lists them: Claude Code lists Opus, Fable, Sonnet, Haiku. */
700
+ function tiersByListOrder(parse, cli) {
701
+ const families = [...new Set(cli.map((model) => parse(model.resolved).family))];
702
+ return new Map(families.map((family, index) => [family, families.length - index]));
605
703
  }
606
- /** "claude-opus-5-5" is Opus of Claude 5.5, "gpt-6.1-sol" Sol of GPT-6.1, "o4-mini" Mini of o4. */
607
- function parseModelId(backend, id) {
608
- const suffix = CONTEXT_SUFFIX.exec(id);
609
- const context = suffix ? `${suffix[1]}${suffix[2].toUpperCase()}` : undefined;
610
- const base = suffix ? id.slice(0, suffix.index) : id;
611
- if (backend === "claude") {
612
- const claude = /^claude-([a-z]+)((?:-\d{1,2})+)(?:-\d{8})?$/.exec(base);
613
- if (claude) {
614
- const version = claude[2].slice(1).split("-").map(Number);
615
- const number = version.join(".");
616
- return { group: `Claude ${number}`, series: 0, version, family: claude[1], name: `${capitalize(claude[1])} ${number}`, context };
617
- }
618
- }
619
- else {
620
- const gpt = /^gpt-(\d+(?:\.\d+)?)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
621
- if (gpt) {
622
- const variant = gpt[2] ?? "";
623
- return { group: `GPT-${gpt[1]}`, series: 0, version: gpt[1].split(".").map(Number), family: variant, name: [`GPT-${gpt[1]}`, ...words(variant)].join(" "), context };
624
- }
625
- const oSeries = /^o(\d+)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
626
- if (oSeries) {
627
- const variant = oSeries[2] ?? "";
628
- return { group: `o${oSeries[1]}`, series: 1, version: [Number(oSeries[1])], family: `o:${variant}`, name: [`o${oSeries[1]}`, ...words(variant)].join(" "), context };
704
+ /** Each family's highest output price in the catalog: Astra before Sol before Terra before Luna. */
705
+ function tiersByPrice(parse, _cli, catalog) {
706
+ const prices = new Map();
707
+ for (const [id, model] of Object.entries(catalog)) {
708
+ const price = model.cost?.output;
709
+ if (typeof price === "number") {
710
+ const { family } = parse(id);
711
+ prices.set(family, Math.max(prices.get(family) ?? 0, price));
629
712
  }
630
713
  }
631
- return { group: "Other", series: 2, version: [], family: base, name: base, context };
714
+ return prices;
715
+ }
716
+ function splitContext(id) {
717
+ const suffix = CONTEXT_SUFFIX.exec(id);
718
+ return suffix ? { base: id.slice(0, suffix.index), context: `${suffix[1]}${suffix[2].toUpperCase()}` } : { base: id };
632
719
  }
633
- function words(variant) {
634
- return variant.split("-").filter(Boolean).map(capitalize);
720
+ /** An id of no known shape reads as its words, without a provider prefix: "anthropic/my-model" is "My Model". */
721
+ function unknownId(base, context) {
722
+ return { series: 2, version: [], family: base, name: words(base.slice(base.lastIndexOf("/") + 1)), context };
635
723
  }
636
- /** Newest generation first; within one, the family with the highest price first. */
637
- function compareModelIds(a, b, prices) {
724
+ /**
725
+ * "opencode/big-pickle" reads "Big Pickle". OpenCode's ids carry no version
726
+ * Rudder can read across providers, so each provider is a family, ranked in
727
+ * list order, and its models go by id.
728
+ */
729
+ function parseOpencodeId(id) {
730
+ const { base, context } = splitContext(id);
731
+ const slash = base.indexOf("/");
732
+ return { ...unknownId(base, context), series: 0, family: slash > 0 ? base.slice(0, slash) : base };
733
+ }
734
+ /** "claude-opus-5-5" is Opus 5.5, "claude-haiku-4-5-20251001" Haiku 4.5. */
735
+ function parseClaudeId(id) {
736
+ const { base, context } = splitContext(id);
737
+ const claude = /^claude-([a-z]+)((?:-\d{1,2})+)(?:-\d{8})?$/.exec(base);
738
+ if (!claude) {
739
+ return unknownId(base, context);
740
+ }
741
+ const version = claude[2].slice(1).split("-").map(Number);
742
+ return { series: 0, version, family: claude[1], name: `${capitalize(claude[1])} ${version.join(".")}`, context };
743
+ }
744
+ /** "gpt-6.1-sol" is Sol 6.1, "gpt-5.3-codex-spark" Codex Spark 5.3; "gpt-5.6" has no family word. */
745
+ function parseGptId(id) {
746
+ const { base, context } = splitContext(id);
747
+ const gpt = /^gpt-(\d+(?:\.\d+)?)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
748
+ if (gpt) {
749
+ const family = gpt[2] ?? "";
750
+ return { series: 0, version: gpt[1].split(".").map(Number), family, name: family ? `${words(family)} ${gpt[1]}` : `GPT-${gpt[1]}`, context };
751
+ }
752
+ const oSeries = /^o(\d+)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
753
+ if (oSeries) {
754
+ const family = oSeries[2] ?? "";
755
+ return { series: 1, version: [Number(oSeries[1])], family: `o:${family}`, name: family ? `${words(family)} o${oSeries[1]}` : `o${oSeries[1]}`, context };
756
+ }
757
+ return unknownId(base, context);
758
+ }
759
+ /** Codex's display name, the name and then the version: "GPT-6.2-Sol" and "GPT-6.2 Sol" read "Sol 6.2". */
760
+ function gptName(display) {
761
+ const named = /^GPT-(\d+(?:\.\d+)?)[- ](.+)$/i.exec(display);
762
+ return named ? `${capitalize(named[2].replace(/-/g, " "))} ${named[1]}` : display;
763
+ }
764
+ function words(family) {
765
+ return family.split(/[-_]/).filter(Boolean).map(capitalize).join(" ");
766
+ }
767
+ /** The highest version first; within one, the family of the highest tier first. */
768
+ function compareModelIds(a, b, tiers) {
638
769
  if (a.series !== b.series) {
639
770
  return a.series - b.series;
640
771
  }
@@ -644,74 +775,73 @@ function compareModelIds(a, b, prices) {
644
775
  return diff;
645
776
  }
646
777
  }
647
- return (prices.get(b.family) ?? 0) - (prices.get(a.family) ?? 0) || Number(!!a.context) - Number(!!b.context);
778
+ return (tiers.get(b.family) ?? 0) - (tiers.get(a.family) ?? 0) || Number(!!a.context) - Number(!!b.context);
648
779
  }
649
- /** Each family's highest output price in the catalog: Fable before Opus before Sonnet before Haiku. */
650
- function familyPrices(backend, catalog) {
651
- const prices = new Map();
652
- for (const [id, model] of Object.entries(catalog)) {
653
- const price = model.cost?.output;
654
- if (typeof price === "number") {
655
- const { family } = parseModelId(backend, id);
656
- prices.set(family, Math.max(prices.get(family) ?? 0, price));
657
- }
658
- }
659
- return prices;
660
- }
661
- /** The CLI's display name for the model ("GPT-6.2-Sol" reads "GPT-6.2 Sol"), or one read from the id. */
662
- function modelLabel(backend, id, parsed, listed) {
780
+ /** The harness's name for the CLI's display name, or the name read from the id. */
781
+ function modelLabel(harness, id, parsed, listed) {
663
782
  const own = listed.get(id.replace(CONTEXT_SUFFIX, ""))?.name?.trim();
664
- const name = own ? (backend === "codex" ? own.replace(/^(GPT-\d+(?:\.\d+)?)-/i, "$1 ") : own) : parsed.name;
665
- return withContext(name, id);
783
+ return withContext(own ? harness.name(own) : parsed.name, id);
666
784
  }
667
785
  /** "Opus 5.5" of "claude-opus-5-5[1m]" reads "Opus 5.5 · 1M". */
668
786
  function withContext(name, id) {
669
787
  const suffix = CONTEXT_SUFFIX.exec(id);
670
788
  return suffix ? `${name} · ${suffix[1]}${suffix[2].toUpperCase()}` : name;
671
789
  }
672
- /** The levels both the model's CLI lists and the dashboard passes; the dashboard refuses any other. */
673
- function modelEfforts(backend, id, model, listed) {
674
- // Claude Code's levels, kept in the catalog: the dashboard takes exactly these.
675
- if (model?.efforts) {
676
- return model.efforts;
677
- }
678
- if (!hasEffortSetting(backend, id, model)) {
679
- return [];
680
- }
681
- return listed ? RUDDER_EFFORTS[backend].filter((level) => listed.efforts.includes(level)) : RUDDER_EFFORTS[backend];
682
- }
683
- /** native/src/models.rs model_supports_reasoning: the family rule, or the catalog's word. */
684
- function hasEffortSetting(backend, id, model) {
685
- if (model?.reasoning === true) {
686
- return true;
790
+ /**
791
+ * The name the app shows for any model an agent runs on. The home names every
792
+ * model it sends with this (cloud/worker/home.mjs), so the app never names
793
+ * one itself. A model its harness lists reads as its picker row does (an
794
+ * alias like the model it stands for: "opus" is "Opus 5.5"); any other id
795
+ * reads as the rows' rules read it ("claude-opus-4-1" is "Opus 4.1", "gpt-6.1-sol"
796
+ * Sol 6.1, "my-model" My Model). No id is the model the harness runs when
797
+ * given none (HarnessModels.default), and null when it does not say which.
798
+ * `harnesses` is the last discoverHarnesses() answer, empty before the first.
799
+ */
800
+ export function modelName(harnesses, backend, id) {
801
+ const listed = harnesses.find((harness) => harness.id === backend);
802
+ if (!id) {
803
+ return listed?.default ? modelName(harnesses, backend, listed.default) : null;
687
804
  }
688
- if (backend === "claude") {
689
- return /opus|sonnet|fable/.test(id) || (id.startsWith("claude-") && !id.includes("3-"));
805
+ const row = listed?.models.find((model) => model.value === id);
806
+ if (row) {
807
+ return row.label;
690
808
  }
691
- return isGptTextModel(id) || id.includes("codex") || isOSeriesModel(id);
809
+ const harness = HARNESSES.find((entry) => entry.id === backend);
810
+ return withContext(harness ? harness.parse(id).name : unknownId(splitContext(id).base).name, id);
692
811
  }
693
812
  const CLAUDE_CODE_TIMEOUT_MS = 20_000;
694
813
  /**
695
814
  * Claude Code's own /model list for this account, with each alias's current
696
815
  * model, display names and the effort levels each model takes. Each alias
697
816
  * also lists the model it stands for. Empty when Claude Code is not installed.
817
+ * Its "default" row is not a model of its own: it names the model an agent
818
+ * started without one runs.
698
819
  */
699
820
  async function readClaudeCodeModels() {
700
821
  const answer = await claudeCodeModelList();
701
822
  const models = [];
823
+ let runsByDefault = null;
702
824
  for (const row of answer ?? []) {
703
- // Claude Code's "default" is what Rudder's Default row starts.
704
- if (!row.value || row.value === "default") {
825
+ if (row.value === "default") {
826
+ runsByDefault = row.resolvedModel?.startsWith("claude-") ? row.resolvedModel : null;
827
+ continue;
828
+ }
829
+ if (!row.value) {
705
830
  continue;
706
831
  }
707
832
  const efforts = row.supportsEffort ? row.supportedEffortLevels ?? [] : [];
708
- const alias = !row.value.startsWith("claude-");
709
- models.push({ id: row.value, name: row.displayName, description: row.description, efforts, alias });
710
- if (alias && row.resolvedModel?.startsWith("claude-")) {
711
- models.push({ id: row.resolvedModel, name: row.displayName, description: row.description, efforts, alias: false });
833
+ if (row.value.startsWith("claude-")) {
834
+ models.push({ id: row.value, name: row.displayName, description: row.description, efforts, alias: false, resolved: row.value });
835
+ continue;
712
836
  }
837
+ // An alias is named and placed like the model it stands for.
838
+ if (!row.resolvedModel?.startsWith("claude-")) {
839
+ throw new Error(`Claude Code listed the model alias "${row.value}" without the Claude model it stands for`);
840
+ }
841
+ models.push({ id: row.value, name: row.displayName, description: row.description, efforts, alias: true, resolved: row.resolvedModel });
842
+ models.push({ id: row.resolvedModel, name: row.displayName, description: row.description, efforts, alias: false, resolved: row.resolvedModel });
713
843
  }
714
- return models;
844
+ return { models, default: runsByDefault };
715
845
  }
716
846
  /** Claude Code's headless `initialize` answer: its model list, or null when Claude Code is not installed. */
717
847
  function claudeCodeModelList() {