Skip to content

Commit 6d21189

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix/persist-project-action-preview-url
2 parents b36a2f8 + 5ca3266 commit 6d21189

26 files changed

Lines changed: 633 additions & 77 deletions

‎apps/desktop/scripts/electron-launcher.mjs‎

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const APP_BUNDLE_ID = isDevelopment
2020
? `com.t3tools.t3code.dev.${devBundleIdSuffix || "local"}`
2121
: "com.t3tools.t3code";
2222
const APP_PROTOCOL_SCHEMES = isDevelopment ? ["t3code-dev"] : ["t3code"];
23-
const LAUNCHER_VERSION = 12;
23+
const LAUNCHER_VERSION = 14;
2424
const defaultIconPath = NodePath.join(desktopDir, "resources", "icon.icns");
2525
const developmentMacIconPngPath = NodePath.join(
2626
repoRoot,
@@ -220,11 +220,12 @@ function ensureDevelopmentIconIcns(runtimeDir) {
220220
}
221221
}
222222

223-
function patchMainBundleInfoPlist(appBundlePath, iconPath) {
223+
function patchMainBundleInfoPlist(appBundlePath, iconPath, executableName) {
224224
const infoPlistPath = NodePath.join(appBundlePath, "Contents", "Info.plist");
225225
setPlistString(infoPlistPath, "CFBundleDisplayName", APP_DISPLAY_NAME);
226226
setPlistString(infoPlistPath, "CFBundleName", APP_DISPLAY_NAME);
227227
setPlistString(infoPlistPath, "CFBundleIdentifier", APP_BUNDLE_ID);
228+
setPlistString(infoPlistPath, "CFBundleExecutable", executableName);
228229
setPlistString(infoPlistPath, "CFBundleIconFile", "icon.icns");
229230
setPlistJson(infoPlistPath, "CFBundleURLTypes", [
230231
{
@@ -277,11 +278,25 @@ function readJson(path) {
277278
}
278279
}
279280

281+
export function resolveMacLauncherPaths(appBundlePath, displayName = APP_DISPLAY_NAME) {
282+
const executableDir = NodePath.join(appBundlePath, "Contents", "MacOS");
283+
const launcherExecutableName = `${displayName} Launcher`;
284+
return {
285+
launcherExecutableName,
286+
launcherBinaryPath: NodePath.join(executableDir, launcherExecutableName),
287+
runtimeElectronBinaryPath: NodePath.join(executableDir, "Electron"),
288+
};
289+
}
290+
280291
function buildMacLauncher(electronBinaryPath) {
281292
const sourceAppBundlePath = NodePath.resolve(NodePath.dirname(electronBinaryPath), "../..");
282293
const runtimeDir = NodePath.join(desktopDir, ".electron-runtime");
283294
const targetAppBundlePath = NodePath.join(runtimeDir, `${APP_DISPLAY_NAME}.app`);
284-
const targetBinaryPath = NodePath.join(targetAppBundlePath, "Contents", "MacOS", "Electron");
295+
const developmentPaths = resolveMacLauncherPaths(targetAppBundlePath);
296+
const runtimeElectronBinaryPath = developmentPaths.runtimeElectronBinaryPath;
297+
const launcherBinaryPath = isDevelopment
298+
? developmentPaths.launcherBinaryPath
299+
: runtimeElectronBinaryPath;
285300
const iconPath = isDevelopment ? ensureDevelopmentIconIcns(runtimeDir) : defaultIconPath;
286301
const metadataPath = NodePath.join(runtimeDir, "metadata.json");
287302

@@ -298,18 +313,19 @@ function buildMacLauncher(electronBinaryPath) {
298313

299314
const currentMetadata = readJson(metadataPath);
300315
if (
301-
NodeFS.existsSync(targetBinaryPath) &&
316+
NodeFS.existsSync(launcherBinaryPath) &&
317+
(!isDevelopment || NodeFS.existsSync(runtimeElectronBinaryPath)) &&
302318
currentMetadata &&
303319
JSON.stringify(currentMetadata) === JSON.stringify(expectedMetadata)
304320
) {
305321
if (isDevelopment) {
306322
// The launcher also handles protocol activations outside the dev runner,
307323
// so refresh its fallback environment on every launch. Never let a value
308324
// captured by an older parent app override the live dev-runner environment.
309-
writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath);
325+
writeDevelopmentLauncherScript(launcherBinaryPath, runtimeElectronBinaryPath);
310326
}
311327
registerMacLauncherBundle(targetAppBundlePath);
312-
return targetBinaryPath;
328+
return launcherBinaryPath;
313329
}
314330

315331
NodeFS.rmSync(targetAppBundlePath, { recursive: true, force: true });
@@ -321,15 +337,24 @@ function buildMacLauncher(electronBinaryPath) {
321337
recursive: true,
322338
verbatimSymlinks: true,
323339
});
324-
patchMainBundleInfoPlist(targetAppBundlePath, iconPath);
340+
patchMainBundleInfoPlist(
341+
targetAppBundlePath,
342+
iconPath,
343+
isDevelopment ? developmentPaths.launcherExecutableName : "Electron",
344+
);
325345
patchHelperBundleInfoPlists(targetAppBundlePath);
326346
if (isDevelopment) {
327-
writeDevelopmentLauncherScript(targetBinaryPath, electronBinaryPath);
347+
// Keep Electron's native executable inside the branded bundle. Launching the
348+
// node_modules copy makes macOS associate the process (and Dock label) with
349+
// Electron.app even though this bundle's Info.plist has the T3 Code name.
350+
// Its conventional executable name also keeps Electron's default-app runtime
351+
// in development mode instead of making app.isPackaged report true.
352+
writeDevelopmentLauncherScript(launcherBinaryPath, runtimeElectronBinaryPath);
328353
}
329354
NodeFS.writeFileSync(metadataPath, `${JSON.stringify(expectedMetadata, null, 2)}\n`);
330355
registerMacLauncherBundle(targetAppBundlePath);
331356

332-
return targetBinaryPath;
357+
return launcherBinaryPath;
333358
}
334359

335360
function isLinuxSetuidSandboxConfigured(electronBinaryPath) {

‎apps/desktop/scripts/electron-launcher.test.mjs‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { assert, describe, it } from "vite-plus/test";
22

3-
import { makeDevelopmentLauncherScript, resolveElectronBinaryPath } from "./electron-launcher.mjs";
3+
import {
4+
makeDevelopmentLauncherScript,
5+
resolveElectronBinaryPath,
6+
resolveMacLauncherPaths,
7+
} from "./electron-launcher.mjs";
48

59
describe("electron development launcher", () => {
610
it("uses captured values only as fallbacks for a live runner environment", () => {
@@ -45,4 +49,33 @@ describe("electron development launcher", () => {
4549
);
4650
assert.deepEqual(calls, ["ensure", "require:electron"]);
4751
});
52+
53+
it("keeps the native Electron executable name inside the branded macOS bundle", () => {
54+
const paths = resolveMacLauncherPaths(
55+
"/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app",
56+
"T3 Code (Dev)",
57+
);
58+
59+
assert.equal(paths.launcherExecutableName, "T3 Code (Dev) Launcher");
60+
assert.equal(
61+
paths.launcherBinaryPath,
62+
"/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/T3 Code (Dev) Launcher",
63+
);
64+
assert.equal(
65+
paths.runtimeElectronBinaryPath,
66+
"/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/Electron",
67+
);
68+
69+
const script = makeDevelopmentLauncherScript({
70+
electronBinaryPath: paths.runtimeElectronBinaryPath,
71+
mainEntryPath: "/repo/apps/desktop/dist-electron/main.cjs",
72+
desktopRoot: "/repo/apps/desktop",
73+
environment: {},
74+
});
75+
assert.include(
76+
script,
77+
"exec '/repo/apps/desktop/.electron-runtime/T3 Code (Dev).app/Contents/MacOS/Electron'",
78+
);
79+
assert.notInclude(script, "node_modules/electron");
80+
});
4881
});

‎apps/server/src/persistence/ProviderSessionRuntime.ts‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import * as Arr from "effect/Array";
12
import * as Context from "effect/Context";
23
import * as Effect from "effect/Effect";
34
import * as Layer from "effect/Layer";
45
import * as Option from "effect/Option";
6+
import * as Result from "effect/Result";
57
import * as Schema from "effect/Schema";
68
import * as Struct from "effect/Struct";
79
import * as SqlClient from "effect/unstable/sql/SqlClient";
@@ -280,18 +282,30 @@ export const make = Effect.gen(function* () {
280282
),
281283
),
282284
Effect.flatMap((rows) =>
285+
// Skip rows that no longer decode (e.g. written by an older build)
286+
// instead of failing the whole list — one stale row must not disable
287+
// every consumer that enumerates sessions, such as the reaper.
283288
Effect.forEach(rows, (row) =>
284289
decodeRuntimeRow(row).pipe(
285-
Effect.mapError((cause) =>
286-
PersistenceDecodeError.fromSchemaError(
287-
"ProviderSessionRuntimeRepository.list:decodeRows",
288-
cause,
289-
{ threadId: row.threadId },
290-
),
290+
Effect.map(Option.some),
291+
Effect.catch((cause) =>
292+
Effect.logWarning("provider.session.runtime.row-skipped", {
293+
threadId: row.threadId,
294+
error: PersistenceDecodeError.fromSchemaError(
295+
"ProviderSessionRuntimeRepository.list:decodeRows",
296+
cause,
297+
{ threadId: row.threadId },
298+
).message,
299+
}).pipe(Effect.as(Option.none<ProviderSessionRuntime>())),
291300
),
292301
),
293302
),
294303
),
304+
Effect.map((decoded) =>
305+
Arr.filterMap(decoded, (row) =>
306+
Option.isSome(row) ? Result.succeed(row.value) : Result.failVoid,
307+
),
308+
),
295309
);
296310

297311
const deleteByThreadId: ProviderSessionRuntimeRepository["Service"]["deleteByThreadId"] = (

‎apps/server/src/persistence/RepositoryErrorCorrelation.test.ts‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ describe("persistence error correlation", () => {
182182
}).pipe(Effect.provide(authPairingLinkLayer)),
183183
);
184184

185-
it.effect("correlates provider runtime SQL and per-row decode failures by thread", () =>
185+
it.effect("skips undecodable provider runtime rows and correlates SQL failures by thread", () =>
186186
Effect.gen(function* () {
187187
const runtimes = yield* ProviderSessionRuntime.ProviderSessionRuntimeRepository;
188188
const sql = yield* SqlClient.SqlClient;
@@ -215,16 +215,24 @@ describe("persistence error correlation", () => {
215215
)
216216
`;
217217

218-
const decodeError = yield* Effect.flip(runtimes.list());
219-
assert.instanceOf(decodeError, PersistenceErrors.PersistenceDecodeError);
220-
assert.deepStrictEqual(decodeError.correlation, { threadId });
221-
assert.equal(
222-
decodeError.message,
223-
`Decode error in ProviderSessionRuntimeRepository.list:decodeRows: ${decodeError.issue}`,
218+
const validThreadId = ThreadId.make("thread-valid");
219+
yield* runtimes.upsert({
220+
threadId: validThreadId,
221+
providerName: "codex",
222+
providerInstanceId: null,
223+
adapterKey: "codex",
224+
runtimeMode: "full-access",
225+
status: "running",
226+
lastSeenAt,
227+
resumeCursor: null,
228+
runtimePayload: null,
229+
});
230+
231+
const listed = yield* runtimes.list();
232+
assert.deepStrictEqual(
233+
listed.map((runtime) => runtime.threadId),
234+
[validThreadId],
224235
);
225-
assert.notInclude(decodeError.issue, runtimePayload);
226-
assert.notInclude(decodeError.message, runtimePayload);
227-
assert.notInclude(decodeError.message, lastSeenAt);
228236

229237
yield* sql`DROP TABLE provider_session_runtime`;
230238
const sqlFailure = yield* Effect.flip(

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ProviderInteractionMode } from "@t3tools/contracts";
2+
13
const T3_CODE_BROWSER_TOOL_INSTRUCTIONS = `
24
35
## T3 Code collaborative browser
@@ -145,3 +147,26 @@ The \`request_user_input\` tool is unavailable in Default mode. If you call it w
145147
In Default mode, strongly prefer making reasonable assumptions and executing the user's request rather than stopping to ask questions. If you absolutely must ask a question because the answer cannot be discovered from local context and a reasonable assumption would be risky, ask the user directly with a concise plain-text question. Never write a multiple choice question as a textual assistant message.
146148
${T3_CODE_BROWSER_TOOL_INSTRUCTIONS}
147149
</collaboration_mode>`;
150+
151+
export interface CodexRuntimeInfo {
152+
readonly model: string;
153+
readonly reasoningEffort: string;
154+
}
155+
156+
// Values come from trusted config, but keep the block single-line regardless.
157+
function toSingleLine(value: string): string {
158+
return value.replaceAll(/\s+/g, " ").trim();
159+
}
160+
161+
export function buildCodexDeveloperInstructions(
162+
interactionMode: ProviderInteractionMode,
163+
runtime: CodexRuntimeInfo,
164+
): string {
165+
const base =
166+
interactionMode === "plan"
167+
? CODEX_PLAN_MODE_DEVELOPER_INSTRUCTIONS
168+
: CODEX_DEFAULT_MODE_DEVELOPER_INSTRUCTIONS;
169+
return `${base}
170+
171+
<runtime_info>In case you're asked: you are running in T3 Code through the Codex harness, as ${toSingleLine(runtime.model)} with ${toSingleLine(runtime.reasoningEffort)} reasoning effort. No need to mention this otherwise.</runtime_info>`;
172+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv> = {
119119
Effect.gen(function* () {
120120
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
121121
const path = yield* Path.Path;
122+
const { cwd } = yield* ServerConfig;
122123
const httpClient = yield* HttpClient.HttpClient;
123124
const serverSettings = yield* ServerSettingsService;
124125
const eventLoggers = yield* ProviderEventLoggers;
@@ -154,11 +155,11 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv> = {
154155
capacity: 1,
155156
timeToLive: CAPABILITIES_PROBE_TTL,
156157
lookup: () =>
157-
probeClaudeCapabilities(effectiveConfig, processEnv).pipe(
158+
probeClaudeCapabilities(effectiveConfig, processEnv, cwd).pipe(
158159
Effect.provideService(Path.Path, path),
159160
),
160161
});
161-
const capabilitiesCacheKey = yield* makeClaudeCapabilitiesCacheKey(effectiveConfig);
162+
const capabilitiesCacheKey = yield* makeClaudeCapabilitiesCacheKey(effectiveConfig, cwd);
162163

163164
const checkProvider = checkClaudeProviderStatus(
164165
effectiveConfig,

‎apps/server/src/provider/Drivers/ClaudeHome.test.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,20 @@ it.layer(NodeServices.layer)("ClaudeHome", (it) => {
3434
expect((yield* makeClaudeEnvironment({ homePath })).CLAUDE_CONFIG_DIR).toBe(resolved);
3535
expect(yield* makeClaudeContinuationGroupKey({ homePath })).toBe(`claude:home:${resolved}`);
3636
expect(yield* makeClaudeCapabilitiesCacheKey({ binaryPath: "claude", homePath })).toBe(
37-
`claude\0${resolved}`,
37+
`claude\0${resolved}\0`,
3838
);
3939
}),
4040
);
4141

42+
it.effect("separates capability probes by cwd", () =>
43+
Effect.gen(function* () {
44+
const config = { binaryPath: "claude", homePath: "" };
45+
const first = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-a");
46+
const second = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-b");
47+
expect(first).not.toBe(second);
48+
}),
49+
);
50+
4251
it.effect("keeps continuation compatible across instances with the same Claude HOME", () =>
4352
Effect.gen(function* () {
4453
const path = yield* Path.Path;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ export const makeClaudeContinuationGroupKey = Effect.fn("makeClaudeContinuationG
4444
export const makeClaudeCapabilitiesCacheKey = Effect.fn("makeClaudeCapabilitiesCacheKey")(
4545
function* (
4646
config: Pick<ClaudeSettings, "binaryPath" | "homePath">,
47+
cwd?: string,
4748
): Effect.fn.Return<string, never, Path.Path> {
4849
const resolvedHomePath = yield* resolveClaudeHomePath(config);
49-
return `${config.binaryPath}\0${resolvedHomePath}`;
50+
return `${config.binaryPath}\0${resolvedHomePath}\0${cwd ?? ""}`;
5051
},
5152
);

‎apps/server/src/provider/Drivers/CodexHomeLayout.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
114114

115115
const sessionsTarget = yield* fileSystem.readLink(path.join(shadowHome, "sessions"));
116116
const configTarget = yield* fileSystem.readLink(path.join(shadowHome, "config.toml"));
117+
const mcpOauthLocksTarget = yield* fileSystem.readLink(
118+
path.join(shadowHome, "mcp-oauth-locks"),
119+
);
117120
const modelsCacheExists = yield* fileSystem.exists(
118121
path.join(shadowHome, "models_cache.json"),
119122
);
@@ -124,12 +127,45 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
124127

125128
expect(sessionsTarget).toBe(path.join(sharedHome, "sessions"));
126129
expect(configTarget).toBe(path.join(sharedHome, "config.toml"));
130+
expect(mcpOauthLocksTarget).toBe(path.join(sharedHome, "mcp-oauth-locks"));
127131
expect(modelsCacheExists).toBe(false);
128132
expect(authLinkResult._tag).toBe("Failure");
129133
expect(authContents).toContain("shadow");
130134
}),
131135
);
132136

137+
it.effect("replaces Codex-created local MCP OAuth locks with the shared lock directory", () =>
138+
Effect.gen(function* () {
139+
const fileSystem = yield* FileSystem.FileSystem;
140+
const path = yield* Path.Path;
141+
const sharedHome = yield* makeTempDir("t3code-codex-shared-");
142+
const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
143+
const shadowHome = path.join(shadowRoot, "shadow");
144+
const sharedLocks = path.join(sharedHome, "mcp-oauth-locks");
145+
const shadowLocks = path.join(shadowHome, "mcp-oauth-locks");
146+
147+
yield* writeTextFile(path.join(sharedLocks, "file-store.lock"), "");
148+
yield* writeTextFile(path.join(shadowLocks, "file-store.lock"), "");
149+
150+
const layout = yield* resolveCodexHomeLayout(
151+
decodeCodexSettings({
152+
homePath: sharedHome,
153+
shadowHomePath: shadowHome,
154+
}),
155+
);
156+
157+
yield* materializeCodexShadowHome(layout);
158+
159+
const locksTarget = yield* fileSystem.readLink(shadowLocks);
160+
const sharedLockExists = yield* fileSystem.exists(
161+
path.join(sharedLocks, "file-store.lock"),
162+
);
163+
164+
expect(locksTarget).toBe(sharedLocks);
165+
expect(sharedLockExists).toBe(true);
166+
}),
167+
);
168+
133169
it.effect("accepts Codex-created shadow-local runtime directories", () =>
134170
Effect.gen(function* () {
135171
const fileSystem = yield* FileSystem.FileSystem;

0 commit comments

Comments
 (0)