@commonlyai/cli 0.1.380 → 0.1.382

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.380",
3
+ "version": "0.1.382",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -186,6 +186,7 @@ import {
186
186
  import { buildReplyReceipt } from '../lib/reply-receipt.js';
187
187
  import { savedRuntimeControls, withSavedRuntimeControls, effortRefusedByDevice } from '../lib/seat-runtime-controls.js';
188
188
  import { CLI } from '../lib/cli-hint.js';
189
+ import { reportRunStopped } from '../lib/run-stopped.js';
189
190
 
190
191
  // F167: shared by attach, init and register.
191
192
  const NARROWING_FLAG_HELP = 'Install even when joining this pod would limit where the agent can write in its other pods '
@@ -295,6 +296,21 @@ export const deleteAgentToken = (name) => {
295
296
  export const BOOTSTRAP_ADAPTER_DETECT_ORDER = ['claude', 'codex', 'pi'];
296
297
  export const NO_AGENT_CLI_CODE = 'no_agent_cli';
297
298
 
299
+ /**
300
+ * What `agent run` says when no token is set. On Windows the page's lines are
301
+ * PowerShell: pasted into Command Prompt, the `$env:` lines set nothing and the
302
+ * run ends here before it reaches the server (F548), so name the shell and its
303
+ * form rather than `export`.
304
+ */
305
+ export const noRunTokenMessage = ({ name, agentArg = name, platform = process.platform }) => {
306
+ const set = platform === 'win32'
307
+ ? 'In PowerShell, not Command Prompt, run the $env:COMMONLY_API_URL="…" and $env:COMMONLY_AGENT_TOKEN="…" lines'
308
+ : 'Either export COMMONLY_API_URL + COMMONLY_AGENT_TOKEN';
309
+ return `No token for '${name}'. ${set}`
310
+ + ` (shown on the Connect your own agent page) and re-run, or:`
311
+ + ` ${CLI} agent attach <adapter> --pod <podId> --name ${agentArg}`;
312
+ };
313
+
298
314
  /**
299
315
  * A saved seat with no enforced sandbox: an adapter that takes one, no
300
316
  * workspace, and an environment that is absent or enforces nothing (a record
@@ -5946,14 +5962,11 @@ Docs:
5946
5962
  process.exit(1);
5947
5963
  }
5948
5964
  if (!record) {
5949
- // F515: on Windows the page's lines are PowerShell's ($env:…), and in
5950
- // Command Prompt they set nothing, so this is where that run lands.
5951
- console.error(process.platform === 'win32'
5952
- ? `No token for '${name}'. Run all the lines from the Connect your own agent page together, `
5953
- + 'in PowerShell (not Command Prompt): the $env: lines set the token for this window.'
5954
- : `No token for '${name}'. Either export COMMONLY_API_URL + COMMONLY_AGENT_TOKEN`
5955
- + ` (shown on the Connect your own agent page) and re-run, or:`
5956
- + ` ${CLI} agent attach <adapter> --pod <podId> --name ${agentArg}`);
5965
+ // On Windows the page's lines are PowerShell's ($env:…), and in Command
5966
+ // Prompt they set nothing, so this is where that run lands.
5967
+ console.error(noRunTokenMessage({ name, agentArg }));
5968
+ // Nothing reached the server yet, so say which stop this was (F551).
5969
+ await reportRunStopped({ agentName: agentArg, reason: 'no-token' });
5957
5970
  process.exit(1);
5958
5971
  }
5959
5972
  const instanceRefusal = named ? runInstanceRefusal({ record, instanceId }) : null;
@@ -0,0 +1,44 @@
1
+ import { resolveInstanceUrl } from './config.js';
2
+
3
+ // F551: a first `agent run` with no key in its environment (the two
4
+ // `$env:` lines pasted into Command Prompt, or skipped) exits before any
5
+ // server call, so the connect page waits on a key that never arrives and
6
+ // nobody can tell this stop from a line that never ran. This tells the
7
+ // server which stop it was. It carries no key: only a fixed reason, the
8
+ // agent's name (the server matches it to a BYO agent made in the last day),
9
+ // the platform and Node's major version. Any DO_NOT_TRACK value but 0/false, or
10
+ // COMMONLY_TELEMETRY=0 turns it off. It never throws and gives up after
11
+ // `timeoutMs`, so the exit it precedes is never held up for long.
12
+ export const reportRunStopped = async ({
13
+ agentName,
14
+ reason,
15
+ env = process.env,
16
+ platform = process.platform,
17
+ nodeVersion = process.version,
18
+ fetchImpl = globalThis.fetch,
19
+ defaultUrl = () => resolveInstanceUrl(undefined),
20
+ timeoutMs = 2000,
21
+ }) => {
22
+ const dnt = String(env.DO_NOT_TRACK || '').trim().toLowerCase();
23
+ if ((dnt && dnt !== '0' && dnt !== 'false') || env.COMMONLY_TELEMETRY === '0') return false;
24
+ if (typeof fetchImpl !== 'function') return false;
25
+ const controller = new AbortController();
26
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
27
+ try {
28
+ const base = ((env.COMMONLY_API_URL || '').trim() || defaultUrl()).replace(/\/+$/, '');
29
+ const nodeMajor = Number.parseInt(String(nodeVersion).replace(/^v/, ''), 10);
30
+ const res = await fetchImpl(`${base}/api/stats/run-stopped`, {
31
+ method: 'POST',
32
+ headers: { 'Content-Type': 'application/json' },
33
+ body: JSON.stringify({
34
+ reason, agentName, platform, ...(Number.isFinite(nodeMajor) ? { nodeMajor } : {}),
35
+ }),
36
+ signal: controller.signal,
37
+ });
38
+ return Boolean(res?.ok);
39
+ } catch {
40
+ return false;
41
+ } finally {
42
+ clearTimeout(timer);
43
+ }
44
+ };