@botbuddy/cli 1.0.0 → 1.2.0
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 +52 -4
- package/src/commands.mjs +38 -54
package/package.json
CHANGED
package/src/codex-bridge.mjs
CHANGED
|
@@ -47,18 +47,18 @@ export async function runBridge(args) {
|
|
|
47
47
|
let wsPort = 4500;
|
|
48
48
|
let repoPath = process.cwd();
|
|
49
49
|
let model = "gpt-5.4";
|
|
50
|
-
let
|
|
50
|
+
let noServer = false;
|
|
51
51
|
|
|
52
52
|
for (let i = 0; i < args.length; i++) {
|
|
53
53
|
if ((args[i] === "--port" || args[i] === "-p") && args[i + 1]) wsPort = parseInt(args[++i], 10);
|
|
54
54
|
else if ((args[i] === "--repo" || args[i] === "-r") && args[i + 1]) repoPath = args[++i];
|
|
55
55
|
else if ((args[i] === "--model" || args[i] === "-m") && args[i + 1]) model = args[++i];
|
|
56
|
-
else if (args[i] === "--
|
|
56
|
+
else if (args[i] === "--no-server") noServer = true;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
const wsUrl = `ws://127.0.0.1:${wsPort}`;
|
|
60
|
-
const hostname =
|
|
61
|
-
const host =
|
|
60
|
+
const { hostname: getHostname } = await import("os");
|
|
61
|
+
const host = getHostname();
|
|
62
62
|
|
|
63
63
|
console.log(`${bold("BotBuddy Codex Bridge")}\n`);
|
|
64
64
|
console.log(` ${dim("WebSocket:")} ${cyan(wsUrl)}`);
|
|
@@ -67,6 +67,50 @@ export async function runBridge(args) {
|
|
|
67
67
|
console.log(` ${dim("Host:")} ${dim(host)}`);
|
|
68
68
|
console.log(` ${dim("Security:")} ${green("HMAC-SHA256")} session signing + ${green("loopback-only")} WS\n`);
|
|
69
69
|
|
|
70
|
+
// ── Step 0: Auto-start codex app-server ──
|
|
71
|
+
let serverProc = null;
|
|
72
|
+
if (!noServer) {
|
|
73
|
+
console.log(dim("→ Starting codex app-server..."));
|
|
74
|
+
const { spawn } = await import("child_process");
|
|
75
|
+
serverProc = spawn("codex", ["app-server", "--listen", wsUrl], {
|
|
76
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
77
|
+
env: { ...process.env },
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
serverProc.on("error", (err) => {
|
|
81
|
+
if (err.code === "ENOENT") {
|
|
82
|
+
console.log(` ${red("✗")} 'codex' not found in PATH. Install it or use ${cyan("--no-server")} to skip.`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
console.error(` ${red("✗")} Failed to start codex app-server: ${err.message}`);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Wait for the server to be ready
|
|
89
|
+
await new Promise((resolve) => {
|
|
90
|
+
let resolved = false;
|
|
91
|
+
serverProc.stdout.on("data", (chunk) => {
|
|
92
|
+
const text = chunk.toString();
|
|
93
|
+
if (!resolved && text.includes("listening on")) {
|
|
94
|
+
resolved = true;
|
|
95
|
+
console.log(` ${green("✓")} codex app-server started on port ${wsPort}`);
|
|
96
|
+
resolve();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
serverProc.stderr.on("data", (chunk) => {
|
|
100
|
+
const text = chunk.toString().trim();
|
|
101
|
+
if (text) console.log(` ${dim(`[codex] ${text}`)}`);
|
|
102
|
+
});
|
|
103
|
+
// Timeout fallback — proceed after 5s even if we didn't see the message
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
if (!resolved) {
|
|
106
|
+
resolved = true;
|
|
107
|
+
console.log(` ${yellow("⚠")} Proceeding without readiness confirmation`);
|
|
108
|
+
resolve();
|
|
109
|
+
}
|
|
110
|
+
}, 5000);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
70
114
|
// ── Step 1: Register bridge session with BotBuddy ──
|
|
71
115
|
console.log(dim("→ Connecting to BotBuddy..."));
|
|
72
116
|
const session = await relayPost("/bridge/connect", {
|
|
@@ -417,6 +461,10 @@ export async function runBridge(args) {
|
|
|
417
461
|
await relayPost("/bridge/disconnect", { session_id: sessionId });
|
|
418
462
|
} catch {}
|
|
419
463
|
if (ws) ws.close();
|
|
464
|
+
if (serverProc) {
|
|
465
|
+
console.log(dim("→ Stopping codex app-server..."));
|
|
466
|
+
serverProc.kill("SIGTERM");
|
|
467
|
+
}
|
|
420
468
|
console.log(`${green("✓")} Bridge disconnected.`);
|
|
421
469
|
process.exit(0);
|
|
422
470
|
};
|
package/src/commands.mjs
CHANGED
|
@@ -4,16 +4,18 @@ 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
6
|
|
|
7
|
-
const VERSION = "1.
|
|
7
|
+
const VERSION = "1.1.0";
|
|
8
8
|
|
|
9
|
-
export function run(argv) {
|
|
9
|
+
export async function run(argv) {
|
|
10
10
|
loadConfig();
|
|
11
11
|
const [command, ...args] = argv;
|
|
12
12
|
|
|
13
13
|
switch (command) {
|
|
14
|
+
case "start": return cmdStart(args);
|
|
14
15
|
case "login": return doLogin();
|
|
15
16
|
case "logout": return cmdLogout();
|
|
16
17
|
case "status": return cmdStatus();
|
|
18
|
+
// Agent-only commands (used by MCP agents, not humans)
|
|
17
19
|
case "register": return cmdRegister(args);
|
|
18
20
|
case "heartbeat": return cmdHeartbeat(args);
|
|
19
21
|
case "lock": return cmdLock(args);
|
|
@@ -39,52 +41,39 @@ function cmdHelp() {
|
|
|
39
41
|
console.log(`${bold("botbuddy")} ${dim(`v${VERSION}`)} — Swarm coordination CLI
|
|
40
42
|
|
|
41
43
|
${bold("USAGE")}
|
|
42
|
-
botbuddy
|
|
44
|
+
botbuddy start Start BotBuddy (login + codex server + bridge)
|
|
45
|
+
|
|
46
|
+
${bold("OPTIONS")}
|
|
47
|
+
start [options]
|
|
48
|
+
-p, --port <port> WebSocket port (default: 4500)
|
|
49
|
+
-r, --repo <path> Repository path (default: cwd)
|
|
50
|
+
-m, --model <model> Default model (default: gpt-5.4)
|
|
51
|
+
--no-server Don't auto-start codex app-server
|
|
43
52
|
|
|
44
53
|
${bold("AUTH")}
|
|
45
|
-
login
|
|
46
|
-
logout
|
|
47
|
-
status
|
|
48
|
-
|
|
49
|
-
${bold("AGENTS")}
|
|
50
|
-
register <name> [type] Register a new agent (type: codex|claude|gpt|custom)
|
|
51
|
-
agents List all agents
|
|
52
|
-
heartbeat [task] Send a heartbeat
|
|
53
|
-
|
|
54
|
-
${bold("RESOURCES")}
|
|
55
|
-
lock <name> <type> Acquire a single lock (type: port|mcp_server|file|...)
|
|
56
|
-
locks [options] Batch-acquire resources (auto-assigns free ones)
|
|
57
|
-
-p, --port [type] Request a port (frontend|backend, default: frontend)
|
|
58
|
-
-m, --mcp Request an MCP server slot
|
|
59
|
-
-t, --ticket <id> Ticket ID (shared across all locks)
|
|
60
|
-
--pr <id> PR ID (shared across all locks)
|
|
61
|
-
unlock <name> Release a lock
|
|
62
|
-
resources List all resources and locks
|
|
63
|
-
|
|
64
|
-
${bold("TASKS")}
|
|
65
|
-
task create <title> [-d description] [-p priority]
|
|
66
|
-
task claim <id> Claim a pending task
|
|
67
|
-
task done <id> Mark a task as done
|
|
68
|
-
tasks List all tasks
|
|
69
|
-
|
|
70
|
-
${bold("SWARM")}
|
|
71
|
-
hours Get current working hours
|
|
72
|
-
hours derive Derive working hours from activity
|
|
73
|
-
hours set <json> Set working hours manually
|
|
74
|
-
|
|
75
|
-
${bold("BROWSE")}
|
|
76
|
-
browse agents|tasks|resources|activity|settings
|
|
77
|
-
|
|
78
|
-
${bold("CODEX")}
|
|
79
|
-
codex bridge [options] Start Codex app-server bridge
|
|
80
|
-
-p, --port <port> WebSocket port (default: 4500)
|
|
81
|
-
-r, --repo <path> Repository path (default: cwd)
|
|
82
|
-
-m, --model <model> Default model (default: gpt-5.4)
|
|
83
|
-
--auto-start Auto-start app-server
|
|
54
|
+
login Re-authenticate via OAuth
|
|
55
|
+
logout Remove saved credentials
|
|
56
|
+
status Show current auth status
|
|
84
57
|
|
|
85
58
|
${bold("OTHER")}
|
|
86
|
-
help
|
|
87
|
-
version
|
|
59
|
+
help Show this help
|
|
60
|
+
version Show version`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function cmdStart(args) {
|
|
64
|
+
const cfg = getConfig();
|
|
65
|
+
|
|
66
|
+
// Auto-login if not authenticated
|
|
67
|
+
if (!cfg.access_token && !cfg.api_key) {
|
|
68
|
+
console.log(dim("→ No credentials found. Starting login...\n"));
|
|
69
|
+
await doLogin();
|
|
70
|
+
} else if (cfg.token_expires_at && cfg.token_expires_at <= Date.now()) {
|
|
71
|
+
console.log(dim("→ Token expired. Re-authenticating...\n"));
|
|
72
|
+
await doLogin();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Start the bridge (which auto-starts codex app-server)
|
|
76
|
+
return runBridge(args);
|
|
88
77
|
}
|
|
89
78
|
|
|
90
79
|
function cmdStatus() {
|
|
@@ -96,7 +85,7 @@ function cmdStatus() {
|
|
|
96
85
|
if (cfg.token_expires_at) {
|
|
97
86
|
const remaining = cfg.token_expires_at - Date.now();
|
|
98
87
|
if (remaining <= 0) {
|
|
99
|
-
console.log(` Token: ${red("EXPIRED")} — run ${cyan("botbuddy
|
|
88
|
+
console.log(` Token: ${red("EXPIRED")} — run ${cyan("botbuddy start")}`);
|
|
100
89
|
} else {
|
|
101
90
|
const mins = Math.round(remaining / 60000);
|
|
102
91
|
const label = mins > 60 ? `${Math.round(mins / 60)}h ${mins % 60}m` : `${mins}m`;
|
|
@@ -109,7 +98,7 @@ function cmdStatus() {
|
|
|
109
98
|
if (cfg.agent_name) console.log(` Agent: ${cyan(cfg.agent_name)}`);
|
|
110
99
|
} else {
|
|
111
100
|
console.log(`${red("✗")} Not authenticated`);
|
|
112
|
-
console.log(` Run: ${cyan("botbuddy
|
|
101
|
+
console.log(` Run: ${cyan("botbuddy start")}`);
|
|
113
102
|
}
|
|
114
103
|
}
|
|
115
104
|
|
|
@@ -214,12 +203,7 @@ function cmdBrowse(args) {
|
|
|
214
203
|
}
|
|
215
204
|
|
|
216
205
|
function cmdCodex(args) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
case "bridge":
|
|
221
|
-
return runBridge(args.slice(1));
|
|
222
|
-
default:
|
|
223
|
-
die(`Unknown codex subcommand: ${sub}. Try: botbuddy codex bridge`);
|
|
224
|
-
}
|
|
206
|
+
// Legacy alias — redirect to start
|
|
207
|
+
console.log(dim("Note: 'botbuddy codex bridge' is now 'botbuddy start'\n"));
|
|
208
|
+
return runBridge(args.slice(1));
|
|
225
209
|
}
|