Skip to content

Commit 0a14f55

Browse files
authored
Merge branch 'main' into fix/checkpoint-write-cleanup
2 parents 63a7f66 + 087cfb8 commit 0a14f55

27 files changed

Lines changed: 1544 additions & 325 deletions

‎apps/server/src/provider/ClaudeModelCatalog.test.ts‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import {
77
formatClaudeVersionUpgradeMessage,
88
normalizeClaudeCatalogEffort,
99
resolveClaudeCatalogApiModelId,
10+
resolveClaudeCatalogEffort,
1011
resolveClaudeModelCatalog,
1112
resolveClaudeModelsForVersion,
1213
resolveClaudeModelSlug,
14+
scopeClaudeModelCatalog,
1315
} from "./ClaudeModelCatalog.ts";
1416

1517
/**
@@ -134,4 +136,58 @@ describe("Claude model catalog", () => {
134136
};
135137
assert.isFalse(hasValidClaudeManifestAdapters(malformed));
136138
});
139+
140+
it("appends custom models with their own descriptors and keeps bare slugs opaque", () => {
141+
const catalog = scopeClaudeModelCatalog(resolveClaudeModelCatalog(manifest()), [
142+
"synthetic",
143+
{
144+
slug: "claude-custom-tuned",
145+
name: "Tuned",
146+
capabilities: {
147+
optionDescriptors: [
148+
{
149+
id: "effort",
150+
label: "Reasoning",
151+
type: "select",
152+
options: [
153+
{ id: "gentle", label: "Gentle", isDefault: true },
154+
{ id: "brutal", label: "Brutal" },
155+
],
156+
},
157+
],
158+
},
159+
},
160+
]);
161+
162+
// The bare custom slug shadows the built-in alias, so it no longer resolves to it.
163+
assert.strictEqual(resolveClaudeModelSlug(catalog, "synthetic"), "synthetic");
164+
assert.strictEqual(resolveClaudeCatalogEffort(catalog, "synthetic", "extreme"), undefined);
165+
166+
// The entry with descriptors resolves user-defined effort ids and passes
167+
// them through untouched (no effortMap, no model suffix).
168+
assert.strictEqual(
169+
resolveClaudeCatalogEffort(catalog, "claude-custom-tuned", "brutal"),
170+
"brutal",
171+
);
172+
assert.strictEqual(
173+
resolveClaudeCatalogEffort(catalog, "claude-custom-tuned", "bogus"),
174+
"gentle",
175+
);
176+
assert.strictEqual(
177+
normalizeClaudeCatalogEffort(catalog, "brutal", "claude-custom-tuned"),
178+
"brutal",
179+
);
180+
assert.strictEqual(
181+
resolveClaudeCatalogApiModelId(catalog, {
182+
instanceId: ProviderInstanceId.make("claudeAgent"),
183+
model: "claude-custom-tuned",
184+
options: [{ id: "effort", value: "brutal" }],
185+
}),
186+
"claude-custom-tuned",
187+
);
188+
assert.deepStrictEqual(
189+
resolveClaudeModelsForVersion(catalog, "3.2.0").map((model) => model.slug),
190+
["claude-synthetic-next", "claude-custom-tuned"],
191+
);
192+
});
137193
});

‎apps/server/src/provider/ClaudeModelCatalog.ts‎

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type CustomModelSetting,
23
type ModelCapabilities,
34
type ModelSelection,
45
ProviderDriverKind,
@@ -9,7 +10,7 @@ import {
910
getModelSelectionStringOptionValue,
1011
getProviderOptionCurrentValue,
1112
getProviderOptionDescriptors,
12-
normalizeCustomModelSlug,
13+
readCustomModelEntries,
1314
} from "@t3tools/shared/model";
1415
import { compareSemverVersions } from "@t3tools/shared/semver";
1516

@@ -70,33 +71,51 @@ export function resolveClaudeModelCatalog(manifest: ModelManifestData): ClaudeMo
7071

7172
export const BUNDLED_CLAUDE_MODEL_CATALOG = resolveClaudeModelCatalog(BUNDLED_MODEL_MANIFEST);
7273

73-
/** Keeps custom model aliases opaque while preserving canonical built-in models and capabilities. */
74+
/**
75+
* Scope the catalog to one instance's settings: custom model slugs stay opaque
76+
* (a built-in alias they shadow is dropped, canonical slugs and capabilities
77+
* are preserved), and custom entries that declare their own capabilities are
78+
* appended so the adapter resolves effort / fast mode / thinking against the
79+
* user's descriptors instead of the empty default. Custom entries carry no
80+
* runtime profile, so option values pass through to Claude Code verbatim.
81+
*/
7482
export function scopeClaudeModelCatalog(
7583
catalog: ClaudeModelCatalog,
76-
customModels: ReadonlyArray<string>,
84+
customModels: ReadonlyArray<CustomModelSetting>,
7785
): ClaudeModelCatalog {
78-
const customAliases = new Set(
79-
customModels.flatMap((model) => {
80-
const slug = normalizeCustomModelSlug(model);
81-
return slug ? [slug.toLowerCase()] : [];
82-
}),
83-
);
84-
if (customAliases.size === 0) return catalog;
86+
const customEntries = readCustomModelEntries(customModels);
87+
if (customEntries.length === 0) return catalog;
88+
const customAliases = new Set(customEntries.map((entry) => entry.slug.toLowerCase()));
8589

86-
return {
87-
models: catalog.models.map((entry) => {
88-
if (!entry.model.aliases?.some((alias) => customAliases.has(alias.toLowerCase()))) {
89-
return entry;
90-
}
91-
return {
92-
...entry,
93-
model: {
94-
...entry.model,
95-
aliases: entry.model.aliases.filter((alias) => !customAliases.has(alias.toLowerCase())),
96-
},
97-
};
98-
}),
99-
};
90+
const builtInModels = catalog.models.map((entry) => {
91+
if (!entry.model.aliases?.some((alias) => customAliases.has(alias.toLowerCase()))) {
92+
return entry;
93+
}
94+
return {
95+
...entry,
96+
model: {
97+
...entry.model,
98+
aliases: entry.model.aliases.filter((alias) => !customAliases.has(alias.toLowerCase())),
99+
},
100+
};
101+
});
102+
const builtInSlugs = new Set(builtInModels.map((entry) => entry.model.slug));
103+
const customCatalogModels: Array<ClaudeCatalogModel> = [];
104+
for (const entry of customEntries) {
105+
if (!entry.capabilities || builtInSlugs.has(entry.slug)) continue;
106+
customCatalogModels.push({
107+
model: {
108+
slug: entry.slug,
109+
name: entry.name,
110+
isCustom: true,
111+
capabilities: entry.capabilities,
112+
},
113+
runtime: {},
114+
compatibility: {},
115+
});
116+
}
117+
118+
return { models: [...builtInModels, ...customCatalogModels] };
100119
}
101120

102121
export function resolveClaudeCatalogModel(

‎apps/server/src/provider/Drivers/CursorSkills.ts‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,18 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
147147
if (!resolvedDirectory) {
148148
return;
149149
}
150-
if (
151-
visitedDirectories.has(resolvedDirectory) ||
152-
(resolvedDirectory !== rootDirectory &&
153-
!resolvedDirectory.startsWith(`${rootDirectory}${path.sep}`))
154-
) {
150+
if (visitedDirectories.has(resolvedDirectory)) {
155151
return;
156152
}
157153
visitedDirectories.add(resolvedDirectory);
154+
// A symlink whose target lives outside the root is a skill package
155+
// boundary: read its own SKILL.md so linked skill libraries show up, but
156+
// never walk the target tree.
157+
const insideRoot =
158+
resolvedDirectory === rootDirectory ||
159+
resolvedDirectory.startsWith(`${rootDirectory}${path.sep}`);
158160

159-
const skillPath = path.join(resolvedDirectory, "SKILL.md");
161+
const skillPath = path.join(directory, "SKILL.md");
160162
const skillInfo = yield* orUndefined(fileSystem.stat(skillPath), input.budget);
161163
if (skillInfo?.type === "File") {
162164
let frontmatter: CursorSkillFrontmatter | undefined = { cliVisible: true };
@@ -167,7 +169,7 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
167169
frontmatter = parseSkillFrontmatter(contents);
168170
}
169171
}
170-
const name = path.basename(resolvedDirectory).trim();
172+
const name = path.basename(directory).trim();
171173
if (frontmatter?.cliVisible && name) {
172174
skills.push({
173175
name,
@@ -184,7 +186,10 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
184186
}
185187
}
186188

187-
const entries = yield* orUndefined(fileSystem.readDirectory(resolvedDirectory), input.budget);
189+
if (!insideRoot) {
190+
return;
191+
}
192+
const entries = yield* orUndefined(fileSystem.readDirectory(directory), input.budget);
188193
if (!entries) {
189194
return;
190195
}
@@ -194,7 +199,7 @@ const discoverSkillsInRoot = Effect.fn("discoverCursorSkillsInRoot")(function* (
194199
return;
195200
}
196201
input.budget.remainingEntries -= 1;
197-
const child = path.join(resolvedDirectory, entry);
202+
const child = path.join(directory, entry);
198203
const info = yield* orUndefined(fileSystem.stat(child), input.budget);
199204
if (info?.type !== "Directory") continue;
200205
if (depth >= MAX_SKILL_DEPTH) {

‎apps/server/src/provider/Layers/CodexProvider.ts‎

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as CodexErrors from "effect-codex-app-server/errors";
1515

1616
import type {
1717
CodexSettings,
18+
CustomModelSetting,
1819
ServerProvider,
1920
ServerProviderState,
2021
ModelCapabilities,
@@ -24,7 +25,7 @@ import type {
2425
} from "@t3tools/contracts";
2526
import { PREFERRED_DEFAULT_CODEX_MODELS, ServerSettingsError } from "@t3tools/contracts";
2627

27-
import { createModelCapabilities } from "@t3tools/shared/model";
28+
import { createModelCapabilities, readCustomModelEntries } from "@t3tools/shared/model";
2829
import { resolveSpawnCommand } from "@t3tools/shared/shell";
2930
import { codexAppServerArgs, resolveCodexLaunchArgs } from "./codexLaunchArgs.ts";
3031
import {
@@ -244,9 +245,14 @@ export function applyPreferredCodexDefaultModel(
244245
});
245246
}
246247

248+
/**
249+
* Codex has no static default capability set, so a bare custom slug borrows
250+
* the first built-in's descriptors; an entry with its own capabilities keeps
251+
* them.
252+
*/
247253
function appendCustomCodexModels(
248254
models: ReadonlyArray<ServerProviderModel>,
249-
customModels: ReadonlyArray<string>,
255+
customModels: ReadonlyArray<CustomModelSetting>,
250256
): ReadonlyArray<ServerProviderModel> {
251257
if (customModels.length === 0) {
252258
return models;
@@ -255,17 +261,16 @@ function appendCustomCodexModels(
255261
const seen = new Set(models.map((model) => model.slug));
256262
const fallbackCapabilities = models.find((model) => model.capabilities)?.capabilities ?? null;
257263
const customEntries: ServerProviderModel[] = [];
258-
for (const rawModel of customModels) {
259-
const slug = rawModel.trim();
260-
if (!slug || seen.has(slug)) {
264+
for (const entry of readCustomModelEntries(customModels)) {
265+
if (seen.has(entry.slug)) {
261266
continue;
262267
}
263-
seen.add(slug);
268+
seen.add(entry.slug);
264269
customEntries.push({
265-
slug,
266-
name: slug,
270+
slug: entry.slug,
271+
name: entry.name,
267272
isCustom: true,
268-
capabilities: fallbackCapabilities,
273+
capabilities: entry.capabilities ?? fallbackCapabilities,
269274
});
270275
}
271276
return customEntries.length === 0 ? models : [...models, ...customEntries];
@@ -399,7 +404,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
399404
readonly homePath?: string;
400405
readonly launchArgs?: string;
401406
readonly cwd: string;
402-
readonly customModels?: ReadonlyArray<string>;
407+
readonly customModels?: ReadonlyArray<CustomModelSetting>;
403408
readonly environment?: NodeJS.ProcessEnv;
404409
}) {
405410
const { client, initialize } = yield* withCodexAppServerClient(input);
@@ -470,21 +475,8 @@ export const probeCodexSkillsForCwd = Effect.fn("probeCodexSkillsForCwd")(functi
470475
return parseCodexSkillsListResponse(skillsResponse, input.cwd);
471476
});
472477

473-
const emptyCodexModelsFromSettings = (codexSettings: CodexSettings): ServerProvider["models"] => {
474-
const models = new Set<string>();
475-
for (const model of codexSettings.customModels) {
476-
const trimmed = model.trim();
477-
if (trimmed.length > 0) {
478-
models.add(trimmed);
479-
}
480-
}
481-
return Array.from(models, (model) => ({
482-
slug: model,
483-
name: model,
484-
isCustom: true,
485-
capabilities: null,
486-
}));
487-
};
478+
const emptyCodexModelsFromSettings = (codexSettings: CodexSettings): ServerProvider["models"] =>
479+
appendCustomCodexModels([], codexSettings.customModels);
488480

489481
const makePendingCodexProvider = (
490482
codexSettings: CodexSettings,
@@ -562,7 +554,7 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
562554
readonly homePath?: string;
563555
readonly launchArgs?: string;
564556
readonly cwd: string;
565-
readonly customModels: ReadonlyArray<string>;
557+
readonly customModels: ReadonlyArray<CustomModelSetting>;
566558
readonly environment?: NodeJS.ProcessEnv;
567559
}) => Effect.Effect<
568560
CodexAppServerProviderSnapshot,

‎apps/server/src/provider/Layers/CursorProvider.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,56 @@ describe("Cursor skills", () => {
395395
}),
396396
));
397397

398+
it("treats a symlinked skill outside the root as a package boundary", async () =>
399+
await runNode(
400+
Effect.gen(function* () {
401+
const fileSystem = yield* FileSystem.FileSystem;
402+
const path = yield* Path.Path;
403+
const userHome = yield* fileSystem.makeTempDirectory({
404+
directory: NodeOS.tmpdir(),
405+
prefix: "cursor-skills-home-",
406+
});
407+
const workspace = yield* fileSystem.makeTempDirectory({
408+
directory: NodeOS.tmpdir(),
409+
prefix: "cursor-skills-workspace-",
410+
});
411+
const library = yield* fileSystem.makeTempDirectory({
412+
directory: NodeOS.tmpdir(),
413+
prefix: "cursor-skills-library-",
414+
});
415+
const writeSkill = Effect.fn("writeCursorSkill")(function* (
416+
directory: string,
417+
contents: string,
418+
) {
419+
yield* fileSystem.makeDirectory(directory, { recursive: true });
420+
yield* fileSystem.writeFileString(path.join(directory, "SKILL.md"), contents);
421+
});
422+
423+
// A skill package managed in a config repo and installed by symlink.
424+
// Its own SKILL.md must be discovered under the link name, but nothing
425+
// below the target may be walked.
426+
yield* writeSkill(path.join(library, "shared-review"), "---\ndescription: shared\n---\n");
427+
yield* writeSkill(path.join(library, "shared-review", "hidden"), "---\n---\n");
428+
const root = path.join(workspace, ".cursor", "skills");
429+
yield* fileSystem.makeDirectory(root, { recursive: true });
430+
yield* fileSystem.symlink(path.join(library, "shared-review"), path.join(root, "review"));
431+
432+
const skills = yield* discoverCursorSkills(workspace, { HOME: userHome });
433+
expect(skills).toEqual([
434+
{
435+
name: "review",
436+
description: "shared",
437+
path: path.join(root, "review", "SKILL.md"),
438+
scope: "project",
439+
enabled: true,
440+
},
441+
]);
442+
expect(
443+
(yield* probeCursorSkills(workspace, { HOME: userHome }).pipe(Effect.result))._tag,
444+
).toBe("Success");
445+
}),
446+
));
447+
398448
it("rewrites only discovered skill mentions into Cursor slash invocations", () => {
399449
expect(hasCursorSkillMention("use $Review_Pr:V2 here")).toBe(true);
400450
expect(hasCursorSkillMention("please $review this")).toBe(true);

‎apps/server/src/provider/Layers/GrokProvider.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type CustomModelSetting,
23
type GrokSettings,
34
type ModelCapabilities,
45
type ServerProvider,
@@ -104,7 +105,7 @@ export function buildInitialGrokProviderSnapshot(
104105
}
105106

106107
function grokModelsFromSettings(
107-
customModels: ReadonlyArray<string> | undefined,
108+
customModels: ReadonlyArray<CustomModelSetting> | undefined,
108109
builtInModels: ReadonlyArray<ServerProviderModel> = GROK_BUILT_IN_MODELS,
109110
): ReadonlyArray<ServerProviderModel> {
110111
return providerModelsFromSettings(builtInModels, customModels ?? [], EMPTY_CAPABILITIES);

0 commit comments

Comments
 (0)