@commonlyai/cli 0.1.247 → 0.1.248

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.247",
3
+ "version": "0.1.248",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -43,12 +43,13 @@
43
43
 
44
44
  import { requireSeatModel } from './seat-model.js';
45
45
  import { probeVersion } from './tested-version.js';
46
+ import { resolveOnPath } from '../resolve-on-path.js';
46
47
  import { spawn as childSpawn, spawnSync } from 'child_process';
47
48
  import { createHash, randomUUID } from 'crypto';
48
- import { accessSync, constants as fsConstants, existsSync, readFileSync, realpathSync } from 'fs';
49
+ import { existsSync, readFileSync, realpathSync } from 'fs';
49
50
  import { mkdir, readdir, writeFile } from 'fs/promises';
50
51
  import { homedir } from 'os';
51
- import { delimiter, dirname, isAbsolute, join } from 'path';
52
+ import { dirname, isAbsolute, join } from 'path';
52
53
  import { fileURLToPath } from 'url';
53
54
  import {
54
55
  readUpstreamRefusal,
@@ -396,18 +397,8 @@ export const assertSandboxSupported = (environment = {}, platform = process.plat
396
397
  }
397
398
  };
398
399
 
399
- /** The first executable `name` on PATH, absolute, or null. No shell involved. */
400
- export const resolveOnPath = (name, pathValue) => {
401
- for (const dir of String(pathValue || '').split(delimiter)) {
402
- if (!dir || !isAbsolute(dir)) continue;
403
- const candidate = join(dir, name);
404
- try {
405
- accessSync(candidate, fsConstants.X_OK);
406
- return candidate;
407
- } catch { /* next */ }
408
- }
409
- return null;
410
- };
400
+ // Shared with the version probe (tested-version.js).
401
+ export { resolveOnPath };
411
402
 
412
403
  /**
413
404
  * pi's install tree: the nearest directory above the real entry file whose
@@ -2,6 +2,8 @@
2
2
  // only spawn/spawnSync still load this module.
3
3
  import * as childProcess from 'node:child_process';
4
4
  import { realpathSync, statSync } from 'node:fs';
5
+ import { basename } from 'node:path';
6
+ import { resolveOnPath } from '../resolve-on-path.js';
5
7
 
6
8
  // Public seats run only on a harness version smoke-tested in its sandbox, with
7
9
  // one tolerance: a stable patch release after the newest tested one, on that
@@ -28,27 +30,40 @@ export const isPatchAfterNewestTested = (version, tested) => {
28
30
  // The cache key is the binary's real path; its mtime decides freshness, so a
29
31
  // harness upgraded in place is probed again. Only a parsed version is kept: a
30
32
  // failed or unparseable probe is asked again next turn, never remembered.
33
+ //
34
+ // A bare name ('goose', 'qwen') is resolved through the probe env's PATH, as
35
+ // execFile would resolve it, never against the daemon's working directory: a
36
+ // cwd lookup missed the cache every turn and could key it on a same-named file
37
+ // there. What runs is that resolved real path, so the binary that answers is
38
+ // the one the key names. A name that does not resolve runs as given, uncached.
31
39
  const versionCache = new Map();
32
40
 
33
- export const probeVersion = async (binary, {
34
- env, timeoutMs = 30000, parse, execFileImpl = childProcess.execFile, cache = versionCache,
35
- } = {}) => {
36
- let key = null;
37
- let mtimeMs = null;
41
+ const resolveBinary = (binary, env) => {
42
+ const name = String(binary || '');
43
+ if (!name) return null;
44
+ const located = basename(name) === name ? resolveOnPath(name, env?.PATH) : name;
45
+ if (!located) return null;
38
46
  try {
39
- key = realpathSync(binary);
40
- mtimeMs = statSync(key).mtimeMs;
47
+ const key = realpathSync(located);
48
+ return { key, mtimeMs: statSync(key).mtimeMs };
41
49
  } catch {
42
- key = null;
50
+ return null;
43
51
  }
52
+ };
53
+
54
+ export const probeVersion = async (binary, {
55
+ env, timeoutMs = 30000, parse, execFileImpl = childProcess.execFile, cache = versionCache,
56
+ } = {}) => {
57
+ const resolved = resolveBinary(binary, env);
58
+ const key = resolved?.key || null;
44
59
  const hit = key ? cache.get(key) : null;
45
- if (hit && hit.mtimeMs === mtimeMs) return hit.version;
60
+ if (hit && hit.mtimeMs === resolved.mtimeMs) return hit.version;
46
61
  const stdout = await new Promise((resolve) => {
47
- execFileImpl(binary, ['--version'], { encoding: 'utf8', env, timeout: timeoutMs }, (error, out) => {
62
+ execFileImpl(key || binary, ['--version'], { encoding: 'utf8', env, timeout: timeoutMs }, (error, out) => {
48
63
  resolve(error ? null : out);
49
64
  });
50
65
  });
51
66
  const version = stdout === null ? null : parse(stdout);
52
- if (version && key) cache.set(key, { mtimeMs, version });
67
+ if (version && key) cache.set(key, { mtimeMs: resolved.mtimeMs, version });
53
68
  return version;
54
69
  };
@@ -0,0 +1,19 @@
1
+ import { accessSync, constants as fsConstants } from 'node:fs';
2
+ import { delimiter, isAbsolute, join } from 'node:path';
3
+
4
+ /**
5
+ * The first executable `name` on `pathValue`, absolute, or null. No shell
6
+ * involved, and only absolute PATH entries count: a relative entry would
7
+ * resolve against whatever the daemon's working directory happens to be.
8
+ */
9
+ export const resolveOnPath = (name, pathValue) => {
10
+ for (const dir of String(pathValue || '').split(delimiter)) {
11
+ if (!dir || !isAbsolute(dir)) continue;
12
+ const candidate = join(dir, name);
13
+ try {
14
+ accessSync(candidate, fsConstants.X_OK);
15
+ return candidate;
16
+ } catch { /* next */ }
17
+ }
18
+ return null;
19
+ };