@commonlyai/cli 0.1.390 → 0.1.392

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.390",
3
+ "version": "0.1.392",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -41,7 +41,7 @@ import { formatDigestFrame, formatUnreadMessagesFrame } from '../lib/digest-fram
41
41
  import { startWebhookServer, forwardToLocalWebhook, logOnlyHandler } from '../lib/webhook-server.js';
42
42
  import { getAdapter, listAdapterNames, listPublicAdapterNames } from '../lib/adapters/index.js';
43
43
  import {
44
- harnessFindings, nodeFinding, preflightOutcome, reportListenBlocked,
44
+ harnessFindings, nodeFinding, preflightOutcome, reportListenBlocked, SANDBOX_STOPS,
45
45
  } from '../lib/run-preflight.js';
46
46
  import {
47
47
  getSession,
@@ -296,6 +296,9 @@ export const deleteAgentToken = (name) => {
296
296
  // just because its binary happens to be installed on the operator's machine.
297
297
  export const BOOTSTRAP_ADAPTER_DETECT_ORDER = ['claude', 'codex', 'pi'];
298
298
  export const NO_AGENT_CLI_CODE = 'no_agent_cli';
299
+ // F571: the instance answered 401 to the first-run key, so the run can't sign
300
+ // in to say why it stopped, and reports without a key instead.
301
+ export const TOKEN_REFUSED_CODE = 'token_refused';
299
302
 
300
303
  /**
301
304
  * What `agent run` says when no token is set. On Windows the page's lines are
@@ -596,10 +599,14 @@ export const bootstrapAgentRecordFromEnv = async ({
596
599
  client = clientFactory({ instance: instanceUrl, token: runtimeToken });
597
600
  identity = await client.get('/api/agents/runtime/installations');
598
601
  } catch (err) {
599
- throw new Error(
602
+ const resolveErr = new Error(
600
603
  `Could not resolve the agent behind COMMONLY_AGENT_TOKEN against ${instanceUrl}: ${err.message}. `
601
604
  + 'Check the token was copied whole and the URL matches the instance that issued it.',
602
605
  );
606
+ // 401 alone, as adoptEnvToken reads it: a 403 comes from something in
607
+ // front of the app, and a network failure means nothing reached it.
608
+ if (err?.status === 401) resolveErr.code = TOKEN_REFUSED_CODE;
609
+ throw resolveErr;
603
610
  }
604
611
 
605
612
  const installs = Array.isArray(identity?.installations) ? identity.installations : [];
@@ -6020,6 +6027,12 @@ Docs:
6020
6027
  if (err.code === NO_AGENT_CLI_CODE && process.platform === 'win32') {
6021
6028
  console.error(windowsSandboxMessage('claude'));
6022
6029
  }
6030
+ // F571: a refused key can't sign the listen-blocked report, so this
6031
+ // one goes keyless, by name and code only. An unreachable instance
6032
+ // hears nothing either way, so nothing is sent for it.
6033
+ if (err.code === TOKEN_REFUSED_CODE) {
6034
+ await reportRunStopped({ agentName: agentArg, reason: 'token-refused' });
6035
+ }
6023
6036
  process.exit(1);
6024
6037
  }
6025
6038
  if (!record) {
@@ -6068,6 +6081,15 @@ Docs:
6068
6081
  const flagRefusal = unsandboxedFlagRefusal(process.platform, { adapterName: record.adapter });
6069
6082
  if (flagRefusal) {
6070
6083
  console.error(`${stamp()} [${name}] ${flagRefusal}`);
6084
+ // F571: the record's token still works here, so the page hears why.
6085
+ // Only a first run: the page waits on nothing else, and a saved seat's
6086
+ // respawn must not wait on a black-holed instance.
6087
+ if (bootstrapped) {
6088
+ await reportListenBlocked(
6089
+ createClient({ instance: record.instanceUrl, token: record.runtimeToken }),
6090
+ SANDBOX_STOPS.flagRefused,
6091
+ );
6092
+ }
6071
6093
  process.exit(1);
6072
6094
  }
6073
6095
  }
@@ -6126,6 +6148,14 @@ Docs:
6126
6148
  });
6127
6149
  if (hostRefusal) {
6128
6150
  console.error(`${stamp()} [${name}] ${hostRefusal}`);
6151
+ // F571: by code only; the refusal text can name a path on this computer.
6152
+ // First run only, as above.
6153
+ if (bootstrapped) {
6154
+ await reportListenBlocked(
6155
+ createClient({ instance: record.instanceUrl, token: record.runtimeToken }),
6156
+ SANDBOX_STOPS.hostRefused,
6157
+ );
6158
+ }
6129
6159
  process.exit(1);
6130
6160
  }
6131
6161
  // F444: on Linux a private Codex seat has a sandbox, so a flag its pods
@@ -6211,7 +6241,7 @@ Docs:
6211
6241
  });
6212
6242
 
6213
6243
  console.log(`${stamp()} [${name}] polling ${record.instanceUrl} for events (ctrl+c to stop)`);
6214
- console.log(`${stamp()} [${name}] ${foregroundDaemonHint({ daemonRegistered: hasDaemonRecord() })}`);
6244
+ console.log(`${stamp()} [${name}] ${foregroundDaemonHint({ daemonRegistered: hasDaemonRecord(), instanceUrl: record.instanceUrl })}`);
6215
6245
  // TASK-660: one line when this CLI is stale. Fired, not awaited, so a
6216
6246
  // slow registry never delays the first poll.
6217
6247
  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);
@@ -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}`
@@ -20,7 +20,19 @@ import { resolveWindowsCommandWithReason } from './windows-command.js';
20
20
 
21
21
  // The reason codes the instance accepts (POST /api/agents/runtime/listen-blocked).
22
22
  // A code, never text: nothing from this computer but the code is sent.
23
- export const LISTEN_BLOCKED_REASONS = ['node-too-old', 'harness-signed-out'];
23
+ export const LISTEN_BLOCKED_REASONS = [
24
+ 'node-too-old', 'harness-signed-out', 'sandbox-unavailable', 'unsandboxed-refused',
25
+ ];
26
+
27
+ // F571: the two sandbox stops `agent run` makes once it has read the record,
28
+ // and so holds a token the instance accepts. Neither names a harness, and the
29
+ // refusal text stays in the terminal: it can carry a path.
30
+ export const SANDBOX_STOPS = Object.freeze({
31
+ // This computer can't start the sandbox the seat runs in.
32
+ hostRefused: Object.freeze({ reason: 'sandbox-unavailable', harness: null }),
33
+ // --unsandboxed was typed where it doesn't apply to this agent.
34
+ flagRefused: Object.freeze({ reason: 'unsandboxed-refused', harness: null }),
35
+ });
24
36
 
25
37
  // The floor the CLI declares, read as `commonly doctor` reads it.
26
38
  const CLI_ENGINES_NODE = (() => {
@@ -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.