Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bun
import { runBridgeMcpServer } from "./loop/bridge";
import {
BRIDGE_SUBCOMMAND,
BRIDGE_WORKER_SUBCOMMAND,
runBridgeMcpServer,
runBridgeWorker,
} from "./loop/bridge";
} from "./loop/bridge-constants";
import { runBridgeWorker } from "./loop/bridge-runtime";
import { closeClaudeSdk } from "./loop/claude-sdk-server";
import { closeAppServer } from "./loop/codex-app-server";
import {
Expand Down
52 changes: 52 additions & 0 deletions src/loop/bridge-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { mkdirSync, writeFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { BRIDGE_SERVER, BRIDGE_SUBCOMMAND } from "./bridge-constants";
import { buildLaunchArgv } from "./launch";
import type { Agent } from "./types";

const ensureParentDir = (path: string): void => {
mkdirSync(dirname(path), { recursive: true });
};

const stringifyToml = (value: string): string => JSON.stringify(value);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The function stringifyToml uses JSON.stringify, which produces JSON output, not TOML. This naming is misleading. Additionally, please ensure that when communicating between agents in a paired tmux runtime, you use newline-delimited JSON on stdout for agent CLIs, as Content-Length framing can break registration/connection.

Suggested change
const stringifyToml = (value: string): string => JSON.stringify(value);
const stringifyJsonForToml = (value: string): string => JSON.stringify(value);
References
  1. When communicating between agents in a paired tmux runtime, use newline-delimited JSON on stdout for agent CLIs, as Content-Length framing can break registration/connection.


export const buildCodexBridgeConfigArgs = (
runDir: string,
source: Agent
): string[] => {
const [command, ...baseArgs] = buildLaunchArgv();
const args = [...baseArgs, BRIDGE_SUBCOMMAND, runDir, source];
return [
"-c",
`mcp_servers.${BRIDGE_SERVER}.command=${stringifyToml(command)}`,
"-c",
`mcp_servers.${BRIDGE_SERVER}.args=${JSON.stringify(args)}`,
];
};

export const ensureClaudeBridgeConfig = (
runDir: string,
source: Agent
): string => {
const [command, ...baseArgs] = buildLaunchArgv();
const path = join(runDir, `${source}-mcp.json`);
ensureParentDir(path);
writeFileSync(
path,
`${JSON.stringify(
{
mcpServers: {
[BRIDGE_SERVER]: {
args: [...baseArgs, BRIDGE_SUBCOMMAND, runDir, source],
command,
type: "stdio",
},
},
},
null,
2
)}\n`,
"utf8"
);
return path;
};
4 changes: 4 additions & 0 deletions src/loop/bridge-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const BRIDGE_SUBCOMMAND = "__bridge-mcp";
export const BRIDGE_WORKER_SUBCOMMAND = "__bridge-worker";
export const BRIDGE_SERVER = "loop-bridge";
export const CLAUDE_CHANNEL_USER = "Codex";
Loading
Loading