@botbuddy/cli 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/codex-bridge.mjs +76 -37
- package/src/commands.mjs +2 -2
- package/src/version.mjs +6 -0
package/package.json
CHANGED
package/src/codex-bridge.mjs
CHANGED
|
@@ -9,16 +9,19 @@
|
|
|
9
9
|
* - Bridge ↔ Codex app-server: localhost-only WS with nonce handshake
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
|
-
* botbuddy
|
|
12
|
+
* botbuddy start [--port 4500] [--repo /path/to/repo] [--model gpt-5.4]
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { createHash, randomBytes } from "crypto";
|
|
16
16
|
import { getConfig, SERVER_URL } from "./config.mjs";
|
|
17
17
|
import { green, red, cyan, dim, bold, yellow, die } from "./utils.mjs";
|
|
18
|
+
import { VERSION } from "./version.mjs";
|
|
18
19
|
|
|
19
20
|
const RELAY_URL = SERVER_URL.replace("/mcp-server", "/codex-relay");
|
|
20
21
|
const POLL_INTERVAL_MS = 2000;
|
|
21
22
|
const PING_INTERVAL_MS = 15000;
|
|
23
|
+
const STARTUP_TIMEOUT_MS = 5000;
|
|
24
|
+
const READY_POLL_INTERVAL_MS = 250;
|
|
22
25
|
|
|
23
26
|
// ─── HMAC signing ───────────────────────────────────────────────
|
|
24
27
|
let sessionSecret = null;
|
|
@@ -37,10 +40,33 @@ async function signRequest(sessionId) {
|
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
function sleep(ms) {
|
|
44
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function waitForCodexReady(readyUrl, timeoutMs = STARTUP_TIMEOUT_MS) {
|
|
48
|
+
const deadline = Date.now() + timeoutMs;
|
|
49
|
+
|
|
50
|
+
while (Date.now() < deadline) {
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetch(readyUrl);
|
|
53
|
+
if (res.ok) return true;
|
|
54
|
+
} catch {}
|
|
55
|
+
|
|
56
|
+
await sleep(READY_POLL_INTERVAL_MS);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function isAddressInUseError(text) {
|
|
63
|
+
return /address already in use|eaddrinuse|os error 48/i.test(text);
|
|
64
|
+
}
|
|
65
|
+
|
|
40
66
|
export async function runBridge(args) {
|
|
41
67
|
const cfg = getConfig();
|
|
42
68
|
if (!cfg.api_key && !cfg.access_token) {
|
|
43
|
-
die(`Not authenticated. Run: ${cyan("botbuddy
|
|
69
|
+
die(`Not authenticated. Run: ${cyan("botbuddy start")} or ${cyan("botbuddy login")}`);
|
|
44
70
|
}
|
|
45
71
|
|
|
46
72
|
// Parse args
|
|
@@ -57,10 +83,11 @@ export async function runBridge(args) {
|
|
|
57
83
|
}
|
|
58
84
|
|
|
59
85
|
const wsUrl = `ws://127.0.0.1:${wsPort}`;
|
|
86
|
+
const readyUrl = `http://127.0.0.1:${wsPort}/readyz`;
|
|
60
87
|
const { hostname: getHostname } = await import("os");
|
|
61
88
|
const host = getHostname();
|
|
62
89
|
|
|
63
|
-
console.log(`${bold("BotBuddy Codex Bridge")}\n`);
|
|
90
|
+
console.log(`${bold("BotBuddy Codex Bridge")} ${dim(`v${VERSION}`)}\n`);
|
|
64
91
|
console.log(` ${dim("WebSocket:")} ${cyan(wsUrl)}`);
|
|
65
92
|
console.log(` ${dim("Repo:")} ${cyan(repoPath)}`);
|
|
66
93
|
console.log(` ${dim("Model:")} ${cyan(model)}`);
|
|
@@ -70,45 +97,57 @@ export async function runBridge(args) {
|
|
|
70
97
|
// ── Step 0: Auto-start codex app-server ──
|
|
71
98
|
let serverProc = null;
|
|
72
99
|
if (!noServer) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
100
|
+
const existingServerReady = await waitForCodexReady(readyUrl, 750);
|
|
101
|
+
|
|
102
|
+
if (existingServerReady) {
|
|
103
|
+
console.log(dim("→ Reusing existing codex app-server..."));
|
|
104
|
+
console.log(` ${green("✓")} codex app-server already running on port ${wsPort}`);
|
|
105
|
+
} else {
|
|
106
|
+
console.log(dim("→ Starting codex app-server..."));
|
|
107
|
+
const { spawn } = await import("child_process");
|
|
108
|
+
serverProc = spawn("codex", ["app-server", "--listen", wsUrl], {
|
|
109
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
110
|
+
env: { ...process.env },
|
|
111
|
+
});
|
|
79
112
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
113
|
+
serverProc.on("error", (err) => {
|
|
114
|
+
if (err.code === "ENOENT") {
|
|
115
|
+
console.log(` ${red("✗")} 'codex' not found in PATH. Install it or use ${cyan("--no-server")} to skip.`);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
console.error(` ${red("✗")} Failed to start codex app-server: ${err.message}`);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
serverProc.on("exit", () => {
|
|
122
|
+
serverProc = null;
|
|
123
|
+
});
|
|
87
124
|
|
|
88
|
-
// Wait for the server to be ready
|
|
89
|
-
await new Promise((resolve) => {
|
|
90
|
-
let resolved = false;
|
|
91
125
|
serverProc.stdout.on("data", (chunk) => {
|
|
92
|
-
const text = chunk.toString();
|
|
93
|
-
if (!
|
|
94
|
-
|
|
95
|
-
console.log(` ${
|
|
96
|
-
resolve();
|
|
126
|
+
const text = chunk.toString().trim();
|
|
127
|
+
if (!text) return;
|
|
128
|
+
for (const line of text.split(/\r?\n/)) {
|
|
129
|
+
console.log(` ${dim(`[codex] ${line}`)}`);
|
|
97
130
|
}
|
|
98
131
|
});
|
|
132
|
+
|
|
99
133
|
serverProc.stderr.on("data", (chunk) => {
|
|
100
134
|
const text = chunk.toString().trim();
|
|
101
|
-
if (text)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
setTimeout(() => {
|
|
105
|
-
if (!resolved) {
|
|
106
|
-
resolved = true;
|
|
107
|
-
console.log(` ${yellow("⚠")} Proceeding without readiness confirmation`);
|
|
108
|
-
resolve();
|
|
135
|
+
if (!text) return;
|
|
136
|
+
for (const line of text.split(/\r?\n/)) {
|
|
137
|
+
console.log(` ${dim(`[codex] ${line}`)}`);
|
|
109
138
|
}
|
|
110
|
-
|
|
111
|
-
|
|
139
|
+
if (isAddressInUseError(text)) {
|
|
140
|
+
console.log(` ${yellow("⚠")} Port ${wsPort} is already in use — attempting to reuse the existing codex app-server.`);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const ready = await waitForCodexReady(readyUrl);
|
|
145
|
+
if (ready) {
|
|
146
|
+
console.log(` ${green("✓")} codex app-server ready on port ${wsPort}`);
|
|
147
|
+
} else {
|
|
148
|
+
console.log(` ${yellow("⚠")} Proceeding without readiness confirmation`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
112
151
|
}
|
|
113
152
|
|
|
114
153
|
// ── Step 1: Register bridge session with BotBuddy ──
|
|
@@ -117,7 +156,7 @@ export async function runBridge(args) {
|
|
|
117
156
|
bridge_name: cfg.agent_name || `bridge-${host}`,
|
|
118
157
|
machine_host: host,
|
|
119
158
|
repo_path: repoPath,
|
|
120
|
-
config: { ws_port: wsPort, model, auto_start:
|
|
159
|
+
config: { ws_port: wsPort, model, auto_start: !noServer },
|
|
121
160
|
});
|
|
122
161
|
|
|
123
162
|
if (!session?.session?.id) die("Failed to register bridge session");
|
|
@@ -175,7 +214,7 @@ export async function runBridge(args) {
|
|
|
175
214
|
clientInfo: {
|
|
176
215
|
name: "botbuddy_bridge",
|
|
177
216
|
title: "BotBuddy Codex Bridge",
|
|
178
|
-
version:
|
|
217
|
+
version: VERSION,
|
|
179
218
|
bridgeNonce,
|
|
180
219
|
},
|
|
181
220
|
capabilities: { experimentalApi: true },
|
|
@@ -365,7 +404,7 @@ export async function runBridge(args) {
|
|
|
365
404
|
model: cmd.params.model || model,
|
|
366
405
|
cwd: cmd.params.cwd || repoPath,
|
|
367
406
|
approvalPolicy: cmd.params.approval_policy || "never",
|
|
368
|
-
sandbox: cmd.params.sandbox || "
|
|
407
|
+
sandbox: cmd.params.sandbox || "workspace-write",
|
|
369
408
|
});
|
|
370
409
|
// Track thread
|
|
371
410
|
if (result?.thread?.id) {
|
package/src/commands.mjs
CHANGED
|
@@ -3,8 +3,7 @@ import { doLogin } from "./auth.mjs";
|
|
|
3
3
|
import { runBridge } from "./codex-bridge.mjs";
|
|
4
4
|
import { loadConfig, getConfig, clearConfig, saveConfig, getConfigPath } from "./config.mjs";
|
|
5
5
|
import { green, red, cyan, dim, bold, die } from "./utils.mjs";
|
|
6
|
-
|
|
7
|
-
const VERSION = "1.1.0";
|
|
6
|
+
import { VERSION } from "./version.mjs";
|
|
8
7
|
|
|
9
8
|
export async function run(argv) {
|
|
10
9
|
loadConfig();
|
|
@@ -61,6 +60,7 @@ ${bold("OTHER")}
|
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
async function cmdStart(args) {
|
|
63
|
+
console.log(`${bold("botbuddy")} ${dim(`v${VERSION}`)}\n`);
|
|
64
64
|
const cfg = getConfig();
|
|
65
65
|
|
|
66
66
|
// Auto-login if not authenticated
|