Context7 Platform -- Up-to-date docs for AI agents
feat: add installation count metric collection (#1523)
Fahreddin Özcan04b7b395db94
diff --git a/packages/cli/src/commands/skill.ts b/packages/cli/src/commands/skill.tsindex 20a7bc46..f472ef99 100644--- a/packages/cli/src/commands/skill.ts+++ b/packages/cli/src/commands/skill.ts@@ -6,7 +6,7 @@ import { readdir, rm } from "fs/promises";import { join } from "path";import { parseSkillInput } from "../utils/parse-input.js";-import { listProjectSkills, searchSkills, downloadSkill } from "../utils/api.js";+import { listProjectSkills, searchSkills, downloadSkill, trackInstalls } from "../utils/api.js";import { log } from "../utils/logger.js";import {promptForInstallTargets,@@ -248,9 +248,9 @@ async function installCommand(const installSpinner = ora("Installing skills...").start();- let installedCount = 0;let permissionError = false;const failedDirs: Set<string> = new Set();+ const installedSkills: string[] = [];for (const skill of selectedSkills) {try {@@ -291,7 +291,7 @@ async function installCommand(}}- installedCount++;+ installedSkills.push(`${skill.project}/${skill.name}`);} catch (err) {const error = err as NodeJS.ErrnoException;if (error.code === "EACCES" || error.code === "EPERM") {@@ -314,7 +314,8 @@ async function installCommand(return;}- installSpinner.succeed(`Installed ${installedCount} skill(s)`);+ installSpinner.succeed(`Installed ${installedSkills.length} skill(s)`);+ trackInstalls(installedSkills, targets.ides);const installedNames = selectedSkills.map((s) => s.name);logInstallSummary(targets, targetDirs, installedNames);@@ -395,9 +396,9 @@ async function searchCommand(query: string): Promise<void> {const installSpinner = ora("Installing skills...").start();- let installedCount = 0;let permissionError = false;const failedDirs: Set<string> = new Set();+ const installedSkills: string[] = [];for (const skill of uniqueSkills) {try {@@ -438,7 +439,7 @@ async function searchCommand(query: string): Promise<void> {}}- installedCount++;+ installedSkills.push(`${skill.project}/${skill.name}`);} catch (err) {const error = err as NodeJS.ErrnoException;if (error.code === "EACCES" || error.code === "EPERM") {@@ -461,7 +462,8 @@ async function searchCommand(query: string): Promise<void> {return;}- installSpinner.succeed(`Installed ${installedCount} skill(s)`);+ installSpinner.succeed(`Installed ${installedSkills.length} skill(s)`);+ trackInstalls(installedSkills, targets.ides);const installedNames = uniqueSkills.map((s) => s.name);logInstallSummary(targets, targetDirs, installedNames);diff --git a/packages/cli/src/utils/api.ts b/packages/cli/src/utils/api.tsindex d76f4bfa..a9d6c788 100644--- a/packages/cli/src/utils/api.ts+++ b/packages/cli/src/utils/api.ts@@ -30,6 +30,15 @@ export async function searchSkills(query: string): Promise<SearchResponse> {return (await response.json()) as SearchResponse;}+export function trackInstalls(skills: string[], ides: string[]): void {+ if (process.env.CTX7_TELEMETRY_DISABLED || !skills.length) return;+ fetch(`${baseUrl}/api/v2/skills/track`, {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ skills, ides }),+ }).catch(() => {});+}+export async function downloadSkill(project: string, skillName: string): Promise<DownloadResponse> {const skillData = await getSkill(project, skillName);