@commonlyai/cli 0.1.242 → 0.1.243

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.242",
3
+ "version": "0.1.243",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -35,6 +35,7 @@ import {
35
35
  readBinInPrefix, versionDirFor,
36
36
  } from './mcp-home.js';
37
37
  import { MCP_PACKAGE, exactVersion, parseVersion } from './mcp-server-version.js';
38
+ import { resolveLaunch } from './windows-command.js';
38
39
 
39
40
  export const PROBE_API_URL_PLACEHOLDER = 'http://127.0.0.1:1';
40
41
  export const PROBE_TOKEN_PLACEHOLDER = 'cm_agent_warm_probe';
@@ -106,8 +107,15 @@ export const acquireWarmLock = (home, {
106
107
  }
107
108
  };
108
109
 
109
- /** Default `npm` runner. Resolves `{ ok, stdout }`; never rejects. */
110
- export const runCommand = (bin, args, { timeout = REGISTRY_TIMEOUT_MS, cwd } = {}) => new Promise((resolve) => {
110
+ /**
111
+ * Default `npm` runner. Resolves `{ ok, stdout }`; never rejects. On Windows
112
+ * `npm` is npm.cmd, which Node cannot spawn without a shell, so the name goes
113
+ * through the resolver the adapters use (npm.cmd becomes node.exe npm-cli.js).
114
+ * Off Windows it is spawned as given. `resolution` is the resolver's test seam.
115
+ */
116
+ export const runCommand = (bin, args, {
117
+ timeout = REGISTRY_TIMEOUT_MS, cwd, resolution,
118
+ } = {}) => new Promise((resolve) => {
111
119
  let settled = false;
112
120
  let child;
113
121
  const done = (result) => {
@@ -116,7 +124,9 @@ export const runCommand = (bin, args, { timeout = REGISTRY_TIMEOUT_MS, cwd } = {
116
124
  resolve(result);
117
125
  };
118
126
  try {
119
- child = spawnChild(bin, args, { stdio: ['ignore', 'pipe', 'pipe'], env: process.env, cwd });
127
+ // The child runs in `cwd`, so a relative PATH entry is read there.
128
+ const launch = resolveLaunch(bin, args, { cwd, ...resolution });
129
+ child = spawnChild(launch.command, launch.args, { stdio: ['ignore', 'pipe', 'pipe'], env: process.env, cwd });
120
130
  } catch (error) {
121
131
  done({ ok: false, stdout: '', stderr: String(error && error.message) });
122
132
  return;
@@ -42,7 +42,10 @@ const extOf = (file) => win32.extname(file).toLowerCase();
42
42
  // not: `{ ...process.env, PATH }` can carry both `Path` and `PATH`. Read
43
43
  // `Path` first (the casing Windows itself uses), then `PATH`, then any other
44
44
  // casing, and drop duplicates.
45
- const pathEntries = (env = {}) => {
45
+ // A relative entry (`.`, `bin`) names a folder relative to the working
46
+ // directory the child is spawned in, as Windows reads it there. Given `cwd`,
47
+ // it is resolved against that, never against this process's own directory.
48
+ const pathEntries = (env = {}, cwd) => {
46
49
  const keys = Object.keys(env).filter((key) => key.toLowerCase() === 'path');
47
50
  const rank = (key) => (key === 'Path' ? 0 : key === 'PATH' ? 1 : 2);
48
51
  keys.sort((a, b) => rank(a) - rank(b));
@@ -50,7 +53,8 @@ const pathEntries = (env = {}) => {
50
53
  const entries = [];
51
54
  for (const key of keys) {
52
55
  for (const raw of String(env[key] || '').split(';')) {
53
- const dir = raw.trim().replace(/^"(.*)"$/, '$1');
56
+ const entry = raw.trim().replace(/^"(.*)"$/, '$1');
57
+ const dir = entry && cwd && !win32.isAbsolute(entry) ? win32.resolve(cwd, entry) : entry;
54
58
  if (!dir || seen.has(dir.toLowerCase())) continue;
55
59
  seen.add(dir.toLowerCase());
56
60
  entries.push(dir);
@@ -251,6 +255,8 @@ const classify = (file, deps) => {
251
255
  * Resolve `name` to something spawnable without a shell, with the reason when
252
256
  * it cannot be. On anything but win32, `{ command: name, args: [] }`.
253
257
  * On win32, `source` is the file found on PATH (the shim, or the .exe).
258
+ * `cwd` is the child's working directory; relative PATH entries are read
259
+ * against it (unset: this process's, as before).
254
260
  *
255
261
  * @returns {{ command: string, args: string[], source?: string }
256
262
  * | { command: null, reason: string, source?: string }}
@@ -261,6 +267,7 @@ export const resolveWindowsCommandWithReason = (name, {
261
267
  existsSync = realExistsSync,
262
268
  readFileSync = realReadFileSync,
263
269
  execPath = process.execPath,
270
+ cwd,
264
271
  } = {}) => {
265
272
  if (platform !== 'win32') return { command: name, args: [] };
266
273
  const deps = { existsSync, readFileSync, execPath, env };
@@ -290,7 +297,7 @@ export const resolveWindowsCommandWithReason = (name, {
290
297
  // (a `.vbs`, a `.js`, a `.ps1` someone added to PATHEXT), the answer is a
291
298
  // refusal, never a later match, which would be a different program from the
292
299
  // one the person runs by typing the name.
293
- for (const dir of pathEntries(env)) {
300
+ for (const dir of pathEntries(env, cwd)) {
294
301
  for (const candidate of candidatesFor(win32.join(dir, name))) {
295
302
  if (!existsSync(candidate)) continue;
296
303
  return classify(candidate, deps) || {