@commonlyai/cli 0.1.390 → 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 +1 -1
- package/src/commands/agent.js +1 -1
- package/src/commands/daemon.js +4 -1
- package/src/lib/cli-hint.js +9 -1
- package/src/lib/daemon-hint.js +14 -3
- package/src/lib/stable-install.js +17 -1
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -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({
|
package/src/commands/daemon.js
CHANGED
|
@@ -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);
|
package/src/lib/cli-hint.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
package/src/lib/daemon-hint.js
CHANGED
|
@@ -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
|
-
|
|
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 = ({
|
|
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
|
-
|
|
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}`
|
|
@@ -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.
|