@commonlyai/cli 0.1.381 → 0.1.383
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/environment.js +261 -32
- 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;
|
package/src/lib/environment.js
CHANGED
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
|
-
readFile, mkdir, lstat, cp, rm, chmod, readdir, writeFile,
|
|
18
|
+
readFile, mkdir, lstat, cp, rm, chmod, readdir, writeFile, mkdtemp, rename, realpath, readlink,
|
|
19
19
|
} from 'fs/promises';
|
|
20
20
|
import { existsSync } from 'fs';
|
|
21
|
-
import {
|
|
22
|
-
|
|
21
|
+
import {
|
|
22
|
+
isAbsolute, join, resolve as pathResolve, basename, dirname, relative, parse, sep,
|
|
23
|
+
} from 'path';
|
|
24
|
+
import { homedir, tmpdir } from 'os';
|
|
23
25
|
import { resolveSkillSource } from './skill-prompt.js';
|
|
24
26
|
|
|
25
27
|
// ── Schema — keep the allow-list narrow; ADR-008 §invariants #1+#2 ──────────
|
|
@@ -586,6 +588,104 @@ const realSkillsDir = async (workspacePath) => {
|
|
|
586
588
|
return dir;
|
|
587
589
|
};
|
|
588
590
|
|
|
591
|
+
// F171: whether .claude and .claude/skills are still the real directories
|
|
592
|
+
// checked above. Nothing is created here: a missing or replaced one is a no.
|
|
593
|
+
const skillsDirUnchanged = async (workspacePath, checked) => {
|
|
594
|
+
let dir = workspacePath;
|
|
595
|
+
let st = null;
|
|
596
|
+
for (const part of SKILLS_DIR_PARTS) {
|
|
597
|
+
dir = join(dir, part);
|
|
598
|
+
// eslint-disable-next-line no-await-in-loop
|
|
599
|
+
st = await lstatOrNull(dir);
|
|
600
|
+
if (!st || st.isSymbolicLink() || !st.isDirectory()) return false;
|
|
601
|
+
}
|
|
602
|
+
return st.dev === checked.dev && st.ino === checked.ino;
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// F171: each snapshot is built in a folder only the host writes, then moved
|
|
606
|
+
// into place with one rename, so a link swapped into the workspace mid-mount
|
|
607
|
+
// can't steer the copy, marker or read-only writes. The workspace's parent is
|
|
608
|
+
// tried first because it shares the workspace's disk, which a rename needs;
|
|
609
|
+
// the system temp folder is the fallback.
|
|
610
|
+
const makeSkillStage = async (workspacePath) => {
|
|
611
|
+
try {
|
|
612
|
+
return await mkdtemp(join(dirname(workspacePath), '.commonly-skill-stage-'));
|
|
613
|
+
} catch {
|
|
614
|
+
return mkdtemp(join(tmpdir(), 'commonly-skill-stage-'));
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
// Whether `child` is `parent` or lies under it. Only a whole `..` part
|
|
619
|
+
// leaves `parent`; a child named `..skills` is still inside it.
|
|
620
|
+
const isWithin = (child, parent) => {
|
|
621
|
+
const rel = relative(parent, child);
|
|
622
|
+
return !isAbsolute(rel) && rel !== '..' && !rel.startsWith(`..${sep}`);
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// A folder's identity on disk. Paths can't be compared as strings: macOS
|
|
626
|
+
// disks ignore case and Unicode normalization by default, so `/WS` and `/ws`
|
|
627
|
+
// are one folder. Read with bigint stats: inode numbers can pass 2^53.
|
|
628
|
+
const folderId = (st) => `${st.dev}:${st.ino}`;
|
|
629
|
+
|
|
630
|
+
// realpath, one part at a time, returning every path it passed through and
|
|
631
|
+
// the identity of every real folder on the way. realpath alone gives only the
|
|
632
|
+
// end, so a chain that goes through a folder the seat writes and back out
|
|
633
|
+
// would look clean.
|
|
634
|
+
const MAX_LINK_HOPS = 40;
|
|
635
|
+
const resolveVisiting = async (target) => {
|
|
636
|
+
const abs = pathResolve(target);
|
|
637
|
+
let current = parse(abs).root;
|
|
638
|
+
const rest = abs.slice(current.length).split(sep).filter(Boolean);
|
|
639
|
+
const visited = [];
|
|
640
|
+
const folders = new Set();
|
|
641
|
+
let hops = 0;
|
|
642
|
+
while (rest.length) {
|
|
643
|
+
const part = rest.shift();
|
|
644
|
+
if (part === '.') continue;
|
|
645
|
+
if (part === '..') {
|
|
646
|
+
// `current` has no links in it, so its parent is the real parent.
|
|
647
|
+
current = dirname(current);
|
|
648
|
+
visited.push(current);
|
|
649
|
+
// eslint-disable-next-line no-await-in-loop
|
|
650
|
+
folders.add(folderId(await lstat(current, { bigint: true })));
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
const next = join(current, part);
|
|
654
|
+
visited.push(next);
|
|
655
|
+
// eslint-disable-next-line no-await-in-loop
|
|
656
|
+
const st = await lstat(next, { bigint: true });
|
|
657
|
+
if (!st.isSymbolicLink()) {
|
|
658
|
+
folders.add(folderId(st));
|
|
659
|
+
current = next;
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
hops += 1;
|
|
663
|
+
if (hops > MAX_LINK_HOPS) throw Object.assign(new Error(`too many links: ${target}`), { code: 'ELOOP' });
|
|
664
|
+
// eslint-disable-next-line no-await-in-loop
|
|
665
|
+
const link = await readlink(next);
|
|
666
|
+
if (isAbsolute(link)) current = parse(link).root;
|
|
667
|
+
rest.unshift(...link.slice(isAbsolute(link) ? parse(link).root.length : 0).split(sep).filter(Boolean));
|
|
668
|
+
}
|
|
669
|
+
return { visited, folders };
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
// Why a source that can't be resolved is refused: one that isn't there, or
|
|
673
|
+
// one that can be read but not followed (a loop, no permission).
|
|
674
|
+
const unresolvedReason = (err) => (
|
|
675
|
+
err?.code === 'ENOENT' || err?.code === 'ENOTDIR' ? 'missing-source' : 'unreadable-source'
|
|
676
|
+
);
|
|
677
|
+
|
|
678
|
+
// Whether a copied tree holds a link anywhere in it. Read in the stage, which
|
|
679
|
+
// only the host writes, so nothing can change it between the copy and here.
|
|
680
|
+
const holdsLink = async (dir) => {
|
|
681
|
+
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
|
682
|
+
if (entry.isSymbolicLink()) return true;
|
|
683
|
+
// eslint-disable-next-line no-await-in-loop
|
|
684
|
+
if (entry.isDirectory() && await holdsLink(join(dir, entry.name))) return true;
|
|
685
|
+
}
|
|
686
|
+
return false;
|
|
687
|
+
};
|
|
688
|
+
|
|
589
689
|
/**
|
|
590
690
|
* Mount each `skills.claude[]` source into `<workspacePath>/.claude/skills/`
|
|
591
691
|
* as a READ-ONLY SNAPSHOT COPY.
|
|
@@ -614,14 +714,40 @@ const realSkillsDir = async (workspacePath) => {
|
|
|
614
714
|
*
|
|
615
715
|
* A workspace whose .claude or .claude/skills is a link, or not a directory,
|
|
616
716
|
* gets no mount at all: every source is reported as 'unsafe-skill-dir' and
|
|
617
|
-
* nothing is written (F171).
|
|
717
|
+
* nothing is written (F171). Each snapshot is built outside the workspace and
|
|
718
|
+
* renamed into place after a fresh check, and a replaced mount is moved out
|
|
719
|
+
* before it is deleted, so a swap mid-mount is refused the same way. What is
|
|
720
|
+
* left is the moment between that check and the renames: Node has no
|
|
721
|
+
* renameat, so they still resolve the path. A swap there can move whatever
|
|
722
|
+
* has the slot's name at the link's target into the stage, and put the
|
|
723
|
+
* snapshot there. What arrives in the stage is checked there: only a link or
|
|
724
|
+
* a directory carrying MOUNT_MARKER is deleted; anything else is kept in the
|
|
725
|
+
* stage folder, beside the workspace, and reported. Nothing is ever copied or
|
|
726
|
+
* deleted at a workspace path: when the stage is on another disk, so a rename
|
|
727
|
+
* fails with EXDEV, the mount is refused ('cross-disk-stage'), and an old
|
|
728
|
+
* mount already moved out is kept rather than deleted.
|
|
729
|
+
*
|
|
730
|
+
* A source in the workspace, or one that resolves into it, is refused
|
|
731
|
+
* ('source-in-workspace'): the seat writes there, so it could make the source
|
|
732
|
+
* a link to any host folder. A source that is itself a link is copied as the
|
|
733
|
+
* folder it points to. A link inside a source is never followed: a source
|
|
734
|
+
* holding one, or swapped for one after it was resolved, is refused
|
|
735
|
+
* ('linked-skill-file'), since following it would copy whatever it names, a
|
|
736
|
+
* credential included, into a folder the seat reads. Links are judged by
|
|
737
|
+
* lstat, so a hard link is a file; only the source's owner can make one.
|
|
738
|
+
*
|
|
739
|
+
* `hooks.onStep(step)` is for tests: it runs after the check ('checked'),
|
|
740
|
+
* after each source is resolved ('resolved'), after each snapshot is built
|
|
741
|
+
* ('staged') and after the slot is read ('slot-checked'). `hooks.rename`
|
|
742
|
+
* stands in for fs.rename, so a test can fail it as another disk would.
|
|
618
743
|
*
|
|
619
744
|
* Returns `{ mounted, conflicted }`:
|
|
620
745
|
* - `mounted`: string[] — absolute source paths snapshotted
|
|
621
746
|
* - `conflicted`: Array<{path, reason}> where reason ∈
|
|
622
|
-
* 'not-a-mount' | 'missing-source' | 'unsafe-skill-dir'
|
|
747
|
+
* 'not-a-mount' | 'missing-source' | 'unreadable-source' | 'unsafe-skill-dir'
|
|
748
|
+
* | 'cross-disk-stage' | 'linked-skill-file' | 'source-in-workspace'
|
|
623
749
|
*/
|
|
624
|
-
export const mountSkills = async (spec, workspacePath, envFileDir = null) => {
|
|
750
|
+
export const mountSkills = async (spec, workspacePath, envFileDir = null, hooks = {}) => {
|
|
625
751
|
const sources = Array.isArray(spec?.skills?.claude) ? spec.skills.claude : [];
|
|
626
752
|
const mounted = [];
|
|
627
753
|
const conflicted = [];
|
|
@@ -637,6 +763,11 @@ export const mountSkills = async (spec, workspacePath, envFileDir = null) => {
|
|
|
637
763
|
})),
|
|
638
764
|
};
|
|
639
765
|
}
|
|
766
|
+
const checked = await lstat(skillsDir);
|
|
767
|
+
await hooks.onStep?.('checked');
|
|
768
|
+
const move = hooks.rename || rename;
|
|
769
|
+
const workspaceReal = await realpath(workspacePath);
|
|
770
|
+
const workspaceId = folderId(await lstat(workspaceReal, { bigint: true }));
|
|
640
771
|
|
|
641
772
|
for (const rawSource of sources) {
|
|
642
773
|
const absSource = resolveSkillSource(rawSource, envFileDir || workspacePath);
|
|
@@ -644,41 +775,139 @@ export const mountSkills = async (spec, workspacePath, envFileDir = null) => {
|
|
|
644
775
|
conflicted.push({ path: absSource, reason: 'missing-source' });
|
|
645
776
|
continue;
|
|
646
777
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
778
|
+
// The seat writes its workspace, so a source there (a relative entry
|
|
779
|
+
// resolves against it) could be made a link to any host folder, and
|
|
780
|
+
// following it would copy that folder in. One that resolves into the
|
|
781
|
+
// workspace is the seat's own writing, and so is one whose links pass
|
|
782
|
+
// through it on the way somewhere else, or one that holds the workspace.
|
|
783
|
+
// All of these are refused. Every way into the workspace passes through
|
|
784
|
+
// the workspace folder itself, so the walk is checked by folder identity,
|
|
785
|
+
// which no spelling of the path can dodge. realSource comes from realpath,
|
|
786
|
+
// spelled as on disk, so the copy and the string checks agree with it.
|
|
787
|
+
let resolved;
|
|
788
|
+
let realSource;
|
|
650
789
|
try {
|
|
651
790
|
// eslint-disable-next-line no-await-in-loop
|
|
652
|
-
|
|
791
|
+
resolved = await resolveVisiting(absSource);
|
|
792
|
+
// eslint-disable-next-line no-await-in-loop
|
|
793
|
+
realSource = await realpath(absSource);
|
|
653
794
|
} catch (err) {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
795
|
+
conflicted.push({ path: absSource, reason: unresolvedReason(err) });
|
|
796
|
+
continue;
|
|
797
|
+
}
|
|
798
|
+
const entersWorkspace = resolved.folders.has(workspaceId)
|
|
799
|
+
|| resolved.visited.some((step) => isWithin(step, workspaceReal) || isWithin(step, workspacePath));
|
|
800
|
+
if (isWithin(absSource, workspacePath) || entersWorkspace
|
|
801
|
+
|| isWithin(realSource, workspaceReal) || isWithin(workspaceReal, realSource)) {
|
|
802
|
+
conflicted.push({ path: absSource, reason: 'source-in-workspace' });
|
|
803
|
+
continue;
|
|
658
804
|
}
|
|
805
|
+
// eslint-disable-next-line no-await-in-loop
|
|
806
|
+
await hooks.onStep?.('resolved');
|
|
807
|
+
const destPath = join(skillsDir, basename(absSource));
|
|
808
|
+
// eslint-disable-next-line no-await-in-loop
|
|
809
|
+
const stage = await makeSkillStage(workspacePath);
|
|
810
|
+
// Set when the stage holds something that may not be ours, so it is kept.
|
|
811
|
+
let keepStage = false;
|
|
812
|
+
try {
|
|
813
|
+
const snapshot = join(stage, 'new');
|
|
814
|
+
// A source that is a link (a ~/.claude/skills entry into a checkout)
|
|
815
|
+
// is copied as the folder it points to: a copied link would make the
|
|
816
|
+
// mount write through to the source. Links inside it are copied as
|
|
817
|
+
// links and then refused, never followed. A source swapped for a link
|
|
818
|
+
// after it was resolved arrives as a link at the snapshot's root.
|
|
819
|
+
// eslint-disable-next-line no-await-in-loop
|
|
820
|
+
await cp(realSource, snapshot, { recursive: true, verbatimSymlinks: true });
|
|
821
|
+
// eslint-disable-next-line no-await-in-loop
|
|
822
|
+
const copied = await lstat(snapshot);
|
|
823
|
+
// eslint-disable-next-line no-await-in-loop
|
|
824
|
+
if (copied.isSymbolicLink() || !copied.isDirectory() || await holdsLink(snapshot)) {
|
|
825
|
+
conflicted.push({ path: absSource, reason: 'linked-skill-file' });
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
// eslint-disable-next-line no-await-in-loop
|
|
829
|
+
await writeFile(join(snapshot, MOUNT_MARKER), `mounted-from: ${absSource}\n`, 'utf8');
|
|
830
|
+
// eslint-disable-next-line no-await-in-loop
|
|
831
|
+
await freezeFiles(snapshot);
|
|
832
|
+
// eslint-disable-next-line no-await-in-loop
|
|
833
|
+
await hooks.onStep?.('staged');
|
|
659
834
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if (!isLegacySymlink && !isOwnedMount) {
|
|
664
|
-
// A real file, or a directory we did not create — user content.
|
|
665
|
-
conflicted.push({ path: absSource, reason: 'not-a-mount' });
|
|
835
|
+
// eslint-disable-next-line no-await-in-loop
|
|
836
|
+
if (!await skillsDirUnchanged(workspacePath, checked)) {
|
|
837
|
+
conflicted.push({ path: absSource, reason: 'unsafe-skill-dir' });
|
|
666
838
|
continue;
|
|
667
839
|
}
|
|
840
|
+
|
|
841
|
+
let slot = null;
|
|
842
|
+
try {
|
|
843
|
+
// eslint-disable-next-line no-await-in-loop
|
|
844
|
+
slot = await lstat(destPath);
|
|
845
|
+
} catch (err) {
|
|
846
|
+
// Only ENOENT means "slot is free, proceed." EACCES / EPERM / EIO are
|
|
847
|
+
// real failures that should surface rather than becoming a confusing
|
|
848
|
+
// follow-on error from the rename below.
|
|
849
|
+
if (err.code !== 'ENOENT') throw err;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
if (slot) {
|
|
853
|
+
const isLegacySymlink = slot.isSymbolicLink();
|
|
854
|
+
const isOwnedMount = slot.isDirectory() && existsSync(join(destPath, MOUNT_MARKER));
|
|
855
|
+
if (!isLegacySymlink && !isOwnedMount) {
|
|
856
|
+
// A real file, or a directory we did not create — user content.
|
|
857
|
+
conflicted.push({ path: absSource, reason: 'not-a-mount' });
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
668
861
|
// eslint-disable-next-line no-await-in-loop
|
|
669
|
-
await
|
|
670
|
-
|
|
862
|
+
await hooks.onStep?.('slot-checked');
|
|
863
|
+
|
|
864
|
+
const retired = join(stage, 'old');
|
|
865
|
+
if (slot) {
|
|
866
|
+
// Moved out first: the recursive delete runs in the stage, never at
|
|
867
|
+
// a path inside the workspace. The move resolves the path again, so
|
|
868
|
+
// what arrived is checked in the stage, which only the host writes:
|
|
869
|
+
// only a link or one of our marked mounts is ever deleted.
|
|
870
|
+
try {
|
|
871
|
+
// eslint-disable-next-line no-await-in-loop
|
|
872
|
+
await move(destPath, retired);
|
|
873
|
+
} catch (err) {
|
|
874
|
+
if (err.code !== 'EXDEV') throw err;
|
|
875
|
+
conflicted.push({ path: absSource, reason: 'cross-disk-stage' });
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
// eslint-disable-next-line no-await-in-loop
|
|
879
|
+
const moved = await lstat(retired);
|
|
880
|
+
// eslint-disable-next-line no-await-in-loop
|
|
881
|
+
const marker = moved.isDirectory() ? await lstatOrNull(join(retired, MOUNT_MARKER)) : null;
|
|
882
|
+
if (!moved.isSymbolicLink() && !(marker && marker.isFile())) {
|
|
883
|
+
keepStage = true;
|
|
884
|
+
conflicted.push({ path: absSource, reason: 'unsafe-skill-dir' });
|
|
885
|
+
continue;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
671
888
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
889
|
+
try {
|
|
890
|
+
// eslint-disable-next-line no-await-in-loop
|
|
891
|
+
await move(snapshot, destPath);
|
|
892
|
+
} catch (err) {
|
|
893
|
+
// The old mount, if any, is in the stage now: keep it rather than
|
|
894
|
+
// delete it with the stage.
|
|
895
|
+
keepStage = Boolean(slot);
|
|
896
|
+
if (err.code !== 'EXDEV') throw err;
|
|
897
|
+
conflicted.push({ path: absSource, reason: 'cross-disk-stage' });
|
|
898
|
+
continue;
|
|
899
|
+
}
|
|
900
|
+
} finally {
|
|
901
|
+
if (keepStage) {
|
|
902
|
+
// eslint-disable-next-line no-console
|
|
903
|
+
console.warn(`[skills] ${destPath}: the slot changed during the mount; what was there is kept in ${stage}`);
|
|
904
|
+
// eslint-disable-next-line no-await-in-loop
|
|
905
|
+
await rm(join(stage, 'new'), { recursive: true, force: true });
|
|
906
|
+
} else {
|
|
907
|
+
// eslint-disable-next-line no-await-in-loop
|
|
908
|
+
await rm(stage, { recursive: true, force: true });
|
|
909
|
+
}
|
|
910
|
+
}
|
|
682
911
|
mounted.push(absSource);
|
|
683
912
|
}
|
|
684
913
|
|
|
@@ -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
|
+
};
|