Skip to content

Commit 37b0f6a

Browse files
t3dotggclaude
andcommitted
fix(server): run agentcast with a real Node runtime in packaged builds
Review finding (Macroscope): in the single-file (Node SEA) CLI build, process.execPath is the t3 binary, so agentcast's MCP server did not start. The adapters now resolve the runtime once with resolveNodeExecutable, as the device tools do: the server's own Node or Electron binary, or the node on PATH in a packaged build. With none, agentcast stays off and a warning is logged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 904bdb4 commit 37b0f6a

5 files changed

Lines changed: 124 additions & 35 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {
2727
AGENTCAST_MCP_SERVER,
2828
AGENTCAST_READ_ONLY_TOOLS,
2929
agentcastStdioServer,
30+
resolveAgentcastLauncher,
31+
type AgentcastLauncher,
3032
} from "../../provider/agentcastMcp.ts";
3133
import {
3234
type CanUseTool,
@@ -1723,6 +1725,7 @@ export function claudeMcpQueryOverrides(input: {
17231725
readonly mcpSession: McpProviderSession.McpProviderSessionConfig | undefined;
17241726
readonly readOnlySandbox: boolean;
17251727
/** agentcast's write tools are pre-approved only in full-access; elsewhere canUseTool asks. */
1728+
readonly agentcast?: AgentcastLauncher | undefined;
17261729
readonly fullAccess?: boolean;
17271730
readonly allowedTools?: ReadonlyArray<string>;
17281731
}): {
@@ -1736,7 +1739,7 @@ export function claudeMcpQueryOverrides(input: {
17361739
const mcpAllowedTools = input.readOnlySandbox
17371740
? CLAUDE_READ_ONLY_T3_MCP_ALLOWED_TOOLS
17381741
: [CLAUDE_T3_MCP_TOOL_WILDCARD];
1739-
const agentcast = agentcastStdioServer(session.threadId);
1742+
const agentcast = agentcastStdioServer(session.threadId, input.agentcast);
17401743
const agentcastAllowedTools =
17411744
agentcast === undefined
17421745
? []
@@ -4524,6 +4527,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
45244527
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
45254528
const serverSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService);
45264529
const { attachmentsDir, fileSystem, path, crypto, idAllocator, queryRunner } = adapterOptions;
4530+
const agentcastLauncher = yield* resolveAgentcastLauncher();
45274531
const subagentModelCatalog = scopeClaudeModelCatalog(
45284532
BUNDLED_CLAUDE_MODEL_CATALOG,
45294533
adapterOptions.settings.customModels,
@@ -10115,6 +10119,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1011510119
const queryPolicy = yield* queryPolicyForTurn(turnInput);
1011610120
const mcpSession = yield* mcpSessions.read(turnInput.threadId);
1011710121
const mcpOverrides = claudeMcpQueryOverrides({
10122+
agentcast: agentcastLauncher,
1011810123
mcpSession,
1011910124
readOnlySandbox:
1012010125
sandboxPolicyKindForClaudeRuntimePolicy(turnInput.runtimePolicy) === "readOnly",

‎apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ import {
126126
AGENTCAST_MCP_SERVER,
127127
agentcastCodexApprovals,
128128
agentcastStdioServer,
129+
resolveAgentcastLauncher,
130+
type AgentcastLauncher,
129131
} from "../../provider/agentcastMcp.ts";
130132
import {
131133
MCP_APP_EXTENSION_ID,
@@ -1328,8 +1330,9 @@ const CODEX_T3_MCP_TOOL_TIMEOUT_SEC = 65 * 60;
13281330
function codexAgentcastConfig(
13291331
threadId: string,
13301332
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy | undefined,
1333+
launcher: AgentcastLauncher | undefined,
13311334
): Record<string, Schema.Json> {
1332-
const agentcast = agentcastStdioServer(threadId);
1335+
const agentcast = agentcastStdioServer(threadId, launcher);
13331336
if (agentcast === undefined) return {};
13341337
return {
13351338
[`mcp_servers.${AGENTCAST_MCP_SERVER}`]: {
@@ -1350,15 +1353,17 @@ function codexAgentcastConfig(
13501353
function codexAgentcastApprovalsKey(
13511354
mcpSession: McpProviderSession.McpProviderSessionConfig | undefined,
13521355
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy | undefined,
1356+
launcher: AgentcastLauncher | undefined,
13531357
): string | undefined {
1354-
if (mcpSession === undefined || agentcastStdioServer(mcpSession.threadId) === undefined) {
1358+
if (mcpSession === undefined || launcher === undefined) {
13551359
return undefined;
13561360
}
13571361
return JSON.stringify(agentcastCodexApprovals(runtimePolicy));
13581362
}
13591363

13601364
function codexThreadRuntimeParams(input: {
13611365
readonly mcpSession: McpProviderSession.McpProviderSessionConfig | undefined;
1366+
readonly agentcast: AgentcastLauncher | undefined;
13621367
readonly modelSelection?: { readonly model: string };
13631368
readonly runtimePolicy?: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
13641369
}): {
@@ -1383,7 +1388,7 @@ function codexThreadRuntimeParams(input: {
13831388
Authorization: mcpSession.authorizationHeader,
13841389
},
13851390
},
1386-
...codexAgentcastConfig(mcpSession.threadId, input.runtimePolicy),
1391+
...codexAgentcastConfig(mcpSession.threadId, input.runtimePolicy, input.agentcast),
13871392
}),
13881393
},
13891394
};
@@ -1663,6 +1668,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
16631668
threadId === null ? Effect.succeed(undefined) : mcpSessions.read(threadId);
16641669
const { clientFactory, crypto, fileSystem, idAllocator, serverConfig } = adapterOptions;
16651670
const continuationRequests = adapterOptions.continuationRequests;
1671+
const agentcastLauncher = yield* resolveAgentcastLauncher();
16661672

16671673
return ProviderAdapter.ProviderAdapterV2.of({
16681674
instanceId: adapterOptions.instanceId,
@@ -1871,7 +1877,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
18711877
mcpSession: McpProviderSession.McpProviderSessionConfig | undefined,
18721878
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy | undefined,
18731879
) => {
1874-
const key = codexAgentcastApprovalsKey(mcpSession, runtimePolicy);
1880+
const key = codexAgentcastApprovalsKey(mcpSession, runtimePolicy, agentcastLauncher);
18751881
if (key === undefined) agentcastApprovalsByThread.delete(nativeThreadId);
18761882
else agentcastApprovalsByThread.set(nativeThreadId, key);
18771883
};
@@ -6682,7 +6688,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
66826688
mcpSession: McpProviderSession.McpProviderSessionConfig | undefined,
66836689
runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy | undefined,
66846690
) {
6685-
const wanted = codexAgentcastApprovalsKey(mcpSession, runtimePolicy);
6691+
const wanted = codexAgentcastApprovalsKey(mcpSession, runtimePolicy, agentcastLauncher);
66866692
if (wanted === undefined || agentcastApprovalsByThread.get(nativeThreadId) === wanted) {
66876693
return false;
66886694
}
@@ -6708,6 +6714,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
67086714
threadId,
67096715
excludeTurns: true,
67106716
...codexThreadRuntimeParams({
6717+
agentcast: agentcastLauncher,
67116718
mcpSession,
67126719
modelSelection: turnInput.modelSelection,
67136720
runtimePolicy: turnInput.runtimePolicy,
@@ -7031,6 +7038,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
70317038
.request(
70327039
"thread/start",
70337040
codexThreadRuntimeParams({
7041+
agentcast: agentcastLauncher,
70347042
mcpSession,
70357043
modelSelection: threadInput.modelSelection,
70367044
runtimePolicy: threadInput.runtimePolicy,
@@ -7088,6 +7096,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
70887096
threadId: nativeThreadId,
70897097
excludeTurns: true,
70907098
...codexThreadRuntimeParams({
7099+
agentcast: agentcastLauncher,
70917100
mcpSession,
70927101
...(threadInput.modelSelection === undefined
70937102
? {}
@@ -7877,6 +7886,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
78777886
threadId,
78787887
excludeTurns: true,
78797888
...codexThreadRuntimeParams({
7889+
agentcast: agentcastLauncher,
78807890
mcpSession,
78817891
modelSelection: input.modelSelection,
78827892
runtimePolicy: input.runtimePolicy,
@@ -7931,6 +7941,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
79317941
? {}
79327942
: { lastTurnId: boundary.lastTurnId }),
79337943
...codexThreadRuntimeParams({
7944+
agentcast: agentcastLauncher,
79347945
mcpSession,
79357946
...(threadInput.modelSelection === undefined
79367947
? {}

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

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,70 @@
1+
import * as NodeServices from "@effect/platform-node/NodeServices";
2+
import { assert, it as effectIt } from "@effect/vitest";
3+
import * as HostProcess from "@t3tools/shared/HostProcess";
4+
import * as Effect from "effect/Effect";
15
import { describe, expect, it } from "vite-plus/test";
26

3-
import { agentcastCodexApprovals, agentcastStdioServer } from "./agentcastMcp.ts";
7+
import {
8+
agentcastCodexApprovals,
9+
agentcastStdioServer,
10+
resolveAgentcastLauncher,
11+
} from "./agentcastMcp.ts";
412

5-
describe("agentcastStdioServer", () => {
6-
it("is off unless T3CODE_AGENTCAST_MAIN is set", () => {
7-
expect(agentcastStdioServer("thread-1", {})).toBeUndefined();
8-
});
13+
describe("resolveAgentcastLauncher", () => {
14+
effectIt.effect("is off unless T3CODE_AGENTCAST_MAIN is set", () =>
15+
Effect.gen(function* () {
16+
assert.isUndefined(yield* resolveAgentcastLauncher({}));
17+
}).pipe(Effect.provide(NodeServices.layer)),
18+
);
19+
20+
effectIt.effect("runs agentcast with the server's own runtime when it is Node", () =>
21+
Effect.gen(function* () {
22+
const launcher = yield* resolveAgentcastLauncher({
23+
T3CODE_AGENTCAST_MAIN: "/opt/agentcast/dist/agentcast.mjs",
24+
SSH_AUTH_SOCK: "/tmp/agent.sock",
25+
}).pipe(
26+
Effect.provideService(HostProcess.IsExecutable, false),
27+
Effect.provideService(HostProcess.ExecutablePath, "/usr/bin/node"),
28+
);
29+
assert.deepStrictEqual(launcher, {
30+
node: "/usr/bin/node",
31+
main: "/opt/agentcast/dist/agentcast.mjs",
32+
env: { SSH_AUTH_SOCK: "/tmp/agent.sock" },
33+
});
34+
}).pipe(Effect.provide(NodeServices.layer)),
35+
);
36+
37+
effectIt.effect("is off in a packaged binary with no Node.js on PATH", () =>
38+
Effect.gen(function* () {
39+
const launcher = yield* resolveAgentcastLauncher({
40+
T3CODE_AGENTCAST_MAIN: "/opt/agentcast/dist/agentcast.mjs",
41+
PATH: "/nonexistent",
42+
}).pipe(
43+
Effect.provideService(HostProcess.IsExecutable, true),
44+
Effect.provideService(HostProcess.ExecutablePath, "/opt/t3/t3"),
45+
);
46+
assert.isUndefined(launcher);
47+
}).pipe(Effect.provide(NodeServices.layer)),
48+
);
49+
});
950

51+
describe("agentcastStdioServer", () => {
1052
it("runs agentcast mcp with the thread as its client name", () => {
1153
const server = agentcastStdioServer("thread-1", {
12-
T3CODE_AGENTCAST_MAIN: "/opt/agentcast/dist/main.js",
54+
node: "/usr/bin/node",
55+
main: "/opt/agentcast/dist/agentcast.mjs",
56+
env: { SSH_AUTH_SOCK: "/tmp/agent.sock" },
1357
});
14-
expect(server?.args).toEqual(["/opt/agentcast/dist/main.js", "mcp"]);
15-
expect(server?.env.AGENTCAST_CLIENT).toBe("t3:thread-1");
16-
});
17-
18-
it("passes the ssh agent socket through", () => {
19-
const server = agentcastStdioServer("t", {
20-
T3CODE_AGENTCAST_MAIN: "/x/main.js",
58+
expect(server?.command).toBe("/usr/bin/node");
59+
expect(server?.args).toEqual(["/opt/agentcast/dist/agentcast.mjs", "mcp"]);
60+
expect(server?.env).toMatchObject({
61+
AGENTCAST_CLIENT: "t3:thread-1",
2162
SSH_AUTH_SOCK: "/tmp/agent.sock",
2263
});
23-
expect(server?.env.SSH_AUTH_SOCK).toBe("/tmp/agent.sock");
64+
});
65+
66+
it("is off without a launcher", () => {
67+
expect(agentcastStdioServer("thread-1", undefined)).toBeUndefined();
2468
});
2569
});
2670

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

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import * as Effect from "effect/Effect";
12
import type * as Schema from "effect/Schema";
3+
import { resolveNodeExecutable } from "@t3tools/shared/nodeRuntime";
24

35
/**
46
* agentcast gives agents remote Windows desktops (UI trees, background input, a lock gate and
@@ -27,33 +29,59 @@ export interface AgentcastStdioServer {
2729
readonly env: Readonly<Record<string, string>>;
2830
}
2931

32+
/** How to start `agentcast mcp`: the same for every thread, resolved once per adapter. */
33+
export interface AgentcastLauncher {
34+
readonly node: string;
35+
readonly main: string;
36+
readonly env: Readonly<Record<string, string>>;
37+
}
38+
3039
// MCP stdio clients start servers with a short default environment. agentcast needs the ssh
3140
// agent socket for its SSH keys, and its own host settings.
3241
const PASSED_THROUGH = ["SSH_AUTH_SOCK", "AGENTCAST_HOSTS", "AGENTCAST_HOSTS_JSON"] as const;
3342

3443
/**
35-
* The stdio command for one thread, or undefined when agentcast is not configured.
36-
* `AGENTCAST_CLIENT` names the thread in each host's journal and gives it its own engine session.
44+
* The launcher, or undefined when agentcast is off or no Node runtime is found. A packaged T3
45+
* binary cannot run agentcast's CLI itself, so this finds Node as the device tools do.
46+
*/
47+
export const resolveAgentcastLauncher = Effect.fn("agentcastMcp.resolveAgentcastLauncher")(
48+
function* (env: NodeJS.ProcessEnv = process.env) {
49+
// The opt-in switch. Set it only on machines with agentcast hosts: the tool list costs about
50+
// 9k tokens in every session.
51+
const main = env.T3CODE_AGENTCAST_MAIN;
52+
if (!main) return undefined;
53+
const node = yield* resolveNodeExecutable("Remote desktops", env).pipe(
54+
Effect.catch((cause) =>
55+
Effect.logWarning("agentcast is configured but no Node.js runtime was found", {
56+
cause,
57+
}).pipe(Effect.as(undefined)),
58+
),
59+
);
60+
if (node === undefined) return undefined;
61+
const passed = Object.fromEntries(
62+
PASSED_THROUGH.flatMap((name) => (env[name] ? [[name, env[name]]] : [])),
63+
);
64+
return { node, main, env: passed } satisfies AgentcastLauncher;
65+
},
66+
);
67+
68+
/**
69+
* The stdio command for one thread, or undefined without a launcher. `AGENTCAST_CLIENT` names the
70+
* thread in each host's journal and gives it its own engine session.
3771
*/
3872
export function agentcastStdioServer(
3973
threadId: string,
40-
env: NodeJS.ProcessEnv = process.env,
74+
launcher: AgentcastLauncher | undefined,
4175
): AgentcastStdioServer | undefined {
42-
// The opt-in switch. Set it only on machines with agentcast hosts: the tool list costs about
43-
// 9k tokens in every session.
44-
const main = env.T3CODE_AGENTCAST_MAIN;
45-
if (!main) return undefined;
46-
const passed = Object.fromEntries(
47-
PASSED_THROUGH.flatMap((name) => (env[name] ? [[name, env[name]]] : [])),
48-
);
76+
if (launcher === undefined) return undefined;
4977
return {
50-
command: process.execPath,
51-
args: [main, "mcp"],
78+
command: launcher.node,
79+
args: [launcher.main, "mcp"],
5280
env: {
53-
...passed,
81+
...launcher.env,
5482
AGENTCAST_CLIENT: `t3:${threadId}`,
55-
// Inside the packaged app, process.execPath is Electron: run it as Node.
56-
...(process.versions.electron ? { ELECTRON_RUN_AS_NODE: "1" } : {}),
83+
// In the desktop app the runtime is Electron's binary: run it as Node. Node ignores this.
84+
ELECTRON_RUN_AS_NODE: "1",
5785
},
5886
};
5987
}

‎packages/shared/src/nodeRuntime.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const NodeRuntimeFeature = Schema.Literals([
1212
"Device automation",
1313
"Antigravity",
1414
"Antigravity sign-in",
15+
"Remote desktops",
1516
]);
1617

1718
export const nodeRuntimeUnavailableMessage = (feature: typeof NodeRuntimeFeature.Type): string =>

0 commit comments

Comments
 (0)