@btatum5/codex-bridge 0.1.0 → 1.3.3

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.
@@ -1,105 +1,141 @@
1
- #!/usr/bin/env node
2
-
3
- const args = process.argv.slice(2);
4
- const command = resolveCommand(args[0]);
5
- const commandArgs = command === "up" ? args : args.slice(1);
6
-
7
- switch (command) {
8
- case "up":
9
- case "start":
10
- runServer(commandArgs);
11
- break;
12
- case "help":
13
- case "--help":
14
- case "-h":
15
- printHelp();
16
- break;
17
- case "version":
18
- case "--version":
19
- case "-v":
20
- printVersion();
21
- break;
22
- default:
23
- console.error(`[codex-bridge] Unknown command: ${command}`);
24
- printHelp(1);
25
- break;
26
- }
27
-
28
- function runServer(args) {
29
- const options = parseArgs(args);
30
-
31
- if (options.port) {
32
- process.env.PORT = String(options.port);
33
- }
34
-
35
- if (options.host) {
36
- process.env.HOST = options.host;
37
- }
38
-
39
- import(new URL("../server.mjs", import.meta.url).href);
40
- }
41
-
42
- function parseArgs(args) {
43
- const options = {
44
- host: "",
45
- port: ""
46
- };
47
-
48
- for (let index = 0; index < args.length; index += 1) {
49
- const value = args[index];
50
-
51
- if (value === "up" || value === "start") {
52
- continue;
1
+ #!/usr/bin/env node
2
+ // FILE: codex-bridge.js
3
+ // Purpose: CLI surface for foreground bridge runs, pairing reset, thread resume, and macOS service control.
4
+ // Layer: CLI binary
5
+ // Exports: none
6
+ // Depends on: ../src
7
+
8
+ const {
9
+ printMacOSBridgePairingQr,
10
+ printMacOSBridgeServiceStatus,
11
+ readBridgeConfig,
12
+ resetMacOSBridgePairing,
13
+ runMacOSBridgeService,
14
+ startBridge,
15
+ startMacOSBridgeService,
16
+ stopMacOSBridgeService,
17
+ resetBridgePairing,
18
+ openLastActiveThread,
19
+ watchThreadRollout,
20
+ } = require("../src");
21
+ const { version } = require("../package.json");
22
+
23
+ const command = process.argv[2] || "up";
24
+
25
+ void main();
26
+
27
+ // ─── ENTRY POINT ─────────────────────────────────────────────
28
+
29
+ async function main() {
30
+ if (isVersionCommand(command)) {
31
+ console.log(version);
32
+ return;
33
+ }
34
+
35
+ if (command === "up") {
36
+ if (process.platform === "darwin") {
37
+ const result = await startMacOSBridgeService({
38
+ waitForPairing: true,
39
+ });
40
+ printMacOSBridgePairingQr({
41
+ pairingSession: result.pairingSession,
42
+ });
43
+ return;
44
+ }
45
+
46
+ startBridge();
47
+ return;
48
+ }
49
+
50
+ if (command === "run") {
51
+ startBridge();
52
+ return;
53
+ }
54
+
55
+ if (command === "run-service") {
56
+ runMacOSBridgeService();
57
+ return;
58
+ }
59
+
60
+ if (command === "start") {
61
+ assertMacOSCommand(command);
62
+ readBridgeConfig();
63
+ await startMacOSBridgeService({
64
+ waitForPairing: false,
65
+ });
66
+ console.log("[codex-bridge] macOS bridge service is running.");
67
+ return;
68
+ }
69
+
70
+ if (command === "stop") {
71
+ assertMacOSCommand(command);
72
+ stopMacOSBridgeService();
73
+ console.log("[codex-bridge] macOS bridge service stopped.");
74
+ return;
75
+ }
76
+
77
+ if (command === "status") {
78
+ assertMacOSCommand(command);
79
+ printMacOSBridgeServiceStatus();
80
+ return;
81
+ }
82
+
83
+ if (command === "reset-pairing") {
84
+ try {
85
+ if (process.platform === "darwin") {
86
+ resetMacOSBridgePairing();
87
+ console.log("[codex-bridge] Stopped the macOS bridge service and cleared the saved pairing state. Run `codex-bridge up` to pair again.");
88
+ } else {
89
+ resetBridgePairing();
90
+ console.log("[codex-bridge] Cleared the saved pairing state. Run `codex-bridge up` to pair again.");
91
+ }
92
+ } catch (error) {
93
+ console.error(`[codex-bridge] ${(error && error.message) || "Failed to clear the saved pairing state."}`);
94
+ process.exit(1);
53
95
  }
54
-
55
- if (value === "--host" && args[index + 1]) {
56
- options.host = args[index + 1];
57
- index += 1;
58
- continue;
96
+ return;
97
+ }
98
+
99
+ if (command === "resume") {
100
+ try {
101
+ const state = openLastActiveThread();
102
+ console.log(
103
+ `[codex-bridge] Opened last active thread: ${state.threadId} (${state.source || "unknown"})`
104
+ );
105
+ } catch (error) {
106
+ console.error(`[codex-bridge] ${(error && error.message) || "Failed to reopen the last thread."}`);
107
+ process.exit(1);
59
108
  }
60
-
61
- if ((value === "--port" || value === "-p") && args[index + 1]) {
62
- options.port = args[index + 1];
63
- index += 1;
109
+ return;
110
+ }
111
+
112
+ if (command === "watch") {
113
+ try {
114
+ watchThreadRollout(process.argv[3] || "");
115
+ } catch (error) {
116
+ console.error(`[codex-bridge] ${(error && error.message) || "Failed to watch the thread rollout."}`);
117
+ process.exit(1);
64
118
  }
65
- }
66
-
67
- return options;
68
- }
69
-
70
- function resolveCommand(firstArg) {
71
- if (!firstArg) {
72
- return "up";
73
- }
74
-
75
- switch (firstArg) {
76
- case "help":
77
- case "--help":
78
- case "-h":
79
- return "help";
80
- case "version":
81
- case "--version":
82
- case "-v":
83
- return "version";
84
- default:
85
- return firstArg.startsWith("-") ? "up" : firstArg;
86
- }
87
- }
88
-
89
- function printHelp(exitCode = 0) {
90
- const lines = [
91
- "Usage:",
92
- " codex-bridge up [--host 127.0.0.1] [--port 8787]",
93
- " codex-bridge start [--host 127.0.0.1] [--port 8787]",
94
- " codex-bridge help",
95
- " codex-bridge version"
96
- ];
97
-
98
- const stream = exitCode === 0 ? process.stdout : process.stderr;
99
- stream.write(`${lines.join("\n")}\n`);
100
- process.exit(exitCode);
119
+ return;
120
+ }
121
+
122
+ console.error(`Unknown command: ${command}`);
123
+ console.error(
124
+ "Usage: codex-bridge up | codex-bridge run | codex-bridge start | codex-bridge stop | codex-bridge status | "
125
+ + "codex-bridge reset-pairing | codex-bridge resume | codex-bridge watch [threadId] | codex-bridge --version"
126
+ );
127
+ process.exit(1);
101
128
  }
102
-
103
- function printVersion() {
104
- process.stdout.write("0.1.0\n");
129
+
130
+ function assertMacOSCommand(name) {
131
+ if (process.platform === "darwin") {
132
+ return;
133
+ }
134
+
135
+ console.error(`[codex-bridge] \`${name}\` is only available on macOS. Use \`codex-bridge up\` or \`codex-bridge run\` for the foreground bridge on this OS.`);
136
+ process.exit(1);
105
137
  }
138
+
139
+ function isVersionCommand(value) {
140
+ return value === "-v" || value === "--v" || value === "-V" || value === "--version" || value === "version";
141
+ }
package/bin/phodex.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ // FILE: phodex.js
3
+ // Purpose: Backward-compatible wrapper that forwards legacy `phodex` usage to `codex-bridge`.
4
+ // Layer: CLI binary
5
+ // Exports: none
6
+ // Depends on: ./codex-bridge
7
+
8
+ require("./codex-bridge");
package/bin/remodex.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ // FILE: codex-bridge.js
3
+ // Purpose: Backward-compatible wrapper that forwards legacy `remodex` usage to `codex-bridge`.
4
+ // Layer: CLI binary
5
+ // Exports: none
6
+ // Depends on: ./codex-bridge
7
+
8
+ require("./codex-bridge");
package/package.json CHANGED
@@ -1,24 +1,38 @@
1
- {
2
- "name": "@btatum5/codex-bridge",
3
- "version": "0.1.0",
4
- "description": "Codex desktop companion bridge for the iOS controller app.",
5
- "license": "MIT",
6
- "type": "module",
7
- "bin": {
8
- "codex-bridge": "bin/codex-bridge.js"
9
- },
10
- "files": [
11
- "bin",
12
- "server.mjs",
13
- "README.md"
14
- ],
15
- "publishConfig": {
16
- "access": "public"
17
- },
18
- "engines": {
19
- "node": ">=20"
20
- },
21
- "scripts": {
22
- "start": "node ./bin/codex-bridge.js up"
23
- }
24
- }
1
+ {
2
+ "name": "@btatum5/codex-bridge",
3
+ "version": "1.3.3",
4
+ "description": "Local bridge between Codex and the Codex mobile app. Run `codex-bridge up` to start.",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "codex-bridge": "bin/codex-bridge.js",
8
+ "remodex": "bin/codex-bridge.js",
9
+ "phodex": "bin/phodex.js"
10
+ },
11
+ "files": [
12
+ "bin/",
13
+ "src/"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "start": "node ./bin/codex-bridge.js up",
20
+ "test": "node --test ./test/*.test.js",
21
+ "prepack": "node ./scripts/prepare-private-defaults.js",
22
+ "postpack": "node ./scripts/cleanup-private-defaults.js"
23
+ },
24
+ "keywords": [
25
+ "codex-bridge",
26
+ "remodex",
27
+ "codex",
28
+ "bridge",
29
+ "cli"
30
+ ],
31
+ "author": "Emanuele Di Pietro",
32
+ "license": "ISC",
33
+ "type": "commonjs",
34
+ "dependencies": {
35
+ "qrcode-terminal": "^0.12.0",
36
+ "ws": "^8.19.0"
37
+ }
38
+ }