@commonlyai/cli 0.1.389 → 0.1.391

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.389",
3
+ "version": "0.1.391",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -6211,7 +6211,7 @@ Docs:
6211
6211
  });
6212
6212
 
6213
6213
  console.log(`${stamp()} [${name}] polling ${record.instanceUrl} for events (ctrl+c to stop)`);
6214
- console.log(`${stamp()} [${name}] ${foregroundDaemonHint({ daemonRegistered: hasDaemonRecord() })}`);
6214
+ console.log(`${stamp()} [${name}] ${foregroundDaemonHint({ daemonRegistered: hasDaemonRecord(), instanceUrl: record.instanceUrl })}`);
6215
6215
  // TASK-660: one line when this CLI is stale. Fired, not awaited, so a
6216
6216
  // slow registry never delays the first poll.
6217
6217
  startUpdateNotice({
@@ -57,7 +57,7 @@ import {
57
57
  } from '../lib/daemon-agent-states.js';
58
58
  import { installedCliVersion, startUpdateNotice, UPDATE_CHECK_OPT_OUT_ENV } from '../lib/update-check.js';
59
59
  import { machineHostReport } from '../lib/machine-host.js';
60
- import { orchestrateDaemonSetup } from '../lib/stable-install.js';
60
+ import { npxInstallRefusal, orchestrateDaemonSetup } from '../lib/stable-install.js';
61
61
  import { CLI } from '../lib/cli-hint.js';
62
62
 
63
63
  // Set on the steps `daemon setup` runs, so a step can leave a line to setup.
@@ -598,6 +598,9 @@ Examples:
598
598
  .option(REPLACE_FLAG, REPLACE_HELP)
599
599
  .action(async (opts) => {
600
600
  try {
601
+ // F570: never pin a service to npx's cache.
602
+ const npxRefusal = npxInstallRefusal();
603
+ if (npxRefusal) throw new Error(npxRefusal);
601
604
  if (opts.unsandboxed) {
602
605
  const flagRefusal = unsandboxedFlagRefusal();
603
606
  if (flagRefusal) throw new Error(flagRefusal);
@@ -148,7 +148,8 @@ const WORK_CUES = [PARALLEL_READS_CUE, ROW_SLICING_CUE, BACKGROUND_PROCESS_CUE];
148
148
  const RUNTIME_CREDENTIAL_PLACEHOLDER = '${COMMONLY_AGENT_TOKEN}';
149
149
 
150
150
  // A workspace seat's sandbox.filesystem.read-outside, with `~` expanded the way
151
- // bwrap.js expands it. Anything still relative is refused by the profile.
151
+ // bwrap.js expands it. resolveHostReadDirectories refuses anything still
152
+ // relative, naming the entry, before the turn spawns.
152
153
  const workspaceReadOutside = (env) => {
153
154
  const declared = env?.sandbox?.filesystem?.['read-outside'];
154
155
  if (!Array.isArray(declared)) return [];
@@ -15,7 +15,15 @@
15
15
  // The guard in __tests__/cli-hint.test.mjs fails on a `commonly <subcommand>`
16
16
  // written into a string anywhere else in cli/src: use `${CLI} <subcommand>`.
17
17
 
18
- export const cliName = (platform = process.platform) => (platform === 'win32' ? 'commonly.cmd' : 'commonly');
18
+ //
19
+ // Run through npx (F570: the Bring your own page's line), the CLI lives under
20
+ // a `_npx` folder of npm's cache and no `commonly` is on PATH, so a hint that
21
+ // names `commonly` would fail; it names the npx line that started it instead.
22
+ export const runsFromNpxCache = (entry = process.argv[1]) => Boolean(entry) && /[\\/]_npx[\\/]/.test(String(entry));
23
+ export const cliName = (platform = process.platform, { entry = process.argv[1] } = {}) => {
24
+ if (runsFromNpxCache(entry)) return `${npxName(platform)} -y @commonlyai/cli@latest`;
25
+ return platform === 'win32' ? 'commonly.cmd' : 'commonly';
26
+ };
19
27
  export const npxName = (platform = process.platform) => (platform === 'win32' ? 'npx.cmd' : 'npx');
20
28
  export const npmName = (platform = process.platform) => (platform === 'win32' ? 'npm.cmd' : 'npm');
21
29
 
@@ -4,13 +4,24 @@
4
4
  //
5
5
  // The two daemon steps depend on each other, so on Windows they print one per
6
6
  // line instead of joined with `&&`, which Windows PowerShell 5.1 lacks (F435).
7
- import { cliName, cliSteps } from './cli-hint.js';
7
+ //
8
+ // Run from npx's cache (F570: the Bring your own page's line), `daemon
9
+ // install` would pin the service to a folder npm can clear, so the hint names
10
+ // the one line that installs a stable copy first (`daemon setup`, F370).
11
+ import { cliName, cliSteps, npxName, runsFromNpxCache } from './cli-hint.js';
8
12
 
9
- export const foregroundDaemonHint = ({ daemonRegistered, platform = process.platform }) => {
13
+ export const foregroundDaemonHint = ({
14
+ daemonRegistered, platform = process.platform, entry = process.argv[1], instanceUrl = null,
15
+ }) => {
10
16
  const lead = 'foreground mode; this stops when the terminal closes. To keep it running, ';
11
17
  const inWebApp = 'the web app: Agents → Bring your own → On my computer';
12
18
  if (daemonRegistered) return `${lead}add the agent to this computer in ${inWebApp}`;
13
- const cli = cliName(platform);
19
+ if (runsFromNpxCache(entry)) {
20
+ const setup = `${npxName(platform)} -y @commonlyai/cli@latest daemon setup`
21
+ + `${instanceUrl ? ` --instance ${instanceUrl}` : ''}${platform === 'win32' ? ' --unsandboxed' : ''}`;
22
+ return `${lead}add this computer once with: ${setup}\n then add the agent to it in ${inWebApp}`;
23
+ }
24
+ const cli = cliName(platform, { entry });
14
25
  const steps = cliSteps([`${cli} daemon register`, `${cli} daemon install`], { platform, indent: ' ' });
15
26
  return platform === 'win32'
16
27
  ? `${lead}add this computer by running these two commands, one after the other:${steps}\n then add the agent to it in ${inWebApp}`
@@ -625,6 +625,11 @@ export const resolveHostReadDirectories = (entries, home = homedir(), { fold = t
625
625
  try {
626
626
  const canonicalHome = canonicalPath(home);
627
627
  return entries.map((entry) => {
628
+ // A relative entry would resolve against the CLI's own folder, which is
629
+ // no folder the operator named (CodeRabbit on #4111). Callers expand ~/.
630
+ if (typeof entry !== 'string' || !isAbsolute(entry)) {
631
+ throw new Error(`refusing sandbox.filesystem.read-outside ${entry}: name a folder by its absolute path or by ~/.`);
632
+ }
628
633
  const canonical = canonicalPath(entry);
629
634
  let reason = hostReadRefusal(canonical, canonicalHome);
630
635
  if (!reason && only && !only.some((allowed) => foldedWithin(join(canonicalHome, allowed), canonical))) {
@@ -797,10 +802,12 @@ export const buildSeatbeltProfile = ({
797
802
  `(allow file-read* file-test-existence ${subpath(path)})`,
798
803
  `(allow file-read-metadata file-test-existence (path-ancestors "${escapeSbplString(path)}"))`,
799
804
  ].join('\n'))).join('\n');
800
- // The adapter's own read-only inputs, without the host read grants.
805
+ // The adapter's own read-only inputs, stated again after the host dot denies.
806
+ // Built from the adapter's list itself, so a folder the seat also names keeps
807
+ // the adapter's view of it, dot files included (CodeRabbit on #4111).
801
808
  const adapterReadOnlyRules = resolvedReadOnlyPaths.map((path) => (
802
809
  `(allow file-read* file-test-existence ${literal(path)})`
803
- )).concat(resolvedReadOnlyDirectories.filter((path) => !grantedHostReads.includes(path)).map((path) => (
810
+ )).concat([...new Set(readOnlyDirectories.map(realpathOrSelf))].map((path) => (
804
811
  `(allow file-read* file-test-existence ${subpath(path)})`
805
812
  ))).join('\n');
806
813
  // A symlinked entry is held at both its name and its target, so the write
@@ -24,7 +24,7 @@ import { existsSync, mkdirSync, readFileSync } from 'fs';
24
24
  import { homedir } from 'os';
25
25
  import { join, sep } from 'path';
26
26
  import { resolveLaunch } from './windows-command.js';
27
- import { NPX } from './cli-hint.js';
27
+ import { NPX, npxName, runsFromNpxCache } from './cli-hint.js';
28
28
 
29
29
  export const CLI_PACKAGE = '@commonlyai/cli';
30
30
 
@@ -38,6 +38,22 @@ export const stableCliDir = (home = homedir()) => join(home, '.commonly', 'cli')
38
38
  /** The one line that sets up or updates a computer, for advice the CLI prints. */
39
39
  export const DAEMON_SETUP_LINE = `${NPX} -y ${CLI_PACKAGE}@latest daemon setup`;
40
40
 
41
+ /**
42
+ * F570: `daemon install` run from npx's cache would pin the service to a
43
+ * folder npm can clear (see the top of this file), and since the Bring your
44
+ * own page's line runs the CLI through npx, a hint that names `daemon install`
45
+ * can be run from there. Refused with the setup line instead; `daemon setup`
46
+ * runs its install step as the stable copy, so this never refuses it.
47
+ */
48
+ export const npxInstallRefusal = ({ entry = process.argv[1], platform = process.platform } = {}) => (
49
+ runsFromNpxCache(entry)
50
+ ? 'this CLI is running from npx\'s cache, which npm can clear, so a login service installed from it would stop '
51
+ + 'starting with nothing on screen to say why. Set this computer up with '
52
+ + `${npxName(platform)} -y ${CLI_PACKAGE}@latest daemon setup --instance <your Commonly URL>`
53
+ + `${platform === 'win32' ? ' --unsandboxed' : ''}, which installs a stable copy first `
54
+ + '(the web app shows the exact line under Agents → Bring your own → Add a computer).'
55
+ : null);
56
+
41
57
  /** True when this process runs the copy `daemon setup` installed under $HOME. */
42
58
  export const runsFromStableInstall = (entry = process.argv[1], home = homedir()) => (
43
59
  // The folder plus a separator, so a sibling such as ~/.commonly/cli-old never matches.