Compare commits

..
Author SHA1 Message Date
Julius Marmingeandcodex f7607138c5 Fix macOS helper bundle identities
Co-authored-by: codex <[email protected]>
2026-04-29 16:33:15 -07:00
8 changed files with 176 additions and 152 deletions

No files matched your search

+38 -1
View File
@@ -8,6 +8,7 @@ import {
mkdirSync,
mkdtempSync,
readFileSync,
readdirSync,
rmSync,
statSync,
writeFileSync,
@@ -19,7 +20,7 @@ import { fileURLToPath } from "node:url";
const isDevelopment = Boolean(process.env.VITE_DEV_SERVER_URL);
const APP_DISPLAY_NAME = isDevelopment ? "T3 Code (Dev)" : "T3 Code (Alpha)";
const APP_BUNDLE_ID = isDevelopment ? "com.t3tools.t3code.dev" : "com.t3tools.t3code";
const LAUNCHER_VERSION = 2;
const LAUNCHER_VERSION = 3;
const __dirname = dirname(fileURLToPath(import.meta.url));
export const desktopDir = resolve(__dirname, "..");
@@ -120,6 +121,41 @@ function patchMainBundleInfoPlist(appBundlePath, iconPath) {
copyFileSync(iconPath, join(resourcesDir, "electron.icns"));
}
function patchHelperBundleInfoPlists(appBundlePath) {
const frameworksDir = join(appBundlePath, "Contents", "Frameworks");
if (!existsSync(frameworksDir)) {
return;
}
for (const entry of readdirSync(frameworksDir, { withFileTypes: true })) {
if (
!entry.isDirectory() ||
!entry.name.startsWith("Electron Helper") ||
!entry.name.endsWith(".app")
) {
continue;
}
const helperPlistPath = join(frameworksDir, entry.name, "Contents", "Info.plist");
if (!existsSync(helperPlistPath)) {
continue;
}
const suffix = entry.name.replace("Electron Helper", "").replace(".app", "").trim();
const helperName = suffix
? `${APP_DISPLAY_NAME} Helper ${suffix}`
: `${APP_DISPLAY_NAME} Helper`;
const helperIdSuffix = suffix.replace(/[()]/g, "").trim().toLowerCase().replace(/\s+/g, "-");
const helperBundleId = helperIdSuffix
? `${APP_BUNDLE_ID}.helper.${helperIdSuffix}`
: `${APP_BUNDLE_ID}.helper`;
setPlistString(helperPlistPath, "CFBundleDisplayName", helperName);
setPlistString(helperPlistPath, "CFBundleName", helperName);
setPlistString(helperPlistPath, "CFBundleIdentifier", helperBundleId);
}
}
function readJson(path) {
try {
return JSON.parse(readFileSync(path, "utf8"));
@@ -157,6 +193,7 @@ function buildMacLauncher(electronBinaryPath) {
rmSync(targetAppBundlePath, { recursive: true, force: true });
cpSync(sourceAppBundlePath, targetAppBundlePath, { recursive: true });
patchMainBundleInfoPlist(targetAppBundlePath, iconPath);
patchHelperBundleInfoPlists(targetAppBundlePath);
writeFileSync(metadataPath, `${JSON.stringify(expectedMetadata, null, 2)}\n`);
return targetBinaryPath;
-35
View File
@@ -182,35 +182,6 @@ function configOptions(): ReadonlyArray<AcpSchema.SessionConfigOption> {
];
}
function modelConfigOptionsFor(modelId: string): ReadonlyArray<AcpSchema.SessionConfigOption> {
const previousModelId = currentModelId;
try {
currentModelId = modelId;
return configOptions().filter(
(option) => option.category !== "mode" && option.category !== "model",
);
} finally {
currentModelId = previousModelId;
}
}
function availableModels(): ReadonlyArray<{
readonly value: string;
readonly name: string;
readonly configOptions: ReadonlyArray<AcpSchema.SessionConfigOption>;
}> {
return [
{ value: "default", name: "Auto" },
{ value: "composer-2", name: "Composer 2" },
{ value: "gpt-5.4", name: "GPT-5.4" },
{ value: "claude-opus-4-6", name: "Opus 4.6" },
].map((model) => ({
value: model.value,
name: model.name,
configOptions: modelConfigOptionsFor(model.value),
}));
}
const availableModes: ReadonlyArray<AcpSchema.SessionMode> = [
{
id: "ask",
@@ -545,12 +516,6 @@ const program = Effect.gen(function* () {
);
yield* agent.handleUnknownExtRequest((method, params) => {
if (method === "cursor/list_available_models") {
return Effect.succeed({
models: availableModels(),
});
}
if (method !== "session/mode/set") {
return Effect.fail(AcpError.AcpRequestError.methodNotFound(method));
}
@@ -471,7 +471,7 @@ describe("discoverCursorModelsViaAcp", () => {
});
describe("discoverCursorModelCapabilitiesViaAcp", () => {
it("discovers model capabilities through Cursor's list_available_models extension method", async () => {
it("closes all ACP probe runtimes after capability enrichment completes", async () => {
const tempDir = await mkdtemp(path.join(os.tmpdir(), "cursor-capabilities-exit-log-"));
const exitLogPath = path.join(tempDir, "exit.log");
const wrapperPath = await makeMockAgentWrapper({
@@ -507,26 +507,9 @@ describe("discoverCursorModelCapabilitiesViaAcp", () => {
"gpt-5.4",
"claude-opus-4-6",
]);
expect(models.find((model) => model.slug === "gpt-5.4")?.capabilities).toEqual(
createModelCapabilities({
optionDescriptors: [
selectDescriptor("reasoning", "Reasoning", [
{ id: "low", label: "Low" },
{ id: "medium", label: "Medium", isDefault: true },
{ id: "high", label: "High" },
{ id: "xhigh", label: "Extra High" },
]),
selectDescriptor("contextWindow", "Context", [
{ id: "272k", label: "272K", isDefault: true },
{ id: "1m", label: "1M" },
]),
booleanDescriptor("fastMode", "Fast", false),
],
}),
);
const exitLog = await waitForFileContent(exitLogPath);
expect(exitLog.match(/SIGTERM/g)?.length ?? 0).toBe(1);
expect(exitLog.match(/SIGTERM/g)?.length ?? 0).toBe(4);
});
});
+107 -57
View File
@@ -13,7 +13,7 @@ import type {
ServerSettingsError,
} from "@t3tools/contracts";
import type * as EffectAcpSchema from "effect-acp/schema";
import { Cause, Effect, Equal, Exit, Layer, Option, Result, Schema, Stream } from "effect";
import { Cause, Effect, Equal, Exit, Layer, Option, Result, Stream } from "effect";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
import {
createModelCapabilities,
@@ -33,7 +33,6 @@ import {
import { makeManagedServerProvider } from "../makeManagedServerProvider.ts";
import { CursorProvider } from "../Services/CursorProvider.ts";
import { AcpSessionRuntime } from "../acp/AcpSessionRuntime.ts";
import { CursorListAvailableModelsResponse } from "../acp/CursorAcpExtension.ts";
import { ServerSettingsService } from "../../serverSettings.ts";
const PROVIDER = "cursor" as const;
@@ -47,6 +46,8 @@ const EMPTY_CAPABILITIES: ModelCapabilities = createModelCapabilities({
});
const CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT_MS = 15_000;
const CURSOR_ACP_MODEL_CAPABILITY_TIMEOUT = "4 seconds";
const CURSOR_ACP_MODEL_DISCOVERY_CONCURRENCY = 4;
const CURSOR_REFRESH_INTERVAL = "1 hour";
const CURSOR_PARAMETERIZED_MODEL_PICKER_MIN_VERSION_DATE = 2026_04_08;
export const CURSOR_PARAMETERIZED_MODEL_PICKER_CAPABILITIES = {
@@ -391,28 +392,6 @@ export function buildCursorDiscoveredModelsFromConfigOptions(
);
}
function buildCursorDiscoveredModelsFromAvailableModelsResponse(
response: typeof CursorListAvailableModelsResponse.Type,
): ReadonlyArray<ServerProviderModel> {
return buildCursorDiscoveredModels(
response.models.flatMap((model) => {
const slug = model.value.trim();
const name = model.name.trim();
if (!slug || !name) {
return [];
}
return [
{
slug,
name,
capabilities: buildCursorCapabilitiesFromConfigOptions(model.configOptions),
},
];
}),
);
}
const makeCursorAcpProbeRuntime = (cursorSettings: CursorSettings) =>
Effect.gen(function* () {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
@@ -546,46 +525,117 @@ export function resolveCursorAcpConfigUpdates(
return updates;
}
const discoverCursorModelsViaListAvailableModels = (cursorSettings: CursorSettings) =>
withCursorAcpProbeRuntime(cursorSettings, (acp) =>
Effect.gen(function* () {
yield* acp.start();
const response = yield* acp.request("cursor/list_available_models", {});
const decoded = yield* Schema.decodeUnknownEffect(CursorListAvailableModelsResponse)(
response,
);
return buildCursorDiscoveredModelsFromAvailableModelsResponse(decoded);
}),
);
export const discoverCursorModelsViaAcp = (cursorSettings: CursorSettings) =>
discoverCursorModelsViaListAvailableModels(cursorSettings).pipe(
Effect.catchCause(() =>
withCursorAcpProbeRuntime(cursorSettings, (acp) =>
Effect.map(acp.start(), (started) =>
buildCursorDiscoveredModelsFromConfigOptions(
started.sessionSetupResult.configOptions ?? [],
),
),
),
withCursorAcpProbeRuntime(cursorSettings, (acp) =>
Effect.map(acp.start(), (started) =>
buildCursorDiscoveredModelsFromConfigOptions(started.sessionSetupResult.configOptions ?? []),
),
);
export const discoverCursorModelCapabilitiesViaAcp = (
cursorSettings: CursorSettings,
_existingModels: ReadonlyArray<ServerProviderModel>,
existingModels: ReadonlyArray<ServerProviderModel>,
) =>
discoverCursorModelsViaListAvailableModels(cursorSettings).pipe(
Effect.catchCause(() =>
withCursorAcpProbeRuntime(cursorSettings, (acp) =>
Effect.map(acp.start(), (started) =>
buildCursorDiscoveredModelsFromConfigOptions(
started.sessionSetupResult.configOptions ?? [],
),
),
),
),
Effect.withSpan("cursor-acp-model-capability-discovery", {}),
withCursorAcpProbeRuntime(cursorSettings, (acp) =>
Effect.gen(function* () {
const started = yield* acp.start();
const initialConfigOptions = started.sessionSetupResult.configOptions ?? [];
const modelOption = findCursorModelConfigOption(initialConfigOptions);
const modelChoices = flattenSessionConfigSelectOptions(modelOption);
if (!modelOption || modelChoices.length === 0) {
return [];
}
const currentModelValue =
modelOption.type === "select" ? modelOption.currentValue?.trim() || undefined : undefined;
const capabilitiesBySlug = new Map<string, ModelCapabilities>();
if (currentModelValue) {
capabilitiesBySlug.set(
currentModelValue,
buildCursorCapabilitiesFromConfigOptions(initialConfigOptions),
);
}
const targetModelSlugs = new Set(
existingModels
.filter((model) => !model.isCustom && !hasCursorModelCapabilities(model))
.map((model) => model.slug),
);
if (targetModelSlugs.size === 0) {
return buildCursorDiscoveredModels(
modelChoices.map((modelChoice) => ({
slug: modelChoice.value.trim(),
name: modelChoice.name.trim(),
capabilities: capabilitiesBySlug.get(modelChoice.value.trim()) ?? EMPTY_CAPABILITIES,
})),
);
}
const probedCapabilities = yield* Effect.forEach(
modelChoices,
(modelChoice) => {
const modelSlug = modelChoice.value.trim();
if (!modelSlug || !targetModelSlugs.has(modelSlug) || capabilitiesBySlug.has(modelSlug)) {
return Effect.void.pipe(
Effect.as<readonly [string, ModelCapabilities] | undefined>(undefined),
);
}
return withCursorAcpProbeRuntime(cursorSettings, (probeAcp) =>
Effect.gen(function* () {
const probeStarted = yield* probeAcp.start();
const probeConfigOptions = probeStarted.sessionSetupResult.configOptions ?? [];
const probeModelOption = findCursorModelConfigOption(probeConfigOptions);
const probeCurrentModelValue =
probeModelOption?.type === "select"
? probeModelOption.currentValue?.trim() || undefined
: undefined;
yield* Effect.annotateCurrentSpan({
"cursor.acp.model.value": modelSlug,
"cursor.acp.model.currentValue": probeCurrentModelValue,
"cursor.acp.config_option_id": probeModelOption?.id ?? modelOption.id,
});
const nextConfigOptions =
probeCurrentModelValue === modelSlug
? probeConfigOptions
: yield* probeAcp
.setConfigOption(probeModelOption?.id ?? modelOption.id, modelSlug)
.pipe(Effect.map((response) => response.configOptions ?? probeConfigOptions));
return [
modelSlug,
buildCursorCapabilitiesFromConfigOptions(nextConfigOptions),
] as const;
}),
).pipe(
Effect.timeout(CURSOR_ACP_MODEL_CAPABILITY_TIMEOUT),
Effect.retry({ times: 3 }),
Effect.withSpan("cursor-acp-model-capability-probe"),
Effect.catchCause((cause) =>
Effect.logWarning("Cursor ACP capability probe failed", {
modelSlug,
cause: Cause.pretty(cause),
}),
),
);
},
{ concurrency: CURSOR_ACP_MODEL_DISCOVERY_CONCURRENCY },
);
for (const entry of probedCapabilities) {
if (!entry) {
continue;
}
capabilitiesBySlug.set(entry[0], entry[1]);
}
return buildCursorDiscoveredModels(
modelChoices.map((modelChoice) => ({
slug: modelChoice.value.trim(),
name: modelChoice.name.trim(),
capabilities: capabilitiesBySlug.get(modelChoice.value.trim()) ?? EMPTY_CAPABILITIES,
})),
);
}).pipe(Effect.withSpan("cursor-acp-model-capability-discovery", {})),
);
export function getCursorFallbackModels(
@@ -1,7 +1,6 @@
import { describe, expect, it } from "vitest";
import {
CursorListAvailableModelsResponse,
extractAskQuestions,
extractPlanMarkdown,
extractTodosAsPlan,
@@ -106,30 +105,4 @@ describe("CursorAcpExtension", () => {
],
});
});
it("decodes Cursor list_available_models responses with per-model config options", () => {
const decoded = CursorListAvailableModelsResponse.make({
models: [
{
value: "gpt-5.4",
name: "GPT-5.4",
configOptions: [
{
id: "reasoning",
name: "Reasoning",
category: "thought_level",
type: "select",
currentValue: "medium",
options: [
{ value: "low", name: "Low" },
{ value: "medium", name: "Medium" },
],
},
],
},
],
});
expect(decoded.models[0]?.configOptions?.[0]?.id).toBe("reasoning");
});
});
@@ -4,7 +4,6 @@
*/
import type { UserInputQuestion } from "@t3tools/contracts";
import { Schema } from "effect";
import * as AcpSchema from "effect-acp/schema";
const CursorAskQuestionOption = Schema.Struct({
id: Schema.String,
@@ -54,16 +53,6 @@ export const CursorUpdateTodosRequest = Schema.Struct({
merge: Schema.Boolean,
});
const CursorAvailableModel = Schema.Struct({
value: Schema.String,
name: Schema.String,
configOptions: Schema.optional(Schema.Array(AcpSchema.SessionConfigOption)),
});
export const CursorListAvailableModelsResponse = Schema.Struct({
models: Schema.Array(CursorAvailableModel),
});
export function extractAskQuestions(
params: typeof CursorAskQuestionRequest.Type,
): ReadonlyArray<UserInputQuestion> {
+15
View File
@@ -3,6 +3,8 @@ import { assert, it } from "@effect/vitest";
import { ConfigProvider, Effect, Option } from "effect";
import {
createBuildConfig,
MAC_HELPER_BUNDLE_IDS,
resolveBuildOptions,
resolveDesktopBuildIconAssets,
resolveDesktopProductName,
@@ -37,6 +39,19 @@ it.layer(NodeServices.layer)("build-desktop-artifact", (it) => {
});
});
it.effect("pins macOS Electron helper bundle IDs to the T3 Code app identity", () =>
Effect.gen(function* () {
const buildConfig = yield* createBuildConfig("mac", "dmg", "0.0.21", false, false, undefined);
assert.deepStrictEqual(buildConfig.mac, {
target: ["dmg", "zip"],
icon: "icon.icns",
category: "public.app-category.developer-tools",
...MAC_HELPER_BUNDLE_IDS,
});
}),
);
it("falls back to the default mock update port when the configured port is blank", () => {
assert.equal(resolveMockUpdateServerUrl(undefined), "http://localhost:3000");
assert.equal(resolveMockUpdateServerUrl(4123), "http://localhost:4123");
+14 -2
View File
@@ -63,6 +63,17 @@ const PLATFORM_CONFIG: Record<typeof BuildPlatform.Type, PlatformConfig> = {
},
};
const MAC_APP_BUNDLE_ID = "com.t3tools.t3code";
export const MAC_HELPER_BUNDLE_IDS = {
helperBundleId: `${MAC_APP_BUNDLE_ID}.helper`,
helperEHBundleId: `${MAC_APP_BUNDLE_ID}.helper.eh`,
helperGPUBundleId: `${MAC_APP_BUNDLE_ID}.helper.gpu`,
helperNPBundleId: `${MAC_APP_BUNDLE_ID}.helper.np`,
helperPluginBundleId: `${MAC_APP_BUNDLE_ID}.helper.plugin`,
helperRendererBundleId: `${MAC_APP_BUNDLE_ID}.helper.renderer`,
} as const;
interface BuildCliInput {
readonly platform: Option.Option<typeof BuildPlatform.Type>;
readonly target: Option.Option<string>;
@@ -558,7 +569,7 @@ export function resolveDesktopProductName(version: string): string {
: (desktopPackageJson.productName ?? "T3 Code");
}
const createBuildConfig = Effect.fn("createBuildConfig")(function* (
export const createBuildConfig = Effect.fn("createBuildConfig")(function* (
platform: typeof BuildPlatform.Type,
target: string,
version: string,
@@ -567,7 +578,7 @@ const createBuildConfig = Effect.fn("createBuildConfig")(function* (
mockUpdateServerPort: number | undefined,
) {
const buildConfig: Record<string, unknown> = {
appId: "com.t3tools.t3code",
appId: MAC_APP_BUNDLE_ID,
productName: resolveDesktopProductName(version),
artifactName: "T3-Code-${version}-${arch}.${ext}",
directories: {
@@ -592,6 +603,7 @@ const createBuildConfig = Effect.fn("createBuildConfig")(function* (
target: target === "dmg" ? [target, "zip"] : [target],
icon: "icon.icns",
category: "public.app-category.developer-tools",
...MAC_HELPER_BUNDLE_IDS,
};
}