diff --git a/.github/workflows/stats.yml b/.github/workflows/stats.yml index 8ad02d25..ab7f24e2 100644 --- a/.github/workflows/stats.yml +++ b/.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 }} diff --git a/AGENTS.md b/AGENTS.md index 0852d237..cca69e4b 100644 --- a/AGENTS.md +++ b/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() diff --git a/packages/opencode/AGENTS.md b/packages/opencode/AGENTS.md index 8b3b03dc..287cbc26 100644 --- a/packages/opencode/AGENTS.md +++ b/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 diff --git a/script/stats.ts b/script/stats.ts index bce21185..d5f6c103 100755 --- a/script/stats.ts +++ b/script/stats.ts @@ -1,5 +1,33 @@ #!/usr/bin/env bun +async function sendToPostHog(event: string, properties: Record) { + 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`)