@codexhost/cli 0.1.0-test.2 → 0.1.1

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/README.md CHANGED
@@ -5,9 +5,11 @@ Run Pi and Claude Code as first-class external harnesses inside Codex Desktop.
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install -g @codexhost/cli@0.1.0-test.2
8
+ npm install -g @codexhost/cli@0.1.1
9
9
  ```
10
10
 
11
11
  npm automatically installs the matching macOS or Windows platform package. Node.js 22 or newer and Codex Desktop are required.
12
12
 
13
+ The `codexhost` command starts Codex Desktop and returns immediately: the packaged Launcher keeps supervising in the background and exits after you quit the Desktop. Re-running `codexhost` attaches to the same controlled instance.
14
+
13
15
  If installation used `--omit=optional`, reinstall without that option so npm can select the native package for the current architecture.
package/bin/codexhost.js CHANGED
@@ -3,6 +3,7 @@ import { spawn } from "node:child_process";
3
3
  import { existsSync } from "node:fs";
4
4
  import { createRequire } from "node:module";
5
5
  import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
6
7
 
7
8
  const platformPackages = {
8
9
  "darwin-arm64": "@codexhost/cli-darwin-arm64",
@@ -19,9 +20,26 @@ let packageRoot;
19
20
  try {
20
21
  packageRoot = path.dirname(require.resolve(`${platformPackage}/package.json`));
21
22
  } catch {
22
- fail(
23
- `missing optional platform package '${platformPackage}'. Reinstall @codexhost/cli without --omit=optional.`,
24
- );
23
+ // Local folder installs symlink packages into the source tree; Node realpaths
24
+ // the entry script, so the sibling platform package drops off the resolution
25
+ // chain. Fall back to the npm global layout derived from the bin symlink.
26
+ packageRoot = null;
27
+ if (process.platform !== "win32" && process.argv[1]) {
28
+ const prefix = path.dirname(path.dirname(path.resolve(process.argv[1])));
29
+ const globalPackage = path.join(
30
+ prefix,
31
+ "lib",
32
+ "node_modules",
33
+ platformPackage,
34
+ "package.json",
35
+ );
36
+ if (existsSync(globalPackage)) packageRoot = path.dirname(globalPackage);
37
+ }
38
+ if (!packageRoot) {
39
+ fail(
40
+ `missing optional platform package '${platformPackage}'. Reinstall @codexhost/cli without --omit=optional.`,
41
+ );
42
+ }
25
43
  }
26
44
 
27
45
  const executableSuffix = process.platform === "win32" ? ".exe" : "";
@@ -46,6 +64,29 @@ for (const [label, filePath] of [
46
64
  if (!existsSync(filePath)) fail(`missing ${label}: ${filePath}`);
47
65
  }
48
66
 
67
+ const npmCliCandidates = [
68
+ process.env.npm_execpath,
69
+ process.platform === "win32"
70
+ ? path.join(path.dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js")
71
+ : path.join(
72
+ path.dirname(path.dirname(process.execPath)),
73
+ "lib",
74
+ "node_modules",
75
+ "npm",
76
+ "bin",
77
+ "npm-cli.js",
78
+ ),
79
+ ].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
80
+ const npmCliPath = npmCliCandidates.find((candidate) => existsSync(candidate));
81
+ if (!npmCliPath) fail("could not locate the npm CLI used to update this global installation");
82
+ const updateEnvironment = {
83
+ ...process.env,
84
+ CODEXHOST_NPM_NODE_PATH: process.execPath,
85
+ CODEXHOST_NPM_CLI_PATH: path.resolve(npmCliPath),
86
+ CODEXHOST_NPM_LAUNCHER_PATH: fileURLToPath(import.meta.url),
87
+ CODEXHOST_NPM_PACKAGE_ROOT: packageRoot,
88
+ };
89
+
49
90
  const userArguments = process.argv.slice(2);
50
91
  let launchArguments;
51
92
  if (userArguments.length === 0) {
@@ -99,15 +140,47 @@ if (launchArguments[0] === "launch") {
99
140
  launchArguments = ["launch", ...extras, ...launchArguments.slice(1)];
100
141
  }
101
142
 
102
- const child = spawn(launcher, launchArguments, {
103
- stdio: "inherit",
104
- windowsHide: true,
105
- });
106
- child.on("error", (error) => fail(error.message));
107
- child.on("exit", (code, signal) => {
108
- if (signal) {
109
- process.kill(process.pid, signal);
110
- return;
111
- }
112
- process.exit(code ?? 1);
113
- });
143
+ if (launchArguments[0] === "launch") {
144
+ // The Launcher prints "ready" once the Desktop, Controller, and Host chain
145
+ // are up, then detaches from the terminal to keep supervising. Return
146
+ // success immediately so the terminal is not held open by this command.
147
+ const child = spawn(launcher, launchArguments, {
148
+ env: updateEnvironment,
149
+ stdio: ["ignore", "pipe", "inherit"],
150
+ windowsHide: true,
151
+ });
152
+ let finished = false;
153
+ const finish = (code) => {
154
+ if (finished) return;
155
+ finished = true;
156
+ process.exit(code);
157
+ };
158
+ child.stdout.setEncoding("utf8");
159
+ let launcherOutput = "";
160
+ child.stdout.on("data", (chunk) => {
161
+ launcherOutput += chunk;
162
+ if (launcherOutput.includes("ready\n")) finish(0);
163
+ });
164
+ child.on("error", (error) => fail(error.message));
165
+ child.on("exit", (code, signal) => {
166
+ if (signal) {
167
+ process.kill(process.pid, signal);
168
+ return;
169
+ }
170
+ finish(code ?? 1);
171
+ });
172
+ } else {
173
+ const child = spawn(launcher, launchArguments, {
174
+ env: updateEnvironment,
175
+ stdio: "inherit",
176
+ windowsHide: true,
177
+ });
178
+ child.on("error", (error) => fail(error.message));
179
+ child.on("exit", (code, signal) => {
180
+ if (signal) {
181
+ process.kill(process.pid, signal);
182
+ return;
183
+ }
184
+ process.exit(code ?? 1);
185
+ });
186
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codexhost/cli",
3
- "version": "0.1.0-test.2",
3
+ "version": "0.1.1",
4
4
  "description": "Run Pi and Claude Code as first-class external harnesses inside Codex Desktop.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,10 +14,10 @@
14
14
  "node": ">=22"
15
15
  },
16
16
  "optionalDependencies": {
17
- "@codexhost/cli-darwin-arm64": "0.1.0-test.2",
18
- "@codexhost/cli-darwin-x64": "0.1.0-test.2",
19
- "@codexhost/cli-win32-x64": "0.1.0-test.2",
20
- "@codexhost/cli-win32-arm64": "0.1.0-test.2"
17
+ "@codexhost/cli-darwin-arm64": "0.1.1",
18
+ "@codexhost/cli-darwin-x64": "0.1.1",
19
+ "@codexhost/cli-win32-x64": "0.1.1",
20
+ "@codexhost/cli-win32-arm64": "0.1.1"
21
21
  },
22
22
  "keywords": [
23
23
  "codex",