@commonlyai/cli 0.1.381 → 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 +1 -1
- package/src/commands/agent.js +3 -0
- package/src/lib/run-stopped.js +44 -0
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -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 '
|
|
@@ -5964,6 +5965,8 @@ Docs:
|
|
|
5964
5965
|
// On Windows the page's lines are PowerShell's ($env:…), and in Command
|
|
5965
5966
|
// Prompt they set nothing, so this is where that run lands.
|
|
5966
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' });
|
|
5967
5970
|
process.exit(1);
|
|
5968
5971
|
}
|
|
5969
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
|
+
};
|