Răsfoiți Sursa

ci: send stats to posthog

Dax Raad 8 luni în urmă
părinte
comite
3db8e7c2b6
4 a modificat fișierele cu 51 adăugiri și 42 ștergeri
  1. 2 0
      .github/workflows/stats.yml
  2. 11 12
      AGENTS.md
  3. 0 13
      packages/opencode/AGENTS.md
  4. 38 17
      script/stats.ts

+ 2 - 0
.github/workflows/stats.yml

@@ -30,3 +30,5 @@ jobs:
           git add STATS.md
           git diff --staged --quiet || git commit -m "ignore: update download stats $(date -I)"
           git push
+        env:
+          POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}

+ 11 - 12
AGENTS.md

@@ -1,13 +1,12 @@
-## Style
+## IMPORTANT
 
-- prefer single word variable/function names
-- avoid try catch where possible - prefer to let exceptions bubble up
-- avoid else statements where possible
-- do not make useless helper functions - inline functionality unless the
-  function is reusable or composable
-- prefer Bun apis
-
-## Workflow
-
-- you can regenerate the golang sdk by calling ./scripts/stainless.ts
-- we use bun for everything
+- Try to keep things in one function unless composable or reusable
+- DO NOT do unnecessary destructuring of variables
+- DO NOT use `else` statements unless necessary
+- DO NOT use `try`/`catch` if it can be avoided
+- AVOID `try`/`catch` where possible
+- AVOID `else` statements
+- AVOID using `any` type
+- AVOID `let` statements
+- PREFER single word variable names where possible
+- Use as many bun apis as possible like Bun.file()

+ 0 - 13
packages/opencode/AGENTS.md

@@ -17,19 +17,6 @@
 - **Error handling**: Use Result patterns, avoid throwing exceptions in tools
 - **File structure**: Namespace-based organization (e.g., `Tool.define()`, `Session.create()`)
 
-## IMPORTANT
-
-- Try to keep things in one function unless composable or reusable
-- DO NOT do unnecessary destructuring of variables
-- DO NOT use `else` statements unless necessary
-- DO NOT use `try`/`catch` if it can be avoided
-- AVOID `try`/`catch` where possible
-- AVOID `else` statements
-- AVOID using `any` type
-- AVOID `let` statements
-- PREFER single word variable names where possible
-- Use as many bun apis as possible like Bun.file()
-
 ## Architecture
 
 - **Tools**: Implement `Tool.Info` interface with `execute()` method

+ 38 - 17
script/stats.ts

@@ -1,5 +1,33 @@
 #!/usr/bin/env bun
 
+async function sendToPostHog(event: string, properties: Record<string, any>) {
+  const key = process.env["POSTHOG_KEY"]
+
+  if (!key) {
+    console.warn("POSTHOG_API_KEY not set, skipping PostHog event")
+    return
+  }
+
+  const response = await fetch("https://us.i.posthog.com/i/v0/e/", {
+    method: "POST",
+    headers: {
+      "Content-Type": "application/json",
+    },
+    body: JSON.stringify({
+      distinct_id: "download",
+      api_key: key,
+      event,
+      properties: {
+        ...properties,
+      },
+    }),
+  }).catch(() => null)
+
+  if (response && !response.ok) {
+    console.warn(`PostHog API error: ${response.status}`)
+  }
+}
+
 interface Asset {
   name: string
   download_count: number
@@ -173,6 +201,16 @@ console.log(`Fetched npm all-time downloads: ${npmDownloads.toLocaleString()}\n`
 
 await save(githubTotal, npmDownloads)
 
+await sendToPostHog("download", {
+  count: githubTotal,
+  source: "github",
+})
+
+await sendToPostHog("download", {
+  count: npmDownloads,
+  source: "npm",
+})
+
 const totalDownloads = githubTotal + npmDownloads
 
 console.log("=".repeat(60))
@@ -181,23 +219,6 @@ console.log(`  GitHub: ${githubTotal.toLocaleString()}`)
 console.log(`  npm: ${npmDownloads.toLocaleString()}`)
 console.log("=".repeat(60))
 
-console.log("\nDownloads by release:")
-console.log("-".repeat(60))
-
-stats
-  .sort((a, b) => b.downloads - a.downloads)
-  .forEach((release) => {
-    console.log(`${release.tag.padEnd(15)} ${release.downloads.toLocaleString().padStart(10)} downloads`)
-
-    if (release.assets.length > 1) {
-      release.assets
-        .sort((a, b) => b.downloads - a.downloads)
-        .forEach((asset) => {
-          console.log(`  └─ ${asset.name.padEnd(25)} ${asset.downloads.toLocaleString().padStart(8)}`)
-        })
-    }
-  })
-
 console.log("-".repeat(60))
 console.log(`GitHub Total: ${githubTotal.toLocaleString()} downloads across ${releases.length} releases`)
 console.log(`npm Total: ${npmDownloads.toLocaleString()} downloads`)