Skip to content

"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/

Python

feat(hub): fetch live analytics from PostHog in-browser, drop static snapshot

yuhao412754f216fe
diff --git a/.github/scripts/update_hub_analytics_stats.py b/.github/scripts/update_hub_analytics_stats.py
deleted file mode 100644
index 6a41b8451..000000000
--- a/.github/scripts/update_hub_analytics_stats.py
+++ /dev/null
@@ -1,149 +0,0 @@
-#!/usr/bin/env python3
-"""Generate docs/hub/analytics-stats.json from a fixed Umami baseline plus PostHog increments."""
-
-from __future__ import annotations
-
-import json
-import os
-import sys
-from datetime import UTC, datetime
-from pathlib import Path
-from urllib import error, request
-
-
-REPO_ROOT = Path(__file__).resolve().parents[2]
-OUTPUT_PATH = REPO_ROOT / "docs" / "hub" / "analytics-stats.json"
-
-SITE = "clianything.cc"
-MIGRATION_STARTED_AT = "2026-04-23T09:06:38Z"
-MIGRATION_STARTED_AT_MS = 1776935198505
-DEFAULT_POSTHOG_APP_HOST = "https://us.posthog.com"
-DEFAULT_POSTHOG_PROJECT_ID = "393992"
-
-BASELINE = {
- "provider": "umami",
- "site": SITE,
- "scope": "clianything.cc only",
- "queried_at": "2026-04-23T09:06:38.505000+00:00",
- "total": 21123,
- "human": 7689,
- "agent": 13434,
- "cli_hub_total": 16361,
- "cli_hub_human": 3237,
- "cli_hub_agent": 13124,
-}
-
-
-def _posthog_increment():
- api_key = os.environ.get("POSTHOG_PERSONAL_API_KEY", "").strip()
- app_host = os.environ.get("POSTHOG_APP_HOST", DEFAULT_POSTHOG_APP_HOST).rstrip("/")
- project_id = os.environ.get("POSTHOG_PROJECT_ID", DEFAULT_POSTHOG_PROJECT_ID).strip()
-
- if not api_key:
- return {
- "status": "missing_api_key",
- "total": 0,
- "human": 0,
- "agent": 0,
- "cli_hub_total": 0,
- "cli_hub_human": 0,
- "cli_hub_agent": 0,
- }
-
- hogql = (
- "select "
- "countIf(event = 'visit-human' and properties.source = 'web' and properties.site = 'clianything.cc') as human, "
- "countIf(event = 'visit-agent' and properties.source = 'web' and properties.site = 'clianything.cc') as agent, "
- "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = false) as cli_hub_human, "
- "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = true) as cli_hub_agent "
- "from events "
- f"where timestamp >= parseDateTimeBestEffort('{MIGRATION_STARTED_AT}') "
- )
- payload = {
- "query": {
- "kind": "HogQLQuery",
- "query": hogql,
- },
- "name": "cli-anything hub public website stats",
- }
- req = request.Request(
- f"{app_host}/api/projects/{project_id}/query/",
- data=json.dumps(payload).encode("utf-8"),
- headers={
- "Authorization": f"Bearer {api_key}",
- "Content-Type": "application/json",
- },
- method="POST",
- )
-
- try:
- with request.urlopen(req, timeout=30) as response:
- data = json.loads(response.read().decode("utf-8"))
- except error.HTTPError as exc:
- detail = exc.read().decode("utf-8", errors="replace").strip()
- print(f"Warning: PostHog stats query failed ({exc.code}): {detail}", file=sys.stderr)
- return {
- "status": f"http_{exc.code}",
- "total": 0,
- "human": 0,
- "agent": 0,
- "cli_hub_total": 0,
- "cli_hub_human": 0,
- "cli_hub_agent": 0,
- }
- except Exception as exc: # pragma: no cover - exercised in CI failure mode
- print(f"Warning: PostHog stats query failed: {exc}", file=sys.stderr)
- return {
- "status": "error",
- "total": 0,
- "human": 0,
- "agent": 0,
- "cli_hub_total": 0,
- "cli_hub_human": 0,
- "cli_hub_agent": 0,
- }
-
- results = data.get("results") or [[0, 0, 0, 0]]
- row = results[0] if results else [0, 0, 0, 0]
- human = int(row[0] or 0)
- agent = int(row[1] or 0)
- cli_hub_human = int(row[2] or 0)
- cli_hub_agent = int(row[3] or 0)
- return {
- "status": "ok",
- "app_host": app_host,
- "project_id": project_id,
- "human": human,
- "agent": agent,
- "total": human + agent,
- "cli_hub_human": cli_hub_human,
- "cli_hub_agent": cli_hub_agent,
- "cli_hub_total": cli_hub_human + cli_hub_agent,
- }
-
-
-def main():
- posthog_increment = _posthog_increment()
- totals = {
- "total": BASELINE["total"] + posthog_increment["total"],
- "human": BASELINE["human"] + posthog_increment["human"],
- "agent": BASELINE["agent"] + posthog_increment["agent"],
- "cli_hub_total": BASELINE["cli_hub_total"] + posthog_increment["cli_hub_total"],
- "cli_hub_human": BASELINE["cli_hub_human"] + posthog_increment["cli_hub_human"],
- "cli_hub_agent": BASELINE["cli_hub_agent"] + posthog_increment["cli_hub_agent"],
- }
- payload = {
- "site": SITE,
- "provider": "posthog",
- "generated_at": datetime.now(UTC).isoformat(),
- "migration_started_at": MIGRATION_STARTED_AT,
- "baseline": BASELINE,
- "posthog_increment": posthog_increment,
- "totals": totals,
- }
- OUTPUT_PATH.write_text(json.dumps(payload, indent=2) + "\n")
- print(json.dumps(payload, indent=2))
-
-
-if __name__ == "__main__":
- main()
diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml
index 96751310d..f47848ba8 100644
--- a/.github/workflows/deploy-pages.yml
+++ b/.github/workflows/deploy-pages.yml
@@ -12,7 +12,6 @@ on:
- 'docs/hub/**'
- '.github/workflows/deploy-pages.yml'
- '.github/scripts/update_registry_dates.py'
- - '.github/scripts/update_hub_analytics_stats.py'
- '.github/scripts/generate_meta_skill.py'
workflow_dispatch:
@@ -45,13 +44,6 @@ jobs:
- name: Generate meta-skill
run: python3 .github/scripts/generate_meta_skill.py
- - name: Generate hub analytics stats
- env:
- POSTHOG_APP_HOST: https://us.posthog.com
- POSTHOG_PROJECT_ID: "393992"
- POSTHOG_PERSONAL_API_KEY: ${{ secrets.POSTHOG_PERSONAL_API_KEY }}
- run: python3 .github/scripts/update_hub_analytics_stats.py
-
- name: Install AWS CLI
run: pip install awscli
diff --git a/docs/hub/analytics-stats.json b/docs/hub/analytics-stats.json
deleted file mode 100644
index 964fb134e..000000000
--- a/docs/hub/analytics-stats.json
+++ /dev/null
@@ -1,37 +0,0 @@
-{
- "site": "clianything.cc",
- "provider": "posthog",
- "generated_at": "2026-04-23T15:31:59.837617+00:00",
- "migration_started_at": "2026-04-23T09:06:38Z",
- "baseline": {
- "provider": "umami",
- "site": "clianything.cc",
- "scope": "clianything.cc only",
- "queried_at": "2026-04-23T09:06:38.505000+00:00",
- "total": 21123,
- "human": 7689,
- "agent": 13434,
- "cli_hub_total": 16361,
- "cli_hub_human": 3237,
- "cli_hub_agent": 13124
- },
- "posthog_increment": {
- "status": "ok",
- "app_host": "https://us.posthog.com",
- "project_id": "393992",
- "human": 3,
- "agent": 1,
- "total": 4,
- "cli_hub_human": 0,
- "cli_hub_agent": 2,
- "cli_hub_total": 2
- },
- "totals": {
- "total": 21127,
- "human": 7692,
- "agent": 13435,
- "cli_hub_total": 16363,
- "cli_hub_human": 3237,
- "cli_hub_agent": 13126
- }
-}
diff --git a/docs/hub/index-modern.html b/docs/hub/index-modern.html
index a76f5626e..f609c8446 100644
--- a/docs/hub/index-modern.html
+++ b/docs/hub/index-modern.html
@@ -2909,20 +2909,80 @@
document.addEventListener(evt, onHumanInteraction, { once: false, passive: true });
});
- async function loadVisitorStats() {
- applyVisitorStats(BASELINE_STATS);
+ // ── Live analytics (PostHog HogQL) ──
+ // Read-only personal API key, scoped to `query:read` on project 393992 only.
+ // See https://us.posthog.com/settings/user-api-keys.
+ const POSTHOG_READONLY_KEY = 'phx_FizBjpYkycqd7b9UC2ZebHNhze6gn8T9SmUv5uG8dXXLepHj';
+ const POSTHOG_QUERY_HOST = 'https://us.posthog.com';
+ const POSTHOG_QUERY_PROJECT_ID = '393992';
+ const MIGRATION_STARTED_AT = '2026-04-23T09:06:38Z';
+ const LIVE_STATS_REFRESH_MS = 60_000;
+
+ async function fetchPosthogIncrement() {
+ if (!POSTHOG_READONLY_KEY || POSTHOG_READONLY_KEY.indexOf('REPLACE') !== -1) {
+ throw new Error('posthog readonly key not configured');
+ }
+ const hogql = (
+ "select " +
+ "countIf(event = 'visit-human' and properties.source = 'web' and properties.site = 'clianything.cc') as human, " +
+ "countIf(event = 'visit-agent' and properties.source = 'web' and properties.site = 'clianything.cc') as agent, " +
+ "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = false) as cli_hub_human, " +
+ "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = true) as cli_hub_agent " +
+ "from events " +
+ "where timestamp >= parseDateTimeBestEffort('" + MIGRATION_STARTED_AT + "')"
+ );
+ const response = await fetch(POSTHOG_QUERY_HOST + '/api/projects/' + POSTHOG_QUERY_PROJECT_ID + '/query/', {
+ method: 'POST',
+ headers: {
+ 'Authorization': 'Bearer ' + POSTHOG_READONLY_KEY,
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ query: { kind: 'HogQLQuery', query: hogql } }),
+ });
+ if (!response.ok) throw new Error('posthog query http ' + response.status);
+ const data = await response.json();
+ const row = (data.results && data.results[0]) || [0, 0, 0, 0];
+ const human = Number(row[0]) || 0;
+ const agent = Number(row[1]) || 0;
+ const cliHuman = Number(row[2]) || 0;
+ const cliAgent = Number(row[3]) || 0;
+ return {
+ total: human + agent,
+ human,
+ agent,
+ cli_hub_total: cliHuman + cliAgent,
+ cli_hub_human: cliHuman,
+ cli_hub_agent: cliAgent,
+ };
+ }
+
+ function mergeStats(baseline, increment) {
+ return {
+ total: baseline.total + increment.total,
+ human: baseline.human + increment.human,
+ agent: baseline.agent + increment.agent,
+ cli_hub_total: baseline.cli_hub_total + increment.cli_hub_total,
+ cli_hub_human: baseline.cli_hub_human + increment.cli_hub_human,
+ cli_hub_agent: baseline.cli_hub_agent + increment.cli_hub_agent,
+ };
+ }
+
+ async function refreshVisitorStats() {
try {
- const response = await fetch('./analytics-stats.json', { cache: 'no-store' });
- if (!response.ok) return;
- const stats = await response.json();
- if (stats && stats.totals) {
- applyVisitorStats(stats.totals);
- }
+ const increment = await fetchPosthogIncrement();
+ applyVisitorStats(mergeStats(BASELINE_STATS, increment));
+ return true;
} catch (_) {
- // Fall back to the fixed baseline values.
+ return false;
}
}
+ async function loadVisitorStats() {
+ applyVisitorStats(BASELINE_STATS);
+ await refreshVisitorStats();
+ setInterval(refreshVisitorStats, LIVE_STATS_REFRESH_MS);
+ }
+
loadVisitorStats();
if (typeof loadGitHubStars === 'function') {
loadGitHubStars();
diff --git a/docs/hub/index.html b/docs/hub/index.html
index 2e78843d8..3baa8027f 100644
--- a/docs/hub/index.html
+++ b/docs/hub/index.html
@@ -3123,20 +3123,82 @@
document.addEventListener(evt, onHumanInteraction, { once: false, passive: true });
});
- async function loadVisitorStats() {
- applyVisitorStats(BASELINE_STATS);
+ // ── Live analytics (PostHog HogQL) ──
+ // Read-only personal API key, scoped to `query:read` on project 393992 only.
+ // See https://us.posthog.com/settings/user-api-keys — create a scoped key
+ // and paste it below. The Umami baseline is fixed at the migration cutover
+ // and PostHog counts are added on top of it.
+ const POSTHOG_READONLY_KEY = 'phx_FizBjpYkycqd7b9UC2ZebHNhze6gn8T9SmUv5uG8dXXLepHj';
+ const POSTHOG_QUERY_HOST = 'https://us.posthog.com';
+ const POSTHOG_QUERY_PROJECT_ID = '393992';
+ const MIGRATION_STARTED_AT = '2026-04-23T09:06:38Z';
+ const LIVE_STATS_REFRESH_MS = 60_000;
+
+ async function fetchPosthogIncrement() {
+ if (!POSTHOG_READONLY_KEY || POSTHOG_READONLY_KEY.indexOf('REPLACE') !== -1) {
+ throw new Error('posthog readonly key not configured');
+ }
+ const hogql = (
+ "select " +
+ "countIf(event = 'visit-human' and properties.source = 'web' and properties.site = 'clianything.cc') as human, " +
+ "countIf(event = 'visit-agent' and properties.source = 'web' and properties.site = 'clianything.cc') as agent, " +
+ "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = false) as cli_hub_human, " +
+ "countIf(event = 'cli-hub call' and properties.source = 'cli' and properties.channel = 'cli-hub' and properties.is_agent = true) as cli_hub_agent " +
+ "from events " +
+ "where timestamp >= parseDateTimeBestEffort('" + MIGRATION_STARTED_AT + "')"
+ );
+ const response = await fetch(POSTHOG_QUERY_HOST + '/api/projects/' + POSTHOG_QUERY_PROJECT_ID + '/query/', {
+ method: 'POST',
+ headers: {
+ 'Authorization': 'Bearer ' + POSTHOG_READONLY_KEY,
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ query: { kind: 'HogQLQuery', query: hogql } }),
+ });
+ if (!response.ok) throw new Error('posthog query http ' + response.status);
+ const data = await response.json();
+ const row = (data.results && data.results[0]) || [0, 0, 0, 0];
+ const human = Number(row[0]) || 0;
+ const agent = Number(row[1]) || 0;
+ const cliHuman = Number(row[2]) || 0;
+ const cliAgent = Number(row[3]) || 0;
+ return {
+ total: human + agent,
+ human,
+ agent,
+ cli_hub_total: cliHuman + cliAgent,
+ cli_hub_human: cliHuman,
+ cli_hub_agent: cliAgent,
+ };
+ }
+
+ function mergeStats(baseline, increment) {
+ return {
+ total: baseline.total + increment.total,
+ human: baseline.human + increment.human,
+ agent: baseline.agent + increment.agent,
+ cli_hub_total: baseline.cli_hub_total + increment.cli_hub_total,
+ cli_hub_human: baseline.cli_hub_human + increment.cli_hub_human,
+ cli_hub_agent: baseline.cli_hub_agent + increment.cli_hub_agent,
+ };
+ }
+
+ async function refreshVisitorStats() {
try {
- const response = await fetch('./analytics-stats.json', { cache: 'no-store' });
- if (!response.ok) return;
- const stats = await response.json();
- if (stats && stats.totals) {
- applyVisitorStats(stats.totals);
- }
+ const increment = await fetchPosthogIncrement();
+ applyVisitorStats(mergeStats(BASELINE_STATS, increment));
+ return true;
} catch (_) {
- // Fall back to the fixed baseline values.
+ return false;
}
}
+ async function loadVisitorStats() {
+ applyVisitorStats(BASELINE_STATS);
+ await refreshVisitorStats();
+ setInterval(refreshVisitorStats, LIVE_STATS_REFRESH_MS);
+ }
+
loadVisitorStats();
if (typeof loadGitHubStars === 'function') {
loadGitHubStars();